1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-29 17:50:09 +02:00
Files
php-web-maker/app/vendor.js
Kushagra Gour 9e3a8a9087 build dist->app
2018-01-05 02:47:20 +05:30

70250 lines
2.0 MiB
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// This is CodeMirror (http://codemirror.net), a code editor
// implemented in JavaScript on top of the browser's DOM.
//
// You can find some technical background for some of the code below
// at http://marijnhaverbeke.nl/blog/#cm-internals .
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
module.exports = mod();
else if (typeof define == "function" && define.amd) // AMD
return define([], mod);
else // Plain browser env
(this || window).CodeMirror = mod();
})(function() {
"use strict";
// BROWSER SNIFFING
// Kludges for bugs and behavior differences that can't be feature
// detected are enabled based on userAgent etc sniffing.
var userAgent = navigator.userAgent;
var platform = navigator.platform;
var gecko = /gecko\/\d/i.test(userAgent);
var ie_upto10 = /MSIE \d/.test(userAgent);
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
var ie = ie_upto10 || ie_11up;
var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : ie_11up[1]);
var webkit = /WebKit\//.test(userAgent);
var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
var chrome = /Chrome\//.test(userAgent);
var presto = /Opera\//.test(userAgent);
var safari = /Apple Computer/.test(navigator.vendor);
var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
var phantom = /PhantomJS/.test(userAgent);
var ios = /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
// This is woefully incomplete. Suggestions for alternative methods welcome.
var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
var mac = ios || /Mac/.test(platform);
var chromeOS = /\bCrOS\b/.test(userAgent);
var windows = /win/i.test(platform);
var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
if (presto_version) presto_version = Number(presto_version[1]);
if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
// Some browsers use the wrong event properties to signal cmd/ctrl on OS X
var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
var captureRightClick = gecko || (ie && ie_version >= 9);
// Optimize some code when these features are not used.
var sawReadOnlySpans = false, sawCollapsedSpans = false;
// EDITOR CONSTRUCTOR
// A CodeMirror instance represents an editor. This is the object
// that user code is usually dealing with.
function CodeMirror(place, options) {
if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
this.options = options = options ? copyObj(options) : {};
// Determine effective options based on given values and defaults.
copyObj(defaults, options, false);
setGuttersForLineNumbers(options);
var doc = options.value;
if (typeof doc == "string") doc = new Doc(doc, options.mode, null, options.lineSeparator);
this.doc = doc;
var input = new CodeMirror.inputStyles[options.inputStyle](this);
var display = this.display = new Display(place, doc, input);
display.wrapper.CodeMirror = this;
updateGutters(this);
themeChanged(this);
if (options.lineWrapping)
this.display.wrapper.className += " CodeMirror-wrap";
if (options.autofocus && !mobile) display.input.focus();
initScrollbars(this);
this.state = {
keyMaps: [], // stores maps added by addKeyMap
overlays: [], // highlighting overlays, as added by addOverlay
modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
overwrite: false,
delayingBlurEvent: false,
focused: false,
suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
selectingText: false,
draggingText: false,
highlight: new Delayed(), // stores highlight worker timeout
keySeq: null, // Unfinished key sequence
specialChars: null
};
var cm = this;
// Override magic textarea content restore that IE sometimes does
// on our hidden textarea on reload
if (ie && ie_version < 11) setTimeout(function() { cm.display.input.reset(true); }, 20);
registerEventHandlers(this);
ensureGlobalHandlers();
startOperation(this);
this.curOp.forceUpdate = true;
attachDoc(this, doc);
if ((options.autofocus && !mobile) || cm.hasFocus())
setTimeout(bind(onFocus, this), 20);
else
onBlur(this);
for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
optionHandlers[opt](this, options[opt], Init);
maybeUpdateLineNumberWidth(this);
if (options.finishInit) options.finishInit(this);
for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
endOperation(this);
// Suppress optimizelegibility in Webkit, since it breaks text
// measuring on line wrapping boundaries.
if (webkit && options.lineWrapping &&
getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
display.lineDiv.style.textRendering = "auto";
}
// DISPLAY CONSTRUCTOR
// The display handles the DOM integration, both for input reading
// and content drawing. It holds references to DOM nodes and
// display-related state.
function Display(place, doc, input) {
var d = this;
this.input = input;
// Covers bottom-right square when both scrollbars are present.
d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
d.scrollbarFiller.setAttribute("cm-not-content", "true");
// Covers bottom of gutter when coverGutterNextToScrollbar is on
// and h scrollbar is present.
d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
d.gutterFiller.setAttribute("cm-not-content", "true");
// Will contain the actual code, positioned to cover the viewport.
d.lineDiv = elt("div", null, "CodeMirror-code");
// Elements are added to these to represent selection and cursors.
d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
d.cursorDiv = elt("div", null, "CodeMirror-cursors");
// A visibility: hidden element used to find the size of things.
d.measure = elt("div", null, "CodeMirror-measure");
// When lines outside of the viewport are measured, they are drawn in this.
d.lineMeasure = elt("div", null, "CodeMirror-measure");
// Wraps everything that needs to exist inside the vertically-padded coordinate system
d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
null, "position: relative; outline: none");
// Moved around its parent to cover visible view.
d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
// Set to the height of the document, allowing scrolling.
d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
d.sizerWidth = null;
// Behavior of elts with overflow: auto and padding is
// inconsistent across browsers. This is used to ensure the
// scrollable area is big enough.
d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
// Will contain the gutters, if any.
d.gutters = elt("div", null, "CodeMirror-gutters");
d.lineGutter = null;
// Actual scrollable element.
d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
d.scroller.setAttribute("tabIndex", "-1");
// The element in which the editor lives.
d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
// Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
if (!webkit && !(gecko && mobile)) d.scroller.draggable = true;
if (place) {
if (place.appendChild) place.appendChild(d.wrapper);
else place(d.wrapper);
}
// Current rendered range (may be bigger than the view window).
d.viewFrom = d.viewTo = doc.first;
d.reportedViewFrom = d.reportedViewTo = doc.first;
// Information about the rendered lines.
d.view = [];
d.renderedView = null;
// Holds info about a single rendered line when it was rendered
// for measurement, while not in view.
d.externalMeasured = null;
// Empty space (in pixels) above the view
d.viewOffset = 0;
d.lastWrapHeight = d.lastWrapWidth = 0;
d.updateLineNumbers = null;
d.nativeBarWidth = d.barHeight = d.barWidth = 0;
d.scrollbarsClipped = false;
// Used to only resize the line number gutter when necessary (when
// the amount of lines crosses a boundary that makes its width change)
d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
// Set to true when a non-horizontal-scrolling line widget is
// added. As an optimization, line widget aligning is skipped when
// this is false.
d.alignWidgets = false;
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
// Tracks the maximum line length so that the horizontal scrollbar
// can be kept static when scrolling.
d.maxLine = null;
d.maxLineLength = 0;
d.maxLineChanged = false;
// Used for measuring wheel scrolling granularity
d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
// True when shift is held down.
d.shift = false;
// Used to track whether anything happened since the context menu
// was opened.
d.selForContextMenu = null;
d.activeTouch = null;
input.init(d);
}
// STATE UPDATES
// Used to get the editor into a consistent state again when options change.
function loadMode(cm) {
cm.doc.mode = CodeMirror.getMode(cm.options, cm.doc.modeOption);
resetModeState(cm);
}
function resetModeState(cm) {
cm.doc.iter(function(line) {
if (line.stateAfter) line.stateAfter = null;
if (line.styles) line.styles = null;
});
cm.doc.frontier = cm.doc.first;
startWorker(cm, 100);
cm.state.modeGen++;
if (cm.curOp) regChange(cm);
}
function wrappingChanged(cm) {
if (cm.options.lineWrapping) {
addClass(cm.display.wrapper, "CodeMirror-wrap");
cm.display.sizer.style.minWidth = "";
cm.display.sizerWidth = null;
} else {
rmClass(cm.display.wrapper, "CodeMirror-wrap");
findMaxLine(cm);
}
estimateLineHeights(cm);
regChange(cm);
clearCaches(cm);
setTimeout(function(){updateScrollbars(cm);}, 100);
}
// Returns a function that estimates the height of a line, to use as
// first approximation until the line becomes visible (and is thus
// properly measurable).
function estimateHeight(cm) {
var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
return function(line) {
if (lineIsHidden(cm.doc, line)) return 0;
var widgetsHeight = 0;
if (line.widgets) for (var i = 0; i < line.widgets.length; i++) {
if (line.widgets[i].height) widgetsHeight += line.widgets[i].height;
}
if (wrapping)
return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
else
return widgetsHeight + th;
};
}
function estimateLineHeights(cm) {
var doc = cm.doc, est = estimateHeight(cm);
doc.iter(function(line) {
var estHeight = est(line);
if (estHeight != line.height) updateLineHeight(line, estHeight);
});
}
function themeChanged(cm) {
cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
clearCaches(cm);
}
function guttersChanged(cm) {
updateGutters(cm);
regChange(cm);
setTimeout(function(){alignHorizontally(cm);}, 20);
}
// Rebuild the gutter elements, ensure the margin to the left of the
// code matches their width.
function updateGutters(cm) {
var gutters = cm.display.gutters, specs = cm.options.gutters;
removeChildren(gutters);
for (var i = 0; i < specs.length; ++i) {
var gutterClass = specs[i];
var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
if (gutterClass == "CodeMirror-linenumbers") {
cm.display.lineGutter = gElt;
gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
}
}
gutters.style.display = i ? "" : "none";
updateGutterSpace(cm);
}
function updateGutterSpace(cm) {
var width = cm.display.gutters.offsetWidth;
cm.display.sizer.style.marginLeft = width + "px";
}
// Compute the character length of a line, taking into account
// collapsed ranges (see markText) that might hide parts, and join
// other lines onto it.
function lineLength(line) {
if (line.height == 0) return 0;
var len = line.text.length, merged, cur = line;
while (merged = collapsedSpanAtStart(cur)) {
var found = merged.find(0, true);
cur = found.from.line;
len += found.from.ch - found.to.ch;
}
cur = line;
while (merged = collapsedSpanAtEnd(cur)) {
var found = merged.find(0, true);
len -= cur.text.length - found.from.ch;
cur = found.to.line;
len += cur.text.length - found.to.ch;
}
return len;
}
// Find the longest line in the document.
function findMaxLine(cm) {
var d = cm.display, doc = cm.doc;
d.maxLine = getLine(doc, doc.first);
d.maxLineLength = lineLength(d.maxLine);
d.maxLineChanged = true;
doc.iter(function(line) {
var len = lineLength(line);
if (len > d.maxLineLength) {
d.maxLineLength = len;
d.maxLine = line;
}
});
}
// Make sure the gutters options contains the element
// "CodeMirror-linenumbers" when the lineNumbers option is true.
function setGuttersForLineNumbers(options) {
var found = indexOf(options.gutters, "CodeMirror-linenumbers");
if (found == -1 && options.lineNumbers) {
options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
} else if (found > -1 && !options.lineNumbers) {
options.gutters = options.gutters.slice(0);
options.gutters.splice(found, 1);
}
}
// SCROLLBARS
// Prepare DOM reads needed to update the scrollbars. Done in one
// shot to minimize update/measure roundtrips.
function measureForScrollbars(cm) {
var d = cm.display, gutterW = d.gutters.offsetWidth;
var docH = Math.round(cm.doc.height + paddingVert(cm.display));
return {
clientHeight: d.scroller.clientHeight,
viewHeight: d.wrapper.clientHeight,
scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
viewWidth: d.wrapper.clientWidth,
barLeft: cm.options.fixedGutter ? gutterW : 0,
docHeight: docH,
scrollHeight: docH + scrollGap(cm) + d.barHeight,
nativeBarWidth: d.nativeBarWidth,
gutterWidth: gutterW
};
}
function NativeScrollbars(place, scroll, cm) {
this.cm = cm;
var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
place(vert); place(horiz);
on(vert, "scroll", function() {
if (vert.clientHeight) scroll(vert.scrollTop, "vertical");
});
on(horiz, "scroll", function() {
if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal");
});
this.checkedZeroWidth = false;
// Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
if (ie && ie_version < 8) this.horiz.style.minHeight = this.vert.style.minWidth = "18px";
}
NativeScrollbars.prototype = copyObj({
update: function(measure) {
var needsH = measure.scrollWidth > measure.clientWidth + 1;
var needsV = measure.scrollHeight > measure.clientHeight + 1;
var sWidth = measure.nativeBarWidth;
if (needsV) {
this.vert.style.display = "block";
this.vert.style.bottom = needsH ? sWidth + "px" : "0";
var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
// A bug in IE8 can cause this value to be negative, so guard it.
this.vert.firstChild.style.height =
Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
} else {
this.vert.style.display = "";
this.vert.firstChild.style.height = "0";
}
if (needsH) {
this.horiz.style.display = "block";
this.horiz.style.right = needsV ? sWidth + "px" : "0";
this.horiz.style.left = measure.barLeft + "px";
var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
this.horiz.firstChild.style.width =
(measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
} else {
this.horiz.style.display = "";
this.horiz.firstChild.style.width = "0";
}
if (!this.checkedZeroWidth && measure.clientHeight > 0) {
if (sWidth == 0) this.zeroWidthHack();
this.checkedZeroWidth = true;
}
return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0};
},
setScrollLeft: function(pos) {
if (this.horiz.scrollLeft != pos) this.horiz.scrollLeft = pos;
if (this.disableHoriz) this.enableZeroWidthBar(this.horiz, this.disableHoriz);
},
setScrollTop: function(pos) {
if (this.vert.scrollTop != pos) this.vert.scrollTop = pos;
if (this.disableVert) this.enableZeroWidthBar(this.vert, this.disableVert);
},
zeroWidthHack: function() {
var w = mac && !mac_geMountainLion ? "12px" : "18px";
this.horiz.style.height = this.vert.style.width = w;
this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none";
this.disableHoriz = new Delayed;
this.disableVert = new Delayed;
},
enableZeroWidthBar: function(bar, delay) {
bar.style.pointerEvents = "auto";
function maybeDisable() {
// To find out whether the scrollbar is still visible, we
// check whether the element under the pixel in the bottom
// left corner of the scrollbar box is the scrollbar box
// itself (when the bar is still visible) or its filler child
// (when the bar is hidden). If it is still visible, we keep
// it enabled, if it's hidden, we disable pointer events.
var box = bar.getBoundingClientRect();
var elt = document.elementFromPoint(box.left + 1, box.bottom - 1);
if (elt != bar) bar.style.pointerEvents = "none";
else delay.set(1000, maybeDisable);
}
delay.set(1000, maybeDisable);
},
clear: function() {
var parent = this.horiz.parentNode;
parent.removeChild(this.horiz);
parent.removeChild(this.vert);
}
}, NativeScrollbars.prototype);
function NullScrollbars() {}
NullScrollbars.prototype = copyObj({
update: function() { return {bottom: 0, right: 0}; },
setScrollLeft: function() {},
setScrollTop: function() {},
clear: function() {}
}, NullScrollbars.prototype);
CodeMirror.scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
function initScrollbars(cm) {
if (cm.display.scrollbars) {
cm.display.scrollbars.clear();
if (cm.display.scrollbars.addClass)
rmClass(cm.display.wrapper, cm.display.scrollbars.addClass);
}
cm.display.scrollbars = new CodeMirror.scrollbarModel[cm.options.scrollbarStyle](function(node) {
cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
// Prevent clicks in the scrollbars from killing focus
on(node, "mousedown", function() {
if (cm.state.focused) setTimeout(function() { cm.display.input.focus(); }, 0);
});
node.setAttribute("cm-not-content", "true");
}, function(pos, axis) {
if (axis == "horizontal") setScrollLeft(cm, pos);
else setScrollTop(cm, pos);
}, cm);
if (cm.display.scrollbars.addClass)
addClass(cm.display.wrapper, cm.display.scrollbars.addClass);
}
function updateScrollbars(cm, measure) {
if (!measure) measure = measureForScrollbars(cm);
var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
updateScrollbarsInner(cm, measure);
for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
updateHeightsInViewport(cm);
updateScrollbarsInner(cm, measureForScrollbars(cm));
startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
}
}
// Re-synchronize the fake scrollbars with the actual size of the
// content.
function updateScrollbarsInner(cm, measure) {
var d = cm.display;
var sizes = d.scrollbars.update(measure);
d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent"
if (sizes.right && sizes.bottom) {
d.scrollbarFiller.style.display = "block";
d.scrollbarFiller.style.height = sizes.bottom + "px";
d.scrollbarFiller.style.width = sizes.right + "px";
} else d.scrollbarFiller.style.display = "";
if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
d.gutterFiller.style.display = "block";
d.gutterFiller.style.height = sizes.bottom + "px";
d.gutterFiller.style.width = measure.gutterWidth + "px";
} else d.gutterFiller.style.display = "";
}
// Compute the lines that are visible in a given viewport (defaults
// the the current scroll position). viewport may contain top,
// height, and ensure (see op.scrollToPos) properties.
function visibleLines(display, doc, viewport) {
var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
top = Math.floor(top - paddingTop(display));
var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
// Ensure is a {from: {line, ch}, to: {line, ch}} object, and
// forces those lines into the viewport (if possible).
if (viewport && viewport.ensure) {
var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
if (ensureFrom < from) {
from = ensureFrom;
to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
} else if (Math.min(ensureTo, doc.lastLine()) >= to) {
from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
to = ensureTo;
}
}
return {from: from, to: Math.max(to, from + 1)};
}
// LINE NUMBERS
// Re-align line numbers and gutter marks to compensate for
// horizontal scrolling.
function alignHorizontally(cm) {
var display = cm.display, view = display.view;
if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return;
var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
var gutterW = display.gutters.offsetWidth, left = comp + "px";
for (var i = 0; i < view.length; i++) if (!view[i].hidden) {
if (cm.options.fixedGutter && view[i].gutter)
view[i].gutter.style.left = left;
var align = view[i].alignable;
if (align) for (var j = 0; j < align.length; j++)
align[j].style.left = left;
}
if (cm.options.fixedGutter)
display.gutters.style.left = (comp + gutterW) + "px";
}
// Used to ensure that the line number gutter is still the right
// size for the current document size. Returns true when an update
// is needed.
function maybeUpdateLineNumberWidth(cm) {
if (!cm.options.lineNumbers) return false;
var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
if (last.length != display.lineNumChars) {
var test = display.measure.appendChild(elt("div", [elt("div", last)],
"CodeMirror-linenumber CodeMirror-gutter-elt"));
var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
display.lineGutter.style.width = "";
display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
display.lineNumWidth = display.lineNumInnerWidth + padding;
display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
display.lineGutter.style.width = display.lineNumWidth + "px";
updateGutterSpace(cm);
return true;
}
return false;
}
function lineNumberFor(options, i) {
return String(options.lineNumberFormatter(i + options.firstLineNumber));
}
// Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
// but using getBoundingClientRect to get a sub-pixel-accurate
// result.
function compensateForHScroll(display) {
return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
}
// DISPLAY DRAWING
function DisplayUpdate(cm, viewport, force) {
var display = cm.display;
this.viewport = viewport;
// Store some values that we'll need later (but don't want to force a relayout for)
this.visible = visibleLines(display, cm.doc, viewport);
this.editorIsHidden = !display.wrapper.offsetWidth;
this.wrapperHeight = display.wrapper.clientHeight;
this.wrapperWidth = display.wrapper.clientWidth;
this.oldDisplayWidth = displayWidth(cm);
this.force = force;
this.dims = getDimensions(cm);
this.events = [];
}
DisplayUpdate.prototype.signal = function(emitter, type) {
if (hasHandler(emitter, type))
this.events.push(arguments);
};
DisplayUpdate.prototype.finish = function() {
for (var i = 0; i < this.events.length; i++)
signal.apply(null, this.events[i]);
};
function maybeClipScrollbars(cm) {
var display = cm.display;
if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
display.heightForcer.style.height = scrollGap(cm) + "px";
display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
display.scrollbarsClipped = true;
}
}
// Does the actual updating of the line display. Bails out
// (returning false) when there is nothing to be done and forced is
// false.
function updateDisplayIfNeeded(cm, update) {
var display = cm.display, doc = cm.doc;
if (update.editorIsHidden) {
resetView(cm);
return false;
}
// Bail out if the visible area is already rendered and nothing changed.
if (!update.force &&
update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
display.renderedView == display.view && countDirtyView(cm) == 0)
return false;
if (maybeUpdateLineNumberWidth(cm)) {
resetView(cm);
update.dims = getDimensions(cm);
}
// Compute a suitable new viewport (from & to)
var end = doc.first + doc.size;
var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
if (display.viewFrom < from && from - display.viewFrom < 20) from = Math.max(doc.first, display.viewFrom);
if (display.viewTo > to && display.viewTo - to < 20) to = Math.min(end, display.viewTo);
if (sawCollapsedSpans) {
from = visualLineNo(cm.doc, from);
to = visualLineEndNo(cm.doc, to);
}
var different = from != display.viewFrom || to != display.viewTo ||
display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
adjustView(cm, from, to);
display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
// Position the mover div to align with the current scroll position
cm.display.mover.style.top = display.viewOffset + "px";
var toUpdate = countDirtyView(cm);
if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
return false;
// For big changes, we hide the enclosing element during the
// update, since that speeds up the operations on most browsers.
var focused = activeElt();
if (toUpdate > 4) display.lineDiv.style.display = "none";
patchDisplay(cm, display.updateLineNumbers, update.dims);
if (toUpdate > 4) display.lineDiv.style.display = "";
display.renderedView = display.view;
// There might have been a widget with a focused element that got
// hidden or updated, if so re-focus it.
if (focused && activeElt() != focused && focused.offsetHeight) focused.focus();
// Prevent selection and cursors from interfering with the scroll
// width and height.
removeChildren(display.cursorDiv);
removeChildren(display.selectionDiv);
display.gutters.style.height = display.sizer.style.minHeight = 0;
if (different) {
display.lastWrapHeight = update.wrapperHeight;
display.lastWrapWidth = update.wrapperWidth;
startWorker(cm, 400);
}
display.updateLineNumbers = null;
return true;
}
function postUpdateDisplay(cm, update) {
var viewport = update.viewport;
for (var first = true;; first = false) {
if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
// Clip forced viewport to actual scrollable area.
if (viewport && viewport.top != null)
viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)};
// Updated line heights might result in the drawn area not
// actually covering the viewport. Keep looping until it does.
update.visible = visibleLines(cm.display, cm.doc, viewport);
if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
break;
}
if (!updateDisplayIfNeeded(cm, update)) break;
updateHeightsInViewport(cm);
var barMeasure = measureForScrollbars(cm);
updateSelection(cm);
updateScrollbars(cm, barMeasure);
setDocumentHeight(cm, barMeasure);
}
update.signal(cm, "update", cm);
if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
}
}
function updateDisplaySimple(cm, viewport) {
var update = new DisplayUpdate(cm, viewport);
if (updateDisplayIfNeeded(cm, update)) {
updateHeightsInViewport(cm);
postUpdateDisplay(cm, update);
var barMeasure = measureForScrollbars(cm);
updateSelection(cm);
updateScrollbars(cm, barMeasure);
setDocumentHeight(cm, barMeasure);
update.finish();
}
}
function setDocumentHeight(cm, measure) {
cm.display.sizer.style.minHeight = measure.docHeight + "px";
cm.display.heightForcer.style.top = measure.docHeight + "px";
cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px";
}
// Read the actual heights of the rendered lines, and update their
// stored heights to match.
function updateHeightsInViewport(cm) {
var display = cm.display;
var prevBottom = display.lineDiv.offsetTop;
for (var i = 0; i < display.view.length; i++) {
var cur = display.view[i], height;
if (cur.hidden) continue;
if (ie && ie_version < 8) {
var bot = cur.node.offsetTop + cur.node.offsetHeight;
height = bot - prevBottom;
prevBottom = bot;
} else {
var box = cur.node.getBoundingClientRect();
height = box.bottom - box.top;
}
var diff = cur.line.height - height;
if (height < 2) height = textHeight(display);
if (diff > .001 || diff < -.001) {
updateLineHeight(cur.line, height);
updateWidgetHeight(cur.line);
if (cur.rest) for (var j = 0; j < cur.rest.length; j++)
updateWidgetHeight(cur.rest[j]);
}
}
}
// Read and store the height of line widgets associated with the
// given line.
function updateWidgetHeight(line) {
if (line.widgets) for (var i = 0; i < line.widgets.length; ++i)
line.widgets[i].height = line.widgets[i].node.parentNode.offsetHeight;
}
// Do a bulk-read of the DOM positions and sizes needed to draw the
// view, so that we don't interleave reading and writing to the DOM.
function getDimensions(cm) {
var d = cm.display, left = {}, width = {};
var gutterLeft = d.gutters.clientLeft;
for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft;
width[cm.options.gutters[i]] = n.clientWidth;
}
return {fixedPos: compensateForHScroll(d),
gutterTotalWidth: d.gutters.offsetWidth,
gutterLeft: left,
gutterWidth: width,
wrapperWidth: d.wrapper.clientWidth};
}
// Sync the actual display DOM structure with display.view, removing
// nodes for lines that are no longer in view, and creating the ones
// that are not there yet, and updating the ones that are out of
// date.
function patchDisplay(cm, updateNumbersFrom, dims) {
var display = cm.display, lineNumbers = cm.options.lineNumbers;
var container = display.lineDiv, cur = container.firstChild;
function rm(node) {
var next = node.nextSibling;
// Works around a throw-scroll bug in OS X Webkit
if (webkit && mac && cm.display.currentWheelTarget == node)
node.style.display = "none";
else
node.parentNode.removeChild(node);
return next;
}
var view = display.view, lineN = display.viewFrom;
// Loop over the elements in the view, syncing cur (the DOM nodes
// in display.lineDiv) with the view as we go.
for (var i = 0; i < view.length; i++) {
var lineView = view[i];
if (lineView.hidden) {
} else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
var node = buildLineElement(cm, lineView, lineN, dims);
container.insertBefore(node, cur);
} else { // Already drawn
while (cur != lineView.node) cur = rm(cur);
var updateNumber = lineNumbers && updateNumbersFrom != null &&
updateNumbersFrom <= lineN && lineView.lineNumber;
if (lineView.changes) {
if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false;
updateLineForChanges(cm, lineView, lineN, dims);
}
if (updateNumber) {
removeChildren(lineView.lineNumber);
lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
}
cur = lineView.node.nextSibling;
}
lineN += lineView.size;
}
while (cur) cur = rm(cur);
}
// When an aspect of a line changes, a string is added to
// lineView.changes. This updates the relevant part of the line's
// DOM structure.
function updateLineForChanges(cm, lineView, lineN, dims) {
for (var j = 0; j < lineView.changes.length; j++) {
var type = lineView.changes[j];
if (type == "text") updateLineText(cm, lineView);
else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims);
else if (type == "class") updateLineClasses(lineView);
else if (type == "widget") updateLineWidgets(cm, lineView, dims);
}
lineView.changes = null;
}
// Lines with gutter elements, widgets or a background class need to
// be wrapped, and have the extra elements added to the wrapper div
function ensureLineWrapped(lineView) {
if (lineView.node == lineView.text) {
lineView.node = elt("div", null, null, "position: relative");
if (lineView.text.parentNode)
lineView.text.parentNode.replaceChild(lineView.node, lineView.text);
lineView.node.appendChild(lineView.text);
if (ie && ie_version < 8) lineView.node.style.zIndex = 2;
}
return lineView.node;
}
function updateLineBackground(lineView) {
var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
if (cls) cls += " CodeMirror-linebackground";
if (lineView.background) {
if (cls) lineView.background.className = cls;
else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
} else if (cls) {
var wrap = ensureLineWrapped(lineView);
lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
}
}
// Wrapper around buildLineContent which will reuse the structure
// in display.externalMeasured when possible.
function getLineContent(cm, lineView) {
var ext = cm.display.externalMeasured;
if (ext && ext.line == lineView.line) {
cm.display.externalMeasured = null;
lineView.measure = ext.measure;
return ext.built;
}
return buildLineContent(cm, lineView);
}
// Redraw the line's text. Interacts with the background and text
// classes because the mode may output tokens that influence these
// classes.
function updateLineText(cm, lineView) {
var cls = lineView.text.className;
var built = getLineContent(cm, lineView);
if (lineView.text == lineView.node) lineView.node = built.pre;
lineView.text.parentNode.replaceChild(built.pre, lineView.text);
lineView.text = built.pre;
if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
lineView.bgClass = built.bgClass;
lineView.textClass = built.textClass;
updateLineClasses(lineView);
} else if (cls) {
lineView.text.className = cls;
}
}
function updateLineClasses(lineView) {
updateLineBackground(lineView);
if (lineView.line.wrapClass)
ensureLineWrapped(lineView).className = lineView.line.wrapClass;
else if (lineView.node != lineView.text)
lineView.node.className = "";
var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
lineView.text.className = textClass || "";
}
function updateLineGutter(cm, lineView, lineN, dims) {
if (lineView.gutter) {
lineView.node.removeChild(lineView.gutter);
lineView.gutter = null;
}
if (lineView.gutterBackground) {
lineView.node.removeChild(lineView.gutterBackground);
lineView.gutterBackground = null;
}
if (lineView.line.gutterClass) {
var wrap = ensureLineWrapped(lineView);
lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
"left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) +
"px; width: " + dims.gutterTotalWidth + "px");
wrap.insertBefore(lineView.gutterBackground, lineView.text);
}
var markers = lineView.line.gutterMarkers;
if (cm.options.lineNumbers || markers) {
var wrap = ensureLineWrapped(lineView);
var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", "left: " +
(cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px");
cm.display.input.setUneditable(gutterWrap);
wrap.insertBefore(gutterWrap, lineView.text);
if (lineView.line.gutterClass)
gutterWrap.className += " " + lineView.line.gutterClass;
if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
lineView.lineNumber = gutterWrap.appendChild(
elt("div", lineNumberFor(cm.options, lineN),
"CodeMirror-linenumber CodeMirror-gutter-elt",
"left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
+ cm.display.lineNumInnerWidth + "px"));
if (markers) for (var k = 0; k < cm.options.gutters.length; ++k) {
var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
if (found)
gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
}
}
}
function updateLineWidgets(cm, lineView, dims) {
if (lineView.alignable) lineView.alignable = null;
for (var node = lineView.node.firstChild, next; node; node = next) {
var next = node.nextSibling;
if (node.className == "CodeMirror-linewidget")
lineView.node.removeChild(node);
}
insertLineWidgets(cm, lineView, dims);
}
// Build a line's DOM representation from scratch
function buildLineElement(cm, lineView, lineN, dims) {
var built = getLineContent(cm, lineView);
lineView.text = lineView.node = built.pre;
if (built.bgClass) lineView.bgClass = built.bgClass;
if (built.textClass) lineView.textClass = built.textClass;
updateLineClasses(lineView);
updateLineGutter(cm, lineView, lineN, dims);
insertLineWidgets(cm, lineView, dims);
return lineView.node;
}
// A lineView may contain multiple logical lines (when merged by
// collapsed spans). The widgets for all of them need to be drawn.
function insertLineWidgets(cm, lineView, dims) {
insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false);
}
function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
if (!line.widgets) return;
var wrap = ensureLineWrapped(lineView);
for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true");
positionLineWidget(widget, node, lineView, dims);
cm.display.input.setUneditable(node);
if (allowAbove && widget.above)
wrap.insertBefore(node, lineView.gutter || lineView.text);
else
wrap.appendChild(node);
signalLater(widget, "redraw");
}
}
function positionLineWidget(widget, node, lineView, dims) {
if (widget.noHScroll) {
(lineView.alignable || (lineView.alignable = [])).push(node);
var width = dims.wrapperWidth;
node.style.left = dims.fixedPos + "px";
if (!widget.coverGutter) {
width -= dims.gutterTotalWidth;
node.style.paddingLeft = dims.gutterTotalWidth + "px";
}
node.style.width = width + "px";
}
if (widget.coverGutter) {
node.style.zIndex = 5;
node.style.position = "relative";
if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
}
}
// POSITION OBJECT
// A Pos instance represents a position within the text.
var Pos = CodeMirror.Pos = function(line, ch) {
if (!(this instanceof Pos)) return new Pos(line, ch);
this.line = line; this.ch = ch;
};
// Compare two positions, return 0 if they are the same, a negative
// number when a is less, and a positive number otherwise.
var cmp = CodeMirror.cmpPos = function(a, b) { return a.line - b.line || a.ch - b.ch; };
function copyPos(x) {return Pos(x.line, x.ch);}
function maxPos(a, b) { return cmp(a, b) < 0 ? b : a; }
function minPos(a, b) { return cmp(a, b) < 0 ? a : b; }
// INPUT HANDLING
function ensureFocus(cm) {
if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
}
// This will be set to an array of strings when copying, so that,
// when pasting, we know what kind of selections the copied text
// was made out of.
var lastCopied = null;
function applyTextInput(cm, inserted, deleted, sel, origin) {
var doc = cm.doc;
cm.display.shift = false;
if (!sel) sel = doc.sel;
var paste = cm.state.pasteIncoming || origin == "paste";
var textLines = doc.splitLines(inserted), multiPaste = null;
// When pasing N lines into N selections, insert one line per selection
if (paste && sel.ranges.length > 1) {
if (lastCopied && lastCopied.join("\n") == inserted) {
if (sel.ranges.length % lastCopied.length == 0) {
multiPaste = [];
for (var i = 0; i < lastCopied.length; i++)
multiPaste.push(doc.splitLines(lastCopied[i]));
}
} else if (textLines.length == sel.ranges.length) {
multiPaste = map(textLines, function(l) { return [l]; });
}
}
// Normal behavior is to insert the new text into every selection
for (var i = sel.ranges.length - 1; i >= 0; i--) {
var range = sel.ranges[i];
var from = range.from(), to = range.to();
if (range.empty()) {
if (deleted && deleted > 0) // Handle deletion
from = Pos(from.line, from.ch - deleted);
else if (cm.state.overwrite && !paste) // Handle overwrite
to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));
}
var updateInput = cm.curOp.updateInput;
var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines,
origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")};
makeChange(cm.doc, changeEvent);
signalLater(cm, "inputRead", cm, changeEvent);
}
if (inserted && !paste)
triggerElectric(cm, inserted);
ensureCursorVisible(cm);
cm.curOp.updateInput = updateInput;
cm.curOp.typing = true;
cm.state.pasteIncoming = cm.state.cutIncoming = false;
}
function handlePaste(e, cm) {
var pasted = e.clipboardData && e.clipboardData.getData("text/plain");
if (pasted) {
e.preventDefault();
if (!cm.isReadOnly() && !cm.options.disableInput)
runInOp(cm, function() { applyTextInput(cm, pasted, 0, null, "paste"); });
return true;
}
}
function triggerElectric(cm, inserted) {
// When an 'electric' character is inserted, immediately trigger a reindent
if (!cm.options.electricChars || !cm.options.smartIndent) return;
var sel = cm.doc.sel;
for (var i = sel.ranges.length - 1; i >= 0; i--) {
var range = sel.ranges[i];
if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) continue;
var mode = cm.getModeAt(range.head);
var indented = false;
if (mode.electricChars) {
for (var j = 0; j < mode.electricChars.length; j++)
if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
indented = indentLine(cm, range.head.line, "smart");
break;
}
} else if (mode.electricInput) {
if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch)))
indented = indentLine(cm, range.head.line, "smart");
}
if (indented) signalLater(cm, "electricInput", cm, range.head.line);
}
}
function copyableRanges(cm) {
var text = [], ranges = [];
for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
var line = cm.doc.sel.ranges[i].head.line;
var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
ranges.push(lineRange);
text.push(cm.getRange(lineRange.anchor, lineRange.head));
}
return {text: text, ranges: ranges};
}
function disableBrowserMagic(field) {
field.setAttribute("autocorrect", "off");
field.setAttribute("autocapitalize", "off");
field.setAttribute("spellcheck", "false");
}
// TEXTAREA INPUT STYLE
function TextareaInput(cm) {
this.cm = cm;
// See input.poll and input.reset
this.prevInput = "";
// Flag that indicates whether we expect input to appear real soon
// now (after some event like 'keypress' or 'input') and are
// polling intensively.
this.pollingFast = false;
// Self-resetting timeout for the poller
this.polling = new Delayed();
// Tracks when input.reset has punted to just putting a short
// string into the textarea instead of the full selection.
this.inaccurateSelection = false;
// Used to work around IE issue with selection being forgotten when focus moves away from textarea
this.hasSelection = false;
this.composing = null;
};
function hiddenTextarea() {
var te = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none");
var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
// The textarea is kept positioned near the cursor to prevent the
// fact that it'll be scrolled into view on input from scrolling
// our fake cursor out of view. On webkit, when wrap=off, paste is
// very slow. So make the area wide instead.
if (webkit) te.style.width = "1000px";
else te.setAttribute("wrap", "off");
// If border: 0; -- iOS fails to open keyboard (issue #1287)
if (ios) te.style.border = "1px solid black";
disableBrowserMagic(te);
return div;
}
TextareaInput.prototype = copyObj({
init: function(display) {
var input = this, cm = this.cm;
// Wraps and hides input textarea
var div = this.wrapper = hiddenTextarea();
// The semihidden textarea that is focused when the editor is
// focused, and receives input.
var te = this.textarea = div.firstChild;
display.wrapper.insertBefore(div, display.wrapper.firstChild);
// Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
if (ios) te.style.width = "0px";
on(te, "input", function() {
if (ie && ie_version >= 9 && input.hasSelection) input.hasSelection = null;
input.poll();
});
on(te, "paste", function(e) {
if (signalDOMEvent(cm, e) || handlePaste(e, cm)) return
cm.state.pasteIncoming = true;
input.fastPoll();
});
function prepareCopyCut(e) {
if (signalDOMEvent(cm, e)) return
if (cm.somethingSelected()) {
lastCopied = cm.getSelections();
if (input.inaccurateSelection) {
input.prevInput = "";
input.inaccurateSelection = false;
te.value = lastCopied.join("\n");
selectInput(te);
}
} else if (!cm.options.lineWiseCopyCut) {
return;
} else {
var ranges = copyableRanges(cm);
lastCopied = ranges.text;
if (e.type == "cut") {
cm.setSelections(ranges.ranges, null, sel_dontScroll);
} else {
input.prevInput = "";
te.value = ranges.text.join("\n");
selectInput(te);
}
}
if (e.type == "cut") cm.state.cutIncoming = true;
}
on(te, "cut", prepareCopyCut);
on(te, "copy", prepareCopyCut);
on(display.scroller, "paste", function(e) {
if (eventInWidget(display, e) || signalDOMEvent(cm, e)) return;
cm.state.pasteIncoming = true;
input.focus();
});
// Prevent normal selection in the editor (we handle our own)
on(display.lineSpace, "selectstart", function(e) {
if (!eventInWidget(display, e)) e_preventDefault(e);
});
on(te, "compositionstart", function() {
var start = cm.getCursor("from");
if (input.composing) input.composing.range.clear()
input.composing = {
start: start,
range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
};
});
on(te, "compositionend", function() {
if (input.composing) {
input.poll();
input.composing.range.clear();
input.composing = null;
}
});
},
prepareSelection: function() {
// Redraw the selection and/or cursor
var cm = this.cm, display = cm.display, doc = cm.doc;
var result = prepareSelection(cm);
// Move the hidden textarea near the cursor to prevent scrolling artifacts
if (cm.options.moveInputWithCursor) {
var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
headPos.top + lineOff.top - wrapOff.top));
result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
headPos.left + lineOff.left - wrapOff.left));
}
return result;
},
showSelection: function(drawn) {
var cm = this.cm, display = cm.display;
removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
removeChildrenAndAdd(display.selectionDiv, drawn.selection);
if (drawn.teTop != null) {
this.wrapper.style.top = drawn.teTop + "px";
this.wrapper.style.left = drawn.teLeft + "px";
}
},
// Reset the input to correspond to the selection (or to be empty,
// when not typing and nothing is selected)
reset: function(typing) {
if (this.contextMenuPending) return;
var minimal, selected, cm = this.cm, doc = cm.doc;
if (cm.somethingSelected()) {
this.prevInput = "";
var range = doc.sel.primary();
minimal = hasCopyEvent &&
(range.to().line - range.from().line > 100 || (selected = cm.getSelection()).length > 1000);
var content = minimal ? "-" : selected || cm.getSelection();
this.textarea.value = content;
if (cm.state.focused) selectInput(this.textarea);
if (ie && ie_version >= 9) this.hasSelection = content;
} else if (!typing) {
this.prevInput = this.textarea.value = "";
if (ie && ie_version >= 9) this.hasSelection = null;
}
this.inaccurateSelection = minimal;
},
getField: function() { return this.textarea; },
supportsTouch: function() { return false; },
focus: function() {
if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
try { this.textarea.focus(); }
catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
}
},
blur: function() { this.textarea.blur(); },
resetPosition: function() {
this.wrapper.style.top = this.wrapper.style.left = 0;
},
receivedFocus: function() { this.slowPoll(); },
// Poll for input changes, using the normal rate of polling. This
// runs as long as the editor is focused.
slowPoll: function() {
var input = this;
if (input.pollingFast) return;
input.polling.set(this.cm.options.pollInterval, function() {
input.poll();
if (input.cm.state.focused) input.slowPoll();
});
},
// When an event has just come in that is likely to add or change
// something in the input textarea, we poll faster, to ensure that
// the change appears on the screen quickly.
fastPoll: function() {
var missed = false, input = this;
input.pollingFast = true;
function p() {
var changed = input.poll();
if (!changed && !missed) {missed = true; input.polling.set(60, p);}
else {input.pollingFast = false; input.slowPoll();}
}
input.polling.set(20, p);
},
// Read input from the textarea, and update the document to match.
// When something is selected, it is present in the textarea, and
// selected (unless it is huge, in which case a placeholder is
// used). When nothing is selected, the cursor sits after previously
// seen text (can be empty), which is stored in prevInput (we must
// not reset the textarea when typing, because that breaks IME).
poll: function() {
var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
// Since this is called a *lot*, try to bail out as cheaply as
// possible when it is clear that nothing happened. hasSelection
// will be the case when there is a lot of text in the textarea,
// in which case reading its value would be expensive.
if (this.contextMenuPending || !cm.state.focused ||
(hasSelection(input) && !prevInput && !this.composing) ||
cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
return false;
var text = input.value;
// If nothing changed, bail.
if (text == prevInput && !cm.somethingSelected()) return false;
// Work around nonsensical selection resetting in IE9/10, and
// inexplicable appearance of private area unicode characters on
// some key combos in Mac (#2689).
if (ie && ie_version >= 9 && this.hasSelection === text ||
mac && /[\uf700-\uf7ff]/.test(text)) {
cm.display.input.reset();
return false;
}
if (cm.doc.sel == cm.display.selForContextMenu) {
var first = text.charCodeAt(0);
if (first == 0x200b && !prevInput) prevInput = "\u200b";
if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo"); }
}
// Find the part of the input that is actually new
var same = 0, l = Math.min(prevInput.length, text.length);
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
var self = this;
runInOp(cm, function() {
applyTextInput(cm, text.slice(same), prevInput.length - same,
null, self.composing ? "*compose" : null);
// Don't leave long text in the textarea, since it makes further polling slow
if (text.length > 1000 || text.indexOf("\n") > -1) input.value = self.prevInput = "";
else self.prevInput = text;
if (self.composing) {
self.composing.range.clear();
self.composing.range = cm.markText(self.composing.start, cm.getCursor("to"),
{className: "CodeMirror-composing"});
}
});
return true;
},
ensurePolled: function() {
if (this.pollingFast && this.poll()) this.pollingFast = false;
},
onKeyPress: function() {
if (ie && ie_version >= 9) this.hasSelection = null;
this.fastPoll();
},
onContextMenu: function(e) {
var input = this, cm = input.cm, display = cm.display, te = input.textarea;
var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
if (!pos || presto) return; // Opera is difficult.
// Reset the current text selection only if the click is done outside of the selection
// and 'resetSelectionOnContextMenu' option is true.
var reset = cm.options.resetSelectionOnContextMenu;
if (reset && cm.doc.sel.contains(pos) == -1)
operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll);
var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText;
input.wrapper.style.cssText = "position: absolute"
var wrapperBox = input.wrapper.getBoundingClientRect()
te.style.cssText = "position: absolute; width: 30px; height: 30px; top: " + (e.clientY - wrapperBox.top - 5) +
"px; left: " + (e.clientX - wrapperBox.left - 5) + "px; z-index: 1000; background: " +
(ie ? "rgba(255, 255, 255, .05)" : "transparent") +
"; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
if (webkit) var oldScrollY = window.scrollY; // Work around Chrome issue (#2712)
display.input.focus();
if (webkit) window.scrollTo(null, oldScrollY);
display.input.reset();
// Adds "Select all" to context menu in FF
if (!cm.somethingSelected()) te.value = input.prevInput = " ";
input.contextMenuPending = true;
display.selForContextMenu = cm.doc.sel;
clearTimeout(display.detectingSelectAll);
// Select-all will be greyed out if there's nothing to select, so
// this adds a zero-width space so that we can later check whether
// it got selected.
function prepareSelectAllHack() {
if (te.selectionStart != null) {
var selected = cm.somethingSelected();
var extval = "\u200b" + (selected ? te.value : "");
te.value = "\u21da"; // Used to catch context-menu undo
te.value = extval;
input.prevInput = selected ? "" : "\u200b";
te.selectionStart = 1; te.selectionEnd = extval.length;
// Re-set this, in case some other handler touched the
// selection in the meantime.
display.selForContextMenu = cm.doc.sel;
}
}
function rehide() {
input.contextMenuPending = false;
input.wrapper.style.cssText = oldWrapperCSS
te.style.cssText = oldCSS;
if (ie && ie_version < 9) display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos);
// Try to detect the user choosing select-all
if (te.selectionStart != null) {
if (!ie || (ie && ie_version < 9)) prepareSelectAllHack();
var i = 0, poll = function() {
if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
te.selectionEnd > 0 && input.prevInput == "\u200b")
operation(cm, commands.selectAll)(cm);
else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500);
else display.input.reset();
};
display.detectingSelectAll = setTimeout(poll, 200);
}
}
if (ie && ie_version >= 9) prepareSelectAllHack();
if (captureRightClick) {
e_stop(e);
var mouseup = function() {
off(window, "mouseup", mouseup);
setTimeout(rehide, 20);
};
on(window, "mouseup", mouseup);
} else {
setTimeout(rehide, 50);
}
},
readOnlyChanged: function(val) {
if (!val) this.reset();
},
setUneditable: nothing,
needsContentAttribute: false
}, TextareaInput.prototype);
// CONTENTEDITABLE INPUT STYLE
function ContentEditableInput(cm) {
this.cm = cm;
this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
this.polling = new Delayed();
this.gracePeriod = false;
}
ContentEditableInput.prototype = copyObj({
init: function(display) {
var input = this, cm = input.cm;
var div = input.div = display.lineDiv;
disableBrowserMagic(div);
on(div, "paste", function(e) {
if (!signalDOMEvent(cm, e)) handlePaste(e, cm);
})
on(div, "compositionstart", function(e) {
var data = e.data;
input.composing = {sel: cm.doc.sel, data: data, startData: data};
if (!data) return;
var prim = cm.doc.sel.primary();
var line = cm.getLine(prim.head.line);
var found = line.indexOf(data, Math.max(0, prim.head.ch - data.length));
if (found > -1 && found <= prim.head.ch)
input.composing.sel = simpleSelection(Pos(prim.head.line, found),
Pos(prim.head.line, found + data.length));
});
on(div, "compositionupdate", function(e) {
input.composing.data = e.data;
});
on(div, "compositionend", function(e) {
var ours = input.composing;
if (!ours) return;
if (e.data != ours.startData && !/\u200b/.test(e.data))
ours.data = e.data;
// Need a small delay to prevent other code (input event,
// selection polling) from doing damage when fired right after
// compositionend.
setTimeout(function() {
if (!ours.handled)
input.applyComposition(ours);
if (input.composing == ours)
input.composing = null;
}, 50);
});
on(div, "touchstart", function() {
input.forceCompositionEnd();
});
on(div, "input", function() {
if (input.composing) return;
if (cm.isReadOnly() || !input.pollContent())
runInOp(input.cm, function() {regChange(cm);});
});
function onCopyCut(e) {
if (signalDOMEvent(cm, e)) return
if (cm.somethingSelected()) {
lastCopied = cm.getSelections();
if (e.type == "cut") cm.replaceSelection("", null, "cut");
} else if (!cm.options.lineWiseCopyCut) {
return;
} else {
var ranges = copyableRanges(cm);
lastCopied = ranges.text;
if (e.type == "cut") {
cm.operation(function() {
cm.setSelections(ranges.ranges, 0, sel_dontScroll);
cm.replaceSelection("", null, "cut");
});
}
}
// iOS exposes the clipboard API, but seems to discard content inserted into it
if (e.clipboardData && !ios) {
e.preventDefault();
e.clipboardData.clearData();
e.clipboardData.setData("text/plain", lastCopied.join("\n"));
} else {
// Old-fashioned briefly-focus-a-textarea hack
var kludge = hiddenTextarea(), te = kludge.firstChild;
cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
te.value = lastCopied.join("\n");
var hadFocus = document.activeElement;
selectInput(te);
setTimeout(function() {
cm.display.lineSpace.removeChild(kludge);
hadFocus.focus();
}, 50);
}
}
on(div, "copy", onCopyCut);
on(div, "cut", onCopyCut);
},
prepareSelection: function() {
var result = prepareSelection(this.cm, false);
result.focus = this.cm.state.focused;
return result;
},
showSelection: function(info) {
if (!info || !this.cm.display.view.length) return;
if (info.focus) this.showPrimarySelection();
this.showMultipleSelections(info);
},
showPrimarySelection: function() {
var sel = window.getSelection(), prim = this.cm.doc.sel.primary();
var curAnchor = domToPos(this.cm, sel.anchorNode, sel.anchorOffset);
var curFocus = domToPos(this.cm, sel.focusNode, sel.focusOffset);
if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
cmp(minPos(curAnchor, curFocus), prim.from()) == 0 &&
cmp(maxPos(curAnchor, curFocus), prim.to()) == 0)
return;
var start = posToDOM(this.cm, prim.from());
var end = posToDOM(this.cm, prim.to());
if (!start && !end) return;
var view = this.cm.display.view;
var old = sel.rangeCount && sel.getRangeAt(0);
if (!start) {
start = {node: view[0].measure.map[2], offset: 0};
} else if (!end) { // FIXME dangerously hacky
var measure = view[view.length - 1].measure;
var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]};
}
try { var rng = range(start.node, start.offset, end.offset, end.node); }
catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
if (rng) {
if (!gecko && this.cm.state.focused) {
sel.collapse(start.node, start.offset);
if (!rng.collapsed) sel.addRange(rng);
} else {
sel.removeAllRanges();
sel.addRange(rng);
}
if (old && sel.anchorNode == null) sel.addRange(old);
else if (gecko) this.startGracePeriod();
}
this.rememberSelection();
},
startGracePeriod: function() {
var input = this;
clearTimeout(this.gracePeriod);
this.gracePeriod = setTimeout(function() {
input.gracePeriod = false;
if (input.selectionChanged())
input.cm.operation(function() { input.cm.curOp.selectionChanged = true; });
}, 20);
},
showMultipleSelections: function(info) {
removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
},
rememberSelection: function() {
var sel = window.getSelection();
this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset;
this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset;
},
selectionInEditor: function() {
var sel = window.getSelection();
if (!sel.rangeCount) return false;
var node = sel.getRangeAt(0).commonAncestorContainer;
return contains(this.div, node);
},
focus: function() {
if (this.cm.options.readOnly != "nocursor") this.div.focus();
},
blur: function() { this.div.blur(); },
getField: function() { return this.div; },
supportsTouch: function() { return true; },
receivedFocus: function() {
var input = this;
if (this.selectionInEditor())
this.pollSelection();
else
runInOp(this.cm, function() { input.cm.curOp.selectionChanged = true; });
function poll() {
if (input.cm.state.focused) {
input.pollSelection();
input.polling.set(input.cm.options.pollInterval, poll);
}
}
this.polling.set(this.cm.options.pollInterval, poll);
},
selectionChanged: function() {
var sel = window.getSelection();
return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset;
},
pollSelection: function() {
if (!this.composing && !this.gracePeriod && this.selectionChanged()) {
var sel = window.getSelection(), cm = this.cm;
this.rememberSelection();
var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
var head = domToPos(cm, sel.focusNode, sel.focusOffset);
if (anchor && head) runInOp(cm, function() {
setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
if (anchor.bad || head.bad) cm.curOp.selectionChanged = true;
});
}
},
pollContent: function() {
var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
var from = sel.from(), to = sel.to();
if (from.line < display.viewFrom || to.line > display.viewTo - 1) return false;
var fromIndex;
if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
var fromLine = lineNo(display.view[0].line);
var fromNode = display.view[0].node;
} else {
var fromLine = lineNo(display.view[fromIndex].line);
var fromNode = display.view[fromIndex - 1].node.nextSibling;
}
var toIndex = findViewIndex(cm, to.line);
if (toIndex == display.view.length - 1) {
var toLine = display.viewTo - 1;
var toNode = display.lineDiv.lastChild;
} else {
var toLine = lineNo(display.view[toIndex + 1].line) - 1;
var toNode = display.view[toIndex + 1].node.previousSibling;
}
var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
while (newText.length > 1 && oldText.length > 1) {
if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; }
else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; }
else break;
}
var cutFront = 0, cutEnd = 0;
var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
++cutFront;
var newBot = lst(newText), oldBot = lst(oldText);
var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
oldBot.length - (oldText.length == 1 ? cutFront : 0));
while (cutEnd < maxCutEnd &&
newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
++cutEnd;
newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd);
newText[0] = newText[0].slice(cutFront);
var chFrom = Pos(fromLine, cutFront);
var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
replaceRange(cm.doc, newText, chFrom, chTo, "+input");
return true;
}
},
ensurePolled: function() {
this.forceCompositionEnd();
},
reset: function() {
this.forceCompositionEnd();
},
forceCompositionEnd: function() {
if (!this.composing || this.composing.handled) return;
this.applyComposition(this.composing);
this.composing.handled = true;
this.div.blur();
this.div.focus();
},
applyComposition: function(composing) {
if (this.cm.isReadOnly())
operation(this.cm, regChange)(this.cm)
else if (composing.data && composing.data != composing.startData)
operation(this.cm, applyTextInput)(this.cm, composing.data, 0, composing.sel);
},
setUneditable: function(node) {
node.contentEditable = "false"
},
onKeyPress: function(e) {
e.preventDefault();
if (!this.cm.isReadOnly())
operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
},
readOnlyChanged: function(val) {
this.div.contentEditable = String(val != "nocursor")
},
onContextMenu: nothing,
resetPosition: nothing,
needsContentAttribute: true
}, ContentEditableInput.prototype);
function posToDOM(cm, pos) {
var view = findViewForLine(cm, pos.line);
if (!view || view.hidden) return null;
var line = getLine(cm.doc, pos.line);
var info = mapFromLineView(view, line, pos.line);
var order = getOrder(line), side = "left";
if (order) {
var partPos = getBidiPartAt(order, pos.ch);
side = partPos % 2 ? "right" : "left";
}
var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
result.offset = result.collapse == "right" ? result.end : result.start;
return result;
}
function badPos(pos, bad) { if (bad) pos.bad = true; return pos; }
function domToPos(cm, node, offset) {
var lineNode;
if (node == cm.display.lineDiv) {
lineNode = cm.display.lineDiv.childNodes[offset];
if (!lineNode) return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true);
node = null; offset = 0;
} else {
for (lineNode = node;; lineNode = lineNode.parentNode) {
if (!lineNode || lineNode == cm.display.lineDiv) return null;
if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) break;
}
}
for (var i = 0; i < cm.display.view.length; i++) {
var lineView = cm.display.view[i];
if (lineView.node == lineNode)
return locateNodeInLineView(lineView, node, offset);
}
}
function locateNodeInLineView(lineView, node, offset) {
var wrapper = lineView.text.firstChild, bad = false;
if (!node || !contains(wrapper, node)) return badPos(Pos(lineNo(lineView.line), 0), true);
if (node == wrapper) {
bad = true;
node = wrapper.childNodes[offset];
offset = 0;
if (!node) {
var line = lineView.rest ? lst(lineView.rest) : lineView.line;
return badPos(Pos(lineNo(line), line.text.length), bad);
}
}
var textNode = node.nodeType == 3 ? node : null, topNode = node;
if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
textNode = node.firstChild;
if (offset) offset = textNode.nodeValue.length;
}
while (topNode.parentNode != wrapper) topNode = topNode.parentNode;
var measure = lineView.measure, maps = measure.maps;
function find(textNode, topNode, offset) {
for (var i = -1; i < (maps ? maps.length : 0); i++) {
var map = i < 0 ? measure.map : maps[i];
for (var j = 0; j < map.length; j += 3) {
var curNode = map[j + 2];
if (curNode == textNode || curNode == topNode) {
var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
var ch = map[j] + offset;
if (offset < 0 || curNode != textNode) ch = map[j + (offset ? 1 : 0)];
return Pos(line, ch);
}
}
}
}
var found = find(textNode, topNode, offset);
if (found) return badPos(found, bad);
// FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
found = find(after, after.firstChild, 0);
if (found)
return badPos(Pos(found.line, found.ch - dist), bad);
else
dist += after.textContent.length;
}
for (var before = topNode.previousSibling, dist = offset; before; before = before.previousSibling) {
found = find(before, before.firstChild, -1);
if (found)
return badPos(Pos(found.line, found.ch + dist), bad);
else
dist += after.textContent.length;
}
}
function domTextBetween(cm, from, to, fromLine, toLine) {
var text = "", closing = false, lineSep = cm.doc.lineSeparator();
function recognizeMarker(id) { return function(marker) { return marker.id == id; }; }
function walk(node) {
if (node.nodeType == 1) {
var cmText = node.getAttribute("cm-text");
if (cmText != null) {
if (cmText == "") cmText = node.textContent.replace(/\u200b/g, "");
text += cmText;
return;
}
var markerID = node.getAttribute("cm-marker"), range;
if (markerID) {
var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
if (found.length && (range = found[0].find()))
text += getBetween(cm.doc, range.from, range.to).join(lineSep);
return;
}
if (node.getAttribute("contenteditable") == "false") return;
for (var i = 0; i < node.childNodes.length; i++)
walk(node.childNodes[i]);
if (/^(pre|div|p)$/i.test(node.nodeName))
closing = true;
} else if (node.nodeType == 3) {
var val = node.nodeValue;
if (!val) return;
if (closing) {
text += lineSep;
closing = false;
}
text += val;
}
}
for (;;) {
walk(from);
if (from == to) break;
from = from.nextSibling;
}
return text;
}
CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
// SELECTION / CURSOR
// Selection objects are immutable. A new one is created every time
// the selection changes. A selection is one or more non-overlapping
// (and non-touching) ranges, sorted, and an integer that indicates
// which one is the primary selection (the one that's scrolled into
// view, that getCursor returns, etc).
function Selection(ranges, primIndex) {
this.ranges = ranges;
this.primIndex = primIndex;
}
Selection.prototype = {
primary: function() { return this.ranges[this.primIndex]; },
equals: function(other) {
if (other == this) return true;
if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) return false;
for (var i = 0; i < this.ranges.length; i++) {
var here = this.ranges[i], there = other.ranges[i];
if (cmp(here.anchor, there.anchor) != 0 || cmp(here.head, there.head) != 0) return false;
}
return true;
},
deepCopy: function() {
for (var out = [], i = 0; i < this.ranges.length; i++)
out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head));
return new Selection(out, this.primIndex);
},
somethingSelected: function() {
for (var i = 0; i < this.ranges.length; i++)
if (!this.ranges[i].empty()) return true;
return false;
},
contains: function(pos, end) {
if (!end) end = pos;
for (var i = 0; i < this.ranges.length; i++) {
var range = this.ranges[i];
if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
return i;
}
return -1;
}
};
function Range(anchor, head) {
this.anchor = anchor; this.head = head;
}
Range.prototype = {
from: function() { return minPos(this.anchor, this.head); },
to: function() { return maxPos(this.anchor, this.head); },
empty: function() {
return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
}
};
// Take an unsorted, potentially overlapping set of ranges, and
// build a selection out of it. 'Consumes' ranges array (modifying
// it).
function normalizeSelection(ranges, primIndex) {
var prim = ranges[primIndex];
ranges.sort(function(a, b) { return cmp(a.from(), b.from()); });
primIndex = indexOf(ranges, prim);
for (var i = 1; i < ranges.length; i++) {
var cur = ranges[i], prev = ranges[i - 1];
if (cmp(prev.to(), cur.from()) >= 0) {
var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
if (i <= primIndex) --primIndex;
ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
}
}
return new Selection(ranges, primIndex);
}
function simpleSelection(anchor, head) {
return new Selection([new Range(anchor, head || anchor)], 0);
}
// Most of the external API clips given positions to make sure they
// actually exist within the document.
function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));}
function clipPos(doc, pos) {
if (pos.line < doc.first) return Pos(doc.first, 0);
var last = doc.first + doc.size - 1;
if (pos.line > last) return Pos(last, getLine(doc, last).text.length);
return clipToLen(pos, getLine(doc, pos.line).text.length);
}
function clipToLen(pos, linelen) {
var ch = pos.ch;
if (ch == null || ch > linelen) return Pos(pos.line, linelen);
else if (ch < 0) return Pos(pos.line, 0);
else return pos;
}
function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size;}
function clipPosArray(doc, array) {
for (var out = [], i = 0; i < array.length; i++) out[i] = clipPos(doc, array[i]);
return out;
}
// SELECTION UPDATES
// The 'scroll' parameter given to many of these indicated whether
// the new cursor position should be scrolled into view after
// modifying the selection.
// If shift is held or the extend flag is set, extends a range to
// include a given position (and optionally a second position).
// Otherwise, simply returns the range between the given positions.
// Used for cursor motion and such.
function extendRange(doc, range, head, other) {
if (doc.cm && doc.cm.display.shift || doc.extend) {
var anchor = range.anchor;
if (other) {
var posBefore = cmp(head, anchor) < 0;
if (posBefore != (cmp(other, anchor) < 0)) {
anchor = head;
head = other;
} else if (posBefore != (cmp(head, other) < 0)) {
head = other;
}
}
return new Range(anchor, head);
} else {
return new Range(other || head, head);
}
}
// Extend the primary selection range, discard the rest.
function extendSelection(doc, head, other, options) {
setSelection(doc, new Selection([extendRange(doc, doc.sel.primary(), head, other)], 0), options);
}
// Extend all selections (pos is an array of selections with length
// equal the number of selections)
function extendSelections(doc, heads, options) {
for (var out = [], i = 0; i < doc.sel.ranges.length; i++)
out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null);
var newSel = normalizeSelection(out, doc.sel.primIndex);
setSelection(doc, newSel, options);
}
// Updates a single range in the selection.
function replaceOneSelection(doc, i, range, options) {
var ranges = doc.sel.ranges.slice(0);
ranges[i] = range;
setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options);
}
// Reset the selection to a single range.
function setSimpleSelection(doc, anchor, head, options) {
setSelection(doc, simpleSelection(anchor, head), options);
}
// Give beforeSelectionChange handlers a change to influence a
// selection update.
function filterSelectionChange(doc, sel, options) {
var obj = {
ranges: sel.ranges,
update: function(ranges) {
this.ranges = [];
for (var i = 0; i < ranges.length; i++)
this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
clipPos(doc, ranges[i].head));
},
origin: options && options.origin
};
signal(doc, "beforeSelectionChange", doc, obj);
if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj);
if (obj.ranges != sel.ranges) return normalizeSelection(obj.ranges, obj.ranges.length - 1);
else return sel;
}
function setSelectionReplaceHistory(doc, sel, options) {
var done = doc.history.done, last = lst(done);
if (last && last.ranges) {
done[done.length - 1] = sel;
setSelectionNoUndo(doc, sel, options);
} else {
setSelection(doc, sel, options);
}
}
// Set a new selection.
function setSelection(doc, sel, options) {
setSelectionNoUndo(doc, sel, options);
addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
}
function setSelectionNoUndo(doc, sel, options) {
if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
sel = filterSelectionChange(doc, sel, options);
var bias = options && options.bias ||
(cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
if (!(options && options.scroll === false) && doc.cm)
ensureCursorVisible(doc.cm);
}
function setSelectionInner(doc, sel) {
if (sel.equals(doc.sel)) return;
doc.sel = sel;
if (doc.cm) {
doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true;
signalCursorActivity(doc.cm);
}
signalLater(doc, "cursorActivity", doc);
}
// Verify that the selection does not partially select any atomic
// marked ranges.
function reCheckSelection(doc) {
setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false), sel_dontScroll);
}
// Return a selection that does not partially select any atomic
// ranges.
function skipAtomicInSelection(doc, sel, bias, mayClear) {
var out;
for (var i = 0; i < sel.ranges.length; i++) {
var range = sel.ranges[i];
var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i];
var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear);
var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear);
if (out || newAnchor != range.anchor || newHead != range.head) {
if (!out) out = sel.ranges.slice(0, i);
out[i] = new Range(newAnchor, newHead);
}
}
return out ? normalizeSelection(out, sel.primIndex) : sel;
}
function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
var line = getLine(doc, pos.line);
if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
var sp = line.markedSpans[i], m = sp.marker;
if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
(sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
if (mayClear) {
signal(m, "beforeCursorEnter");
if (m.explicitlyCleared) {
if (!line.markedSpans) break;
else {--i; continue;}
}
}
if (!m.atomic) continue;
if (oldPos) {
var near = m.find(dir < 0 ? 1 : -1), diff;
if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft)
near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null);
if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
return skipAtomicInner(doc, near, pos, dir, mayClear);
}
var far = m.find(dir < 0 ? -1 : 1);
if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight)
far = movePos(doc, far, dir, far.line == pos.line ? line : null);
return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null;
}
}
return pos;
}
// Ensure a given position is not inside an atomic range.
function skipAtomic(doc, pos, oldPos, bias, mayClear) {
var dir = bias || 1;
var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
(!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
(!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true));
if (!found) {
doc.cantEdit = true;
return Pos(doc.first, 0);
}
return found;
}
function movePos(doc, pos, dir, line) {
if (dir < 0 && pos.ch == 0) {
if (pos.line > doc.first) return clipPos(doc, Pos(pos.line - 1));
else return null;
} else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
if (pos.line < doc.first + doc.size - 1) return Pos(pos.line + 1, 0);
else return null;
} else {
return new Pos(pos.line, pos.ch + dir);
}
}
// SELECTION DRAWING
function updateSelection(cm) {
cm.display.input.showSelection(cm.display.input.prepareSelection());
}
function prepareSelection(cm, primary) {
var doc = cm.doc, result = {};
var curFragment = result.cursors = document.createDocumentFragment();
var selFragment = result.selection = document.createDocumentFragment();
for (var i = 0; i < doc.sel.ranges.length; i++) {
if (primary === false && i == doc.sel.primIndex) continue;
var range = doc.sel.ranges[i];
if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) continue;
var collapsed = range.empty();
if (collapsed || cm.options.showCursorWhenSelecting)
drawSelectionCursor(cm, range.head, curFragment);
if (!collapsed)
drawSelectionRange(cm, range, selFragment);
}
return result;
}
// Draws a cursor for the given range
function drawSelectionCursor(cm, head, output) {
var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);
var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
cursor.style.left = pos.left + "px";
cursor.style.top = pos.top + "px";
cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
if (pos.other) {
// Secondary cursor, shown when on a 'jump' in bi-directional text
var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
otherCursor.style.display = "";
otherCursor.style.left = pos.other.left + "px";
otherCursor.style.top = pos.other.top + "px";
otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
}
}
// Draws the given range as a highlighted selection
function drawSelectionRange(cm, range, output) {
var display = cm.display, doc = cm.doc;
var fragment = document.createDocumentFragment();
var padding = paddingH(cm.display), leftSide = padding.left;
var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
function add(left, top, width, bottom) {
if (top < 0) top = 0;
top = Math.round(top);
bottom = Math.round(bottom);
fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
"px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) +
"px; height: " + (bottom - top) + "px"));
}
function drawForLine(line, fromArg, toArg) {
var lineObj = getLine(doc, line);
var lineLen = lineObj.text.length;
var start, end;
function coords(ch, bias) {
return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
}
iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
var leftPos = coords(from, "left"), rightPos, left, right;
if (from == to) {
rightPos = leftPos;
left = right = leftPos.left;
} else {
rightPos = coords(to - 1, "right");
if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
left = leftPos.left;
right = rightPos.right;
}
if (fromArg == null && from == 0) left = leftSide;
if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
add(left, leftPos.top, null, leftPos.bottom);
left = leftSide;
if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
}
if (toArg == null && to == lineLen) right = rightSide;
if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
start = leftPos;
if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
end = rightPos;
if (left < leftSide + 1) left = leftSide;
add(left, rightPos.top, right - left, rightPos.bottom);
});
return {start: start, end: end};
}
var sFrom = range.from(), sTo = range.to();
if (sFrom.line == sTo.line) {
drawForLine(sFrom.line, sFrom.ch, sTo.ch);
} else {
var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
var singleVLine = visualLine(fromLine) == visualLine(toLine);
var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
if (singleVLine) {
if (leftEnd.top < rightStart.top - 2) {
add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
} else {
add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
}
}
if (leftEnd.bottom < rightStart.top)
add(leftSide, leftEnd.bottom, null, rightStart.top);
}
output.appendChild(fragment);
}
// Cursor-blinking
function restartBlink(cm) {
if (!cm.state.focused) return;
var display = cm.display;
clearInterval(display.blinker);
var on = true;
display.cursorDiv.style.visibility = "";
if (cm.options.cursorBlinkRate > 0)
display.blinker = setInterval(function() {
display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden";
}, cm.options.cursorBlinkRate);
else if (cm.options.cursorBlinkRate < 0)
display.cursorDiv.style.visibility = "hidden";
}
// HIGHLIGHT WORKER
function startWorker(cm, time) {
if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
cm.state.highlight.set(time, bind(highlightWorker, cm));
}
function highlightWorker(cm) {
var doc = cm.doc;
if (doc.frontier < doc.first) doc.frontier = doc.first;
if (doc.frontier >= cm.display.viewTo) return;
var end = +new Date + cm.options.workTime;
var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
var changedLines = [];
doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) {
if (doc.frontier >= cm.display.viewFrom) { // Visible
var oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength;
var highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true);
line.styles = highlighted.styles;
var oldCls = line.styleClasses, newCls = highlighted.classes;
if (newCls) line.styleClasses = newCls;
else if (oldCls) line.styleClasses = null;
var ischange = !oldStyles || oldStyles.length != line.styles.length ||
oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
if (ischange) changedLines.push(doc.frontier);
line.stateAfter = tooLong ? state : copyState(doc.mode, state);
} else {
if (line.text.length <= cm.options.maxHighlightLength)
processLine(cm, line.text, state);
line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
}
++doc.frontier;
if (+new Date > end) {
startWorker(cm, cm.options.workDelay);
return true;
}
});
if (changedLines.length) runInOp(cm, function() {
for (var i = 0; i < changedLines.length; i++)
regLineChange(cm, changedLines[i], "text");
});
}
// Finds the line to start with when starting a parse. Tries to
// find a line with a stateAfter, so that it can start with a
// valid state. If that fails, it returns the line with the
// smallest indentation, which tends to need the least context to
// parse correctly.
function findStartLine(cm, n, precise) {
var minindent, minline, doc = cm.doc;
var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
for (var search = n; search > lim; --search) {
if (search <= doc.first) return doc.first;
var line = getLine(doc, search - 1);
if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
var indented = countColumn(line.text, null, cm.options.tabSize);
if (minline == null || minindent > indented) {
minline = search - 1;
minindent = indented;
}
}
return minline;
}
function getStateBefore(cm, n, precise) {
var doc = cm.doc, display = cm.display;
if (!doc.mode.startState) return true;
var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
if (!state) state = startState(doc.mode);
else state = copyState(doc.mode, state);
doc.iter(pos, n, function(line) {
processLine(cm, line.text, state);
var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo;
line.stateAfter = save ? copyState(doc.mode, state) : null;
++pos;
});
if (precise) doc.frontier = pos;
return state;
}
// POSITION MEASUREMENT
function paddingTop(display) {return display.lineSpace.offsetTop;}
function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
function paddingH(display) {
if (display.cachedPaddingH) return display.cachedPaddingH;
var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
if (!isNaN(data.left) && !isNaN(data.right)) display.cachedPaddingH = data;
return data;
}
function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth; }
function displayWidth(cm) {
return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth;
}
function displayHeight(cm) {
return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight;
}
// Ensure the lineView.wrapping.heights array is populated. This is
// an array of bottom offsets for the lines that make up a drawn
// line. When lineWrapping is on, there might be more than one
// height.
function ensureLineHeights(cm, lineView, rect) {
var wrapping = cm.options.lineWrapping;
var curWidth = wrapping && displayWidth(cm);
if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
var heights = lineView.measure.heights = [];
if (wrapping) {
lineView.measure.width = curWidth;
var rects = lineView.text.firstChild.getClientRects();
for (var i = 0; i < rects.length - 1; i++) {
var cur = rects[i], next = rects[i + 1];
if (Math.abs(cur.bottom - next.bottom) > 2)
heights.push((cur.bottom + next.top) / 2 - rect.top);
}
}
heights.push(rect.bottom - rect.top);
}
}
// Find a line map (mapping character offsets to text nodes) and a
// measurement cache for the given line number. (A line view might
// contain multiple lines when collapsed ranges are present.)
function mapFromLineView(lineView, line, lineN) {
if (lineView.line == line)
return {map: lineView.measure.map, cache: lineView.measure.cache};
for (var i = 0; i < lineView.rest.length; i++)
if (lineView.rest[i] == line)
return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]};
for (var i = 0; i < lineView.rest.length; i++)
if (lineNo(lineView.rest[i]) > lineN)
return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i], before: true};
}
// Render a line into the hidden node display.externalMeasured. Used
// when measurement is needed for a line that's not in the viewport.
function updateExternalMeasurement(cm, line) {
line = visualLine(line);
var lineN = lineNo(line);
var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
view.lineN = lineN;
var built = view.built = buildLineContent(cm, view);
view.text = built.pre;
removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
return view;
}
// Get a {top, bottom, left, right} box (in line-local coordinates)
// for a given character.
function measureChar(cm, line, ch, bias) {
return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);
}
// Find a line view that corresponds to the given line number.
function findViewForLine(cm, lineN) {
if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
return cm.display.view[findViewIndex(cm, lineN)];
var ext = cm.display.externalMeasured;
if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
return ext;
}
// Measurement can be split in two steps, the set-up work that
// applies to the whole line, and the measurement of the actual
// character. Functions like coordsChar, that need to do a lot of
// measurements in a row, can thus ensure that the set-up work is
// only done once.
function prepareMeasureForLine(cm, line) {
var lineN = lineNo(line);
var view = findViewForLine(cm, lineN);
if (view && !view.text) {
view = null;
} else if (view && view.changes) {
updateLineForChanges(cm, view, lineN, getDimensions(cm));
cm.curOp.forceUpdate = true;
}
if (!view)
view = updateExternalMeasurement(cm, line);
var info = mapFromLineView(view, line, lineN);
return {
line: line, view: view, rect: null,
map: info.map, cache: info.cache, before: info.before,
hasHeights: false
};
}
// Given a prepared measurement object, measures the position of an
// actual character (or fetches it from the cache).
function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
if (prepared.before) ch = -1;
var key = ch + (bias || ""), found;
if (prepared.cache.hasOwnProperty(key)) {
found = prepared.cache[key];
} else {
if (!prepared.rect)
prepared.rect = prepared.view.text.getBoundingClientRect();
if (!prepared.hasHeights) {
ensureLineHeights(cm, prepared.view, prepared.rect);
prepared.hasHeights = true;
}
found = measureCharInner(cm, prepared, ch, bias);
if (!found.bogus) prepared.cache[key] = found;
}
return {left: found.left, right: found.right,
top: varHeight ? found.rtop : found.top,
bottom: varHeight ? found.rbottom : found.bottom};
}
var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
function nodeAndOffsetInLineMap(map, ch, bias) {
var node, start, end, collapse;
// First, search the line map for the text node corresponding to,
// or closest to, the target character.
for (var i = 0; i < map.length; i += 3) {
var mStart = map[i], mEnd = map[i + 1];
if (ch < mStart) {
start = 0; end = 1;
collapse = "left";
} else if (ch < mEnd) {
start = ch - mStart;
end = start + 1;
} else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
end = mEnd - mStart;
start = end - 1;
if (ch >= mEnd) collapse = "right";
}
if (start != null) {
node = map[i + 2];
if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
collapse = bias;
if (bias == "left" && start == 0)
while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
node = map[(i -= 3) + 2];
collapse = "left";
}
if (bias == "right" && start == mEnd - mStart)
while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
node = map[(i += 3) + 2];
collapse = "right";
}
break;
}
}
return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd};
}
function measureCharInner(cm, prepared, ch, bias) {
var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
var rect;
if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
for (var i = 0; i < 4; i++) { // Retry a maximum of 4 times when nonsense rectangles are returned
while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) --start;
while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) ++end;
if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) {
rect = node.parentNode.getBoundingClientRect();
} else if (ie && cm.options.lineWrapping) {
var rects = range(node, start, end).getClientRects();
if (rects.length)
rect = rects[bias == "right" ? rects.length - 1 : 0];
else
rect = nullRect;
} else {
rect = range(node, start, end).getBoundingClientRect() || nullRect;
}
if (rect.left || rect.right || start == 0) break;
end = start;
start = start - 1;
collapse = "right";
}
if (ie && ie_version < 11) rect = maybeUpdateRectForZooming(cm.display.measure, rect);
} else { // If it is a widget, simply get the box for the whole widget.
if (start > 0) collapse = bias = "right";
var rects;
if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
rect = rects[bias == "right" ? rects.length - 1 : 0];
else
rect = node.getBoundingClientRect();
}
if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
var rSpan = node.parentNode.getClientRects()[0];
if (rSpan)
rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom};
else
rect = nullRect;
}
var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
var mid = (rtop + rbot) / 2;
var heights = prepared.view.measure.heights;
for (var i = 0; i < heights.length - 1; i++)
if (mid < heights[i]) break;
var top = i ? heights[i - 1] : 0, bot = heights[i];
var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
top: top, bottom: bot};
if (!rect.left && !rect.right) result.bogus = true;
if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
return result;
}
// Work around problem with bounding client rects on ranges being
// returned incorrectly when zoomed on IE10 and below.
function maybeUpdateRectForZooming(measure, rect) {
if (!window.screen || screen.logicalXDPI == null ||
screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
return rect;
var scaleX = screen.logicalXDPI / screen.deviceXDPI;
var scaleY = screen.logicalYDPI / screen.deviceYDPI;
return {left: rect.left * scaleX, right: rect.right * scaleX,
top: rect.top * scaleY, bottom: rect.bottom * scaleY};
}
function clearLineMeasurementCacheFor(lineView) {
if (lineView.measure) {
lineView.measure.cache = {};
lineView.measure.heights = null;
if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
lineView.measure.caches[i] = {};
}
}
function clearLineMeasurementCache(cm) {
cm.display.externalMeasure = null;
removeChildren(cm.display.lineMeasure);
for (var i = 0; i < cm.display.view.length; i++)
clearLineMeasurementCacheFor(cm.display.view[i]);
}
function clearCaches(cm) {
clearLineMeasurementCache(cm);
cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
cm.display.lineNumChars = null;
}
function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft; }
function pageScrollY() { return window.pageYOffset || (document.documentElement || document.body).scrollTop; }
// Converts a {top, bottom, left, right} box from line-local
// coordinates into another coordinate system. Context may be one of
// "line", "div" (display.lineDiv), "local"/null (editor), "window",
// or "page".
function intoCoordSystem(cm, lineObj, rect, context) {
if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
var size = widgetHeight(lineObj.widgets[i]);
rect.top += size; rect.bottom += size;
}
if (context == "line") return rect;
if (!context) context = "local";
var yOff = heightAtLine(lineObj);
if (context == "local") yOff += paddingTop(cm.display);
else yOff -= cm.display.viewOffset;
if (context == "page" || context == "window") {
var lOff = cm.display.lineSpace.getBoundingClientRect();
yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
rect.left += xOff; rect.right += xOff;
}
rect.top += yOff; rect.bottom += yOff;
return rect;
}
// Coverts a box from "div" coords to another coordinate system.
// Context may be "window", "page", "div", or "local"/null.
function fromCoordSystem(cm, coords, context) {
if (context == "div") return coords;
var left = coords.left, top = coords.top;
// First move into "page" coordinate system
if (context == "page") {
left -= pageScrollX();
top -= pageScrollY();
} else if (context == "local" || !context) {
var localBox = cm.display.sizer.getBoundingClientRect();
left += localBox.left;
top += localBox.top;
}
var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top};
}
function charCoords(cm, pos, context, lineObj, bias) {
if (!lineObj) lineObj = getLine(cm.doc, pos.line);
return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context);
}
// Returns a box for a given cursor position, which may have an
// 'other' property containing the position of the secondary cursor
// on a bidi boundary.
function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
lineObj = lineObj || getLine(cm.doc, pos.line);
if (!preparedMeasure) preparedMeasure = prepareMeasureForLine(cm, lineObj);
function get(ch, right) {
var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
if (right) m.left = m.right; else m.right = m.left;
return intoCoordSystem(cm, lineObj, m, context);
}
function getBidi(ch, partPos) {
var part = order[partPos], right = part.level % 2;
if (ch == bidiLeft(part) && partPos && part.level < order[partPos - 1].level) {
part = order[--partPos];
ch = bidiRight(part) - (part.level % 2 ? 0 : 1);
right = true;
} else if (ch == bidiRight(part) && partPos < order.length - 1 && part.level < order[partPos + 1].level) {
part = order[++partPos];
ch = bidiLeft(part) - part.level % 2;
right = false;
}
if (right && ch == part.to && ch > part.from) return get(ch - 1);
return get(ch, right);
}
var order = getOrder(lineObj), ch = pos.ch;
if (!order) return get(ch);
var partPos = getBidiPartAt(order, ch);
var val = getBidi(ch, partPos);
if (bidiOther != null) val.other = getBidi(ch, bidiOther);
return val;
}
// Used to cheaply estimate the coordinates for a position. Used for
// intermediate scroll updates.
function estimateCoords(cm, pos) {
var left = 0, pos = clipPos(cm.doc, pos);
if (!cm.options.lineWrapping) left = charWidth(cm.display) * pos.ch;
var lineObj = getLine(cm.doc, pos.line);
var top = heightAtLine(lineObj) + paddingTop(cm.display);
return {left: left, right: left, top: top, bottom: top + lineObj.height};
}
// Positions returned by coordsChar contain some extra information.
// xRel is the relative x position of the input coordinates compared
// to the found position (so xRel > 0 means the coordinates are to
// the right of the character position, for example). When outside
// is true, that means the coordinates lie outside the line's
// vertical range.
function PosWithInfo(line, ch, outside, xRel) {
var pos = Pos(line, ch);
pos.xRel = xRel;
if (outside) pos.outside = true;
return pos;
}
// Compute the character position closest to the given coordinates.
// Input must be lineSpace-local ("div" coordinate system).
function coordsChar(cm, x, y) {
var doc = cm.doc;
y += cm.display.viewOffset;
if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
if (lineN > last)
return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
if (x < 0) x = 0;
var lineObj = getLine(doc, lineN);
for (;;) {
var found = coordsCharInner(cm, lineObj, lineN, x, y);
var merged = collapsedSpanAtEnd(lineObj);
var mergedPos = merged && merged.find(0, true);
if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
lineN = lineNo(lineObj = mergedPos.to.line);
else
return found;
}
}
function coordsCharInner(cm, lineObj, lineNo, x, y) {
var innerOff = y - heightAtLine(lineObj);
var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
var preparedMeasure = prepareMeasureForLine(cm, lineObj);
function getX(ch) {
var sp = cursorCoords(cm, Pos(lineNo, ch), "line", lineObj, preparedMeasure);
wrongLine = true;
if (innerOff > sp.bottom) return sp.left - adjust;
else if (innerOff < sp.top) return sp.left + adjust;
else wrongLine = false;
return sp.left;
}
var bidi = getOrder(lineObj), dist = lineObj.text.length;
var from = lineLeft(lineObj), to = lineRight(lineObj);
var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
// Do a binary search between these bounds.
for (;;) {
if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
var ch = x < fromX || x - fromX <= toX - x ? from : to;
var xDiff = x - (ch == from ? fromX : toX);
while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
return pos;
}
var step = Math.ceil(dist / 2), middle = from + step;
if (bidi) {
middle = from;
for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
}
var middleX = getX(middle);
if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
}
}
var measureText;
// Compute the default text height.
function textHeight(display) {
if (display.cachedTextHeight != null) return display.cachedTextHeight;
if (measureText == null) {
measureText = elt("pre");
// Measure a bunch of lines, for browsers that compute
// fractional heights.
for (var i = 0; i < 49; ++i) {
measureText.appendChild(document.createTextNode("x"));
measureText.appendChild(elt("br"));
}
measureText.appendChild(document.createTextNode("x"));
}
removeChildrenAndAdd(display.measure, measureText);
var height = measureText.offsetHeight / 50;
if (height > 3) display.cachedTextHeight = height;
removeChildren(display.measure);
return height || 1;
}
// Compute the default character width.
function charWidth(display) {
if (display.cachedCharWidth != null) return display.cachedCharWidth;
var anchor = elt("span", "xxxxxxxxxx");
var pre = elt("pre", [anchor]);
removeChildrenAndAdd(display.measure, pre);
var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
if (width > 2) display.cachedCharWidth = width;
return width || 10;
}
// OPERATIONS
// Operations are used to wrap a series of changes to the editor
// state in such a way that each change won't have to update the
// cursor and display (which would be awkward, slow, and
// error-prone). Instead, display updates are batched and then all
// combined and executed at once.
var operationGroup = null;
var nextOpId = 0;
// Start a new operation.
function startOperation(cm) {
cm.curOp = {
cm: cm,
viewChanged: false, // Flag that indicates that lines might need to be redrawn
startHeight: cm.doc.height, // Used to detect need to update scrollbar
forceUpdate: false, // Used to force a redraw
updateInput: null, // Whether to reset the input textarea
typing: false, // Whether this reset should be careful to leave existing text (for compositing)
changeObjs: null, // Accumulated changes, for firing change events
cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
selectionChanged: false, // Whether the selection needs to be redrawn
updateMaxLine: false, // Set when the widest line needs to be determined anew
scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
scrollToPos: null, // Used to scroll to a specific position
focus: false,
id: ++nextOpId // Unique ID
};
if (operationGroup) {
operationGroup.ops.push(cm.curOp);
} else {
cm.curOp.ownsGroup = operationGroup = {
ops: [cm.curOp],
delayedCallbacks: []
};
}
}
function fireCallbacksForOps(group) {
// Calls delayed callbacks and cursorActivity handlers until no
// new ones appear
var callbacks = group.delayedCallbacks, i = 0;
do {
for (; i < callbacks.length; i++)
callbacks[i].call(null);
for (var j = 0; j < group.ops.length; j++) {
var op = group.ops[j];
if (op.cursorActivityHandlers)
while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm);
}
} while (i < callbacks.length);
}
// Finish an operation, updating the display and signalling delayed events
function endOperation(cm) {
var op = cm.curOp, group = op.ownsGroup;
if (!group) return;
try { fireCallbacksForOps(group); }
finally {
operationGroup = null;
for (var i = 0; i < group.ops.length; i++)
group.ops[i].cm.curOp = null;
endOperations(group);
}
}
// The DOM updates done when an operation finishes are batched so
// that the minimum number of relayouts are required.
function endOperations(group) {
var ops = group.ops;
for (var i = 0; i < ops.length; i++) // Read DOM
endOperation_R1(ops[i]);
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
endOperation_W1(ops[i]);
for (var i = 0; i < ops.length; i++) // Read DOM
endOperation_R2(ops[i]);
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
endOperation_W2(ops[i]);
for (var i = 0; i < ops.length; i++) // Read DOM
endOperation_finish(ops[i]);
}
function endOperation_R1(op) {
var cm = op.cm, display = cm.display;
maybeClipScrollbars(cm);
if (op.updateMaxLine) findMaxLine(cm);
op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
op.scrollToPos.to.line >= display.viewTo) ||
display.maxLineChanged && cm.options.lineWrapping;
op.update = op.mustUpdate &&
new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
}
function endOperation_W1(op) {
op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
}
function endOperation_R2(op) {
var cm = op.cm, display = cm.display;
if (op.updatedDisplay) updateHeightsInViewport(cm);
op.barMeasure = measureForScrollbars(cm);
// If the max line changed since it was last measured, measure it,
// and ensure the document's width matches it.
// updateDisplay_W2 will use these properties to do the actual resizing
if (display.maxLineChanged && !cm.options.lineWrapping) {
op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
cm.display.sizerWidth = op.adjustWidthTo;
op.barMeasure.scrollWidth =
Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
}
if (op.updatedDisplay || op.selectionChanged)
op.preparedSelection = display.input.prepareSelection();
}
function endOperation_W2(op) {
var cm = op.cm;
if (op.adjustWidthTo != null) {
cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
if (op.maxScrollLeft < cm.doc.scrollLeft)
setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true);
cm.display.maxLineChanged = false;
}
if (op.preparedSelection)
cm.display.input.showSelection(op.preparedSelection);
if (op.updatedDisplay || op.startHeight != cm.doc.height)
updateScrollbars(cm, op.barMeasure);
if (op.updatedDisplay)
setDocumentHeight(cm, op.barMeasure);
if (op.selectionChanged) restartBlink(cm);
if (cm.state.focused && op.updateInput)
cm.display.input.reset(op.typing);
if (op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus()))
ensureFocus(op.cm);
}
function endOperation_finish(op) {
var cm = op.cm, display = cm.display, doc = cm.doc;
if (op.updatedDisplay) postUpdateDisplay(cm, op.update);
// Abort mouse wheel delta measurement, when scrolling explicitly
if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
display.wheelStartX = display.wheelStartY = null;
// Propagate the scroll position to the actual DOM scroller
if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop));
display.scrollbars.setScrollTop(doc.scrollTop);
display.scroller.scrollTop = doc.scrollTop;
}
if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft));
display.scrollbars.setScrollLeft(doc.scrollLeft);
display.scroller.scrollLeft = doc.scrollLeft;
alignHorizontally(cm);
}
// If we need to scroll a specific position into view, do so.
if (op.scrollToPos) {
var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
if (op.scrollToPos.isCursor && cm.state.focused) maybeScrollWindow(cm, coords);
}
// Fire events for markers that are hidden/unidden by editing or
// undoing
var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
if (hidden) for (var i = 0; i < hidden.length; ++i)
if (!hidden[i].lines.length) signal(hidden[i], "hide");
if (unhidden) for (var i = 0; i < unhidden.length; ++i)
if (unhidden[i].lines.length) signal(unhidden[i], "unhide");
if (display.wrapper.offsetHeight)
doc.scrollTop = cm.display.scroller.scrollTop;
// Fire change events, and delayed event handlers
if (op.changeObjs)
signal(cm, "changes", cm, op.changeObjs);
if (op.update)
op.update.finish();
}
// Run the given function in an operation
function runInOp(cm, f) {
if (cm.curOp) return f();
startOperation(cm);
try { return f(); }
finally { endOperation(cm); }
}
// Wraps a function in an operation. Returns the wrapped function.
function operation(cm, f) {
return function() {
if (cm.curOp) return f.apply(cm, arguments);
startOperation(cm);
try { return f.apply(cm, arguments); }
finally { endOperation(cm); }
};
}
// Used to add methods to editor and doc instances, wrapping them in
// operations.
function methodOp(f) {
return function() {
if (this.curOp) return f.apply(this, arguments);
startOperation(this);
try { return f.apply(this, arguments); }
finally { endOperation(this); }
};
}
function docMethodOp(f) {
return function() {
var cm = this.cm;
if (!cm || cm.curOp) return f.apply(this, arguments);
startOperation(cm);
try { return f.apply(this, arguments); }
finally { endOperation(cm); }
};
}
// VIEW TRACKING
// These objects are used to represent the visible (currently drawn)
// part of the document. A LineView may correspond to multiple
// logical lines, if those are connected by collapsed ranges.
function LineView(doc, line, lineN) {
// The starting line
this.line = line;
// Continuing lines, if any
this.rest = visualLineContinued(line);
// Number of logical lines in this visual line
this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
this.node = this.text = null;
this.hidden = lineIsHidden(doc, line);
}
// Create a range of LineView objects for the given lines.
function buildViewArray(cm, from, to) {
var array = [], nextPos;
for (var pos = from; pos < to; pos = nextPos) {
var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
nextPos = pos + view.size;
array.push(view);
}
return array;
}
// Updates the display.view data structure for a given change to the
// document. From and to are in pre-change coordinates. Lendiff is
// the amount of lines added or subtracted by the change. This is
// used for changes that span multiple lines, or change the way
// lines are divided into visual lines. regLineChange (below)
// registers single-line changes.
function regChange(cm, from, to, lendiff) {
if (from == null) from = cm.doc.first;
if (to == null) to = cm.doc.first + cm.doc.size;
if (!lendiff) lendiff = 0;
var display = cm.display;
if (lendiff && to < display.viewTo &&
(display.updateLineNumbers == null || display.updateLineNumbers > from))
display.updateLineNumbers = from;
cm.curOp.viewChanged = true;
if (from >= display.viewTo) { // Change after
if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
resetView(cm);
} else if (to <= display.viewFrom) { // Change before
if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
resetView(cm);
} else {
display.viewFrom += lendiff;
display.viewTo += lendiff;
}
} else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
resetView(cm);
} else if (from <= display.viewFrom) { // Top overlap
var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
if (cut) {
display.view = display.view.slice(cut.index);
display.viewFrom = cut.lineN;
display.viewTo += lendiff;
} else {
resetView(cm);
}
} else if (to >= display.viewTo) { // Bottom overlap
var cut = viewCuttingPoint(cm, from, from, -1);
if (cut) {
display.view = display.view.slice(0, cut.index);
display.viewTo = cut.lineN;
} else {
resetView(cm);
}
} else { // Gap in the middle
var cutTop = viewCuttingPoint(cm, from, from, -1);
var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
if (cutTop && cutBot) {
display.view = display.view.slice(0, cutTop.index)
.concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
.concat(display.view.slice(cutBot.index));
display.viewTo += lendiff;
} else {
resetView(cm);
}
}
var ext = display.externalMeasured;
if (ext) {
if (to < ext.lineN)
ext.lineN += lendiff;
else if (from < ext.lineN + ext.size)
display.externalMeasured = null;
}
}
// Register a change to a single line. Type must be one of "text",
// "gutter", "class", "widget"
function regLineChange(cm, line, type) {
cm.curOp.viewChanged = true;
var display = cm.display, ext = cm.display.externalMeasured;
if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
display.externalMeasured = null;
if (line < display.viewFrom || line >= display.viewTo) return;
var lineView = display.view[findViewIndex(cm, line)];
if (lineView.node == null) return;
var arr = lineView.changes || (lineView.changes = []);
if (indexOf(arr, type) == -1) arr.push(type);
}
// Clear the view.
function resetView(cm) {
cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
cm.display.view = [];
cm.display.viewOffset = 0;
}
// Find the view element corresponding to a given line. Return null
// when the line isn't visible.
function findViewIndex(cm, n) {
if (n >= cm.display.viewTo) return null;
n -= cm.display.viewFrom;
if (n < 0) return null;
var view = cm.display.view;
for (var i = 0; i < view.length; i++) {
n -= view[i].size;
if (n < 0) return i;
}
}
function viewCuttingPoint(cm, oldN, newN, dir) {
var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
return {index: index, lineN: newN};
for (var i = 0, n = cm.display.viewFrom; i < index; i++)
n += view[i].size;
if (n != oldN) {
if (dir > 0) {
if (index == view.length - 1) return null;
diff = (n + view[index].size) - oldN;
index++;
} else {
diff = n - oldN;
}
oldN += diff; newN += diff;
}
while (visualLineNo(cm.doc, newN) != newN) {
if (index == (dir < 0 ? 0 : view.length - 1)) return null;
newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
index += dir;
}
return {index: index, lineN: newN};
}
// Force the view to cover a given range, adding empty view element
// or clipping off existing ones as needed.
function adjustView(cm, from, to) {
var display = cm.display, view = display.view;
if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
display.view = buildViewArray(cm, from, to);
display.viewFrom = from;
} else {
if (display.viewFrom > from)
display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view);
else if (display.viewFrom < from)
display.view = display.view.slice(findViewIndex(cm, from));
display.viewFrom = from;
if (display.viewTo < to)
display.view = display.view.concat(buildViewArray(cm, display.viewTo, to));
else if (display.viewTo > to)
display.view = display.view.slice(0, findViewIndex(cm, to));
}
display.viewTo = to;
}
// Count the number of lines in the view whose DOM representation is
// out of date (or nonexistent).
function countDirtyView(cm) {
var view = cm.display.view, dirty = 0;
for (var i = 0; i < view.length; i++) {
var lineView = view[i];
if (!lineView.hidden && (!lineView.node || lineView.changes)) ++dirty;
}
return dirty;
}
// EVENT HANDLERS
// Attach the necessary event handlers when initializing the editor
function registerEventHandlers(cm) {
var d = cm.display;
on(d.scroller, "mousedown", operation(cm, onMouseDown));
// Older IE's will not fire a second mousedown for a double click
if (ie && ie_version < 11)
on(d.scroller, "dblclick", operation(cm, function(e) {
if (signalDOMEvent(cm, e)) return;
var pos = posFromMouse(cm, e);
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
e_preventDefault(e);
var word = cm.findWordAt(pos);
extendSelection(cm.doc, word.anchor, word.head);
}));
else
on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); });
// Some browsers fire contextmenu *after* opening the menu, at
// which point we can't mess with it anymore. Context menu is
// handled in onMouseDown for these browsers.
if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
// Used to suppress mouse event handling when a touch happens
var touchFinished, prevTouch = {end: 0};
function finishTouch() {
if (d.activeTouch) {
touchFinished = setTimeout(function() {d.activeTouch = null;}, 1000);
prevTouch = d.activeTouch;
prevTouch.end = +new Date;
}
};
function isMouseLikeTouchEvent(e) {
if (e.touches.length != 1) return false;
var touch = e.touches[0];
return touch.radiusX <= 1 && touch.radiusY <= 1;
}
function farAway(touch, other) {
if (other.left == null) return true;
var dx = other.left - touch.left, dy = other.top - touch.top;
return dx * dx + dy * dy > 20 * 20;
}
on(d.scroller, "touchstart", function(e) {
if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) {
clearTimeout(touchFinished);
var now = +new Date;
d.activeTouch = {start: now, moved: false,
prev: now - prevTouch.end <= 300 ? prevTouch : null};
if (e.touches.length == 1) {
d.activeTouch.left = e.touches[0].pageX;
d.activeTouch.top = e.touches[0].pageY;
}
}
});
on(d.scroller, "touchmove", function() {
if (d.activeTouch) d.activeTouch.moved = true;
});
on(d.scroller, "touchend", function(e) {
var touch = d.activeTouch;
if (touch && !eventInWidget(d, e) && touch.left != null &&
!touch.moved && new Date - touch.start < 300) {
var pos = cm.coordsChar(d.activeTouch, "page"), range;
if (!touch.prev || farAway(touch, touch.prev)) // Single tap
range = new Range(pos, pos);
else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
range = cm.findWordAt(pos);
else // Triple tap
range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)));
cm.setSelection(range.anchor, range.head);
cm.focus();
e_preventDefault(e);
}
finishTouch();
});
on(d.scroller, "touchcancel", finishTouch);
// Sync scrolling between fake scrollbars and real scrollable
// area, ensure viewport is updated when scrolling.
on(d.scroller, "scroll", function() {
if (d.scroller.clientHeight) {
setScrollTop(cm, d.scroller.scrollTop);
setScrollLeft(cm, d.scroller.scrollLeft, true);
signal(cm, "scroll", cm);
}
});
// Listen to wheel events in order to try and update the viewport on time.
on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
// Prevent wrapper from ever scrolling
on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
d.dragFunctions = {
enter: function(e) {if (!signalDOMEvent(cm, e)) e_stop(e);},
over: function(e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }},
start: function(e){onDragStart(cm, e);},
drop: operation(cm, onDrop),
leave: function(e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }}
};
var inp = d.input.getField();
on(inp, "keyup", function(e) { onKeyUp.call(cm, e); });
on(inp, "keydown", operation(cm, onKeyDown));
on(inp, "keypress", operation(cm, onKeyPress));
on(inp, "focus", bind(onFocus, cm));
on(inp, "blur", bind(onBlur, cm));
}
function dragDropChanged(cm, value, old) {
var wasOn = old && old != CodeMirror.Init;
if (!value != !wasOn) {
var funcs = cm.display.dragFunctions;
var toggle = value ? on : off;
toggle(cm.display.scroller, "dragstart", funcs.start);
toggle(cm.display.scroller, "dragenter", funcs.enter);
toggle(cm.display.scroller, "dragover", funcs.over);
toggle(cm.display.scroller, "dragleave", funcs.leave);
toggle(cm.display.scroller, "drop", funcs.drop);
}
}
// Called when the window resizes
function onResize(cm) {
var d = cm.display;
if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
return;
// Might be a text scaling operation, clear size caches.
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
d.scrollbarsClipped = false;
cm.setSize();
}
// MOUSE EVENTS
// Return true when the given mouse event happened in a widget
function eventInWidget(display, e) {
for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
(n.parentNode == display.sizer && n != display.mover))
return true;
}
}
// Given a mouse event, find the corresponding position. If liberal
// is false, it checks whether a gutter or scrollbar was clicked,
// and returns null if it was. forRect is used by rectangular
// selections, and tries to estimate a character position even for
// coordinates beyond the right of the text.
function posFromMouse(cm, e, liberal, forRect) {
var display = cm.display;
if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") return null;
var x, y, space = display.lineSpace.getBoundingClientRect();
// Fails unpredictably on IE[67] when mouse is dragged around quickly.
try { x = e.clientX - space.left; y = e.clientY - space.top; }
catch (e) { return null; }
var coords = coordsChar(cm, x, y), line;
if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
}
return coords;
}
// A mouse down can be a single click, double click, triple click,
// start of selection drag, start of text drag, new cursor
// (ctrl-click), rectangle drag (alt-drag), or xwin
// middle-click-paste. Or it might be a click on something we should
// not interfere with, such as a scrollbar or widget.
function onMouseDown(e) {
var cm = this, display = cm.display;
if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) return;
display.shift = e.shiftKey;
if (eventInWidget(display, e)) {
if (!webkit) {
// Briefly turn off draggability, to allow widgets to do
// normal dragging things.
display.scroller.draggable = false;
setTimeout(function(){display.scroller.draggable = true;}, 100);
}
return;
}
if (clickInGutter(cm, e)) return;
var start = posFromMouse(cm, e);
window.focus();
switch (e_button(e)) {
case 1:
// #3261: make sure, that we're not starting a second selection
if (cm.state.selectingText)
cm.state.selectingText(e);
else if (start)
leftButtonDown(cm, e, start);
else if (e_target(e) == display.scroller)
e_preventDefault(e);
break;
case 2:
if (webkit) cm.state.lastMiddleDown = +new Date;
if (start) extendSelection(cm.doc, start);
setTimeout(function() {display.input.focus();}, 20);
e_preventDefault(e);
break;
case 3:
if (captureRightClick) onContextMenu(cm, e);
else delayBlurEvent(cm);
break;
}
}
var lastClick, lastDoubleClick;
function leftButtonDown(cm, e, start) {
if (ie) setTimeout(bind(ensureFocus, cm), 0);
else cm.curOp.focus = activeElt();
var now = +new Date, type;
if (lastDoubleClick && lastDoubleClick.time > now - 400 && cmp(lastDoubleClick.pos, start) == 0) {
type = "triple";
} else if (lastClick && lastClick.time > now - 400 && cmp(lastClick.pos, start) == 0) {
type = "double";
lastDoubleClick = {time: now, pos: start};
} else {
type = "single";
lastClick = {time: now, pos: start};
}
var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained;
if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
type == "single" && (contained = sel.contains(start)) > -1 &&
(cmp((contained = sel.ranges[contained]).from(), start) < 0 || start.xRel > 0) &&
(cmp(contained.to(), start) > 0 || start.xRel < 0))
leftButtonStartDrag(cm, e, start, modifier);
else
leftButtonSelect(cm, e, start, type, modifier);
}
// Start a text drag. When it ends, see if any dragging actually
// happen, and treat as a click if it didn't.
function leftButtonStartDrag(cm, e, start, modifier) {
var display = cm.display, startTime = +new Date;
var dragEnd = operation(cm, function(e2) {
if (webkit) display.scroller.draggable = false;
cm.state.draggingText = false;
off(document, "mouseup", dragEnd);
off(display.scroller, "drop", dragEnd);
if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
e_preventDefault(e2);
if (!modifier && +new Date - 200 < startTime)
extendSelection(cm.doc, start);
// Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
if (webkit || ie && ie_version == 9)
setTimeout(function() {document.body.focus(); display.input.focus();}, 20);
else
display.input.focus();
}
});
// Let the drag handler handle this.
if (webkit) display.scroller.draggable = true;
cm.state.draggingText = dragEnd;
// IE's approach to draggable
if (display.scroller.dragDrop) display.scroller.dragDrop();
on(document, "mouseup", dragEnd);
on(display.scroller, "drop", dragEnd);
}
// Normal selection, as opposed to text dragging.
function leftButtonSelect(cm, e, start, type, addNew) {
var display = cm.display, doc = cm.doc;
e_preventDefault(e);
var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
if (addNew && !e.shiftKey) {
ourIndex = doc.sel.contains(start);
if (ourIndex > -1)
ourRange = ranges[ourIndex];
else
ourRange = new Range(start, start);
} else {
ourRange = doc.sel.primary();
ourIndex = doc.sel.primIndex;
}
if (chromeOS ? e.shiftKey && e.metaKey : e.altKey) {
type = "rect";
if (!addNew) ourRange = new Range(start, start);
start = posFromMouse(cm, e, true, true);
ourIndex = -1;
} else if (type == "double") {
var word = cm.findWordAt(start);
if (cm.display.shift || doc.extend)
ourRange = extendRange(doc, ourRange, word.anchor, word.head);
else
ourRange = word;
} else if (type == "triple") {
var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
if (cm.display.shift || doc.extend)
ourRange = extendRange(doc, ourRange, line.anchor, line.head);
else
ourRange = line;
} else {
ourRange = extendRange(doc, ourRange, start);
}
if (!addNew) {
ourIndex = 0;
setSelection(doc, new Selection([ourRange], 0), sel_mouse);
startSel = doc.sel;
} else if (ourIndex == -1) {
ourIndex = ranges.length;
setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
{scroll: false, origin: "*mouse"});
} else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single" && !e.shiftKey) {
setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
{scroll: false, origin: "*mouse"});
startSel = doc.sel;
} else {
replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
}
var lastPos = start;
function extendTo(pos) {
if (cmp(lastPos, pos) == 0) return;
lastPos = pos;
if (type == "rect") {
var ranges = [], tabSize = cm.options.tabSize;
var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
line <= end; line++) {
var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
if (left == right)
ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
else if (text.length > leftPos)
ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
}
if (!ranges.length) ranges.push(new Range(start, start));
setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
{origin: "*mouse", scroll: false});
cm.scrollIntoView(pos);
} else {
var oldRange = ourRange;
var anchor = oldRange.anchor, head = pos;
if (type != "single") {
if (type == "double")
var range = cm.findWordAt(pos);
else
var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0)));
if (cmp(range.anchor, anchor) > 0) {
head = range.head;
anchor = minPos(oldRange.from(), range.anchor);
} else {
head = range.anchor;
anchor = maxPos(oldRange.to(), range.head);
}
}
var ranges = startSel.ranges.slice(0);
ranges[ourIndex] = new Range(clipPos(doc, anchor), head);
setSelection(doc, normalizeSelection(ranges, ourIndex), sel_mouse);
}
}
var editorSize = display.wrapper.getBoundingClientRect();
// Used to ensure timeout re-tries don't fire when another extend
// happened in the meantime (clearTimeout isn't reliable -- at
// least on Chrome, the timeouts still happen even when cleared,
// if the clear happens after their scheduled firing time).
var counter = 0;
function extend(e) {
var curCount = ++counter;
var cur = posFromMouse(cm, e, true, type == "rect");
if (!cur) return;
if (cmp(cur, lastPos) != 0) {
cm.curOp.focus = activeElt();
extendTo(cur);
var visible = visibleLines(display, doc);
if (cur.line >= visible.to || cur.line < visible.from)
setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
} else {
var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
if (outside) setTimeout(operation(cm, function() {
if (counter != curCount) return;
display.scroller.scrollTop += outside;
extend(e);
}), 50);
}
}
function done(e) {
cm.state.selectingText = false;
counter = Infinity;
e_preventDefault(e);
display.input.focus();
off(document, "mousemove", move);
off(document, "mouseup", up);
doc.history.lastSelOrigin = null;
}
var move = operation(cm, function(e) {
if (!e_button(e)) done(e);
else extend(e);
});
var up = operation(cm, done);
cm.state.selectingText = up;
on(document, "mousemove", move);
on(document, "mouseup", up);
}
// Determines whether an event happened in the gutter, and fires the
// handlers for the corresponding event.
function gutterEvent(cm, e, type, prevent) {
try { var mX = e.clientX, mY = e.clientY; }
catch(e) { return false; }
if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) return false;
if (prevent) e_preventDefault(e);
var display = cm.display;
var lineBox = display.lineDiv.getBoundingClientRect();
if (mY > lineBox.bottom || !hasHandler(cm, type)) return e_defaultPrevented(e);
mY -= lineBox.top - display.viewOffset;
for (var i = 0; i < cm.options.gutters.length; ++i) {
var g = display.gutters.childNodes[i];
if (g && g.getBoundingClientRect().right >= mX) {
var line = lineAtHeight(cm.doc, mY);
var gutter = cm.options.gutters[i];
signal(cm, type, cm, line, gutter, e);
return e_defaultPrevented(e);
}
}
}
function clickInGutter(cm, e) {
return gutterEvent(cm, e, "gutterClick", true);
}
// Kludge to work around strange IE behavior where it'll sometimes
// re-fire a series of drag-related events right after the drop (#1551)
var lastDrop = 0;
function onDrop(e) {
var cm = this;
clearDragCursor(cm);
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
return;
e_preventDefault(e);
if (ie) lastDrop = +new Date;
var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
if (!pos || cm.isReadOnly()) return;
// Might be a file drop, in which case we simply extract the text
// and insert it.
if (files && files.length && window.FileReader && window.File) {
var n = files.length, text = Array(n), read = 0;
var loadFile = function(file, i) {
if (cm.options.allowDropFileTypes &&
indexOf(cm.options.allowDropFileTypes, file.type) == -1)
return;
var reader = new FileReader;
reader.onload = operation(cm, function() {
var content = reader.result;
if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) content = "";
text[i] = content;
if (++read == n) {
pos = clipPos(cm.doc, pos);
var change = {from: pos, to: pos,
text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
origin: "paste"};
makeChange(cm.doc, change);
setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
}
});
reader.readAsText(file);
};
for (var i = 0; i < n; ++i) loadFile(files[i], i);
} else { // Normal drop
// Don't do a replace if the drop happened inside of the selected text.
if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
cm.state.draggingText(e);
// Ensure the editor is re-focused
setTimeout(function() {cm.display.input.focus();}, 20);
return;
}
try {
var text = e.dataTransfer.getData("Text");
if (text) {
if (cm.state.draggingText && !(mac ? e.altKey : e.ctrlKey))
var selected = cm.listSelections();
setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
if (selected) for (var i = 0; i < selected.length; ++i)
replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag");
cm.replaceSelection(text, "around", "paste");
cm.display.input.focus();
}
}
catch(e){}
}
}
function onDragStart(cm, e) {
if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return; }
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return;
e.dataTransfer.setData("Text", cm.getSelection());
e.dataTransfer.effectAllowed = "copyMove"
// Use dummy image instead of default browsers image.
// Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
if (e.dataTransfer.setDragImage && !safari) {
var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
if (presto) {
img.width = img.height = 1;
cm.display.wrapper.appendChild(img);
// Force a relayout, or Opera won't use our image for some obscure reason
img._top = img.offsetTop;
}
e.dataTransfer.setDragImage(img, 0, 0);
if (presto) img.parentNode.removeChild(img);
}
}
function onDragOver(cm, e) {
var pos = posFromMouse(cm, e);
if (!pos) return;
var frag = document.createDocumentFragment();
drawSelectionCursor(cm, pos, frag);
if (!cm.display.dragCursor) {
cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors");
cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);
}
removeChildrenAndAdd(cm.display.dragCursor, frag);
}
function clearDragCursor(cm) {
if (cm.display.dragCursor) {
cm.display.lineSpace.removeChild(cm.display.dragCursor);
cm.display.dragCursor = null;
}
}
// SCROLL EVENTS
// Sync the scrollable area and scrollbars, ensure the viewport
// covers the visible area.
function setScrollTop(cm, val) {
if (Math.abs(cm.doc.scrollTop - val) < 2) return;
cm.doc.scrollTop = val;
if (!gecko) updateDisplaySimple(cm, {top: val});
if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
cm.display.scrollbars.setScrollTop(val);
if (gecko) updateDisplaySimple(cm);
startWorker(cm, 100);
}
// Sync scroller and scrollbar, ensure the gutter elements are
// aligned.
function setScrollLeft(cm, val, isScroller) {
if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) return;
val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
cm.doc.scrollLeft = val;
alignHorizontally(cm);
if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
cm.display.scrollbars.setScrollLeft(val);
}
// Since the delta values reported on mouse wheel events are
// unstandardized between browsers and even browser versions, and
// generally horribly unpredictable, this code starts by measuring
// the scroll effect that the first few mouse wheel events have,
// and, from that, detects the way it can convert deltas to pixel
// offsets afterwards.
//
// The reason we want to know the amount a wheel event will scroll
// is that it gives us a chance to update the display before the
// actual scrolling happens, reducing flickering.
var wheelSamples = 0, wheelPixelsPerUnit = null;
// Fill in a browser-detected starting value on browsers where we
// know one. These don't have to be accurate -- the result of them
// being wrong would just be a slight flicker on the first wheel
// scroll (if it is large enough).
if (ie) wheelPixelsPerUnit = -.53;
else if (gecko) wheelPixelsPerUnit = 15;
else if (chrome) wheelPixelsPerUnit = -.7;
else if (safari) wheelPixelsPerUnit = -1/3;
var wheelEventDelta = function(e) {
var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
else if (dy == null) dy = e.wheelDelta;
return {x: dx, y: dy};
};
CodeMirror.wheelEventPixels = function(e) {
var delta = wheelEventDelta(e);
delta.x *= wheelPixelsPerUnit;
delta.y *= wheelPixelsPerUnit;
return delta;
};
function onScrollWheel(cm, e) {
var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
var display = cm.display, scroll = display.scroller;
// Quit if there's nothing to scroll here
var canScrollX = scroll.scrollWidth > scroll.clientWidth;
var canScrollY = scroll.scrollHeight > scroll.clientHeight;
if (!(dx && canScrollX || dy && canScrollY)) return;
// Webkit browsers on OS X abort momentum scrolls when the target
// of the scroll event is removed from the scrollable element.
// This hack (see related code in patchDisplay) makes sure the
// element is kept around.
if (dy && mac && webkit) {
outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
for (var i = 0; i < view.length; i++) {
if (view[i].node == cur) {
cm.display.currentWheelTarget = cur;
break outer;
}
}
}
}
// On some browsers, horizontal scrolling will cause redraws to
// happen before the gutter has been realigned, causing it to
// wriggle around in a most unseemly way. When we have an
// estimated pixels/delta value, we just handle horizontal
// scrolling entirely here. It'll be slightly off from native, but
// better than glitching out.
if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
if (dy && canScrollY)
setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
// Only prevent default scrolling if vertical scrolling is
// actually possible. Otherwise, it causes vertical scroll
// jitter on OSX trackpads when deltaX is small and deltaY
// is large (issue #3579)
if (!dy || (dy && canScrollY))
e_preventDefault(e);
display.wheelStartX = null; // Abort measurement, if in progress
return;
}
// 'Project' the visible viewport to cover the area that is being
// scrolled into view (if we know enough to estimate it).
if (dy && wheelPixelsPerUnit != null) {
var pixels = dy * wheelPixelsPerUnit;
var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
if (pixels < 0) top = Math.max(0, top + pixels - 50);
else bot = Math.min(cm.doc.height, bot + pixels + 50);
updateDisplaySimple(cm, {top: top, bottom: bot});
}
if (wheelSamples < 20) {
if (display.wheelStartX == null) {
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
display.wheelDX = dx; display.wheelDY = dy;
setTimeout(function() {
if (display.wheelStartX == null) return;
var movedX = scroll.scrollLeft - display.wheelStartX;
var movedY = scroll.scrollTop - display.wheelStartY;
var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
(movedX && display.wheelDX && movedX / display.wheelDX);
display.wheelStartX = display.wheelStartY = null;
if (!sample) return;
wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
++wheelSamples;
}, 200);
} else {
display.wheelDX += dx; display.wheelDY += dy;
}
}
}
// KEY EVENTS
// Run a handler that was bound to a key.
function doHandleBinding(cm, bound, dropShift) {
if (typeof bound == "string") {
bound = commands[bound];
if (!bound) return false;
}
// Ensure previous input has been read, so that the handler sees a
// consistent view of the document
cm.display.input.ensurePolled();
var prevShift = cm.display.shift, done = false;
try {
if (cm.isReadOnly()) cm.state.suppressEdits = true;
if (dropShift) cm.display.shift = false;
done = bound(cm) != Pass;
} finally {
cm.display.shift = prevShift;
cm.state.suppressEdits = false;
}
return done;
}
function lookupKeyForEditor(cm, name, handle) {
for (var i = 0; i < cm.state.keyMaps.length; i++) {
var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
if (result) return result;
}
return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
|| lookupKey(name, cm.options.keyMap, handle, cm);
}
var stopSeq = new Delayed;
function dispatchKey(cm, name, e, handle) {
var seq = cm.state.keySeq;
if (seq) {
if (isModifierKey(name)) return "handled";
stopSeq.set(50, function() {
if (cm.state.keySeq == seq) {
cm.state.keySeq = null;
cm.display.input.reset();
}
});
name = seq + " " + name;
}
var result = lookupKeyForEditor(cm, name, handle);
if (result == "multi")
cm.state.keySeq = name;
if (result == "handled")
signalLater(cm, "keyHandled", cm, name, e);
if (result == "handled" || result == "multi") {
e_preventDefault(e);
restartBlink(cm);
}
if (seq && !result && /\'$/.test(name)) {
e_preventDefault(e);
return true;
}
return !!result;
}
// Handle a key from the keydown event.
function handleKeyBinding(cm, e) {
var name = keyName(e, true);
if (!name) return false;
if (e.shiftKey && !cm.state.keySeq) {
// First try to resolve full name (including 'Shift-'). Failing
// that, see if there is a cursor-motion command (starting with
// 'go') bound to the keyname without 'Shift-'.
return dispatchKey(cm, "Shift-" + name, e, function(b) {return doHandleBinding(cm, b, true);})
|| dispatchKey(cm, name, e, function(b) {
if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
return doHandleBinding(cm, b);
});
} else {
return dispatchKey(cm, name, e, function(b) { return doHandleBinding(cm, b); });
}
}
// Handle a key from the keypress event
function handleCharBinding(cm, e, ch) {
return dispatchKey(cm, "'" + ch + "'", e,
function(b) { return doHandleBinding(cm, b, true); });
}
var lastStoppedKey = null;
function onKeyDown(e) {
var cm = this;
cm.curOp.focus = activeElt();
if (signalDOMEvent(cm, e)) return;
// IE does strange things with escape.
if (ie && ie_version < 11 && e.keyCode == 27) e.returnValue = false;
var code = e.keyCode;
cm.display.shift = code == 16 || e.shiftKey;
var handled = handleKeyBinding(cm, e);
if (presto) {
lastStoppedKey = handled ? code : null;
// Opera has no cut event... we try to at least catch the key combo
if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
cm.replaceSelection("", null, "cut");
}
// Turn mouse into crosshair when Alt is held on Mac.
if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
showCrossHair(cm);
}
function showCrossHair(cm) {
var lineDiv = cm.display.lineDiv;
addClass(lineDiv, "CodeMirror-crosshair");
function up(e) {
if (e.keyCode == 18 || !e.altKey) {
rmClass(lineDiv, "CodeMirror-crosshair");
off(document, "keyup", up);
off(document, "mouseover", up);
}
}
on(document, "keyup", up);
on(document, "mouseover", up);
}
function onKeyUp(e) {
if (e.keyCode == 16) this.doc.sel.shift = false;
signalDOMEvent(this, e);
}
function onKeyPress(e) {
var cm = this;
if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) return;
var keyCode = e.keyCode, charCode = e.charCode;
if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) return;
var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
if (handleCharBinding(cm, e, ch)) return;
cm.display.input.onKeyPress(e);
}
// FOCUS/BLUR EVENTS
function delayBlurEvent(cm) {
cm.state.delayingBlurEvent = true;
setTimeout(function() {
if (cm.state.delayingBlurEvent) {
cm.state.delayingBlurEvent = false;
onBlur(cm);
}
}, 100);
}
function onFocus(cm) {
if (cm.state.delayingBlurEvent) cm.state.delayingBlurEvent = false;
if (cm.options.readOnly == "nocursor") return;
if (!cm.state.focused) {
signal(cm, "focus", cm);
cm.state.focused = true;
addClass(cm.display.wrapper, "CodeMirror-focused");
// This test prevents this from firing when a context
// menu is closed (since the input reset would kill the
// select-all detection hack)
if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
cm.display.input.reset();
if (webkit) setTimeout(function() { cm.display.input.reset(true); }, 20); // Issue #1730
}
cm.display.input.receivedFocus();
}
restartBlink(cm);
}
function onBlur(cm) {
if (cm.state.delayingBlurEvent) return;
if (cm.state.focused) {
signal(cm, "blur", cm);
cm.state.focused = false;
rmClass(cm.display.wrapper, "CodeMirror-focused");
}
clearInterval(cm.display.blinker);
setTimeout(function() {if (!cm.state.focused) cm.display.shift = false;}, 150);
}
// CONTEXT MENU HANDLING
// To make the context menu work, we need to briefly unhide the
// textarea (making it as unobtrusive as possible) to let the
// right-click take effect on it.
function onContextMenu(cm, e) {
if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) return;
if (signalDOMEvent(cm, e, "contextmenu")) return;
cm.display.input.onContextMenu(e);
}
function contextMenuInGutter(cm, e) {
if (!hasHandler(cm, "gutterContextMenu")) return false;
return gutterEvent(cm, e, "gutterContextMenu", false);
}
// UPDATING
// Compute the position of the end of a change (its 'to' property
// refers to the pre-change end).
var changeEnd = CodeMirror.changeEnd = function(change) {
if (!change.text) return change.to;
return Pos(change.from.line + change.text.length - 1,
lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));
};
// Adjust a position to refer to the post-change position of the
// same text, or the end of the change if the change covers it.
function adjustForChange(pos, change) {
if (cmp(pos, change.from) < 0) return pos;
if (cmp(pos, change.to) <= 0) return changeEnd(change);
var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
if (pos.line == change.to.line) ch += changeEnd(change).ch - change.to.ch;
return Pos(line, ch);
}
function computeSelAfterChange(doc, change) {
var out = [];
for (var i = 0; i < doc.sel.ranges.length; i++) {
var range = doc.sel.ranges[i];
out.push(new Range(adjustForChange(range.anchor, change),
adjustForChange(range.head, change)));
}
return normalizeSelection(out, doc.sel.primIndex);
}
function offsetPos(pos, old, nw) {
if (pos.line == old.line)
return Pos(nw.line, pos.ch - old.ch + nw.ch);
else
return Pos(nw.line + (pos.line - old.line), pos.ch);
}
// Used by replaceSelections to allow moving the selection to the
// start or around the replaced test. Hint may be "start" or "around".
function computeReplacedSel(doc, changes, hint) {
var out = [];
var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
for (var i = 0; i < changes.length; i++) {
var change = changes[i];
var from = offsetPos(change.from, oldPrev, newPrev);
var to = offsetPos(changeEnd(change), oldPrev, newPrev);
oldPrev = change.to;
newPrev = to;
if (hint == "around") {
var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
out[i] = new Range(inv ? to : from, inv ? from : to);
} else {
out[i] = new Range(from, from);
}
}
return new Selection(out, doc.sel.primIndex);
}
// Allow "beforeChange" event handlers to influence a change
function filterChange(doc, change, update) {
var obj = {
canceled: false,
from: change.from,
to: change.to,
text: change.text,
origin: change.origin,
cancel: function() { this.canceled = true; }
};
if (update) obj.update = function(from, to, text, origin) {
if (from) this.from = clipPos(doc, from);
if (to) this.to = clipPos(doc, to);
if (text) this.text = text;
if (origin !== undefined) this.origin = origin;
};
signal(doc, "beforeChange", doc, obj);
if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj);
if (obj.canceled) return null;
return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin};
}
// Apply a change to a document, and add it to the document's
// history, and propagating it to all linked documents.
function makeChange(doc, change, ignoreReadOnly) {
if (doc.cm) {
if (!doc.cm.curOp) return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly);
if (doc.cm.state.suppressEdits) return;
}
if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
change = filterChange(doc, change, true);
if (!change) return;
}
// Possibly split or suppress the update based on the presence
// of read-only spans in its range.
var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
if (split) {
for (var i = split.length - 1; i >= 0; --i)
makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text});
} else {
makeChangeInner(doc, change);
}
}
function makeChangeInner(doc, change) {
if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) return;
var selAfter = computeSelAfterChange(doc, change);
addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
var rebased = [];
linkedDocs(doc, function(doc, sharedHist) {
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
rebaseHist(doc.history, change);
rebased.push(doc.history);
}
makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
});
}
// Revert a change stored in a document's history.
function makeChangeFromHistory(doc, type, allowSelectionOnly) {
if (doc.cm && doc.cm.state.suppressEdits) return;
var hist = doc.history, event, selAfter = doc.sel;
var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
// Verify that there is a useable event (so that ctrl-z won't
// needlessly clear selection events)
for (var i = 0; i < source.length; i++) {
event = source[i];
if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
break;
}
if (i == source.length) return;
hist.lastOrigin = hist.lastSelOrigin = null;
for (;;) {
event = source.pop();
if (event.ranges) {
pushSelectionToHistory(event, dest);
if (allowSelectionOnly && !event.equals(doc.sel)) {
setSelection(doc, event, {clearRedo: false});
return;
}
selAfter = event;
}
else break;
}
// Build up a reverse change object to add to the opposite history
// stack (redo when undoing, and vice versa).
var antiChanges = [];
pushSelectionToHistory(selAfter, dest);
dest.push({changes: antiChanges, generation: hist.generation});
hist.generation = event.generation || ++hist.maxGeneration;
var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
for (var i = event.changes.length - 1; i >= 0; --i) {
var change = event.changes[i];
change.origin = type;
if (filter && !filterChange(doc, change, false)) {
source.length = 0;
return;
}
antiChanges.push(historyChangeFromChange(doc, change));
var after = i ? computeSelAfterChange(doc, change) : lst(source);
makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
if (!i && doc.cm) doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)});
var rebased = [];
// Propagate to the linked documents
linkedDocs(doc, function(doc, sharedHist) {
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
rebaseHist(doc.history, change);
rebased.push(doc.history);
}
makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
});
}
}
// Sub-views need their line numbers shifted when text is added
// above or below them in the parent document.
function shiftDoc(doc, distance) {
if (distance == 0) return;
doc.first += distance;
doc.sel = new Selection(map(doc.sel.ranges, function(range) {
return new Range(Pos(range.anchor.line + distance, range.anchor.ch),
Pos(range.head.line + distance, range.head.ch));
}), doc.sel.primIndex);
if (doc.cm) {
regChange(doc.cm, doc.first, doc.first - distance, distance);
for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
regLineChange(doc.cm, l, "gutter");
}
}
// More lower-level change function, handling only a single document
// (not linked ones).
function makeChangeSingleDoc(doc, change, selAfter, spans) {
if (doc.cm && !doc.cm.curOp)
return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);
if (change.to.line < doc.first) {
shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
return;
}
if (change.from.line > doc.lastLine()) return;
// Clip the change to the size of this doc
if (change.from.line < doc.first) {
var shift = change.text.length - 1 - (doc.first - change.from.line);
shiftDoc(doc, shift);
change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
text: [lst(change.text)], origin: change.origin};
}
var last = doc.lastLine();
if (change.to.line > last) {
change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
text: [change.text[0]], origin: change.origin};
}
change.removed = getBetween(doc, change.from, change.to);
if (!selAfter) selAfter = computeSelAfterChange(doc, change);
if (doc.cm) makeChangeSingleDocInEditor(doc.cm, change, spans);
else updateDoc(doc, change, spans);
setSelectionNoUndo(doc, selAfter, sel_dontScroll);
}
// Handle the interaction of a change to a document with the editor
// that this document is part of.
function makeChangeSingleDocInEditor(cm, change, spans) {
var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
var recomputeMaxLength = false, checkWidthStart = from.line;
if (!cm.options.lineWrapping) {
checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
doc.iter(checkWidthStart, to.line + 1, function(line) {
if (line == display.maxLine) {
recomputeMaxLength = true;
return true;
}
});
}
if (doc.sel.contains(change.from, change.to) > -1)
signalCursorActivity(cm);
updateDoc(doc, change, spans, estimateHeight(cm));
if (!cm.options.lineWrapping) {
doc.iter(checkWidthStart, from.line + change.text.length, function(line) {
var len = lineLength(line);
if (len > display.maxLineLength) {
display.maxLine = line;
display.maxLineLength = len;
display.maxLineChanged = true;
recomputeMaxLength = false;
}
});
if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
}
// Adjust frontier, schedule worker
doc.frontier = Math.min(doc.frontier, from.line);
startWorker(cm, 400);
var lendiff = change.text.length - (to.line - from.line) - 1;
// Remember that these lines changed, for updating the display
if (change.full)
regChange(cm);
else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
regLineChange(cm, from.line, "text");
else
regChange(cm, from.line, to.line + 1, lendiff);
var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
if (changeHandler || changesHandler) {
var obj = {
from: from, to: to,
text: change.text,
removed: change.removed,
origin: change.origin
};
if (changeHandler) signalLater(cm, "change", cm, obj);
if (changesHandler) (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
}
cm.display.selForContextMenu = null;
}
function replaceRange(doc, code, from, to, origin) {
if (!to) to = from;
if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp; }
if (typeof code == "string") code = doc.splitLines(code);
makeChange(doc, {from: from, to: to, text: code, origin: origin});
}
// SCROLLING THINGS INTO VIEW
// If an editor sits on the top or bottom of the window, partially
// scrolled out of view, this ensures that the cursor is visible.
function maybeScrollWindow(cm, coords) {
if (signalDOMEvent(cm, "scrollCursorIntoView")) return;
var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
if (coords.top + box.top < 0) doScroll = true;
else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
if (doScroll != null && !phantom) {
var scrollNode = elt("div", "\u200b", null, "position: absolute; top: " +
(coords.top - display.viewOffset - paddingTop(cm.display)) + "px; height: " +
(coords.bottom - coords.top + scrollGap(cm) + display.barHeight) + "px; left: " +
coords.left + "px; width: 2px;");
cm.display.lineSpace.appendChild(scrollNode);
scrollNode.scrollIntoView(doScroll);
cm.display.lineSpace.removeChild(scrollNode);
}
}
// Scroll a given position into view (immediately), verifying that
// it actually became visible (as line heights are accurately
// measured, the position of something may 'drift' during drawing).
function scrollPosIntoView(cm, pos, end, margin) {
if (margin == null) margin = 0;
for (var limit = 0; limit < 5; limit++) {
var changed = false, coords = cursorCoords(cm, pos);
var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
Math.min(coords.top, endCoords.top) - margin,
Math.max(coords.left, endCoords.left),
Math.max(coords.bottom, endCoords.bottom) + margin);
var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
if (scrollPos.scrollTop != null) {
setScrollTop(cm, scrollPos.scrollTop);
if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true;
}
if (scrollPos.scrollLeft != null) {
setScrollLeft(cm, scrollPos.scrollLeft);
if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true;
}
if (!changed) break;
}
return coords;
}
// Scroll a given set of coordinates into view (immediately).
function scrollIntoView(cm, x1, y1, x2, y2) {
var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
}
// Calculate a new scroll position needed to scroll the given
// rectangle into view. Returns an object with scrollTop and
// scrollLeft properties. When these are undefined, the
// vertical/horizontal position does not need to be adjusted.
function calculateScrollPos(cm, x1, y1, x2, y2) {
var display = cm.display, snapMargin = textHeight(cm.display);
if (y1 < 0) y1 = 0;
var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
var screen = displayHeight(cm), result = {};
if (y2 - y1 > screen) y2 = y1 + screen;
var docBottom = cm.doc.height + paddingVert(display);
var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
if (y1 < screentop) {
result.scrollTop = atTop ? 0 : y1;
} else if (y2 > screentop + screen) {
var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
if (newTop != screentop) result.scrollTop = newTop;
}
var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
var tooWide = x2 - x1 > screenw;
if (tooWide) x2 = x1 + screenw;
if (x1 < 10)
result.scrollLeft = 0;
else if (x1 < screenleft)
result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10));
else if (x2 > screenw + screenleft - 3)
result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw;
return result;
}
// Store a relative adjustment to the scroll position in the current
// operation (to be applied when the operation finishes).
function addToScrollPos(cm, left, top) {
if (left != null || top != null) resolveScrollToPos(cm);
if (left != null)
cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left;
if (top != null)
cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
}
// Make sure that at the end of the operation the current cursor is
// shown.
function ensureCursorVisible(cm) {
resolveScrollToPos(cm);
var cur = cm.getCursor(), from = cur, to = cur;
if (!cm.options.lineWrapping) {
from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur;
to = Pos(cur.line, cur.ch + 1);
}
cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin, isCursor: true};
}
// When an operation has its scrollToPos property set, and another
// scroll action is applied before the end of the operation, this
// 'simulates' scrolling that position into view in a cheap way, so
// that the effect of intermediate scroll commands is not ignored.
function resolveScrollToPos(cm) {
var range = cm.curOp.scrollToPos;
if (range) {
cm.curOp.scrollToPos = null;
var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
var sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
Math.min(from.top, to.top) - range.margin,
Math.max(from.right, to.right),
Math.max(from.bottom, to.bottom) + range.margin);
cm.scrollTo(sPos.scrollLeft, sPos.scrollTop);
}
}
// API UTILITIES
// Indent the given line. The how parameter can be "smart",
// "add"/null, "subtract", or "prev". When aggressive is false
// (typically set to true for forced single-line indents), empty
// lines are not indented, and places where the mode returns Pass
// are left alone.
function indentLine(cm, n, how, aggressive) {
var doc = cm.doc, state;
if (how == null) how = "add";
if (how == "smart") {
// Fall back to "prev" when the mode doesn't have an indentation
// method.
if (!doc.mode.indent) how = "prev";
else state = getStateBefore(cm, n);
}
var tabSize = cm.options.tabSize;
var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
if (line.stateAfter) line.stateAfter = null;
var curSpaceString = line.text.match(/^\s*/)[0], indentation;
if (!aggressive && !/\S/.test(line.text)) {
indentation = 0;
how = "not";
} else if (how == "smart") {
indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
if (indentation == Pass || indentation > 150) {
if (!aggressive) return;
how = "prev";
}
}
if (how == "prev") {
if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
else indentation = 0;
} else if (how == "add") {
indentation = curSpace + cm.options.indentUnit;
} else if (how == "subtract") {
indentation = curSpace - cm.options.indentUnit;
} else if (typeof how == "number") {
indentation = curSpace + how;
}
indentation = Math.max(0, indentation);
var indentString = "", pos = 0;
if (cm.options.indentWithTabs)
for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
if (pos < indentation) indentString += spaceStr(indentation - pos);
if (indentString != curSpaceString) {
replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
line.stateAfter = null;
return true;
} else {
// Ensure that, if the cursor was in the whitespace at the start
// of the line, it is moved to the end of that space.
for (var i = 0; i < doc.sel.ranges.length; i++) {
var range = doc.sel.ranges[i];
if (range.head.line == n && range.head.ch < curSpaceString.length) {
var pos = Pos(n, curSpaceString.length);
replaceOneSelection(doc, i, new Range(pos, pos));
break;
}
}
}
}
// Utility for applying a change to a line by handle or number,
// returning the number and optionally registering the line as
// changed.
function changeLine(doc, handle, changeType, op) {
var no = handle, line = handle;
if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
else no = lineNo(handle);
if (no == null) return null;
if (op(line, no) && doc.cm) regLineChange(doc.cm, no, changeType);
return line;
}
// Helper for deleting text near the selection(s), used to implement
// backspace, delete, and similar functionality.
function deleteNearSelection(cm, compute) {
var ranges = cm.doc.sel.ranges, kill = [];
// Build up a set of ranges to kill first, merging overlapping
// ranges.
for (var i = 0; i < ranges.length; i++) {
var toKill = compute(ranges[i]);
while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
var replaced = kill.pop();
if (cmp(replaced.from, toKill.from) < 0) {
toKill.from = replaced.from;
break;
}
}
kill.push(toKill);
}
// Next, remove those actual ranges.
runInOp(cm, function() {
for (var i = kill.length - 1; i >= 0; i--)
replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete");
ensureCursorVisible(cm);
});
}
// Used for horizontal relative motion. Dir is -1 or 1 (left or
// right), unit can be "char", "column" (like char, but doesn't
// cross line boundaries), "word" (across next word), or "group" (to
// the start of next group of word or non-word-non-whitespace
// chars). The visually param controls whether, in right-to-left
// text, direction 1 means to move towards the next index in the
// string, or towards the character to the right of the current
// position. The resulting position will have a hitSide=true
// property if it reached the end of the document.
function findPosH(doc, pos, dir, unit, visually) {
var line = pos.line, ch = pos.ch, origDir = dir;
var lineObj = getLine(doc, line);
function findNextLine() {
var l = line + dir;
if (l < doc.first || l >= doc.first + doc.size) return false
line = l;
return lineObj = getLine(doc, l);
}
function moveOnce(boundToLine) {
var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
if (next == null) {
if (!boundToLine && findNextLine()) {
if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
else ch = dir < 0 ? lineObj.text.length : 0;
} else return false
} else ch = next;
return true;
}
if (unit == "char") {
moveOnce()
} else if (unit == "column") {
moveOnce(true)
} else if (unit == "word" || unit == "group") {
var sawType = null, group = unit == "group";
var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
for (var first = true;; first = false) {
if (dir < 0 && !moveOnce(!first)) break;
var cur = lineObj.text.charAt(ch) || "\n";
var type = isWordChar(cur, helper) ? "w"
: group && cur == "\n" ? "n"
: !group || /\s/.test(cur) ? null
: "p";
if (group && !first && !type) type = "s";
if (sawType && sawType != type) {
if (dir < 0) {dir = 1; moveOnce();}
break;
}
if (type) sawType = type;
if (dir > 0 && !moveOnce(!first)) break;
}
}
var result = skipAtomic(doc, Pos(line, ch), pos, origDir, true);
if (!cmp(pos, result)) result.hitSide = true;
return result;
}
// For relative vertical movement. Dir may be -1 or 1. Unit can be
// "page" or "line". The resulting position will have a hitSide=true
// property if it reached the end of the document.
function findPosV(cm, pos, dir, unit) {
var doc = cm.doc, x = pos.left, y;
if (unit == "page") {
var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
y = pos.top + dir * (pageSize - (dir < 0 ? 1.5 : .5) * textHeight(cm.display));
} else if (unit == "line") {
y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
}
for (;;) {
var target = coordsChar(cm, x, y);
if (!target.outside) break;
if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break; }
y += dir * 5;
}
return target;
}
// EDITOR METHODS
// The publicly visible API. Note that methodOp(f) means
// 'wrap f in an operation, performed on its `this` parameter'.
// This is not the complete set of editor methods. Most of the
// methods defined on the Doc type are also injected into
// CodeMirror.prototype, for backwards compatibility and
// convenience.
CodeMirror.prototype = {
constructor: CodeMirror,
focus: function(){window.focus(); this.display.input.focus();},
setOption: function(option, value) {
var options = this.options, old = options[option];
if (options[option] == value && option != "mode") return;
options[option] = value;
if (optionHandlers.hasOwnProperty(option))
operation(this, optionHandlers[option])(this, value, old);
},
getOption: function(option) {return this.options[option];},
getDoc: function() {return this.doc;},
addKeyMap: function(map, bottom) {
this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map));
},
removeKeyMap: function(map) {
var maps = this.state.keyMaps;
for (var i = 0; i < maps.length; ++i)
if (maps[i] == map || maps[i].name == map) {
maps.splice(i, 1);
return true;
}
},
addOverlay: methodOp(function(spec, options) {
var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
if (mode.startState) throw new Error("Overlays may not be stateful.");
this.state.overlays.push({mode: mode, modeSpec: spec, opaque: options && options.opaque});
this.state.modeGen++;
regChange(this);
}),
removeOverlay: methodOp(function(spec) {
var overlays = this.state.overlays;
for (var i = 0; i < overlays.length; ++i) {
var cur = overlays[i].modeSpec;
if (cur == spec || typeof spec == "string" && cur.name == spec) {
overlays.splice(i, 1);
this.state.modeGen++;
regChange(this);
return;
}
}
}),
indentLine: methodOp(function(n, dir, aggressive) {
if (typeof dir != "string" && typeof dir != "number") {
if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
else dir = dir ? "add" : "subtract";
}
if (isLine(this.doc, n)) indentLine(this, n, dir, aggressive);
}),
indentSelection: methodOp(function(how) {
var ranges = this.doc.sel.ranges, end = -1;
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (!range.empty()) {
var from = range.from(), to = range.to();
var start = Math.max(end, from.line);
end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
for (var j = start; j < end; ++j)
indentLine(this, j, how);
var newRanges = this.doc.sel.ranges;
if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
replaceOneSelection(this.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll);
} else if (range.head.line > end) {
indentLine(this, range.head.line, how, true);
end = range.head.line;
if (i == this.doc.sel.primIndex) ensureCursorVisible(this);
}
}
}),
// Fetch the parser token for a given character. Useful for hacks
// that want to inspect the mode state (say, for completion).
getTokenAt: function(pos, precise) {
return takeToken(this, pos, precise);
},
getLineTokens: function(line, precise) {
return takeToken(this, Pos(line), precise, true);
},
getTokenTypeAt: function(pos) {
pos = clipPos(this.doc, pos);
var styles = getLineStyles(this, getLine(this.doc, pos.line));
var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
var type;
if (ch == 0) type = styles[2];
else for (;;) {
var mid = (before + after) >> 1;
if ((mid ? styles[mid * 2 - 1] : 0) >= ch) after = mid;
else if (styles[mid * 2 + 1] < ch) before = mid + 1;
else { type = styles[mid * 2 + 2]; break; }
}
var cut = type ? type.indexOf("cm-overlay ") : -1;
return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1);
},
getModeAt: function(pos) {
var mode = this.doc.mode;
if (!mode.innerMode) return mode;
return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode;
},
getHelper: function(pos, type) {
return this.getHelpers(pos, type)[0];
},
getHelpers: function(pos, type) {
var found = [];
if (!helpers.hasOwnProperty(type)) return found;
var help = helpers[type], mode = this.getModeAt(pos);
if (typeof mode[type] == "string") {
if (help[mode[type]]) found.push(help[mode[type]]);
} else if (mode[type]) {
for (var i = 0; i < mode[type].length; i++) {
var val = help[mode[type][i]];
if (val) found.push(val);
}
} else if (mode.helperType && help[mode.helperType]) {
found.push(help[mode.helperType]);
} else if (help[mode.name]) {
found.push(help[mode.name]);
}
for (var i = 0; i < help._global.length; i++) {
var cur = help._global[i];
if (cur.pred(mode, this) && indexOf(found, cur.val) == -1)
found.push(cur.val);
}
return found;
},
getStateAfter: function(line, precise) {
var doc = this.doc;
line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
return getStateBefore(this, line + 1, precise);
},
cursorCoords: function(start, mode) {
var pos, range = this.doc.sel.primary();
if (start == null) pos = range.head;
else if (typeof start == "object") pos = clipPos(this.doc, start);
else pos = start ? range.from() : range.to();
return cursorCoords(this, pos, mode || "page");
},
charCoords: function(pos, mode) {
return charCoords(this, clipPos(this.doc, pos), mode || "page");
},
coordsChar: function(coords, mode) {
coords = fromCoordSystem(this, coords, mode || "page");
return coordsChar(this, coords.left, coords.top);
},
lineAtHeight: function(height, mode) {
height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
return lineAtHeight(this.doc, height + this.display.viewOffset);
},
heightAtLine: function(line, mode) {
var end = false, lineObj;
if (typeof line == "number") {
var last = this.doc.first + this.doc.size - 1;
if (line < this.doc.first) line = this.doc.first;
else if (line > last) { line = last; end = true; }
lineObj = getLine(this.doc, line);
} else {
lineObj = line;
}
return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page").top +
(end ? this.doc.height - heightAtLine(lineObj) : 0);
},
defaultTextHeight: function() { return textHeight(this.display); },
defaultCharWidth: function() { return charWidth(this.display); },
setGutterMarker: methodOp(function(line, gutterID, value) {
return changeLine(this.doc, line, "gutter", function(line) {
var markers = line.gutterMarkers || (line.gutterMarkers = {});
markers[gutterID] = value;
if (!value && isEmpty(markers)) line.gutterMarkers = null;
return true;
});
}),
clearGutter: methodOp(function(gutterID) {
var cm = this, doc = cm.doc, i = doc.first;
doc.iter(function(line) {
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
line.gutterMarkers[gutterID] = null;
regLineChange(cm, i, "gutter");
if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
}
++i;
});
}),
lineInfo: function(line) {
if (typeof line == "number") {
if (!isLine(this.doc, line)) return null;
var n = line;
line = getLine(this.doc, line);
if (!line) return null;
} else {
var n = lineNo(line);
if (n == null) return null;
}
return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
widgets: line.widgets};
},
getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo};},
addWidget: function(pos, node, scroll, vert, horiz) {
var display = this.display;
pos = cursorCoords(this, clipPos(this.doc, pos));
var top = pos.bottom, left = pos.left;
node.style.position = "absolute";
node.setAttribute("cm-ignore-events", "true");
this.display.input.setUneditable(node);
display.sizer.appendChild(node);
if (vert == "over") {
top = pos.top;
} else if (vert == "above" || vert == "near") {
var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
// Default to positioning above (if specified and possible); otherwise default to positioning below
if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
top = pos.top - node.offsetHeight;
else if (pos.bottom + node.offsetHeight <= vspace)
top = pos.bottom;
if (left + node.offsetWidth > hspace)
left = hspace - node.offsetWidth;
}
node.style.top = top + "px";
node.style.left = node.style.right = "";
if (horiz == "right") {
left = display.sizer.clientWidth - node.offsetWidth;
node.style.right = "0px";
} else {
if (horiz == "left") left = 0;
else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
node.style.left = left + "px";
}
if (scroll)
scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
},
triggerOnKeyDown: methodOp(onKeyDown),
triggerOnKeyPress: methodOp(onKeyPress),
triggerOnKeyUp: onKeyUp,
execCommand: function(cmd) {
if (commands.hasOwnProperty(cmd))
return commands[cmd].call(null, this);
},
triggerElectric: methodOp(function(text) { triggerElectric(this, text); }),
findPosH: function(from, amount, unit, visually) {
var dir = 1;
if (amount < 0) { dir = -1; amount = -amount; }
for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
cur = findPosH(this.doc, cur, dir, unit, visually);
if (cur.hitSide) break;
}
return cur;
},
moveH: methodOp(function(dir, unit) {
var cm = this;
cm.extendSelectionsBy(function(range) {
if (cm.display.shift || cm.doc.extend || range.empty())
return findPosH(cm.doc, range.head, dir, unit, cm.options.rtlMoveVisually);
else
return dir < 0 ? range.from() : range.to();
}, sel_move);
}),
deleteH: methodOp(function(dir, unit) {
var sel = this.doc.sel, doc = this.doc;
if (sel.somethingSelected())
doc.replaceSelection("", null, "+delete");
else
deleteNearSelection(this, function(range) {
var other = findPosH(doc, range.head, dir, unit, false);
return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other};
});
}),
findPosV: function(from, amount, unit, goalColumn) {
var dir = 1, x = goalColumn;
if (amount < 0) { dir = -1; amount = -amount; }
for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
var coords = cursorCoords(this, cur, "div");
if (x == null) x = coords.left;
else coords.left = x;
cur = findPosV(this, coords, dir, unit);
if (cur.hitSide) break;
}
return cur;
},
moveV: methodOp(function(dir, unit) {
var cm = this, doc = this.doc, goals = [];
var collapse = !cm.display.shift && !doc.extend && doc.sel.somethingSelected();
doc.extendSelectionsBy(function(range) {
if (collapse)
return dir < 0 ? range.from() : range.to();
var headPos = cursorCoords(cm, range.head, "div");
if (range.goalColumn != null) headPos.left = range.goalColumn;
goals.push(headPos.left);
var pos = findPosV(cm, headPos, dir, unit);
if (unit == "page" && range == doc.sel.primary())
addToScrollPos(cm, null, charCoords(cm, pos, "div").top - headPos.top);
return pos;
}, sel_move);
if (goals.length) for (var i = 0; i < doc.sel.ranges.length; i++)
doc.sel.ranges[i].goalColumn = goals[i];
}),
// Find the word at the given position (as returned by coordsChar).
findWordAt: function(pos) {
var doc = this.doc, line = getLine(doc, pos.line).text;
var start = pos.ch, end = pos.ch;
if (line) {
var helper = this.getHelper(pos, "wordChars");
if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
var startChar = line.charAt(start);
var check = isWordChar(startChar, helper)
? function(ch) { return isWordChar(ch, helper); }
: /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
: function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
while (start > 0 && check(line.charAt(start - 1))) --start;
while (end < line.length && check(line.charAt(end))) ++end;
}
return new Range(Pos(pos.line, start), Pos(pos.line, end));
},
toggleOverwrite: function(value) {
if (value != null && value == this.state.overwrite) return;
if (this.state.overwrite = !this.state.overwrite)
addClass(this.display.cursorDiv, "CodeMirror-overwrite");
else
rmClass(this.display.cursorDiv, "CodeMirror-overwrite");
signal(this, "overwriteToggle", this, this.state.overwrite);
},
hasFocus: function() { return this.display.input.getField() == activeElt(); },
isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit); },
scrollTo: methodOp(function(x, y) {
if (x != null || y != null) resolveScrollToPos(this);
if (x != null) this.curOp.scrollLeft = x;
if (y != null) this.curOp.scrollTop = y;
}),
getScrollInfo: function() {
var scroller = this.display.scroller;
return {left: scroller.scrollLeft, top: scroller.scrollTop,
height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
clientHeight: displayHeight(this), clientWidth: displayWidth(this)};
},
scrollIntoView: methodOp(function(range, margin) {
if (range == null) {
range = {from: this.doc.sel.primary().head, to: null};
if (margin == null) margin = this.options.cursorScrollMargin;
} else if (typeof range == "number") {
range = {from: Pos(range, 0), to: null};
} else if (range.from == null) {
range = {from: range, to: null};
}
if (!range.to) range.to = range.from;
range.margin = margin || 0;
if (range.from.line != null) {
resolveScrollToPos(this);
this.curOp.scrollToPos = range;
} else {
var sPos = calculateScrollPos(this, Math.min(range.from.left, range.to.left),
Math.min(range.from.top, range.to.top) - range.margin,
Math.max(range.from.right, range.to.right),
Math.max(range.from.bottom, range.to.bottom) + range.margin);
this.scrollTo(sPos.scrollLeft, sPos.scrollTop);
}
}),
setSize: methodOp(function(width, height) {
var cm = this;
function interpret(val) {
return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
}
if (width != null) cm.display.wrapper.style.width = interpret(width);
if (height != null) cm.display.wrapper.style.height = interpret(height);
if (cm.options.lineWrapping) clearLineMeasurementCache(this);
var lineNo = cm.display.viewFrom;
cm.doc.iter(lineNo, cm.display.viewTo, function(line) {
if (line.widgets) for (var i = 0; i < line.widgets.length; i++)
if (line.widgets[i].noHScroll) { regLineChange(cm, lineNo, "widget"); break; }
++lineNo;
});
cm.curOp.forceUpdate = true;
signal(cm, "refresh", this);
}),
operation: function(f){return runInOp(this, f);},
refresh: methodOp(function() {
var oldHeight = this.display.cachedTextHeight;
regChange(this);
this.curOp.forceUpdate = true;
clearCaches(this);
this.scrollTo(this.doc.scrollLeft, this.doc.scrollTop);
updateGutterSpace(this);
if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
estimateLineHeights(this);
signal(this, "refresh", this);
}),
swapDoc: methodOp(function(doc) {
var old = this.doc;
old.cm = null;
attachDoc(this, doc);
clearCaches(this);
this.display.input.reset();
this.scrollTo(doc.scrollLeft, doc.scrollTop);
this.curOp.forceScroll = true;
signalLater(this, "swapDoc", this, old);
return old;
}),
getInputField: function(){return this.display.input.getField();},
getWrapperElement: function(){return this.display.wrapper;},
getScrollerElement: function(){return this.display.scroller;},
getGutterElement: function(){return this.display.gutters;}
};
eventMixin(CodeMirror);
// OPTION DEFAULTS
// The default configuration options.
var defaults = CodeMirror.defaults = {};
// Functions to run when options are changed.
var optionHandlers = CodeMirror.optionHandlers = {};
function option(name, deflt, handle, notOnInit) {
CodeMirror.defaults[name] = deflt;
if (handle) optionHandlers[name] =
notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
}
// Passed to option handlers when there is no old value.
var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
// These two are, on init, called from the constructor because they
// have to be initialized before the editor can start at all.
option("value", "", function(cm, val) {
cm.setValue(val);
}, true);
option("mode", null, function(cm, val) {
cm.doc.modeOption = val;
loadMode(cm);
}, true);
option("indentUnit", 2, loadMode, true);
option("indentWithTabs", false);
option("smartIndent", true);
option("tabSize", 4, function(cm) {
resetModeState(cm);
clearCaches(cm);
regChange(cm);
}, true);
option("lineSeparator", null, function(cm, val) {
cm.doc.lineSep = val;
if (!val) return;
var newBreaks = [], lineNo = cm.doc.first;
cm.doc.iter(function(line) {
for (var pos = 0;;) {
var found = line.text.indexOf(val, pos);
if (found == -1) break;
pos = found + val.length;
newBreaks.push(Pos(lineNo, found));
}
lineNo++;
});
for (var i = newBreaks.length - 1; i >= 0; i--)
replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length))
});
option("specialChars", /[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val, old) {
cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
if (old != CodeMirror.Init) cm.refresh();
});
option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {cm.refresh();}, true);
option("electricChars", true);
option("inputStyle", mobile ? "contenteditable" : "textarea", function() {
throw new Error("inputStyle can not (yet) be changed in a running editor"); // FIXME
}, true);
option("rtlMoveVisually", !windows);
option("wholeLineUpdateBefore", true);
option("theme", "default", function(cm) {
themeChanged(cm);
guttersChanged(cm);
}, true);
option("keyMap", "default", function(cm, val, old) {
var next = getKeyMap(val);
var prev = old != CodeMirror.Init && getKeyMap(old);
if (prev && prev.detach) prev.detach(cm, next);
if (next.attach) next.attach(cm, prev || null);
});
option("extraKeys", null);
option("lineWrapping", false, wrappingChanged, true);
option("gutters", [], function(cm) {
setGuttersForLineNumbers(cm.options);
guttersChanged(cm);
}, true);
option("fixedGutter", true, function(cm, val) {
cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
cm.refresh();
}, true);
option("coverGutterNextToScrollbar", false, function(cm) {updateScrollbars(cm);}, true);
option("scrollbarStyle", "native", function(cm) {
initScrollbars(cm);
updateScrollbars(cm);
cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
}, true);
option("lineNumbers", false, function(cm) {
setGuttersForLineNumbers(cm.options);
guttersChanged(cm);
}, true);
option("firstLineNumber", 1, guttersChanged, true);
option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
option("showCursorWhenSelecting", false, updateSelection, true);
option("resetSelectionOnContextMenu", true);
option("lineWiseCopyCut", true);
option("readOnly", false, function(cm, val) {
if (val == "nocursor") {
onBlur(cm);
cm.display.input.blur();
cm.display.disabled = true;
} else {
cm.display.disabled = false;
}
cm.display.input.readOnlyChanged(val)
});
option("disableInput", false, function(cm, val) {if (!val) cm.display.input.reset();}, true);
option("dragDrop", true, dragDropChanged);
option("allowDropFileTypes", null);
option("cursorBlinkRate", 530);
option("cursorScrollMargin", 0);
option("cursorHeight", 1, updateSelection, true);
option("singleCursorHeightPerLine", true, updateSelection, true);
option("workTime", 100);
option("workDelay", 100);
option("flattenSpans", true, resetModeState, true);
option("addModeClass", false, resetModeState, true);
option("pollInterval", 100);
option("undoDepth", 200, function(cm, val){cm.doc.history.undoDepth = val;});
option("historyEventDelay", 1250);
option("viewportMargin", 10, function(cm){cm.refresh();}, true);
option("maxHighlightLength", 10000, resetModeState, true);
option("moveInputWithCursor", true, function(cm, val) {
if (!val) cm.display.input.resetPosition();
});
option("tabindex", null, function(cm, val) {
cm.display.input.getField().tabIndex = val || "";
});
option("autofocus", null);
// MODE DEFINITION AND QUERYING
// Known modes, by name and by MIME
var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
// Extra arguments are stored as the mode's dependencies, which is
// used by (legacy) mechanisms like loadmode.js to automatically
// load a mode. (Preferred mechanism is the require/define calls.)
CodeMirror.defineMode = function(name, mode) {
if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
if (arguments.length > 2)
mode.dependencies = Array.prototype.slice.call(arguments, 2);
modes[name] = mode;
};
CodeMirror.defineMIME = function(mime, spec) {
mimeModes[mime] = spec;
};
// Given a MIME type, a {name, ...options} config object, or a name
// string, return a mode config object.
CodeMirror.resolveMode = function(spec) {
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
spec = mimeModes[spec];
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
var found = mimeModes[spec.name];
if (typeof found == "string") found = {name: found};
spec = createObj(found, spec);
spec.name = found.name;
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
return CodeMirror.resolveMode("application/xml");
}
if (typeof spec == "string") return {name: spec};
else return spec || {name: "null"};
};
// Given a mode spec (anything that resolveMode accepts), find and
// initialize an actual mode object.
CodeMirror.getMode = function(options, spec) {
var spec = CodeMirror.resolveMode(spec);
var mfactory = modes[spec.name];
if (!mfactory) return CodeMirror.getMode(options, "text/plain");
var modeObj = mfactory(options, spec);
if (modeExtensions.hasOwnProperty(spec.name)) {
var exts = modeExtensions[spec.name];
for (var prop in exts) {
if (!exts.hasOwnProperty(prop)) continue;
if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
modeObj[prop] = exts[prop];
}
}
modeObj.name = spec.name;
if (spec.helperType) modeObj.helperType = spec.helperType;
if (spec.modeProps) for (var prop in spec.modeProps)
modeObj[prop] = spec.modeProps[prop];
return modeObj;
};
// Minimal default mode.
CodeMirror.defineMode("null", function() {
return {token: function(stream) {stream.skipToEnd();}};
});
CodeMirror.defineMIME("text/plain", "null");
// This can be used to attach properties to mode objects from
// outside the actual mode definition.
var modeExtensions = CodeMirror.modeExtensions = {};
CodeMirror.extendMode = function(mode, properties) {
var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
copyObj(properties, exts);
};
// EXTENSIONS
CodeMirror.defineExtension = function(name, func) {
CodeMirror.prototype[name] = func;
};
CodeMirror.defineDocExtension = function(name, func) {
Doc.prototype[name] = func;
};
CodeMirror.defineOption = option;
var initHooks = [];
CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
var helpers = CodeMirror.helpers = {};
CodeMirror.registerHelper = function(type, name, value) {
if (!helpers.hasOwnProperty(type)) helpers[type] = CodeMirror[type] = {_global: []};
helpers[type][name] = value;
};
CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
CodeMirror.registerHelper(type, name, value);
helpers[type]._global.push({pred: predicate, val: value});
};
// MODE STATE HANDLING
// Utility functions for working with state. Exported because nested
// modes need to do this for their inner modes.
var copyState = CodeMirror.copyState = function(mode, state) {
if (state === true) return state;
if (mode.copyState) return mode.copyState(state);
var nstate = {};
for (var n in state) {
var val = state[n];
if (val instanceof Array) val = val.concat([]);
nstate[n] = val;
}
return nstate;
};
var startState = CodeMirror.startState = function(mode, a1, a2) {
return mode.startState ? mode.startState(a1, a2) : true;
};
// Given a mode and a state (for that mode), find the inner mode and
// state at the position that the state refers to.
CodeMirror.innerMode = function(mode, state) {
while (mode.innerMode) {
var info = mode.innerMode(state);
if (!info || info.mode == mode) break;
state = info.state;
mode = info.mode;
}
return info || {mode: mode, state: state};
};
// STANDARD COMMANDS
// Commands are parameter-less actions that can be performed on an
// editor, mostly used for keybindings.
var commands = CodeMirror.commands = {
selectAll: function(cm) {cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);},
singleSelection: function(cm) {
cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll);
},
killLine: function(cm) {
deleteNearSelection(cm, function(range) {
if (range.empty()) {
var len = getLine(cm.doc, range.head.line).text.length;
if (range.head.ch == len && range.head.line < cm.lastLine())
return {from: range.head, to: Pos(range.head.line + 1, 0)};
else
return {from: range.head, to: Pos(range.head.line, len)};
} else {
return {from: range.from(), to: range.to()};
}
});
},
deleteLine: function(cm) {
deleteNearSelection(cm, function(range) {
return {from: Pos(range.from().line, 0),
to: clipPos(cm.doc, Pos(range.to().line + 1, 0))};
});
},
delLineLeft: function(cm) {
deleteNearSelection(cm, function(range) {
return {from: Pos(range.from().line, 0), to: range.from()};
});
},
delWrappedLineLeft: function(cm) {
deleteNearSelection(cm, function(range) {
var top = cm.charCoords(range.head, "div").top + 5;
var leftPos = cm.coordsChar({left: 0, top: top}, "div");
return {from: leftPos, to: range.from()};
});
},
delWrappedLineRight: function(cm) {
deleteNearSelection(cm, function(range) {
var top = cm.charCoords(range.head, "div").top + 5;
var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
return {from: range.from(), to: rightPos };
});
},
undo: function(cm) {cm.undo();},
redo: function(cm) {cm.redo();},
undoSelection: function(cm) {cm.undoSelection();},
redoSelection: function(cm) {cm.redoSelection();},
goDocStart: function(cm) {cm.extendSelection(Pos(cm.firstLine(), 0));},
goDocEnd: function(cm) {cm.extendSelection(Pos(cm.lastLine()));},
goLineStart: function(cm) {
cm.extendSelectionsBy(function(range) { return lineStart(cm, range.head.line); },
{origin: "+move", bias: 1});
},
goLineStartSmart: function(cm) {
cm.extendSelectionsBy(function(range) {
return lineStartSmart(cm, range.head);
}, {origin: "+move", bias: 1});
},
goLineEnd: function(cm) {
cm.extendSelectionsBy(function(range) { return lineEnd(cm, range.head.line); },
{origin: "+move", bias: -1});
},
goLineRight: function(cm) {
cm.extendSelectionsBy(function(range) {
var top = cm.charCoords(range.head, "div").top + 5;
return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
}, sel_move);
},
goLineLeft: function(cm) {
cm.extendSelectionsBy(function(range) {
var top = cm.charCoords(range.head, "div").top + 5;
return cm.coordsChar({left: 0, top: top}, "div");
}, sel_move);
},
goLineLeftSmart: function(cm) {
cm.extendSelectionsBy(function(range) {
var top = cm.charCoords(range.head, "div").top + 5;
var pos = cm.coordsChar({left: 0, top: top}, "div");
if (pos.ch < cm.getLine(pos.line).search(/\S/)) return lineStartSmart(cm, range.head);
return pos;
}, sel_move);
},
goLineUp: function(cm) {cm.moveV(-1, "line");},
goLineDown: function(cm) {cm.moveV(1, "line");},
goPageUp: function(cm) {cm.moveV(-1, "page");},
goPageDown: function(cm) {cm.moveV(1, "page");},
goCharLeft: function(cm) {cm.moveH(-1, "char");},
goCharRight: function(cm) {cm.moveH(1, "char");},
goColumnLeft: function(cm) {cm.moveH(-1, "column");},
goColumnRight: function(cm) {cm.moveH(1, "column");},
goWordLeft: function(cm) {cm.moveH(-1, "word");},
goGroupRight: function(cm) {cm.moveH(1, "group");},
goGroupLeft: function(cm) {cm.moveH(-1, "group");},
goWordRight: function(cm) {cm.moveH(1, "word");},
delCharBefore: function(cm) {cm.deleteH(-1, "char");},
delCharAfter: function(cm) {cm.deleteH(1, "char");},
delWordBefore: function(cm) {cm.deleteH(-1, "word");},
delWordAfter: function(cm) {cm.deleteH(1, "word");},
delGroupBefore: function(cm) {cm.deleteH(-1, "group");},
delGroupAfter: function(cm) {cm.deleteH(1, "group");},
indentAuto: function(cm) {cm.indentSelection("smart");},
indentMore: function(cm) {cm.indentSelection("add");},
indentLess: function(cm) {cm.indentSelection("subtract");},
insertTab: function(cm) {cm.replaceSelection("\t");},
insertSoftTab: function(cm) {
var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
for (var i = 0; i < ranges.length; i++) {
var pos = ranges[i].from();
var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
spaces.push(new Array(tabSize - col % tabSize + 1).join(" "));
}
cm.replaceSelections(spaces);
},
defaultTab: function(cm) {
if (cm.somethingSelected()) cm.indentSelection("add");
else cm.execCommand("insertTab");
},
transposeChars: function(cm) {
runInOp(cm, function() {
var ranges = cm.listSelections(), newSel = [];
for (var i = 0; i < ranges.length; i++) {
var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
if (line) {
if (cur.ch == line.length) cur = new Pos(cur.line, cur.ch - 1);
if (cur.ch > 0) {
cur = new Pos(cur.line, cur.ch + 1);
cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
Pos(cur.line, cur.ch - 2), cur, "+transpose");
} else if (cur.line > cm.doc.first) {
var prev = getLine(cm.doc, cur.line - 1).text;
if (prev)
cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
prev.charAt(prev.length - 1),
Pos(cur.line - 1, prev.length - 1), Pos(cur.line, 1), "+transpose");
}
}
newSel.push(new Range(cur, cur));
}
cm.setSelections(newSel);
});
},
newlineAndIndent: function(cm) {
runInOp(cm, function() {
var len = cm.listSelections().length;
for (var i = 0; i < len; i++) {
var range = cm.listSelections()[i];
cm.replaceRange(cm.doc.lineSeparator(), range.anchor, range.head, "+input");
cm.indentLine(range.from().line + 1, null, true);
}
ensureCursorVisible(cm);
});
},
toggleOverwrite: function(cm) {cm.toggleOverwrite();}
};
// STANDARD KEYMAPS
var keyMap = CodeMirror.keyMap = {};
keyMap.basic = {
"Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
"End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
"Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
"Tab": "defaultTab", "Shift-Tab": "indentAuto",
"Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
"Esc": "singleSelection"
};
// Note that the save and find-related commands aren't defined by
// default. User code or addons can define them. Unknown commands
// are simply ignored.
keyMap.pcDefault = {
"Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
"Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
"Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
"Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
"Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
"Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
"Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
fallthrough: "basic"
};
// Very basic readline/emacs-style bindings, which are standard on Mac.
keyMap.emacsy = {
"Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
"Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
"Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
"Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
};
keyMap.macDefault = {
"Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
"Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
"Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
"Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
"Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
"Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
"Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
fallthrough: ["basic", "emacsy"]
};
keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
// KEYMAP DISPATCH
function normalizeKeyName(name) {
var parts = name.split(/-(?!$)/), name = parts[parts.length - 1];
var alt, ctrl, shift, cmd;
for (var i = 0; i < parts.length - 1; i++) {
var mod = parts[i];
if (/^(cmd|meta|m)$/i.test(mod)) cmd = true;
else if (/^a(lt)?$/i.test(mod)) alt = true;
else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true;
else if (/^s(hift)$/i.test(mod)) shift = true;
else throw new Error("Unrecognized modifier name: " + mod);
}
if (alt) name = "Alt-" + name;
if (ctrl) name = "Ctrl-" + name;
if (cmd) name = "Cmd-" + name;
if (shift) name = "Shift-" + name;
return name;
}
// This is a kludge to keep keymaps mostly working as raw objects
// (backwards compatibility) while at the same time support features
// like normalization and multi-stroke key bindings. It compiles a
// new normalized keymap, and then updates the old object to reflect
// this.
CodeMirror.normalizeKeyMap = function(keymap) {
var copy = {};
for (var keyname in keymap) if (keymap.hasOwnProperty(keyname)) {
var value = keymap[keyname];
if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) continue;
if (value == "...") { delete keymap[keyname]; continue; }
var keys = map(keyname.split(" "), normalizeKeyName);
for (var i = 0; i < keys.length; i++) {
var val, name;
if (i == keys.length - 1) {
name = keys.join(" ");
val = value;
} else {
name = keys.slice(0, i + 1).join(" ");
val = "...";
}
var prev = copy[name];
if (!prev) copy[name] = val;
else if (prev != val) throw new Error("Inconsistent bindings for " + name);
}
delete keymap[keyname];
}
for (var prop in copy) keymap[prop] = copy[prop];
return keymap;
};
var lookupKey = CodeMirror.lookupKey = function(key, map, handle, context) {
map = getKeyMap(map);
var found = map.call ? map.call(key, context) : map[key];
if (found === false) return "nothing";
if (found === "...") return "multi";
if (found != null && handle(found)) return "handled";
if (map.fallthrough) {
if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
return lookupKey(key, map.fallthrough, handle, context);
for (var i = 0; i < map.fallthrough.length; i++) {
var result = lookupKey(key, map.fallthrough[i], handle, context);
if (result) return result;
}
}
};
// Modifier key presses don't count as 'real' key presses for the
// purpose of keymap fallthrough.
var isModifierKey = CodeMirror.isModifierKey = function(value) {
var name = typeof value == "string" ? value : keyNames[value.keyCode];
return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
};
// Look up the name of a key as indicated by an event object.
var keyName = CodeMirror.keyName = function(event, noShift) {
if (presto && event.keyCode == 34 && event["char"]) return false;
var base = keyNames[event.keyCode], name = base;
if (name == null || event.altGraphKey) return false;
if (event.altKey && base != "Alt") name = "Alt-" + name;
if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") name = "Ctrl-" + name;
if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") name = "Cmd-" + name;
if (!noShift && event.shiftKey && base != "Shift") name = "Shift-" + name;
return name;
};
function getKeyMap(val) {
return typeof val == "string" ? keyMap[val] : val;
}
// FROMTEXTAREA
CodeMirror.fromTextArea = function(textarea, options) {
options = options ? copyObj(options) : {};
options.value = textarea.value;
if (!options.tabindex && textarea.tabIndex)
options.tabindex = textarea.tabIndex;
if (!options.placeholder && textarea.placeholder)
options.placeholder = textarea.placeholder;
// Set autofocus to true if this textarea is focused, or if it has
// autofocus and no other element is focused.
if (options.autofocus == null) {
var hasFocus = activeElt();
options.autofocus = hasFocus == textarea ||
textarea.getAttribute("autofocus") != null && hasFocus == document.body;
}
function save() {textarea.value = cm.getValue();}
if (textarea.form) {
on(textarea.form, "submit", save);
// Deplorable hack to make the submit method do the right thing.
if (!options.leaveSubmitMethodAlone) {
var form = textarea.form, realSubmit = form.submit;
try {
var wrappedSubmit = form.submit = function() {
save();
form.submit = realSubmit;
form.submit();
form.submit = wrappedSubmit;
};
} catch(e) {}
}
}
options.finishInit = function(cm) {
cm.save = save;
cm.getTextArea = function() { return textarea; };
cm.toTextArea = function() {
cm.toTextArea = isNaN; // Prevent this from being ran twice
save();
textarea.parentNode.removeChild(cm.getWrapperElement());
textarea.style.display = "";
if (textarea.form) {
off(textarea.form, "submit", save);
if (typeof textarea.form.submit == "function")
textarea.form.submit = realSubmit;
}
};
};
textarea.style.display = "none";
var cm = CodeMirror(function(node) {
textarea.parentNode.insertBefore(node, textarea.nextSibling);
}, options);
return cm;
};
// STRING STREAM
// Fed to the mode parsers, provides helper functions to make
// parsers more succinct.
var StringStream = CodeMirror.StringStream = function(string, tabSize) {
this.pos = this.start = 0;
this.string = string;
this.tabSize = tabSize || 8;
this.lastColumnPos = this.lastColumnValue = 0;
this.lineStart = 0;
};
StringStream.prototype = {
eol: function() {return this.pos >= this.string.length;},
sol: function() {return this.pos == this.lineStart;},
peek: function() {return this.string.charAt(this.pos) || undefined;},
next: function() {
if (this.pos < this.string.length)
return this.string.charAt(this.pos++);
},
eat: function(match) {
var ch = this.string.charAt(this.pos);
if (typeof match == "string") var ok = ch == match;
else var ok = ch && (match.test ? match.test(ch) : match(ch));
if (ok) {++this.pos; return ch;}
},
eatWhile: function(match) {
var start = this.pos;
while (this.eat(match)){}
return this.pos > start;
},
eatSpace: function() {
var start = this.pos;
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
return this.pos > start;
},
skipToEnd: function() {this.pos = this.string.length;},
skipTo: function(ch) {
var found = this.string.indexOf(ch, this.pos);
if (found > -1) {this.pos = found; return true;}
},
backUp: function(n) {this.pos -= n;},
column: function() {
if (this.lastColumnPos < this.start) {
this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
this.lastColumnPos = this.start;
}
return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
},
indentation: function() {
return countColumn(this.string, null, this.tabSize) -
(this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
},
match: function(pattern, consume, caseInsensitive) {
if (typeof pattern == "string") {
var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
var substr = this.string.substr(this.pos, pattern.length);
if (cased(substr) == cased(pattern)) {
if (consume !== false) this.pos += pattern.length;
return true;
}
} else {
var match = this.string.slice(this.pos).match(pattern);
if (match && match.index > 0) return null;
if (match && consume !== false) this.pos += match[0].length;
return match;
}
},
current: function(){return this.string.slice(this.start, this.pos);},
hideFirstChars: function(n, inner) {
this.lineStart += n;
try { return inner(); }
finally { this.lineStart -= n; }
}
};
// TEXTMARKERS
// Created with markText and setBookmark methods. A TextMarker is a
// handle that can be used to clear or find a marked position in the
// document. Line objects hold arrays (markedSpans) containing
// {from, to, marker} object pointing to such marker objects, and
// indicating that such a marker is present on that line. Multiple
// lines may point to the same marker when it spans across lines.
// The spans will have null for their from/to properties when the
// marker continues beyond the start/end of the line. Markers have
// links back to the lines they currently touch.
var nextMarkerId = 0;
var TextMarker = CodeMirror.TextMarker = function(doc, type) {
this.lines = [];
this.type = type;
this.doc = doc;
this.id = ++nextMarkerId;
};
eventMixin(TextMarker);
// Clear the marker.
TextMarker.prototype.clear = function() {
if (this.explicitlyCleared) return;
var cm = this.doc.cm, withOp = cm && !cm.curOp;
if (withOp) startOperation(cm);
if (hasHandler(this, "clear")) {
var found = this.find();
if (found) signalLater(this, "clear", found.from, found.to);
}
var min = null, max = null;
for (var i = 0; i < this.lines.length; ++i) {
var line = this.lines[i];
var span = getMarkedSpanFor(line.markedSpans, this);
if (cm && !this.collapsed) regLineChange(cm, lineNo(line), "text");
else if (cm) {
if (span.to != null) max = lineNo(line);
if (span.from != null) min = lineNo(line);
}
line.markedSpans = removeMarkedSpan(line.markedSpans, span);
if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm)
updateLineHeight(line, textHeight(cm.display));
}
if (cm && this.collapsed && !cm.options.lineWrapping) for (var i = 0; i < this.lines.length; ++i) {
var visual = visualLine(this.lines[i]), len = lineLength(visual);
if (len > cm.display.maxLineLength) {
cm.display.maxLine = visual;
cm.display.maxLineLength = len;
cm.display.maxLineChanged = true;
}
}
if (min != null && cm && this.collapsed) regChange(cm, min, max + 1);
this.lines.length = 0;
this.explicitlyCleared = true;
if (this.atomic && this.doc.cantEdit) {
this.doc.cantEdit = false;
if (cm) reCheckSelection(cm.doc);
}
if (cm) signalLater(cm, "markerCleared", cm, this);
if (withOp) endOperation(cm);
if (this.parent) this.parent.clear();
};
// Find the position of the marker in the document. Returns a {from,
// to} object by default. Side can be passed to get a specific side
// -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
// Pos objects returned contain a line object, rather than a line
// number (used to prevent looking up the same line twice).
TextMarker.prototype.find = function(side, lineObj) {
if (side == null && this.type == "bookmark") side = 1;
var from, to;
for (var i = 0; i < this.lines.length; ++i) {
var line = this.lines[i];
var span = getMarkedSpanFor(line.markedSpans, this);
if (span.from != null) {
from = Pos(lineObj ? line : lineNo(line), span.from);
if (side == -1) return from;
}
if (span.to != null) {
to = Pos(lineObj ? line : lineNo(line), span.to);
if (side == 1) return to;
}
}
return from && {from: from, to: to};
};
// Signals that the marker's widget changed, and surrounding layout
// should be recomputed.
TextMarker.prototype.changed = function() {
var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
if (!pos || !cm) return;
runInOp(cm, function() {
var line = pos.line, lineN = lineNo(pos.line);
var view = findViewForLine(cm, lineN);
if (view) {
clearLineMeasurementCacheFor(view);
cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
}
cm.curOp.updateMaxLine = true;
if (!lineIsHidden(widget.doc, line) && widget.height != null) {
var oldHeight = widget.height;
widget.height = null;
var dHeight = widgetHeight(widget) - oldHeight;
if (dHeight)
updateLineHeight(line, line.height + dHeight);
}
});
};
TextMarker.prototype.attachLine = function(line) {
if (!this.lines.length && this.doc.cm) {
var op = this.doc.cm.curOp;
if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
(op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);
}
this.lines.push(line);
};
TextMarker.prototype.detachLine = function(line) {
this.lines.splice(indexOf(this.lines, line), 1);
if (!this.lines.length && this.doc.cm) {
var op = this.doc.cm.curOp;
(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
}
};
// Collapsed markers have unique ids, in order to be able to order
// them, which is needed for uniquely determining an outer marker
// when they overlap (they may nest, but not partially overlap).
var nextMarkerId = 0;
// Create a marker, wire it up to the right lines, and
function markText(doc, from, to, options, type) {
// Shared markers (across linked documents) are handled separately
// (markTextShared will call out to this again, once per
// document).
if (options && options.shared) return markTextShared(doc, from, to, options, type);
// Ensure we are in an operation.
if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
var marker = new TextMarker(doc, type), diff = cmp(from, to);
if (options) copyObj(options, marker, false);
// Don't connect empty markers unless clearWhenEmpty is false
if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
return marker;
if (marker.replacedWith) {
// Showing up as a widget implies collapsed (widget replaces text)
marker.collapsed = true;
marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget");
if (!options.handleMouseEvents) marker.widgetNode.setAttribute("cm-ignore-events", "true");
if (options.insertLeft) marker.widgetNode.insertLeft = true;
}
if (marker.collapsed) {
if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
throw new Error("Inserting collapsed marker partially overlapping an existing one");
sawCollapsedSpans = true;
}
if (marker.addToHistory)
addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN);
var curLine = from.line, cm = doc.cm, updateMaxLine;
doc.iter(curLine, to.line + 1, function(line) {
if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
updateMaxLine = true;
if (marker.collapsed && curLine != from.line) updateLineHeight(line, 0);
addMarkedSpan(line, new MarkedSpan(marker,
curLine == from.line ? from.ch : null,
curLine == to.line ? to.ch : null));
++curLine;
});
// lineIsHidden depends on the presence of the spans, so needs a second pass
if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
});
if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); });
if (marker.readOnly) {
sawReadOnlySpans = true;
if (doc.history.done.length || doc.history.undone.length)
doc.clearHistory();
}
if (marker.collapsed) {
marker.id = ++nextMarkerId;
marker.atomic = true;
}
if (cm) {
// Sync editor state
if (updateMaxLine) cm.curOp.updateMaxLine = true;
if (marker.collapsed)
regChange(cm, from.line, to.line + 1);
else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css)
for (var i = from.line; i <= to.line; i++) regLineChange(cm, i, "text");
if (marker.atomic) reCheckSelection(cm.doc);
signalLater(cm, "markerAdded", cm, marker);
}
return marker;
}
// SHARED TEXTMARKERS
// A shared marker spans multiple linked documents. It is
// implemented as a meta-marker-object controlling multiple normal
// markers.
var SharedTextMarker = CodeMirror.SharedTextMarker = function(markers, primary) {
this.markers = markers;
this.primary = primary;
for (var i = 0; i < markers.length; ++i)
markers[i].parent = this;
};
eventMixin(SharedTextMarker);
SharedTextMarker.prototype.clear = function() {
if (this.explicitlyCleared) return;
this.explicitlyCleared = true;
for (var i = 0; i < this.markers.length; ++i)
this.markers[i].clear();
signalLater(this, "clear");
};
SharedTextMarker.prototype.find = function(side, lineObj) {
return this.primary.find(side, lineObj);
};
function markTextShared(doc, from, to, options, type) {
options = copyObj(options);
options.shared = false;
var markers = [markText(doc, from, to, options, type)], primary = markers[0];
var widget = options.widgetNode;
linkedDocs(doc, function(doc) {
if (widget) options.widgetNode = widget.cloneNode(true);
markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
for (var i = 0; i < doc.linked.length; ++i)
if (doc.linked[i].isParent) return;
primary = lst(markers);
});
return new SharedTextMarker(markers, primary);
}
function findSharedMarkers(doc) {
return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())),
function(m) { return m.parent; });
}
function copySharedMarkers(doc, markers) {
for (var i = 0; i < markers.length; i++) {
var marker = markers[i], pos = marker.find();
var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
if (cmp(mFrom, mTo)) {
var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
marker.markers.push(subMark);
subMark.parent = marker;
}
}
}
function detachSharedMarkers(markers) {
for (var i = 0; i < markers.length; i++) {
var marker = markers[i], linked = [marker.primary.doc];;
linkedDocs(marker.primary.doc, function(d) { linked.push(d); });
for (var j = 0; j < marker.markers.length; j++) {
var subMarker = marker.markers[j];
if (indexOf(linked, subMarker.doc) == -1) {
subMarker.parent = null;
marker.markers.splice(j--, 1);
}
}
}
}
// TEXTMARKER SPANS
function MarkedSpan(marker, from, to) {
this.marker = marker;
this.from = from; this.to = to;
}
// Search an array of spans for a span matching the given marker.
function getMarkedSpanFor(spans, marker) {
if (spans) for (var i = 0; i < spans.length; ++i) {
var span = spans[i];
if (span.marker == marker) return span;
}
}
// Remove a span from an array, returning undefined if no spans are
// left (we don't store arrays for lines without spans).
function removeMarkedSpan(spans, span) {
for (var r, i = 0; i < spans.length; ++i)
if (spans[i] != span) (r || (r = [])).push(spans[i]);
return r;
}
// Add a span to a line.
function addMarkedSpan(line, span) {
line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
span.marker.attachLine(line);
}
// Used for the algorithm that adjusts markers for a change in the
// document. These functions cut an array of spans at a given
// character position, returning an array of remaining chunks (or
// undefined if nothing remains).
function markedSpansBefore(old, startCh, isInsert) {
if (old) for (var i = 0, nw; i < old.length; ++i) {
var span = old[i], marker = span.marker;
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
}
}
return nw;
}
function markedSpansAfter(old, endCh, isInsert) {
if (old) for (var i = 0, nw; i < old.length; ++i) {
var span = old[i], marker = span.marker;
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
span.to == null ? null : span.to - endCh));
}
}
return nw;
}
// Given a change object, compute the new set of marker spans that
// cover the line in which the change took place. Removes spans
// entirely within the change, reconnects spans belonging to the
// same marker that appear on both sides of the change, and cuts off
// spans partially within the change. Returns an array of span
// arrays with one element for each line in (after) the change.
function stretchSpansOverChange(doc, change) {
if (change.full) return null;
var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
if (!oldFirst && !oldLast) return null;
var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
// Get the spans that 'stick out' on both sides
var first = markedSpansBefore(oldFirst, startCh, isInsert);
var last = markedSpansAfter(oldLast, endCh, isInsert);
// Next, merge those two ends
var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
if (first) {
// Fix up .to properties of first
for (var i = 0; i < first.length; ++i) {
var span = first[i];
if (span.to == null) {
var found = getMarkedSpanFor(last, span.marker);
if (!found) span.to = startCh;
else if (sameLine) span.to = found.to == null ? null : found.to + offset;
}
}
}
if (last) {
// Fix up .from in last (or move them into first in case of sameLine)
for (var i = 0; i < last.length; ++i) {
var span = last[i];
if (span.to != null) span.to += offset;
if (span.from == null) {
var found = getMarkedSpanFor(first, span.marker);
if (!found) {
span.from = offset;
if (sameLine) (first || (first = [])).push(span);
}
} else {
span.from += offset;
if (sameLine) (first || (first = [])).push(span);
}
}
}
// Make sure we didn't create any zero-length spans
if (first) first = clearEmptySpans(first);
if (last && last != first) last = clearEmptySpans(last);
var newMarkers = [first];
if (!sameLine) {
// Fill gap with whole-line-spans
var gap = change.text.length - 2, gapMarkers;
if (gap > 0 && first)
for (var i = 0; i < first.length; ++i)
if (first[i].to == null)
(gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i].marker, null, null));
for (var i = 0; i < gap; ++i)
newMarkers.push(gapMarkers);
newMarkers.push(last);
}
return newMarkers;
}
// Remove spans that are empty and don't have a clearWhenEmpty
// option of false.
function clearEmptySpans(spans) {
for (var i = 0; i < spans.length; ++i) {
var span = spans[i];
if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
spans.splice(i--, 1);
}
if (!spans.length) return null;
return spans;
}
// Used for un/re-doing changes from the history. Combines the
// result of computing the existing spans with the set of spans that
// existed in the history (so that deleting around a span and then
// undoing brings back the span).
function mergeOldSpans(doc, change) {
var old = getOldSpans(doc, change);
var stretched = stretchSpansOverChange(doc, change);
if (!old) return stretched;
if (!stretched) return old;
for (var i = 0; i < old.length; ++i) {
var oldCur = old[i], stretchCur = stretched[i];
if (oldCur && stretchCur) {
spans: for (var j = 0; j < stretchCur.length; ++j) {
var span = stretchCur[j];
for (var k = 0; k < oldCur.length; ++k)
if (oldCur[k].marker == span.marker) continue spans;
oldCur.push(span);
}
} else if (stretchCur) {
old[i] = stretchCur;
}
}
return old;
}
// Used to 'clip' out readOnly ranges when making a change.
function removeReadOnlyRanges(doc, from, to) {
var markers = null;
doc.iter(from.line, to.line + 1, function(line) {
if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
var mark = line.markedSpans[i].marker;
if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
(markers || (markers = [])).push(mark);
}
});
if (!markers) return null;
var parts = [{from: from, to: to}];
for (var i = 0; i < markers.length; ++i) {
var mk = markers[i], m = mk.find(0);
for (var j = 0; j < parts.length; ++j) {
var p = parts[j];
if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) continue;
var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
newParts.push({from: p.from, to: m.from});
if (dto > 0 || !mk.inclusiveRight && !dto)
newParts.push({from: m.to, to: p.to});
parts.splice.apply(parts, newParts);
j += newParts.length - 1;
}
}
return parts;
}
// Connect or disconnect spans from a line.
function detachMarkedSpans(line) {
var spans = line.markedSpans;
if (!spans) return;
for (var i = 0; i < spans.length; ++i)
spans[i].marker.detachLine(line);
line.markedSpans = null;
}
function attachMarkedSpans(line, spans) {
if (!spans) return;
for (var i = 0; i < spans.length; ++i)
spans[i].marker.attachLine(line);
line.markedSpans = spans;
}
// Helpers used when computing which overlapping collapsed span
// counts as the larger one.
function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0; }
function extraRight(marker) { return marker.inclusiveRight ? 1 : 0; }
// Returns a number indicating which of two overlapping collapsed
// spans is larger (and thus includes the other). Falls back to
// comparing ids when the spans cover exactly the same range.
function compareCollapsedMarkers(a, b) {
var lenDiff = a.lines.length - b.lines.length;
if (lenDiff != 0) return lenDiff;
var aPos = a.find(), bPos = b.find();
var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
if (fromCmp) return -fromCmp;
var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
if (toCmp) return toCmp;
return b.id - a.id;
}
// Find out whether a line ends or starts in a collapsed span. If
// so, return the marker for that span.
function collapsedSpanAtSide(line, start) {
var sps = sawCollapsedSpans && line.markedSpans, found;
if (sps) for (var sp, i = 0; i < sps.length; ++i) {
sp = sps[i];
if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
(!found || compareCollapsedMarkers(found, sp.marker) < 0))
found = sp.marker;
}
return found;
}
function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true); }
function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false); }
// Test whether there exists a collapsed span that partially
// overlaps (covers the start or end, but not both) of a new span.
// Such overlap is not allowed.
function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
var line = getLine(doc, lineNo);
var sps = sawCollapsedSpans && line.markedSpans;
if (sps) for (var i = 0; i < sps.length; ++i) {
var sp = sps[i];
if (!sp.marker.collapsed) continue;
var found = sp.marker.find(0);
var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) continue;
if (fromCmp <= 0 && (cmp(found.to, from) > 0 || (sp.marker.inclusiveRight && marker.inclusiveLeft)) ||
fromCmp >= 0 && (cmp(found.from, to) < 0 || (sp.marker.inclusiveLeft && marker.inclusiveRight)))
return true;
}
}
// A visual line is a line as drawn on the screen. Folding, for
// example, can cause multiple logical lines to appear on the same
// visual line. This finds the start of the visual line that the
// given line is part of (usually that is the line itself).
function visualLine(line) {
var merged;
while (merged = collapsedSpanAtStart(line))
line = merged.find(-1, true).line;
return line;
}
// Returns an array of logical lines that continue the visual line
// started by the argument, or undefined if there are no such lines.
function visualLineContinued(line) {
var merged, lines;
while (merged = collapsedSpanAtEnd(line)) {
line = merged.find(1, true).line;
(lines || (lines = [])).push(line);
}
return lines;
}
// Get the line number of the start of the visual line that the
// given line number is part of.
function visualLineNo(doc, lineN) {
var line = getLine(doc, lineN), vis = visualLine(line);
if (line == vis) return lineN;
return lineNo(vis);
}
// Get the line number of the start of the next visual line after
// the given line.
function visualLineEndNo(doc, lineN) {
if (lineN > doc.lastLine()) return lineN;
var line = getLine(doc, lineN), merged;
if (!lineIsHidden(doc, line)) return lineN;
while (merged = collapsedSpanAtEnd(line))
line = merged.find(1, true).line;
return lineNo(line) + 1;
}
// Compute whether a line is hidden. Lines count as hidden when they
// are part of a visual line that starts with another line, or when
// they are entirely covered by collapsed, non-widget span.
function lineIsHidden(doc, line) {
var sps = sawCollapsedSpans && line.markedSpans;
if (sps) for (var sp, i = 0; i < sps.length; ++i) {
sp = sps[i];
if (!sp.marker.collapsed) continue;
if (sp.from == null) return true;
if (sp.marker.widgetNode) continue;
if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
return true;
}
}
function lineIsHiddenInner(doc, line, span) {
if (span.to == null) {
var end = span.marker.find(1, true);
return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker));
}
if (span.marker.inclusiveRight && span.to == line.text.length)
return true;
for (var sp, i = 0; i < line.markedSpans.length; ++i) {
sp = line.markedSpans[i];
if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
(sp.to == null || sp.to != span.from) &&
(sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
lineIsHiddenInner(doc, line, sp)) return true;
}
}
// LINE WIDGETS
// Line widgets are block elements displayed above or below a line.
var LineWidget = CodeMirror.LineWidget = function(doc, node, options) {
if (options) for (var opt in options) if (options.hasOwnProperty(opt))
this[opt] = options[opt];
this.doc = doc;
this.node = node;
};
eventMixin(LineWidget);
function adjustScrollWhenAboveVisible(cm, line, diff) {
if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
addToScrollPos(cm, null, diff);
}
LineWidget.prototype.clear = function() {
var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
if (no == null || !ws) return;
for (var i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1);
if (!ws.length) line.widgets = null;
var height = widgetHeight(this);
updateLineHeight(line, Math.max(0, line.height - height));
if (cm) runInOp(cm, function() {
adjustScrollWhenAboveVisible(cm, line, -height);
regLineChange(cm, no, "widget");
});
};
LineWidget.prototype.changed = function() {
var oldH = this.height, cm = this.doc.cm, line = this.line;
this.height = null;
var diff = widgetHeight(this) - oldH;
if (!diff) return;
updateLineHeight(line, line.height + diff);
if (cm) runInOp(cm, function() {
cm.curOp.forceUpdate = true;
adjustScrollWhenAboveVisible(cm, line, diff);
});
};
function widgetHeight(widget) {
if (widget.height != null) return widget.height;
var cm = widget.doc.cm;
if (!cm) return 0;
if (!contains(document.body, widget.node)) {
var parentStyle = "position: relative;";
if (widget.coverGutter)
parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;";
if (widget.noHScroll)
parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;";
removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
}
return widget.height = widget.node.parentNode.offsetHeight;
}
function addLineWidget(doc, handle, node, options) {
var widget = new LineWidget(doc, node, options);
var cm = doc.cm;
if (cm && widget.noHScroll) cm.display.alignWidgets = true;
changeLine(doc, handle, "widget", function(line) {
var widgets = line.widgets || (line.widgets = []);
if (widget.insertAt == null) widgets.push(widget);
else widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);
widget.line = line;
if (cm && !lineIsHidden(doc, line)) {
var aboveVisible = heightAtLine(line) < doc.scrollTop;
updateLineHeight(line, line.height + widgetHeight(widget));
if (aboveVisible) addToScrollPos(cm, null, widget.height);
cm.curOp.forceUpdate = true;
}
return true;
});
return widget;
}
// LINE DATA STRUCTURE
// Line objects. These hold state related to a line, including
// highlighting info (the styles array).
var Line = CodeMirror.Line = function(text, markedSpans, estimateHeight) {
this.text = text;
attachMarkedSpans(this, markedSpans);
this.height = estimateHeight ? estimateHeight(this) : 1;
};
eventMixin(Line);
Line.prototype.lineNo = function() { return lineNo(this); };
// Change the content (text, markers) of a line. Automatically
// invalidates cached information and tries to re-estimate the
// line's height.
function updateLine(line, text, markedSpans, estimateHeight) {
line.text = text;
if (line.stateAfter) line.stateAfter = null;
if (line.styles) line.styles = null;
if (line.order != null) line.order = null;
detachMarkedSpans(line);
attachMarkedSpans(line, markedSpans);
var estHeight = estimateHeight ? estimateHeight(line) : 1;
if (estHeight != line.height) updateLineHeight(line, estHeight);
}
// Detach a line from the document tree and its markers.
function cleanUpLine(line) {
line.parent = null;
detachMarkedSpans(line);
}
function extractLineClasses(type, output) {
if (type) for (;;) {
var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
if (!lineClass) break;
type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
var prop = lineClass[1] ? "bgClass" : "textClass";
if (output[prop] == null)
output[prop] = lineClass[2];
else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
output[prop] += " " + lineClass[2];
}
return type;
}
function callBlankLine(mode, state) {
if (mode.blankLine) return mode.blankLine(state);
if (!mode.innerMode) return;
var inner = CodeMirror.innerMode(mode, state);
if (inner.mode.blankLine) return inner.mode.blankLine(inner.state);
}
function readToken(mode, stream, state, inner) {
for (var i = 0; i < 10; i++) {
if (inner) inner[0] = CodeMirror.innerMode(mode, state).mode;
var style = mode.token(stream, state);
if (stream.pos > stream.start) return style;
}
throw new Error("Mode " + mode.name + " failed to advance stream.");
}
// Utility for getTokenAt and getLineTokens
function takeToken(cm, pos, precise, asArray) {
function getObj(copy) {
return {start: stream.start, end: stream.pos,
string: stream.current(),
type: style || null,
state: copy ? copyState(doc.mode, state) : state};
}
var doc = cm.doc, mode = doc.mode, style;
pos = clipPos(doc, pos);
var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise);
var stream = new StringStream(line.text, cm.options.tabSize), tokens;
if (asArray) tokens = [];
while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
stream.start = stream.pos;
style = readToken(mode, stream, state);
if (asArray) tokens.push(getObj(true));
}
return asArray ? tokens : getObj();
}
// Run the given mode's parser over a line, calling f for each token.
function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
var flattenSpans = mode.flattenSpans;
if (flattenSpans == null) flattenSpans = cm.options.flattenSpans;
var curStart = 0, curStyle = null;
var stream = new StringStream(text, cm.options.tabSize), style;
var inner = cm.options.addModeClass && [null];
if (text == "") extractLineClasses(callBlankLine(mode, state), lineClasses);
while (!stream.eol()) {
if (stream.pos > cm.options.maxHighlightLength) {
flattenSpans = false;
if (forceToEnd) processLine(cm, text, state, stream.pos);
stream.pos = text.length;
style = null;
} else {
style = extractLineClasses(readToken(mode, stream, state, inner), lineClasses);
}
if (inner) {
var mName = inner[0].name;
if (mName) style = "m-" + (style ? mName + " " + style : mName);
}
if (!flattenSpans || curStyle != style) {
while (curStart < stream.start) {
curStart = Math.min(stream.start, curStart + 50000);
f(curStart, curStyle);
}
curStyle = style;
}
stream.start = stream.pos;
}
while (curStart < stream.pos) {
// Webkit seems to refuse to render text nodes longer than 57444 characters
var pos = Math.min(stream.pos, curStart + 50000);
f(pos, curStyle);
curStart = pos;
}
}
// Compute a style array (an array starting with a mode generation
// -- for invalidation -- followed by pairs of end positions and
// style strings), which is used to highlight the tokens on the
// line.
function highlightLine(cm, line, state, forceToEnd) {
// A styles array always starts with a number identifying the
// mode/overlays that it is based on (for easy invalidation).
var st = [cm.state.modeGen], lineClasses = {};
// Compute the base array of styles
runMode(cm, line.text, cm.doc.mode, state, function(end, style) {
st.push(end, style);
}, lineClasses, forceToEnd);
// Run overlays, adjust style array.
for (var o = 0; o < cm.state.overlays.length; ++o) {
var overlay = cm.state.overlays[o], i = 1, at = 0;
runMode(cm, line.text, overlay.mode, true, function(end, style) {
var start = i;
// Ensure there's a token end at the current position, and that i points at it
while (at < end) {
var i_end = st[i];
if (i_end > end)
st.splice(i, 1, end, st[i+1], i_end);
i += 2;
at = Math.min(end, i_end);
}
if (!style) return;
if (overlay.opaque) {
st.splice(start, i - start, end, "cm-overlay " + style);
i = start + 2;
} else {
for (; start < i; start += 2) {
var cur = st[start+1];
st[start+1] = (cur ? cur + " " : "") + "cm-overlay " + style;
}
}
}, lineClasses);
}
return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null};
}
function getLineStyles(cm, line, updateFrontier) {
if (!line.styles || line.styles[0] != cm.state.modeGen) {
var state = getStateBefore(cm, lineNo(line));
var result = highlightLine(cm, line, line.text.length > cm.options.maxHighlightLength ? copyState(cm.doc.mode, state) : state);
line.stateAfter = state;
line.styles = result.styles;
if (result.classes) line.styleClasses = result.classes;
else if (line.styleClasses) line.styleClasses = null;
if (updateFrontier === cm.doc.frontier) cm.doc.frontier++;
}
return line.styles;
}
// Lightweight form of highlight -- proceed over this line and
// update state, but don't save a style array. Used for lines that
// aren't currently visible.
function processLine(cm, text, state, startAt) {
var mode = cm.doc.mode;
var stream = new StringStream(text, cm.options.tabSize);
stream.start = stream.pos = startAt || 0;
if (text == "") callBlankLine(mode, state);
while (!stream.eol()) {
readToken(mode, stream, state);
stream.start = stream.pos;
}
}
// Convert a style as returned by a mode (either null, or a string
// containing one or more styles) to a CSS style. This is cached,
// and also looks for line-wide styles.
var styleToClassCache = {}, styleToClassCacheWithMode = {};
function interpretTokenStyle(style, options) {
if (!style || /^\s*$/.test(style)) return null;
var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
return cache[style] ||
(cache[style] = style.replace(/\S+/g, "cm-$&"));
}
// Render the DOM representation of the text of a line. Also builds
// up a 'line map', which points at the DOM nodes that represent
// specific stretches of text, and is used by the measuring code.
// The returned object contains the DOM node, this map, and
// information about line-wide styles that were set by the mode.
function buildLineContent(cm, lineView) {
// The padding-right forces the element to have a 'border', which
// is needed on Webkit to be able to get line-level bounding
// rectangles for it (in measureChar).
var content = elt("span", null, null, webkit ? "padding-right: .1px" : null);
var builder = {pre: elt("pre", [content], "CodeMirror-line"), content: content,
col: 0, pos: 0, cm: cm,
splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")};
lineView.measure = {};
// Iterate over the logical lines that make up this visual line.
for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
var line = i ? lineView.rest[i - 1] : lineView.line, order;
builder.pos = 0;
builder.addToken = buildToken;
// Optionally wire in some hacks into the token-rendering
// algorithm, to deal with browser quirks.
if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line)))
builder.addToken = buildTokenBadBidi(builder.addToken, order);
builder.map = [];
var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
if (line.styleClasses) {
if (line.styleClasses.bgClass)
builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "");
if (line.styleClasses.textClass)
builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "");
}
// Ensure at least a single node is present, for measuring.
if (builder.map.length == 0)
builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)));
// Store the map and a cache object for the current logical line
if (i == 0) {
lineView.measure.map = builder.map;
lineView.measure.cache = {};
} else {
(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);
(lineView.measure.caches || (lineView.measure.caches = [])).push({});
}
}
// See issue #2901
if (webkit && /\bcm-tab\b/.test(builder.content.lastChild.className))
builder.content.className = "cm-tab-wrap-hack";
signal(cm, "renderLine", cm, lineView.line, builder.pre);
if (builder.pre.className)
builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
return builder;
}
function defaultSpecialCharPlaceholder(ch) {
var token = elt("span", "\u2022", "cm-invalidchar");
token.title = "\\u" + ch.charCodeAt(0).toString(16);
token.setAttribute("aria-label", token.title);
return token;
}
// Build up the DOM representation for a single token, and add it to
// the line map. Takes care to render special characters separately.
function buildToken(builder, text, style, startStyle, endStyle, title, css) {
if (!text) return;
var displayText = builder.splitSpaces ? text.replace(/ {3,}/g, splitSpaces) : text;
var special = builder.cm.state.specialChars, mustWrap = false;
if (!special.test(text)) {
builder.col += text.length;
var content = document.createTextNode(displayText);
builder.map.push(builder.pos, builder.pos + text.length, content);
if (ie && ie_version < 9) mustWrap = true;
builder.pos += text.length;
} else {
var content = document.createDocumentFragment(), pos = 0;
while (true) {
special.lastIndex = pos;
var m = special.exec(text);
var skipped = m ? m.index - pos : text.length - pos;
if (skipped) {
var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
else content.appendChild(txt);
builder.map.push(builder.pos, builder.pos + skipped, txt);
builder.col += skipped;
builder.pos += skipped;
}
if (!m) break;
pos += skipped + 1;
if (m[0] == "\t") {
var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
txt.setAttribute("role", "presentation");
txt.setAttribute("cm-text", "\t");
builder.col += tabWidth;
} else if (m[0] == "\r" || m[0] == "\n") {
var txt = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
txt.setAttribute("cm-text", m[0]);
builder.col += 1;
} else {
var txt = builder.cm.options.specialCharPlaceholder(m[0]);
txt.setAttribute("cm-text", m[0]);
if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
else content.appendChild(txt);
builder.col += 1;
}
builder.map.push(builder.pos, builder.pos + 1, txt);
builder.pos++;
}
}
if (style || startStyle || endStyle || mustWrap || css) {
var fullStyle = style || "";
if (startStyle) fullStyle += startStyle;
if (endStyle) fullStyle += endStyle;
var token = elt("span", [content], fullStyle, css);
if (title) token.title = title;
return builder.content.appendChild(token);
}
builder.content.appendChild(content);
}
function splitSpaces(old) {
var out = " ";
for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0";
out += " ";
return out;
}
// Work around nonsense dimensions being reported for stretches of
// right-to-left text.
function buildTokenBadBidi(inner, order) {
return function(builder, text, style, startStyle, endStyle, title, css) {
style = style ? style + " cm-force-border" : "cm-force-border";
var start = builder.pos, end = start + text.length;
for (;;) {
// Find the part that overlaps with the start of this text
for (var i = 0; i < order.length; i++) {
var part = order[i];
if (part.to > start && part.from <= start) break;
}
if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title, css);
inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css);
startStyle = null;
text = text.slice(part.to - start);
start = part.to;
}
};
}
function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
var widget = !ignoreWidget && marker.widgetNode;
if (widget) builder.map.push(builder.pos, builder.pos + size, widget);
if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
if (!widget)
widget = builder.content.appendChild(document.createElement("span"));
widget.setAttribute("cm-marker", marker.id);
}
if (widget) {
builder.cm.display.input.setUneditable(widget);
builder.content.appendChild(widget);
}
builder.pos += size;
}
// Outputs a number of spans to make up a line, taking highlighting
// and marked text into account.
function insertLineContent(line, builder, styles) {
var spans = line.markedSpans, allText = line.text, at = 0;
if (!spans) {
for (var i = 1; i < styles.length; i+=2)
builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options));
return;
}
var len = allText.length, pos = 0, i = 1, text = "", style, css;
var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed;
for (;;) {
if (nextChange == pos) { // Update current marker set
spanStyle = spanEndStyle = spanStartStyle = title = css = "";
collapsed = null; nextChange = Infinity;
var foundBookmarks = [], endStyles
for (var j = 0; j < spans.length; ++j) {
var sp = spans[j], m = sp.marker;
if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
foundBookmarks.push(m);
} else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
if (sp.to != null && sp.to != pos && nextChange > sp.to) {
nextChange = sp.to;
spanEndStyle = "";
}
if (m.className) spanStyle += " " + m.className;
if (m.css) css = (css ? css + ";" : "") + m.css;
if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
if (m.endStyle && sp.to == nextChange) (endStyles || (endStyles = [])).push(m.endStyle, sp.to)
if (m.title && !title) title = m.title;
if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
collapsed = sp;
} else if (sp.from > pos && nextChange > sp.from) {
nextChange = sp.from;
}
}
if (endStyles) for (var j = 0; j < endStyles.length; j += 2)
if (endStyles[j + 1] == nextChange) spanEndStyle += " " + endStyles[j]
if (!collapsed || collapsed.from == pos) for (var j = 0; j < foundBookmarks.length; ++j)
buildCollapsedSpan(builder, 0, foundBookmarks[j]);
if (collapsed && (collapsed.from || 0) == pos) {
buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
collapsed.marker, collapsed.from == null);
if (collapsed.to == null) return;
if (collapsed.to == pos) collapsed = false;
}
}
if (pos >= len) break;
var upto = Math.min(len, nextChange);
while (true) {
if (text) {
var end = pos + text.length;
if (!collapsed) {
var tokenText = end > upto ? text.slice(0, upto - pos) : text;
builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css);
}
if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
pos = end;
spanStartStyle = "";
}
text = allText.slice(at, at = styles[i++]);
style = interpretTokenStyle(styles[i++], builder.cm.options);
}
}
}
// DOCUMENT DATA STRUCTURE
// By default, updates that start and end at the beginning of a line
// are treated specially, in order to make the association of line
// widgets and marker elements with the text behave more intuitive.
function isWholeLineUpdate(doc, change) {
return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
(!doc.cm || doc.cm.options.wholeLineUpdateBefore);
}
// Perform a change on the document data structure.
function updateDoc(doc, change, markedSpans, estimateHeight) {
function spansFor(n) {return markedSpans ? markedSpans[n] : null;}
function update(line, text, spans) {
updateLine(line, text, spans, estimateHeight);
signalLater(line, "change", line, change);
}
function linesFor(start, end) {
for (var i = start, result = []; i < end; ++i)
result.push(new Line(text[i], spansFor(i), estimateHeight));
return result;
}
var from = change.from, to = change.to, text = change.text;
var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
// Adjust the line structure
if (change.full) {
doc.insert(0, linesFor(0, text.length));
doc.remove(text.length, doc.size - text.length);
} else if (isWholeLineUpdate(doc, change)) {
// This is a whole-line replace. Treated specially to make
// sure line objects move the way they are supposed to.
var added = linesFor(0, text.length - 1);
update(lastLine, lastLine.text, lastSpans);
if (nlines) doc.remove(from.line, nlines);
if (added.length) doc.insert(from.line, added);
} else if (firstLine == lastLine) {
if (text.length == 1) {
update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
} else {
var added = linesFor(1, text.length - 1);
added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
doc.insert(from.line + 1, added);
}
} else if (text.length == 1) {
update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
doc.remove(from.line + 1, nlines);
} else {
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
var added = linesFor(1, text.length - 1);
if (nlines > 1) doc.remove(from.line + 1, nlines - 1);
doc.insert(from.line + 1, added);
}
signalLater(doc, "change", doc, change);
}
// The document is represented as a BTree consisting of leaves, with
// chunk of lines in them, and branches, with up to ten leaves or
// other branch nodes below them. The top node is always a branch
// node, and is the document object itself (meaning it has
// additional methods and properties).
//
// All nodes have parent links. The tree is used both to go from
// line numbers to line objects, and to go from objects to numbers.
// It also indexes by height, and is used to convert between height
// and line object, and to find the total height of the document.
//
// See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
function LeafChunk(lines) {
this.lines = lines;
this.parent = null;
for (var i = 0, height = 0; i < lines.length; ++i) {
lines[i].parent = this;
height += lines[i].height;
}
this.height = height;
}
LeafChunk.prototype = {
chunkSize: function() { return this.lines.length; },
// Remove the n lines at offset 'at'.
removeInner: function(at, n) {
for (var i = at, e = at + n; i < e; ++i) {
var line = this.lines[i];
this.height -= line.height;
cleanUpLine(line);
signalLater(line, "delete");
}
this.lines.splice(at, n);
},
// Helper used to collapse a small branch into a single leaf.
collapse: function(lines) {
lines.push.apply(lines, this.lines);
},
// Insert the given array of lines at offset 'at', count them as
// having the given height.
insertInner: function(at, lines, height) {
this.height += height;
this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
for (var i = 0; i < lines.length; ++i) lines[i].parent = this;
},
// Used to iterate over a part of the tree.
iterN: function(at, n, op) {
for (var e = at + n; at < e; ++at)
if (op(this.lines[at])) return true;
}
};
function BranchChunk(children) {
this.children = children;
var size = 0, height = 0;
for (var i = 0; i < children.length; ++i) {
var ch = children[i];
size += ch.chunkSize(); height += ch.height;
ch.parent = this;
}
this.size = size;
this.height = height;
this.parent = null;
}
BranchChunk.prototype = {
chunkSize: function() { return this.size; },
removeInner: function(at, n) {
this.size -= n;
for (var i = 0; i < this.children.length; ++i) {
var child = this.children[i], sz = child.chunkSize();
if (at < sz) {
var rm = Math.min(n, sz - at), oldHeight = child.height;
child.removeInner(at, rm);
this.height -= oldHeight - child.height;
if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
if ((n -= rm) == 0) break;
at = 0;
} else at -= sz;
}
// If the result is smaller than 25 lines, ensure that it is a
// single leaf node.
if (this.size - n < 25 &&
(this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
var lines = [];
this.collapse(lines);
this.children = [new LeafChunk(lines)];
this.children[0].parent = this;
}
},
collapse: function(lines) {
for (var i = 0; i < this.children.length; ++i) this.children[i].collapse(lines);
},
insertInner: function(at, lines, height) {
this.size += lines.length;
this.height += height;
for (var i = 0; i < this.children.length; ++i) {
var child = this.children[i], sz = child.chunkSize();
if (at <= sz) {
child.insertInner(at, lines, height);
if (child.lines && child.lines.length > 50) {
while (child.lines.length > 50) {
var spilled = child.lines.splice(child.lines.length - 25, 25);
var newleaf = new LeafChunk(spilled);
child.height -= newleaf.height;
this.children.splice(i + 1, 0, newleaf);
newleaf.parent = this;
}
this.maybeSpill();
}
break;
}
at -= sz;
}
},
// When a node has grown, check whether it should be split.
maybeSpill: function() {
if (this.children.length <= 10) return;
var me = this;
do {
var spilled = me.children.splice(me.children.length - 5, 5);
var sibling = new BranchChunk(spilled);
if (!me.parent) { // Become the parent node
var copy = new BranchChunk(me.children);
copy.parent = me;
me.children = [copy, sibling];
me = copy;
} else {
me.size -= sibling.size;
me.height -= sibling.height;
var myIndex = indexOf(me.parent.children, me);
me.parent.children.splice(myIndex + 1, 0, sibling);
}
sibling.parent = me.parent;
} while (me.children.length > 10);
me.parent.maybeSpill();
},
iterN: function(at, n, op) {
for (var i = 0; i < this.children.length; ++i) {
var child = this.children[i], sz = child.chunkSize();
if (at < sz) {
var used = Math.min(n, sz - at);
if (child.iterN(at, used, op)) return true;
if ((n -= used) == 0) break;
at = 0;
} else at -= sz;
}
}
};
var nextDocId = 0;
var Doc = CodeMirror.Doc = function(text, mode, firstLine, lineSep) {
if (!(this instanceof Doc)) return new Doc(text, mode, firstLine, lineSep);
if (firstLine == null) firstLine = 0;
BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
this.first = firstLine;
this.scrollTop = this.scrollLeft = 0;
this.cantEdit = false;
this.cleanGeneration = 1;
this.frontier = firstLine;
var start = Pos(firstLine, 0);
this.sel = simpleSelection(start);
this.history = new History(null);
this.id = ++nextDocId;
this.modeOption = mode;
this.lineSep = lineSep;
this.extend = false;
if (typeof text == "string") text = this.splitLines(text);
updateDoc(this, {from: start, to: start, text: text});
setSelection(this, simpleSelection(start), sel_dontScroll);
};
Doc.prototype = createObj(BranchChunk.prototype, {
constructor: Doc,
// Iterate over the document. Supports two forms -- with only one
// argument, it calls that for each line in the document. With
// three, it iterates over the range given by the first two (with
// the second being non-inclusive).
iter: function(from, to, op) {
if (op) this.iterN(from - this.first, to - from, op);
else this.iterN(this.first, this.first + this.size, from);
},
// Non-public interface for adding and removing lines.
insert: function(at, lines) {
var height = 0;
for (var i = 0; i < lines.length; ++i) height += lines[i].height;
this.insertInner(at - this.first, lines, height);
},
remove: function(at, n) { this.removeInner(at - this.first, n); },
// From here, the methods are part of the public interface. Most
// are also available from CodeMirror (editor) instances.
getValue: function(lineSep) {
var lines = getLines(this, this.first, this.first + this.size);
if (lineSep === false) return lines;
return lines.join(lineSep || this.lineSeparator());
},
setValue: docMethodOp(function(code) {
var top = Pos(this.first, 0), last = this.first + this.size - 1;
makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
text: this.splitLines(code), origin: "setValue", full: true}, true);
setSelection(this, simpleSelection(top));
}),
replaceRange: function(code, from, to, origin) {
from = clipPos(this, from);
to = to ? clipPos(this, to) : from;
replaceRange(this, code, from, to, origin);
},
getRange: function(from, to, lineSep) {
var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
if (lineSep === false) return lines;
return lines.join(lineSep || this.lineSeparator());
},
getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
getLineHandle: function(line) {if (isLine(this, line)) return getLine(this, line);},
getLineNumber: function(line) {return lineNo(line);},
getLineHandleVisualStart: function(line) {
if (typeof line == "number") line = getLine(this, line);
return visualLine(line);
},
lineCount: function() {return this.size;},
firstLine: function() {return this.first;},
lastLine: function() {return this.first + this.size - 1;},
clipPos: function(pos) {return clipPos(this, pos);},
getCursor: function(start) {
var range = this.sel.primary(), pos;
if (start == null || start == "head") pos = range.head;
else if (start == "anchor") pos = range.anchor;
else if (start == "end" || start == "to" || start === false) pos = range.to();
else pos = range.from();
return pos;
},
listSelections: function() { return this.sel.ranges; },
somethingSelected: function() {return this.sel.somethingSelected();},
setCursor: docMethodOp(function(line, ch, options) {
setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
}),
setSelection: docMethodOp(function(anchor, head, options) {
setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
}),
extendSelection: docMethodOp(function(head, other, options) {
extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
}),
extendSelections: docMethodOp(function(heads, options) {
extendSelections(this, clipPosArray(this, heads), options);
}),
extendSelectionsBy: docMethodOp(function(f, options) {
var heads = map(this.sel.ranges, f);
extendSelections(this, clipPosArray(this, heads), options);
}),
setSelections: docMethodOp(function(ranges, primary, options) {
if (!ranges.length) return;
for (var i = 0, out = []; i < ranges.length; i++)
out[i] = new Range(clipPos(this, ranges[i].anchor),
clipPos(this, ranges[i].head));
if (primary == null) primary = Math.min(ranges.length - 1, this.sel.primIndex);
setSelection(this, normalizeSelection(out, primary), options);
}),
addSelection: docMethodOp(function(anchor, head, options) {
var ranges = this.sel.ranges.slice(0);
ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
setSelection(this, normalizeSelection(ranges, ranges.length - 1), options);
}),
getSelection: function(lineSep) {
var ranges = this.sel.ranges, lines;
for (var i = 0; i < ranges.length; i++) {
var sel = getBetween(this, ranges[i].from(), ranges[i].to());
lines = lines ? lines.concat(sel) : sel;
}
if (lineSep === false) return lines;
else return lines.join(lineSep || this.lineSeparator());
},
getSelections: function(lineSep) {
var parts = [], ranges = this.sel.ranges;
for (var i = 0; i < ranges.length; i++) {
var sel = getBetween(this, ranges[i].from(), ranges[i].to());
if (lineSep !== false) sel = sel.join(lineSep || this.lineSeparator());
parts[i] = sel;
}
return parts;
},
replaceSelection: function(code, collapse, origin) {
var dup = [];
for (var i = 0; i < this.sel.ranges.length; i++)
dup[i] = code;
this.replaceSelections(dup, collapse, origin || "+input");
},
replaceSelections: docMethodOp(function(code, collapse, origin) {
var changes = [], sel = this.sel;
for (var i = 0; i < sel.ranges.length; i++) {
var range = sel.ranges[i];
changes[i] = {from: range.from(), to: range.to(), text: this.splitLines(code[i]), origin: origin};
}
var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
for (var i = changes.length - 1; i >= 0; i--)
makeChange(this, changes[i]);
if (newSel) setSelectionReplaceHistory(this, newSel);
else if (this.cm) ensureCursorVisible(this.cm);
}),
undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
setExtending: function(val) {this.extend = val;},
getExtending: function() {return this.extend;},
historySize: function() {
var hist = this.history, done = 0, undone = 0;
for (var i = 0; i < hist.done.length; i++) if (!hist.done[i].ranges) ++done;
for (var i = 0; i < hist.undone.length; i++) if (!hist.undone[i].ranges) ++undone;
return {undo: done, redo: undone};
},
clearHistory: function() {this.history = new History(this.history.maxGeneration);},
markClean: function() {
this.cleanGeneration = this.changeGeneration(true);
},
changeGeneration: function(forceSplit) {
if (forceSplit)
this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null;
return this.history.generation;
},
isClean: function (gen) {
return this.history.generation == (gen || this.cleanGeneration);
},
getHistory: function() {
return {done: copyHistoryArray(this.history.done),
undone: copyHistoryArray(this.history.undone)};
},
setHistory: function(histData) {
var hist = this.history = new History(this.history.maxGeneration);
hist.done = copyHistoryArray(histData.done.slice(0), null, true);
hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
},
addLineClass: docMethodOp(function(handle, where, cls) {
return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
var prop = where == "text" ? "textClass"
: where == "background" ? "bgClass"
: where == "gutter" ? "gutterClass" : "wrapClass";
if (!line[prop]) line[prop] = cls;
else if (classTest(cls).test(line[prop])) return false;
else line[prop] += " " + cls;
return true;
});
}),
removeLineClass: docMethodOp(function(handle, where, cls) {
return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
var prop = where == "text" ? "textClass"
: where == "background" ? "bgClass"
: where == "gutter" ? "gutterClass" : "wrapClass";
var cur = line[prop];
if (!cur) return false;
else if (cls == null) line[prop] = null;
else {
var found = cur.match(classTest(cls));
if (!found) return false;
var end = found.index + found[0].length;
line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
}
return true;
});
}),
addLineWidget: docMethodOp(function(handle, node, options) {
return addLineWidget(this, handle, node, options);
}),
removeLineWidget: function(widget) { widget.clear(); },
markText: function(from, to, options) {
return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range");
},
setBookmark: function(pos, options) {
var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
insertLeft: options && options.insertLeft,
clearWhenEmpty: false, shared: options && options.shared,
handleMouseEvents: options && options.handleMouseEvents};
pos = clipPos(this, pos);
return markText(this, pos, pos, realOpts, "bookmark");
},
findMarksAt: function(pos) {
pos = clipPos(this, pos);
var markers = [], spans = getLine(this, pos.line).markedSpans;
if (spans) for (var i = 0; i < spans.length; ++i) {
var span = spans[i];
if ((span.from == null || span.from <= pos.ch) &&
(span.to == null || span.to >= pos.ch))
markers.push(span.marker.parent || span.marker);
}
return markers;
},
findMarks: function(from, to, filter) {
from = clipPos(this, from); to = clipPos(this, to);
var found = [], lineNo = from.line;
this.iter(from.line, to.line + 1, function(line) {
var spans = line.markedSpans;
if (spans) for (var i = 0; i < spans.length; i++) {
var span = spans[i];
if (!(span.to != null && lineNo == from.line && from.ch >= span.to ||
span.from == null && lineNo != from.line ||
span.from != null && lineNo == to.line && span.from >= to.ch) &&
(!filter || filter(span.marker)))
found.push(span.marker.parent || span.marker);
}
++lineNo;
});
return found;
},
getAllMarks: function() {
var markers = [];
this.iter(function(line) {
var sps = line.markedSpans;
if (sps) for (var i = 0; i < sps.length; ++i)
if (sps[i].from != null) markers.push(sps[i].marker);
});
return markers;
},
posFromIndex: function(off) {
var ch, lineNo = this.first, sepSize = this.lineSeparator().length;
this.iter(function(line) {
var sz = line.text.length + sepSize;
if (sz > off) { ch = off; return true; }
off -= sz;
++lineNo;
});
return clipPos(this, Pos(lineNo, ch));
},
indexFromPos: function (coords) {
coords = clipPos(this, coords);
var index = coords.ch;
if (coords.line < this.first || coords.ch < 0) return 0;
var sepSize = this.lineSeparator().length;
this.iter(this.first, coords.line, function (line) {
index += line.text.length + sepSize;
});
return index;
},
copy: function(copyHistory) {
var doc = new Doc(getLines(this, this.first, this.first + this.size),
this.modeOption, this.first, this.lineSep);
doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
doc.sel = this.sel;
doc.extend = false;
if (copyHistory) {
doc.history.undoDepth = this.history.undoDepth;
doc.setHistory(this.getHistory());
}
return doc;
},
linkedDoc: function(options) {
if (!options) options = {};
var from = this.first, to = this.first + this.size;
if (options.from != null && options.from > from) from = options.from;
if (options.to != null && options.to < to) to = options.to;
var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep);
if (options.sharedHist) copy.history = this.history;
(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
copySharedMarkers(copy, findSharedMarkers(this));
return copy;
},
unlinkDoc: function(other) {
if (other instanceof CodeMirror) other = other.doc;
if (this.linked) for (var i = 0; i < this.linked.length; ++i) {
var link = this.linked[i];
if (link.doc != other) continue;
this.linked.splice(i, 1);
other.unlinkDoc(this);
detachSharedMarkers(findSharedMarkers(this));
break;
}
// If the histories were shared, split them again
if (other.history == this.history) {
var splitIds = [other.id];
linkedDocs(other, function(doc) {splitIds.push(doc.id);}, true);
other.history = new History(null);
other.history.done = copyHistoryArray(this.history.done, splitIds);
other.history.undone = copyHistoryArray(this.history.undone, splitIds);
}
},
iterLinkedDocs: function(f) {linkedDocs(this, f);},
getMode: function() {return this.mode;},
getEditor: function() {return this.cm;},
splitLines: function(str) {
if (this.lineSep) return str.split(this.lineSep);
return splitLinesAuto(str);
},
lineSeparator: function() { return this.lineSep || "\n"; }
});
// Public alias.
Doc.prototype.eachLine = Doc.prototype.iter;
// Set up methods on CodeMirror's prototype to redirect to the editor's document.
var dontDelegate = "iter insert remove copy getEditor constructor".split(" ");
for (var prop in Doc.prototype) if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
CodeMirror.prototype[prop] = (function(method) {
return function() {return method.apply(this.doc, arguments);};
})(Doc.prototype[prop]);
eventMixin(Doc);
// Call f for all linked documents.
function linkedDocs(doc, f, sharedHistOnly) {
function propagate(doc, skip, sharedHist) {
if (doc.linked) for (var i = 0; i < doc.linked.length; ++i) {
var rel = doc.linked[i];
if (rel.doc == skip) continue;
var shared = sharedHist && rel.sharedHist;
if (sharedHistOnly && !shared) continue;
f(rel.doc, shared);
propagate(rel.doc, doc, shared);
}
}
propagate(doc, null, true);
}
// Attach a document to an editor.
function attachDoc(cm, doc) {
if (doc.cm) throw new Error("This document is already in use.");
cm.doc = doc;
doc.cm = cm;
estimateLineHeights(cm);
loadMode(cm);
if (!cm.options.lineWrapping) findMaxLine(cm);
cm.options.mode = doc.modeOption;
regChange(cm);
}
// LINE UTILITIES
// Find the line object corresponding to the given line number.
function getLine(doc, n) {
n -= doc.first;
if (n < 0 || n >= doc.size) throw new Error("There is no line " + (n + doc.first) + " in the document.");
for (var chunk = doc; !chunk.lines;) {
for (var i = 0;; ++i) {
var child = chunk.children[i], sz = child.chunkSize();
if (n < sz) { chunk = child; break; }
n -= sz;
}
}
return chunk.lines[n];
}
// Get the part of a document between two positions, as an array of
// strings.
function getBetween(doc, start, end) {
var out = [], n = start.line;
doc.iter(start.line, end.line + 1, function(line) {
var text = line.text;
if (n == end.line) text = text.slice(0, end.ch);
if (n == start.line) text = text.slice(start.ch);
out.push(text);
++n;
});
return out;
}
// Get the lines between from and to, as array of strings.
function getLines(doc, from, to) {
var out = [];
doc.iter(from, to, function(line) { out.push(line.text); });
return out;
}
// Update the height of a line, propagating the height change
// upwards to parent nodes.
function updateLineHeight(line, height) {
var diff = height - line.height;
if (diff) for (var n = line; n; n = n.parent) n.height += diff;
}
// Given a line object, find its line number by walking up through
// its parent links.
function lineNo(line) {
if (line.parent == null) return null;
var cur = line.parent, no = indexOf(cur.lines, line);
for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
for (var i = 0;; ++i) {
if (chunk.children[i] == cur) break;
no += chunk.children[i].chunkSize();
}
}
return no + cur.first;
}
// Find the line at the given vertical position, using the height
// information in the document tree.
function lineAtHeight(chunk, h) {
var n = chunk.first;
outer: do {
for (var i = 0; i < chunk.children.length; ++i) {
var child = chunk.children[i], ch = child.height;
if (h < ch) { chunk = child; continue outer; }
h -= ch;
n += child.chunkSize();
}
return n;
} while (!chunk.lines);
for (var i = 0; i < chunk.lines.length; ++i) {
var line = chunk.lines[i], lh = line.height;
if (h < lh) break;
h -= lh;
}
return n + i;
}
// Find the height above the given line.
function heightAtLine(lineObj) {
lineObj = visualLine(lineObj);
var h = 0, chunk = lineObj.parent;
for (var i = 0; i < chunk.lines.length; ++i) {
var line = chunk.lines[i];
if (line == lineObj) break;
else h += line.height;
}
for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
for (var i = 0; i < p.children.length; ++i) {
var cur = p.children[i];
if (cur == chunk) break;
else h += cur.height;
}
}
return h;
}
// Get the bidi ordering for the given line (and cache it). Returns
// false for lines that are fully left-to-right, and an array of
// BidiSpan objects otherwise.
function getOrder(line) {
var order = line.order;
if (order == null) order = line.order = bidiOrdering(line.text);
return order;
}
// HISTORY
function History(startGen) {
// Arrays of change events and selections. Doing something adds an
// event to done and clears undo. Undoing moves events from done
// to undone, redoing moves them in the other direction.
this.done = []; this.undone = [];
this.undoDepth = Infinity;
// Used to track when changes can be merged into a single undo
// event
this.lastModTime = this.lastSelTime = 0;
this.lastOp = this.lastSelOp = null;
this.lastOrigin = this.lastSelOrigin = null;
// Used by the isClean() method
this.generation = this.maxGeneration = startGen || 1;
}
// Create a history change event from an updateDoc-style change
// object.
function historyChangeFromChange(doc, change) {
var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
linkedDocs(doc, function(doc) {attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);}, true);
return histChange;
}
// Pop all selection events off the end of a history array. Stop at
// a change event.
function clearSelectionEvents(array) {
while (array.length) {
var last = lst(array);
if (last.ranges) array.pop();
else break;
}
}
// Find the top change event in the history. Pop off selection
// events that are in the way.
function lastChangeEvent(hist, force) {
if (force) {
clearSelectionEvents(hist.done);
return lst(hist.done);
} else if (hist.done.length && !lst(hist.done).ranges) {
return lst(hist.done);
} else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
hist.done.pop();
return lst(hist.done);
}
}
// Register a change in the history. Merges changes that are within
// a single operation, ore are close together with an origin that
// allows merging (starting with "+") into a single event.
function addChangeToHistory(doc, change, selAfter, opId) {
var hist = doc.history;
hist.undone.length = 0;
var time = +new Date, cur;
if ((hist.lastOp == opId ||
hist.lastOrigin == change.origin && change.origin &&
((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) ||
change.origin.charAt(0) == "*")) &&
(cur = lastChangeEvent(hist, hist.lastOp == opId))) {
// Merge this change into the last event
var last = lst(cur.changes);
if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
// Optimized case for simple insertion -- don't want to add
// new changesets for every character typed
last.to = changeEnd(change);
} else {
// Add new sub-event
cur.changes.push(historyChangeFromChange(doc, change));
}
} else {
// Can not be merged, start a new event.
var before = lst(hist.done);
if (!before || !before.ranges)
pushSelectionToHistory(doc.sel, hist.done);
cur = {changes: [historyChangeFromChange(doc, change)],
generation: hist.generation};
hist.done.push(cur);
while (hist.done.length > hist.undoDepth) {
hist.done.shift();
if (!hist.done[0].ranges) hist.done.shift();
}
}
hist.done.push(selAfter);
hist.generation = ++hist.maxGeneration;
hist.lastModTime = hist.lastSelTime = time;
hist.lastOp = hist.lastSelOp = opId;
hist.lastOrigin = hist.lastSelOrigin = change.origin;
if (!last) signal(doc, "historyAdded");
}
function selectionEventCanBeMerged(doc, origin, prev, sel) {
var ch = origin.charAt(0);
return ch == "*" ||
ch == "+" &&
prev.ranges.length == sel.ranges.length &&
prev.somethingSelected() == sel.somethingSelected() &&
new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500);
}
// Called whenever the selection changes, sets the new selection as
// the pending selection in the history, and pushes the old pending
// selection into the 'done' array when it was significantly
// different (in number of selected ranges, emptiness, or time).
function addSelectionToHistory(doc, sel, opId, options) {
var hist = doc.history, origin = options && options.origin;
// A new event is started when the previous origin does not match
// the current, or the origins don't allow matching. Origins
// starting with * are always merged, those starting with + are
// merged when similar and close together in time.
if (opId == hist.lastSelOp ||
(origin && hist.lastSelOrigin == origin &&
(hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
hist.done[hist.done.length - 1] = sel;
else
pushSelectionToHistory(sel, hist.done);
hist.lastSelTime = +new Date;
hist.lastSelOrigin = origin;
hist.lastSelOp = opId;
if (options && options.clearRedo !== false)
clearSelectionEvents(hist.undone);
}
function pushSelectionToHistory(sel, dest) {
var top = lst(dest);
if (!(top && top.ranges && top.equals(sel)))
dest.push(sel);
}
// Used to store marked span information in the history.
function attachLocalSpans(doc, change, from, to) {
var existing = change["spans_" + doc.id], n = 0;
doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function(line) {
if (line.markedSpans)
(existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans;
++n;
});
}
// When un/re-doing restores text containing marked spans, those
// that have been explicitly cleared should not be restored.
function removeClearedSpans(spans) {
if (!spans) return null;
for (var i = 0, out; i < spans.length; ++i) {
if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
else if (out) out.push(spans[i]);
}
return !out ? spans : out.length ? out : null;
}
// Retrieve and filter the old marked spans stored in a change event.
function getOldSpans(doc, change) {
var found = change["spans_" + doc.id];
if (!found) return null;
for (var i = 0, nw = []; i < change.text.length; ++i)
nw.push(removeClearedSpans(found[i]));
return nw;
}
// Used both to provide a JSON-safe object in .getHistory, and, when
// detaching a document, to split the history in two
function copyHistoryArray(events, newGroup, instantiateSel) {
for (var i = 0, copy = []; i < events.length; ++i) {
var event = events[i];
if (event.ranges) {
copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
continue;
}
var changes = event.changes, newChanges = [];
copy.push({changes: newChanges});
for (var j = 0; j < changes.length; ++j) {
var change = changes[j], m;
newChanges.push({from: change.from, to: change.to, text: change.text});
if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) {
if (indexOf(newGroup, Number(m[1])) > -1) {
lst(newChanges)[prop] = change[prop];
delete change[prop];
}
}
}
}
return copy;
}
// Rebasing/resetting history to deal with externally-sourced changes
function rebaseHistSelSingle(pos, from, to, diff) {
if (to < pos.line) {
pos.line += diff;
} else if (from < pos.line) {
pos.line = from;
pos.ch = 0;
}
}
// Tries to rebase an array of history events given a change in the
// document. If the change touches the same lines as the event, the
// event, and everything 'behind' it, is discarded. If the change is
// before the event, the event's positions are updated. Uses a
// copy-on-write scheme for the positions, to avoid having to
// reallocate them all on every rebase, but also avoid problems with
// shared position objects being unsafely updated.
function rebaseHistArray(array, from, to, diff) {
for (var i = 0; i < array.length; ++i) {
var sub = array[i], ok = true;
if (sub.ranges) {
if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
for (var j = 0; j < sub.ranges.length; j++) {
rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
}
continue;
}
for (var j = 0; j < sub.changes.length; ++j) {
var cur = sub.changes[j];
if (to < cur.from.line) {
cur.from = Pos(cur.from.line + diff, cur.from.ch);
cur.to = Pos(cur.to.line + diff, cur.to.ch);
} else if (from <= cur.to.line) {
ok = false;
break;
}
}
if (!ok) {
array.splice(0, i + 1);
i = 0;
}
}
}
function rebaseHist(hist, change) {
var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
rebaseHistArray(hist.done, from, to, diff);
rebaseHistArray(hist.undone, from, to, diff);
}
// EVENT UTILITIES
// Due to the fact that we still support jurassic IE versions, some
// compatibility wrappers are needed.
var e_preventDefault = CodeMirror.e_preventDefault = function(e) {
if (e.preventDefault) e.preventDefault();
else e.returnValue = false;
};
var e_stopPropagation = CodeMirror.e_stopPropagation = function(e) {
if (e.stopPropagation) e.stopPropagation();
else e.cancelBubble = true;
};
function e_defaultPrevented(e) {
return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
}
var e_stop = CodeMirror.e_stop = function(e) {e_preventDefault(e); e_stopPropagation(e);};
function e_target(e) {return e.target || e.srcElement;}
function e_button(e) {
var b = e.which;
if (b == null) {
if (e.button & 1) b = 1;
else if (e.button & 2) b = 3;
else if (e.button & 4) b = 2;
}
if (mac && e.ctrlKey && b == 1) b = 3;
return b;
}
// EVENT HANDLING
// Lightweight event framework. on/off also work on DOM nodes,
// registering native DOM handlers.
var on = CodeMirror.on = function(emitter, type, f) {
if (emitter.addEventListener)
emitter.addEventListener(type, f, false);
else if (emitter.attachEvent)
emitter.attachEvent("on" + type, f);
else {
var map = emitter._handlers || (emitter._handlers = {});
var arr = map[type] || (map[type] = []);
arr.push(f);
}
};
var noHandlers = []
function getHandlers(emitter, type, copy) {
var arr = emitter._handlers && emitter._handlers[type]
if (copy) return arr && arr.length > 0 ? arr.slice() : noHandlers
else return arr || noHandlers
}
var off = CodeMirror.off = function(emitter, type, f) {
if (emitter.removeEventListener)
emitter.removeEventListener(type, f, false);
else if (emitter.detachEvent)
emitter.detachEvent("on" + type, f);
else {
var handlers = getHandlers(emitter, type, false)
for (var i = 0; i < handlers.length; ++i)
if (handlers[i] == f) { handlers.splice(i, 1); break; }
}
};
var signal = CodeMirror.signal = function(emitter, type /*, values...*/) {
var handlers = getHandlers(emitter, type, true)
if (!handlers.length) return;
var args = Array.prototype.slice.call(arguments, 2);
for (var i = 0; i < handlers.length; ++i) handlers[i].apply(null, args);
};
var orphanDelayedCallbacks = null;
// Often, we want to signal events at a point where we are in the
// middle of some work, but don't want the handler to start calling
// other methods on the editor, which might be in an inconsistent
// state or simply not expect any other events to happen.
// signalLater looks whether there are any handlers, and schedules
// them to be executed when the last operation ends, or, if no
// operation is active, when a timeout fires.
function signalLater(emitter, type /*, values...*/) {
var arr = getHandlers(emitter, type, false)
if (!arr.length) return;
var args = Array.prototype.slice.call(arguments, 2), list;
if (operationGroup) {
list = operationGroup.delayedCallbacks;
} else if (orphanDelayedCallbacks) {
list = orphanDelayedCallbacks;
} else {
list = orphanDelayedCallbacks = [];
setTimeout(fireOrphanDelayed, 0);
}
function bnd(f) {return function(){f.apply(null, args);};};
for (var i = 0; i < arr.length; ++i)
list.push(bnd(arr[i]));
}
function fireOrphanDelayed() {
var delayed = orphanDelayedCallbacks;
orphanDelayedCallbacks = null;
for (var i = 0; i < delayed.length; ++i) delayed[i]();
}
// The DOM events that CodeMirror handles can be overridden by
// registering a (non-DOM) handler on the editor for the event name,
// and preventDefault-ing the event in that handler.
function signalDOMEvent(cm, e, override) {
if (typeof e == "string")
e = {type: e, preventDefault: function() { this.defaultPrevented = true; }};
signal(cm, override || e.type, cm, e);
return e_defaultPrevented(e) || e.codemirrorIgnore;
}
function signalCursorActivity(cm) {
var arr = cm._handlers && cm._handlers.cursorActivity;
if (!arr) return;
var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
for (var i = 0; i < arr.length; ++i) if (indexOf(set, arr[i]) == -1)
set.push(arr[i]);
}
function hasHandler(emitter, type) {
return getHandlers(emitter, type).length > 0
}
// Add on and off methods to a constructor's prototype, to make
// registering events on such objects more convenient.
function eventMixin(ctor) {
ctor.prototype.on = function(type, f) {on(this, type, f);};
ctor.prototype.off = function(type, f) {off(this, type, f);};
}
// MISC UTILITIES
// Number of pixels added to scroller and sizer to hide scrollbar
var scrollerGap = 30;
// Returned or thrown by various protocols to signal 'I'm not
// handling this'.
var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
// Reused option objects for setSelection & friends
var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
function Delayed() {this.id = null;}
Delayed.prototype.set = function(ms, f) {
clearTimeout(this.id);
this.id = setTimeout(f, ms);
};
// Counts the column offset in a string, taking tabs into account.
// Used mostly to find indentation.
var countColumn = CodeMirror.countColumn = function(string, end, tabSize, startIndex, startValue) {
if (end == null) {
end = string.search(/[^\s\u00a0]/);
if (end == -1) end = string.length;
}
for (var i = startIndex || 0, n = startValue || 0;;) {
var nextTab = string.indexOf("\t", i);
if (nextTab < 0 || nextTab >= end)
return n + (end - i);
n += nextTab - i;
n += tabSize - (n % tabSize);
i = nextTab + 1;
}
};
// The inverse of countColumn -- find the offset that corresponds to
// a particular column.
var findColumn = CodeMirror.findColumn = function(string, goal, tabSize) {
for (var pos = 0, col = 0;;) {
var nextTab = string.indexOf("\t", pos);
if (nextTab == -1) nextTab = string.length;
var skipped = nextTab - pos;
if (nextTab == string.length || col + skipped >= goal)
return pos + Math.min(skipped, goal - col);
col += nextTab - pos;
col += tabSize - (col % tabSize);
pos = nextTab + 1;
if (col >= goal) return pos;
}
}
var spaceStrs = [""];
function spaceStr(n) {
while (spaceStrs.length <= n)
spaceStrs.push(lst(spaceStrs) + " ");
return spaceStrs[n];
}
function lst(arr) { return arr[arr.length-1]; }
var selectInput = function(node) { node.select(); };
if (ios) // Mobile Safari apparently has a bug where select() is broken.
selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; };
else if (ie) // Suppress mysterious IE10 errors
selectInput = function(node) { try { node.select(); } catch(_e) {} };
function indexOf(array, elt) {
for (var i = 0; i < array.length; ++i)
if (array[i] == elt) return i;
return -1;
}
function map(array, f) {
var out = [];
for (var i = 0; i < array.length; i++) out[i] = f(array[i], i);
return out;
}
function nothing() {}
function createObj(base, props) {
var inst;
if (Object.create) {
inst = Object.create(base);
} else {
nothing.prototype = base;
inst = new nothing();
}
if (props) copyObj(props, inst);
return inst;
};
function copyObj(obj, target, overwrite) {
if (!target) target = {};
for (var prop in obj)
if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
target[prop] = obj[prop];
return target;
}
function bind(f) {
var args = Array.prototype.slice.call(arguments, 1);
return function(){return f.apply(null, args);};
}
var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
var isWordCharBasic = CodeMirror.isWordChar = function(ch) {
return /\w/.test(ch) || ch > "\x80" &&
(ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
};
function isWordChar(ch, helper) {
if (!helper) return isWordCharBasic(ch);
if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) return true;
return helper.test(ch);
}
function isEmpty(obj) {
for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) return false;
return true;
}
// Extending unicode characters. A series of a non-extending char +
// any number of extending chars is treated as a single unit as far
// as editing and measuring is concerned. This is not fully correct,
// since some scripts/fonts/browsers also treat other configurations
// of code points as a group.
var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch); }
// DOM UTILITIES
function elt(tag, content, className, style) {
var e = document.createElement(tag);
if (className) e.className = className;
if (style) e.style.cssText = style;
if (typeof content == "string") e.appendChild(document.createTextNode(content));
else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
return e;
}
var range;
if (document.createRange) range = function(node, start, end, endNode) {
var r = document.createRange();
r.setEnd(endNode || node, end);
r.setStart(node, start);
return r;
};
else range = function(node, start, end) {
var r = document.body.createTextRange();
try { r.moveToElementText(node.parentNode); }
catch(e) { return r; }
r.collapse(true);
r.moveEnd("character", end);
r.moveStart("character", start);
return r;
};
function removeChildren(e) {
for (var count = e.childNodes.length; count > 0; --count)
e.removeChild(e.firstChild);
return e;
}
function removeChildrenAndAdd(parent, e) {
return removeChildren(parent).appendChild(e);
}
var contains = CodeMirror.contains = function(parent, child) {
if (child.nodeType == 3) // Android browser always returns false when child is a textnode
child = child.parentNode;
if (parent.contains)
return parent.contains(child);
do {
if (child.nodeType == 11) child = child.host;
if (child == parent) return true;
} while (child = child.parentNode);
};
function activeElt() {
var activeElement = document.activeElement;
while (activeElement && activeElement.root && activeElement.root.activeElement)
activeElement = activeElement.root.activeElement;
return activeElement;
}
// Older versions of IE throws unspecified error when touching
// document.activeElement in some cases (during loading, in iframe)
if (ie && ie_version < 11) activeElt = function() {
try { return document.activeElement; }
catch(e) { return document.body; }
};
function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*"); }
var rmClass = CodeMirror.rmClass = function(node, cls) {
var current = node.className;
var match = classTest(cls).exec(current);
if (match) {
var after = current.slice(match.index + match[0].length);
node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
}
};
var addClass = CodeMirror.addClass = function(node, cls) {
var current = node.className;
if (!classTest(cls).test(current)) node.className += (current ? " " : "") + cls;
};
function joinClasses(a, b) {
var as = a.split(" ");
for (var i = 0; i < as.length; i++)
if (as[i] && !classTest(as[i]).test(b)) b += " " + as[i];
return b;
}
// WINDOW-WIDE EVENTS
// These must be handled carefully, because naively registering a
// handler for each editor will cause the editors to never be
// garbage collected.
function forEachCodeMirror(f) {
if (!document.body.getElementsByClassName) return;
var byClass = document.body.getElementsByClassName("CodeMirror");
for (var i = 0; i < byClass.length; i++) {
var cm = byClass[i].CodeMirror;
if (cm) f(cm);
}
}
var globalsRegistered = false;
function ensureGlobalHandlers() {
if (globalsRegistered) return;
registerGlobalHandlers();
globalsRegistered = true;
}
function registerGlobalHandlers() {
// When the window resizes, we need to refresh active editors.
var resizeTimer;
on(window, "resize", function() {
if (resizeTimer == null) resizeTimer = setTimeout(function() {
resizeTimer = null;
forEachCodeMirror(onResize);
}, 100);
});
// When the window loses focus, we want to show the editor as blurred
on(window, "blur", function() {
forEachCodeMirror(onBlur);
});
}
// FEATURE DETECTION
// Detect drag-and-drop
var dragAndDrop = function() {
// There is *some* kind of drag-and-drop support in IE6-8, but I
// couldn't get it to work yet.
if (ie && ie_version < 9) return false;
var div = elt('div');
return "draggable" in div || "dragDrop" in div;
}();
var zwspSupported;
function zeroWidthElement(measure) {
if (zwspSupported == null) {
var test = elt("span", "\u200b");
removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
if (measure.firstChild.offsetHeight != 0)
zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8);
}
var node = zwspSupported ? elt("span", "\u200b") :
elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
node.setAttribute("cm-text", "");
return node;
}
// Feature-detect IE's crummy client rect reporting for bidi text
var badBidiRects;
function hasBadBidiRects(measure) {
if (badBidiRects != null) return badBidiRects;
var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
var r0 = range(txt, 0, 1).getBoundingClientRect();
if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780)
var r1 = range(txt, 1, 2).getBoundingClientRect();
return badBidiRects = (r1.right - r0.right < 3);
}
// See if "".split is the broken IE version, if so, provide an
// alternative way to split lines.
var splitLinesAuto = CodeMirror.splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
var pos = 0, result = [], l = string.length;
while (pos <= l) {
var nl = string.indexOf("\n", pos);
if (nl == -1) nl = string.length;
var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
var rt = line.indexOf("\r");
if (rt != -1) {
result.push(line.slice(0, rt));
pos += rt + 1;
} else {
result.push(line);
pos = nl + 1;
}
}
return result;
} : function(string){return string.split(/\r\n?|\n/);};
var hasSelection = window.getSelection ? function(te) {
try { return te.selectionStart != te.selectionEnd; }
catch(e) { return false; }
} : function(te) {
try {var range = te.ownerDocument.selection.createRange();}
catch(e) {}
if (!range || range.parentElement() != te) return false;
return range.compareEndPoints("StartToEnd", range) != 0;
};
var hasCopyEvent = (function() {
var e = elt("div");
if ("oncopy" in e) return true;
e.setAttribute("oncopy", "return;");
return typeof e.oncopy == "function";
})();
var badZoomedRects = null;
function hasBadZoomedRects(measure) {
if (badZoomedRects != null) return badZoomedRects;
var node = removeChildrenAndAdd(measure, elt("span", "x"));
var normal = node.getBoundingClientRect();
var fromRange = range(node, 0, 1).getBoundingClientRect();
return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1;
}
// KEY NAMES
var keyNames = CodeMirror.keyNames = {
3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete",
173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
};
(function() {
// Number keys
for (var i = 0; i < 10; i++) keyNames[i + 48] = keyNames[i + 96] = String(i);
// Alphabetic keys
for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
// Function keys
for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
})();
// BIDI HELPERS
function iterateBidiSections(order, from, to, f) {
if (!order) return f(from, to, "ltr");
var found = false;
for (var i = 0; i < order.length; ++i) {
var part = order[i];
if (part.from < to && part.to > from || from == to && part.to == from) {
f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
found = true;
}
}
if (!found) f(from, to, "ltr");
}
function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
function lineRight(line) {
var order = getOrder(line);
if (!order) return line.text.length;
return bidiRight(lst(order));
}
function lineStart(cm, lineN) {
var line = getLine(cm.doc, lineN);
var visual = visualLine(line);
if (visual != line) lineN = lineNo(visual);
var order = getOrder(visual);
var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
return Pos(lineN, ch);
}
function lineEnd(cm, lineN) {
var merged, line = getLine(cm.doc, lineN);
while (merged = collapsedSpanAtEnd(line)) {
line = merged.find(1, true).line;
lineN = null;
}
var order = getOrder(line);
var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
return Pos(lineN == null ? lineNo(line) : lineN, ch);
}
function lineStartSmart(cm, pos) {
var start = lineStart(cm, pos.line);
var line = getLine(cm.doc, start.line);
var order = getOrder(line);
if (!order || order[0].level == 0) {
var firstNonWS = Math.max(0, line.text.search(/\S/));
var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
return Pos(start.line, inWS ? 0 : firstNonWS);
}
return start;
}
function compareBidiLevel(order, a, b) {
var linedir = order[0].level;
if (a == linedir) return true;
if (b == linedir) return false;
return a < b;
}
var bidiOther;
function getBidiPartAt(order, pos) {
bidiOther = null;
for (var i = 0, found; i < order.length; ++i) {
var cur = order[i];
if (cur.from < pos && cur.to > pos) return i;
if ((cur.from == pos || cur.to == pos)) {
if (found == null) {
found = i;
} else if (compareBidiLevel(order, cur.level, order[found].level)) {
if (cur.from != cur.to) bidiOther = found;
return i;
} else {
if (cur.from != cur.to) bidiOther = i;
return found;
}
}
}
return found;
}
function moveInLine(line, pos, dir, byUnit) {
if (!byUnit) return pos + dir;
do pos += dir;
while (pos > 0 && isExtendingChar(line.text.charAt(pos)));
return pos;
}
// This is needed in order to move 'visually' through bi-directional
// text -- i.e., pressing left should make the cursor go left, even
// when in RTL text. The tricky part is the 'jumps', where RTL and
// LTR text touch each other. This often requires the cursor offset
// to move more than one unit, in order to visually move one unit.
function moveVisually(line, start, dir, byUnit) {
var bidi = getOrder(line);
if (!bidi) return moveLogically(line, start, dir, byUnit);
var pos = getBidiPartAt(bidi, start), part = bidi[pos];
var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit);
for (;;) {
if (target > part.from && target < part.to) return target;
if (target == part.from || target == part.to) {
if (getBidiPartAt(bidi, target) == pos) return target;
part = bidi[pos += dir];
return (dir > 0) == part.level % 2 ? part.to : part.from;
} else {
part = bidi[pos += dir];
if (!part) return null;
if ((dir > 0) == part.level % 2)
target = moveInLine(line, part.to, -1, byUnit);
else
target = moveInLine(line, part.from, 1, byUnit);
}
}
}
function moveLogically(line, start, dir, byUnit) {
var target = start + dir;
if (byUnit) while (target > 0 && isExtendingChar(line.text.charAt(target))) target += dir;
return target < 0 || target > line.text.length ? null : target;
}
// Bidirectional ordering algorithm
// See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
// that this (partially) implements.
// One-char codes used for character types:
// L (L): Left-to-Right
// R (R): Right-to-Left
// r (AL): Right-to-Left Arabic
// 1 (EN): European Number
// + (ES): European Number Separator
// % (ET): European Number Terminator
// n (AN): Arabic Number
// , (CS): Common Number Separator
// m (NSM): Non-Spacing Mark
// b (BN): Boundary Neutral
// s (B): Paragraph Separator
// t (S): Segment Separator
// w (WS): Whitespace
// N (ON): Other Neutrals
// Returns null if characters are ordered as they appear
// (left-to-right), or an array of sections ({from, to, level}
// objects) in the order in which they occur visually.
var bidiOrdering = (function() {
// Character types for codepoints 0 to 0xff
var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
// Character types for codepoints 0x600 to 0x6ff
var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm";
function charType(code) {
if (code <= 0xf7) return lowTypes.charAt(code);
else if (0x590 <= code && code <= 0x5f4) return "R";
else if (0x600 <= code && code <= 0x6ed) return arabicTypes.charAt(code - 0x600);
else if (0x6ee <= code && code <= 0x8ac) return "r";
else if (0x2000 <= code && code <= 0x200b) return "w";
else if (code == 0x200c) return "b";
else return "L";
}
var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
// Browsers seem to always treat the boundaries of block elements as being L.
var outerType = "L";
function BidiSpan(level, from, to) {
this.level = level;
this.from = from; this.to = to;
}
return function(str) {
if (!bidiRE.test(str)) return false;
var len = str.length, types = [];
for (var i = 0, type; i < len; ++i)
types.push(type = charType(str.charCodeAt(i)));
// W1. Examine each non-spacing mark (NSM) in the level run, and
// change the type of the NSM to the type of the previous
// character. If the NSM is at the start of the level run, it will
// get the type of sor.
for (var i = 0, prev = outerType; i < len; ++i) {
var type = types[i];
if (type == "m") types[i] = prev;
else prev = type;
}
// W2. Search backwards from each instance of a European number
// until the first strong type (R, L, AL, or sor) is found. If an
// AL is found, change the type of the European number to Arabic
// number.
// W3. Change all ALs to R.
for (var i = 0, cur = outerType; i < len; ++i) {
var type = types[i];
if (type == "1" && cur == "r") types[i] = "n";
else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
}
// W4. A single European separator between two European numbers
// changes to a European number. A single common separator between
// two numbers of the same type changes to that type.
for (var i = 1, prev = types[0]; i < len - 1; ++i) {
var type = types[i];
if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
else if (type == "," && prev == types[i+1] &&
(prev == "1" || prev == "n")) types[i] = prev;
prev = type;
}
// W5. A sequence of European terminators adjacent to European
// numbers changes to all European numbers.
// W6. Otherwise, separators and terminators change to Other
// Neutral.
for (var i = 0; i < len; ++i) {
var type = types[i];
if (type == ",") types[i] = "N";
else if (type == "%") {
for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
var replace = (i && types[i-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
for (var j = i; j < end; ++j) types[j] = replace;
i = end - 1;
}
}
// W7. Search backwards from each instance of a European number
// until the first strong type (R, L, or sor) is found. If an L is
// found, then change the type of the European number to L.
for (var i = 0, cur = outerType; i < len; ++i) {
var type = types[i];
if (cur == "L" && type == "1") types[i] = "L";
else if (isStrong.test(type)) cur = type;
}
// N1. A sequence of neutrals takes the direction of the
// surrounding strong text if the text on both sides has the same
// direction. European and Arabic numbers act as if they were R in
// terms of their influence on neutrals. Start-of-level-run (sor)
// and end-of-level-run (eor) are used at level run boundaries.
// N2. Any remaining neutrals take the embedding direction.
for (var i = 0; i < len; ++i) {
if (isNeutral.test(types[i])) {
for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
var before = (i ? types[i-1] : outerType) == "L";
var after = (end < len ? types[end] : outerType) == "L";
var replace = before || after ? "L" : "R";
for (var j = i; j < end; ++j) types[j] = replace;
i = end - 1;
}
}
// Here we depart from the documented algorithm, in order to avoid
// building up an actual levels array. Since there are only three
// levels (0, 1, 2) in an implementation that doesn't take
// explicit embedding into account, we can build up the order on
// the fly, without following the level-based algorithm.
var order = [], m;
for (var i = 0; i < len;) {
if (countsAsLeft.test(types[i])) {
var start = i;
for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
order.push(new BidiSpan(0, start, i));
} else {
var pos = i, at = order.length;
for (++i; i < len && types[i] != "L"; ++i) {}
for (var j = pos; j < i;) {
if (countsAsNum.test(types[j])) {
if (pos < j) order.splice(at, 0, new BidiSpan(1, pos, j));
var nstart = j;
for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
order.splice(at, 0, new BidiSpan(2, nstart, j));
pos = j;
} else ++j;
}
if (pos < i) order.splice(at, 0, new BidiSpan(1, pos, i));
}
}
if (order[0].level == 1 && (m = str.match(/^\s+/))) {
order[0].from = m[0].length;
order.unshift(new BidiSpan(0, 0, m[0].length));
}
if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
lst(order).to -= m[0].length;
order.push(new BidiSpan(0, len - m[0].length, len));
}
if (order[0].level == 2)
order.unshift(new BidiSpan(1, order[0].to, order[0].to));
if (order[0].level != lst(order).level)
order.push(new BidiSpan(order[0].level, len, len));
return order;
};
})();
// THE END
CodeMirror.version = "5.14.2";
return CodeMirror;
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
(document.documentMode == null || document.documentMode < 8);
var Pos = CodeMirror.Pos;
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
function findMatchingBracket(cm, where, strict, config) {
var line = cm.getLineHandle(where.line), pos = where.ch - 1;
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
if (!match) return null;
var dir = match.charAt(1) == ">" ? 1 : -1;
if (strict && (dir > 0) != (pos == where.ch)) return null;
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
if (found == null) return null;
return {from: Pos(where.line, pos), to: found && found.pos,
match: found && found.ch == match.charAt(0), forward: dir > 0};
}
// bracketRegex is used to specify which type of bracket to scan
// should be a regexp, e.g. /[[\]]/
//
// Note: If "where" is on an open bracket, then this bracket is ignored.
//
// Returns false when no bracket was found, null when it reached
// maxScanLines and gave up
function scanForBracket(cm, where, dir, style, config) {
var maxScanLen = (config && config.maxScanLineLength) || 10000;
var maxScanLines = (config && config.maxScanLines) || 1000;
var stack = [];
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
: Math.max(cm.firstLine() - 1, where.line - maxScanLines);
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
var line = cm.getLine(lineNo);
if (!line) continue;
var pos = dir > 0 ? 0 : line.length - 1, end = dir > 0 ? line.length : -1;
if (line.length > maxScanLen) continue;
if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
for (; pos != end; pos += dir) {
var ch = line.charAt(pos);
if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) {
var match = matching[ch];
if ((match.charAt(1) == ">") == (dir > 0)) stack.push(ch);
else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch};
else stack.pop();
}
}
}
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
}
function matchBrackets(cm, autoclear, config) {
// Disable brace matching in long lines, since it'll cause hugely slow updates
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
var marks = [], ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, false, config);
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
}
}
if (marks.length) {
// Kludge to work around the IE bug from issue #1193, where text
// input stops going to the textare whever this fires.
if (ie_lt8 && cm.state.focused) cm.focus();
var clear = function() {
cm.operation(function() {
for (var i = 0; i < marks.length; i++) marks[i].clear();
});
};
if (autoclear) setTimeout(clear, 800);
else return clear;
}
}
var currentlyHighlighted = null;
function doMatchBrackets(cm) {
cm.operation(function() {
if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;}
currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
});
}
CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
if (old && old != CodeMirror.Init)
cm.off("cursorActivity", doMatchBrackets);
if (val) {
cm.state.matchBrackets = typeof val == "object" ? val : {};
cm.on("cursorActivity", doMatchBrackets);
}
});
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict, config){
return findMatchingBracket(this, pos, strict, config);
});
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
return scanForBracket(this, pos, dir, style, config);
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineOption("matchTags", false, function(cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.off("cursorActivity", doMatchTags);
cm.off("viewportChange", maybeUpdateMatch);
clear(cm);
}
if (val) {
cm.state.matchBothTags = typeof val == "object" && val.bothTags;
cm.on("cursorActivity", doMatchTags);
cm.on("viewportChange", maybeUpdateMatch);
doMatchTags(cm);
}
});
function clear(cm) {
if (cm.state.tagHit) cm.state.tagHit.clear();
if (cm.state.tagOther) cm.state.tagOther.clear();
cm.state.tagHit = cm.state.tagOther = null;
}
function doMatchTags(cm) {
cm.state.failedTagMatch = false;
cm.operation(function() {
clear(cm);
if (cm.somethingSelected()) return;
var cur = cm.getCursor(), range = cm.getViewport();
range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to);
var match = CodeMirror.findMatchingTag(cm, cur, range);
if (!match) return;
if (cm.state.matchBothTags) {
var hit = match.at == "open" ? match.open : match.close;
if (hit) cm.state.tagHit = cm.markText(hit.from, hit.to, {className: "CodeMirror-matchingtag"});
}
var other = match.at == "close" ? match.open : match.close;
if (other)
cm.state.tagOther = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"});
else
cm.state.failedTagMatch = true;
});
}
function maybeUpdateMatch(cm) {
if (cm.state.failedTagMatch) doMatchTags(cm);
}
CodeMirror.commands.toMatchingTag = function(cm) {
var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
if (found) {
var other = found.at == "close" ? found.open : found.close;
if (other) cm.extendSelection(other.to, other.from);
}
};
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
var defaults = {
pairs: "()[]{}''\"\"",
triples: "",
explode: "[]{}"
};
var Pos = CodeMirror.Pos;
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.removeKeyMap(keyMap);
cm.state.closeBrackets = null;
}
if (val) {
cm.state.closeBrackets = val;
cm.addKeyMap(keyMap);
}
});
function getOption(conf, name) {
if (name == "pairs" && typeof conf == "string") return conf;
if (typeof conf == "object" && conf[name] != null) return conf[name];
return defaults[name];
}
var bind = defaults.pairs + "`";
var keyMap = {Backspace: handleBackspace, Enter: handleEnter};
for (var i = 0; i < bind.length; i++)
keyMap["'" + bind.charAt(i) + "'"] = handler(bind.charAt(i));
function handler(ch) {
return function(cm) { return handleChar(cm, ch); };
}
function getConfig(cm) {
var deflt = cm.state.closeBrackets;
if (!deflt) return null;
var mode = cm.getModeAt(cm.getCursor());
return mode.closeBrackets || deflt;
}
function handleBackspace(cm) {
var conf = getConfig(cm);
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
var pairs = getOption(conf, "pairs");
var ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var around = charsAround(cm, ranges[i].head);
if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
}
for (var i = ranges.length - 1; i >= 0; i--) {
var cur = ranges[i].head;
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1), "+delete");
}
}
function handleEnter(cm) {
var conf = getConfig(cm);
var explode = conf && getOption(conf, "explode");
if (!explode || cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var around = charsAround(cm, ranges[i].head);
if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass;
}
cm.operation(function() {
cm.replaceSelection("\n\n", null);
cm.execCommand("goCharLeft");
ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var line = ranges[i].head.line;
cm.indentLine(line, null, true);
cm.indentLine(line + 1, null, true);
}
});
}
function contractSelection(sel) {
var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0;
return {anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)),
head: new Pos(sel.head.line, sel.head.ch + (inverted ? 1 : -1))};
}
function handleChar(cm, ch) {
var conf = getConfig(cm);
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
var pairs = getOption(conf, "pairs");
var pos = pairs.indexOf(ch);
if (pos == -1) return CodeMirror.Pass;
var triples = getOption(conf, "triples");
var identical = pairs.charAt(pos + 1) == ch;
var ranges = cm.listSelections();
var opening = pos % 2 == 0;
var type, next;
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i], cur = range.head, curType;
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
if (opening && !range.empty()) {
curType = "surround";
} else if ((identical || !opening) && next == ch) {
if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch)
curType = "skipThree";
else
curType = "skip";
} else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 &&
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch &&
(cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != ch)) {
curType = "addFour";
} else if (identical) {
if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, ch)) curType = "both";
else return CodeMirror.Pass;
} else if (opening && (cm.getLine(cur.line).length == cur.ch ||
isClosingBracket(next, pairs) ||
/\s/.test(next))) {
curType = "both";
} else {
return CodeMirror.Pass;
}
if (!type) type = curType;
else if (type != curType) return CodeMirror.Pass;
}
var left = pos % 2 ? pairs.charAt(pos - 1) : ch;
var right = pos % 2 ? ch : pairs.charAt(pos + 1);
cm.operation(function() {
if (type == "skip") {
cm.execCommand("goCharRight");
} else if (type == "skipThree") {
for (var i = 0; i < 3; i++)
cm.execCommand("goCharRight");
} else if (type == "surround") {
var sels = cm.getSelections();
for (var i = 0; i < sels.length; i++)
sels[i] = left + sels[i] + right;
cm.replaceSelections(sels, "around");
sels = cm.listSelections().slice();
for (var i = 0; i < sels.length; i++)
sels[i] = contractSelection(sels[i]);
cm.setSelections(sels);
} else if (type == "both") {
cm.replaceSelection(left + right, null);
cm.triggerElectric(left + right);
cm.execCommand("goCharLeft");
} else if (type == "addFour") {
cm.replaceSelection(left + left + left + left, "before");
cm.execCommand("goCharRight");
}
});
}
function isClosingBracket(ch, pairs) {
var pos = pairs.lastIndexOf(ch);
return pos > -1 && pos % 2 == 1;
}
function charsAround(cm, pos) {
var str = cm.getRange(Pos(pos.line, pos.ch - 1),
Pos(pos.line, pos.ch + 1));
return str.length == 2 ? str : null;
}
// Project the token type that will exists after the given char is
// typed, and use it to determine whether it would cause the start
// of a string token.
function enteringString(cm, pos, ch) {
var line = cm.getLine(pos.line);
var token = cm.getTokenAt(pos);
if (/\bstring2?\b/.test(token.type)) return false;
var stream = new CodeMirror.StringStream(line.slice(0, pos.ch) + ch + line.slice(pos.ch), 4);
stream.pos = stream.start = token.start;
for (;;) {
var type1 = cm.getMode().token(stream, token.state);
if (stream.pos >= pos.ch + 1) return /\bstring2?\b/.test(type1);
stream.start = stream.pos;
}
}
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
/**
* Tag-closer extension for CodeMirror.
*
* This extension adds an "autoCloseTags" option that can be set to
* either true to get the default behavior, or an object to further
* configure its behavior.
*
* These are supported options:
*
* `whenClosing` (default true)
* Whether to autoclose when the '/' of a closing tag is typed.
* `whenOpening` (default true)
* Whether to autoclose the tag when the final '>' of an opening
* tag is typed.
* `dontCloseTags` (default is empty tags for HTML, none for XML)
* An array of tag names that should not be autoclosed.
* `indentTags` (default is block tags for HTML, none for XML)
* An array of tag names that should, when opened, cause a
* blank line to be added inside the tag, and the blank line and
* closing line to be indented.
*
* See demos/closetag.html for a usage example.
*/
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) {
if (old != CodeMirror.Init && old)
cm.removeKeyMap("autoCloseTags");
if (!val) return;
var map = {name: "autoCloseTags"};
if (typeof val != "object" || val.whenClosing)
map["'/'"] = function(cm) { return autoCloseSlash(cm); };
if (typeof val != "object" || val.whenOpening)
map["'>'"] = function(cm) { return autoCloseGT(cm); };
cm.addKeyMap(map);
});
var htmlDontClose = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param",
"source", "track", "wbr"];
var htmlIndent = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4",
"h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
function autoCloseGT(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(), replacements = [];
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass;
var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
var tagName = state.tagName;
if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
var lowerTagName = tagName.toLowerCase();
// Don't process the '>' at the end of an end-tag or self-closing tag
if (!tagName ||
tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) ||
tok.type == "tag" && state.type == "closeTag" ||
tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 ||
closingTagExists(cm, tagName, pos, state, true))
return CodeMirror.Pass;
var indent = indentTags && indexOf(indentTags, lowerTagName) > -1;
replacements[i] = {indent: indent,
text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">",
newPos: indent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1)};
}
for (var i = ranges.length - 1; i >= 0; i--) {
var info = replacements[i];
cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, "+insert");
var sel = cm.listSelections().slice(0);
sel[i] = {head: info.newPos, anchor: info.newPos};
cm.setSelections(sel);
if (info.indent) {
cm.indentLine(info.newPos.line, null, true);
cm.indentLine(info.newPos.line + 1, null, true);
}
}
}
function autoCloseCurrent(cm, typingSlash) {
var ranges = cm.listSelections(), replacements = [];
var head = typingSlash ? "/" : "</";
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
if (typingSlash && (tok.type == "string" || tok.string.charAt(0) != "<" ||
tok.start != pos.ch - 1))
return CodeMirror.Pass;
// Kludge to get around the fact that we are not in XML mode
// when completing in JS/CSS snippet in htmlmixed mode. Does not
// work for other XML embedded languages (there is no general
// way to go from a mixed mode to its current XML state).
var replacement;
if (inner.mode.name != "xml") {
if (cm.getMode().name == "htmlmixed" && inner.mode.name == "javascript")
replacement = head + "script";
else if (cm.getMode().name == "htmlmixed" && inner.mode.name == "css")
replacement = head + "style";
else
return CodeMirror.Pass;
} else {
if (!state.context || !state.context.tagName ||
closingTagExists(cm, state.context.tagName, pos, state))
return CodeMirror.Pass;
replacement = head + state.context.tagName;
}
if (cm.getLine(pos.line).charAt(tok.end) != ">") replacement += ">";
replacements[i] = replacement;
}
cm.replaceSelections(replacements);
ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++)
if (i == ranges.length - 1 || ranges[i].head.line < ranges[i + 1].head.line)
cm.indentLine(ranges[i].head.line);
}
function autoCloseSlash(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
return autoCloseCurrent(cm, true);
}
CodeMirror.commands.closeTag = function(cm) { return autoCloseCurrent(cm); };
function indexOf(collection, elt) {
if (collection.indexOf) return collection.indexOf(elt);
for (var i = 0, e = collection.length; i < e; ++i)
if (collection[i] == elt) return i;
return -1;
}
// If xml-fold is loaded, we use its functionality to try and verify
// whether a given tag is actually unclosed.
function closingTagExists(cm, tagName, pos, state, newTag) {
if (!CodeMirror.scanForClosingTag) return false;
var end = Math.min(cm.lastLine() + 1, pos.line + 500);
var nextClose = CodeMirror.scanForClosingTag(cm, pos, null, end);
if (!nextClose || nextClose.tag != tagName) return false;
var cx = state.context;
// If the immediate wrapping context contains onCx instances of
// the same tag, a closing tag only exists if there are at least
// that many closing tags of that type following.
for (var onCx = newTag ? 1 : 0; cx && cx.tagName == tagName; cx = cx.prev) ++onCx;
pos = nextClose.to;
for (var i = 1; i < onCx; i++) {
var next = CodeMirror.scanForClosingTag(cm, pos, null, end);
if (!next || next.tag != tagName) return false;
pos = next.to;
}
return true;
}
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var noOptions = {};
var nonWS = /[^\s\u00a0]/;
var Pos = CodeMirror.Pos;
function firstNonWS(str) {
var found = str.search(nonWS);
return found == -1 ? 0 : found;
}
CodeMirror.commands.toggleComment = function(cm) {
cm.toggleComment();
};
CodeMirror.defineExtension("toggleComment", function(options) {
if (!options) options = noOptions;
var cm = this;
var minLine = Infinity, ranges = this.listSelections(), mode = null;
for (var i = ranges.length - 1; i >= 0; i--) {
var from = ranges[i].from(), to = ranges[i].to();
if (from.line >= minLine) continue;
if (to.line >= minLine) to = Pos(minLine, 0);
minLine = from.line;
if (mode == null) {
if (cm.uncomment(from, to, options)) mode = "un";
else { cm.lineComment(from, to, options); mode = "line"; }
} else if (mode == "un") {
cm.uncomment(from, to, options);
} else {
cm.lineComment(from, to, options);
}
}
});
// Rough heuristic to try and detect lines that are part of multi-line string
function probablyInsideString(cm, pos, line) {
return /\bstring\b/.test(cm.getTokenTypeAt(Pos(pos.line, 0))) && !/^[\'\"`]/.test(line)
}
CodeMirror.defineExtension("lineComment", function(from, to, options) {
if (!options) options = noOptions;
var self = this, mode = self.getModeAt(from);
var firstLine = self.getLine(from.line);
if (firstLine == null || probablyInsideString(self, from, firstLine)) return;
var commentString = options.lineComment || mode.lineComment;
if (!commentString) {
if (options.blockCommentStart || mode.blockCommentStart) {
options.fullLines = true;
self.blockComment(from, to, options);
}
return;
}
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1);
var pad = options.padding == null ? " " : options.padding;
var blankLines = options.commentBlankLines || from.line == to.line;
self.operation(function() {
if (options.indent) {
var baseString = null;
for (var i = from.line; i < end; ++i) {
var line = self.getLine(i);
var whitespace = line.slice(0, firstNonWS(line));
if (baseString == null || baseString.length > whitespace.length) {
baseString = whitespace;
}
}
for (var i = from.line; i < end; ++i) {
var line = self.getLine(i), cut = baseString.length;
if (!blankLines && !nonWS.test(line)) continue;
if (line.slice(0, cut) != baseString) cut = firstNonWS(line);
self.replaceRange(baseString + commentString + pad, Pos(i, 0), Pos(i, cut));
}
} else {
for (var i = from.line; i < end; ++i) {
if (blankLines || nonWS.test(self.getLine(i)))
self.replaceRange(commentString + pad, Pos(i, 0));
}
}
});
});
CodeMirror.defineExtension("blockComment", function(from, to, options) {
if (!options) options = noOptions;
var self = this, mode = self.getModeAt(from);
var startString = options.blockCommentStart || mode.blockCommentStart;
var endString = options.blockCommentEnd || mode.blockCommentEnd;
if (!startString || !endString) {
if ((options.lineComment || mode.lineComment) && options.fullLines != false)
self.lineComment(from, to, options);
return;
}
var end = Math.min(to.line, self.lastLine());
if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end;
var pad = options.padding == null ? " " : options.padding;
if (from.line > end) return;
self.operation(function() {
if (options.fullLines != false) {
var lastLineHasText = nonWS.test(self.getLine(end));
self.replaceRange(pad + endString, Pos(end));
self.replaceRange(startString + pad, Pos(from.line, 0));
var lead = options.blockCommentLead || mode.blockCommentLead;
if (lead != null) for (var i = from.line + 1; i <= end; ++i)
if (i != end || lastLineHasText)
self.replaceRange(lead + pad, Pos(i, 0));
} else {
self.replaceRange(endString, to);
self.replaceRange(startString, from);
}
});
});
CodeMirror.defineExtension("uncomment", function(from, to, options) {
if (!options) options = noOptions;
var self = this, mode = self.getModeAt(from);
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()), start = Math.min(from.line, end);
// Try finding line comments
var lineString = options.lineComment || mode.lineComment, lines = [];
var pad = options.padding == null ? " " : options.padding, didSomething;
lineComment: {
if (!lineString) break lineComment;
for (var i = start; i <= end; ++i) {
var line = self.getLine(i);
var found = line.indexOf(lineString);
if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1;
if (found == -1 && (i != end || i == start) && nonWS.test(line)) break lineComment;
if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment;
lines.push(line);
}
self.operation(function() {
for (var i = start; i <= end; ++i) {
var line = lines[i - start];
var pos = line.indexOf(lineString), endPos = pos + lineString.length;
if (pos < 0) continue;
if (line.slice(endPos, endPos + pad.length) == pad) endPos += pad.length;
didSomething = true;
self.replaceRange("", Pos(i, pos), Pos(i, endPos));
}
});
if (didSomething) return true;
}
// Try block comments
var startString = options.blockCommentStart || mode.blockCommentStart;
var endString = options.blockCommentEnd || mode.blockCommentEnd;
if (!startString || !endString) return false;
var lead = options.blockCommentLead || mode.blockCommentLead;
var startLine = self.getLine(start), endLine = end == start ? startLine : self.getLine(end);
var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endString);
if (close == -1 && start != end) {
endLine = self.getLine(--end);
close = endLine.lastIndexOf(endString);
}
if (open == -1 || close == -1 ||
!/comment/.test(self.getTokenTypeAt(Pos(start, open + 1))) ||
!/comment/.test(self.getTokenTypeAt(Pos(end, close + 1))))
return false;
// Avoid killing block comments completely outside the selection.
// Positions of the last startString before the start of the selection, and the first endString after it.
var lastStart = startLine.lastIndexOf(startString, from.ch);
var firstEnd = lastStart == -1 ? -1 : startLine.slice(0, from.ch).indexOf(endString, lastStart + startString.length);
if (lastStart != -1 && firstEnd != -1 && firstEnd + endString.length != from.ch) return false;
// Positions of the first endString after the end of the selection, and the last startString before it.
firstEnd = endLine.indexOf(endString, to.ch);
var almostLastStart = endLine.slice(to.ch).lastIndexOf(startString, firstEnd - to.ch);
lastStart = (firstEnd == -1 || almostLastStart == -1) ? -1 : to.ch + almostLastStart;
if (firstEnd != -1 && lastStart != -1 && lastStart != to.ch) return false;
self.operation(function() {
self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.length, close) == pad ? pad.length : 0)),
Pos(end, close + endString.length));
var openEnd = open + startString.length;
if (pad && startLine.slice(openEnd, openEnd + pad.length) == pad) openEnd += pad.length;
self.replaceRange("", Pos(start, open), Pos(start, openEnd));
if (lead) for (var i = start + 1; i <= end; ++i) {
var line = self.getLine(i), found = line.indexOf(lead);
if (found == -1 || nonWS.test(line.slice(0, found))) continue;
var foundEnd = found + lead.length;
if (pad && line.slice(foundEnd, foundEnd + pad.length) == pad) foundEnd += pad.length;
self.replaceRange("", Pos(i, found), Pos(i, foundEnd));
}
});
return true;
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
function doFold(cm, pos, options, force) {
if (options && options.call) {
var finder = options;
options = null;
} else {
var finder = getOption(cm, options, "rangeFinder");
}
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
var minSize = getOption(cm, options, "minFoldSize");
function getRange(allowFolded) {
var range = finder(cm, pos);
if (!range || range.to.line - range.from.line < minSize) return null;
var marks = cm.findMarksAt(range.from);
for (var i = 0; i < marks.length; ++i) {
if (marks[i].__isFold && force !== "fold") {
if (!allowFolded) return null;
range.cleared = true;
marks[i].clear();
}
}
return range;
}
var range = getRange(true);
if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
pos = CodeMirror.Pos(pos.line - 1, 0);
range = getRange(false);
}
if (!range || range.cleared || force === "unfold") return;
var myWidget = makeWidget(cm, options);
CodeMirror.on(myWidget, "mousedown", function(e) {
myRange.clear();
CodeMirror.e_preventDefault(e);
});
var myRange = cm.markText(range.from, range.to, {
replacedWith: myWidget,
clearOnEnter: true,
__isFold: true
});
myRange.on("clear", function(from, to) {
CodeMirror.signal(cm, "unfold", cm, from, to);
});
CodeMirror.signal(cm, "fold", cm, range.from, range.to);
}
function makeWidget(cm, options) {
var widget = getOption(cm, options, "widget");
if (typeof widget == "string") {
var text = document.createTextNode(widget);
widget = document.createElement("span");
widget.appendChild(text);
widget.className = "CodeMirror-foldmarker";
}
return widget;
}
// Clumsy backwards-compatible interface
CodeMirror.newFoldFunction = function(rangeFinder, widget) {
return function(cm, pos) { doFold(cm, pos, {rangeFinder: rangeFinder, widget: widget}); };
};
// New-style interface
CodeMirror.defineExtension("foldCode", function(pos, options, force) {
doFold(this, pos, options, force);
});
CodeMirror.defineExtension("isFolded", function(pos) {
var marks = this.findMarksAt(pos);
for (var i = 0; i < marks.length; ++i)
if (marks[i].__isFold) return true;
});
CodeMirror.commands.toggleFold = function(cm) {
cm.foldCode(cm.getCursor());
};
CodeMirror.commands.fold = function(cm) {
cm.foldCode(cm.getCursor(), null, "fold");
};
CodeMirror.commands.unfold = function(cm) {
cm.foldCode(cm.getCursor(), null, "unfold");
};
CodeMirror.commands.foldAll = function(cm) {
cm.operation(function() {
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
});
};
CodeMirror.commands.unfoldAll = function(cm) {
cm.operation(function() {
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
cm.foldCode(CodeMirror.Pos(i, 0), null, "unfold");
});
};
CodeMirror.registerHelper("fold", "combine", function() {
var funcs = Array.prototype.slice.call(arguments, 0);
return function(cm, start) {
for (var i = 0; i < funcs.length; ++i) {
var found = funcs[i](cm, start);
if (found) return found;
}
};
});
CodeMirror.registerHelper("fold", "auto", function(cm, start) {
var helpers = cm.getHelpers(start, "fold");
for (var i = 0; i < helpers.length; i++) {
var cur = helpers[i](cm, start);
if (cur) return cur;
}
});
var defaultOptions = {
rangeFinder: CodeMirror.fold.auto,
widget: "\u2194",
minFoldSize: 0,
scanUp: false
};
CodeMirror.defineOption("foldOptions", null);
function getOption(cm, options, name) {
if (options && options[name] !== undefined)
return options[name];
var editorOptions = cm.options.foldOptions;
if (editorOptions && editorOptions[name] !== undefined)
return editorOptions[name];
return defaultOptions[name];
}
CodeMirror.defineExtension("foldOption", function(options, name) {
return getOption(this, options, name);
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("./foldcode"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "./foldcode"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineOption("foldGutter", false, function(cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.clearGutter(cm.state.foldGutter.options.gutter);
cm.state.foldGutter = null;
cm.off("gutterClick", onGutterClick);
cm.off("change", onChange);
cm.off("viewportChange", onViewportChange);
cm.off("fold", onFold);
cm.off("unfold", onFold);
cm.off("swapDoc", onChange);
}
if (val) {
cm.state.foldGutter = new State(parseOptions(val));
updateInViewport(cm);
cm.on("gutterClick", onGutterClick);
cm.on("change", onChange);
cm.on("viewportChange", onViewportChange);
cm.on("fold", onFold);
cm.on("unfold", onFold);
cm.on("swapDoc", onChange);
}
});
var Pos = CodeMirror.Pos;
function State(options) {
this.options = options;
this.from = this.to = 0;
}
function parseOptions(opts) {
if (opts === true) opts = {};
if (opts.gutter == null) opts.gutter = "CodeMirror-foldgutter";
if (opts.indicatorOpen == null) opts.indicatorOpen = "CodeMirror-foldgutter-open";
if (opts.indicatorFolded == null) opts.indicatorFolded = "CodeMirror-foldgutter-folded";
return opts;
}
function isFolded(cm, line) {
var marks = cm.findMarksAt(Pos(line));
for (var i = 0; i < marks.length; ++i)
if (marks[i].__isFold && marks[i].find().from.line == line) return marks[i];
}
function marker(spec) {
if (typeof spec == "string") {
var elt = document.createElement("div");
elt.className = spec + " CodeMirror-guttermarker-subtle";
return elt;
} else {
return spec.cloneNode(true);
}
}
function updateFoldInfo(cm, from, to) {
var opts = cm.state.foldGutter.options, cur = from;
var minSize = cm.foldOption(opts, "minFoldSize");
var func = cm.foldOption(opts, "rangeFinder");
cm.eachLine(from, to, function(line) {
var mark = null;
if (isFolded(cm, cur)) {
mark = marker(opts.indicatorFolded);
} else {
var pos = Pos(cur, 0);
var range = func && func(cm, pos);
if (range && range.to.line - range.from.line >= minSize)
mark = marker(opts.indicatorOpen);
}
cm.setGutterMarker(line, opts.gutter, mark);
++cur;
});
}
function updateInViewport(cm) {
var vp = cm.getViewport(), state = cm.state.foldGutter;
if (!state) return;
cm.operation(function() {
updateFoldInfo(cm, vp.from, vp.to);
});
state.from = vp.from; state.to = vp.to;
}
function onGutterClick(cm, line, gutter) {
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
if (gutter != opts.gutter) return;
var folded = isFolded(cm, line);
if (folded) folded.clear();
else cm.foldCode(Pos(line, 0), opts.rangeFinder);
}
function onChange(cm) {
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
state.from = state.to = 0;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function() { updateInViewport(cm); }, opts.foldOnChangeTimeSpan || 600);
}
function onViewportChange(cm) {
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function() {
var vp = cm.getViewport();
if (state.from == state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
updateInViewport(cm);
} else {
cm.operation(function() {
if (vp.from < state.from) {
updateFoldInfo(cm, vp.from, state.from);
state.from = vp.from;
}
if (vp.to > state.to) {
updateFoldInfo(cm, state.to, vp.to);
state.to = vp.to;
}
});
}
}, opts.updateViewportTimeSpan || 400);
}
function onFold(cm, from) {
var state = cm.state.foldGutter;
if (!state) return;
var line = from.line;
if (line >= state.from && line < state.to)
updateFoldInfo(cm, line, line + 1);
}
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var Pos = CodeMirror.Pos;
function cmp(a, b) { return a.line - b.line || a.ch - b.ch; }
var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
var xmlTagStart = new RegExp("<(/?)([" + nameStartChar + "][" + nameChar + "]*)", "g");
function Iter(cm, line, ch, range) {
this.line = line; this.ch = ch;
this.cm = cm; this.text = cm.getLine(line);
this.min = range ? range.from : cm.firstLine();
this.max = range ? range.to - 1 : cm.lastLine();
}
function tagAt(iter, ch) {
var type = iter.cm.getTokenTypeAt(Pos(iter.line, ch));
return type && /\btag\b/.test(type);
}
function nextLine(iter) {
if (iter.line >= iter.max) return;
iter.ch = 0;
iter.text = iter.cm.getLine(++iter.line);
return true;
}
function prevLine(iter) {
if (iter.line <= iter.min) return;
iter.text = iter.cm.getLine(--iter.line);
iter.ch = iter.text.length;
return true;
}
function toTagEnd(iter) {
for (;;) {
var gt = iter.text.indexOf(">", iter.ch);
if (gt == -1) { if (nextLine(iter)) continue; else return; }
if (!tagAt(iter, gt + 1)) { iter.ch = gt + 1; continue; }
var lastSlash = iter.text.lastIndexOf("/", gt);
var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt));
iter.ch = gt + 1;
return selfClose ? "selfClose" : "regular";
}
}
function toTagStart(iter) {
for (;;) {
var lt = iter.ch ? iter.text.lastIndexOf("<", iter.ch - 1) : -1;
if (lt == -1) { if (prevLine(iter)) continue; else return; }
if (!tagAt(iter, lt + 1)) { iter.ch = lt; continue; }
xmlTagStart.lastIndex = lt;
iter.ch = lt;
var match = xmlTagStart.exec(iter.text);
if (match && match.index == lt) return match;
}
}
function toNextTag(iter) {
for (;;) {
xmlTagStart.lastIndex = iter.ch;
var found = xmlTagStart.exec(iter.text);
if (!found) { if (nextLine(iter)) continue; else return; }
if (!tagAt(iter, found.index + 1)) { iter.ch = found.index + 1; continue; }
iter.ch = found.index + found[0].length;
return found;
}
}
function toPrevTag(iter) {
for (;;) {
var gt = iter.ch ? iter.text.lastIndexOf(">", iter.ch - 1) : -1;
if (gt == -1) { if (prevLine(iter)) continue; else return; }
if (!tagAt(iter, gt + 1)) { iter.ch = gt; continue; }
var lastSlash = iter.text.lastIndexOf("/", gt);
var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt));
iter.ch = gt + 1;
return selfClose ? "selfClose" : "regular";
}
}
function findMatchingClose(iter, tag) {
var stack = [];
for (;;) {
var next = toNextTag(iter), end, startLine = iter.line, startCh = iter.ch - (next ? next[0].length : 0);
if (!next || !(end = toTagEnd(iter))) return;
if (end == "selfClose") continue;
if (next[1]) { // closing tag
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == next[2]) {
stack.length = i;
break;
}
if (i < 0 && (!tag || tag == next[2])) return {
tag: next[2],
from: Pos(startLine, startCh),
to: Pos(iter.line, iter.ch)
};
} else { // opening tag
stack.push(next[2]);
}
}
}
function findMatchingOpen(iter, tag) {
var stack = [];
for (;;) {
var prev = toPrevTag(iter);
if (!prev) return;
if (prev == "selfClose") { toTagStart(iter); continue; }
var endLine = iter.line, endCh = iter.ch;
var start = toTagStart(iter);
if (!start) return;
if (start[1]) { // closing tag
stack.push(start[2]);
} else { // opening tag
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == start[2]) {
stack.length = i;
break;
}
if (i < 0 && (!tag || tag == start[2])) return {
tag: start[2],
from: Pos(iter.line, iter.ch),
to: Pos(endLine, endCh)
};
}
}
}
CodeMirror.registerHelper("fold", "xml", function(cm, start) {
var iter = new Iter(cm, start.line, 0);
for (;;) {
var openTag = toNextTag(iter), end;
if (!openTag || iter.line != start.line || !(end = toTagEnd(iter))) return;
if (!openTag[1] && end != "selfClose") {
var start = Pos(iter.line, iter.ch);
var close = findMatchingClose(iter, openTag[2]);
return close && {from: start, to: close.from};
}
}
});
CodeMirror.findMatchingTag = function(cm, pos, range) {
var iter = new Iter(cm, pos.line, pos.ch, range);
if (iter.text.indexOf(">") == -1 && iter.text.indexOf("<") == -1) return;
var end = toTagEnd(iter), to = end && Pos(iter.line, iter.ch);
var start = end && toTagStart(iter);
if (!end || !start || cmp(iter, pos) > 0) return;
var here = {from: Pos(iter.line, iter.ch), to: to, tag: start[2]};
if (end == "selfClose") return {open: here, close: null, at: "open"};
if (start[1]) { // closing tag
return {open: findMatchingOpen(iter, start[2]), close: here, at: "close"};
} else { // opening tag
iter = new Iter(cm, to.line, to.ch, range);
return {open: here, close: findMatchingClose(iter, start[2]), at: "open"};
}
};
CodeMirror.findEnclosingTag = function(cm, pos, range) {
var iter = new Iter(cm, pos.line, pos.ch, range);
for (;;) {
var open = findMatchingOpen(iter);
if (!open) break;
var forward = new Iter(cm, pos.line, pos.ch, range);
var close = findMatchingClose(forward, open.tag);
if (close) return {open: open, close: close};
}
};
// Used by addon/edit/closetag.js
CodeMirror.scanForClosingTag = function(cm, pos, name, end) {
var iter = new Iter(cm, pos.line, pos.ch, end ? {from: 0, to: end} : null);
return findMatchingClose(iter, name);
};
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.registerHelper("fold", "indent", function(cm, start) {
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
if (!/\S/.test(firstLine)) return;
var getIndent = function(line) {
return CodeMirror.countColumn(line, null, tabSize);
};
var myIndent = getIndent(firstLine);
var lastLineInFold = null;
// Go through lines until we find a line that definitely doesn't belong in
// the block we're folding, or to the end.
for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
var curLine = cm.getLine(i);
var curIndent = getIndent(curLine);
if (curIndent > myIndent) {
// Lines with a greater indent are considered part of the block.
lastLineInFold = i;
} else if (!/\S/.test(curLine)) {
// Empty lines might be breaks within the block we're trying to fold.
} else {
// A non-empty line at an indent equal to or less than ours marks the
// start of another block.
break;
}
}
if (lastLineInFold) return {
from: CodeMirror.Pos(start.line, firstLine.length),
to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
};
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
return mode.blockCommentStart && mode.blockCommentEnd;
}, function(cm, start) {
var mode = cm.getModeAt(start), startToken = mode.blockCommentStart, endToken = mode.blockCommentEnd;
if (!startToken || !endToken) return;
var line = start.line, lineText = cm.getLine(line);
var startCh;
for (var at = start.ch, pass = 0;;) {
var found = at <= 0 ? -1 : lineText.lastIndexOf(startToken, at - 1);
if (found == -1) {
if (pass == 1) return;
pass = 1;
at = lineText.length;
continue;
}
if (pass == 1 && found < start.ch) return;
if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1))) &&
(lineText.slice(found - endToken.length, found) == endToken ||
!/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found))))) {
startCh = found + startToken.length;
break;
}
at = found - 1;
}
var depth = 1, lastLine = cm.lastLine(), end, endCh;
outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i), pos = i == line ? startCh : 0;
for (;;) {
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (pos == nextOpen) ++depth;
else if (!--depth) { end = i; endCh = pos; break outer; }
++pos;
}
}
if (end == null || line == end && endCh == startCh) return;
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.registerHelper("fold", "brace", function(cm, start) {
var line = start.line, lineText = cm.getLine(line);
var startCh, tokenType;
function findOpening(openCh) {
for (var at = start.ch, pass = 0;;) {
var found = at <= 0 ? -1 : lineText.lastIndexOf(openCh, at - 1);
if (found == -1) {
if (pass == 1) break;
pass = 1;
at = lineText.length;
continue;
}
if (pass == 1 && found < start.ch) break;
tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
if (!/^(comment|string)/.test(tokenType)) return found + 1;
at = found - 1;
}
}
var startToken = "{", endToken = "}", startCh = findOpening("{");
if (startCh == null) {
startToken = "[", endToken = "]";
startCh = findOpening("[");
}
if (startCh == null) return;
var count = 1, lastLine = cm.lastLine(), end, endCh;
outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i), pos = i == line ? startCh : 0;
for (;;) {
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == tokenType) {
if (pos == nextOpen) ++count;
else if (!--count) { end = i; endCh = pos; break outer; }
}
++pos;
}
}
if (end == null || line == end && endCh == startCh) return;
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
});
CodeMirror.registerHelper("fold", "import", function(cm, start) {
function hasImport(line) {
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type != "keyword" || start.string != "import") return null;
// Now find closing semicolon, return its position
for (var i = line, e = Math.min(cm.lastLine(), line + 10); i <= e; ++i) {
var text = cm.getLine(i), semi = text.indexOf(";");
if (semi != -1) return {startCh: start.end, end: CodeMirror.Pos(i, semi)};
}
}
var start = start.line, has = hasImport(start), prev;
if (!has || hasImport(start - 1) || ((prev = hasImport(start - 2)) && prev.end.line == start - 1))
return null;
for (var end = has.end;;) {
var next = hasImport(end.line + 1);
if (next == null) break;
end = next.end;
}
return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end};
});
CodeMirror.registerHelper("fold", "include", function(cm, start) {
function hasInclude(line) {
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type == "meta" && start.string.slice(0, 8) == "#include") return start.start + 8;
}
var start = start.line, has = hasInclude(start);
if (has == null || hasInclude(start - 1) != null) return null;
for (var end = start;;) {
var next = hasInclude(end + 1);
if (next == null) break;
++end;
}
return {from: CodeMirror.Pos(start, has + 1),
to: cm.clipPos(CodeMirror.Pos(end))};
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), "cjs");
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], function(CM) { mod(CM, "amd"); });
else // Plain browser env
mod(CodeMirror, "plain");
})(function(CodeMirror, env) {
if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";
var loading = {};
function splitCallback(cont, n) {
var countDown = n;
return function() { if (--countDown == 0) cont(); };
}
function ensureDeps(mode, cont) {
var deps = CodeMirror.modes[mode].dependencies;
if (!deps) return cont();
var missing = [];
for (var i = 0; i < deps.length; ++i) {
if (!CodeMirror.modes.hasOwnProperty(deps[i]))
missing.push(deps[i]);
}
if (!missing.length) return cont();
var split = splitCallback(cont, missing.length);
for (var i = 0; i < missing.length; ++i)
CodeMirror.requireMode(missing[i], split);
}
CodeMirror.requireMode = function(mode, cont) {
if (typeof mode != "string") mode = mode.name;
if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont);
if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);
var file = CodeMirror.modeURL.replace(/%N/g, mode);
if (env == "plain") {
var script = document.createElement("script");
script.src = file;
var others = document.getElementsByTagName("script")[0];
var list = loading[mode] = [cont];
CodeMirror.on(script, "load", function() {
ensureDeps(mode, function() {
for (var i = 0; i < list.length; ++i) list[i]();
});
});
others.parentNode.insertBefore(script, others);
} else if (env == "cjs") {
require(file);
cont();
} else if (env == "amd") {
requirejs([file], cont);
}
};
CodeMirror.autoLoadMode = function(instance, mode) {
if (!CodeMirror.modes.hasOwnProperty(mode))
CodeMirror.requireMode(mode, function() {
instance.setOption("mode", instance.getOption("mode"));
});
};
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
// This is the old interface, kept around for now to stay
// backwards-compatible.
CodeMirror.showHint = function(cm, getHints, options) {
if (!getHints) return cm.showHint(options);
if (options && options.async) getHints.async = true;
var newOpts = {hint: getHints};
if (options) for (var prop in options) newOpts[prop] = options[prop];
return cm.showHint(newOpts);
};
CodeMirror.defineExtension("showHint", function(options) {
options = parseOptions(this, this.getCursor("start"), options);
var selections = this.listSelections()
if (selections.length > 1) return;
// By default, don't allow completion when something is selected.
// A hint function can have a `supportsSelection` property to
// indicate that it can handle selections.
if (this.somethingSelected()) {
if (!options.hint.supportsSelection) return;
// Don't try with cross-line selections
for (var i = 0; i < selections.length; i++)
if (selections[i].head.line != selections[i].anchor.line) return;
}
if (this.state.completionActive) this.state.completionActive.close();
var completion = this.state.completionActive = new Completion(this, options);
if (!completion.options.hint) return;
CodeMirror.signal(this, "startCompletion", this);
completion.update(true);
});
function Completion(cm, options) {
this.cm = cm;
this.options = options;
this.widget = null;
this.debounce = 0;
this.tick = 0;
this.startPos = this.cm.getCursor("start");
this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
var self = this;
cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
}
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
return setTimeout(fn, 1000/60);
};
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
Completion.prototype = {
close: function() {
if (!this.active()) return;
this.cm.state.completionActive = null;
this.tick = null;
this.cm.off("cursorActivity", this.activityFunc);
if (this.widget && this.data) CodeMirror.signal(this.data, "close");
if (this.widget) this.widget.close();
CodeMirror.signal(this.cm, "endCompletion", this.cm);
},
active: function() {
return this.cm.state.completionActive == this;
},
pick: function(data, i) {
var completion = data.list[i];
if (completion.hint) completion.hint(this.cm, data, completion);
else this.cm.replaceRange(getText(completion), completion.from || data.from,
completion.to || data.to, "complete");
CodeMirror.signal(data, "pick", completion);
this.close();
},
cursorActivity: function() {
if (this.debounce) {
cancelAnimationFrame(this.debounce);
this.debounce = 0;
}
var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
pos.ch < this.startPos.ch || this.cm.somethingSelected() ||
(pos.ch && this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
this.close();
} else {
var self = this;
this.debounce = requestAnimationFrame(function() {self.update();});
if (this.widget) this.widget.disable();
}
},
update: function(first) {
if (this.tick == null) return
var self = this, myTick = ++this.tick
fetchHints(this.options.hint, this.cm, this.options, function(data) {
if (self.tick == myTick) self.finishUpdate(data, first)
})
},
finishUpdate: function(data, first) {
if (this.data) CodeMirror.signal(this.data, "update");
var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
if (this.widget) this.widget.close();
if (data && this.data && isNewCompletion(this.data, data)) return;
this.data = data;
if (data && data.list.length) {
if (picked && data.list.length == 1) {
this.pick(data, 0);
} else {
this.widget = new Widget(this, data);
CodeMirror.signal(data, "shown");
}
}
}
};
function isNewCompletion(old, nw) {
var moved = CodeMirror.cmpPos(nw.from, old.from)
return moved > 0 && old.to.ch - old.from.ch != nw.to.ch - nw.from.ch
}
function parseOptions(cm, pos, options) {
var editor = cm.options.hintOptions;
var out = {};
for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
if (editor) for (var prop in editor)
if (editor[prop] !== undefined) out[prop] = editor[prop];
if (options) for (var prop in options)
if (options[prop] !== undefined) out[prop] = options[prop];
if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos)
return out;
}
function getText(completion) {
if (typeof completion == "string") return completion;
else return completion.text;
}
function buildKeyMap(completion, handle) {
var baseMap = {
Up: function() {handle.moveFocus(-1);},
Down: function() {handle.moveFocus(1);},
PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
Home: function() {handle.setFocus(0);},
End: function() {handle.setFocus(handle.length - 1);},
Enter: handle.pick,
Tab: handle.pick,
Esc: handle.close
};
var custom = completion.options.customKeys;
var ourMap = custom ? {} : baseMap;
function addBinding(key, val) {
var bound;
if (typeof val != "string")
bound = function(cm) { return val(cm, handle); };
// This mechanism is deprecated
else if (baseMap.hasOwnProperty(val))
bound = baseMap[val];
else
bound = val;
ourMap[key] = bound;
}
if (custom)
for (var key in custom) if (custom.hasOwnProperty(key))
addBinding(key, custom[key]);
var extra = completion.options.extraKeys;
if (extra)
for (var key in extra) if (extra.hasOwnProperty(key))
addBinding(key, extra[key]);
return ourMap;
}
function getHintElement(hintsElement, el) {
while (el && el != hintsElement) {
if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
el = el.parentNode;
}
}
function Widget(completion, data) {
this.completion = completion;
this.data = data;
this.picked = false;
var widget = this, cm = completion.cm;
var hints = this.hints = document.createElement("ul");
hints.className = "CodeMirror-hints";
this.selectedHint = data.selectedHint || 0;
var completions = data.list;
for (var i = 0; i < completions.length; ++i) {
var elt = hints.appendChild(document.createElement("li")), cur = completions[i];
var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
if (cur.className != null) className = cur.className + " " + className;
elt.className = className;
if (cur.render) cur.render(elt, data, cur);
else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
elt.hintId = i;
}
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
var left = pos.left, top = pos.bottom, below = true;
hints.style.left = left + "px";
hints.style.top = top + "px";
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
(completion.options.container || document.body).appendChild(hints);
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
if (overlapY > 0) {
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
if (curTop - height > 0) { // Fits above cursor
hints.style.top = (top = pos.top - height) + "px";
below = false;
} else if (height > winH) {
hints.style.height = (winH - 5) + "px";
hints.style.top = (top = pos.bottom - box.top) + "px";
var cursor = cm.getCursor();
if (data.from.ch != cursor.ch) {
pos = cm.cursorCoords(cursor);
hints.style.left = (left = pos.left) + "px";
box = hints.getBoundingClientRect();
}
}
}
var overlapX = box.right - winW;
if (overlapX > 0) {
if (box.right - box.left > winW) {
hints.style.width = (winW - 5) + "px";
overlapX -= (box.right - box.left) - winW;
}
hints.style.left = (left = pos.left - overlapX) + "px";
}
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
setFocus: function(n) { widget.changeActive(n); },
menuSize: function() { return widget.screenAmount(); },
length: completions.length,
close: function() { completion.close(); },
pick: function() { widget.pick(); },
data: data
}));
if (completion.options.closeOnUnfocus) {
var closingOnBlur;
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
}
var startScroll = cm.getScrollInfo();
cm.on("scroll", this.onScroll = function() {
var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
var newTop = top + startScroll.top - curScroll.top;
var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
if (!below) point += hints.offsetHeight;
if (point <= editor.top || point >= editor.bottom) return completion.close();
hints.style.top = newTop + "px";
hints.style.left = (left + startScroll.left - curScroll.left) + "px";
});
CodeMirror.on(hints, "dblclick", function(e) {
var t = getHintElement(hints, e.target || e.srcElement);
if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
});
CodeMirror.on(hints, "click", function(e) {
var t = getHintElement(hints, e.target || e.srcElement);
if (t && t.hintId != null) {
widget.changeActive(t.hintId);
if (completion.options.completeOnSingleClick) widget.pick();
}
});
CodeMirror.on(hints, "mousedown", function() {
setTimeout(function(){cm.focus();}, 20);
});
CodeMirror.signal(data, "select", completions[0], hints.firstChild);
return true;
}
Widget.prototype = {
close: function() {
if (this.completion.widget != this) return;
this.completion.widget = null;
this.hints.parentNode.removeChild(this.hints);
this.completion.cm.removeKeyMap(this.keyMap);
var cm = this.completion.cm;
if (this.completion.options.closeOnUnfocus) {
cm.off("blur", this.onBlur);
cm.off("focus", this.onFocus);
}
cm.off("scroll", this.onScroll);
},
disable: function() {
this.completion.cm.removeKeyMap(this.keyMap);
var widget = this;
this.keyMap = {Enter: function() { widget.picked = true; }};
this.completion.cm.addKeyMap(this.keyMap);
},
pick: function() {
this.completion.pick(this.data, this.selectedHint);
},
changeActive: function(i, avoidWrap) {
if (i >= this.data.list.length)
i = avoidWrap ? this.data.list.length - 1 : 0;
else if (i < 0)
i = avoidWrap ? 0 : this.data.list.length - 1;
if (this.selectedHint == i) return;
var node = this.hints.childNodes[this.selectedHint];
node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
node = this.hints.childNodes[this.selectedHint = i];
node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
if (node.offsetTop < this.hints.scrollTop)
this.hints.scrollTop = node.offsetTop - 3;
else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
},
screenAmount: function() {
return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
}
};
function applicableHelpers(cm, helpers) {
if (!cm.somethingSelected()) return helpers
var result = []
for (var i = 0; i < helpers.length; i++)
if (helpers[i].supportsSelection) result.push(helpers[i])
return result
}
function fetchHints(hint, cm, options, callback) {
if (hint.async) {
hint(cm, callback, options)
} else {
var result = hint(cm, options)
if (result && result.then) result.then(callback)
else callback(result)
}
}
function resolveAutoHints(cm, pos) {
var helpers = cm.getHelpers(pos, "hint"), words
if (helpers.length) {
var resolved = function(cm, callback, options) {
var app = applicableHelpers(cm, helpers);
function run(i) {
if (i == app.length) return callback(null)
fetchHints(app[i], cm, options, function(result) {
if (result && result.list.length > 0) callback(result)
else run(i + 1)
})
}
run(0)
}
resolved.async = true
resolved.supportsSelection = true
return resolved
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
return function(cm) { return CodeMirror.hint.fromList(cm, {words: words}) }
} else if (CodeMirror.hint.anyword) {
return function(cm, options) { return CodeMirror.hint.anyword(cm, options) }
} else {
return function() {}
}
}
CodeMirror.registerHelper("hint", "auto", {
resolve: resolveAutoHints
});
CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
var to = CodeMirror.Pos(cur.line, token.end);
if (token.string && /\w/.test(token.string[token.string.length - 1])) {
var term = token.string, from = CodeMirror.Pos(cur.line, token.start);
} else {
var term = "", from = to;
}
var found = [];
for (var i = 0; i < options.words.length; i++) {
var word = options.words[i];
if (word.slice(0, term.length) == term)
found.push(word);
}
if (found.length) return {list: found, from: from, to: to};
});
CodeMirror.commands.autocomplete = CodeMirror.showHint;
var defaultOptions = {
hint: CodeMirror.hint.auto,
completeSingle: true,
alignWithWord: true,
closeCharacters: /[\s()\[\]{};:>,]/,
closeOnUnfocus: true,
completeOnSingleClick: true,
container: null,
customKeys: null,
extraKeys: null
};
CodeMirror.defineOption("hintOptions", null);
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
var Pos = CodeMirror.Pos;
function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}
function arrayContains(arr, item) {
if (!Array.prototype.indexOf) {
var i = arr.length;
while (i--) {
if (arr[i] === item) {
return true;
}
}
return false;
}
return arr.indexOf(item) != -1;
}
function scriptHint(editor, keywords, getToken, options) {
// Find the token at the cursor
var cur = editor.getCursor(), token = getToken(editor, cur);
if (/\b(?:string|comment)\b/.test(token.type)) return;
token.state = CodeMirror.innerMode(editor.getMode(), token.state).state;
// If it's not a 'word-style' token, ignore the token.
if (!/^[\w$_]*$/.test(token.string)) {
token = {start: cur.ch, end: cur.ch, string: "", state: token.state,
type: token.string == "." ? "property" : null};
} else if (token.end > cur.ch) {
token.end = cur.ch;
token.string = token.string.slice(0, cur.ch - token.start);
}
var tprop = token;
// If it is a property, find out what it is a property of.
while (tprop.type == "property") {
tprop = getToken(editor, Pos(cur.line, tprop.start));
if (tprop.string != ".") return;
tprop = getToken(editor, Pos(cur.line, tprop.start));
if (!context) var context = [];
context.push(tprop);
}
return {list: getCompletions(token, context, keywords, options),
from: Pos(cur.line, token.start),
to: Pos(cur.line, token.end)};
}
function javascriptHint(editor, options) {
return scriptHint(editor, javascriptKeywords,
function (e, cur) {return e.getTokenAt(cur);},
options);
};
CodeMirror.registerHelper("hint", "javascript", javascriptHint);
function getCoffeeScriptToken(editor, cur) {
// This getToken, it is for coffeescript, imitates the behavior of
// getTokenAt method in javascript.js, that is, returning "property"
// type and treat "." as indepenent token.
var token = editor.getTokenAt(cur);
if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
token.end = token.start;
token.string = '.';
token.type = "property";
}
else if (/^\.[\w$_]*$/.test(token.string)) {
token.type = "property";
token.start++;
token.string = token.string.replace(/\./, '');
}
return token;
}
function coffeescriptHint(editor, options) {
return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
}
CodeMirror.registerHelper("hint", "coffeescript", coffeescriptHint);
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
"toUpperCase toLowerCase split concat match replace search").split(" ");
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
"lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
var funcProps = "prototype apply call bind".split(" ");
var javascriptKeywords = ("break case catch continue debugger default delete do else false finally for function " +
"if in instanceof new null return switch throw true try typeof var void while with").split(" ");
var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " +
"if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
function getCompletions(token, context, keywords, options) {
var found = [], start = token.string, global = options && options.globalScope || window;
function maybeAdd(str) {
if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
}
function gatherCompletions(obj) {
if (typeof obj == "string") forEach(stringProps, maybeAdd);
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
for (var name in obj) maybeAdd(name);
}
if (context && context.length) {
// If this is a property, see if it belongs to some object we can
// find in the current environment.
var obj = context.pop(), base;
if (obj.type && obj.type.indexOf("variable") === 0) {
if (options && options.additionalContext)
base = options.additionalContext[obj.string];
if (!options || options.useGlobalScope !== false)
base = base || global[obj.string];
} else if (obj.type == "string") {
base = "";
} else if (obj.type == "atom") {
base = 1;
} else if (obj.type == "function") {
if (global.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
(typeof global.jQuery == 'function'))
base = global.jQuery();
else if (global._ != null && (obj.string == '_') && (typeof global._ == 'function'))
base = global._();
}
while (base != null && context.length)
base = base[context.pop().string];
if (base != null) gatherCompletions(base);
} else {
// If not, just look in the global object and any local scope
// (reading into JS mode internals to get at the local and global variables)
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
if (!options || options.useGlobalScope !== false)
gatherCompletions(global);
forEach(keywords, maybeAdd);
}
return found;
}
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var Pos = CodeMirror.Pos;
function getHints(cm, options) {
var tags = options && options.schemaInfo;
var quote = (options && options.quoteChar) || '"';
if (!tags) return;
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
if (token.end > cur.ch) {
token.end = cur.ch;
token.string = token.string.slice(0, cur.ch - token.start);
}
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
if (inner.mode.name != "xml") return;
var result = [], replaceToken = false, prefix;
var tag = /\btag\b/.test(token.type) && !/>$/.test(token.string);
var tagName = tag && /^\w/.test(token.string), tagStart;
if (tagName) {
var before = cm.getLine(cur.line).slice(Math.max(0, token.start - 2), token.start);
var tagType = /<\/$/.test(before) ? "close" : /<$/.test(before) ? "open" : null;
if (tagType) tagStart = token.start - (tagType == "close" ? 2 : 1);
} else if (tag && token.string == "<") {
tagType = "open";
} else if (tag && token.string == "</") {
tagType = "close";
}
if (!tag && !inner.state.tagName || tagType) {
if (tagName)
prefix = token.string;
replaceToken = tagType;
var cx = inner.state.context, curTag = cx && tags[cx.tagName];
var childList = cx ? curTag && curTag.children : tags["!top"];
if (childList && tagType != "close") {
for (var i = 0; i < childList.length; ++i) if (!prefix || childList[i].lastIndexOf(prefix, 0) == 0)
result.push("<" + childList[i]);
} else if (tagType != "close") {
for (var name in tags)
if (tags.hasOwnProperty(name) && name != "!top" && name != "!attrs" && (!prefix || name.lastIndexOf(prefix, 0) == 0))
result.push("<" + name);
}
if (cx && (!prefix || tagType == "close" && cx.tagName.lastIndexOf(prefix, 0) == 0))
result.push("</" + cx.tagName + ">");
} else {
// Attribute completion
var curTag = tags[inner.state.tagName], attrs = curTag && curTag.attrs;
var globalAttrs = tags["!attrs"];
if (!attrs && !globalAttrs) return;
if (!attrs) {
attrs = globalAttrs;
} else if (globalAttrs) { // Combine tag-local and global attributes
var set = {};
for (var nm in globalAttrs) if (globalAttrs.hasOwnProperty(nm)) set[nm] = globalAttrs[nm];
for (var nm in attrs) if (attrs.hasOwnProperty(nm)) set[nm] = attrs[nm];
attrs = set;
}
if (token.type == "string" || token.string == "=") { // A value
var before = cm.getRange(Pos(cur.line, Math.max(0, cur.ch - 60)),
Pos(cur.line, token.type == "string" ? token.start : token.end));
var atName = before.match(/([^\s\u00a0=<>\"\']+)=$/), atValues;
if (!atName || !attrs.hasOwnProperty(atName[1]) || !(atValues = attrs[atName[1]])) return;
if (typeof atValues == 'function') atValues = atValues.call(this, cm); // Functions can be used to supply values for autocomplete widget
if (token.type == "string") {
prefix = token.string;
var n = 0;
if (/['"]/.test(token.string.charAt(0))) {
quote = token.string.charAt(0);
prefix = token.string.slice(1);
n++;
}
var len = token.string.length;
if (/['"]/.test(token.string.charAt(len - 1))) {
quote = token.string.charAt(len - 1);
prefix = token.string.substr(n, len - 2);
}
replaceToken = true;
}
for (var i = 0; i < atValues.length; ++i) if (!prefix || atValues[i].lastIndexOf(prefix, 0) == 0)
result.push(quote + atValues[i] + quote);
} else { // An attribute name
if (token.type == "attribute") {
prefix = token.string;
replaceToken = true;
}
for (var attr in attrs) if (attrs.hasOwnProperty(attr) && (!prefix || attr.lastIndexOf(prefix, 0) == 0))
result.push(attr);
}
}
return {
list: result,
from: replaceToken ? Pos(cur.line, tagStart == null ? token.start : tagStart) : cur,
to: replaceToken ? Pos(cur.line, token.end) : cur
};
}
CodeMirror.registerHelper("hint", "xml", getHints);
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("./xml-hint"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "./xml-hint"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var langs = "ab aa af ak sq am ar an hy as av ae ay az bm ba eu be bn bh bi bs br bg my ca ch ce ny zh cv kw co cr hr cs da dv nl dz en eo et ee fo fj fi fr ff gl ka de el gn gu ht ha he hz hi ho hu ia id ie ga ig ik io is it iu ja jv kl kn kr ks kk km ki rw ky kv kg ko ku kj la lb lg li ln lo lt lu lv gv mk mg ms ml mt mi mr mh mn na nv nb nd ne ng nn no ii nr oc oj cu om or os pa pi fa pl ps pt qu rm rn ro ru sa sc sd se sm sg sr gd sn si sk sl so st es su sw ss sv ta te tg th ti bo tk tl tn to tr ts tt tw ty ug uk ur uz ve vi vo wa cy wo fy xh yi yo za zu".split(" ");
var targets = ["_blank", "_self", "_top", "_parent"];
var charsets = ["ascii", "utf-8", "utf-16", "latin1", "latin1"];
var methods = ["get", "post", "put", "delete"];
var encs = ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"];
var media = ["all", "screen", "print", "embossed", "braille", "handheld", "print", "projection", "screen", "tty", "tv", "speech",
"3d-glasses", "resolution [>][<][=] [X]", "device-aspect-ratio: X/Y", "orientation:portrait",
"orientation:landscape", "device-height: [X]", "device-width: [X]"];
var s = { attrs: {} }; // Simple tag, reused for a whole lot of tags
var data = {
a: {
attrs: {
href: null, ping: null, type: null,
media: media,
target: targets,
hreflang: langs
}
},
abbr: s,
acronym: s,
address: s,
applet: s,
area: {
attrs: {
alt: null, coords: null, href: null, target: null, ping: null,
media: media, hreflang: langs, type: null,
shape: ["default", "rect", "circle", "poly"]
}
},
article: s,
aside: s,
audio: {
attrs: {
src: null, mediagroup: null,
crossorigin: ["anonymous", "use-credentials"],
preload: ["none", "metadata", "auto"],
autoplay: ["", "autoplay"],
loop: ["", "loop"],
controls: ["", "controls"]
}
},
b: s,
base: { attrs: { href: null, target: targets } },
basefont: s,
bdi: s,
bdo: s,
big: s,
blockquote: { attrs: { cite: null } },
body: s,
br: s,
button: {
attrs: {
form: null, formaction: null, name: null, value: null,
autofocus: ["", "autofocus"],
disabled: ["", "autofocus"],
formenctype: encs,
formmethod: methods,
formnovalidate: ["", "novalidate"],
formtarget: targets,
type: ["submit", "reset", "button"]
}
},
canvas: { attrs: { width: null, height: null } },
caption: s,
center: s,
cite: s,
code: s,
col: { attrs: { span: null } },
colgroup: { attrs: { span: null } },
command: {
attrs: {
type: ["command", "checkbox", "radio"],
label: null, icon: null, radiogroup: null, command: null, title: null,
disabled: ["", "disabled"],
checked: ["", "checked"]
}
},
data: { attrs: { value: null } },
datagrid: { attrs: { disabled: ["", "disabled"], multiple: ["", "multiple"] } },
datalist: { attrs: { data: null } },
dd: s,
del: { attrs: { cite: null, datetime: null } },
details: { attrs: { open: ["", "open"] } },
dfn: s,
dir: s,
div: s,
dl: s,
dt: s,
em: s,
embed: { attrs: { src: null, type: null, width: null, height: null } },
eventsource: { attrs: { src: null } },
fieldset: { attrs: { disabled: ["", "disabled"], form: null, name: null } },
figcaption: s,
figure: s,
font: s,
footer: s,
form: {
attrs: {
action: null, name: null,
"accept-charset": charsets,
autocomplete: ["on", "off"],
enctype: encs,
method: methods,
novalidate: ["", "novalidate"],
target: targets
}
},
frame: s,
frameset: s,
h1: s, h2: s, h3: s, h4: s, h5: s, h6: s,
head: {
attrs: {},
children: ["title", "base", "link", "style", "meta", "script", "noscript", "command"]
},
header: s,
hgroup: s,
hr: s,
html: {
attrs: { manifest: null },
children: ["head", "body"]
},
i: s,
iframe: {
attrs: {
src: null, srcdoc: null, name: null, width: null, height: null,
sandbox: ["allow-top-navigation", "allow-same-origin", "allow-forms", "allow-scripts"],
seamless: ["", "seamless"]
}
},
img: {
attrs: {
alt: null, src: null, ismap: null, usemap: null, width: null, height: null,
crossorigin: ["anonymous", "use-credentials"]
}
},
input: {
attrs: {
alt: null, dirname: null, form: null, formaction: null,
height: null, list: null, max: null, maxlength: null, min: null,
name: null, pattern: null, placeholder: null, size: null, src: null,
step: null, value: null, width: null,
accept: ["audio/*", "video/*", "image/*"],
autocomplete: ["on", "off"],
autofocus: ["", "autofocus"],
checked: ["", "checked"],
disabled: ["", "disabled"],
formenctype: encs,
formmethod: methods,
formnovalidate: ["", "novalidate"],
formtarget: targets,
multiple: ["", "multiple"],
readonly: ["", "readonly"],
required: ["", "required"],
type: ["hidden", "text", "search", "tel", "url", "email", "password", "datetime", "date", "month",
"week", "time", "datetime-local", "number", "range", "color", "checkbox", "radio",
"file", "submit", "image", "reset", "button"]
}
},
ins: { attrs: { cite: null, datetime: null } },
kbd: s,
keygen: {
attrs: {
challenge: null, form: null, name: null,
autofocus: ["", "autofocus"],
disabled: ["", "disabled"],
keytype: ["RSA"]
}
},
label: { attrs: { "for": null, form: null } },
legend: s,
li: { attrs: { value: null } },
link: {
attrs: {
href: null, type: null,
hreflang: langs,
media: media,
sizes: ["all", "16x16", "16x16 32x32", "16x16 32x32 64x64"]
}
},
map: { attrs: { name: null } },
mark: s,
menu: { attrs: { label: null, type: ["list", "context", "toolbar"] } },
meta: {
attrs: {
content: null,
charset: charsets,
name: ["viewport", "application-name", "author", "description", "generator", "keywords"],
"http-equiv": ["content-language", "content-type", "default-style", "refresh"]
}
},
meter: { attrs: { value: null, min: null, low: null, high: null, max: null, optimum: null } },
nav: s,
noframes: s,
noscript: s,
object: {
attrs: {
data: null, type: null, name: null, usemap: null, form: null, width: null, height: null,
typemustmatch: ["", "typemustmatch"]
}
},
ol: { attrs: { reversed: ["", "reversed"], start: null, type: ["1", "a", "A", "i", "I"] } },
optgroup: { attrs: { disabled: ["", "disabled"], label: null } },
option: { attrs: { disabled: ["", "disabled"], label: null, selected: ["", "selected"], value: null } },
output: { attrs: { "for": null, form: null, name: null } },
p: s,
param: { attrs: { name: null, value: null } },
pre: s,
progress: { attrs: { value: null, max: null } },
q: { attrs: { cite: null } },
rp: s,
rt: s,
ruby: s,
s: s,
samp: s,
script: {
attrs: {
type: ["text/javascript"],
src: null,
async: ["", "async"],
defer: ["", "defer"],
charset: charsets
}
},
section: s,
select: {
attrs: {
form: null, name: null, size: null,
autofocus: ["", "autofocus"],
disabled: ["", "disabled"],
multiple: ["", "multiple"]
}
},
small: s,
source: { attrs: { src: null, type: null, media: null } },
span: s,
strike: s,
strong: s,
style: {
attrs: {
type: ["text/css"],
media: media,
scoped: null
}
},
sub: s,
summary: s,
sup: s,
table: s,
tbody: s,
td: { attrs: { colspan: null, rowspan: null, headers: null } },
textarea: {
attrs: {
dirname: null, form: null, maxlength: null, name: null, placeholder: null,
rows: null, cols: null,
autofocus: ["", "autofocus"],
disabled: ["", "disabled"],
readonly: ["", "readonly"],
required: ["", "required"],
wrap: ["soft", "hard"]
}
},
tfoot: s,
th: { attrs: { colspan: null, rowspan: null, headers: null, scope: ["row", "col", "rowgroup", "colgroup"] } },
thead: s,
time: { attrs: { datetime: null } },
title: s,
tr: s,
track: {
attrs: {
src: null, label: null, "default": null,
kind: ["subtitles", "captions", "descriptions", "chapters", "metadata"],
srclang: langs
}
},
tt: s,
u: s,
ul: s,
"var": s,
video: {
attrs: {
src: null, poster: null, width: null, height: null,
crossorigin: ["anonymous", "use-credentials"],
preload: ["auto", "metadata", "none"],
autoplay: ["", "autoplay"],
mediagroup: ["movie"],
muted: ["", "muted"],
controls: ["", "controls"]
}
},
wbr: s
};
var globalAttrs = {
accesskey: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
"class": null,
contenteditable: ["true", "false"],
contextmenu: null,
dir: ["ltr", "rtl", "auto"],
draggable: ["true", "false", "auto"],
dropzone: ["copy", "move", "link", "string:", "file:"],
hidden: ["hidden"],
id: null,
inert: ["inert"],
itemid: null,
itemprop: null,
itemref: null,
itemscope: ["itemscope"],
itemtype: null,
lang: ["en", "es"],
spellcheck: ["true", "false"],
style: null,
tabindex: ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
title: null,
translate: ["yes", "no"],
onclick: null,
rel: ["stylesheet", "alternate", "author", "bookmark", "help", "license", "next", "nofollow", "noreferrer", "prefetch", "prev", "search", "tag"]
};
function populate(obj) {
for (var attr in globalAttrs) if (globalAttrs.hasOwnProperty(attr))
obj.attrs[attr] = globalAttrs[attr];
}
populate(s);
for (var tag in data) if (data.hasOwnProperty(tag) && data[tag] != s)
populate(data[tag]);
CodeMirror.htmlSchema = data;
function htmlHint(cm, options) {
var local = {schemaInfo: data};
if (options) for (var opt in options) local[opt] = options[opt];
return CodeMirror.hint.xml(cm, local);
}
CodeMirror.registerHelper("hint", "html", htmlHint);
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../../mode/css/css"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../../mode/css/css"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var pseudoClasses = {link: 1, visited: 1, active: 1, hover: 1, focus: 1,
"first-letter": 1, "first-line": 1, "first-child": 1,
before: 1, after: 1, lang: 1};
CodeMirror.registerHelper("hint", "css", function(cm) {
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
if (inner.mode.name != "css") return;
if (token.type == "keyword" && "!important".indexOf(token.string) == 0)
return {list: ["!important"], from: CodeMirror.Pos(cur.line, token.start),
to: CodeMirror.Pos(cur.line, token.end)};
var start = token.start, end = cur.ch, word = token.string.slice(0, end - start);
if (/[^\w$_-]/.test(word)) {
word = ""; start = end = cur.ch;
}
var spec = CodeMirror.resolveMode("text/css");
var result = [];
function add(keywords) {
for (var name in keywords)
if (!word || name.lastIndexOf(word, 0) == 0)
result.push(name);
}
var st = inner.state.state;
if (st == "pseudo" || token.type == "variable-3") {
add(pseudoClasses);
} else if (st == "block" || st == "maybeprop") {
add(spec.propertyKeywords);
} else if (st == "prop" || st == "parens" || st == "at" || st == "params") {
add(spec.valueKeywords);
add(spec.colorKeywords);
} else if (st == "media" || st == "media_parens") {
add(spec.mediaTypes);
add(spec.mediaFeatures);
}
if (result.length) return {
list: result,
from: CodeMirror.Pos(cur.line, start),
to: CodeMirror.Pos(cur.line, end)
};
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Because sometimes you need to style the cursor's line.
//
// Adds an option 'styleActiveLine' which, when enabled, gives the
// active line's wrapping <div> the CSS class "CodeMirror-activeline",
// and gives its background <div> the class "CodeMirror-activeline-background".
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var WRAP_CLASS = "CodeMirror-activeline";
var BACK_CLASS = "CodeMirror-activeline-background";
var GUTT_CLASS = "CodeMirror-activeline-gutter";
CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
var prev = old && old != CodeMirror.Init;
if (val && !prev) {
cm.state.activeLines = [];
updateActiveLines(cm, cm.listSelections());
cm.on("beforeSelectionChange", selectionChange);
} else if (!val && prev) {
cm.off("beforeSelectionChange", selectionChange);
clearActiveLines(cm);
delete cm.state.activeLines;
}
});
function clearActiveLines(cm) {
for (var i = 0; i < cm.state.activeLines.length; i++) {
cm.removeLineClass(cm.state.activeLines[i], "wrap", WRAP_CLASS);
cm.removeLineClass(cm.state.activeLines[i], "background", BACK_CLASS);
cm.removeLineClass(cm.state.activeLines[i], "gutter", GUTT_CLASS);
}
}
function sameArray(a, b) {
if (a.length != b.length) return false;
for (var i = 0; i < a.length; i++)
if (a[i] != b[i]) return false;
return true;
}
function updateActiveLines(cm, ranges) {
var active = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (!range.empty()) continue;
var line = cm.getLineHandleVisualStart(range.head.line);
if (active[active.length - 1] != line) active.push(line);
}
if (sameArray(cm.state.activeLines, active)) return;
cm.operation(function() {
clearActiveLines(cm);
for (var i = 0; i < active.length; i++) {
cm.addLineClass(active[i], "wrap", WRAP_CLASS);
cm.addLineClass(active[i], "background", BACK_CLASS);
cm.addLineClass(active[i], "gutter", GUTT_CLASS);
}
cm.state.activeLines = active;
});
}
function selectionChange(cm, sel) {
updateActiveLines(cm, sel.ranges);
}
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var Pos = CodeMirror.Pos;
function SearchCursor(doc, query, pos, caseFold) {
this.atOccurrence = false; this.doc = doc;
if (caseFold == null && typeof query == "string") caseFold = false;
pos = pos ? doc.clipPos(pos) : Pos(0, 0);
this.pos = {from: pos, to: pos};
// The matches method is filled in based on the type of query.
// It takes a position and a direction, and returns an object
// describing the next occurrence of the query, or null if no
// more matches were found.
if (typeof query != "string") { // Regexp match
if (!query.global) query = new RegExp(query.source, query.ignoreCase ? "ig" : "g");
this.matches = function(reverse, pos) {
if (reverse) {
query.lastIndex = 0;
var line = doc.getLine(pos.line).slice(0, pos.ch), cutOff = 0, match, start;
for (;;) {
query.lastIndex = cutOff;
var newMatch = query.exec(line);
if (!newMatch) break;
match = newMatch;
start = match.index;
cutOff = match.index + (match[0].length || 1);
if (cutOff == line.length) break;
}
var matchLen = (match && match[0].length) || 0;
if (!matchLen) {
if (start == 0 && line.length == 0) {match = undefined;}
else if (start != doc.getLine(pos.line).length) {
matchLen++;
}
}
} else {
query.lastIndex = pos.ch;
var line = doc.getLine(pos.line), match = query.exec(line);
var matchLen = (match && match[0].length) || 0;
var start = match && match.index;
if (start + matchLen != line.length && !matchLen) matchLen = 1;
}
if (match && matchLen)
return {from: Pos(pos.line, start),
to: Pos(pos.line, start + matchLen),
match: match};
};
} else { // String query
var origQuery = query;
if (caseFold) query = query.toLowerCase();
var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
var target = query.split("\n");
// Different methods for single-line and multi-line queries
if (target.length == 1) {
if (!query.length) {
// Empty string would match anything and never progress, so
// we define it to match nothing instead.
this.matches = function() {};
} else {
this.matches = function(reverse, pos) {
if (reverse) {
var orig = doc.getLine(pos.line).slice(0, pos.ch), line = fold(orig);
var match = line.lastIndexOf(query);
if (match > -1) {
match = adjustPos(orig, line, match);
return {from: Pos(pos.line, match), to: Pos(pos.line, match + origQuery.length)};
}
} else {
var orig = doc.getLine(pos.line).slice(pos.ch), line = fold(orig);
var match = line.indexOf(query);
if (match > -1) {
match = adjustPos(orig, line, match) + pos.ch;
return {from: Pos(pos.line, match), to: Pos(pos.line, match + origQuery.length)};
}
}
};
}
} else {
var origTarget = origQuery.split("\n");
this.matches = function(reverse, pos) {
var last = target.length - 1;
if (reverse) {
if (pos.line - (target.length - 1) < doc.firstLine()) return;
if (fold(doc.getLine(pos.line).slice(0, origTarget[last].length)) != target[target.length - 1]) return;
var to = Pos(pos.line, origTarget[last].length);
for (var ln = pos.line - 1, i = last - 1; i >= 1; --i, --ln)
if (target[i] != fold(doc.getLine(ln))) return;
var line = doc.getLine(ln), cut = line.length - origTarget[0].length;
if (fold(line.slice(cut)) != target[0]) return;
return {from: Pos(ln, cut), to: to};
} else {
if (pos.line + (target.length - 1) > doc.lastLine()) return;
var line = doc.getLine(pos.line), cut = line.length - origTarget[0].length;
if (fold(line.slice(cut)) != target[0]) return;
var from = Pos(pos.line, cut);
for (var ln = pos.line + 1, i = 1; i < last; ++i, ++ln)
if (target[i] != fold(doc.getLine(ln))) return;
if (fold(doc.getLine(ln).slice(0, origTarget[last].length)) != target[last]) return;
return {from: from, to: Pos(ln, origTarget[last].length)};
}
};
}
}
}
SearchCursor.prototype = {
findNext: function() {return this.find(false);},
findPrevious: function() {return this.find(true);},
find: function(reverse) {
var self = this, pos = this.doc.clipPos(reverse ? this.pos.from : this.pos.to);
function savePosAndFail(line) {
var pos = Pos(line, 0);
self.pos = {from: pos, to: pos};
self.atOccurrence = false;
return false;
}
for (;;) {
if (this.pos = this.matches(reverse, pos)) {
this.atOccurrence = true;
return this.pos.match || true;
}
if (reverse) {
if (!pos.line) return savePosAndFail(0);
pos = Pos(pos.line-1, this.doc.getLine(pos.line-1).length);
}
else {
var maxLine = this.doc.lineCount();
if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
pos = Pos(pos.line + 1, 0);
}
}
},
from: function() {if (this.atOccurrence) return this.pos.from;},
to: function() {if (this.atOccurrence) return this.pos.to;},
replace: function(newText, origin) {
if (!this.atOccurrence) return;
var lines = CodeMirror.splitLines(newText);
this.doc.replaceRange(lines, this.pos.from, this.pos.to, origin);
this.pos.to = Pos(this.pos.from.line + lines.length - 1,
lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0));
}
};
// Maps a position in a case-folded line back to a position in the original line
// (compensating for codepoints increasing in number during folding)
function adjustPos(orig, folded, pos) {
if (orig.length == folded.length) return pos;
for (var pos1 = Math.min(pos, orig.length);;) {
var len1 = orig.slice(0, pos1).toLowerCase().length;
if (len1 < pos) ++pos1;
else if (len1 > pos) --pos1;
else return pos1;
}
}
CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
return new SearchCursor(this.doc, query, pos, caseFold);
});
CodeMirror.defineDocExtension("getSearchCursor", function(query, pos, caseFold) {
return new SearchCursor(this, query, pos, caseFold);
});
CodeMirror.defineExtension("selectMatches", function(query, caseFold) {
var ranges = [];
var cur = this.getSearchCursor(query, this.getCursor("from"), caseFold);
while (cur.findNext()) {
if (CodeMirror.cmpPos(cur.to(), this.getCursor("to")) > 0) break;
ranges.push({anchor: cur.from(), head: cur.to()});
}
if (ranges.length)
this.setSelections(ranges, 0);
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Define search commands. Depends on dialog.js or another
// implementation of the openDialog method.
// Replace works a little oddly -- it will do the replace on the next
// Ctrl-G (or whatever is bound to findNext) press. You prevent a
// replace by making sure the match is no longer selected when hitting
// Ctrl-G.
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("./searchcursor"), require("../dialog/dialog"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "./searchcursor", "../dialog/dialog"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
function searchOverlay(query, caseInsensitive) {
if (typeof query == "string")
query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g");
else if (!query.global)
query = new RegExp(query.source, query.ignoreCase ? "gi" : "g");
return {token: function(stream) {
query.lastIndex = stream.pos;
var match = query.exec(stream.string);
if (match && match.index == stream.pos) {
stream.pos += match[0].length || 1;
return "searching";
} else if (match) {
stream.pos = match.index;
} else {
stream.skipToEnd();
}
}};
}
function SearchState() {
this.posFrom = this.posTo = this.lastQuery = this.query = null;
this.overlay = null;
}
function getSearchState(cm) {
return cm.state.search || (cm.state.search = new SearchState());
}
function queryCaseInsensitive(query) {
return typeof query == "string" && query == query.toLowerCase();
}
function getSearchCursor(cm, query, pos) {
// Heuristic: if the query string is all lowercase, do a case insensitive search.
return cm.getSearchCursor(query, pos, queryCaseInsensitive(query));
}
function persistentDialog(cm, text, deflt, f) {
cm.openDialog(text, f, {
value: deflt,
selectValueOnOpen: true,
closeOnEnter: false,
onClose: function() { clearSearch(cm); }
});
}
function dialog(cm, text, shortText, deflt, f) {
if (cm.openDialog) cm.openDialog(text, f, {value: deflt, selectValueOnOpen: true});
else f(prompt(shortText, deflt));
}
function confirmDialog(cm, text, shortText, fs) {
if (cm.openConfirm) cm.openConfirm(text, fs);
else if (confirm(shortText)) fs[0]();
}
function parseString(string) {
return string.replace(/\\(.)/g, function(_, ch) {
if (ch == "n") return "\n"
if (ch == "r") return "\r"
return ch
})
}
function parseQuery(query) {
var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
if (isRE) {
try { query = new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i"); }
catch(e) {} // Not a regular expression after all, do a string search
} else {
query = parseString(query)
}
if (typeof query == "string" ? query == "" : query.test(""))
query = /x^/;
return query;
}
var queryDialog =
'Search: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
function startSearch(cm, state, query) {
state.queryText = query;
state.query = parseQuery(query);
cm.removeOverlay(state.overlay, queryCaseInsensitive(state.query));
state.overlay = searchOverlay(state.query, queryCaseInsensitive(state.query));
cm.addOverlay(state.overlay);
if (cm.showMatchesOnScrollbar) {
if (state.annotate) { state.annotate.clear(); state.annotate = null; }
state.annotate = cm.showMatchesOnScrollbar(state.query, queryCaseInsensitive(state.query));
}
}
function doSearch(cm, rev, persistent) {
var state = getSearchState(cm);
if (state.query) return findNext(cm, rev);
var q = cm.getSelection() || state.lastQuery;
if (persistent && cm.openDialog) {
var hiding = null
persistentDialog(cm, queryDialog, q, function(query, event) {
CodeMirror.e_stop(event);
if (!query) return;
if (query != state.queryText) {
startSearch(cm, state, query);
state.posFrom = state.posTo = cm.getCursor();
}
if (hiding) hiding.style.opacity = 1
findNext(cm, event.shiftKey, function(_, to) {
var dialog
if (to.line < 3 && document.querySelector &&
(dialog = cm.display.wrapper.querySelector(".CodeMirror-dialog")) &&
dialog.getBoundingClientRect().bottom - 4 > cm.cursorCoords(to, "window").top)
(hiding = dialog).style.opacity = .4
})
});
} else {
dialog(cm, queryDialog, "Search for:", q, function(query) {
if (query && !state.query) cm.operation(function() {
startSearch(cm, state, query);
state.posFrom = state.posTo = cm.getCursor();
findNext(cm, rev);
});
});
}
}
function findNext(cm, rev, callback) {cm.operation(function() {
var state = getSearchState(cm);
var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
if (!cursor.find(rev)) {
cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
if (!cursor.find(rev)) return;
}
cm.setSelection(cursor.from(), cursor.to());
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
state.posFrom = cursor.from(); state.posTo = cursor.to();
if (callback) callback(cursor.from(), cursor.to())
});}
function clearSearch(cm) {cm.operation(function() {
var state = getSearchState(cm);
state.lastQuery = state.query;
if (!state.query) return;
state.query = state.queryText = null;
cm.removeOverlay(state.overlay);
if (state.annotate) { state.annotate.clear(); state.annotate = null; }
});}
var replaceQueryDialog =
' <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
var replacementQueryDialog = 'With: <input type="text" style="width: 10em" class="CodeMirror-search-field"/>';
var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>All</button> <button>Stop</button>";
function replaceAll(cm, query, text) {
cm.operation(function() {
for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
if (typeof query != "string") {
var match = cm.getRange(cursor.from(), cursor.to()).match(query);
cursor.replace(text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
} else cursor.replace(text);
}
});
}
function replace(cm, all) {
if (cm.getOption("readOnly")) return;
var query = cm.getSelection() || getSearchState(cm).lastQuery;
var dialogText = all ? "Replace all:" : "Replace:"
dialog(cm, dialogText + replaceQueryDialog, dialogText, query, function(query) {
if (!query) return;
query = parseQuery(query);
dialog(cm, replacementQueryDialog, "Replace with:", "", function(text) {
text = parseString(text)
if (all) {
replaceAll(cm, query, text)
} else {
clearSearch(cm);
var cursor = getSearchCursor(cm, query, cm.getCursor("from"));
var advance = function() {
var start = cursor.from(), match;
if (!(match = cursor.findNext())) {
cursor = getSearchCursor(cm, query);
if (!(match = cursor.findNext()) ||
(start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
}
cm.setSelection(cursor.from(), cursor.to());
cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
confirmDialog(cm, doReplaceConfirm, "Replace?",
[function() {doReplace(match);}, advance,
function() {replaceAll(cm, query, text)}]);
};
var doReplace = function(match) {
cursor.replace(typeof query == "string" ? text :
text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
advance();
};
advance();
}
});
});
}
CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
CodeMirror.commands.findPersistent = function(cm) {clearSearch(cm); doSearch(cm, false, true);};
CodeMirror.commands.findNext = doSearch;
CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
CodeMirror.commands.clearSearch = clearSearch;
CodeMirror.commands.replace = replace;
CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Open simple dialogs on top of an editor. Relies on dialog.css.
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
function dialogDiv(cm, template, bottom) {
var wrap = cm.getWrapperElement();
var dialog;
dialog = wrap.appendChild(document.createElement("div"));
if (bottom)
dialog.className = "CodeMirror-dialog CodeMirror-dialog-bottom";
else
dialog.className = "CodeMirror-dialog CodeMirror-dialog-top";
if (typeof template == "string") {
dialog.innerHTML = template;
} else { // Assuming it's a detached DOM element.
dialog.appendChild(template);
}
return dialog;
}
function closeNotification(cm, newVal) {
if (cm.state.currentNotificationClose)
cm.state.currentNotificationClose();
cm.state.currentNotificationClose = newVal;
}
CodeMirror.defineExtension("openDialog", function(template, callback, options) {
if (!options) options = {};
closeNotification(this, null);
var dialog = dialogDiv(this, template, options.bottom);
var closed = false, me = this;
function close(newVal) {
if (typeof newVal == 'string') {
inp.value = newVal;
} else {
if (closed) return;
closed = true;
dialog.parentNode.removeChild(dialog);
me.focus();
if (options.onClose) options.onClose(dialog);
}
}
var inp = dialog.getElementsByTagName("input")[0], button;
if (inp) {
inp.focus();
if (options.value) {
inp.value = options.value;
if (options.selectValueOnOpen !== false) {
inp.select();
}
}
if (options.onInput)
CodeMirror.on(inp, "input", function(e) { options.onInput(e, inp.value, close);});
if (options.onKeyUp)
CodeMirror.on(inp, "keyup", function(e) {options.onKeyUp(e, inp.value, close);});
CodeMirror.on(inp, "keydown", function(e) {
if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) { return; }
if (e.keyCode == 27 || (options.closeOnEnter !== false && e.keyCode == 13)) {
inp.blur();
CodeMirror.e_stop(e);
close();
}
if (e.keyCode == 13) callback(inp.value, e);
});
if (options.closeOnBlur !== false) CodeMirror.on(inp, "blur", close);
} else if (button = dialog.getElementsByTagName("button")[0]) {
CodeMirror.on(button, "click", function() {
close();
me.focus();
});
if (options.closeOnBlur !== false) CodeMirror.on(button, "blur", close);
button.focus();
}
return close;
});
CodeMirror.defineExtension("openConfirm", function(template, callbacks, options) {
closeNotification(this, null);
var dialog = dialogDiv(this, template, options && options.bottom);
var buttons = dialog.getElementsByTagName("button");
var closed = false, me = this, blurring = 1;
function close() {
if (closed) return;
closed = true;
dialog.parentNode.removeChild(dialog);
me.focus();
}
buttons[0].focus();
for (var i = 0; i < buttons.length; ++i) {
var b = buttons[i];
(function(callback) {
CodeMirror.on(b, "click", function(e) {
CodeMirror.e_preventDefault(e);
close();
if (callback) callback(me);
});
})(callbacks[i]);
CodeMirror.on(b, "blur", function() {
--blurring;
setTimeout(function() { if (blurring <= 0) close(); }, 200);
});
CodeMirror.on(b, "focus", function() { ++blurring; });
}
});
/*
* openNotification
* Opens a notification, that can be closed with an optional timer
* (default 5000ms timer) and always closes on click.
*
* If a notification is opened while another is opened, it will close the
* currently opened one and open the new one immediately.
*/
CodeMirror.defineExtension("openNotification", function(template, options) {
closeNotification(this, close);
var dialog = dialogDiv(this, template, options && options.bottom);
var closed = false, doneTimer;
var duration = options && typeof options.duration !== "undefined" ? options.duration : 5000;
function close() {
if (closed) return;
closed = true;
clearTimeout(doneTimer);
dialog.parentNode.removeChild(dialog);
}
CodeMirror.on(dialog, 'click', function(e) {
CodeMirror.e_preventDefault(e);
close();
});
if (duration)
doneTimer = setTimeout(close, duration);
return close;
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Defines jumpToLine command. Uses dialog.js if present.
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../dialog/dialog"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../dialog/dialog"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
function dialog(cm, text, shortText, deflt, f) {
if (cm.openDialog) cm.openDialog(text, f, {value: deflt, selectValueOnOpen: true});
else f(prompt(shortText, deflt));
}
var jumpDialog =
'Jump to line: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use line:column or scroll% syntax)</span>';
function interpretLine(cm, string) {
var num = Number(string)
if (/^[-+]/.test(string)) return cm.getCursor().line + num
else return num - 1
}
CodeMirror.commands.jumpToLine = function(cm) {
var cur = cm.getCursor();
dialog(cm, jumpDialog, "Jump to line:", (cur.line + 1) + ":" + cur.ch, function(posStr) {
if (!posStr) return;
var match;
if (match = /^\s*([\+\-]?\d+)\s*\:\s*(\d+)\s*$/.exec(posStr)) {
cm.setCursor(interpretLine(cm, match[1]), Number(match[2]))
} else if (match = /^\s*([\+\-]?\d+(\.\d+)?)\%\s*/.exec(posStr)) {
var line = Math.round(cm.lineCount() * Number(match[1]) / 100);
if (/^[-+]/.test(match[1])) line = cur.line + line + 1;
cm.setCursor(line - 1, cur.ch);
} else if (match = /^\s*\:?\s*([\+\-]?\d+)\s*/.exec(posStr)) {
cm.setCursor(interpretLine(cm, match[1]), cur.ch);
}
});
};
CodeMirror.keyMap["default"]["Alt-G"] = "jumpToLine";
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var htmlConfig = {
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
'track': true, 'wbr': true, 'menuitem': true},
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
'th': true, 'tr': true},
contextGrabbers: {
'dd': {'dd': true, 'dt': true},
'dt': {'dd': true, 'dt': true},
'li': {'li': true},
'option': {'option': true, 'optgroup': true},
'optgroup': {'optgroup': true},
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
'rp': {'rp': true, 'rt': true},
'rt': {'rp': true, 'rt': true},
'tbody': {'tbody': true, 'tfoot': true},
'td': {'td': true, 'th': true},
'tfoot': {'tbody': true},
'th': {'td': true, 'th': true},
'thead': {'tbody': true, 'tfoot': true},
'tr': {'tr': true}
},
doNotIndent: {"pre": true},
allowUnquoted: true,
allowMissing: true,
caseFold: true
}
var xmlConfig = {
autoSelfClosers: {},
implicitlyClosed: {},
contextGrabbers: {},
doNotIndent: {},
allowUnquoted: false,
allowMissing: false,
caseFold: false
}
CodeMirror.defineMode("xml", function(editorConf, config_) {
var indentUnit = editorConf.indentUnit
var config = {}
var defaults = config_.htmlMode ? htmlConfig : xmlConfig
for (var prop in defaults) config[prop] = defaults[prop]
for (var prop in config_) config[prop] = config_[prop]
// Return variables for tokenizers
var type, setStyle;
function inText(stream, state) {
function chain(parser) {
state.tokenize = parser;
return parser(stream, state);
}
var ch = stream.next();
if (ch == "<") {
if (stream.eat("!")) {
if (stream.eat("[")) {
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
else return null;
} else if (stream.match("--")) {
return chain(inBlock("comment", "-->"));
} else if (stream.match("DOCTYPE", true, true)) {
stream.eatWhile(/[\w\._\-]/);
return chain(doctype(1));
} else {
return null;
}
} else if (stream.eat("?")) {
stream.eatWhile(/[\w\._\-]/);
state.tokenize = inBlock("meta", "?>");
return "meta";
} else {
type = stream.eat("/") ? "closeTag" : "openTag";
state.tokenize = inTag;
return "tag bracket";
}
} else if (ch == "&") {
var ok;
if (stream.eat("#")) {
if (stream.eat("x")) {
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
} else {
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
}
} else {
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
}
return ok ? "atom" : "error";
} else {
stream.eatWhile(/[^&<]/);
return null;
}
}
inText.isInText = true;
function inTag(stream, state) {
var ch = stream.next();
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
state.tokenize = inText;
type = ch == ">" ? "endTag" : "selfcloseTag";
return "tag bracket";
} else if (ch == "=") {
type = "equals";
return null;
} else if (ch == "<") {
state.tokenize = inText;
state.state = baseState;
state.tagName = state.tagStart = null;
var next = state.tokenize(stream, state);
return next ? next + " tag error" : "tag error";
} else if (/[\'\"]/.test(ch)) {
state.tokenize = inAttribute(ch);
state.stringStartCol = stream.column();
return state.tokenize(stream, state);
} else {
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
return "word";
}
}
function inAttribute(quote) {
var closure = function(stream, state) {
while (!stream.eol()) {
if (stream.next() == quote) {
state.tokenize = inTag;
break;
}
}
return "string";
};
closure.isInAttribute = true;
return closure;
}
function inBlock(style, terminator) {
return function(stream, state) {
while (!stream.eol()) {
if (stream.match(terminator)) {
state.tokenize = inText;
break;
}
stream.next();
}
return style;
};
}
function doctype(depth) {
return function(stream, state) {
var ch;
while ((ch = stream.next()) != null) {
if (ch == "<") {
state.tokenize = doctype(depth + 1);
return state.tokenize(stream, state);
} else if (ch == ">") {
if (depth == 1) {
state.tokenize = inText;
break;
} else {
state.tokenize = doctype(depth - 1);
return state.tokenize(stream, state);
}
}
}
return "meta";
};
}
function Context(state, tagName, startOfLine) {
this.prev = state.context;
this.tagName = tagName;
this.indent = state.indented;
this.startOfLine = startOfLine;
if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
this.noIndent = true;
}
function popContext(state) {
if (state.context) state.context = state.context.prev;
}
function maybePopContext(state, nextTagName) {
var parentTagName;
while (true) {
if (!state.context) {
return;
}
parentTagName = state.context.tagName;
if (!config.contextGrabbers.hasOwnProperty(parentTagName) ||
!config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
return;
}
popContext(state);
}
}
function baseState(type, stream, state) {
if (type == "openTag") {
state.tagStart = stream.column();
return tagNameState;
} else if (type == "closeTag") {
return closeTagNameState;
} else {
return baseState;
}
}
function tagNameState(type, stream, state) {
if (type == "word") {
state.tagName = stream.current();
setStyle = "tag";
return attrState;
} else {
setStyle = "error";
return tagNameState;
}
}
function closeTagNameState(type, stream, state) {
if (type == "word") {
var tagName = stream.current();
if (state.context && state.context.tagName != tagName &&
config.implicitlyClosed.hasOwnProperty(state.context.tagName))
popContext(state);
if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) {
setStyle = "tag";
return closeState;
} else {
setStyle = "tag error";
return closeStateErr;
}
} else {
setStyle = "error";
return closeStateErr;
}
}
function closeState(type, _stream, state) {
if (type != "endTag") {
setStyle = "error";
return closeState;
}
popContext(state);
return baseState;
}
function closeStateErr(type, stream, state) {
setStyle = "error";
return closeState(type, stream, state);
}
function attrState(type, _stream, state) {
if (type == "word") {
setStyle = "attribute";
return attrEqState;
} else if (type == "endTag" || type == "selfcloseTag") {
var tagName = state.tagName, tagStart = state.tagStart;
state.tagName = state.tagStart = null;
if (type == "selfcloseTag" ||
config.autoSelfClosers.hasOwnProperty(tagName)) {
maybePopContext(state, tagName);
} else {
maybePopContext(state, tagName);
state.context = new Context(state, tagName, tagStart == state.indented);
}
return baseState;
}
setStyle = "error";
return attrState;
}
function attrEqState(type, stream, state) {
if (type == "equals") return attrValueState;
if (!config.allowMissing) setStyle = "error";
return attrState(type, stream, state);
}
function attrValueState(type, stream, state) {
if (type == "string") return attrContinuedState;
if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;}
setStyle = "error";
return attrState(type, stream, state);
}
function attrContinuedState(type, stream, state) {
if (type == "string") return attrContinuedState;
return attrState(type, stream, state);
}
return {
startState: function(baseIndent) {
var state = {tokenize: inText,
state: baseState,
indented: baseIndent || 0,
tagName: null, tagStart: null,
context: null}
if (baseIndent != null) state.baseIndent = baseIndent
return state
},
token: function(stream, state) {
if (!state.tagName && stream.sol())
state.indented = stream.indentation();
if (stream.eatSpace()) return null;
type = null;
var style = state.tokenize(stream, state);
if ((style || type) && style != "comment") {
setStyle = null;
state.state = state.state(type || style, stream, state);
if (setStyle)
style = setStyle == "error" ? style + " error" : setStyle;
}
return style;
},
indent: function(state, textAfter, fullLine) {
var context = state.context;
// Indent multi-line strings (e.g. css).
if (state.tokenize.isInAttribute) {
if (state.tagStart == state.indented)
return state.stringStartCol + 1;
else
return state.indented + indentUnit;
}
if (context && context.noIndent) return CodeMirror.Pass;
if (state.tokenize != inTag && state.tokenize != inText)
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
// Indent the starts of attribute names.
if (state.tagName) {
if (config.multilineTagIndentPastTag !== false)
return state.tagStart + state.tagName.length + 2;
else
return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1);
}
if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
if (tagAfter && tagAfter[1]) { // Closing tag spotted
while (context) {
if (context.tagName == tagAfter[2]) {
context = context.prev;
break;
} else if (config.implicitlyClosed.hasOwnProperty(context.tagName)) {
context = context.prev;
} else {
break;
}
}
} else if (tagAfter) { // Opening tag spotted
while (context) {
var grabbers = config.contextGrabbers[context.tagName];
if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
context = context.prev;
else
break;
}
}
while (context && context.prev && !context.startOfLine)
context = context.prev;
if (context) return context.indent + indentUnit;
else return state.baseIndent || 0;
},
electricInput: /<\/[\s\w:]+>$/,
blockCommentStart: "<!--",
blockCommentEnd: "-->",
configuration: config.htmlMode ? "html" : "xml",
helperType: config.htmlMode ? "html" : "xml",
skipAttribute: function(state) {
if (state.state == attrValueState)
state.state = attrState
}
};
});
CodeMirror.defineMIME("text/xml", "xml");
CodeMirror.defineMIME("application/xml", "xml");
if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// TODO actually recognize syntax of TypeScript constructs
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
function expressionAllowed(stream, state, backUp) {
return /^(?:operator|sof|keyword c|case|new|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
(state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
}
CodeMirror.defineMode("javascript", function(config, parserConfig) {
var indentUnit = config.indentUnit;
var statementIndent = parserConfig.statementIndent;
var jsonldMode = parserConfig.jsonld;
var jsonMode = parserConfig.json || jsonldMode;
var isTS = parserConfig.typescript;
var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
// Tokenizer
var keywords = function(){
function kw(type) {return {type: type, style: "keyword"};}
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
var jsKeywords = {
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
"return": C, "break": C, "continue": C, "new": kw("new"), "delete": C, "throw": C, "debugger": C,
"var": kw("var"), "const": kw("var"), "let": kw("var"),
"function": kw("function"), "catch": kw("catch"),
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
"in": operator, "typeof": operator, "instanceof": operator,
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
"this": kw("this"), "class": kw("class"), "super": kw("atom"),
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C
};
// Extend the 'normal' keywords with the TypeScript language extensions
if (isTS) {
var type = {type: "variable", style: "variable-3"};
var tsKeywords = {
// object-like things
"interface": kw("class"),
"implements": C,
"namespace": C,
"module": kw("module"),
"enum": kw("module"),
// scope modifiers
"public": kw("modifier"),
"private": kw("modifier"),
"protected": kw("modifier"),
"abstract": kw("modifier"),
// operators
"as": operator,
// types
"string": type, "number": type, "boolean": type, "any": type
};
for (var attr in tsKeywords) {
jsKeywords[attr] = tsKeywords[attr];
}
}
return jsKeywords;
}();
var isOperatorChar = /[+\-*&%=<>!?|~^]/;
var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
function readRegexp(stream) {
var escaped = false, next, inSet = false;
while ((next = stream.next()) != null) {
if (!escaped) {
if (next == "/" && !inSet) return;
if (next == "[") inSet = true;
else if (inSet && next == "]") inSet = false;
}
escaped = !escaped && next == "\\";
}
}
// Used as scratch variables to communicate multiple values without
// consing up tons of objects.
var type, content;
function ret(tp, style, cont) {
type = tp; content = cont;
return style;
}
function tokenBase(stream, state) {
var ch = stream.next();
if (ch == '"' || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
} else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
return ret("number", "number");
} else if (ch == "." && stream.match("..")) {
return ret("spread", "meta");
} else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
return ret(ch);
} else if (ch == "=" && stream.eat(">")) {
return ret("=>", "operator");
} else if (ch == "0" && stream.eat(/x/i)) {
stream.eatWhile(/[\da-f]/i);
return ret("number", "number");
} else if (ch == "0" && stream.eat(/o/i)) {
stream.eatWhile(/[0-7]/i);
return ret("number", "number");
} else if (ch == "0" && stream.eat(/b/i)) {
stream.eatWhile(/[01]/i);
return ret("number", "number");
} else if (/\d/.test(ch)) {
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
return ret("number", "number");
} else if (ch == "/") {
if (stream.eat("*")) {
state.tokenize = tokenComment;
return tokenComment(stream, state);
} else if (stream.eat("/")) {
stream.skipToEnd();
return ret("comment", "comment");
} else if (expressionAllowed(stream, state, 1)) {
readRegexp(stream);
stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
return ret("regexp", "string-2");
} else {
stream.eatWhile(isOperatorChar);
return ret("operator", "operator", stream.current());
}
} else if (ch == "`") {
state.tokenize = tokenQuasi;
return tokenQuasi(stream, state);
} else if (ch == "#") {
stream.skipToEnd();
return ret("error", "error");
} else if (isOperatorChar.test(ch)) {
stream.eatWhile(isOperatorChar);
return ret("operator", "operator", stream.current());
} else if (wordRE.test(ch)) {
stream.eatWhile(wordRE);
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
ret("variable", "variable", word);
}
}
function tokenString(quote) {
return function(stream, state) {
var escaped = false, next;
if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
state.tokenize = tokenBase;
return ret("jsonld-keyword", "meta");
}
while ((next = stream.next()) != null) {
if (next == quote && !escaped) break;
escaped = !escaped && next == "\\";
}
if (!escaped) state.tokenize = tokenBase;
return ret("string", "string");
};
}
function tokenComment(stream, state) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
break;
}
maybeEnd = (ch == "*");
}
return ret("comment", "comment");
}
function tokenQuasi(stream, state) {
var escaped = false, next;
while ((next = stream.next()) != null) {
if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
state.tokenize = tokenBase;
break;
}
escaped = !escaped && next == "\\";
}
return ret("quasi", "string-2", stream.current());
}
var brackets = "([{}])";
// This is a crude lookahead trick to try and notice that we're
// parsing the argument patterns for a fat-arrow function before we
// actually hit the arrow token. It only works if the arrow is on
// the same line as the arguments and there's no strange noise
// (comments) in between. Fallback is to only notice when we hit the
// arrow, and not declare the arguments as locals for the arrow
// body.
function findFatArrow(stream, state) {
if (state.fatArrowAt) state.fatArrowAt = null;
var arrow = stream.string.indexOf("=>", stream.start);
if (arrow < 0) return;
var depth = 0, sawSomething = false;
for (var pos = arrow - 1; pos >= 0; --pos) {
var ch = stream.string.charAt(pos);
var bracket = brackets.indexOf(ch);
if (bracket >= 0 && bracket < 3) {
if (!depth) { ++pos; break; }
if (--depth == 0) break;
} else if (bracket >= 3 && bracket < 6) {
++depth;
} else if (wordRE.test(ch)) {
sawSomething = true;
} else if (/["'\/]/.test(ch)) {
return;
} else if (sawSomething && !depth) {
++pos;
break;
}
}
if (sawSomething && !depth) state.fatArrowAt = pos;
}
// Parser
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true};
function JSLexical(indented, column, type, align, prev, info) {
this.indented = indented;
this.column = column;
this.type = type;
this.prev = prev;
this.info = info;
if (align != null) this.align = align;
}
function inScope(state, varname) {
for (var v = state.localVars; v; v = v.next)
if (v.name == varname) return true;
for (var cx = state.context; cx; cx = cx.prev) {
for (var v = cx.vars; v; v = v.next)
if (v.name == varname) return true;
}
}
function parseJS(state, style, type, content, stream) {
var cc = state.cc;
// Communicate our context to the combinators.
// (Less wasteful than consing up a hundred closures on every call.)
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
if (!state.lexical.hasOwnProperty("align"))
state.lexical.align = true;
while(true) {
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
if (combinator(type, content)) {
while(cc.length && cc[cc.length - 1].lex)
cc.pop()();
if (cx.marked) return cx.marked;
if (type == "variable" && inScope(state, content)) return "variable-2";
return style;
}
}
}
// Combinator utils
var cx = {state: null, column: null, marked: null, cc: null};
function pass() {
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
}
function cont() {
pass.apply(null, arguments);
return true;
}
function register(varname) {
function inList(list) {
for (var v = list; v; v = v.next)
if (v.name == varname) return true;
return false;
}
var state = cx.state;
cx.marked = "def";
if (state.context) {
if (inList(state.localVars)) return;
state.localVars = {name: varname, next: state.localVars};
} else {
if (inList(state.globalVars)) return;
if (parserConfig.globalVars)
state.globalVars = {name: varname, next: state.globalVars};
}
}
// Combinators
var defaultVars = {name: "this", next: {name: "arguments"}};
function pushcontext() {
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
cx.state.localVars = defaultVars;
}
function popcontext() {
cx.state.localVars = cx.state.context.vars;
cx.state.context = cx.state.context.prev;
}
function pushlex(type, info) {
var result = function() {
var state = cx.state, indent = state.indented;
if (state.lexical.type == "stat") indent = state.lexical.indented;
else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
indent = outer.indented;
state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
};
result.lex = true;
return result;
}
function poplex() {
var state = cx.state;
if (state.lexical.prev) {
if (state.lexical.type == ")")
state.indented = state.lexical.indented;
state.lexical = state.lexical.prev;
}
}
poplex.lex = true;
function expect(wanted) {
function exp(type) {
if (type == wanted) return cont();
else if (wanted == ";") return pass();
else return cont(exp);
};
return exp;
}
function statement(type, value) {
if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
if (type == "{") return cont(pushlex("}"), block, poplex);
if (type == ";") return cont();
if (type == "if") {
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
cx.state.cc.pop()();
return cont(pushlex("form"), expression, statement, poplex, maybeelse);
}
if (type == "function") return cont(functiondef);
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
if (type == "variable") return cont(pushlex("stat"), maybelabel);
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
block, poplex, poplex);
if (type == "case") return cont(expression, expect(":"));
if (type == "default") return cont(expect(":"));
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
statement, poplex, popcontext);
if (type == "class") return cont(pushlex("form"), className, poplex);
if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
if (type == "module") return cont(pushlex("form"), pattern, pushlex("}"), expect("{"), block, poplex, poplex)
return pass(pushlex("stat"), expression, expect(";"), poplex);
}
function expression(type) {
return expressionInner(type, false);
}
function expressionNoComma(type) {
return expressionInner(type, true);
}
function expressionInner(type, noComma) {
if (cx.state.fatArrowAt == cx.stream.start) {
var body = noComma ? arrowBodyNoComma : arrowBody;
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
}
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
if (type == "function") return cont(functiondef, maybeop);
if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop);
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
if (type == "quasi") return pass(quasi, maybeop);
if (type == "new") return cont(maybeTarget(noComma));
return cont();
}
function maybeexpression(type) {
if (type.match(/[;\}\)\],]/)) return pass();
return pass(expression);
}
function maybeexpressionNoComma(type) {
if (type.match(/[;\}\)\],]/)) return pass();
return pass(expressionNoComma);
}
function maybeoperatorComma(type, value) {
if (type == ",") return cont(expression);
return maybeoperatorNoComma(type, value, false);
}
function maybeoperatorNoComma(type, value, noComma) {
var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
var expr = noComma == false ? expression : expressionNoComma;
if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
if (type == "operator") {
if (/\+\+|--/.test(value)) return cont(me);
if (value == "?") return cont(expression, expect(":"), expr);
return cont(expr);
}
if (type == "quasi") { return pass(quasi, me); }
if (type == ";") return;
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
if (type == ".") return cont(property, me);
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
}
function quasi(type, value) {
if (type != "quasi") return pass();
if (value.slice(value.length - 2) != "${") return cont(quasi);
return cont(expression, continueQuasi);
}
function continueQuasi(type) {
if (type == "}") {
cx.marked = "string-2";
cx.state.tokenize = tokenQuasi;
return cont(quasi);
}
}
function arrowBody(type) {
findFatArrow(cx.stream, cx.state);
return pass(type == "{" ? statement : expression);
}
function arrowBodyNoComma(type) {
findFatArrow(cx.stream, cx.state);
return pass(type == "{" ? statement : expressionNoComma);
}
function maybeTarget(noComma) {
return function(type) {
if (type == ".") return cont(noComma ? targetNoComma : target);
else return pass(noComma ? expressionNoComma : expression);
};
}
function target(_, value) {
if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); }
}
function targetNoComma(_, value) {
if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); }
}
function maybelabel(type) {
if (type == ":") return cont(poplex, statement);
return pass(maybeoperatorComma, expect(";"), poplex);
}
function property(type) {
if (type == "variable") {cx.marked = "property"; return cont();}
}
function objprop(type, value) {
if (type == "variable" || cx.style == "keyword") {
cx.marked = "property";
if (value == "get" || value == "set") return cont(getterSetter);
return cont(afterprop);
} else if (type == "number" || type == "string") {
cx.marked = jsonldMode ? "property" : (cx.style + " property");
return cont(afterprop);
} else if (type == "jsonld-keyword") {
return cont(afterprop);
} else if (type == "modifier") {
return cont(objprop)
} else if (type == "[") {
return cont(expression, expect("]"), afterprop);
} else if (type == "spread") {
return cont(expression);
}
}
function getterSetter(type) {
if (type != "variable") return pass(afterprop);
cx.marked = "property";
return cont(functiondef);
}
function afterprop(type) {
if (type == ":") return cont(expressionNoComma);
if (type == "(") return pass(functiondef);
}
function commasep(what, end) {
function proceed(type) {
if (type == ",") {
var lex = cx.state.lexical;
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
return cont(what, proceed);
}
if (type == end) return cont();
return cont(expect(end));
}
return function(type) {
if (type == end) return cont();
return pass(what, proceed);
};
}
function contCommasep(what, end, info) {
for (var i = 3; i < arguments.length; i++)
cx.cc.push(arguments[i]);
return cont(pushlex(end, info), commasep(what, end), poplex);
}
function block(type) {
if (type == "}") return cont();
return pass(statement, block);
}
function maybetype(type) {
if (isTS && type == ":") return cont(typedef);
}
function maybedefault(_, value) {
if (value == "=") return cont(expressionNoComma);
}
function typedef(type) {
if (type == "variable") {cx.marked = "variable-3"; return cont();}
}
function vardef() {
return pass(pattern, maybetype, maybeAssign, vardefCont);
}
function pattern(type, value) {
if (type == "modifier") return cont(pattern)
if (type == "variable") { register(value); return cont(); }
if (type == "spread") return cont(pattern);
if (type == "[") return contCommasep(pattern, "]");
if (type == "{") return contCommasep(proppattern, "}");
}
function proppattern(type, value) {
if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
register(value);
return cont(maybeAssign);
}
if (type == "variable") cx.marked = "property";
if (type == "spread") return cont(pattern);
if (type == "}") return pass();
return cont(expect(":"), pattern, maybeAssign);
}
function maybeAssign(_type, value) {
if (value == "=") return cont(expressionNoComma);
}
function vardefCont(type) {
if (type == ",") return cont(vardef);
}
function maybeelse(type, value) {
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
}
function forspec(type) {
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
}
function forspec1(type) {
if (type == "var") return cont(vardef, expect(";"), forspec2);
if (type == ";") return cont(forspec2);
if (type == "variable") return cont(formaybeinof);
return pass(expression, expect(";"), forspec2);
}
function formaybeinof(_type, value) {
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
return cont(maybeoperatorComma, forspec2);
}
function forspec2(type, value) {
if (type == ";") return cont(forspec3);
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
return pass(expression, expect(";"), forspec3);
}
function forspec3(type) {
if (type != ")") cont(expression);
}
function functiondef(type, value) {
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
if (type == "variable") {register(value); return cont(functiondef);}
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, statement, popcontext);
}
function funarg(type) {
if (type == "spread") return cont(funarg);
return pass(pattern, maybetype, maybedefault);
}
function className(type, value) {
if (type == "variable") {register(value); return cont(classNameAfter);}
}
function classNameAfter(type, value) {
if (value == "extends") return cont(expression, classNameAfter);
if (type == "{") return cont(pushlex("}"), classBody, poplex);
}
function classBody(type, value) {
if (type == "variable" || cx.style == "keyword") {
if (value == "static") {
cx.marked = "keyword";
return cont(classBody);
}
cx.marked = "property";
if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody);
return cont(functiondef, classBody);
}
if (value == "*") {
cx.marked = "keyword";
return cont(classBody);
}
if (type == ";") return cont(classBody);
if (type == "}") return cont();
}
function classGetterSetter(type) {
if (type != "variable") return pass();
cx.marked = "property";
return cont();
}
function afterExport(_type, value) {
if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
return pass(statement);
}
function afterImport(type) {
if (type == "string") return cont();
return pass(importSpec, maybeFrom);
}
function importSpec(type, value) {
if (type == "{") return contCommasep(importSpec, "}");
if (type == "variable") register(value);
if (value == "*") cx.marked = "keyword";
return cont(maybeAs);
}
function maybeAs(_type, value) {
if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
}
function maybeFrom(_type, value) {
if (value == "from") { cx.marked = "keyword"; return cont(expression); }
}
function arrayLiteral(type) {
if (type == "]") return cont();
return pass(expressionNoComma, maybeArrayComprehension);
}
function maybeArrayComprehension(type) {
if (type == "for") return pass(comprehension, expect("]"));
if (type == ",") return cont(commasep(maybeexpressionNoComma, "]"));
return pass(commasep(expressionNoComma, "]"));
}
function comprehension(type) {
if (type == "for") return cont(forspec, comprehension);
if (type == "if") return cont(expression, comprehension);
}
function isContinuedStatement(state, textAfter) {
return state.lastType == "operator" || state.lastType == "," ||
isOperatorChar.test(textAfter.charAt(0)) ||
/[,.]/.test(textAfter.charAt(0));
}
// Interface
return {
startState: function(basecolumn) {
var state = {
tokenize: tokenBase,
lastType: "sof",
cc: [],
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
localVars: parserConfig.localVars,
context: parserConfig.localVars && {vars: parserConfig.localVars},
indented: basecolumn || 0
};
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
state.globalVars = parserConfig.globalVars;
return state;
},
token: function(stream, state) {
if (stream.sol()) {
if (!state.lexical.hasOwnProperty("align"))
state.lexical.align = false;
state.indented = stream.indentation();
findFatArrow(stream, state);
}
if (state.tokenize != tokenComment && stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
if (type == "comment") return style;
state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
return parseJS(state, style, type, content, stream);
},
indent: function(state, textAfter) {
if (state.tokenize == tokenComment) return CodeMirror.Pass;
if (state.tokenize != tokenBase) return 0;
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
// Kludge to prevent 'maybelse' from blocking lexical scope pops
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
var c = state.cc[i];
if (c == poplex) lexical = lexical.prev;
else if (c != maybeelse) break;
}
if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev;
if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
lexical = lexical.prev;
var type = lexical.type, closing = firstChar == type;
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0);
else if (type == "form" && firstChar == "{") return lexical.indented;
else if (type == "form") return lexical.indented + indentUnit;
else if (type == "stat")
return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
else return lexical.indented + (closing ? 0 : indentUnit);
},
electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
blockCommentStart: jsonMode ? null : "/*",
blockCommentEnd: jsonMode ? null : "*/",
lineComment: jsonMode ? null : "//",
fold: "brace",
closeBrackets: "()[]{}''\"\"``",
helperType: jsonMode ? "json" : "javascript",
jsonldMode: jsonldMode,
jsonMode: jsonMode,
expressionAllowed: expressionAllowed,
skipExpression: function(state) {
var top = state.cc[state.cc.length - 1]
if (top == expression || top == expressionNoComma) state.cc.pop()
}
};
});
CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
CodeMirror.defineMIME("text/javascript", "javascript");
CodeMirror.defineMIME("text/ecmascript", "javascript");
CodeMirror.defineMIME("application/javascript", "javascript");
CodeMirror.defineMIME("application/x-javascript", "javascript");
CodeMirror.defineMIME("application/ecmascript", "javascript");
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true});
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineMode("css", function(config, parserConfig) {
var inline = parserConfig.inline
if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
var indentUnit = config.indentUnit,
tokenHooks = parserConfig.tokenHooks,
documentTypes = parserConfig.documentTypes || {},
mediaTypes = parserConfig.mediaTypes || {},
mediaFeatures = parserConfig.mediaFeatures || {},
mediaValueKeywords = parserConfig.mediaValueKeywords || {},
propertyKeywords = parserConfig.propertyKeywords || {},
nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
fontProperties = parserConfig.fontProperties || {},
counterDescriptors = parserConfig.counterDescriptors || {},
colorKeywords = parserConfig.colorKeywords || {},
valueKeywords = parserConfig.valueKeywords || {},
allowNested = parserConfig.allowNested,
supportsAtComponent = parserConfig.supportsAtComponent === true;
var type, override;
function ret(style, tp) { type = tp; return style; }
// Tokenizers
function tokenBase(stream, state) {
var ch = stream.next();
if (tokenHooks[ch]) {
var result = tokenHooks[ch](stream, state);
if (result !== false) return result;
}
if (ch == "@") {
stream.eatWhile(/[\w\\\-]/);
return ret("def", stream.current());
} else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) {
return ret(null, "compare");
} else if (ch == "\"" || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
} else if (ch == "#") {
stream.eatWhile(/[\w\\\-]/);
return ret("atom", "hash");
} else if (ch == "!") {
stream.match(/^\s*\w*/);
return ret("keyword", "important");
} else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
} else if (ch === "-") {
if (/[\d.]/.test(stream.peek())) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
} else if (stream.match(/^-[\w\\\-]+/)) {
stream.eatWhile(/[\w\\\-]/);
if (stream.match(/^\s*:/, false))
return ret("variable-2", "variable-definition");
return ret("variable-2", "variable");
} else if (stream.match(/^\w+-/)) {
return ret("meta", "meta");
}
} else if (/[,+>*\/]/.test(ch)) {
return ret(null, "select-op");
} else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
return ret("qualifier", "qualifier");
} else if (/[:;{}\[\]\(\)]/.test(ch)) {
return ret(null, ch);
} else if ((ch == "u" && stream.match(/rl(-prefix)?\(/)) ||
(ch == "d" && stream.match("omain(")) ||
(ch == "r" && stream.match("egexp("))) {
stream.backUp(1);
state.tokenize = tokenParenthesized;
return ret("property", "word");
} else if (/[\w\\\-]/.test(ch)) {
stream.eatWhile(/[\w\\\-]/);
return ret("property", "word");
} else {
return ret(null, null);
}
}
function tokenString(quote) {
return function(stream, state) {
var escaped = false, ch;
while ((ch = stream.next()) != null) {
if (ch == quote && !escaped) {
if (quote == ")") stream.backUp(1);
break;
}
escaped = !escaped && ch == "\\";
}
if (ch == quote || !escaped && quote != ")") state.tokenize = null;
return ret("string", "string");
};
}
function tokenParenthesized(stream, state) {
stream.next(); // Must be '('
if (!stream.match(/\s*[\"\')]/, false))
state.tokenize = tokenString(")");
else
state.tokenize = null;
return ret(null, "(");
}
// Context management
function Context(type, indent, prev) {
this.type = type;
this.indent = indent;
this.prev = prev;
}
function pushContext(state, stream, type, indent) {
state.context = new Context(type, stream.indentation() + (indent === false ? 0 : indentUnit), state.context);
return type;
}
function popContext(state) {
if (state.context.prev)
state.context = state.context.prev;
return state.context.type;
}
function pass(type, stream, state) {
return states[state.context.type](type, stream, state);
}
function popAndPass(type, stream, state, n) {
for (var i = n || 1; i > 0; i--)
state.context = state.context.prev;
return pass(type, stream, state);
}
// Parser
function wordAsValue(stream) {
var word = stream.current().toLowerCase();
if (valueKeywords.hasOwnProperty(word))
override = "atom";
else if (colorKeywords.hasOwnProperty(word))
override = "keyword";
else
override = "variable";
}
var states = {};
states.top = function(type, stream, state) {
if (type == "{") {
return pushContext(state, stream, "block");
} else if (type == "}" && state.context.prev) {
return popContext(state);
} else if (supportsAtComponent && /@component/.test(type)) {
return pushContext(state, stream, "atComponentBlock");
} else if (/^@(-moz-)?document$/.test(type)) {
return pushContext(state, stream, "documentTypes");
} else if (/^@(media|supports|(-moz-)?document|import)$/.test(type)) {
return pushContext(state, stream, "atBlock");
} else if (/^@(font-face|counter-style)/.test(type)) {
state.stateArg = type;
return "restricted_atBlock_before";
} else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/.test(type)) {
return "keyframes";
} else if (type && type.charAt(0) == "@") {
return pushContext(state, stream, "at");
} else if (type == "hash") {
override = "builtin";
} else if (type == "word") {
override = "tag";
} else if (type == "variable-definition") {
return "maybeprop";
} else if (type == "interpolation") {
return pushContext(state, stream, "interpolation");
} else if (type == ":") {
return "pseudo";
} else if (allowNested && type == "(") {
return pushContext(state, stream, "parens");
}
return state.context.type;
};
states.block = function(type, stream, state) {
if (type == "word") {
var word = stream.current().toLowerCase();
if (propertyKeywords.hasOwnProperty(word)) {
override = "property";
return "maybeprop";
} else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
override = "string-2";
return "maybeprop";
} else if (allowNested) {
override = stream.match(/^\s*:(?:\s|$)/, false) ? "property" : "tag";
return "block";
} else {
override += " error";
return "maybeprop";
}
} else if (type == "meta") {
return "block";
} else if (!allowNested && (type == "hash" || type == "qualifier")) {
override = "error";
return "block";
} else {
return states.top(type, stream, state);
}
};
states.maybeprop = function(type, stream, state) {
if (type == ":") return pushContext(state, stream, "prop");
return pass(type, stream, state);
};
states.prop = function(type, stream, state) {
if (type == ";") return popContext(state);
if (type == "{" && allowNested) return pushContext(state, stream, "propBlock");
if (type == "}" || type == "{") return popAndPass(type, stream, state);
if (type == "(") return pushContext(state, stream, "parens");
if (type == "hash" && !/^#([0-9a-fA-f]{3,4}|[0-9a-fA-f]{6}|[0-9a-fA-f]{8})$/.test(stream.current())) {
override += " error";
} else if (type == "word") {
wordAsValue(stream);
} else if (type == "interpolation") {
return pushContext(state, stream, "interpolation");
}
return "prop";
};
states.propBlock = function(type, _stream, state) {
if (type == "}") return popContext(state);
if (type == "word") { override = "property"; return "maybeprop"; }
return state.context.type;
};
states.parens = function(type, stream, state) {
if (type == "{" || type == "}") return popAndPass(type, stream, state);
if (type == ")") return popContext(state);
if (type == "(") return pushContext(state, stream, "parens");
if (type == "interpolation") return pushContext(state, stream, "interpolation");
if (type == "word") wordAsValue(stream);
return "parens";
};
states.pseudo = function(type, stream, state) {
if (type == "word") {
override = "variable-3";
return state.context.type;
}
return pass(type, stream, state);
};
states.documentTypes = function(type, stream, state) {
if (type == "word" && documentTypes.hasOwnProperty(stream.current())) {
override = "tag";
return state.context.type;
} else {
return states.atBlock(type, stream, state);
}
};
states.atBlock = function(type, stream, state) {
if (type == "(") return pushContext(state, stream, "atBlock_parens");
if (type == "}" || type == ";") return popAndPass(type, stream, state);
if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
if (type == "interpolation") return pushContext(state, stream, "interpolation");
if (type == "word") {
var word = stream.current().toLowerCase();
if (word == "only" || word == "not" || word == "and" || word == "or")
override = "keyword";
else if (mediaTypes.hasOwnProperty(word))
override = "attribute";
else if (mediaFeatures.hasOwnProperty(word))
override = "property";
else if (mediaValueKeywords.hasOwnProperty(word))
override = "keyword";
else if (propertyKeywords.hasOwnProperty(word))
override = "property";
else if (nonStandardPropertyKeywords.hasOwnProperty(word))
override = "string-2";
else if (valueKeywords.hasOwnProperty(word))
override = "atom";
else if (colorKeywords.hasOwnProperty(word))
override = "keyword";
else
override = "error";
}
return state.context.type;
};
states.atComponentBlock = function(type, stream, state) {
if (type == "}")
return popAndPass(type, stream, state);
if (type == "{")
return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top", false);
if (type == "word")
override = "error";
return state.context.type;
};
states.atBlock_parens = function(type, stream, state) {
if (type == ")") return popContext(state);
if (type == "{" || type == "}") return popAndPass(type, stream, state, 2);
return states.atBlock(type, stream, state);
};
states.restricted_atBlock_before = function(type, stream, state) {
if (type == "{")
return pushContext(state, stream, "restricted_atBlock");
if (type == "word" && state.stateArg == "@counter-style") {
override = "variable";
return "restricted_atBlock_before";
}
return pass(type, stream, state);
};
states.restricted_atBlock = function(type, stream, state) {
if (type == "}") {
state.stateArg = null;
return popContext(state);
}
if (type == "word") {
if ((state.stateArg == "@font-face" && !fontProperties.hasOwnProperty(stream.current().toLowerCase())) ||
(state.stateArg == "@counter-style" && !counterDescriptors.hasOwnProperty(stream.current().toLowerCase())))
override = "error";
else
override = "property";
return "maybeprop";
}
return "restricted_atBlock";
};
states.keyframes = function(type, stream, state) {
if (type == "word") { override = "variable"; return "keyframes"; }
if (type == "{") return pushContext(state, stream, "top");
return pass(type, stream, state);
};
states.at = function(type, stream, state) {
if (type == ";") return popContext(state);
if (type == "{" || type == "}") return popAndPass(type, stream, state);
if (type == "word") override = "tag";
else if (type == "hash") override = "builtin";
return "at";
};
states.interpolation = function(type, stream, state) {
if (type == "}") return popContext(state);
if (type == "{" || type == ";") return popAndPass(type, stream, state);
if (type == "word") override = "variable";
else if (type != "variable" && type != "(" && type != ")") override = "error";
return "interpolation";
};
return {
startState: function(base) {
return {tokenize: null,
state: inline ? "block" : "top",
stateArg: null,
context: new Context(inline ? "block" : "top", base || 0, null)};
},
token: function(stream, state) {
if (!state.tokenize && stream.eatSpace()) return null;
var style = (state.tokenize || tokenBase)(stream, state);
if (style && typeof style == "object") {
type = style[1];
style = style[0];
}
override = style;
state.state = states[state.state](type, stream, state);
return override;
},
indent: function(state, textAfter) {
var cx = state.context, ch = textAfter && textAfter.charAt(0);
var indent = cx.indent;
if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
if (cx.prev) {
if (ch == "}" && (cx.type == "block" || cx.type == "top" ||
cx.type == "interpolation" || cx.type == "restricted_atBlock")) {
// Resume indentation from parent context.
cx = cx.prev;
indent = cx.indent;
} else if (ch == ")" && (cx.type == "parens" || cx.type == "atBlock_parens") ||
ch == "{" && (cx.type == "at" || cx.type == "atBlock")) {
// Dedent relative to current context.
indent = Math.max(0, cx.indent - indentUnit);
cx = cx.prev;
}
}
return indent;
},
electricChars: "}",
blockCommentStart: "/*",
blockCommentEnd: "*/",
fold: "brace"
};
});
function keySet(array) {
var keys = {};
for (var i = 0; i < array.length; ++i) {
keys[array[i]] = true;
}
return keys;
}
var documentTypes_ = [
"domain", "regexp", "url", "url-prefix"
], documentTypes = keySet(documentTypes_);
var mediaTypes_ = [
"all", "aural", "braille", "handheld", "print", "projection", "screen",
"tty", "tv", "embossed"
], mediaTypes = keySet(mediaTypes_);
var mediaFeatures_ = [
"width", "min-width", "max-width", "height", "min-height", "max-height",
"device-width", "min-device-width", "max-device-width", "device-height",
"min-device-height", "max-device-height", "aspect-ratio",
"min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
"min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
"max-color", "color-index", "min-color-index", "max-color-index",
"monochrome", "min-monochrome", "max-monochrome", "resolution",
"min-resolution", "max-resolution", "scan", "grid", "orientation",
"device-pixel-ratio", "min-device-pixel-ratio", "max-device-pixel-ratio",
"pointer", "any-pointer", "hover", "any-hover"
], mediaFeatures = keySet(mediaFeatures_);
var mediaValueKeywords_ = [
"landscape", "portrait", "none", "coarse", "fine", "on-demand", "hover",
"interlace", "progressive"
], mediaValueKeywords = keySet(mediaValueKeywords_);
var propertyKeywords_ = [
"align-content", "align-items", "align-self", "alignment-adjust",
"alignment-baseline", "anchor-point", "animation", "animation-delay",
"animation-direction", "animation-duration", "animation-fill-mode",
"animation-iteration-count", "animation-name", "animation-play-state",
"animation-timing-function", "appearance", "azimuth", "backface-visibility",
"background", "background-attachment", "background-blend-mode", "background-clip",
"background-color", "background-image", "background-origin", "background-position",
"background-repeat", "background-size", "baseline-shift", "binding",
"bleed", "bookmark-label", "bookmark-level", "bookmark-state",
"bookmark-target", "border", "border-bottom", "border-bottom-color",
"border-bottom-left-radius", "border-bottom-right-radius",
"border-bottom-style", "border-bottom-width", "border-collapse",
"border-color", "border-image", "border-image-outset",
"border-image-repeat", "border-image-slice", "border-image-source",
"border-image-width", "border-left", "border-left-color",
"border-left-style", "border-left-width", "border-radius", "border-right",
"border-right-color", "border-right-style", "border-right-width",
"border-spacing", "border-style", "border-top", "border-top-color",
"border-top-left-radius", "border-top-right-radius", "border-top-style",
"border-top-width", "border-width", "bottom", "box-decoration-break",
"box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
"caption-side", "clear", "clip", "color", "color-profile", "column-count",
"column-fill", "column-gap", "column-rule", "column-rule-color",
"column-rule-style", "column-rule-width", "column-span", "column-width",
"columns", "content", "counter-increment", "counter-reset", "crop", "cue",
"cue-after", "cue-before", "cursor", "direction", "display",
"dominant-baseline", "drop-initial-after-adjust",
"drop-initial-after-align", "drop-initial-before-adjust",
"drop-initial-before-align", "drop-initial-size", "drop-initial-value",
"elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
"flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
"float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",
"font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",
"font-stretch", "font-style", "font-synthesis", "font-variant",
"font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
"font-variant-ligatures", "font-variant-numeric", "font-variant-position",
"font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
"grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end",
"grid-column-start", "grid-row", "grid-row-end", "grid-row-start",
"grid-template", "grid-template-areas", "grid-template-columns",
"grid-template-rows", "hanging-punctuation", "height", "hyphens",
"icon", "image-orientation", "image-rendering", "image-resolution",
"inline-box-align", "justify-content", "left", "letter-spacing",
"line-break", "line-height", "line-stacking", "line-stacking-ruby",
"line-stacking-shift", "line-stacking-strategy", "list-style",
"list-style-image", "list-style-position", "list-style-type", "margin",
"margin-bottom", "margin-left", "margin-right", "margin-top",
"marker-offset", "marks", "marquee-direction", "marquee-loop",
"marquee-play-count", "marquee-speed", "marquee-style", "max-height",
"max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
"nav-left", "nav-right", "nav-up", "object-fit", "object-position",
"opacity", "order", "orphans", "outline",
"outline-color", "outline-offset", "outline-style", "outline-width",
"overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
"padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
"page", "page-break-after", "page-break-before", "page-break-inside",
"page-policy", "pause", "pause-after", "pause-before", "perspective",
"perspective-origin", "pitch", "pitch-range", "play-during", "position",
"presentation-level", "punctuation-trim", "quotes", "region-break-after",
"region-break-before", "region-break-inside", "region-fragment",
"rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
"right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
"ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",
"shape-outside", "size", "speak", "speak-as", "speak-header",
"speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
"tab-size", "table-layout", "target", "target-name", "target-new",
"target-position", "text-align", "text-align-last", "text-decoration",
"text-decoration-color", "text-decoration-line", "text-decoration-skip",
"text-decoration-style", "text-emphasis", "text-emphasis-color",
"text-emphasis-position", "text-emphasis-style", "text-height",
"text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",
"text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",
"text-wrap", "top", "transform", "transform-origin", "transform-style",
"transition", "transition-delay", "transition-duration",
"transition-property", "transition-timing-function", "unicode-bidi",
"vertical-align", "visibility", "voice-balance", "voice-duration",
"voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
"voice-volume", "volume", "white-space", "widows", "width", "word-break",
"word-spacing", "word-wrap", "z-index",
// SVG-specific
"clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
"flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
"color-interpolation", "color-interpolation-filters",
"color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
"marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
"stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
"stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
"baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
"glyph-orientation-vertical", "text-anchor", "writing-mode"
], propertyKeywords = keySet(propertyKeywords_);
var nonStandardPropertyKeywords_ = [
"scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
"scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
"scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
"searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
"searchfield-results-decoration", "zoom"
], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_);
var fontProperties_ = [
"font-family", "src", "unicode-range", "font-variant", "font-feature-settings",
"font-stretch", "font-weight", "font-style"
], fontProperties = keySet(fontProperties_);
var counterDescriptors_ = [
"additive-symbols", "fallback", "negative", "pad", "prefix", "range",
"speak-as", "suffix", "symbols", "system"
], counterDescriptors = keySet(counterDescriptors_);
var colorKeywords_ = [
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",
"cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",
"darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",
"darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
"darkslateblue", "darkslategray", "darkturquoise", "darkviolet",
"deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",
"floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
"gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",
"hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",
"lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",
"lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",
"lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
"lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
"maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
"mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
"mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
"navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",
"orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",
"papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
"purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown",
"salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",
"slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",
"teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",
"whitesmoke", "yellow", "yellowgreen"
], colorKeywords = keySet(colorKeywords_);
var valueKeywords_ = [
"above", "absolute", "activeborder", "additive", "activecaption", "afar",
"after-white-space", "ahead", "alias", "all", "all-scroll", "alphabetic", "alternate",
"always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
"arabic-indic", "armenian", "asterisks", "attr", "auto", "avoid", "avoid-column", "avoid-page",
"avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",
"bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
"both", "bottom", "break", "break-all", "break-word", "bullets", "button", "button-bevel",
"buttonface", "buttonhighlight", "buttonshadow", "buttontext", "calc", "cambodian",
"capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
"cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch",
"cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
"col-resize", "collapse", "color", "color-burn", "color-dodge", "column", "column-reverse",
"compact", "condensed", "contain", "content",
"content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop",
"cross", "crosshair", "currentcolor", "cursive", "cyclic", "darken", "dashed", "decimal",
"decimal-leading-zero", "default", "default-button", "destination-atop",
"destination-in", "destination-out", "destination-over", "devanagari", "difference",
"disc", "discard", "disclosure-closed", "disclosure-open", "document",
"dot-dash", "dot-dot-dash",
"dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
"element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
"ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
"ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
"ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
"ethiopic-halehame-gez", "ethiopic-halehame-om-et",
"ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
"ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig",
"ethiopic-numeric", "ew-resize", "exclusion", "expanded", "extends", "extra-condensed",
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes",
"forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hard-light", "hebrew",
"help", "hidden", "hide", "higher", "highlight", "highlighttext",
"hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "hue", "icon", "ignore",
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
"infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
"inline-block", "inline-flex", "inline-table", "inset", "inside", "intrinsic", "invert",
"italic", "japanese-formal", "japanese-informal", "justify", "kannada",
"katakana", "katakana-iroha", "keep-all", "khmer",
"korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal",
"landscape", "lao", "large", "larger", "left", "level", "lighter", "lighten",
"line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem",
"local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
"lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
"lower-roman", "lowercase", "ltr", "luminosity", "malayalam", "match", "matrix", "matrix3d",
"media-controls-background", "media-current-time-display",
"media-fullscreen-button", "media-mute-button", "media-play-button",
"media-return-to-realtime-button", "media-rewind-button",
"media-seek-back-button", "media-seek-forward-button", "media-slider",
"media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
"media-volume-slider-container", "media-volume-sliderthumb", "medium",
"menu", "menulist", "menulist-button", "menulist-text",
"menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
"mix", "mongolian", "monospace", "move", "multiple", "multiply", "myanmar", "n-resize",
"narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
"no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
"ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
"optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
"outside", "outside-shape", "overlay", "overline", "padding", "padding-box",
"painted", "page", "paused", "persian", "perspective", "plus-darker", "plus-lighter",
"pointer", "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d",
"progress", "push-button", "radial-gradient", "radio", "read-only",
"read-write", "read-write-plaintext-only", "rectangle", "region",
"relative", "repeat", "repeating-linear-gradient",
"repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse",
"rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY",
"rotateZ", "round", "row", "row-resize", "row-reverse", "rtl", "run-in", "running",
"s-resize", "sans-serif", "saturation", "scale", "scale3d", "scaleX", "scaleY", "scaleZ", "screen",
"scroll", "scrollbar", "se-resize", "searchfield",
"searchfield-cancel-button", "searchfield-decoration",
"searchfield-results-button", "searchfield-results-decoration",
"semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
"simp-chinese-formal", "simp-chinese-informal", "single",
"skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal",
"slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
"small", "small-caps", "small-caption", "smaller", "soft-light", "solid", "somali",
"source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "spell-out", "square",
"square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
"subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "table",
"table-caption", "table-cell", "table-column", "table-column-group",
"table-footer-group", "table-header-group", "table-row", "table-row-group",
"tamil",
"telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
"thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
"threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
"tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
"trad-chinese-formal", "trad-chinese-informal",
"translate", "translate3d", "translateX", "translateY", "translateZ",
"transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
"upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
"upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
"var", "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
"visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
"window", "windowframe", "windowtext", "words", "wrap", "wrap-reverse", "x-large", "x-small", "xor",
"xx-large", "xx-small"
], valueKeywords = keySet(valueKeywords_);
var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(mediaValueKeywords_)
.concat(propertyKeywords_).concat(nonStandardPropertyKeywords_).concat(colorKeywords_)
.concat(valueKeywords_);
CodeMirror.registerHelper("hintWords", "css", allWords);
function tokenCComment(stream, state) {
var maybeEnd = false, ch;
while ((ch = stream.next()) != null) {
if (maybeEnd && ch == "/") {
state.tokenize = null;
break;
}
maybeEnd = (ch == "*");
}
return ["comment", "comment"];
}
CodeMirror.defineMIME("text/css", {
documentTypes: documentTypes,
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
mediaValueKeywords: mediaValueKeywords,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
fontProperties: fontProperties,
counterDescriptors: counterDescriptors,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
tokenHooks: {
"/": function(stream, state) {
if (!stream.eat("*")) return false;
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
}
},
name: "css"
});
CodeMirror.defineMIME("text/x-scss", {
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
mediaValueKeywords: mediaValueKeywords,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
fontProperties: fontProperties,
allowNested: true,
tokenHooks: {
"/": function(stream, state) {
if (stream.eat("/")) {
stream.skipToEnd();
return ["comment", "comment"];
} else if (stream.eat("*")) {
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
} else {
return ["operator", "operator"];
}
},
":": function(stream) {
if (stream.match(/\s*\{/))
return [null, "{"];
return false;
},
"$": function(stream) {
stream.match(/^[\w-]+/);
if (stream.match(/^\s*:/, false))
return ["variable-2", "variable-definition"];
return ["variable-2", "variable"];
},
"#": function(stream) {
if (!stream.eat("{")) return false;
return [null, "interpolation"];
}
},
name: "css",
helperType: "scss"
});
CodeMirror.defineMIME("text/x-less", {
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
mediaValueKeywords: mediaValueKeywords,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
fontProperties: fontProperties,
allowNested: true,
tokenHooks: {
"/": function(stream, state) {
if (stream.eat("/")) {
stream.skipToEnd();
return ["comment", "comment"];
} else if (stream.eat("*")) {
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
} else {
return ["operator", "operator"];
}
},
"@": function(stream) {
if (stream.eat("{")) return [null, "interpolation"];
if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/, false)) return false;
stream.eatWhile(/[\w\\\-]/);
if (stream.match(/^\s*:/, false))
return ["variable-2", "variable-definition"];
return ["variable-2", "variable"];
},
"&": function() {
return ["atom", "atom"];
}
},
name: "css",
helperType: "less"
});
CodeMirror.defineMIME("text/x-gss", {
documentTypes: documentTypes,
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
fontProperties: fontProperties,
counterDescriptors: counterDescriptors,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
supportsAtComponent: true,
tokenHooks: {
"/": function(stream, state) {
if (!stream.eat("*")) return false;
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
}
},
name: "css",
helperType: "gss"
});
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript", "../css/css"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var defaultTags = {
script: [
["lang", /(javascript|babel)/i, "javascript"],
["type", /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^$/i, "javascript"],
["type", /./, "text/plain"],
[null, null, "javascript"]
],
style: [
["lang", /^css$/i, "css"],
["type", /^(text\/)?(x-)?(stylesheet|css)$/i, "css"],
["type", /./, "text/plain"],
[null, null, "css"]
]
};
function maybeBackup(stream, pat, style) {
var cur = stream.current(), close = cur.search(pat);
if (close > -1) {
stream.backUp(cur.length - close);
} else if (cur.match(/<\/?$/)) {
stream.backUp(cur.length);
if (!stream.match(pat, false)) stream.match(cur);
}
return style;
}
var attrRegexpCache = {};
function getAttrRegexp(attr) {
var regexp = attrRegexpCache[attr];
if (regexp) return regexp;
return attrRegexpCache[attr] = new RegExp("\\s+" + attr + "\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*");
}
function getAttrValue(text, attr) {
var match = text.match(getAttrRegexp(attr))
return match ? match[2] : ""
}
function getTagRegexp(tagName, anchored) {
return new RegExp((anchored ? "^" : "") + "<\/\s*" + tagName + "\s*>", "i");
}
function addTags(from, to) {
for (var tag in from) {
var dest = to[tag] || (to[tag] = []);
var source = from[tag];
for (var i = source.length - 1; i >= 0; i--)
dest.unshift(source[i])
}
}
function findMatchingMode(tagInfo, tagText) {
for (var i = 0; i < tagInfo.length; i++) {
var spec = tagInfo[i];
if (!spec[0] || spec[1].test(getAttrValue(tagText, spec[0]))) return spec[2];
}
}
CodeMirror.defineMode("htmlmixed", function (config, parserConfig) {
var htmlMode = CodeMirror.getMode(config, {
name: "xml",
htmlMode: true,
multilineTagIndentFactor: parserConfig.multilineTagIndentFactor,
multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag
});
var tags = {};
var configTags = parserConfig && parserConfig.tags, configScript = parserConfig && parserConfig.scriptTypes;
addTags(defaultTags, tags);
if (configTags) addTags(configTags, tags);
if (configScript) for (var i = configScript.length - 1; i >= 0; i--)
tags.script.unshift(["type", configScript[i].matches, configScript[i].mode])
function html(stream, state) {
var style = htmlMode.token(stream, state.htmlState), tag = /\btag\b/.test(style), tagName
if (tag && !/[<>\s\/]/.test(stream.current()) &&
(tagName = state.htmlState.tagName && state.htmlState.tagName.toLowerCase()) &&
tags.hasOwnProperty(tagName)) {
state.inTag = tagName + " "
} else if (state.inTag && tag && />$/.test(stream.current())) {
var inTag = /^([\S]+) (.*)/.exec(state.inTag)
state.inTag = null
var modeSpec = stream.current() == ">" && findMatchingMode(tags[inTag[1]], inTag[2])
var mode = CodeMirror.getMode(config, modeSpec)
var endTagA = getTagRegexp(inTag[1], true), endTag = getTagRegexp(inTag[1], false);
state.token = function (stream, state) {
if (stream.match(endTagA, false)) {
state.token = html;
state.localState = state.localMode = null;
return null;
}
return maybeBackup(stream, endTag, state.localMode.token(stream, state.localState));
};
state.localMode = mode;
state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, ""));
} else if (state.inTag) {
state.inTag += stream.current()
if (stream.eol()) state.inTag += " "
}
return style;
};
return {
startState: function () {
var state = htmlMode.startState();
return {token: html, inTag: null, localMode: null, localState: null, htmlState: state};
},
copyState: function (state) {
var local;
if (state.localState) {
local = CodeMirror.copyState(state.localMode, state.localState);
}
return {token: state.token, inTag: state.inTag,
localMode: state.localMode, localState: local,
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
},
token: function (stream, state) {
return state.token(stream, state);
},
indent: function (state, textAfter) {
if (!state.localMode || /^\s*<\//.test(textAfter))
return htmlMode.indent(state.htmlState, textAfter);
else if (state.localMode.indent)
return state.localMode.indent(state.localState, textAfter);
else
return CodeMirror.Pass;
},
innerMode: function (state) {
return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode};
}
};
}, "xml", "javascript", "css");
CodeMirror.defineMIME("text/html", "htmlmixed");
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// A rough approximation of Sublime Text's keybindings
// Depends on addon/search/searchcursor.js and optionally addon/dialog/dialogs.js
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../lib/codemirror"), require("../addon/search/searchcursor"), require("../addon/edit/matchbrackets"));
else if (typeof define == "function" && define.amd) // AMD
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/edit/matchbrackets"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var map = CodeMirror.keyMap.sublime = {fallthrough: "default"};
var cmds = CodeMirror.commands;
var Pos = CodeMirror.Pos;
var mac = CodeMirror.keyMap["default"] == CodeMirror.keyMap.macDefault;
var ctrl = mac ? "Cmd-" : "Ctrl-";
// This is not exactly Sublime's algorithm. I couldn't make heads or tails of that.
function findPosSubword(doc, start, dir) {
if (dir < 0 && start.ch == 0) return doc.clipPos(Pos(start.line - 1));
var line = doc.getLine(start.line);
if (dir > 0 && start.ch >= line.length) return doc.clipPos(Pos(start.line + 1, 0));
var state = "start", type;
for (var pos = start.ch, e = dir < 0 ? 0 : line.length, i = 0; pos != e; pos += dir, i++) {
var next = line.charAt(dir < 0 ? pos - 1 : pos);
var cat = next != "_" && CodeMirror.isWordChar(next) ? "w" : "o";
if (cat == "w" && next.toUpperCase() == next) cat = "W";
if (state == "start") {
if (cat != "o") { state = "in"; type = cat; }
} else if (state == "in") {
if (type != cat) {
if (type == "w" && cat == "W" && dir < 0) pos--;
if (type == "W" && cat == "w" && dir > 0) { type = "w"; continue; }
break;
}
}
}
return Pos(start.line, pos);
}
function moveSubword(cm, dir) {
cm.extendSelectionsBy(function(range) {
if (cm.display.shift || cm.doc.extend || range.empty())
return findPosSubword(cm.doc, range.head, dir);
else
return dir < 0 ? range.from() : range.to();
});
}
cmds[map["Alt-Left"] = "goSubwordLeft"] = function(cm) { moveSubword(cm, -1); };
cmds[map["Alt-Right"] = "goSubwordRight"] = function(cm) { moveSubword(cm, 1); };
if (mac) map["Cmd-Left"] = "goLineStartSmart";
var scrollLineCombo = mac ? "Ctrl-Alt-" : "Ctrl-";
cmds[map[scrollLineCombo + "Up"] = "scrollLineUp"] = function(cm) {
var info = cm.getScrollInfo();
if (!cm.somethingSelected()) {
var visibleBottomLine = cm.lineAtHeight(info.top + info.clientHeight, "local");
if (cm.getCursor().line >= visibleBottomLine)
cm.execCommand("goLineUp");
}
cm.scrollTo(null, info.top - cm.defaultTextHeight());
};
cmds[map[scrollLineCombo + "Down"] = "scrollLineDown"] = function(cm) {
var info = cm.getScrollInfo();
if (!cm.somethingSelected()) {
var visibleTopLine = cm.lineAtHeight(info.top, "local")+1;
if (cm.getCursor().line <= visibleTopLine)
cm.execCommand("goLineDown");
}
cm.scrollTo(null, info.top + cm.defaultTextHeight());
};
cmds[map["Shift-" + ctrl + "L"] = "splitSelectionByLine"] = function(cm) {
var ranges = cm.listSelections(), lineRanges = [];
for (var i = 0; i < ranges.length; i++) {
var from = ranges[i].from(), to = ranges[i].to();
for (var line = from.line; line <= to.line; ++line)
if (!(to.line > from.line && line == to.line && to.ch == 0))
lineRanges.push({anchor: line == from.line ? from : Pos(line, 0),
head: line == to.line ? to : Pos(line)});
}
cm.setSelections(lineRanges, 0);
};
map["Shift-Tab"] = "indentLess";
cmds[map["Esc"] = "singleSelectionTop"] = function(cm) {
var range = cm.listSelections()[0];
cm.setSelection(range.anchor, range.head, {scroll: false});
};
cmds[map[ctrl + "L"] = "selectLine"] = function(cm) {
var ranges = cm.listSelections(), extended = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
extended.push({anchor: Pos(range.from().line, 0),
head: Pos(range.to().line + 1, 0)});
}
cm.setSelections(extended);
};
map["Shift-Ctrl-K"] = "deleteLine";
function insertLine(cm, above) {
if (cm.isReadOnly()) return CodeMirror.Pass
cm.operation(function() {
var len = cm.listSelections().length, newSelection = [], last = -1;
for (var i = 0; i < len; i++) {
var head = cm.listSelections()[i].head;
if (head.line <= last) continue;
var at = Pos(head.line + (above ? 0 : 1), 0);
cm.replaceRange("\n", at, null, "+insertLine");
cm.indentLine(at.line, null, true);
newSelection.push({head: at, anchor: at});
last = head.line + 1;
}
cm.setSelections(newSelection);
});
}
cmds[map[ctrl + "Enter"] = "insertLineAfter"] = function(cm) { return insertLine(cm, false); };
cmds[map["Shift-" + ctrl + "Enter"] = "insertLineBefore"] = function(cm) { return insertLine(cm, true); };
function wordAt(cm, pos) {
var start = pos.ch, end = start, line = cm.getLine(pos.line);
while (start && CodeMirror.isWordChar(line.charAt(start - 1))) --start;
while (end < line.length && CodeMirror.isWordChar(line.charAt(end))) ++end;
return {from: Pos(pos.line, start), to: Pos(pos.line, end), word: line.slice(start, end)};
}
cmds[map[ctrl + "D"] = "selectNextOccurrence"] = function(cm) {
var from = cm.getCursor("from"), to = cm.getCursor("to");
var fullWord = cm.state.sublimeFindFullWord == cm.doc.sel;
if (CodeMirror.cmpPos(from, to) == 0) {
var word = wordAt(cm, from);
if (!word.word) return;
cm.setSelection(word.from, word.to);
fullWord = true;
} else {
var text = cm.getRange(from, to);
var query = fullWord ? new RegExp("\\b" + text + "\\b") : text;
var cur = cm.getSearchCursor(query, to);
if (cur.findNext()) {
cm.addSelection(cur.from(), cur.to());
} else {
cur = cm.getSearchCursor(query, Pos(cm.firstLine(), 0));
if (cur.findNext())
cm.addSelection(cur.from(), cur.to());
}
}
if (fullWord)
cm.state.sublimeFindFullWord = cm.doc.sel;
};
var mirror = "(){}[]";
function selectBetweenBrackets(cm) {
var pos = cm.getCursor(), opening = cm.scanForBracket(pos, -1);
if (!opening) return;
for (;;) {
var closing = cm.scanForBracket(pos, 1);
if (!closing) return;
if (closing.ch == mirror.charAt(mirror.indexOf(opening.ch) + 1)) {
cm.setSelection(Pos(opening.pos.line, opening.pos.ch + 1), closing.pos, false);
return true;
}
pos = Pos(closing.pos.line, closing.pos.ch + 1);
}
}
cmds[map["Shift-" + ctrl + "Space"] = "selectScope"] = function(cm) {
selectBetweenBrackets(cm) || cm.execCommand("selectAll");
};
cmds[map["Shift-" + ctrl + "M"] = "selectBetweenBrackets"] = function(cm) {
if (!selectBetweenBrackets(cm)) return CodeMirror.Pass;
};
cmds[map[ctrl + "M"] = "goToBracket"] = function(cm) {
cm.extendSelectionsBy(function(range) {
var next = cm.scanForBracket(range.head, 1);
if (next && CodeMirror.cmpPos(next.pos, range.head) != 0) return next.pos;
var prev = cm.scanForBracket(range.head, -1);
return prev && Pos(prev.pos.line, prev.pos.ch + 1) || range.head;
});
};
var swapLineCombo = mac ? "Cmd-Ctrl-" : "Shift-Ctrl-";
cmds[map[swapLineCombo + "Up"] = "swapLineUp"] = function(cm) {
if (cm.isReadOnly()) return CodeMirror.Pass
var ranges = cm.listSelections(), linesToMove = [], at = cm.firstLine() - 1, newSels = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i], from = range.from().line - 1, to = range.to().line;
newSels.push({anchor: Pos(range.anchor.line - 1, range.anchor.ch),
head: Pos(range.head.line - 1, range.head.ch)});
if (range.to().ch == 0 && !range.empty()) --to;
if (from > at) linesToMove.push(from, to);
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
at = to;
}
cm.operation(function() {
for (var i = 0; i < linesToMove.length; i += 2) {
var from = linesToMove[i], to = linesToMove[i + 1];
var line = cm.getLine(from);
cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
if (to > cm.lastLine())
cm.replaceRange("\n" + line, Pos(cm.lastLine()), null, "+swapLine");
else
cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
}
cm.setSelections(newSels);
cm.scrollIntoView();
});
};
cmds[map[swapLineCombo + "Down"] = "swapLineDown"] = function(cm) {
if (cm.isReadOnly()) return CodeMirror.Pass
var ranges = cm.listSelections(), linesToMove = [], at = cm.lastLine() + 1;
for (var i = ranges.length - 1; i >= 0; i--) {
var range = ranges[i], from = range.to().line + 1, to = range.from().line;
if (range.to().ch == 0 && !range.empty()) from--;
if (from < at) linesToMove.push(from, to);
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
at = to;
}
cm.operation(function() {
for (var i = linesToMove.length - 2; i >= 0; i -= 2) {
var from = linesToMove[i], to = linesToMove[i + 1];
var line = cm.getLine(from);
if (from == cm.lastLine())
cm.replaceRange("", Pos(from - 1), Pos(from), "+swapLine");
else
cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
}
cm.scrollIntoView();
});
};
cmds[map[ctrl + "/"] = "toggleCommentIndented"] = function(cm) {
cm.toggleComment({ indent: true });
}
cmds[map[ctrl + "J"] = "joinLines"] = function(cm) {
var ranges = cm.listSelections(), joined = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i], from = range.from();
var start = from.line, end = range.to().line;
while (i < ranges.length - 1 && ranges[i + 1].from().line == end)
end = ranges[++i].to().line;
joined.push({start: start, end: end, anchor: !range.empty() && from});
}
cm.operation(function() {
var offset = 0, ranges = [];
for (var i = 0; i < joined.length; i++) {
var obj = joined[i];
var anchor = obj.anchor && Pos(obj.anchor.line - offset, obj.anchor.ch), head;
for (var line = obj.start; line <= obj.end; line++) {
var actual = line - offset;
if (line == obj.end) head = Pos(actual, cm.getLine(actual).length + 1);
if (actual < cm.lastLine()) {
cm.replaceRange(" ", Pos(actual), Pos(actual + 1, /^\s*/.exec(cm.getLine(actual + 1))[0].length));
++offset;
}
}
ranges.push({anchor: anchor || head, head: head});
}
cm.setSelections(ranges, 0);
});
};
cmds[map["Shift-" + ctrl + "D"] = "duplicateLine"] = function(cm) {
cm.operation(function() {
var rangeCount = cm.listSelections().length;
for (var i = 0; i < rangeCount; i++) {
var range = cm.listSelections()[i];
if (range.empty())
cm.replaceRange(cm.getLine(range.head.line) + "\n", Pos(range.head.line, 0));
else
cm.replaceRange(cm.getRange(range.from(), range.to()), range.from());
}
cm.scrollIntoView();
});
};
map[ctrl + "T"] = "transposeChars";
function sortLines(cm, caseSensitive) {
if (cm.isReadOnly()) return CodeMirror.Pass
var ranges = cm.listSelections(), toSort = [], selected;
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (range.empty()) continue;
var from = range.from().line, to = range.to().line;
while (i < ranges.length - 1 && ranges[i + 1].from().line == to)
to = range[++i].to().line;
toSort.push(from, to);
}
if (toSort.length) selected = true;
else toSort.push(cm.firstLine(), cm.lastLine());
cm.operation(function() {
var ranges = [];
for (var i = 0; i < toSort.length; i += 2) {
var from = toSort[i], to = toSort[i + 1];
var start = Pos(from, 0), end = Pos(to);
var lines = cm.getRange(start, end, false);
if (caseSensitive)
lines.sort();
else
lines.sort(function(a, b) {
var au = a.toUpperCase(), bu = b.toUpperCase();
if (au != bu) { a = au; b = bu; }
return a < b ? -1 : a == b ? 0 : 1;
});
cm.replaceRange(lines, start, end);
if (selected) ranges.push({anchor: start, head: end});
}
if (selected) cm.setSelections(ranges, 0);
});
}
cmds[map["F9"] = "sortLines"] = function(cm) { sortLines(cm, true); };
cmds[map[ctrl + "F9"] = "sortLinesInsensitive"] = function(cm) { sortLines(cm, false); };
cmds[map["F2"] = "nextBookmark"] = function(cm) {
var marks = cm.state.sublimeBookmarks;
if (marks) while (marks.length) {
var current = marks.shift();
var found = current.find();
if (found) {
marks.push(current);
return cm.setSelection(found.from, found.to);
}
}
};
cmds[map["Shift-F2"] = "prevBookmark"] = function(cm) {
var marks = cm.state.sublimeBookmarks;
if (marks) while (marks.length) {
marks.unshift(marks.pop());
var found = marks[marks.length - 1].find();
if (!found)
marks.pop();
else
return cm.setSelection(found.from, found.to);
}
};
cmds[map[ctrl + "F2"] = "toggleBookmark"] = function(cm) {
var ranges = cm.listSelections();
var marks = cm.state.sublimeBookmarks || (cm.state.sublimeBookmarks = []);
for (var i = 0; i < ranges.length; i++) {
var from = ranges[i].from(), to = ranges[i].to();
var found = cm.findMarks(from, to);
for (var j = 0; j < found.length; j++) {
if (found[j].sublimeBookmark) {
found[j].clear();
for (var k = 0; k < marks.length; k++)
if (marks[k] == found[j])
marks.splice(k--, 1);
break;
}
}
if (j == found.length)
marks.push(cm.markText(from, to, {sublimeBookmark: true, clearWhenEmpty: false}));
}
};
cmds[map["Shift-" + ctrl + "F2"] = "clearBookmarks"] = function(cm) {
var marks = cm.state.sublimeBookmarks;
if (marks) for (var i = 0; i < marks.length; i++) marks[i].clear();
marks.length = 0;
};
cmds[map["Alt-F2"] = "selectBookmarks"] = function(cm) {
var marks = cm.state.sublimeBookmarks, ranges = [];
if (marks) for (var i = 0; i < marks.length; i++) {
var found = marks[i].find();
if (!found)
marks.splice(i--, 0);
else
ranges.push({anchor: found.from, head: found.to});
}
if (ranges.length)
cm.setSelections(ranges, 0);
};
map["Alt-Q"] = "wrapLines";
var cK = ctrl + "K ";
function modifyWordOrSelection(cm, mod) {
cm.operation(function() {
var ranges = cm.listSelections(), indices = [], replacements = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (range.empty()) { indices.push(i); replacements.push(""); }
else replacements.push(mod(cm.getRange(range.from(), range.to())));
}
cm.replaceSelections(replacements, "around", "case");
for (var i = indices.length - 1, at; i >= 0; i--) {
var range = ranges[indices[i]];
if (at && CodeMirror.cmpPos(range.head, at) > 0) continue;
var word = wordAt(cm, range.head);
at = word.from;
cm.replaceRange(mod(word.word), word.from, word.to);
}
});
}
map[cK + ctrl + "Backspace"] = "delLineLeft";
cmds[map["Backspace"] = "smartBackspace"] = function(cm) {
if (cm.somethingSelected()) return CodeMirror.Pass;
var cursor = cm.getCursor();
var toStartOfLine = cm.getRange({line: cursor.line, ch: 0}, cursor);
var column = CodeMirror.countColumn(toStartOfLine, null, cm.getOption("tabSize"));
var indentUnit = cm.getOption("indentUnit");
if (toStartOfLine && !/\S/.test(toStartOfLine) && column % indentUnit == 0) {
var prevIndent = new Pos(cursor.line,
CodeMirror.findColumn(toStartOfLine, column - indentUnit, indentUnit));
// If no smart delete is happening (due to tab sizing) just do a regular delete
if (prevIndent.ch == cursor.ch) return CodeMirror.Pass;
return cm.replaceRange("", prevIndent, cursor, "+delete");
} else {
return CodeMirror.Pass;
}
};
cmds[map[cK + ctrl + "K"] = "delLineRight"] = function(cm) {
cm.operation(function() {
var ranges = cm.listSelections();
for (var i = ranges.length - 1; i >= 0; i--)
cm.replaceRange("", ranges[i].anchor, Pos(ranges[i].to().line), "+delete");
cm.scrollIntoView();
});
};
cmds[map[cK + ctrl + "U"] = "upcaseAtCursor"] = function(cm) {
modifyWordOrSelection(cm, function(str) { return str.toUpperCase(); });
};
cmds[map[cK + ctrl + "L"] = "downcaseAtCursor"] = function(cm) {
modifyWordOrSelection(cm, function(str) { return str.toLowerCase(); });
};
cmds[map[cK + ctrl + "Space"] = "setSublimeMark"] = function(cm) {
if (cm.state.sublimeMark) cm.state.sublimeMark.clear();
cm.state.sublimeMark = cm.setBookmark(cm.getCursor());
};
cmds[map[cK + ctrl + "A"] = "selectToSublimeMark"] = function(cm) {
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
if (found) cm.setSelection(cm.getCursor(), found);
};
cmds[map[cK + ctrl + "W"] = "deleteToSublimeMark"] = function(cm) {
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
if (found) {
var from = cm.getCursor(), to = found;
if (CodeMirror.cmpPos(from, to) > 0) { var tmp = to; to = from; from = tmp; }
cm.state.sublimeKilled = cm.getRange(from, to);
cm.replaceRange("", from, to);
}
};
cmds[map[cK + ctrl + "X"] = "swapWithSublimeMark"] = function(cm) {
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
if (found) {
cm.state.sublimeMark.clear();
cm.state.sublimeMark = cm.setBookmark(cm.getCursor());
cm.setCursor(found);
}
};
cmds[map[cK + ctrl + "Y"] = "sublimeYank"] = function(cm) {
if (cm.state.sublimeKilled != null)
cm.replaceSelection(cm.state.sublimeKilled, null, "paste");
};
map[cK + ctrl + "G"] = "clearBookmarks";
cmds[map[cK + ctrl + "C"] = "showInCenter"] = function(cm) {
var pos = cm.cursorCoords(null, "local");
cm.scrollTo(null, (pos.top + pos.bottom) / 2 - cm.getScrollInfo().clientHeight / 2);
};
cmds[map["Shift-Alt-Up"] = "selectLinesUpward"] = function(cm) {
cm.operation(function() {
var ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (range.head.line > cm.firstLine())
cm.addSelection(Pos(range.head.line - 1, range.head.ch));
}
});
};
cmds[map["Shift-Alt-Down"] = "selectLinesDownward"] = function(cm) {
cm.operation(function() {
var ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (range.head.line < cm.lastLine())
cm.addSelection(Pos(range.head.line + 1, range.head.ch));
}
});
};
function getTarget(cm) {
var from = cm.getCursor("from"), to = cm.getCursor("to");
if (CodeMirror.cmpPos(from, to) == 0) {
var word = wordAt(cm, from);
if (!word.word) return;
from = word.from;
to = word.to;
}
return {from: from, to: to, query: cm.getRange(from, to), word: word};
}
function findAndGoTo(cm, forward) {
var target = getTarget(cm);
if (!target) return;
var query = target.query;
var cur = cm.getSearchCursor(query, forward ? target.to : target.from);
if (forward ? cur.findNext() : cur.findPrevious()) {
cm.setSelection(cur.from(), cur.to());
} else {
cur = cm.getSearchCursor(query, forward ? Pos(cm.firstLine(), 0)
: cm.clipPos(Pos(cm.lastLine())));
if (forward ? cur.findNext() : cur.findPrevious())
cm.setSelection(cur.from(), cur.to());
else if (target.word)
cm.setSelection(target.from, target.to);
}
};
cmds[map[ctrl + "F3"] = "findUnder"] = function(cm) { findAndGoTo(cm, true); };
cmds[map["Shift-" + ctrl + "F3"] = "findUnderPrevious"] = function(cm) { findAndGoTo(cm,false); };
cmds[map["Alt-F3"] = "findAllUnder"] = function(cm) {
var target = getTarget(cm);
if (!target) return;
var cur = cm.getSearchCursor(target.query);
var matches = [];
var primaryIndex = -1;
while (cur.findNext()) {
matches.push({anchor: cur.from(), head: cur.to()});
if (cur.from().line <= target.from.line && cur.from().ch <= target.from.ch)
primaryIndex++;
}
cm.setSelections(matches, primaryIndex);
};
map["Shift-" + ctrl + "["] = "fold";
map["Shift-" + ctrl + "]"] = "unfold";
map[cK + ctrl + "0"] = map[cK + ctrl + "j"] = "unfoldAll";
map[ctrl + "I"] = "findIncremental";
map["Shift-" + ctrl + "I"] = "findIncrementalReverse";
map[ctrl + "H"] = "replace";
map["F3"] = "findNext";
map["Shift-F3"] = "findPrev";
CodeMirror.normalizeKeyMap(map);
});
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
/**
* Supported keybindings:
* Too many to list. Refer to defaultKeyMap below.
*
* Supported Ex commands:
* Refer to defaultExCommandMap below.
*
* Registers: unnamed, -, a-z, A-Z, 0-9
* (Does not respect the special case for number registers when delete
* operator is made with these commands: %, (, ), , /, ?, n, N, {, } )
* TODO: Implement the remaining registers.
*
* Marks: a-z, A-Z, and 0-9
* TODO: Implement the remaining special marks. They have more complex
* behavior.
*
* Events:
* 'vim-mode-change' - raised on the editor anytime the current mode changes,
* Event object: {mode: "visual", subMode: "linewise"}
*
* Code structure:
* 1. Default keymap
* 2. Variable declarations and short basic helpers
* 3. Instance (External API) implementation
* 4. Internal state tracking objects (input state, counter) implementation
* and instantiation
* 5. Key handler (the main command dispatcher) implementation
* 6. Motion, operator, and action implementations
* 7. Helper functions for the key handler, motions, operators, and actions
* 8. Set up Vim to work as a keymap for CodeMirror.
* 9. Ex command implementations.
*/
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../lib/codemirror"), require("../addon/search/searchcursor"), require("../addon/dialog/dialog"), require("../addon/edit/matchbrackets.js"));
else if (typeof define == "function" && define.amd) // AMD
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/dialog/dialog", "../addon/edit/matchbrackets"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
'use strict';
var defaultKeymap = [
// Key to key mapping. This goes first to make it possible to override
// existing mappings.
{ keys: '<Left>', type: 'keyToKey', toKeys: 'h' },
{ keys: '<Right>', type: 'keyToKey', toKeys: 'l' },
{ keys: '<Up>', type: 'keyToKey', toKeys: 'k' },
{ keys: '<Down>', type: 'keyToKey', toKeys: 'j' },
{ keys: '<Space>', type: 'keyToKey', toKeys: 'l' },
{ keys: '<BS>', type: 'keyToKey', toKeys: 'h', context: 'normal'},
{ keys: '<C-Space>', type: 'keyToKey', toKeys: 'W' },
{ keys: '<C-BS>', type: 'keyToKey', toKeys: 'B', context: 'normal' },
{ keys: '<S-Space>', type: 'keyToKey', toKeys: 'w' },
{ keys: '<S-BS>', type: 'keyToKey', toKeys: 'b', context: 'normal' },
{ keys: '<C-n>', type: 'keyToKey', toKeys: 'j' },
{ keys: '<C-p>', type: 'keyToKey', toKeys: 'k' },
{ keys: '<C-[>', type: 'keyToKey', toKeys: '<Esc>' },
{ keys: '<C-c>', type: 'keyToKey', toKeys: '<Esc>' },
{ keys: '<C-[>', type: 'keyToKey', toKeys: '<Esc>', context: 'insert' },
{ keys: '<C-c>', type: 'keyToKey', toKeys: '<Esc>', context: 'insert' },
{ keys: 's', type: 'keyToKey', toKeys: 'cl', context: 'normal' },
{ keys: 's', type: 'keyToKey', toKeys: 'c', context: 'visual'},
{ keys: 'S', type: 'keyToKey', toKeys: 'cc', context: 'normal' },
{ keys: 'S', type: 'keyToKey', toKeys: 'VdO', context: 'visual' },
{ keys: '<Home>', type: 'keyToKey', toKeys: '0' },
{ keys: '<End>', type: 'keyToKey', toKeys: '$' },
{ keys: '<PageUp>', type: 'keyToKey', toKeys: '<C-b>' },
{ keys: '<PageDown>', type: 'keyToKey', toKeys: '<C-f>' },
{ keys: '<CR>', type: 'keyToKey', toKeys: 'j^', context: 'normal' },
{ keys: '<Ins>', type: 'action', action: 'toggleOverwrite', context: 'insert' },
// Motions
{ keys: 'H', type: 'motion', motion: 'moveToTopLine', motionArgs: { linewise: true, toJumplist: true }},
{ keys: 'M', type: 'motion', motion: 'moveToMiddleLine', motionArgs: { linewise: true, toJumplist: true }},
{ keys: 'L', type: 'motion', motion: 'moveToBottomLine', motionArgs: { linewise: true, toJumplist: true }},
{ keys: 'h', type: 'motion', motion: 'moveByCharacters', motionArgs: { forward: false }},
{ keys: 'l', type: 'motion', motion: 'moveByCharacters', motionArgs: { forward: true }},
{ keys: 'j', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, linewise: true }},
{ keys: 'k', type: 'motion', motion: 'moveByLines', motionArgs: { forward: false, linewise: true }},
{ keys: 'gj', type: 'motion', motion: 'moveByDisplayLines', motionArgs: { forward: true }},
{ keys: 'gk', type: 'motion', motion: 'moveByDisplayLines', motionArgs: { forward: false }},
{ keys: 'w', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: false }},
{ keys: 'W', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: false, bigWord: true }},
{ keys: 'e', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: true, inclusive: true }},
{ keys: 'E', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: true, bigWord: true, inclusive: true }},
{ keys: 'b', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false }},
{ keys: 'B', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false, bigWord: true }},
{ keys: 'ge', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: true, inclusive: true }},
{ keys: 'gE', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: true, bigWord: true, inclusive: true }},
{ keys: '{', type: 'motion', motion: 'moveByParagraph', motionArgs: { forward: false, toJumplist: true }},
{ keys: '}', type: 'motion', motion: 'moveByParagraph', motionArgs: { forward: true, toJumplist: true }},
{ keys: '<C-f>', type: 'motion', motion: 'moveByPage', motionArgs: { forward: true }},
{ keys: '<C-b>', type: 'motion', motion: 'moveByPage', motionArgs: { forward: false }},
{ keys: '<C-d>', type: 'motion', motion: 'moveByScroll', motionArgs: { forward: true, explicitRepeat: true }},
{ keys: '<C-u>', type: 'motion', motion: 'moveByScroll', motionArgs: { forward: false, explicitRepeat: true }},
{ keys: 'gg', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: false, explicitRepeat: true, linewise: true, toJumplist: true }},
{ keys: 'G', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: true, explicitRepeat: true, linewise: true, toJumplist: true }},
{ keys: '0', type: 'motion', motion: 'moveToStartOfLine' },
{ keys: '^', type: 'motion', motion: 'moveToFirstNonWhiteSpaceCharacter' },
{ keys: '+', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, toFirstChar:true }},
{ keys: '-', type: 'motion', motion: 'moveByLines', motionArgs: { forward: false, toFirstChar:true }},
{ keys: '_', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, toFirstChar:true, repeatOffset:-1 }},
{ keys: '$', type: 'motion', motion: 'moveToEol', motionArgs: { inclusive: true }},
{ keys: '%', type: 'motion', motion: 'moveToMatchedSymbol', motionArgs: { inclusive: true, toJumplist: true }},
{ keys: 'f<character>', type: 'motion', motion: 'moveToCharacter', motionArgs: { forward: true , inclusive: true }},
{ keys: 'F<character>', type: 'motion', motion: 'moveToCharacter', motionArgs: { forward: false }},
{ keys: 't<character>', type: 'motion', motion: 'moveTillCharacter', motionArgs: { forward: true, inclusive: true }},
{ keys: 'T<character>', type: 'motion', motion: 'moveTillCharacter', motionArgs: { forward: false }},
{ keys: ';', type: 'motion', motion: 'repeatLastCharacterSearch', motionArgs: { forward: true }},
{ keys: ',', type: 'motion', motion: 'repeatLastCharacterSearch', motionArgs: { forward: false }},
{ keys: '\'<character>', type: 'motion', motion: 'goToMark', motionArgs: {toJumplist: true, linewise: true}},
{ keys: '`<character>', type: 'motion', motion: 'goToMark', motionArgs: {toJumplist: true}},
{ keys: ']`', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true } },
{ keys: '[`', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false } },
{ keys: ']\'', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true, linewise: true } },
{ keys: '[\'', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false, linewise: true } },
// the next two aren't motions but must come before more general motion declarations
{ keys: ']p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: true, isEdit: true, matchIndent: true}},
{ keys: '[p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: false, isEdit: true, matchIndent: true}},
{ keys: ']<character>', type: 'motion', motion: 'moveToSymbol', motionArgs: { forward: true, toJumplist: true}},
{ keys: '[<character>', type: 'motion', motion: 'moveToSymbol', motionArgs: { forward: false, toJumplist: true}},
{ keys: '|', type: 'motion', motion: 'moveToColumn'},
{ keys: 'o', type: 'motion', motion: 'moveToOtherHighlightedEnd', context:'visual'},
{ keys: 'O', type: 'motion', motion: 'moveToOtherHighlightedEnd', motionArgs: {sameLine: true}, context:'visual'},
// Operators
{ keys: 'd', type: 'operator', operator: 'delete' },
{ keys: 'y', type: 'operator', operator: 'yank' },
{ keys: 'c', type: 'operator', operator: 'change' },
{ keys: '>', type: 'operator', operator: 'indent', operatorArgs: { indentRight: true }},
{ keys: '<', type: 'operator', operator: 'indent', operatorArgs: { indentRight: false }},
{ keys: 'g~', type: 'operator', operator: 'changeCase' },
{ keys: 'gu', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: true}, isEdit: true },
{ keys: 'gU', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: false}, isEdit: true },
{ keys: 'n', type: 'motion', motion: 'findNext', motionArgs: { forward: true, toJumplist: true }},
{ keys: 'N', type: 'motion', motion: 'findNext', motionArgs: { forward: false, toJumplist: true }},
// Operator-Motion dual commands
{ keys: 'x', type: 'operatorMotion', operator: 'delete', motion: 'moveByCharacters', motionArgs: { forward: true }, operatorMotionArgs: { visualLine: false }},
{ keys: 'X', type: 'operatorMotion', operator: 'delete', motion: 'moveByCharacters', motionArgs: { forward: false }, operatorMotionArgs: { visualLine: true }},
{ keys: 'D', type: 'operatorMotion', operator: 'delete', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal'},
{ keys: 'D', type: 'operator', operator: 'delete', operatorArgs: { linewise: true }, context: 'visual'},
{ keys: 'Y', type: 'operatorMotion', operator: 'yank', motion: 'expandToLine', motionArgs: { linewise: true }, context: 'normal'},
{ keys: 'Y', type: 'operator', operator: 'yank', operatorArgs: { linewise: true }, context: 'visual'},
{ keys: 'C', type: 'operatorMotion', operator: 'change', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal'},
{ keys: 'C', type: 'operator', operator: 'change', operatorArgs: { linewise: true }, context: 'visual'},
{ keys: '~', type: 'operatorMotion', operator: 'changeCase', motion: 'moveByCharacters', motionArgs: { forward: true }, operatorArgs: { shouldMoveCursor: true }, context: 'normal'},
{ keys: '~', type: 'operator', operator: 'changeCase', context: 'visual'},
{ keys: '<C-w>', type: 'operatorMotion', operator: 'delete', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false }, context: 'insert' },
// Actions
{ keys: '<C-i>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: true }},
{ keys: '<C-o>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: false }},
{ keys: '<C-e>', type: 'action', action: 'scroll', actionArgs: { forward: true, linewise: true }},
{ keys: '<C-y>', type: 'action', action: 'scroll', actionArgs: { forward: false, linewise: true }},
{ keys: 'a', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'charAfter' }, context: 'normal' },
{ keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'eol' }, context: 'normal' },
{ keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'endOfSelectedArea' }, context: 'visual' },
{ keys: 'i', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'inplace' }, context: 'normal' },
{ keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'firstNonBlank'}, context: 'normal' },
{ keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'startOfSelectedArea' }, context: 'visual' },
{ keys: 'o', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: true }, context: 'normal' },
{ keys: 'O', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: false }, context: 'normal' },
{ keys: 'v', type: 'action', action: 'toggleVisualMode' },
{ keys: 'V', type: 'action', action: 'toggleVisualMode', actionArgs: { linewise: true }},
{ keys: '<C-v>', type: 'action', action: 'toggleVisualMode', actionArgs: { blockwise: true }},
{ keys: '<C-q>', type: 'action', action: 'toggleVisualMode', actionArgs: { blockwise: true }},
{ keys: 'gv', type: 'action', action: 'reselectLastSelection' },
{ keys: 'J', type: 'action', action: 'joinLines', isEdit: true },
{ keys: 'p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: true, isEdit: true }},
{ keys: 'P', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: false, isEdit: true }},
{ keys: 'r<character>', type: 'action', action: 'replace', isEdit: true },
{ keys: '@<character>', type: 'action', action: 'replayMacro' },
{ keys: 'q<character>', type: 'action', action: 'enterMacroRecordMode' },
// Handle Replace-mode as a special case of insert mode.
{ keys: 'R', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { replace: true }},
{ keys: 'u', type: 'action', action: 'undo', context: 'normal' },
{ keys: 'u', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: true}, context: 'visual', isEdit: true },
{ keys: 'U', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: false}, context: 'visual', isEdit: true },
{ keys: '<C-r>', type: 'action', action: 'redo' },
{ keys: 'm<character>', type: 'action', action: 'setMark' },
{ keys: '"<character>', type: 'action', action: 'setRegister' },
{ keys: 'zz', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' }},
{ keys: 'z.', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' }, motion: 'moveToFirstNonWhiteSpaceCharacter' },
{ keys: 'zt', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'top' }},
{ keys: 'z<CR>', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'top' }, motion: 'moveToFirstNonWhiteSpaceCharacter' },
{ keys: 'z-', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'bottom' }},
{ keys: 'zb', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'bottom' }, motion: 'moveToFirstNonWhiteSpaceCharacter' },
{ keys: '.', type: 'action', action: 'repeatLastEdit' },
{ keys: '<C-a>', type: 'action', action: 'incrementNumberToken', isEdit: true, actionArgs: {increase: true, backtrack: false}},
{ keys: '<C-x>', type: 'action', action: 'incrementNumberToken', isEdit: true, actionArgs: {increase: false, backtrack: false}},
{ keys: '<C-t>', type: 'action', action: 'indent', actionArgs: { indentRight: true }, context: 'insert' },
{ keys: '<C-d>', type: 'action', action: 'indent', actionArgs: { indentRight: false }, context: 'insert' },
// Text object motions
{ keys: 'a<character>', type: 'motion', motion: 'textObjectManipulation' },
{ keys: 'i<character>', type: 'motion', motion: 'textObjectManipulation', motionArgs: { textObjectInner: true }},
// Search
{ keys: '/', type: 'search', searchArgs: { forward: true, querySrc: 'prompt', toJumplist: true }},
{ keys: '?', type: 'search', searchArgs: { forward: false, querySrc: 'prompt', toJumplist: true }},
{ keys: '*', type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
{ keys: '#', type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
{ keys: 'g*', type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', toJumplist: true }},
{ keys: 'g#', type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', toJumplist: true }},
// Ex command
{ keys: ':', type: 'ex' }
];
/**
* Ex commands
* Care must be taken when adding to the default Ex command map. For any
* pair of commands that have a shared prefix, at least one of their
* shortNames must not match the prefix of the other command.
*/
var defaultExCommandMap = [
{ name: 'colorscheme', shortName: 'colo' },
{ name: 'map' },
{ name: 'imap', shortName: 'im' },
{ name: 'nmap', shortName: 'nm' },
{ name: 'vmap', shortName: 'vm' },
{ name: 'unmap' },
{ name: 'write', shortName: 'w' },
{ name: 'undo', shortName: 'u' },
{ name: 'redo', shortName: 'red' },
{ name: 'set', shortName: 'se' },
{ name: 'set', shortName: 'se' },
{ name: 'setlocal', shortName: 'setl' },
{ name: 'setglobal', shortName: 'setg' },
{ name: 'sort', shortName: 'sor' },
{ name: 'substitute', shortName: 's', possiblyAsync: true },
{ name: 'nohlsearch', shortName: 'noh' },
{ name: 'yank', shortName: 'y' },
{ name: 'delmarks', shortName: 'delm' },
{ name: 'registers', shortName: 'reg', excludeFromCommandHistory: true },
{ name: 'global', shortName: 'g' }
];
var Pos = CodeMirror.Pos;
var Vim = function() {
function enterVimMode(cm) {
cm.setOption('disableInput', true);
cm.setOption('showCursorWhenSelecting', false);
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
cm.on('cursorActivity', onCursorActivity);
maybeInitVimState(cm);
CodeMirror.on(cm.getInputField(), 'paste', getOnPasteFn(cm));
}
function leaveVimMode(cm) {
cm.setOption('disableInput', false);
cm.off('cursorActivity', onCursorActivity);
CodeMirror.off(cm.getInputField(), 'paste', getOnPasteFn(cm));
cm.state.vim = null;
}
function detachVimMap(cm, next) {
if (this == CodeMirror.keyMap.vim)
CodeMirror.rmClass(cm.getWrapperElement(), "cm-fat-cursor");
if (!next || next.attach != attachVimMap)
leaveVimMode(cm, false);
}
function attachVimMap(cm, prev) {
if (this == CodeMirror.keyMap.vim)
CodeMirror.addClass(cm.getWrapperElement(), "cm-fat-cursor");
if (!prev || prev.attach != attachVimMap)
enterVimMode(cm);
}
// Deprecated, simply setting the keymap works again.
CodeMirror.defineOption('vimMode', false, function(cm, val, prev) {
if (val && cm.getOption("keyMap") != "vim")
cm.setOption("keyMap", "vim");
else if (!val && prev != CodeMirror.Init && /^vim/.test(cm.getOption("keyMap")))
cm.setOption("keyMap", "default");
});
function cmKey(key, cm) {
if (!cm) { return undefined; }
if (this[key]) { return this[key]; }
var vimKey = cmKeyToVimKey(key);
if (!vimKey) {
return false;
}
var cmd = CodeMirror.Vim.findKey(cm, vimKey);
if (typeof cmd == 'function') {
CodeMirror.signal(cm, 'vim-keypress', vimKey);
}
return cmd;
}
var modifiers = {'Shift': 'S', 'Ctrl': 'C', 'Alt': 'A', 'Cmd': 'D', 'Mod': 'A'};
var specialKeys = {Enter:'CR',Backspace:'BS',Delete:'Del',Insert:'Ins'};
function cmKeyToVimKey(key) {
if (key.charAt(0) == '\'') {
// Keypress character binding of format "'a'"
return key.charAt(1);
}
var pieces = key.split(/-(?!$)/);
var lastPiece = pieces[pieces.length - 1];
if (pieces.length == 1 && pieces[0].length == 1) {
// No-modifier bindings use literal character bindings above. Skip.
return false;
} else if (pieces.length == 2 && pieces[0] == 'Shift' && lastPiece.length == 1) {
// Ignore Shift+char bindings as they should be handled by literal character.
return false;
}
var hasCharacter = false;
for (var i = 0; i < pieces.length; i++) {
var piece = pieces[i];
if (piece in modifiers) { pieces[i] = modifiers[piece]; }
else { hasCharacter = true; }
if (piece in specialKeys) { pieces[i] = specialKeys[piece]; }
}
if (!hasCharacter) {
// Vim does not support modifier only keys.
return false;
}
// TODO: Current bindings expect the character to be lower case, but
// it looks like vim key notation uses upper case.
if (isUpperCase(lastPiece)) {
pieces[pieces.length - 1] = lastPiece.toLowerCase();
}
return '<' + pieces.join('-') + '>';
}
function getOnPasteFn(cm) {
var vim = cm.state.vim;
if (!vim.onPasteFn) {
vim.onPasteFn = function() {
if (!vim.insertMode) {
cm.setCursor(offsetCursor(cm.getCursor(), 0, 1));
actions.enterInsertMode(cm, {}, vim);
}
};
}
return vim.onPasteFn;
}
var numberRegex = /[\d]/;
var wordCharTest = [CodeMirror.isWordChar, function(ch) {
return ch && !CodeMirror.isWordChar(ch) && !/\s/.test(ch);
}], bigWordCharTest = [function(ch) {
return /\S/.test(ch);
}];
function makeKeyRange(start, size) {
var keys = [];
for (var i = start; i < start + size; i++) {
keys.push(String.fromCharCode(i));
}
return keys;
}
var upperCaseAlphabet = makeKeyRange(65, 26);
var lowerCaseAlphabet = makeKeyRange(97, 26);
var numbers = makeKeyRange(48, 10);
var validMarks = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['<', '>']);
var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"', '.', ':', '/']);
function isLine(cm, line) {
return line >= cm.firstLine() && line <= cm.lastLine();
}
function isLowerCase(k) {
return (/^[a-z]$/).test(k);
}
function isMatchableSymbol(k) {
return '()[]{}'.indexOf(k) != -1;
}
function isNumber(k) {
return numberRegex.test(k);
}
function isUpperCase(k) {
return (/^[A-Z]$/).test(k);
}
function isWhiteSpaceString(k) {
return (/^\s*$/).test(k);
}
function inArray(val, arr) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == val) {
return true;
}
}
return false;
}
var options = {};
function defineOption(name, defaultValue, type, aliases, callback) {
if (defaultValue === undefined && !callback) {
throw Error('defaultValue is required unless callback is provided');
}
if (!type) { type = 'string'; }
options[name] = {
type: type,
defaultValue: defaultValue,
callback: callback
};
if (aliases) {
for (var i = 0; i < aliases.length; i++) {
options[aliases[i]] = options[name];
}
}
if (defaultValue) {
setOption(name, defaultValue);
}
}
function setOption(name, value, cm, cfg) {
var option = options[name];
cfg = cfg || {};
var scope = cfg.scope;
if (!option) {
throw Error('Unknown option: ' + name);
}
if (option.type == 'boolean') {
if (value && value !== true) {
throw Error('Invalid argument: ' + name + '=' + value);
} else if (value !== false) {
// Boolean options are set to true if value is not defined.
value = true;
}
}
if (option.callback) {
if (scope !== 'local') {
option.callback(value, undefined);
}
if (scope !== 'global' && cm) {
option.callback(value, cm);
}
} else {
if (scope !== 'local') {
option.value = option.type == 'boolean' ? !!value : value;
}
if (scope !== 'global' && cm) {
cm.state.vim.options[name] = {value: value};
}
}
}
function getOption(name, cm, cfg) {
var option = options[name];
cfg = cfg || {};
var scope = cfg.scope;
if (!option) {
throw Error('Unknown option: ' + name);
}
if (option.callback) {
var local = cm && option.callback(undefined, cm);
if (scope !== 'global' && local !== undefined) {
return local;
}
if (scope !== 'local') {
return option.callback();
}
return;
} else {
var local = (scope !== 'global') && (cm && cm.state.vim.options[name]);
return (local || (scope !== 'local') && option || {}).value;
}
}
defineOption('filetype', undefined, 'string', ['ft'], function(name, cm) {
// Option is local. Do nothing for global.
if (cm === undefined) {
return;
}
// The 'filetype' option proxies to the CodeMirror 'mode' option.
if (name === undefined) {
var mode = cm.getOption('mode');
return mode == 'null' ? '' : mode;
} else {
var mode = name == '' ? 'null' : name;
cm.setOption('mode', mode);
}
});
var createCircularJumpList = function() {
var size = 100;
var pointer = -1;
var head = 0;
var tail = 0;
var buffer = new Array(size);
function add(cm, oldCur, newCur) {
var current = pointer % size;
var curMark = buffer[current];
function useNextSlot(cursor) {
var next = ++pointer % size;
var trashMark = buffer[next];
if (trashMark) {
trashMark.clear();
}
buffer[next] = cm.setBookmark(cursor);
}
if (curMark) {
var markPos = curMark.find();
// avoid recording redundant cursor position
if (markPos && !cursorEqual(markPos, oldCur)) {
useNextSlot(oldCur);
}
} else {
useNextSlot(oldCur);
}
useNextSlot(newCur);
head = pointer;
tail = pointer - size + 1;
if (tail < 0) {
tail = 0;
}
}
function move(cm, offset) {
pointer += offset;
if (pointer > head) {
pointer = head;
} else if (pointer < tail) {
pointer = tail;
}
var mark = buffer[(size + pointer) % size];
// skip marks that are temporarily removed from text buffer
if (mark && !mark.find()) {
var inc = offset > 0 ? 1 : -1;
var newCur;
var oldCur = cm.getCursor();
do {
pointer += inc;
mark = buffer[(size + pointer) % size];
// skip marks that are the same as current position
if (mark &&
(newCur = mark.find()) &&
!cursorEqual(oldCur, newCur)) {
break;
}
} while (pointer < head && pointer > tail);
}
return mark;
}
return {
cachedCursor: undefined, //used for # and * jumps
add: add,
move: move
};
};
// Returns an object to track the changes associated insert mode. It
// clones the object that is passed in, or creates an empty object one if
// none is provided.
var createInsertModeChanges = function(c) {
if (c) {
// Copy construction
return {
changes: c.changes,
expectCursorActivityForChange: c.expectCursorActivityForChange
};
}
return {
// Change list
changes: [],
// Set to true on change, false on cursorActivity.
expectCursorActivityForChange: false
};
};
function MacroModeState() {
this.latestRegister = undefined;
this.isPlaying = false;
this.isRecording = false;
this.replaySearchQueries = [];
this.onRecordingDone = undefined;
this.lastInsertModeChanges = createInsertModeChanges();
}
MacroModeState.prototype = {
exitMacroRecordMode: function() {
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.onRecordingDone) {
macroModeState.onRecordingDone(); // close dialog
}
macroModeState.onRecordingDone = undefined;
macroModeState.isRecording = false;
},
enterMacroRecordMode: function(cm, registerName) {
var register =
vimGlobalState.registerController.getRegister(registerName);
if (register) {
register.clear();
this.latestRegister = registerName;
if (cm.openDialog) {
this.onRecordingDone = cm.openDialog(
'(recording)['+registerName+']', null, {bottom:true});
}
this.isRecording = true;
}
}
};
function maybeInitVimState(cm) {
if (!cm.state.vim) {
// Store instance state in the CodeMirror object.
cm.state.vim = {
inputState: new InputState(),
// Vim's input state that triggered the last edit, used to repeat
// motions and operators with '.'.
lastEditInputState: undefined,
// Vim's action command before the last edit, used to repeat actions
// with '.' and insert mode repeat.
lastEditActionCommand: undefined,
// When using jk for navigation, if you move from a longer line to a
// shorter line, the cursor may clip to the end of the shorter line.
// If j is pressed again and cursor goes to the next line, the
// cursor should go back to its horizontal position on the longer
// line if it can. This is to keep track of the horizontal position.
lastHPos: -1,
// Doing the same with screen-position for gj/gk
lastHSPos: -1,
// The last motion command run. Cleared if a non-motion command gets
// executed in between.
lastMotion: null,
marks: {},
// Mark for rendering fake cursor for visual mode.
fakeCursor: null,
insertMode: false,
// Repeat count for changes made in insert mode, triggered by key
// sequences like 3,i. Only exists when insertMode is true.
insertModeRepeat: undefined,
visualMode: false,
// If we are in visual line mode. No effect if visualMode is false.
visualLine: false,
visualBlock: false,
lastSelection: null,
lastPastedText: null,
sel: {},
// Buffer-local/window-local values of vim options.
options: {}
};
}
return cm.state.vim;
}
var vimGlobalState;
function resetVimGlobalState() {
vimGlobalState = {
// The current search query.
searchQuery: null,
// Whether we are searching backwards.
searchIsReversed: false,
// Replace part of the last substituted pattern
lastSubstituteReplacePart: undefined,
jumpList: createCircularJumpList(),
macroModeState: new MacroModeState,
// Recording latest f, t, F or T motion command.
lastCharacterSearch: {increment:0, forward:true, selectedCharacter:''},
registerController: new RegisterController({}),
// search history buffer
searchHistoryController: new HistoryController({}),
// ex Command history buffer
exCommandHistoryController : new HistoryController({})
};
for (var optionName in options) {
var option = options[optionName];
option.value = option.defaultValue;
}
}
var lastInsertModeKeyTimer;
var vimApi= {
buildKeyMap: function() {
// TODO: Convert keymap into dictionary format for fast lookup.
},
// Testing hook, though it might be useful to expose the register
// controller anyways.
getRegisterController: function() {
return vimGlobalState.registerController;
},
// Testing hook.
resetVimGlobalState_: resetVimGlobalState,
// Testing hook.
getVimGlobalState_: function() {
return vimGlobalState;
},
// Testing hook.
maybeInitVimState_: maybeInitVimState,
suppressErrorLogging: false,
InsertModeKey: InsertModeKey,
map: function(lhs, rhs, ctx) {
// Add user defined key bindings.
exCommandDispatcher.map(lhs, rhs, ctx);
},
unmap: function(lhs, ctx) {
exCommandDispatcher.unmap(lhs, ctx);
},
// TODO: Expose setOption and getOption as instance methods. Need to decide how to namespace
// them, or somehow make them work with the existing CodeMirror setOption/getOption API.
setOption: setOption,
getOption: getOption,
defineOption: defineOption,
defineEx: function(name, prefix, func){
if (!prefix) {
prefix = name;
} else if (name.indexOf(prefix) !== 0) {
throw new Error('(Vim.defineEx) "'+prefix+'" is not a prefix of "'+name+'", command not registered');
}
exCommands[name]=func;
exCommandDispatcher.commandMap_[prefix]={name:name, shortName:prefix, type:'api'};
},
handleKey: function (cm, key, origin) {
var command = this.findKey(cm, key, origin);
if (typeof command === 'function') {
return command();
}
},
/**
* This is the outermost function called by CodeMirror, after keys have
* been mapped to their Vim equivalents.
*
* Finds a command based on the key (and cached keys if there is a
* multi-key sequence). Returns `undefined` if no key is matched, a noop
* function if a partial match is found (multi-key), and a function to
* execute the bound command if a a key is matched. The function always
* returns true.
*/
findKey: function(cm, key, origin) {
var vim = maybeInitVimState(cm);
function handleMacroRecording() {
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isRecording) {
if (key == 'q') {
macroModeState.exitMacroRecordMode();
clearInputState(cm);
return true;
}
if (origin != 'mapping') {
logKey(macroModeState, key);
}
}
}
function handleEsc() {
if (key == '<Esc>') {
// Clear input state and get back to normal mode.
clearInputState(cm);
if (vim.visualMode) {
exitVisualMode(cm);
} else if (vim.insertMode) {
exitInsertMode(cm);
}
return true;
}
}
function doKeyToKey(keys) {
// TODO: prevent infinite recursion.
var match;
while (keys) {
// Pull off one command key, which is either a single character
// or a special sequence wrapped in '<' and '>', e.g. '<Space>'.
match = (/<\w+-.+?>|<\w+>|./).exec(keys);
key = match[0];
keys = keys.substring(match.index + key.length);
CodeMirror.Vim.handleKey(cm, key, 'mapping');
}
}
function handleKeyInsertMode() {
if (handleEsc()) { return true; }
var keys = vim.inputState.keyBuffer = vim.inputState.keyBuffer + key;
var keysAreChars = key.length == 1;
var match = commandDispatcher.matchCommand(keys, defaultKeymap, vim.inputState, 'insert');
// Need to check all key substrings in insert mode.
while (keys.length > 1 && match.type != 'full') {
var keys = vim.inputState.keyBuffer = keys.slice(1);
var thisMatch = commandDispatcher.matchCommand(keys, defaultKeymap, vim.inputState, 'insert');
if (thisMatch.type != 'none') { match = thisMatch; }
}
if (match.type == 'none') { clearInputState(cm); return false; }
else if (match.type == 'partial') {
if (lastInsertModeKeyTimer) { window.clearTimeout(lastInsertModeKeyTimer); }
lastInsertModeKeyTimer = window.setTimeout(
function() { if (vim.insertMode && vim.inputState.keyBuffer) { clearInputState(cm); } },
getOption('insertModeEscKeysTimeout'));
return !keysAreChars;
}
if (lastInsertModeKeyTimer) { window.clearTimeout(lastInsertModeKeyTimer); }
if (keysAreChars) {
var selections = cm.listSelections();
for (var i = 0; i < selections.length; i++) {
var here = selections[i].head;
cm.replaceRange('', offsetCursor(here, 0, -(keys.length - 1)), here, '+input');
}
vimGlobalState.macroModeState.lastInsertModeChanges.changes.pop();
}
clearInputState(cm);
return match.command;
}
function handleKeyNonInsertMode() {
if (handleMacroRecording() || handleEsc()) { return true; };
var keys = vim.inputState.keyBuffer = vim.inputState.keyBuffer + key;
if (/^[1-9]\d*$/.test(keys)) { return true; }
var keysMatcher = /^(\d*)(.*)$/.exec(keys);
if (!keysMatcher) { clearInputState(cm); return false; }
var context = vim.visualMode ? 'visual' :
'normal';
var match = commandDispatcher.matchCommand(keysMatcher[2] || keysMatcher[1], defaultKeymap, vim.inputState, context);
if (match.type == 'none') { clearInputState(cm); return false; }
else if (match.type == 'partial') { return true; }
vim.inputState.keyBuffer = '';
var keysMatcher = /^(\d*)(.*)$/.exec(keys);
if (keysMatcher[1] && keysMatcher[1] != '0') {
vim.inputState.pushRepeatDigit(keysMatcher[1]);
}
return match.command;
}
var command;
if (vim.insertMode) { command = handleKeyInsertMode(); }
else { command = handleKeyNonInsertMode(); }
if (command === false) {
return undefined;
} else if (command === true) {
// TODO: Look into using CodeMirror's multi-key handling.
// Return no-op since we are caching the key. Counts as handled, but
// don't want act on it just yet.
return function() { return true; };
} else {
return function() {
return cm.operation(function() {
cm.curOp.isVimOp = true;
try {
if (command.type == 'keyToKey') {
doKeyToKey(command.toKeys);
} else {
commandDispatcher.processCommand(cm, vim, command);
}
} catch (e) {
// clear VIM state in case it's in a bad state.
cm.state.vim = undefined;
maybeInitVimState(cm);
if (!CodeMirror.Vim.suppressErrorLogging) {
console['log'](e);
}
throw e;
}
return true;
});
};
}
},
handleEx: function(cm, input) {
exCommandDispatcher.processCommand(cm, input);
},
defineMotion: defineMotion,
defineAction: defineAction,
defineOperator: defineOperator,
mapCommand: mapCommand,
_mapCommand: _mapCommand,
defineRegister: defineRegister,
exitVisualMode: exitVisualMode,
exitInsertMode: exitInsertMode
};
// Represents the current input state.
function InputState() {
this.prefixRepeat = [];
this.motionRepeat = [];
this.operator = null;
this.operatorArgs = null;
this.motion = null;
this.motionArgs = null;
this.keyBuffer = []; // For matching multi-key commands.
this.registerName = null; // Defaults to the unnamed register.
}
InputState.prototype.pushRepeatDigit = function(n) {
if (!this.operator) {
this.prefixRepeat = this.prefixRepeat.concat(n);
} else {
this.motionRepeat = this.motionRepeat.concat(n);
}
};
InputState.prototype.getRepeat = function() {
var repeat = 0;
if (this.prefixRepeat.length > 0 || this.motionRepeat.length > 0) {
repeat = 1;
if (this.prefixRepeat.length > 0) {
repeat *= parseInt(this.prefixRepeat.join(''), 10);
}
if (this.motionRepeat.length > 0) {
repeat *= parseInt(this.motionRepeat.join(''), 10);
}
}
return repeat;
};
function clearInputState(cm, reason) {
cm.state.vim.inputState = new InputState();
CodeMirror.signal(cm, 'vim-command-done', reason);
}
/*
* Register stores information about copy and paste registers. Besides
* text, a register must store whether it is linewise (i.e., when it is
* pasted, should it insert itself into a new line, or should the text be
* inserted at the cursor position.)
*/
function Register(text, linewise, blockwise) {
this.clear();
this.keyBuffer = [text || ''];
this.insertModeChanges = [];
this.searchQueries = [];
this.linewise = !!linewise;
this.blockwise = !!blockwise;
}
Register.prototype = {
setText: function(text, linewise, blockwise) {
this.keyBuffer = [text || ''];
this.linewise = !!linewise;
this.blockwise = !!blockwise;
},
pushText: function(text, linewise) {
// if this register has ever been set to linewise, use linewise.
if (linewise) {
if (!this.linewise) {
this.keyBuffer.push('\n');
}
this.linewise = true;
}
this.keyBuffer.push(text);
},
pushInsertModeChanges: function(changes) {
this.insertModeChanges.push(createInsertModeChanges(changes));
},
pushSearchQuery: function(query) {
this.searchQueries.push(query);
},
clear: function() {
this.keyBuffer = [];
this.insertModeChanges = [];
this.searchQueries = [];
this.linewise = false;
},
toString: function() {
return this.keyBuffer.join('');
}
};
/**
* Defines an external register.
*
* The name should be a single character that will be used to reference the register.
* The register should support setText, pushText, clear, and toString(). See Register
* for a reference implementation.
*/
function defineRegister(name, register) {
var registers = vimGlobalState.registerController.registers[name];
if (!name || name.length != 1) {
throw Error('Register name must be 1 character');
}
if (registers[name]) {
throw Error('Register already defined ' + name);
}
registers[name] = register;
validRegisters.push(name);
}
/*
* vim registers allow you to keep many independent copy and paste buffers.
* See http://usevim.com/2012/04/13/registers/ for an introduction.
*
* RegisterController keeps the state of all the registers. An initial
* state may be passed in. The unnamed register '"' will always be
* overridden.
*/
function RegisterController(registers) {
this.registers = registers;
this.unnamedRegister = registers['"'] = new Register();
registers['.'] = new Register();
registers[':'] = new Register();
registers['/'] = new Register();
}
RegisterController.prototype = {
pushText: function(registerName, operator, text, linewise, blockwise) {
if (linewise && text.charAt(0) == '\n') {
text = text.slice(1) + '\n';
}
if (linewise && text.charAt(text.length - 1) !== '\n'){
text += '\n';
}
// Lowercase and uppercase registers refer to the same register.
// Uppercase just means append.
var register = this.isValidRegister(registerName) ?
this.getRegister(registerName) : null;
// if no register/an invalid register was specified, things go to the
// default registers
if (!register) {
switch (operator) {
case 'yank':
// The 0 register contains the text from the most recent yank.
this.registers['0'] = new Register(text, linewise, blockwise);
break;
case 'delete':
case 'change':
if (text.indexOf('\n') == -1) {
// Delete less than 1 line. Update the small delete register.
this.registers['-'] = new Register(text, linewise);
} else {
// Shift down the contents of the numbered registers and put the
// deleted text into register 1.
this.shiftNumericRegisters_();
this.registers['1'] = new Register(text, linewise);
}
break;
}
// Make sure the unnamed register is set to what just happened
this.unnamedRegister.setText(text, linewise, blockwise);
return;
}
// If we've gotten to this point, we've actually specified a register
var append = isUpperCase(registerName);
if (append) {
register.pushText(text, linewise);
} else {
register.setText(text, linewise, blockwise);
}
// The unnamed register always has the same value as the last used
// register.
this.unnamedRegister.setText(register.toString(), linewise);
},
// Gets the register named @name. If one of @name doesn't already exist,
// create it. If @name is invalid, return the unnamedRegister.
getRegister: function(name) {
if (!this.isValidRegister(name)) {
return this.unnamedRegister;
}
name = name.toLowerCase();
if (!this.registers[name]) {
this.registers[name] = new Register();
}
return this.registers[name];
},
isValidRegister: function(name) {
return name && inArray(name, validRegisters);
},
shiftNumericRegisters_: function() {
for (var i = 9; i >= 2; i--) {
this.registers[i] = this.getRegister('' + (i - 1));
}
}
};
function HistoryController() {
this.historyBuffer = [];
this.iterator = 0;
this.initialPrefix = null;
}
HistoryController.prototype = {
// the input argument here acts a user entered prefix for a small time
// until we start autocompletion in which case it is the autocompleted.
nextMatch: function (input, up) {
var historyBuffer = this.historyBuffer;
var dir = up ? -1 : 1;
if (this.initialPrefix === null) this.initialPrefix = input;
for (var i = this.iterator + dir; up ? i >= 0 : i < historyBuffer.length; i+= dir) {
var element = historyBuffer[i];
for (var j = 0; j <= element.length; j++) {
if (this.initialPrefix == element.substring(0, j)) {
this.iterator = i;
return element;
}
}
}
// should return the user input in case we reach the end of buffer.
if (i >= historyBuffer.length) {
this.iterator = historyBuffer.length;
return this.initialPrefix;
}
// return the last autocompleted query or exCommand as it is.
if (i < 0 ) return input;
},
pushInput: function(input) {
var index = this.historyBuffer.indexOf(input);
if (index > -1) this.historyBuffer.splice(index, 1);
if (input.length) this.historyBuffer.push(input);
},
reset: function() {
this.initialPrefix = null;
this.iterator = this.historyBuffer.length;
}
};
var commandDispatcher = {
matchCommand: function(keys, keyMap, inputState, context) {
var matches = commandMatches(keys, keyMap, context, inputState);
if (!matches.full && !matches.partial) {
return {type: 'none'};
} else if (!matches.full && matches.partial) {
return {type: 'partial'};
}
var bestMatch;
for (var i = 0; i < matches.full.length; i++) {
var match = matches.full[i];
if (!bestMatch) {
bestMatch = match;
}
}
if (bestMatch.keys.slice(-11) == '<character>') {
inputState.selectedCharacter = lastChar(keys);
}
return {type: 'full', command: bestMatch};
},
processCommand: function(cm, vim, command) {
vim.inputState.repeatOverride = command.repeatOverride;
switch (command.type) {
case 'motion':
this.processMotion(cm, vim, command);
break;
case 'operator':
this.processOperator(cm, vim, command);
break;
case 'operatorMotion':
this.processOperatorMotion(cm, vim, command);
break;
case 'action':
this.processAction(cm, vim, command);
break;
case 'search':
this.processSearch(cm, vim, command);
break;
case 'ex':
case 'keyToEx':
this.processEx(cm, vim, command);
break;
default:
break;
}
},
processMotion: function(cm, vim, command) {
vim.inputState.motion = command.motion;
vim.inputState.motionArgs = copyArgs(command.motionArgs);
this.evalInput(cm, vim);
},
processOperator: function(cm, vim, command) {
var inputState = vim.inputState;
if (inputState.operator) {
if (inputState.operator == command.operator) {
// Typing an operator twice like 'dd' makes the operator operate
// linewise
inputState.motion = 'expandToLine';
inputState.motionArgs = { linewise: true };
this.evalInput(cm, vim);
return;
} else {
// 2 different operators in a row doesn't make sense.
clearInputState(cm);
}
}
inputState.operator = command.operator;
inputState.operatorArgs = copyArgs(command.operatorArgs);
if (vim.visualMode) {
// Operating on a selection in visual mode. We don't need a motion.
this.evalInput(cm, vim);
}
},
processOperatorMotion: function(cm, vim, command) {
var visualMode = vim.visualMode;
var operatorMotionArgs = copyArgs(command.operatorMotionArgs);
if (operatorMotionArgs) {
// Operator motions may have special behavior in visual mode.
if (visualMode && operatorMotionArgs.visualLine) {
vim.visualLine = true;
}
}
this.processOperator(cm, vim, command);
if (!visualMode) {
this.processMotion(cm, vim, command);
}
},
processAction: function(cm, vim, command) {
var inputState = vim.inputState;
var repeat = inputState.getRepeat();
var repeatIsExplicit = !!repeat;
var actionArgs = copyArgs(command.actionArgs) || {};
if (inputState.selectedCharacter) {
actionArgs.selectedCharacter = inputState.selectedCharacter;
}
// Actions may or may not have motions and operators. Do these first.
if (command.operator) {
this.processOperator(cm, vim, command);
}
if (command.motion) {
this.processMotion(cm, vim, command);
}
if (command.motion || command.operator) {
this.evalInput(cm, vim);
}
actionArgs.repeat = repeat || 1;
actionArgs.repeatIsExplicit = repeatIsExplicit;
actionArgs.registerName = inputState.registerName;
clearInputState(cm);
vim.lastMotion = null;
if (command.isEdit) {
this.recordLastEdit(vim, inputState, command);
}
actions[command.action](cm, actionArgs, vim);
},
processSearch: function(cm, vim, command) {
if (!cm.getSearchCursor) {
// Search depends on SearchCursor.
return;
}
var forward = command.searchArgs.forward;
var wholeWordOnly = command.searchArgs.wholeWordOnly;
getSearchState(cm).setReversed(!forward);
var promptPrefix = (forward) ? '/' : '?';
var originalQuery = getSearchState(cm).getQuery();
var originalScrollPos = cm.getScrollInfo();
function handleQuery(query, ignoreCase, smartCase) {
vimGlobalState.searchHistoryController.pushInput(query);
vimGlobalState.searchHistoryController.reset();
try {
updateSearchQuery(cm, query, ignoreCase, smartCase);
} catch (e) {
showConfirm(cm, 'Invalid regex: ' + query);
clearInputState(cm);
return;
}
commandDispatcher.processMotion(cm, vim, {
type: 'motion',
motion: 'findNext',
motionArgs: { forward: true, toJumplist: command.searchArgs.toJumplist }
});
}
function onPromptClose(query) {
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
handleQuery(query, true /** ignoreCase */, true /** smartCase */);
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isRecording) {
logSearchQuery(macroModeState, query);
}
}
function onPromptKeyUp(e, query, close) {
var keyName = CodeMirror.keyName(e), up, offset;
if (keyName == 'Up' || keyName == 'Down') {
up = keyName == 'Up' ? true : false;
offset = e.target ? e.target.selectionEnd : 0;
query = vimGlobalState.searchHistoryController.nextMatch(query, up) || '';
close(query);
if (offset && e.target) e.target.selectionEnd = e.target.selectionStart = Math.min(offset, e.target.value.length);
} else {
if ( keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift')
vimGlobalState.searchHistoryController.reset();
}
var parsedQuery;
try {
parsedQuery = updateSearchQuery(cm, query,
true /** ignoreCase */, true /** smartCase */);
} catch (e) {
// Swallow bad regexes for incremental search.
}
if (parsedQuery) {
cm.scrollIntoView(findNext(cm, !forward, parsedQuery), 30);
} else {
clearSearchHighlight(cm);
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
}
}
function onPromptKeyDown(e, query, close) {
var keyName = CodeMirror.keyName(e);
if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[' ||
(keyName == 'Backspace' && query == '')) {
vimGlobalState.searchHistoryController.pushInput(query);
vimGlobalState.searchHistoryController.reset();
updateSearchQuery(cm, originalQuery);
clearSearchHighlight(cm);
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
CodeMirror.e_stop(e);
clearInputState(cm);
close();
cm.focus();
} else if (keyName == 'Up' || keyName == 'Down') {
CodeMirror.e_stop(e);
} else if (keyName == 'Ctrl-U') {
// Ctrl-U clears input.
CodeMirror.e_stop(e);
close('');
}
}
switch (command.searchArgs.querySrc) {
case 'prompt':
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) {
var query = macroModeState.replaySearchQueries.shift();
handleQuery(query, true /** ignoreCase */, false /** smartCase */);
} else {
showPrompt(cm, {
onClose: onPromptClose,
prefix: promptPrefix,
desc: searchPromptDesc,
onKeyUp: onPromptKeyUp,
onKeyDown: onPromptKeyDown
});
}
break;
case 'wordUnderCursor':
var word = expandWordUnderCursor(cm, false /** inclusive */,
true /** forward */, false /** bigWord */,
true /** noSymbol */);
var isKeyword = true;
if (!word) {
word = expandWordUnderCursor(cm, false /** inclusive */,
true /** forward */, false /** bigWord */,
false /** noSymbol */);
isKeyword = false;
}
if (!word) {
return;
}
var query = cm.getLine(word.start.line).substring(word.start.ch,
word.end.ch);
if (isKeyword && wholeWordOnly) {
query = '\\b' + query + '\\b';
} else {
query = escapeRegex(query);
}
// cachedCursor is used to save the old position of the cursor
// when * or # causes vim to seek for the nearest word and shift
// the cursor before entering the motion.
vimGlobalState.jumpList.cachedCursor = cm.getCursor();
cm.setCursor(word.start);
handleQuery(query, true /** ignoreCase */, false /** smartCase */);
break;
}
},
processEx: function(cm, vim, command) {
function onPromptClose(input) {
// Give the prompt some time to close so that if processCommand shows
// an error, the elements don't overlap.
vimGlobalState.exCommandHistoryController.pushInput(input);
vimGlobalState.exCommandHistoryController.reset();
exCommandDispatcher.processCommand(cm, input);
}
function onPromptKeyDown(e, input, close) {
var keyName = CodeMirror.keyName(e), up, offset;
if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[' ||
(keyName == 'Backspace' && input == '')) {
vimGlobalState.exCommandHistoryController.pushInput(input);
vimGlobalState.exCommandHistoryController.reset();
CodeMirror.e_stop(e);
clearInputState(cm);
close();
cm.focus();
}
if (keyName == 'Up' || keyName == 'Down') {
CodeMirror.e_stop(e);
up = keyName == 'Up' ? true : false;
offset = e.target ? e.target.selectionEnd : 0;
input = vimGlobalState.exCommandHistoryController.nextMatch(input, up) || '';
close(input);
if (offset && e.target) e.target.selectionEnd = e.target.selectionStart = Math.min(offset, e.target.value.length);
} else if (keyName == 'Ctrl-U') {
// Ctrl-U clears input.
CodeMirror.e_stop(e);
close('');
} else {
if ( keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift')
vimGlobalState.exCommandHistoryController.reset();
}
}
if (command.type == 'keyToEx') {
// Handle user defined Ex to Ex mappings
exCommandDispatcher.processCommand(cm, command.exArgs.input);
} else {
if (vim.visualMode) {
showPrompt(cm, { onClose: onPromptClose, prefix: ':', value: '\'<,\'>',
onKeyDown: onPromptKeyDown});
} else {
showPrompt(cm, { onClose: onPromptClose, prefix: ':',
onKeyDown: onPromptKeyDown});
}
}
},
evalInput: function(cm, vim) {
// If the motion command is set, execute both the operator and motion.
// Otherwise return.
var inputState = vim.inputState;
var motion = inputState.motion;
var motionArgs = inputState.motionArgs || {};
var operator = inputState.operator;
var operatorArgs = inputState.operatorArgs || {};
var registerName = inputState.registerName;
var sel = vim.sel;
// TODO: Make sure cm and vim selections are identical outside visual mode.
var origHead = copyCursor(vim.visualMode ? clipCursorToContent(cm, sel.head): cm.getCursor('head'));
var origAnchor = copyCursor(vim.visualMode ? clipCursorToContent(cm, sel.anchor) : cm.getCursor('anchor'));
var oldHead = copyCursor(origHead);
var oldAnchor = copyCursor(origAnchor);
var newHead, newAnchor;
var repeat;
if (operator) {
this.recordLastEdit(vim, inputState);
}
if (inputState.repeatOverride !== undefined) {
// If repeatOverride is specified, that takes precedence over the
// input state's repeat. Used by Ex mode and can be user defined.
repeat = inputState.repeatOverride;
} else {
repeat = inputState.getRepeat();
}
if (repeat > 0 && motionArgs.explicitRepeat) {
motionArgs.repeatIsExplicit = true;
} else if (motionArgs.noRepeat ||
(!motionArgs.explicitRepeat && repeat === 0)) {
repeat = 1;
motionArgs.repeatIsExplicit = false;
}
if (inputState.selectedCharacter) {
// If there is a character input, stick it in all of the arg arrays.
motionArgs.selectedCharacter = operatorArgs.selectedCharacter =
inputState.selectedCharacter;
}
motionArgs.repeat = repeat;
clearInputState(cm);
if (motion) {
var motionResult = motions[motion](cm, origHead, motionArgs, vim);
vim.lastMotion = motions[motion];
if (!motionResult) {
return;
}
if (motionArgs.toJumplist) {
var jumpList = vimGlobalState.jumpList;
// if the current motion is # or *, use cachedCursor
var cachedCursor = jumpList.cachedCursor;
if (cachedCursor) {
recordJumpPosition(cm, cachedCursor, motionResult);
delete jumpList.cachedCursor;
} else {
recordJumpPosition(cm, origHead, motionResult);
}
}
if (motionResult instanceof Array) {
newAnchor = motionResult[0];
newHead = motionResult[1];
} else {
newHead = motionResult;
}
// TODO: Handle null returns from motion commands better.
if (!newHead) {
newHead = copyCursor(origHead);
}
if (vim.visualMode) {
if (!(vim.visualBlock && newHead.ch === Infinity)) {
newHead = clipCursorToContent(cm, newHead, vim.visualBlock);
}
if (newAnchor) {
newAnchor = clipCursorToContent(cm, newAnchor, true);
}
newAnchor = newAnchor || oldAnchor;
sel.anchor = newAnchor;
sel.head = newHead;
updateCmSelection(cm);
updateMark(cm, vim, '<',
cursorIsBefore(newAnchor, newHead) ? newAnchor
: newHead);
updateMark(cm, vim, '>',
cursorIsBefore(newAnchor, newHead) ? newHead
: newAnchor);
} else if (!operator) {
newHead = clipCursorToContent(cm, newHead);
cm.setCursor(newHead.line, newHead.ch);
}
}
if (operator) {
if (operatorArgs.lastSel) {
// Replaying a visual mode operation
newAnchor = oldAnchor;
var lastSel = operatorArgs.lastSel;
var lineOffset = Math.abs(lastSel.head.line - lastSel.anchor.line);
var chOffset = Math.abs(lastSel.head.ch - lastSel.anchor.ch);
if (lastSel.visualLine) {
// Linewise Visual mode: The same number of lines.
newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch);
} else if (lastSel.visualBlock) {
// Blockwise Visual mode: The same number of lines and columns.
newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch + chOffset);
} else if (lastSel.head.line == lastSel.anchor.line) {
// Normal Visual mode within one line: The same number of characters.
newHead = Pos(oldAnchor.line, oldAnchor.ch + chOffset);
} else {
// Normal Visual mode with several lines: The same number of lines, in the
// last line the same number of characters as in the last line the last time.
newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch);
}
vim.visualMode = true;
vim.visualLine = lastSel.visualLine;
vim.visualBlock = lastSel.visualBlock;
sel = vim.sel = {
anchor: newAnchor,
head: newHead
};
updateCmSelection(cm);
} else if (vim.visualMode) {
operatorArgs.lastSel = {
anchor: copyCursor(sel.anchor),
head: copyCursor(sel.head),
visualBlock: vim.visualBlock,
visualLine: vim.visualLine
};
}
var curStart, curEnd, linewise, mode;
var cmSel;
if (vim.visualMode) {
// Init visual op
curStart = cursorMin(sel.head, sel.anchor);
curEnd = cursorMax(sel.head, sel.anchor);
linewise = vim.visualLine || operatorArgs.linewise;
mode = vim.visualBlock ? 'block' :
linewise ? 'line' :
'char';
cmSel = makeCmSelection(cm, {
anchor: curStart,
head: curEnd
}, mode);
if (linewise) {
var ranges = cmSel.ranges;
if (mode == 'block') {
// Linewise operators in visual block mode extend to end of line
for (var i = 0; i < ranges.length; i++) {
ranges[i].head.ch = lineLength(cm, ranges[i].head.line);
}
} else if (mode == 'line') {
ranges[0].head = Pos(ranges[0].head.line + 1, 0);
}
}
} else {
// Init motion op
curStart = copyCursor(newAnchor || oldAnchor);
curEnd = copyCursor(newHead || oldHead);
if (cursorIsBefore(curEnd, curStart)) {
var tmp = curStart;
curStart = curEnd;
curEnd = tmp;
}
linewise = motionArgs.linewise || operatorArgs.linewise;
if (linewise) {
// Expand selection to entire line.
expandSelectionToLine(cm, curStart, curEnd);
} else if (motionArgs.forward) {
// Clip to trailing newlines only if the motion goes forward.
clipToLine(cm, curStart, curEnd);
}
mode = 'char';
var exclusive = !motionArgs.inclusive || linewise;
cmSel = makeCmSelection(cm, {
anchor: curStart,
head: curEnd
}, mode, exclusive);
}
cm.setSelections(cmSel.ranges, cmSel.primary);
vim.lastMotion = null;
operatorArgs.repeat = repeat; // For indent in visual mode.
operatorArgs.registerName = registerName;
// Keep track of linewise as it affects how paste and change behave.
operatorArgs.linewise = linewise;
var operatorMoveTo = operators[operator](
cm, operatorArgs, cmSel.ranges, oldAnchor, newHead);
if (vim.visualMode) {
exitVisualMode(cm, operatorMoveTo != null);
}
if (operatorMoveTo) {
cm.setCursor(operatorMoveTo);
}
}
},
recordLastEdit: function(vim, inputState, actionCommand) {
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) { return; }
vim.lastEditInputState = inputState;
vim.lastEditActionCommand = actionCommand;
macroModeState.lastInsertModeChanges.changes = [];
macroModeState.lastInsertModeChanges.expectCursorActivityForChange = false;
}
};
/**
* typedef {Object{line:number,ch:number}} Cursor An object containing the
* position of the cursor.
*/
// All of the functions below return Cursor objects.
var motions = {
moveToTopLine: function(cm, _head, motionArgs) {
var line = getUserVisibleLines(cm).top + motionArgs.repeat -1;
return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
},
moveToMiddleLine: function(cm) {
var range = getUserVisibleLines(cm);
var line = Math.floor((range.top + range.bottom) * 0.5);
return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
},
moveToBottomLine: function(cm, _head, motionArgs) {
var line = getUserVisibleLines(cm).bottom - motionArgs.repeat +1;
return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
},
expandToLine: function(_cm, head, motionArgs) {
// Expands forward to end of line, and then to next line if repeat is
// >1. Does not handle backward motion!
var cur = head;
return Pos(cur.line + motionArgs.repeat - 1, Infinity);
},
findNext: function(cm, _head, motionArgs) {
var state = getSearchState(cm);
var query = state.getQuery();
if (!query) {
return;
}
var prev = !motionArgs.forward;
// If search is initiated with ? instead of /, negate direction.
prev = (state.isReversed()) ? !prev : prev;
highlightSearchMatches(cm, query);
return findNext(cm, prev/** prev */, query, motionArgs.repeat);
},
goToMark: function(cm, _head, motionArgs, vim) {
var pos = getMarkPos(cm, vim, motionArgs.selectedCharacter);
if (pos) {
return motionArgs.linewise ? { line: pos.line, ch: findFirstNonWhiteSpaceCharacter(cm.getLine(pos.line)) } : pos;
}
return null;
},
moveToOtherHighlightedEnd: function(cm, _head, motionArgs, vim) {
if (vim.visualBlock && motionArgs.sameLine) {
var sel = vim.sel;
return [
clipCursorToContent(cm, Pos(sel.anchor.line, sel.head.ch)),
clipCursorToContent(cm, Pos(sel.head.line, sel.anchor.ch))
];
} else {
return ([vim.sel.head, vim.sel.anchor]);
}
},
jumpToMark: function(cm, head, motionArgs, vim) {
var best = head;
for (var i = 0; i < motionArgs.repeat; i++) {
var cursor = best;
for (var key in vim.marks) {
if (!isLowerCase(key)) {
continue;
}
var mark = vim.marks[key].find();
var isWrongDirection = (motionArgs.forward) ?
cursorIsBefore(mark, cursor) : cursorIsBefore(cursor, mark);
if (isWrongDirection) {
continue;
}
if (motionArgs.linewise && (mark.line == cursor.line)) {
continue;
}
var equal = cursorEqual(cursor, best);
var between = (motionArgs.forward) ?
cursorIsBetween(cursor, mark, best) :
cursorIsBetween(best, mark, cursor);
if (equal || between) {
best = mark;
}
}
}
if (motionArgs.linewise) {
// Vim places the cursor on the first non-whitespace character of
// the line if there is one, else it places the cursor at the end
// of the line, regardless of whether a mark was found.
best = Pos(best.line, findFirstNonWhiteSpaceCharacter(cm.getLine(best.line)));
}
return best;
},
moveByCharacters: function(_cm, head, motionArgs) {
var cur = head;
var repeat = motionArgs.repeat;
var ch = motionArgs.forward ? cur.ch + repeat : cur.ch - repeat;
return Pos(cur.line, ch);
},
moveByLines: function(cm, head, motionArgs, vim) {
var cur = head;
var endCh = cur.ch;
// Depending what our last motion was, we may want to do different
// things. If our last motion was moving vertically, we want to
// preserve the HPos from our last horizontal move. If our last motion
// was going to the end of a line, moving vertically we should go to
// the end of the line, etc.
switch (vim.lastMotion) {
case this.moveByLines:
case this.moveByDisplayLines:
case this.moveByScroll:
case this.moveToColumn:
case this.moveToEol:
endCh = vim.lastHPos;
break;
default:
vim.lastHPos = endCh;
}
var repeat = motionArgs.repeat+(motionArgs.repeatOffset||0);
var line = motionArgs.forward ? cur.line + repeat : cur.line - repeat;
var first = cm.firstLine();
var last = cm.lastLine();
// Vim go to line begin or line end when cursor at first/last line and
// move to previous/next line is triggered.
if (line < first && cur.line == first){
return this.moveToStartOfLine(cm, head, motionArgs, vim);
}else if (line > last && cur.line == last){
return this.moveToEol(cm, head, motionArgs, vim);
}
if (motionArgs.toFirstChar){
endCh=findFirstNonWhiteSpaceCharacter(cm.getLine(line));
vim.lastHPos = endCh;
}
vim.lastHSPos = cm.charCoords(Pos(line, endCh),'div').left;
return Pos(line, endCh);
},
moveByDisplayLines: function(cm, head, motionArgs, vim) {
var cur = head;
switch (vim.lastMotion) {
case this.moveByDisplayLines:
case this.moveByScroll:
case this.moveByLines:
case this.moveToColumn:
case this.moveToEol:
break;
default:
vim.lastHSPos = cm.charCoords(cur,'div').left;
}
var repeat = motionArgs.repeat;
var res=cm.findPosV(cur,(motionArgs.forward ? repeat : -repeat),'line',vim.lastHSPos);
if (res.hitSide) {
if (motionArgs.forward) {
var lastCharCoords = cm.charCoords(res, 'div');
var goalCoords = { top: lastCharCoords.top + 8, left: vim.lastHSPos };
var res = cm.coordsChar(goalCoords, 'div');
} else {
var resCoords = cm.charCoords(Pos(cm.firstLine(), 0), 'div');
resCoords.left = vim.lastHSPos;
res = cm.coordsChar(resCoords, 'div');
}
}
vim.lastHPos = res.ch;
return res;
},
moveByPage: function(cm, head, motionArgs) {
// CodeMirror only exposes functions that move the cursor page down, so
// doing this bad hack to move the cursor and move it back. evalInput
// will move the cursor to where it should be in the end.
var curStart = head;
var repeat = motionArgs.repeat;
return cm.findPosV(curStart, (motionArgs.forward ? repeat : -repeat), 'page');
},
moveByParagraph: function(cm, head, motionArgs) {
var dir = motionArgs.forward ? 1 : -1;
return findParagraph(cm, head, motionArgs.repeat, dir);
},
moveByScroll: function(cm, head, motionArgs, vim) {
var scrollbox = cm.getScrollInfo();
var curEnd = null;
var repeat = motionArgs.repeat;
if (!repeat) {
repeat = scrollbox.clientHeight / (2 * cm.defaultTextHeight());
}
var orig = cm.charCoords(head, 'local');
motionArgs.repeat = repeat;
var curEnd = motions.moveByDisplayLines(cm, head, motionArgs, vim);
if (!curEnd) {
return null;
}
var dest = cm.charCoords(curEnd, 'local');
cm.scrollTo(null, scrollbox.top + dest.top - orig.top);
return curEnd;
},
moveByWords: function(cm, head, motionArgs) {
return moveToWord(cm, head, motionArgs.repeat, !!motionArgs.forward,
!!motionArgs.wordEnd, !!motionArgs.bigWord);
},
moveTillCharacter: function(cm, _head, motionArgs) {
var repeat = motionArgs.repeat;
var curEnd = moveToCharacter(cm, repeat, motionArgs.forward,
motionArgs.selectedCharacter);
var increment = motionArgs.forward ? -1 : 1;
recordLastCharacterSearch(increment, motionArgs);
if (!curEnd) return null;
curEnd.ch += increment;
return curEnd;
},
moveToCharacter: function(cm, head, motionArgs) {
var repeat = motionArgs.repeat;
recordLastCharacterSearch(0, motionArgs);
return moveToCharacter(cm, repeat, motionArgs.forward,
motionArgs.selectedCharacter) || head;
},
moveToSymbol: function(cm, head, motionArgs) {
var repeat = motionArgs.repeat;
return findSymbol(cm, repeat, motionArgs.forward,
motionArgs.selectedCharacter) || head;
},
moveToColumn: function(cm, head, motionArgs, vim) {
var repeat = motionArgs.repeat;
// repeat is equivalent to which column we want to move to!
vim.lastHPos = repeat - 1;
vim.lastHSPos = cm.charCoords(head,'div').left;
return moveToColumn(cm, repeat);
},
moveToEol: function(cm, head, motionArgs, vim) {
var cur = head;
vim.lastHPos = Infinity;
var retval= Pos(cur.line + motionArgs.repeat - 1, Infinity);
var end=cm.clipPos(retval);
end.ch--;
vim.lastHSPos = cm.charCoords(end,'div').left;
return retval;
},
moveToFirstNonWhiteSpaceCharacter: function(cm, head) {
// Go to the start of the line where the text begins, or the end for
// whitespace-only lines
var cursor = head;
return Pos(cursor.line,
findFirstNonWhiteSpaceCharacter(cm.getLine(cursor.line)));
},
moveToMatchedSymbol: function(cm, head) {
var cursor = head;
var line = cursor.line;
var ch = cursor.ch;
var lineText = cm.getLine(line);
var symbol;
do {
symbol = lineText.charAt(ch++);
if (symbol && isMatchableSymbol(symbol)) {
var style = cm.getTokenTypeAt(Pos(line, ch));
if (style !== "string" && style !== "comment") {
break;
}
}
} while (symbol);
if (symbol) {
var matched = cm.findMatchingBracket(Pos(line, ch));
return matched.to;
} else {
return cursor;
}
},
moveToStartOfLine: function(_cm, head) {
return Pos(head.line, 0);
},
moveToLineOrEdgeOfDocument: function(cm, _head, motionArgs) {
var lineNum = motionArgs.forward ? cm.lastLine() : cm.firstLine();
if (motionArgs.repeatIsExplicit) {
lineNum = motionArgs.repeat - cm.getOption('firstLineNumber');
}
return Pos(lineNum,
findFirstNonWhiteSpaceCharacter(cm.getLine(lineNum)));
},
textObjectManipulation: function(cm, head, motionArgs, vim) {
// TODO: lots of possible exceptions that can be thrown here. Try da(
// outside of a () block.
// TODO: adding <> >< to this map doesn't work, presumably because
// they're operators
var mirroredPairs = {'(': ')', ')': '(',
'{': '}', '}': '{',
'[': ']', ']': '['};
var selfPaired = {'\'': true, '"': true};
var character = motionArgs.selectedCharacter;
// 'b' refers to '()' block.
// 'B' refers to '{}' block.
if (character == 'b') {
character = '(';
} else if (character == 'B') {
character = '{';
}
// Inclusive is the difference between a and i
// TODO: Instead of using the additional text object map to perform text
// object operations, merge the map into the defaultKeyMap and use
// motionArgs to define behavior. Define separate entries for 'aw',
// 'iw', 'a[', 'i[', etc.
var inclusive = !motionArgs.textObjectInner;
var tmp;
if (mirroredPairs[character]) {
tmp = selectCompanionObject(cm, head, character, inclusive);
} else if (selfPaired[character]) {
tmp = findBeginningAndEnd(cm, head, character, inclusive);
} else if (character === 'W') {
tmp = expandWordUnderCursor(cm, inclusive, true /** forward */,
true /** bigWord */);
} else if (character === 'w') {
tmp = expandWordUnderCursor(cm, inclusive, true /** forward */,
false /** bigWord */);
} else if (character === 'p') {
tmp = findParagraph(cm, head, motionArgs.repeat, 0, inclusive);
motionArgs.linewise = true;
if (vim.visualMode) {
if (!vim.visualLine) { vim.visualLine = true; }
} else {
var operatorArgs = vim.inputState.operatorArgs;
if (operatorArgs) { operatorArgs.linewise = true; }
tmp.end.line--;
}
} else {
// No text object defined for this, don't move.
return null;
}
if (!cm.state.vim.visualMode) {
return [tmp.start, tmp.end];
} else {
return expandSelection(cm, tmp.start, tmp.end);
}
},
repeatLastCharacterSearch: function(cm, head, motionArgs) {
var lastSearch = vimGlobalState.lastCharacterSearch;
var repeat = motionArgs.repeat;
var forward = motionArgs.forward === lastSearch.forward;
var increment = (lastSearch.increment ? 1 : 0) * (forward ? -1 : 1);
cm.moveH(-increment, 'char');
motionArgs.inclusive = forward ? true : false;
var curEnd = moveToCharacter(cm, repeat, forward, lastSearch.selectedCharacter);
if (!curEnd) {
cm.moveH(increment, 'char');
return head;
}
curEnd.ch += increment;
return curEnd;
}
};
function defineMotion(name, fn) {
motions[name] = fn;
}
function fillArray(val, times) {
var arr = [];
for (var i = 0; i < times; i++) {
arr.push(val);
}
return arr;
}
/**
* An operator acts on a text selection. It receives the list of selections
* as input. The corresponding CodeMirror selection is guaranteed to
* match the input selection.
*/
var operators = {
change: function(cm, args, ranges) {
var finalHead, text;
var vim = cm.state.vim;
vimGlobalState.macroModeState.lastInsertModeChanges.inVisualBlock = vim.visualBlock;
if (!vim.visualMode) {
var anchor = ranges[0].anchor,
head = ranges[0].head;
text = cm.getRange(anchor, head);
var lastState = vim.lastEditInputState || {};
if (lastState.motion == "moveByWords" && !isWhiteSpaceString(text)) {
// Exclude trailing whitespace if the range is not all whitespace.
var match = (/\s+$/).exec(text);
if (match && lastState.motionArgs && lastState.motionArgs.forward) {
head = offsetCursor(head, 0, - match[0].length);
text = text.slice(0, - match[0].length);
}
}
var prevLineEnd = new Pos(anchor.line - 1, Number.MAX_VALUE);
var wasLastLine = cm.firstLine() == cm.lastLine();
if (head.line > cm.lastLine() && args.linewise && !wasLastLine) {
cm.replaceRange('', prevLineEnd, head);
} else {
cm.replaceRange('', anchor, head);
}
if (args.linewise) {
// Push the next line back down, if there is a next line.
if (!wasLastLine) {
cm.setCursor(prevLineEnd);
CodeMirror.commands.newlineAndIndent(cm);
}
// make sure cursor ends up at the end of the line.
anchor.ch = Number.MAX_VALUE;
}
finalHead = anchor;
} else {
text = cm.getSelection();
var replacement = fillArray('', ranges.length);
cm.replaceSelections(replacement);
finalHead = cursorMin(ranges[0].head, ranges[0].anchor);
}
vimGlobalState.registerController.pushText(
args.registerName, 'change', text,
args.linewise, ranges.length > 1);
actions.enterInsertMode(cm, {head: finalHead}, cm.state.vim);
},
// delete is a javascript keyword.
'delete': function(cm, args, ranges) {
var finalHead, text;
var vim = cm.state.vim;
if (!vim.visualBlock) {
var anchor = ranges[0].anchor,
head = ranges[0].head;
if (args.linewise &&
head.line != cm.firstLine() &&
anchor.line == cm.lastLine() &&
anchor.line == head.line - 1) {
// Special case for dd on last line (and first line).
if (anchor.line == cm.firstLine()) {
anchor.ch = 0;
} else {
anchor = Pos(anchor.line - 1, lineLength(cm, anchor.line - 1));
}
}
text = cm.getRange(anchor, head);
cm.replaceRange('', anchor, head);
finalHead = anchor;
if (args.linewise) {
finalHead = motions.moveToFirstNonWhiteSpaceCharacter(cm, anchor);
}
} else {
text = cm.getSelection();
var replacement = fillArray('', ranges.length);
cm.replaceSelections(replacement);
finalHead = ranges[0].anchor;
}
vimGlobalState.registerController.pushText(
args.registerName, 'delete', text,
args.linewise, vim.visualBlock);
return clipCursorToContent(cm, finalHead);
},
indent: function(cm, args, ranges) {
var vim = cm.state.vim;
var startLine = ranges[0].anchor.line;
var endLine = vim.visualBlock ?
ranges[ranges.length - 1].anchor.line :
ranges[0].head.line;
// In visual mode, n> shifts the selection right n times, instead of
// shifting n lines right once.
var repeat = (vim.visualMode) ? args.repeat : 1;
if (args.linewise) {
// The only way to delete a newline is to delete until the start of
// the next line, so in linewise mode evalInput will include the next
// line. We don't want this in indent, so we go back a line.
endLine--;
}
for (var i = startLine; i <= endLine; i++) {
for (var j = 0; j < repeat; j++) {
cm.indentLine(i, args.indentRight);
}
}
return motions.moveToFirstNonWhiteSpaceCharacter(cm, ranges[0].anchor);
},
changeCase: function(cm, args, ranges, oldAnchor, newHead) {
var selections = cm.getSelections();
var swapped = [];
var toLower = args.toLower;
for (var j = 0; j < selections.length; j++) {
var toSwap = selections[j];
var text = '';
if (toLower === true) {
text = toSwap.toLowerCase();
} else if (toLower === false) {
text = toSwap.toUpperCase();
} else {
for (var i = 0; i < toSwap.length; i++) {
var character = toSwap.charAt(i);
text += isUpperCase(character) ? character.toLowerCase() :
character.toUpperCase();
}
}
swapped.push(text);
}
cm.replaceSelections(swapped);
if (args.shouldMoveCursor){
return newHead;
} else if (!cm.state.vim.visualMode && args.linewise && ranges[0].anchor.line + 1 == ranges[0].head.line) {
return motions.moveToFirstNonWhiteSpaceCharacter(cm, oldAnchor);
} else if (args.linewise){
return oldAnchor;
} else {
return cursorMin(ranges[0].anchor, ranges[0].head);
}
},
yank: function(cm, args, ranges, oldAnchor) {
var vim = cm.state.vim;
var text = cm.getSelection();
var endPos = vim.visualMode
? cursorMin(vim.sel.anchor, vim.sel.head, ranges[0].head, ranges[0].anchor)
: oldAnchor;
vimGlobalState.registerController.pushText(
args.registerName, 'yank',
text, args.linewise, vim.visualBlock);
return endPos;
}
};
function defineOperator(name, fn) {
operators[name] = fn;
}
var actions = {
jumpListWalk: function(cm, actionArgs, vim) {
if (vim.visualMode) {
return;
}
var repeat = actionArgs.repeat;
var forward = actionArgs.forward;
var jumpList = vimGlobalState.jumpList;
var mark = jumpList.move(cm, forward ? repeat : -repeat);
var markPos = mark ? mark.find() : undefined;
markPos = markPos ? markPos : cm.getCursor();
cm.setCursor(markPos);
},
scroll: function(cm, actionArgs, vim) {
if (vim.visualMode) {
return;
}
var repeat = actionArgs.repeat || 1;
var lineHeight = cm.defaultTextHeight();
var top = cm.getScrollInfo().top;
var delta = lineHeight * repeat;
var newPos = actionArgs.forward ? top + delta : top - delta;
var cursor = copyCursor(cm.getCursor());
var cursorCoords = cm.charCoords(cursor, 'local');
if (actionArgs.forward) {
if (newPos > cursorCoords.top) {
cursor.line += (newPos - cursorCoords.top) / lineHeight;
cursor.line = Math.ceil(cursor.line);
cm.setCursor(cursor);
cursorCoords = cm.charCoords(cursor, 'local');
cm.scrollTo(null, cursorCoords.top);
} else {
// Cursor stays within bounds. Just reposition the scroll window.
cm.scrollTo(null, newPos);
}
} else {
var newBottom = newPos + cm.getScrollInfo().clientHeight;
if (newBottom < cursorCoords.bottom) {
cursor.line -= (cursorCoords.bottom - newBottom) / lineHeight;
cursor.line = Math.floor(cursor.line);
cm.setCursor(cursor);
cursorCoords = cm.charCoords(cursor, 'local');
cm.scrollTo(
null, cursorCoords.bottom - cm.getScrollInfo().clientHeight);
} else {
// Cursor stays within bounds. Just reposition the scroll window.
cm.scrollTo(null, newPos);
}
}
},
scrollToCursor: function(cm, actionArgs) {
var lineNum = cm.getCursor().line;
var charCoords = cm.charCoords(Pos(lineNum, 0), 'local');
var height = cm.getScrollInfo().clientHeight;
var y = charCoords.top;
var lineHeight = charCoords.bottom - y;
switch (actionArgs.position) {
case 'center': y = y - (height / 2) + lineHeight;
break;
case 'bottom': y = y - height + lineHeight;
break;
}
cm.scrollTo(null, y);
},
replayMacro: function(cm, actionArgs, vim) {
var registerName = actionArgs.selectedCharacter;
var repeat = actionArgs.repeat;
var macroModeState = vimGlobalState.macroModeState;
if (registerName == '@') {
registerName = macroModeState.latestRegister;
}
while(repeat--){
executeMacroRegister(cm, vim, macroModeState, registerName);
}
},
enterMacroRecordMode: function(cm, actionArgs) {
var macroModeState = vimGlobalState.macroModeState;
var registerName = actionArgs.selectedCharacter;
macroModeState.enterMacroRecordMode(cm, registerName);
},
toggleOverwrite: function(cm) {
if (!cm.state.overwrite) {
cm.toggleOverwrite(true);
cm.setOption('keyMap', 'vim-replace');
CodeMirror.signal(cm, "vim-mode-change", {mode: "replace"});
} else {
cm.toggleOverwrite(false);
cm.setOption('keyMap', 'vim-insert');
CodeMirror.signal(cm, "vim-mode-change", {mode: "insert"});
}
},
enterInsertMode: function(cm, actionArgs, vim) {
if (cm.getOption('readOnly')) { return; }
vim.insertMode = true;
vim.insertModeRepeat = actionArgs && actionArgs.repeat || 1;
var insertAt = (actionArgs) ? actionArgs.insertAt : null;
var sel = vim.sel;
var head = actionArgs.head || cm.getCursor('head');
var height = cm.listSelections().length;
if (insertAt == 'eol') {
head = Pos(head.line, lineLength(cm, head.line));
} else if (insertAt == 'charAfter') {
head = offsetCursor(head, 0, 1);
} else if (insertAt == 'firstNonBlank') {
head = motions.moveToFirstNonWhiteSpaceCharacter(cm, head);
} else if (insertAt == 'startOfSelectedArea') {
if (!vim.visualBlock) {
if (sel.head.line < sel.anchor.line) {
head = sel.head;
} else {
head = Pos(sel.anchor.line, 0);
}
} else {
head = Pos(
Math.min(sel.head.line, sel.anchor.line),
Math.min(sel.head.ch, sel.anchor.ch));
height = Math.abs(sel.head.line - sel.anchor.line) + 1;
}
} else if (insertAt == 'endOfSelectedArea') {
if (!vim.visualBlock) {
if (sel.head.line >= sel.anchor.line) {
head = offsetCursor(sel.head, 0, 1);
} else {
head = Pos(sel.anchor.line, 0);
}
} else {
head = Pos(
Math.min(sel.head.line, sel.anchor.line),
Math.max(sel.head.ch + 1, sel.anchor.ch));
height = Math.abs(sel.head.line - sel.anchor.line) + 1;
}
} else if (insertAt == 'inplace') {
if (vim.visualMode){
return;
}
}
cm.setOption('disableInput', false);
if (actionArgs && actionArgs.replace) {
// Handle Replace-mode as a special case of insert mode.
cm.toggleOverwrite(true);
cm.setOption('keyMap', 'vim-replace');
CodeMirror.signal(cm, "vim-mode-change", {mode: "replace"});
} else {
cm.toggleOverwrite(false);
cm.setOption('keyMap', 'vim-insert');
CodeMirror.signal(cm, "vim-mode-change", {mode: "insert"});
}
if (!vimGlobalState.macroModeState.isPlaying) {
// Only record if not replaying.
cm.on('change', onChange);
CodeMirror.on(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
}
if (vim.visualMode) {
exitVisualMode(cm);
}
selectForInsert(cm, head, height);
},
toggleVisualMode: function(cm, actionArgs, vim) {
var repeat = actionArgs.repeat;
var anchor = cm.getCursor();
var head;
// TODO: The repeat should actually select number of characters/lines
// equal to the repeat times the size of the previous visual
// operation.
if (!vim.visualMode) {
// Entering visual mode
vim.visualMode = true;
vim.visualLine = !!actionArgs.linewise;
vim.visualBlock = !!actionArgs.blockwise;
head = clipCursorToContent(
cm, Pos(anchor.line, anchor.ch + repeat - 1),
true /** includeLineBreak */);
vim.sel = {
anchor: anchor,
head: head
};
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual", subMode: vim.visualLine ? "linewise" : vim.visualBlock ? "blockwise" : ""});
updateCmSelection(cm);
updateMark(cm, vim, '<', cursorMin(anchor, head));
updateMark(cm, vim, '>', cursorMax(anchor, head));
} else if (vim.visualLine ^ actionArgs.linewise ||
vim.visualBlock ^ actionArgs.blockwise) {
// Toggling between modes
vim.visualLine = !!actionArgs.linewise;
vim.visualBlock = !!actionArgs.blockwise;
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual", subMode: vim.visualLine ? "linewise" : vim.visualBlock ? "blockwise" : ""});
updateCmSelection(cm);
} else {
exitVisualMode(cm);
}
},
reselectLastSelection: function(cm, _actionArgs, vim) {
var lastSelection = vim.lastSelection;
if (vim.visualMode) {
updateLastSelection(cm, vim);
}
if (lastSelection) {
var anchor = lastSelection.anchorMark.find();
var head = lastSelection.headMark.find();
if (!anchor || !head) {
// If the marks have been destroyed due to edits, do nothing.
return;
}
vim.sel = {
anchor: anchor,
head: head
};
vim.visualMode = true;
vim.visualLine = lastSelection.visualLine;
vim.visualBlock = lastSelection.visualBlock;
updateCmSelection(cm);
updateMark(cm, vim, '<', cursorMin(anchor, head));
updateMark(cm, vim, '>', cursorMax(anchor, head));
CodeMirror.signal(cm, 'vim-mode-change', {
mode: 'visual',
subMode: vim.visualLine ? 'linewise' :
vim.visualBlock ? 'blockwise' : ''});
}
},
joinLines: function(cm, actionArgs, vim) {
var curStart, curEnd;
if (vim.visualMode) {
curStart = cm.getCursor('anchor');
curEnd = cm.getCursor('head');
if (cursorIsBefore(curEnd, curStart)) {
var tmp = curEnd;
curEnd = curStart;
curStart = tmp;
}
curEnd.ch = lineLength(cm, curEnd.line) - 1;
} else {
// Repeat is the number of lines to join. Minimum 2 lines.
var repeat = Math.max(actionArgs.repeat, 2);
curStart = cm.getCursor();
curEnd = clipCursorToContent(cm, Pos(curStart.line + repeat - 1,
Infinity));
}
var finalCh = 0;
for (var i = curStart.line; i < curEnd.line; i++) {
finalCh = lineLength(cm, curStart.line);
var tmp = Pos(curStart.line + 1,
lineLength(cm, curStart.line + 1));
var text = cm.getRange(curStart, tmp);
text = text.replace(/\n\s*/g, ' ');
cm.replaceRange(text, curStart, tmp);
}
var curFinalPos = Pos(curStart.line, finalCh);
if (vim.visualMode) {
exitVisualMode(cm, false);
}
cm.setCursor(curFinalPos);
},
newLineAndEnterInsertMode: function(cm, actionArgs, vim) {
vim.insertMode = true;
var insertAt = copyCursor(cm.getCursor());
if (insertAt.line === cm.firstLine() && !actionArgs.after) {
// Special case for inserting newline before start of document.
cm.replaceRange('\n', Pos(cm.firstLine(), 0));
cm.setCursor(cm.firstLine(), 0);
} else {
insertAt.line = (actionArgs.after) ? insertAt.line :
insertAt.line - 1;
insertAt.ch = lineLength(cm, insertAt.line);
cm.setCursor(insertAt);
var newlineFn = CodeMirror.commands.newlineAndIndentContinueComment ||
CodeMirror.commands.newlineAndIndent;
newlineFn(cm);
}
this.enterInsertMode(cm, { repeat: actionArgs.repeat }, vim);
},
paste: function(cm, actionArgs, vim) {
var cur = copyCursor(cm.getCursor());
var register = vimGlobalState.registerController.getRegister(
actionArgs.registerName);
var text = register.toString();
if (!text) {
return;
}
if (actionArgs.matchIndent) {
var tabSize = cm.getOption("tabSize");
// length that considers tabs and tabSize
var whitespaceLength = function(str) {
var tabs = (str.split("\t").length - 1);
var spaces = (str.split(" ").length - 1);
return tabs * tabSize + spaces * 1;
};
var currentLine = cm.getLine(cm.getCursor().line);
var indent = whitespaceLength(currentLine.match(/^\s*/)[0]);
// chomp last newline b/c don't want it to match /^\s*/gm
var chompedText = text.replace(/\n$/, '');
var wasChomped = text !== chompedText;
var firstIndent = whitespaceLength(text.match(/^\s*/)[0]);
var text = chompedText.replace(/^\s*/gm, function(wspace) {
var newIndent = indent + (whitespaceLength(wspace) - firstIndent);
if (newIndent < 0) {
return "";
}
else if (cm.getOption("indentWithTabs")) {
var quotient = Math.floor(newIndent / tabSize);
return Array(quotient + 1).join('\t');
}
else {
return Array(newIndent + 1).join(' ');
}
});
text += wasChomped ? "\n" : "";
}
if (actionArgs.repeat > 1) {
var text = Array(actionArgs.repeat + 1).join(text);
}
var linewise = register.linewise;
var blockwise = register.blockwise;
if (linewise) {
if(vim.visualMode) {
text = vim.visualLine ? text.slice(0, -1) : '\n' + text.slice(0, text.length - 1) + '\n';
} else if (actionArgs.after) {
// Move the newline at the end to the start instead, and paste just
// before the newline character of the line we are on right now.
text = '\n' + text.slice(0, text.length - 1);
cur.ch = lineLength(cm, cur.line);
} else {
cur.ch = 0;
}
} else {
if (blockwise) {
text = text.split('\n');
for (var i = 0; i < text.length; i++) {
text[i] = (text[i] == '') ? ' ' : text[i];
}
}
cur.ch += actionArgs.after ? 1 : 0;
}
var curPosFinal;
var idx;
if (vim.visualMode) {
// save the pasted text for reselection if the need arises
vim.lastPastedText = text;
var lastSelectionCurEnd;
var selectedArea = getSelectedAreaRange(cm, vim);
var selectionStart = selectedArea[0];
var selectionEnd = selectedArea[1];
var selectedText = cm.getSelection();
var selections = cm.listSelections();
var emptyStrings = new Array(selections.length).join('1').split('1');
// save the curEnd marker before it get cleared due to cm.replaceRange.
if (vim.lastSelection) {
lastSelectionCurEnd = vim.lastSelection.headMark.find();
}
// push the previously selected text to unnamed register
vimGlobalState.registerController.unnamedRegister.setText(selectedText);
if (blockwise) {
// first delete the selected text
cm.replaceSelections(emptyStrings);
// Set new selections as per the block length of the yanked text
selectionEnd = Pos(selectionStart.line + text.length-1, selectionStart.ch);
cm.setCursor(selectionStart);
selectBlock(cm, selectionEnd);
cm.replaceSelections(text);
curPosFinal = selectionStart;
} else if (vim.visualBlock) {
cm.replaceSelections(emptyStrings);
cm.setCursor(selectionStart);
cm.replaceRange(text, selectionStart, selectionStart);
curPosFinal = selectionStart;
} else {
cm.replaceRange(text, selectionStart, selectionEnd);
curPosFinal = cm.posFromIndex(cm.indexFromPos(selectionStart) + text.length - 1);
}
// restore the the curEnd marker
if(lastSelectionCurEnd) {
vim.lastSelection.headMark = cm.setBookmark(lastSelectionCurEnd);
}
if (linewise) {
curPosFinal.ch=0;
}
} else {
if (blockwise) {
cm.setCursor(cur);
for (var i = 0; i < text.length; i++) {
var line = cur.line+i;
if (line > cm.lastLine()) {
cm.replaceRange('\n', Pos(line, 0));
}
var lastCh = lineLength(cm, line);
if (lastCh < cur.ch) {
extendLineToColumn(cm, line, cur.ch);
}
}
cm.setCursor(cur);
selectBlock(cm, Pos(cur.line + text.length-1, cur.ch));
cm.replaceSelections(text);
curPosFinal = cur;
} else {
cm.replaceRange(text, cur);
// Now fine tune the cursor to where we want it.
if (linewise && actionArgs.after) {
curPosFinal = Pos(
cur.line + 1,
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line + 1)));
} else if (linewise && !actionArgs.after) {
curPosFinal = Pos(
cur.line,
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line)));
} else if (!linewise && actionArgs.after) {
idx = cm.indexFromPos(cur);
curPosFinal = cm.posFromIndex(idx + text.length - 1);
} else {
idx = cm.indexFromPos(cur);
curPosFinal = cm.posFromIndex(idx + text.length);
}
}
}
if (vim.visualMode) {
exitVisualMode(cm, false);
}
cm.setCursor(curPosFinal);
},
undo: function(cm, actionArgs) {
cm.operation(function() {
repeatFn(cm, CodeMirror.commands.undo, actionArgs.repeat)();
cm.setCursor(cm.getCursor('anchor'));
});
},
redo: function(cm, actionArgs) {
repeatFn(cm, CodeMirror.commands.redo, actionArgs.repeat)();
},
setRegister: function(_cm, actionArgs, vim) {
vim.inputState.registerName = actionArgs.selectedCharacter;
},
setMark: function(cm, actionArgs, vim) {
var markName = actionArgs.selectedCharacter;
updateMark(cm, vim, markName, cm.getCursor());
},
replace: function(cm, actionArgs, vim) {
var replaceWith = actionArgs.selectedCharacter;
var curStart = cm.getCursor();
var replaceTo;
var curEnd;
var selections = cm.listSelections();
if (vim.visualMode) {
curStart = cm.getCursor('start');
curEnd = cm.getCursor('end');
} else {
var line = cm.getLine(curStart.line);
replaceTo = curStart.ch + actionArgs.repeat;
if (replaceTo > line.length) {
replaceTo=line.length;
}
curEnd = Pos(curStart.line, replaceTo);
}
if (replaceWith=='\n') {
if (!vim.visualMode) cm.replaceRange('', curStart, curEnd);
// special case, where vim help says to replace by just one line-break
(CodeMirror.commands.newlineAndIndentContinueComment || CodeMirror.commands.newlineAndIndent)(cm);
} else {
var replaceWithStr = cm.getRange(curStart, curEnd);
//replace all characters in range by selected, but keep linebreaks
replaceWithStr = replaceWithStr.replace(/[^\n]/g, replaceWith);
if (vim.visualBlock) {
// Tabs are split in visua block before replacing
var spaces = new Array(cm.getOption("tabSize")+1).join(' ');
replaceWithStr = cm.getSelection();
replaceWithStr = replaceWithStr.replace(/\t/g, spaces).replace(/[^\n]/g, replaceWith).split('\n');
cm.replaceSelections(replaceWithStr);
} else {
cm.replaceRange(replaceWithStr, curStart, curEnd);
}
if (vim.visualMode) {
curStart = cursorIsBefore(selections[0].anchor, selections[0].head) ?
selections[0].anchor : selections[0].head;
cm.setCursor(curStart);
exitVisualMode(cm, false);
} else {
cm.setCursor(offsetCursor(curEnd, 0, -1));
}
}
},
incrementNumberToken: function(cm, actionArgs) {
var cur = cm.getCursor();
var lineStr = cm.getLine(cur.line);
var re = /-?\d+/g;
var match;
var start;
var end;
var numberStr;
var token;
while ((match = re.exec(lineStr)) !== null) {
token = match[0];
start = match.index;
end = start + token.length;
if (cur.ch < end)break;
}
if (!actionArgs.backtrack && (end <= cur.ch))return;
if (token) {
var increment = actionArgs.increase ? 1 : -1;
var number = parseInt(token) + (increment * actionArgs.repeat);
var from = Pos(cur.line, start);
var to = Pos(cur.line, end);
numberStr = number.toString();
cm.replaceRange(numberStr, from, to);
} else {
return;
}
cm.setCursor(Pos(cur.line, start + numberStr.length - 1));
},
repeatLastEdit: function(cm, actionArgs, vim) {
var lastEditInputState = vim.lastEditInputState;
if (!lastEditInputState) { return; }
var repeat = actionArgs.repeat;
if (repeat && actionArgs.repeatIsExplicit) {
vim.lastEditInputState.repeatOverride = repeat;
} else {
repeat = vim.lastEditInputState.repeatOverride || repeat;
}
repeatLastEdit(cm, vim, repeat, false /** repeatForInsert */);
},
indent: function(cm, actionArgs) {
cm.indentLine(cm.getCursor().line, actionArgs.indentRight);
},
exitInsertMode: exitInsertMode
};
function defineAction(name, fn) {
actions[name] = fn;
}
/*
* Below are miscellaneous utility functions used by vim.js
*/
/**
* Clips cursor to ensure that line is within the buffer's range
* If includeLineBreak is true, then allow cur.ch == lineLength.
*/
function clipCursorToContent(cm, cur, includeLineBreak) {
var line = Math.min(Math.max(cm.firstLine(), cur.line), cm.lastLine() );
var maxCh = lineLength(cm, line) - 1;
maxCh = (includeLineBreak) ? maxCh + 1 : maxCh;
var ch = Math.min(Math.max(0, cur.ch), maxCh);
return Pos(line, ch);
}
function copyArgs(args) {
var ret = {};
for (var prop in args) {
if (args.hasOwnProperty(prop)) {
ret[prop] = args[prop];
}
}
return ret;
}
function offsetCursor(cur, offsetLine, offsetCh) {
if (typeof offsetLine === 'object') {
offsetCh = offsetLine.ch;
offsetLine = offsetLine.line;
}
return Pos(cur.line + offsetLine, cur.ch + offsetCh);
}
function getOffset(anchor, head) {
return {
line: head.line - anchor.line,
ch: head.line - anchor.line
};
}
function commandMatches(keys, keyMap, context, inputState) {
// Partial matches are not applied. They inform the key handler
// that the current key sequence is a subsequence of a valid key
// sequence, so that the key buffer is not cleared.
var match, partial = [], full = [];
for (var i = 0; i < keyMap.length; i++) {
var command = keyMap[i];
if (context == 'insert' && command.context != 'insert' ||
command.context && command.context != context ||
inputState.operator && command.type == 'action' ||
!(match = commandMatch(keys, command.keys))) { continue; }
if (match == 'partial') { partial.push(command); }
if (match == 'full') { full.push(command); }
}
return {
partial: partial.length && partial,
full: full.length && full
};
}
function commandMatch(pressed, mapped) {
if (mapped.slice(-11) == '<character>') {
// Last character matches anything.
var prefixLen = mapped.length - 11;
var pressedPrefix = pressed.slice(0, prefixLen);
var mappedPrefix = mapped.slice(0, prefixLen);
return pressedPrefix == mappedPrefix && pressed.length > prefixLen ? 'full' :
mappedPrefix.indexOf(pressedPrefix) == 0 ? 'partial' : false;
} else {
return pressed == mapped ? 'full' :
mapped.indexOf(pressed) == 0 ? 'partial' : false;
}
}
function lastChar(keys) {
var match = /^.*(<[\w\-]+>)$/.exec(keys);
var selectedCharacter = match ? match[1] : keys.slice(-1);
if (selectedCharacter.length > 1){
switch(selectedCharacter){
case '<CR>':
selectedCharacter='\n';
break;
case '<Space>':
selectedCharacter=' ';
break;
default:
break;
}
}
return selectedCharacter;
}
function repeatFn(cm, fn, repeat) {
return function() {
for (var i = 0; i < repeat; i++) {
fn(cm);
}
};
}
function copyCursor(cur) {
return Pos(cur.line, cur.ch);
}
function cursorEqual(cur1, cur2) {
return cur1.ch == cur2.ch && cur1.line == cur2.line;
}
function cursorIsBefore(cur1, cur2) {
if (cur1.line < cur2.line) {
return true;
}
if (cur1.line == cur2.line && cur1.ch < cur2.ch) {
return true;
}
return false;
}
function cursorMin(cur1, cur2) {
if (arguments.length > 2) {
cur2 = cursorMin.apply(undefined, Array.prototype.slice.call(arguments, 1));
}
return cursorIsBefore(cur1, cur2) ? cur1 : cur2;
}
function cursorMax(cur1, cur2) {
if (arguments.length > 2) {
cur2 = cursorMax.apply(undefined, Array.prototype.slice.call(arguments, 1));
}
return cursorIsBefore(cur1, cur2) ? cur2 : cur1;
}
function cursorIsBetween(cur1, cur2, cur3) {
// returns true if cur2 is between cur1 and cur3.
var cur1before2 = cursorIsBefore(cur1, cur2);
var cur2before3 = cursorIsBefore(cur2, cur3);
return cur1before2 && cur2before3;
}
function lineLength(cm, lineNum) {
return cm.getLine(lineNum).length;
}
function trim(s) {
if (s.trim) {
return s.trim();
}
return s.replace(/^\s+|\s+$/g, '');
}
function escapeRegex(s) {
return s.replace(/([.?*+$\[\]\/\\(){}|\-])/g, '\\$1');
}
function extendLineToColumn(cm, lineNum, column) {
var endCh = lineLength(cm, lineNum);
var spaces = new Array(column-endCh+1).join(' ');
cm.setCursor(Pos(lineNum, endCh));
cm.replaceRange(spaces, cm.getCursor());
}
// This functions selects a rectangular block
// of text with selectionEnd as any of its corner
// Height of block:
// Difference in selectionEnd.line and first/last selection.line
// Width of the block:
// Distance between selectionEnd.ch and any(first considered here) selection.ch
function selectBlock(cm, selectionEnd) {
var selections = [], ranges = cm.listSelections();
var head = copyCursor(cm.clipPos(selectionEnd));
var isClipped = !cursorEqual(selectionEnd, head);
var curHead = cm.getCursor('head');
var primIndex = getIndex(ranges, curHead);
var wasClipped = cursorEqual(ranges[primIndex].head, ranges[primIndex].anchor);
var max = ranges.length - 1;
var index = max - primIndex > primIndex ? max : 0;
var base = ranges[index].anchor;
var firstLine = Math.min(base.line, head.line);
var lastLine = Math.max(base.line, head.line);
var baseCh = base.ch, headCh = head.ch;
var dir = ranges[index].head.ch - baseCh;
var newDir = headCh - baseCh;
if (dir > 0 && newDir <= 0) {
baseCh++;
if (!isClipped) { headCh--; }
} else if (dir < 0 && newDir >= 0) {
baseCh--;
if (!wasClipped) { headCh++; }
} else if (dir < 0 && newDir == -1) {
baseCh--;
headCh++;
}
for (var line = firstLine; line <= lastLine; line++) {
var range = {anchor: new Pos(line, baseCh), head: new Pos(line, headCh)};
selections.push(range);
}
primIndex = head.line == lastLine ? selections.length - 1 : 0;
cm.setSelections(selections);
selectionEnd.ch = headCh;
base.ch = baseCh;
return base;
}
function selectForInsert(cm, head, height) {
var sel = [];
for (var i = 0; i < height; i++) {
var lineHead = offsetCursor(head, i, 0);
sel.push({anchor: lineHead, head: lineHead});
}
cm.setSelections(sel, 0);
}
// getIndex returns the index of the cursor in the selections.
function getIndex(ranges, cursor, end) {
for (var i = 0; i < ranges.length; i++) {
var atAnchor = end != 'head' && cursorEqual(ranges[i].anchor, cursor);
var atHead = end != 'anchor' && cursorEqual(ranges[i].head, cursor);
if (atAnchor || atHead) {
return i;
}
}
return -1;
}
function getSelectedAreaRange(cm, vim) {
var lastSelection = vim.lastSelection;
var getCurrentSelectedAreaRange = function() {
var selections = cm.listSelections();
var start = selections[0];
var end = selections[selections.length-1];
var selectionStart = cursorIsBefore(start.anchor, start.head) ? start.anchor : start.head;
var selectionEnd = cursorIsBefore(end.anchor, end.head) ? end.head : end.anchor;
return [selectionStart, selectionEnd];
};
var getLastSelectedAreaRange = function() {
var selectionStart = cm.getCursor();
var selectionEnd = cm.getCursor();
var block = lastSelection.visualBlock;
if (block) {
var width = block.width;
var height = block.height;
selectionEnd = Pos(selectionStart.line + height, selectionStart.ch + width);
var selections = [];
// selectBlock creates a 'proper' rectangular block.
// We do not want that in all cases, so we manually set selections.
for (var i = selectionStart.line; i < selectionEnd.line; i++) {
var anchor = Pos(i, selectionStart.ch);
var head = Pos(i, selectionEnd.ch);
var range = {anchor: anchor, head: head};
selections.push(range);
}
cm.setSelections(selections);
} else {
var start = lastSelection.anchorMark.find();
var end = lastSelection.headMark.find();
var line = end.line - start.line;
var ch = end.ch - start.ch;
selectionEnd = {line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch};
if (lastSelection.visualLine) {
selectionStart = Pos(selectionStart.line, 0);
selectionEnd = Pos(selectionEnd.line, lineLength(cm, selectionEnd.line));
}
cm.setSelection(selectionStart, selectionEnd);
}
return [selectionStart, selectionEnd];
};
if (!vim.visualMode) {
// In case of replaying the action.
return getLastSelectedAreaRange();
} else {
return getCurrentSelectedAreaRange();
}
}
// Updates the previous selection with the current selection's values. This
// should only be called in visual mode.
function updateLastSelection(cm, vim) {
var anchor = vim.sel.anchor;
var head = vim.sel.head;
// To accommodate the effect of lastPastedText in the last selection
if (vim.lastPastedText) {
head = cm.posFromIndex(cm.indexFromPos(anchor) + vim.lastPastedText.length);
vim.lastPastedText = null;
}
vim.lastSelection = {'anchorMark': cm.setBookmark(anchor),
'headMark': cm.setBookmark(head),
'anchor': copyCursor(anchor),
'head': copyCursor(head),
'visualMode': vim.visualMode,
'visualLine': vim.visualLine,
'visualBlock': vim.visualBlock};
}
function expandSelection(cm, start, end) {
var sel = cm.state.vim.sel;
var head = sel.head;
var anchor = sel.anchor;
var tmp;
if (cursorIsBefore(end, start)) {
tmp = end;
end = start;
start = tmp;
}
if (cursorIsBefore(head, anchor)) {
head = cursorMin(start, head);
anchor = cursorMax(anchor, end);
} else {
anchor = cursorMin(start, anchor);
head = cursorMax(head, end);
head = offsetCursor(head, 0, -1);
if (head.ch == -1 && head.line != cm.firstLine()) {
head = Pos(head.line - 1, lineLength(cm, head.line - 1));
}
}
return [anchor, head];
}
/**
* Updates the CodeMirror selection to match the provided vim selection.
* If no arguments are given, it uses the current vim selection state.
*/
function updateCmSelection(cm, sel, mode) {
var vim = cm.state.vim;
sel = sel || vim.sel;
var mode = mode ||
vim.visualLine ? 'line' : vim.visualBlock ? 'block' : 'char';
var cmSel = makeCmSelection(cm, sel, mode);
cm.setSelections(cmSel.ranges, cmSel.primary);
updateFakeCursor(cm);
}
function makeCmSelection(cm, sel, mode, exclusive) {
var head = copyCursor(sel.head);
var anchor = copyCursor(sel.anchor);
if (mode == 'char') {
var headOffset = !exclusive && !cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
var anchorOffset = cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
head = offsetCursor(sel.head, 0, headOffset);
anchor = offsetCursor(sel.anchor, 0, anchorOffset);
return {
ranges: [{anchor: anchor, head: head}],
primary: 0
};
} else if (mode == 'line') {
if (!cursorIsBefore(sel.head, sel.anchor)) {
anchor.ch = 0;
var lastLine = cm.lastLine();
if (head.line > lastLine) {
head.line = lastLine;
}
head.ch = lineLength(cm, head.line);
} else {
head.ch = 0;
anchor.ch = lineLength(cm, anchor.line);
}
return {
ranges: [{anchor: anchor, head: head}],
primary: 0
};
} else if (mode == 'block') {
var top = Math.min(anchor.line, head.line),
left = Math.min(anchor.ch, head.ch),
bottom = Math.max(anchor.line, head.line),
right = Math.max(anchor.ch, head.ch) + 1;
var height = bottom - top + 1;
var primary = head.line == top ? 0 : height - 1;
var ranges = [];
for (var i = 0; i < height; i++) {
ranges.push({
anchor: Pos(top + i, left),
head: Pos(top + i, right)
});
}
return {
ranges: ranges,
primary: primary
};
}
}
function getHead(cm) {
var cur = cm.getCursor('head');
if (cm.getSelection().length == 1) {
// Small corner case when only 1 character is selected. The "real"
// head is the left of head and anchor.
cur = cursorMin(cur, cm.getCursor('anchor'));
}
return cur;
}
/**
* If moveHead is set to false, the CodeMirror selection will not be
* touched. The caller assumes the responsibility of putting the cursor
* in the right place.
*/
function exitVisualMode(cm, moveHead) {
var vim = cm.state.vim;
if (moveHead !== false) {
cm.setCursor(clipCursorToContent(cm, vim.sel.head));
}
updateLastSelection(cm, vim);
vim.visualMode = false;
vim.visualLine = false;
vim.visualBlock = false;
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
if (vim.fakeCursor) {
vim.fakeCursor.clear();
}
}
// Remove any trailing newlines from the selection. For
// example, with the caret at the start of the last word on the line,
// 'dw' should word, but not the newline, while 'w' should advance the
// caret to the first character of the next line.
function clipToLine(cm, curStart, curEnd) {
var selection = cm.getRange(curStart, curEnd);
// Only clip if the selection ends with trailing newline + whitespace
if (/\n\s*$/.test(selection)) {
var lines = selection.split('\n');
// We know this is all whitespace.
lines.pop();
// Cases:
// 1. Last word is an empty line - do not clip the trailing '\n'
// 2. Last word is not an empty line - clip the trailing '\n'
var line;
// Find the line containing the last word, and clip all whitespace up
// to it.
for (var line = lines.pop(); lines.length > 0 && line && isWhiteSpaceString(line); line = lines.pop()) {
curEnd.line--;
curEnd.ch = 0;
}
// If the last word is not an empty line, clip an additional newline
if (line) {
curEnd.line--;
curEnd.ch = lineLength(cm, curEnd.line);
} else {
curEnd.ch = 0;
}
}
}
// Expand the selection to line ends.
function expandSelectionToLine(_cm, curStart, curEnd) {
curStart.ch = 0;
curEnd.ch = 0;
curEnd.line++;
}
function findFirstNonWhiteSpaceCharacter(text) {
if (!text) {
return 0;
}
var firstNonWS = text.search(/\S/);
return firstNonWS == -1 ? text.length : firstNonWS;
}
function expandWordUnderCursor(cm, inclusive, _forward, bigWord, noSymbol) {
var cur = getHead(cm);
var line = cm.getLine(cur.line);
var idx = cur.ch;
// Seek to first word or non-whitespace character, depending on if
// noSymbol is true.
var test = noSymbol ? wordCharTest[0] : bigWordCharTest [0];
while (!test(line.charAt(idx))) {
idx++;
if (idx >= line.length) { return null; }
}
if (bigWord) {
test = bigWordCharTest[0];
} else {
test = wordCharTest[0];
if (!test(line.charAt(idx))) {
test = wordCharTest[1];
}
}
var end = idx, start = idx;
while (test(line.charAt(end)) && end < line.length) { end++; }
while (test(line.charAt(start)) && start >= 0) { start--; }
start++;
if (inclusive) {
// If present, include all whitespace after word.
// Otherwise, include all whitespace before word, except indentation.
var wordEnd = end;
while (/\s/.test(line.charAt(end)) && end < line.length) { end++; }
if (wordEnd == end) {
var wordStart = start;
while (/\s/.test(line.charAt(start - 1)) && start > 0) { start--; }
if (!start) { start = wordStart; }
}
}
return { start: Pos(cur.line, start), end: Pos(cur.line, end) };
}
function recordJumpPosition(cm, oldCur, newCur) {
if (!cursorEqual(oldCur, newCur)) {
vimGlobalState.jumpList.add(cm, oldCur, newCur);
}
}
function recordLastCharacterSearch(increment, args) {
vimGlobalState.lastCharacterSearch.increment = increment;
vimGlobalState.lastCharacterSearch.forward = args.forward;
vimGlobalState.lastCharacterSearch.selectedCharacter = args.selectedCharacter;
}
var symbolToMode = {
'(': 'bracket', ')': 'bracket', '{': 'bracket', '}': 'bracket',
'[': 'section', ']': 'section',
'*': 'comment', '/': 'comment',
'm': 'method', 'M': 'method',
'#': 'preprocess'
};
var findSymbolModes = {
bracket: {
isComplete: function(state) {
if (state.nextCh === state.symb) {
state.depth++;
if (state.depth >= 1)return true;
} else if (state.nextCh === state.reverseSymb) {
state.depth--;
}
return false;
}
},
section: {
init: function(state) {
state.curMoveThrough = true;
state.symb = (state.forward ? ']' : '[') === state.symb ? '{' : '}';
},
isComplete: function(state) {
return state.index === 0 && state.nextCh === state.symb;
}
},
comment: {
isComplete: function(state) {
var found = state.lastCh === '*' && state.nextCh === '/';
state.lastCh = state.nextCh;
return found;
}
},
// TODO: The original Vim implementation only operates on level 1 and 2.
// The current implementation doesn't check for code block level and
// therefore it operates on any levels.
method: {
init: function(state) {
state.symb = (state.symb === 'm' ? '{' : '}');
state.reverseSymb = state.symb === '{' ? '}' : '{';
},
isComplete: function(state) {
if (state.nextCh === state.symb)return true;
return false;
}
},
preprocess: {
init: function(state) {
state.index = 0;
},
isComplete: function(state) {
if (state.nextCh === '#') {
var token = state.lineText.match(/#(\w+)/)[1];
if (token === 'endif') {
if (state.forward && state.depth === 0) {
return true;
}
state.depth++;
} else if (token === 'if') {
if (!state.forward && state.depth === 0) {
return true;
}
state.depth--;
}
if (token === 'else' && state.depth === 0)return true;
}
return false;
}
}
};
function findSymbol(cm, repeat, forward, symb) {
var cur = copyCursor(cm.getCursor());
var increment = forward ? 1 : -1;
var endLine = forward ? cm.lineCount() : -1;
var curCh = cur.ch;
var line = cur.line;
var lineText = cm.getLine(line);
var state = {
lineText: lineText,
nextCh: lineText.charAt(curCh),
lastCh: null,
index: curCh,
symb: symb,
reverseSymb: (forward ? { ')': '(', '}': '{' } : { '(': ')', '{': '}' })[symb],
forward: forward,
depth: 0,
curMoveThrough: false
};
var mode = symbolToMode[symb];
if (!mode)return cur;
var init = findSymbolModes[mode].init;
var isComplete = findSymbolModes[mode].isComplete;
if (init) { init(state); }
while (line !== endLine && repeat) {
state.index += increment;
state.nextCh = state.lineText.charAt(state.index);
if (!state.nextCh) {
line += increment;
state.lineText = cm.getLine(line) || '';
if (increment > 0) {
state.index = 0;
} else {
var lineLen = state.lineText.length;
state.index = (lineLen > 0) ? (lineLen-1) : 0;
}
state.nextCh = state.lineText.charAt(state.index);
}
if (isComplete(state)) {
cur.line = line;
cur.ch = state.index;
repeat--;
}
}
if (state.nextCh || state.curMoveThrough) {
return Pos(line, state.index);
}
return cur;
}
/**
* Returns the boundaries of the next word. If the cursor in the middle of
* the word, then returns the boundaries of the current word, starting at
* the cursor. If the cursor is at the start/end of a word, and we are going
* forward/backward, respectively, find the boundaries of the next word.
*
* @param {CodeMirror} cm CodeMirror object.
* @param {Cursor} cur The cursor position.
* @param {boolean} forward True to search forward. False to search
* backward.
* @param {boolean} bigWord True if punctuation count as part of the word.
* False if only [a-zA-Z0-9] characters count as part of the word.
* @param {boolean} emptyLineIsWord True if empty lines should be treated
* as words.
* @return {Object{from:number, to:number, line: number}} The boundaries of
* the word, or null if there are no more words.
*/
function findWord(cm, cur, forward, bigWord, emptyLineIsWord) {
var lineNum = cur.line;
var pos = cur.ch;
var line = cm.getLine(lineNum);
var dir = forward ? 1 : -1;
var charTests = bigWord ? bigWordCharTest: wordCharTest;
if (emptyLineIsWord && line == '') {
lineNum += dir;
line = cm.getLine(lineNum);
if (!isLine(cm, lineNum)) {
return null;
}
pos = (forward) ? 0 : line.length;
}
while (true) {
if (emptyLineIsWord && line == '') {
return { from: 0, to: 0, line: lineNum };
}
var stop = (dir > 0) ? line.length : -1;
var wordStart = stop, wordEnd = stop;
// Find bounds of next word.
while (pos != stop) {
var foundWord = false;
for (var i = 0; i < charTests.length && !foundWord; ++i) {
if (charTests[i](line.charAt(pos))) {
wordStart = pos;
// Advance to end of word.
while (pos != stop && charTests[i](line.charAt(pos))) {
pos += dir;
}
wordEnd = pos;
foundWord = wordStart != wordEnd;
if (wordStart == cur.ch && lineNum == cur.line &&
wordEnd == wordStart + dir) {
// We started at the end of a word. Find the next one.
continue;
} else {
return {
from: Math.min(wordStart, wordEnd + 1),
to: Math.max(wordStart, wordEnd),
line: lineNum };
}
}
}
if (!foundWord) {
pos += dir;
}
}
// Advance to next/prev line.
lineNum += dir;
if (!isLine(cm, lineNum)) {
return null;
}
line = cm.getLine(lineNum);
pos = (dir > 0) ? 0 : line.length;
}
}
/**
* @param {CodeMirror} cm CodeMirror object.
* @param {Pos} cur The position to start from.
* @param {int} repeat Number of words to move past.
* @param {boolean} forward True to search forward. False to search
* backward.
* @param {boolean} wordEnd True to move to end of word. False to move to
* beginning of word.
* @param {boolean} bigWord True if punctuation count as part of the word.
* False if only alphabet characters count as part of the word.
* @return {Cursor} The position the cursor should move to.
*/
function moveToWord(cm, cur, repeat, forward, wordEnd, bigWord) {
var curStart = copyCursor(cur);
var words = [];
if (forward && !wordEnd || !forward && wordEnd) {
repeat++;
}
// For 'e', empty lines are not considered words, go figure.
var emptyLineIsWord = !(forward && wordEnd);
for (var i = 0; i < repeat; i++) {
var word = findWord(cm, cur, forward, bigWord, emptyLineIsWord);
if (!word) {
var eodCh = lineLength(cm, cm.lastLine());
words.push(forward
? {line: cm.lastLine(), from: eodCh, to: eodCh}
: {line: 0, from: 0, to: 0});
break;
}
words.push(word);
cur = Pos(word.line, forward ? (word.to - 1) : word.from);
}
var shortCircuit = words.length != repeat;
var firstWord = words[0];
var lastWord = words.pop();
if (forward && !wordEnd) {
// w
if (!shortCircuit && (firstWord.from != curStart.ch || firstWord.line != curStart.line)) {
// We did not start in the middle of a word. Discard the extra word at the end.
lastWord = words.pop();
}
return Pos(lastWord.line, lastWord.from);
} else if (forward && wordEnd) {
return Pos(lastWord.line, lastWord.to - 1);
} else if (!forward && wordEnd) {
// ge
if (!shortCircuit && (firstWord.to != curStart.ch || firstWord.line != curStart.line)) {
// We did not start in the middle of a word. Discard the extra word at the end.
lastWord = words.pop();
}
return Pos(lastWord.line, lastWord.to);
} else {
// b
return Pos(lastWord.line, lastWord.from);
}
}
function moveToCharacter(cm, repeat, forward, character) {
var cur = cm.getCursor();
var start = cur.ch;
var idx;
for (var i = 0; i < repeat; i ++) {
var line = cm.getLine(cur.line);
idx = charIdxInLine(start, line, character, forward, true);
if (idx == -1) {
return null;
}
start = idx;
}
return Pos(cm.getCursor().line, idx);
}
function moveToColumn(cm, repeat) {
// repeat is always >= 1, so repeat - 1 always corresponds
// to the column we want to go to.
var line = cm.getCursor().line;
return clipCursorToContent(cm, Pos(line, repeat - 1));
}
function updateMark(cm, vim, markName, pos) {
if (!inArray(markName, validMarks)) {
return;
}
if (vim.marks[markName]) {
vim.marks[markName].clear();
}
vim.marks[markName] = cm.setBookmark(pos);
}
function charIdxInLine(start, line, character, forward, includeChar) {
// Search for char in line.
// motion_options: {forward, includeChar}
// If includeChar = true, include it too.
// If forward = true, search forward, else search backwards.
// If char is not found on this line, do nothing
var idx;
if (forward) {
idx = line.indexOf(character, start + 1);
if (idx != -1 && !includeChar) {
idx -= 1;
}
} else {
idx = line.lastIndexOf(character, start - 1);
if (idx != -1 && !includeChar) {
idx += 1;
}
}
return idx;
}
function findParagraph(cm, head, repeat, dir, inclusive) {
var line = head.line;
var min = cm.firstLine();
var max = cm.lastLine();
var start, end, i = line;
function isEmpty(i) { return !cm.getLine(i); }
function isBoundary(i, dir, any) {
if (any) { return isEmpty(i) != isEmpty(i + dir); }
return !isEmpty(i) && isEmpty(i + dir);
}
if (dir) {
while (min <= i && i <= max && repeat > 0) {
if (isBoundary(i, dir)) { repeat--; }
i += dir;
}
return new Pos(i, 0);
}
var vim = cm.state.vim;
if (vim.visualLine && isBoundary(line, 1, true)) {
var anchor = vim.sel.anchor;
if (isBoundary(anchor.line, -1, true)) {
if (!inclusive || anchor.line != line) {
line += 1;
}
}
}
var startState = isEmpty(line);
for (i = line; i <= max && repeat; i++) {
if (isBoundary(i, 1, true)) {
if (!inclusive || isEmpty(i) != startState) {
repeat--;
}
}
}
end = new Pos(i, 0);
// select boundary before paragraph for the last one
if (i > max && !startState) { startState = true; }
else { inclusive = false; }
for (i = line; i > min; i--) {
if (!inclusive || isEmpty(i) == startState || i == line) {
if (isBoundary(i, -1, true)) { break; }
}
}
start = new Pos(i, 0);
return { start: start, end: end };
}
// TODO: perhaps this finagling of start and end positions belonds
// in codemirror/replaceRange?
function selectCompanionObject(cm, head, symb, inclusive) {
var cur = head, start, end;
var bracketRegexp = ({
'(': /[()]/, ')': /[()]/,
'[': /[[\]]/, ']': /[[\]]/,
'{': /[{}]/, '}': /[{}]/})[symb];
var openSym = ({
'(': '(', ')': '(',
'[': '[', ']': '[',
'{': '{', '}': '{'})[symb];
var curChar = cm.getLine(cur.line).charAt(cur.ch);
// Due to the behavior of scanForBracket, we need to add an offset if the
// cursor is on a matching open bracket.
var offset = curChar === openSym ? 1 : 0;
start = cm.scanForBracket(Pos(cur.line, cur.ch + offset), -1, null, {'bracketRegex': bracketRegexp});
end = cm.scanForBracket(Pos(cur.line, cur.ch + offset), 1, null, {'bracketRegex': bracketRegexp});
if (!start || !end) {
return { start: cur, end: cur };
}
start = start.pos;
end = end.pos;
if ((start.line == end.line && start.ch > end.ch)
|| (start.line > end.line)) {
var tmp = start;
start = end;
end = tmp;
}
if (inclusive) {
end.ch += 1;
} else {
start.ch += 1;
}
return { start: start, end: end };
}
// Takes in a symbol and a cursor and tries to simulate text objects that
// have identical opening and closing symbols
// TODO support across multiple lines
function findBeginningAndEnd(cm, head, symb, inclusive) {
var cur = copyCursor(head);
var line = cm.getLine(cur.line);
var chars = line.split('');
var start, end, i, len;
var firstIndex = chars.indexOf(symb);
// the decision tree is to always look backwards for the beginning first,
// but if the cursor is in front of the first instance of the symb,
// then move the cursor forward
if (cur.ch < firstIndex) {
cur.ch = firstIndex;
// Why is this line even here???
// cm.setCursor(cur.line, firstIndex+1);
}
// otherwise if the cursor is currently on the closing symbol
else if (firstIndex < cur.ch && chars[cur.ch] == symb) {
end = cur.ch; // assign end to the current cursor
--cur.ch; // make sure to look backwards
}
// if we're currently on the symbol, we've got a start
if (chars[cur.ch] == symb && !end) {
start = cur.ch + 1; // assign start to ahead of the cursor
} else {
// go backwards to find the start
for (i = cur.ch; i > -1 && !start; i--) {
if (chars[i] == symb) {
start = i + 1;
}
}
}
// look forwards for the end symbol
if (start && !end) {
for (i = start, len = chars.length; i < len && !end; i++) {
if (chars[i] == symb) {
end = i;
}
}
}
// nothing found
if (!start || !end) {
return { start: cur, end: cur };
}
// include the symbols
if (inclusive) {
--start; ++end;
}
return {
start: Pos(cur.line, start),
end: Pos(cur.line, end)
};
}
// Search functions
defineOption('pcre', true, 'boolean');
function SearchState() {}
SearchState.prototype = {
getQuery: function() {
return vimGlobalState.query;
},
setQuery: function(query) {
vimGlobalState.query = query;
},
getOverlay: function() {
return this.searchOverlay;
},
setOverlay: function(overlay) {
this.searchOverlay = overlay;
},
isReversed: function() {
return vimGlobalState.isReversed;
},
setReversed: function(reversed) {
vimGlobalState.isReversed = reversed;
},
getScrollbarAnnotate: function() {
return this.annotate;
},
setScrollbarAnnotate: function(annotate) {
this.annotate = annotate;
}
};
function getSearchState(cm) {
var vim = cm.state.vim;
return vim.searchState_ || (vim.searchState_ = new SearchState());
}
function dialog(cm, template, shortText, onClose, options) {
if (cm.openDialog) {
cm.openDialog(template, onClose, { bottom: true, value: options.value,
onKeyDown: options.onKeyDown, onKeyUp: options.onKeyUp,
selectValueOnOpen: false});
}
else {
onClose(prompt(shortText, ''));
}
}
function splitBySlash(argString) {
var slashes = findUnescapedSlashes(argString) || [];
if (!slashes.length) return [];
var tokens = [];
// in case of strings like foo/bar
if (slashes[0] !== 0) return;
for (var i = 0; i < slashes.length; i++) {
if (typeof slashes[i] == 'number')
tokens.push(argString.substring(slashes[i] + 1, slashes[i+1]));
}
return tokens;
}
function findUnescapedSlashes(str) {
var escapeNextChar = false;
var slashes = [];
for (var i = 0; i < str.length; i++) {
var c = str.charAt(i);
if (!escapeNextChar && c == '/') {
slashes.push(i);
}
escapeNextChar = !escapeNextChar && (c == '\\');
}
return slashes;
}
// Translates a search string from ex (vim) syntax into javascript form.
function translateRegex(str) {
// When these match, add a '\' if unescaped or remove one if escaped.
var specials = '|(){';
// Remove, but never add, a '\' for these.
var unescape = '}';
var escapeNextChar = false;
var out = [];
for (var i = -1; i < str.length; i++) {
var c = str.charAt(i) || '';
var n = str.charAt(i+1) || '';
var specialComesNext = (n && specials.indexOf(n) != -1);
if (escapeNextChar) {
if (c !== '\\' || !specialComesNext) {
out.push(c);
}
escapeNextChar = false;
} else {
if (c === '\\') {
escapeNextChar = true;
// Treat the unescape list as special for removing, but not adding '\'.
if (n && unescape.indexOf(n) != -1) {
specialComesNext = true;
}
// Not passing this test means removing a '\'.
if (!specialComesNext || n === '\\') {
out.push(c);
}
} else {
out.push(c);
if (specialComesNext && n !== '\\') {
out.push('\\');
}
}
}
}
return out.join('');
}
// Translates the replace part of a search and replace from ex (vim) syntax into
// javascript form. Similar to translateRegex, but additionally fixes back references
// (translates '\[0..9]' to '$[0..9]') and follows different rules for escaping '$'.
var charUnescapes = {'\\n': '\n', '\\r': '\r', '\\t': '\t'};
function translateRegexReplace(str) {
var escapeNextChar = false;
var out = [];
for (var i = -1; i < str.length; i++) {
var c = str.charAt(i) || '';
var n = str.charAt(i+1) || '';
if (charUnescapes[c + n]) {
out.push(charUnescapes[c+n]);
i++;
} else if (escapeNextChar) {
// At any point in the loop, escapeNextChar is true if the previous
// character was a '\' and was not escaped.
out.push(c);
escapeNextChar = false;
} else {
if (c === '\\') {
escapeNextChar = true;
if ((isNumber(n) || n === '$')) {
out.push('$');
} else if (n !== '/' && n !== '\\') {
out.push('\\');
}
} else {
if (c === '$') {
out.push('$');
}
out.push(c);
if (n === '/') {
out.push('\\');
}
}
}
}
return out.join('');
}
// Unescape \ and / in the replace part, for PCRE mode.
var unescapes = {'\\/': '/', '\\\\': '\\', '\\n': '\n', '\\r': '\r', '\\t': '\t'};
function unescapeRegexReplace(str) {
var stream = new CodeMirror.StringStream(str);
var output = [];
while (!stream.eol()) {
// Search for \.
while (stream.peek() && stream.peek() != '\\') {
output.push(stream.next());
}
var matched = false;
for (var matcher in unescapes) {
if (stream.match(matcher, true)) {
matched = true;
output.push(unescapes[matcher]);
break;
}
}
if (!matched) {
// Don't change anything
output.push(stream.next());
}
}
return output.join('');
}
/**
* Extract the regular expression from the query and return a Regexp object.
* Returns null if the query is blank.
* If ignoreCase is passed in, the Regexp object will have the 'i' flag set.
* If smartCase is passed in, and the query contains upper case letters,
* then ignoreCase is overridden, and the 'i' flag will not be set.
* If the query contains the /i in the flag part of the regular expression,
* then both ignoreCase and smartCase are ignored, and 'i' will be passed
* through to the Regex object.
*/
function parseQuery(query, ignoreCase, smartCase) {
// First update the last search register
var lastSearchRegister = vimGlobalState.registerController.getRegister('/');
lastSearchRegister.setText(query);
// Check if the query is already a regex.
if (query instanceof RegExp) { return query; }
// First try to extract regex + flags from the input. If no flags found,
// extract just the regex. IE does not accept flags directly defined in
// the regex string in the form /regex/flags
var slashes = findUnescapedSlashes(query);
var regexPart;
var forceIgnoreCase;
if (!slashes.length) {
// Query looks like 'regexp'
regexPart = query;
} else {
// Query looks like 'regexp/...'
regexPart = query.substring(0, slashes[0]);
var flagsPart = query.substring(slashes[0]);
forceIgnoreCase = (flagsPart.indexOf('i') != -1);
}
if (!regexPart) {
return null;
}
if (!getOption('pcre')) {
regexPart = translateRegex(regexPart);
}
if (smartCase) {
ignoreCase = (/^[^A-Z]*$/).test(regexPart);
}
var regexp = new RegExp(regexPart,
(ignoreCase || forceIgnoreCase) ? 'i' : undefined);
return regexp;
}
function showConfirm(cm, text) {
if (cm.openNotification) {
cm.openNotification('<span style="color: red">' + text + '</span>',
{bottom: true, duration: 5000});
} else {
alert(text);
}
}
function makePrompt(prefix, desc) {
var raw = '<span style="font-family: monospace; white-space: pre">' +
(prefix || "") + '<input type="text"></span>';
if (desc)
raw += ' <span style="color: #888">' + desc + '</span>';
return raw;
}
var searchPromptDesc = '(Javascript regexp)';
function showPrompt(cm, options) {
var shortText = (options.prefix || '') + ' ' + (options.desc || '');
var prompt = makePrompt(options.prefix, options.desc);
dialog(cm, prompt, shortText, options.onClose, options);
}
function regexEqual(r1, r2) {
if (r1 instanceof RegExp && r2 instanceof RegExp) {
var props = ['global', 'multiline', 'ignoreCase', 'source'];
for (var i = 0; i < props.length; i++) {
var prop = props[i];
if (r1[prop] !== r2[prop]) {
return false;
}
}
return true;
}
return false;
}
// Returns true if the query is valid.
function updateSearchQuery(cm, rawQuery, ignoreCase, smartCase) {
if (!rawQuery) {
return;
}
var state = getSearchState(cm);
var query = parseQuery(rawQuery, !!ignoreCase, !!smartCase);
if (!query) {
return;
}
highlightSearchMatches(cm, query);
if (regexEqual(query, state.getQuery())) {
return query;
}
state.setQuery(query);
return query;
}
function searchOverlay(query) {
if (query.source.charAt(0) == '^') {
var matchSol = true;
}
return {
token: function(stream) {
if (matchSol && !stream.sol()) {
stream.skipToEnd();
return;
}
var match = stream.match(query, false);
if (match) {
if (match[0].length == 0) {
// Matched empty string, skip to next.
stream.next();
return 'searching';
}
if (!stream.sol()) {
// Backtrack 1 to match \b
stream.backUp(1);
if (!query.exec(stream.next() + match[0])) {
stream.next();
return null;
}
}
stream.match(query);
return 'searching';
}
while (!stream.eol()) {
stream.next();
if (stream.match(query, false)) break;
}
},
query: query
};
}
function highlightSearchMatches(cm, query) {
var searchState = getSearchState(cm);
var overlay = searchState.getOverlay();
if (!overlay || query != overlay.query) {
if (overlay) {
cm.removeOverlay(overlay);
}
overlay = searchOverlay(query);
cm.addOverlay(overlay);
if (cm.showMatchesOnScrollbar) {
if (searchState.getScrollbarAnnotate()) {
searchState.getScrollbarAnnotate().clear();
}
searchState.setScrollbarAnnotate(cm.showMatchesOnScrollbar(query));
}
searchState.setOverlay(overlay);
}
}
function findNext(cm, prev, query, repeat) {
if (repeat === undefined) { repeat = 1; }
return cm.operation(function() {
var pos = cm.getCursor();
var cursor = cm.getSearchCursor(query, pos);
for (var i = 0; i < repeat; i++) {
var found = cursor.find(prev);
if (i == 0 && found && cursorEqual(cursor.from(), pos)) { found = cursor.find(prev); }
if (!found) {
// SearchCursor may have returned null because it hit EOF, wrap
// around and try again.
cursor = cm.getSearchCursor(query,
(prev) ? Pos(cm.lastLine()) : Pos(cm.firstLine(), 0) );
if (!cursor.find(prev)) {
return;
}
}
}
return cursor.from();
});
}
function clearSearchHighlight(cm) {
var state = getSearchState(cm);
cm.removeOverlay(getSearchState(cm).getOverlay());
state.setOverlay(null);
if (state.getScrollbarAnnotate()) {
state.getScrollbarAnnotate().clear();
state.setScrollbarAnnotate(null);
}
}
/**
* Check if pos is in the specified range, INCLUSIVE.
* Range can be specified with 1 or 2 arguments.
* If the first range argument is an array, treat it as an array of line
* numbers. Match pos against any of the lines.
* If the first range argument is a number,
* if there is only 1 range argument, check if pos has the same line
* number
* if there are 2 range arguments, then check if pos is in between the two
* range arguments.
*/
function isInRange(pos, start, end) {
if (typeof pos != 'number') {
// Assume it is a cursor position. Get the line number.
pos = pos.line;
}
if (start instanceof Array) {
return inArray(pos, start);
} else {
if (end) {
return (pos >= start && pos <= end);
} else {
return pos == start;
}
}
}
function getUserVisibleLines(cm) {
var scrollInfo = cm.getScrollInfo();
var occludeToleranceTop = 6;
var occludeToleranceBottom = 10;
var from = cm.coordsChar({left:0, top: occludeToleranceTop + scrollInfo.top}, 'local');
var bottomY = scrollInfo.clientHeight - occludeToleranceBottom + scrollInfo.top;
var to = cm.coordsChar({left:0, top: bottomY}, 'local');
return {top: from.line, bottom: to.line};
}
function getMarkPos(cm, vim, markName) {
if (markName == '\'') {
var history = cm.doc.history.done;
var event = history[history.length - 2];
return event && event.ranges && event.ranges[0].head;
}
var mark = vim.marks[markName];
return mark && mark.find();
}
var ExCommandDispatcher = function() {
this.buildCommandMap_();
};
ExCommandDispatcher.prototype = {
processCommand: function(cm, input, opt_params) {
var that = this;
cm.operation(function () {
cm.curOp.isVimOp = true;
that._processCommand(cm, input, opt_params);
});
},
_processCommand: function(cm, input, opt_params) {
var vim = cm.state.vim;
var commandHistoryRegister = vimGlobalState.registerController.getRegister(':');
var previousCommand = commandHistoryRegister.toString();
if (vim.visualMode) {
exitVisualMode(cm);
}
var inputStream = new CodeMirror.StringStream(input);
// update ": with the latest command whether valid or invalid
commandHistoryRegister.setText(input);
var params = opt_params || {};
params.input = input;
try {
this.parseInput_(cm, inputStream, params);
} catch(e) {
showConfirm(cm, e);
throw e;
}
var command;
var commandName;
if (!params.commandName) {
// If only a line range is defined, move to the line.
if (params.line !== undefined) {
commandName = 'move';
}
} else {
command = this.matchCommand_(params.commandName);
if (command) {
commandName = command.name;
if (command.excludeFromCommandHistory) {
commandHistoryRegister.setText(previousCommand);
}
this.parseCommandArgs_(inputStream, params, command);
if (command.type == 'exToKey') {
// Handle Ex to Key mapping.
for (var i = 0; i < command.toKeys.length; i++) {
CodeMirror.Vim.handleKey(cm, command.toKeys[i], 'mapping');
}
return;
} else if (command.type == 'exToEx') {
// Handle Ex to Ex mapping.
this.processCommand(cm, command.toInput);
return;
}
}
}
if (!commandName) {
showConfirm(cm, 'Not an editor command ":' + input + '"');
return;
}
try {
exCommands[commandName](cm, params);
// Possibly asynchronous commands (e.g. substitute, which might have a
// user confirmation), are responsible for calling the callback when
// done. All others have it taken care of for them here.
if ((!command || !command.possiblyAsync) && params.callback) {
params.callback();
}
} catch(e) {
showConfirm(cm, e);
throw e;
}
},
parseInput_: function(cm, inputStream, result) {
inputStream.eatWhile(':');
// Parse range.
if (inputStream.eat('%')) {
result.line = cm.firstLine();
result.lineEnd = cm.lastLine();
} else {
result.line = this.parseLineSpec_(cm, inputStream);
if (result.line !== undefined && inputStream.eat(',')) {
result.lineEnd = this.parseLineSpec_(cm, inputStream);
}
}
// Parse command name.
var commandMatch = inputStream.match(/^(\w+)/);
if (commandMatch) {
result.commandName = commandMatch[1];
} else {
result.commandName = inputStream.match(/.*/)[0];
}
return result;
},
parseLineSpec_: function(cm, inputStream) {
var numberMatch = inputStream.match(/^(\d+)/);
if (numberMatch) {
return parseInt(numberMatch[1], 10) - 1;
}
switch (inputStream.next()) {
case '.':
return cm.getCursor().line;
case '$':
return cm.lastLine();
case '\'':
var markName = inputStream.next();
var markPos = getMarkPos(cm, cm.state.vim, markName);
if (!markPos) throw new Error('Mark not set');
return markPos.line;
default:
inputStream.backUp(1);
return undefined;
}
},
parseCommandArgs_: function(inputStream, params, command) {
if (inputStream.eol()) {
return;
}
params.argString = inputStream.match(/.*/)[0];
// Parse command-line arguments
var delim = command.argDelimiter || /\s+/;
var args = trim(params.argString).split(delim);
if (args.length && args[0]) {
params.args = args;
}
},
matchCommand_: function(commandName) {
// Return the command in the command map that matches the shortest
// prefix of the passed in command name. The match is guaranteed to be
// unambiguous if the defaultExCommandMap's shortNames are set up
// correctly. (see @code{defaultExCommandMap}).
for (var i = commandName.length; i > 0; i--) {
var prefix = commandName.substring(0, i);
if (this.commandMap_[prefix]) {
var command = this.commandMap_[prefix];
if (command.name.indexOf(commandName) === 0) {
return command;
}
}
}
return null;
},
buildCommandMap_: function() {
this.commandMap_ = {};
for (var i = 0; i < defaultExCommandMap.length; i++) {
var command = defaultExCommandMap[i];
var key = command.shortName || command.name;
this.commandMap_[key] = command;
}
},
map: function(lhs, rhs, ctx) {
if (lhs != ':' && lhs.charAt(0) == ':') {
if (ctx) { throw Error('Mode not supported for ex mappings'); }
var commandName = lhs.substring(1);
if (rhs != ':' && rhs.charAt(0) == ':') {
// Ex to Ex mapping
this.commandMap_[commandName] = {
name: commandName,
type: 'exToEx',
toInput: rhs.substring(1),
user: true
};
} else {
// Ex to key mapping
this.commandMap_[commandName] = {
name: commandName,
type: 'exToKey',
toKeys: rhs,
user: true
};
}
} else {
if (rhs != ':' && rhs.charAt(0) == ':') {
// Key to Ex mapping.
var mapping = {
keys: lhs,
type: 'keyToEx',
exArgs: { input: rhs.substring(1) }
};
if (ctx) { mapping.context = ctx; }
defaultKeymap.unshift(mapping);
} else {
// Key to key mapping
var mapping = {
keys: lhs,
type: 'keyToKey',
toKeys: rhs
};
if (ctx) { mapping.context = ctx; }
defaultKeymap.unshift(mapping);
}
}
},
unmap: function(lhs, ctx) {
if (lhs != ':' && lhs.charAt(0) == ':') {
// Ex to Ex or Ex to key mapping
if (ctx) { throw Error('Mode not supported for ex mappings'); }
var commandName = lhs.substring(1);
if (this.commandMap_[commandName] && this.commandMap_[commandName].user) {
delete this.commandMap_[commandName];
return;
}
} else {
// Key to Ex or key to key mapping
var keys = lhs;
for (var i = 0; i < defaultKeymap.length; i++) {
if (keys == defaultKeymap[i].keys
&& defaultKeymap[i].context === ctx) {
defaultKeymap.splice(i, 1);
return;
}
}
}
throw Error('No such mapping.');
}
};
var exCommands = {
colorscheme: function(cm, params) {
if (!params.args || params.args.length < 1) {
showConfirm(cm, cm.getOption('theme'));
return;
}
cm.setOption('theme', params.args[0]);
},
map: function(cm, params, ctx) {
var mapArgs = params.args;
if (!mapArgs || mapArgs.length < 2) {
if (cm) {
showConfirm(cm, 'Invalid mapping: ' + params.input);
}
return;
}
exCommandDispatcher.map(mapArgs[0], mapArgs[1], ctx);
},
imap: function(cm, params) { this.map(cm, params, 'insert'); },
nmap: function(cm, params) { this.map(cm, params, 'normal'); },
vmap: function(cm, params) { this.map(cm, params, 'visual'); },
unmap: function(cm, params, ctx) {
var mapArgs = params.args;
if (!mapArgs || mapArgs.length < 1) {
if (cm) {
showConfirm(cm, 'No such mapping: ' + params.input);
}
return;
}
exCommandDispatcher.unmap(mapArgs[0], ctx);
},
move: function(cm, params) {
commandDispatcher.processCommand(cm, cm.state.vim, {
type: 'motion',
motion: 'moveToLineOrEdgeOfDocument',
motionArgs: { forward: false, explicitRepeat: true,
linewise: true },
repeatOverride: params.line+1});
},
set: function(cm, params) {
var setArgs = params.args;
// Options passed through to the setOption/getOption calls. May be passed in by the
// local/global versions of the set command
var setCfg = params.setCfg || {};
if (!setArgs || setArgs.length < 1) {
if (cm) {
showConfirm(cm, 'Invalid mapping: ' + params.input);
}
return;
}
var expr = setArgs[0].split('=');
var optionName = expr[0];
var value = expr[1];
var forceGet = false;
if (optionName.charAt(optionName.length - 1) == '?') {
// If post-fixed with ?, then the set is actually a get.
if (value) { throw Error('Trailing characters: ' + params.argString); }
optionName = optionName.substring(0, optionName.length - 1);
forceGet = true;
}
if (value === undefined && optionName.substring(0, 2) == 'no') {
// To set boolean options to false, the option name is prefixed with
// 'no'.
optionName = optionName.substring(2);
value = false;
}
var optionIsBoolean = options[optionName] && options[optionName].type == 'boolean';
if (optionIsBoolean && value == undefined) {
// Calling set with a boolean option sets it to true.
value = true;
}
// If no value is provided, then we assume this is a get.
if (!optionIsBoolean && value === undefined || forceGet) {
var oldValue = getOption(optionName, cm, setCfg);
if (oldValue === true || oldValue === false) {
showConfirm(cm, ' ' + (oldValue ? '' : 'no') + optionName);
} else {
showConfirm(cm, ' ' + optionName + '=' + oldValue);
}
} else {
setOption(optionName, value, cm, setCfg);
}
},
setlocal: function (cm, params) {
// setCfg is passed through to setOption
params.setCfg = {scope: 'local'};
this.set(cm, params);
},
setglobal: function (cm, params) {
// setCfg is passed through to setOption
params.setCfg = {scope: 'global'};
this.set(cm, params);
},
registers: function(cm, params) {
var regArgs = params.args;
var registers = vimGlobalState.registerController.registers;
var regInfo = '----------Registers----------<br><br>';
if (!regArgs) {
for (var registerName in registers) {
var text = registers[registerName].toString();
if (text.length) {
regInfo += '"' + registerName + ' ' + text + '<br>';
}
}
} else {
var registerName;
regArgs = regArgs.join('');
for (var i = 0; i < regArgs.length; i++) {
registerName = regArgs.charAt(i);
if (!vimGlobalState.registerController.isValidRegister(registerName)) {
continue;
}
var register = registers[registerName] || new Register();
regInfo += '"' + registerName + ' ' + register.toString() + '<br>';
}
}
showConfirm(cm, regInfo);
},
sort: function(cm, params) {
var reverse, ignoreCase, unique, number, pattern;
function parseArgs() {
if (params.argString) {
var args = new CodeMirror.StringStream(params.argString);
if (args.eat('!')) { reverse = true; }
if (args.eol()) { return; }
if (!args.eatSpace()) { return 'Invalid arguments'; }
var opts = args.match(/([dinuox]+)?\s*(\/.+\/)?\s*/);
if (!opts && !args.eol()) { return 'Invalid arguments'; }
if (opts[1]) {
ignoreCase = opts[1].indexOf('i') != -1;
unique = opts[1].indexOf('u') != -1;
var decimal = opts[1].indexOf('d') != -1 || opts[1].indexOf('n') != -1 && 1;
var hex = opts[1].indexOf('x') != -1 && 1;
var octal = opts[1].indexOf('o') != -1 && 1;
if (decimal + hex + octal > 1) { return 'Invalid arguments'; }
number = decimal && 'decimal' || hex && 'hex' || octal && 'octal';
}
if (opts[2]) {
pattern = new RegExp(opts[2].substr(1, opts[2].length - 2), ignoreCase ? 'i' : '');
}
}
}
var err = parseArgs();
if (err) {
showConfirm(cm, err + ': ' + params.argString);
return;
}
var lineStart = params.line || cm.firstLine();
var lineEnd = params.lineEnd || params.line || cm.lastLine();
if (lineStart == lineEnd) { return; }
var curStart = Pos(lineStart, 0);
var curEnd = Pos(lineEnd, lineLength(cm, lineEnd));
var text = cm.getRange(curStart, curEnd).split('\n');
var numberRegex = pattern ? pattern :
(number == 'decimal') ? /(-?)([\d]+)/ :
(number == 'hex') ? /(-?)(?:0x)?([0-9a-f]+)/i :
(number == 'octal') ? /([0-7]+)/ : null;
var radix = (number == 'decimal') ? 10 : (number == 'hex') ? 16 : (number == 'octal') ? 8 : null;
var numPart = [], textPart = [];
if (number || pattern) {
for (var i = 0; i < text.length; i++) {
var matchPart = pattern ? text[i].match(pattern) : null;
if (matchPart && matchPart[0] != '') {
numPart.push(matchPart);
} else if (!pattern && numberRegex.exec(text[i])) {
numPart.push(text[i]);
} else {
textPart.push(text[i]);
}
}
} else {
textPart = text;
}
function compareFn(a, b) {
if (reverse) { var tmp; tmp = a; a = b; b = tmp; }
if (ignoreCase) { a = a.toLowerCase(); b = b.toLowerCase(); }
var anum = number && numberRegex.exec(a);
var bnum = number && numberRegex.exec(b);
if (!anum) { return a < b ? -1 : 1; }
anum = parseInt((anum[1] + anum[2]).toLowerCase(), radix);
bnum = parseInt((bnum[1] + bnum[2]).toLowerCase(), radix);
return anum - bnum;
}
function comparePatternFn(a, b) {
if (reverse) { var tmp; tmp = a; a = b; b = tmp; }
if (ignoreCase) { a[0] = a[0].toLowerCase(); b[0] = b[0].toLowerCase(); }
return (a[0] < b[0]) ? -1 : 1;
}
numPart.sort(pattern ? comparePatternFn : compareFn);
if (pattern) {
for (var i = 0; i < numPart.length; i++) {
numPart[i] = numPart[i].input;
}
} else if (!number) { textPart.sort(compareFn); }
text = (!reverse) ? textPart.concat(numPart) : numPart.concat(textPart);
if (unique) { // Remove duplicate lines
var textOld = text;
var lastLine;
text = [];
for (var i = 0; i < textOld.length; i++) {
if (textOld[i] != lastLine) {
text.push(textOld[i]);
}
lastLine = textOld[i];
}
}
cm.replaceRange(text.join('\n'), curStart, curEnd);
},
global: function(cm, params) {
// a global command is of the form
// :[range]g/pattern/[cmd]
// argString holds the string /pattern/[cmd]
var argString = params.argString;
if (!argString) {
showConfirm(cm, 'Regular Expression missing from global');
return;
}
// range is specified here
var lineStart = (params.line !== undefined) ? params.line : cm.firstLine();
var lineEnd = params.lineEnd || params.line || cm.lastLine();
// get the tokens from argString
var tokens = splitBySlash(argString);
var regexPart = argString, cmd;
if (tokens.length) {
regexPart = tokens[0];
cmd = tokens.slice(1, tokens.length).join('/');
}
if (regexPart) {
// If regex part is empty, then use the previous query. Otherwise
// use the regex part as the new query.
try {
updateSearchQuery(cm, regexPart, true /** ignoreCase */,
true /** smartCase */);
} catch (e) {
showConfirm(cm, 'Invalid regex: ' + regexPart);
return;
}
}
// now that we have the regexPart, search for regex matches in the
// specified range of lines
var query = getSearchState(cm).getQuery();
var matchedLines = [], content = '';
for (var i = lineStart; i <= lineEnd; i++) {
var matched = query.test(cm.getLine(i));
if (matched) {
matchedLines.push(i+1);
content+= cm.getLine(i) + '<br>';
}
}
// if there is no [cmd], just display the list of matched lines
if (!cmd) {
showConfirm(cm, content);
return;
}
var index = 0;
var nextCommand = function() {
if (index < matchedLines.length) {
var command = matchedLines[index] + cmd;
exCommandDispatcher.processCommand(cm, command, {
callback: nextCommand
});
}
index++;
};
nextCommand();
},
substitute: function(cm, params) {
if (!cm.getSearchCursor) {
throw new Error('Search feature not available. Requires searchcursor.js or ' +
'any other getSearchCursor implementation.');
}
var argString = params.argString;
var tokens = argString ? splitBySlash(argString) : [];
var regexPart, replacePart = '', trailing, flagsPart, count;
var confirm = false; // Whether to confirm each replace.
var global = false; // True to replace all instances on a line, false to replace only 1.
if (tokens.length) {
regexPart = tokens[0];
replacePart = tokens[1];
if (replacePart !== undefined) {
if (getOption('pcre')) {
replacePart = unescapeRegexReplace(replacePart);
} else {
replacePart = translateRegexReplace(replacePart);
}
vimGlobalState.lastSubstituteReplacePart = replacePart;
}
trailing = tokens[2] ? tokens[2].split(' ') : [];
} else {
// either the argString is empty or its of the form ' hello/world'
// actually splitBySlash returns a list of tokens
// only if the string starts with a '/'
if (argString && argString.length) {
showConfirm(cm, 'Substitutions should be of the form ' +
':s/pattern/replace/');
return;
}
}
// After the 3rd slash, we can have flags followed by a space followed
// by count.
if (trailing) {
flagsPart = trailing[0];
count = parseInt(trailing[1]);
if (flagsPart) {
if (flagsPart.indexOf('c') != -1) {
confirm = true;
flagsPart.replace('c', '');
}
if (flagsPart.indexOf('g') != -1) {
global = true;
flagsPart.replace('g', '');
}
regexPart = regexPart + '/' + flagsPart;
}
}
if (regexPart) {
// If regex part is empty, then use the previous query. Otherwise use
// the regex part as the new query.
try {
updateSearchQuery(cm, regexPart, true /** ignoreCase */,
true /** smartCase */);
} catch (e) {
showConfirm(cm, 'Invalid regex: ' + regexPart);
return;
}
}
replacePart = replacePart || vimGlobalState.lastSubstituteReplacePart;
if (replacePart === undefined) {
showConfirm(cm, 'No previous substitute regular expression');
return;
}
var state = getSearchState(cm);
var query = state.getQuery();
var lineStart = (params.line !== undefined) ? params.line : cm.getCursor().line;
var lineEnd = params.lineEnd || lineStart;
if (lineStart == cm.firstLine() && lineEnd == cm.lastLine()) {
lineEnd = Infinity;
}
if (count) {
lineStart = lineEnd;
lineEnd = lineStart + count - 1;
}
var startPos = clipCursorToContent(cm, Pos(lineStart, 0));
var cursor = cm.getSearchCursor(query, startPos);
doReplace(cm, confirm, global, lineStart, lineEnd, cursor, query, replacePart, params.callback);
},
redo: CodeMirror.commands.redo,
undo: CodeMirror.commands.undo,
write: function(cm) {
if (CodeMirror.commands.save) {
// If a save command is defined, call it.
CodeMirror.commands.save(cm);
} else if (cm.save) {
// Saves to text area if no save command is defined and cm.save() is available.
cm.save();
}
},
nohlsearch: function(cm) {
clearSearchHighlight(cm);
},
yank: function (cm) {
var cur = copyCursor(cm.getCursor());
var line = cur.line;
var lineText = cm.getLine(line);
vimGlobalState.registerController.pushText(
'0', 'yank', lineText, true, true);
},
delmarks: function(cm, params) {
if (!params.argString || !trim(params.argString)) {
showConfirm(cm, 'Argument required');
return;
}
var state = cm.state.vim;
var stream = new CodeMirror.StringStream(trim(params.argString));
while (!stream.eol()) {
stream.eatSpace();
// Record the streams position at the beginning of the loop for use
// in error messages.
var count = stream.pos;
if (!stream.match(/[a-zA-Z]/, false)) {
showConfirm(cm, 'Invalid argument: ' + params.argString.substring(count));
return;
}
var sym = stream.next();
// Check if this symbol is part of a range
if (stream.match('-', true)) {
// This symbol is part of a range.
// The range must terminate at an alphabetic character.
if (!stream.match(/[a-zA-Z]/, false)) {
showConfirm(cm, 'Invalid argument: ' + params.argString.substring(count));
return;
}
var startMark = sym;
var finishMark = stream.next();
// The range must terminate at an alphabetic character which
// shares the same case as the start of the range.
if (isLowerCase(startMark) && isLowerCase(finishMark) ||
isUpperCase(startMark) && isUpperCase(finishMark)) {
var start = startMark.charCodeAt(0);
var finish = finishMark.charCodeAt(0);
if (start >= finish) {
showConfirm(cm, 'Invalid argument: ' + params.argString.substring(count));
return;
}
// Because marks are always ASCII values, and we have
// determined that they are the same case, we can use
// their char codes to iterate through the defined range.
for (var j = 0; j <= finish - start; j++) {
var mark = String.fromCharCode(start + j);
delete state.marks[mark];
}
} else {
showConfirm(cm, 'Invalid argument: ' + startMark + '-');
return;
}
} else {
// This symbol is a valid mark, and is not part of a range.
delete state.marks[sym];
}
}
}
};
var exCommandDispatcher = new ExCommandDispatcher();
/**
* @param {CodeMirror} cm CodeMirror instance we are in.
* @param {boolean} confirm Whether to confirm each replace.
* @param {Cursor} lineStart Line to start replacing from.
* @param {Cursor} lineEnd Line to stop replacing at.
* @param {RegExp} query Query for performing matches with.
* @param {string} replaceWith Text to replace matches with. May contain $1,
* $2, etc for replacing captured groups using Javascript replace.
* @param {function()} callback A callback for when the replace is done.
*/
function doReplace(cm, confirm, global, lineStart, lineEnd, searchCursor, query,
replaceWith, callback) {
// Set up all the functions.
cm.state.vim.exMode = true;
var done = false;
var lastPos = searchCursor.from();
function replaceAll() {
cm.operation(function() {
while (!done) {
replace();
next();
}
stop();
});
}
function replace() {
var text = cm.getRange(searchCursor.from(), searchCursor.to());
var newText = text.replace(query, replaceWith);
searchCursor.replace(newText);
}
function next() {
// The below only loops to skip over multiple occurrences on the same
// line when 'global' is not true.
while(searchCursor.findNext() &&
isInRange(searchCursor.from(), lineStart, lineEnd)) {
if (!global && lastPos && searchCursor.from().line == lastPos.line) {
continue;
}
cm.scrollIntoView(searchCursor.from(), 30);
cm.setSelection(searchCursor.from(), searchCursor.to());
lastPos = searchCursor.from();
done = false;
return;
}
done = true;
}
function stop(close) {
if (close) { close(); }
cm.focus();
if (lastPos) {
cm.setCursor(lastPos);
var vim = cm.state.vim;
vim.exMode = false;
vim.lastHPos = vim.lastHSPos = lastPos.ch;
}
if (callback) { callback(); }
}
function onPromptKeyDown(e, _value, close) {
// Swallow all keys.
CodeMirror.e_stop(e);
var keyName = CodeMirror.keyName(e);
switch (keyName) {
case 'Y':
replace(); next(); break;
case 'N':
next(); break;
case 'A':
// replaceAll contains a call to close of its own. We don't want it
// to fire too early or multiple times.
var savedCallback = callback;
callback = undefined;
cm.operation(replaceAll);
callback = savedCallback;
break;
case 'L':
replace();
// fall through and exit.
case 'Q':
case 'Esc':
case 'Ctrl-C':
case 'Ctrl-[':
stop(close);
break;
}
if (done) { stop(close); }
return true;
}
// Actually do replace.
next();
if (done) {
showConfirm(cm, 'No matches for ' + query.source);
return;
}
if (!confirm) {
replaceAll();
if (callback) { callback(); };
return;
}
showPrompt(cm, {
prefix: 'replace with <strong>' + replaceWith + '</strong> (y/n/a/q/l)',
onKeyDown: onPromptKeyDown
});
}
CodeMirror.keyMap.vim = {
attach: attachVimMap,
detach: detachVimMap,
call: cmKey
};
function exitInsertMode(cm) {
var vim = cm.state.vim;
var macroModeState = vimGlobalState.macroModeState;
var insertModeChangeRegister = vimGlobalState.registerController.getRegister('.');
var isPlaying = macroModeState.isPlaying;
var lastChange = macroModeState.lastInsertModeChanges;
// In case of visual block, the insertModeChanges are not saved as a
// single word, so we convert them to a single word
// so as to update the ". register as expected in real vim.
var text = [];
if (!isPlaying) {
var selLength = lastChange.inVisualBlock ? vim.lastSelection.visualBlock.height : 1;
var changes = lastChange.changes;
var text = [];
var i = 0;
// In case of multiple selections in blockwise visual,
// the inserted text, for example: 'f<Backspace>oo', is stored as
// 'f', 'f', InsertModeKey 'o', 'o', 'o', 'o'. (if you have a block with 2 lines).
// We push the contents of the changes array as per the following:
// 1. In case of InsertModeKey, just increment by 1.
// 2. In case of a character, jump by selLength (2 in the example).
while (i < changes.length) {
// This loop will convert 'ff<bs>oooo' to 'f<bs>oo'.
text.push(changes[i]);
if (changes[i] instanceof InsertModeKey) {
i++;
} else {
i+= selLength;
}
}
lastChange.changes = text;
cm.off('change', onChange);
CodeMirror.off(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
}
if (!isPlaying && vim.insertModeRepeat > 1) {
// Perform insert mode repeat for commands like 3,a and 3,o.
repeatLastEdit(cm, vim, vim.insertModeRepeat - 1,
true /** repeatForInsert */);
vim.lastEditInputState.repeatOverride = vim.insertModeRepeat;
}
delete vim.insertModeRepeat;
vim.insertMode = false;
cm.setCursor(cm.getCursor().line, cm.getCursor().ch-1);
cm.setOption('keyMap', 'vim');
cm.setOption('disableInput', true);
cm.toggleOverwrite(false); // exit replace mode if we were in it.
// update the ". register before exiting insert mode
insertModeChangeRegister.setText(lastChange.changes.join(''));
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
if (macroModeState.isRecording) {
logInsertModeChange(macroModeState);
}
}
function _mapCommand(command) {
defaultKeymap.unshift(command);
}
function mapCommand(keys, type, name, args, extra) {
var command = {keys: keys, type: type};
command[type] = name;
command[type + "Args"] = args;
for (var key in extra)
command[key] = extra[key];
_mapCommand(command);
}
// The timeout in milliseconds for the two-character ESC keymap should be
// adjusted according to your typing speed to prevent false positives.
defineOption('insertModeEscKeysTimeout', 200, 'number');
CodeMirror.keyMap['vim-insert'] = {
// TODO: override navigation keys so that Esc will cancel automatic
// indentation from o, O, i_<CR>
fallthrough: ['default'],
attach: attachVimMap,
detach: detachVimMap,
call: cmKey
};
CodeMirror.keyMap['vim-replace'] = {
'Backspace': 'goCharLeft',
fallthrough: ['vim-insert'],
attach: attachVimMap,
detach: detachVimMap,
call: cmKey
};
function executeMacroRegister(cm, vim, macroModeState, registerName) {
var register = vimGlobalState.registerController.getRegister(registerName);
if (registerName == ':') {
// Read-only register containing last Ex command.
if (register.keyBuffer[0]) {
exCommandDispatcher.processCommand(cm, register.keyBuffer[0]);
}
macroModeState.isPlaying = false;
return;
}
var keyBuffer = register.keyBuffer;
var imc = 0;
macroModeState.isPlaying = true;
macroModeState.replaySearchQueries = register.searchQueries.slice(0);
for (var i = 0; i < keyBuffer.length; i++) {
var text = keyBuffer[i];
var match, key;
while (text) {
// Pull off one command key, which is either a single character
// or a special sequence wrapped in '<' and '>', e.g. '<Space>'.
match = (/<\w+-.+?>|<\w+>|./).exec(text);
key = match[0];
text = text.substring(match.index + key.length);
CodeMirror.Vim.handleKey(cm, key, 'macro');
if (vim.insertMode) {
var changes = register.insertModeChanges[imc++].changes;
vimGlobalState.macroModeState.lastInsertModeChanges.changes =
changes;
repeatInsertModeChanges(cm, changes, 1);
exitInsertMode(cm);
}
}
};
macroModeState.isPlaying = false;
}
function logKey(macroModeState, key) {
if (macroModeState.isPlaying) { return; }
var registerName = macroModeState.latestRegister;
var register = vimGlobalState.registerController.getRegister(registerName);
if (register) {
register.pushText(key);
}
}
function logInsertModeChange(macroModeState) {
if (macroModeState.isPlaying) { return; }
var registerName = macroModeState.latestRegister;
var register = vimGlobalState.registerController.getRegister(registerName);
if (register && register.pushInsertModeChanges) {
register.pushInsertModeChanges(macroModeState.lastInsertModeChanges);
}
}
function logSearchQuery(macroModeState, query) {
if (macroModeState.isPlaying) { return; }
var registerName = macroModeState.latestRegister;
var register = vimGlobalState.registerController.getRegister(registerName);
if (register && register.pushSearchQuery) {
register.pushSearchQuery(query);
}
}
/**
* Listens for changes made in insert mode.
* Should only be active in insert mode.
*/
function onChange(_cm, changeObj) {
var macroModeState = vimGlobalState.macroModeState;
var lastChange = macroModeState.lastInsertModeChanges;
if (!macroModeState.isPlaying) {
while(changeObj) {
lastChange.expectCursorActivityForChange = true;
if (changeObj.origin == '+input' || changeObj.origin == 'paste'
|| changeObj.origin === undefined /* only in testing */) {
var text = changeObj.text.join('\n');
if (lastChange.maybeReset) {
lastChange.changes = [];
lastChange.maybeReset = false;
}
lastChange.changes.push(text);
}
// Change objects may be chained with next.
changeObj = changeObj.next;
}
}
}
/**
* Listens for any kind of cursor activity on CodeMirror.
*/
function onCursorActivity(cm) {
var vim = cm.state.vim;
if (vim.insertMode) {
// Tracking cursor activity in insert mode (for macro support).
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) { return; }
var lastChange = macroModeState.lastInsertModeChanges;
if (lastChange.expectCursorActivityForChange) {
lastChange.expectCursorActivityForChange = false;
} else {
// Cursor moved outside the context of an edit. Reset the change.
lastChange.maybeReset = true;
}
} else if (!cm.curOp.isVimOp) {
handleExternalSelection(cm, vim);
}
if (vim.visualMode) {
updateFakeCursor(cm);
}
}
function updateFakeCursor(cm) {
var vim = cm.state.vim;
var from = clipCursorToContent(cm, copyCursor(vim.sel.head));
var to = offsetCursor(from, 0, 1);
if (vim.fakeCursor) {
vim.fakeCursor.clear();
}
vim.fakeCursor = cm.markText(from, to, {className: 'cm-animate-fat-cursor'});
}
function handleExternalSelection(cm, vim) {
var anchor = cm.getCursor('anchor');
var head = cm.getCursor('head');
// Enter or exit visual mode to match mouse selection.
if (vim.visualMode && !cm.somethingSelected()) {
exitVisualMode(cm, false);
} else if (!vim.visualMode && !vim.insertMode && cm.somethingSelected()) {
vim.visualMode = true;
vim.visualLine = false;
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual"});
}
if (vim.visualMode) {
// Bind CodeMirror selection model to vim selection model.
// Mouse selections are considered visual characterwise.
var headOffset = !cursorIsBefore(head, anchor) ? -1 : 0;
var anchorOffset = cursorIsBefore(head, anchor) ? -1 : 0;
head = offsetCursor(head, 0, headOffset);
anchor = offsetCursor(anchor, 0, anchorOffset);
vim.sel = {
anchor: anchor,
head: head
};
updateMark(cm, vim, '<', cursorMin(head, anchor));
updateMark(cm, vim, '>', cursorMax(head, anchor));
} else if (!vim.insertMode) {
// Reset lastHPos if selection was modified by something outside of vim mode e.g. by mouse.
vim.lastHPos = cm.getCursor().ch;
}
}
/** Wrapper for special keys pressed in insert mode */
function InsertModeKey(keyName) {
this.keyName = keyName;
}
/**
* Handles raw key down events from the text area.
* - Should only be active in insert mode.
* - For recording deletes in insert mode.
*/
function onKeyEventTargetKeyDown(e) {
var macroModeState = vimGlobalState.macroModeState;
var lastChange = macroModeState.lastInsertModeChanges;
var keyName = CodeMirror.keyName(e);
if (!keyName) { return; }
function onKeyFound() {
if (lastChange.maybeReset) {
lastChange.changes = [];
lastChange.maybeReset = false;
}
lastChange.changes.push(new InsertModeKey(keyName));
return true;
}
if (keyName.indexOf('Delete') != -1 || keyName.indexOf('Backspace') != -1) {
CodeMirror.lookupKey(keyName, 'vim-insert', onKeyFound);
}
}
/**
* Repeats the last edit, which includes exactly 1 command and at most 1
* insert. Operator and motion commands are read from lastEditInputState,
* while action commands are read from lastEditActionCommand.
*
* If repeatForInsert is true, then the function was called by
* exitInsertMode to repeat the insert mode changes the user just made. The
* corresponding enterInsertMode call was made with a count.
*/
function repeatLastEdit(cm, vim, repeat, repeatForInsert) {
var macroModeState = vimGlobalState.macroModeState;
macroModeState.isPlaying = true;
var isAction = !!vim.lastEditActionCommand;
var cachedInputState = vim.inputState;
function repeatCommand() {
if (isAction) {
commandDispatcher.processAction(cm, vim, vim.lastEditActionCommand);
} else {
commandDispatcher.evalInput(cm, vim);
}
}
function repeatInsert(repeat) {
if (macroModeState.lastInsertModeChanges.changes.length > 0) {
// For some reason, repeat cw in desktop VIM does not repeat
// insert mode changes. Will conform to that behavior.
repeat = !vim.lastEditActionCommand ? 1 : repeat;
var changeObject = macroModeState.lastInsertModeChanges;
repeatInsertModeChanges(cm, changeObject.changes, repeat);
}
}
vim.inputState = vim.lastEditInputState;
if (isAction && vim.lastEditActionCommand.interlaceInsertRepeat) {
// o and O repeat have to be interlaced with insert repeats so that the
// insertions appear on separate lines instead of the last line.
for (var i = 0; i < repeat; i++) {
repeatCommand();
repeatInsert(1);
}
} else {
if (!repeatForInsert) {
// Hack to get the cursor to end up at the right place. If I is
// repeated in insert mode repeat, cursor will be 1 insert
// change set left of where it should be.
repeatCommand();
}
repeatInsert(repeat);
}
vim.inputState = cachedInputState;
if (vim.insertMode && !repeatForInsert) {
// Don't exit insert mode twice. If repeatForInsert is set, then we
// were called by an exitInsertMode call lower on the stack.
exitInsertMode(cm);
}
macroModeState.isPlaying = false;
};
function repeatInsertModeChanges(cm, changes, repeat) {
function keyHandler(binding) {
if (typeof binding == 'string') {
CodeMirror.commands[binding](cm);
} else {
binding(cm);
}
return true;
}
var head = cm.getCursor('head');
var inVisualBlock = vimGlobalState.macroModeState.lastInsertModeChanges.inVisualBlock;
if (inVisualBlock) {
// Set up block selection again for repeating the changes.
var vim = cm.state.vim;
var lastSel = vim.lastSelection;
var offset = getOffset(lastSel.anchor, lastSel.head);
selectForInsert(cm, head, offset.line + 1);
repeat = cm.listSelections().length;
cm.setCursor(head);
}
for (var i = 0; i < repeat; i++) {
if (inVisualBlock) {
cm.setCursor(offsetCursor(head, i, 0));
}
for (var j = 0; j < changes.length; j++) {
var change = changes[j];
if (change instanceof InsertModeKey) {
CodeMirror.lookupKey(change.keyName, 'vim-insert', keyHandler);
} else {
var cur = cm.getCursor();
cm.replaceRange(change, cur, cur);
}
}
}
if (inVisualBlock) {
cm.setCursor(offsetCursor(head, 0, 1));
}
}
resetVimGlobalState();
return vimApi;
};
// Initialize Vim and make it available as an API.
CodeMirror.Vim = Vim();
});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.emmetCodeMirror=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Emmet Editor interface implementation for CodeMirror.
* Interface is optimized for multiple cursor usage: authors
* should run acttion multiple times and update `selectionIndex`
* property on each iteration.
*/
var emmet = _interopRequire(require("./emmet"));
var modeMap = {
"text/html": "html",
"application/xml": "xml",
"text/xsl": "xsl",
"text/css": "css",
"text/x-less": "less",
"text/x-scss": "scss",
"text/x-sass": "sass"
};
exports.modeMap = modeMap;
var EmmetEditor = (function () {
function EmmetEditor(ctx) {
var selIndex = arguments[1] === undefined ? 0 : arguments[1];
_classCallCheck(this, EmmetEditor);
this.context = ctx;
this.selectionIndex = selIndex || 0;
}
_createClass(EmmetEditor, {
selectionList: {
/**
* Returns list of selections for current CodeMirror instance.
* @return {Array}
*/
value: function selectionList() {
var cm = this.context;
return cm.listSelections().map(function (sel) {
var anchor = posToIndex(cm, sel.anchor);
var head = posToIndex(cm, sel.head);
return {
start: Math.min(anchor, head),
end: Math.max(anchor, head)
};
});
}
},
getCaretPos: {
value: function getCaretPos() {
return this.getSelectionRange().start;
}
},
setCaretPos: {
value: function setCaretPos(pos) {
this.createSelection(pos);
}
},
getSelectionRange: {
/**
* Returns current selection range (for current selection index)
* @return {Object}
*/
value: function getSelectionRange() {
return this.selectionList()[this.selectionIndex];
}
},
createSelection: {
value: function createSelection(start, end) {
if (typeof end == "undefined") {
end = start;
}
var sels = this.selectionList();
var cm = this.context;
sels[this.selectionIndex] = { start: start, end: end };
this.context.setSelections(sels.map(function (sel) {
return {
head: indexToPos(cm, sel.start),
anchor: indexToPos(cm, sel.end)
};
}));
}
},
getSelection: {
/**
* Returns current selection
* @return {String}
*/
value: function getSelection() {
var sel = this.getSelectionRange();
sel.start = indexToPos(this.context, sel.start);
sel.end = indexToPos(this.context, sel.end);
return this.context.getRange(sel.start, sel.end);
}
},
getCurrentLineRange: {
value: function getCurrentLineRange() {
var caret = indexToPos(this.context, this.getCaretPos());
return {
start: posToIndex(this.context, caret.line, 0),
end: posToIndex(this.context, caret.line, this.context.getLine(caret.line).length)
};
}
},
getCurrentLine: {
value: function getCurrentLine() {
var caret = indexToPos(this.context, this.getCaretPos());
return this.context.getLine(caret.line) || "";
}
},
replaceContent: {
value: function replaceContent(value, start, end, noIndent) {
if (typeof end == "undefined") {
end = typeof start == "undefined" ? this.getContent().length : start;
}
if (typeof start == "undefined") {
start = 0;
}
// normalize indentation according to editor preferences
value = this.normalize(value);
// indent new value
if (!noIndent) {
value = emmet.utils.common.padString(value, emmet.utils.common.getLinePaddingFromPosition(this.getContent(), start));
}
// find new caret position
var tabstopData = emmet.tabStops.extract(value, { escape: function (ch) {
return ch;
} });
value = tabstopData.text;
var firstTabStop = tabstopData.tabstops[0] || { start: value.length, end: value.length };
firstTabStop.start += start;
firstTabStop.end += start;
this.context.replaceRange(value, indexToPos(this.context, start), indexToPos(this.context, end));
this.createSelection(firstTabStop.start, firstTabStop.end);
}
},
normalize: {
/**
* Normalizes string indentation in given string
* according to editor preferences
* @param {String} str
* @return {String}
*/
value: function normalize(str) {
var indent = "\t";
var ctx = this.context;
if (!ctx.getOption("indentWithTabs")) {
indent = emmet.utils.common.repeatString(" ", ctx.getOption("indentUnit"));
}
return emmet.utils.editor.normalize(str, {
indentation: indent
});
}
},
getContent: {
value: function getContent() {
return this.context.getValue();
}
},
getSyntax: {
value: function getSyntax() {
var editor = this.context;
var pos = editor.posFromIndex(this.getCaretPos());
var mode = editor.getModeAt(editor.getCursor());
var syntax = mode.name;
if (syntax === "xml" && mode.configuration) {
syntax = mode.configuration;
}
return syntax || emmet.utils.action.detectSyntax(this, syntax);
}
},
getProfileName: {
/**
* Returns current output profile name (@see emmet#setupProfile)
* @return {String}
*/
value: function getProfileName() {
if (this.context.getOption("profile")) {
return this.context.getOption("profile");
}
return emmet.utils.action.detectProfile(this);
}
},
prompt: {
/**
* Ask user to enter something
* @param {String} title Dialog title
* @return {String} Entered data
*/
value: (function (_prompt) {
var _promptWrapper = function prompt(_x) {
return _prompt.apply(this, arguments);
};
_promptWrapper.toString = function () {
return _prompt.toString();
};
return _promptWrapper;
})(function (title) {
return prompt(title);
})
},
getFilePath: {
/**
* Returns current editor's file path
* @return {String}
*/
value: function getFilePath() {
return location.href;
}
},
isValidSyntax: {
/**
* Check if current editor syntax is valid, e.g. is supported by Emmet
* @return {Boolean}
*/
value: function isValidSyntax() {
return emmet.resources.hasSyntax(this.getSyntax());
}
}
});
return EmmetEditor;
})();
exports["default"] = EmmetEditor;
/**
* Converts CMs inner representation of character
* position (line, ch) to character index in text
* @param {CodeMirror} cm CodeMirror instance
* @param {Object} pos Position object
* @return {Number}
*/
function posToIndex(cm, pos) {
if (arguments.length > 2 && typeof pos !== "object") {
pos = { line: arguments[1], ch: arguments[2] };
}
return cm.indexFromPos(pos);
}
/**
* Converts charater index in text to CMs internal object representation
* @param {CodeMirror} cm CodeMirror instance
* @param {Number} ix Character index in CM document
* @return {Object}
*/
function indexToPos(cm, ix) {
return cm.posFromIndex(ix);
}
},{"./emmet":2}],2:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
var emmet = _interopRequire(require("emmet"));
require("emmet/bundles/snippets");
require("emmet/bundles/caniuse");
module.exports = emmet;
},{"emmet":39,"emmet/bundles/caniuse":3,"emmet/bundles/snippets":4}],3:[function(require,module,exports){
/**
* Bundler, used in builder script to statically
* include optimized caniuse.json into bundle
*/
var ciu = require('../lib/assets/caniuse');
var db = require('../lib/caniuse.json');
ciu.load(db, true);
},{"../lib/assets/caniuse":23,"../lib/caniuse.json":35}],4:[function(require,module,exports){
/**
* Bundler, used in builder script to statically
* include snippets.json into bundle
*/
var res = require('../lib/assets/resources');
var snippets = require('../lib/snippets.json');
res.setVocabulary(snippets, 'system');
},{"../lib/assets/resources":31,"../lib/snippets.json":68}],5:[function(require,module,exports){
/**
* HTML pair matching (balancing) actions
* @constructor
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var htmlMatcher = require('../assets/htmlMatcher');
var utils = require('../utils/common');
var editorUtils = require('../utils/editor');
var actionUtils = require('../utils/action');
var range = require('../assets/range');
var cssEditTree = require('../editTree/css');
var cssSections = require('../utils/cssSections');
var lastMatch = null;
function last(arr) {
return arr[arr.length - 1];
}
function balanceHTML(editor, direction) {
var info = editorUtils.outputInfo(editor);
var content = info.content;
var sel = range(editor.getSelectionRange());
// validate previous match
if (lastMatch && !lastMatch.range.equal(sel)) {
lastMatch = null;
}
if (lastMatch && sel.length()) {
if (direction == 'in') {
// user has previously selected tag and wants to move inward
if (lastMatch.type == 'tag' && !lastMatch.close) {
// unary tag was selected, can't move inward
return false;
} else {
if (lastMatch.range.equal(lastMatch.outerRange)) {
lastMatch.range = lastMatch.innerRange;
} else {
var narrowed = utils.narrowToNonSpace(content, lastMatch.innerRange);
lastMatch = htmlMatcher.find(content, narrowed.start + 1);
if (lastMatch && lastMatch.range.equal(sel) && lastMatch.outerRange.equal(sel)) {
lastMatch.range = lastMatch.innerRange;
}
}
}
} else {
if (
!lastMatch.innerRange.equal(lastMatch.outerRange)
&& lastMatch.range.equal(lastMatch.innerRange)
&& sel.equal(lastMatch.range)) {
lastMatch.range = lastMatch.outerRange;
} else {
lastMatch = htmlMatcher.find(content, sel.start);
if (lastMatch && lastMatch.range.equal(sel) && lastMatch.innerRange.equal(sel)) {
lastMatch.range = lastMatch.outerRange;
}
}
}
} else {
lastMatch = htmlMatcher.find(content, sel.start);
}
if (lastMatch) {
if (lastMatch.innerRange.equal(sel)) {
lastMatch.range = lastMatch.outerRange;
}
if (!lastMatch.range.equal(sel)) {
editor.createSelection(lastMatch.range.start, lastMatch.range.end);
return true;
}
}
lastMatch = null;
return false;
}
function rangesForCSSRule(rule, pos) {
// find all possible ranges
var ranges = [rule.range(true)];
// braces content
ranges.push(rule.valueRange(true));
// find nested sections
var nestedSections = cssSections.nestedSectionsInRule(rule);
// real content, e.g. from first property name to
// last property value
var items = rule.list();
if (items.length || nestedSections.length) {
var start = Number.POSITIVE_INFINITY, end = -1;
if (items.length) {
start = items[0].namePosition(true);
end = last(items).range(true).end;
}
if (nestedSections.length) {
if (nestedSections[0].start < start) {
start = nestedSections[0].start;
}
if (last(nestedSections).end > end) {
end = last(nestedSections).end;
}
}
ranges.push(range.create2(start, end));
}
ranges = ranges.concat(nestedSections);
var prop = cssEditTree.propertyFromPosition(rule, pos) || items[0];
if (prop) {
ranges.push(prop.range(true));
var valueRange = prop.valueRange(true);
if (!prop.end()) {
valueRange._unterminated = true;
}
ranges.push(valueRange);
}
return ranges;
}
/**
* Returns all possible selection ranges for given caret position
* @param {String} content CSS content
* @param {Number} pos Caret position(where to start searching)
* @return {Array}
*/
function getCSSRanges(content, pos) {
var rule;
if (typeof content === 'string') {
var ruleRange = cssSections.matchEnclosingRule(content, pos);
if (ruleRange) {
rule = cssEditTree.parse(ruleRange.substring(content), {
offset: ruleRange.start
});
}
} else {
// passed parsed CSS rule
rule = content;
}
if (!rule) {
return null;
}
// find all possible ranges
var ranges = rangesForCSSRule(rule, pos);
// remove empty ranges
ranges = ranges.filter(function(item) {
return !!item.length;
});
return utils.unique(ranges, function(item) {
return item.valueOf();
});
}
function balanceCSS(editor, direction) {
var info = editorUtils.outputInfo(editor);
var content = info.content;
var sel = range(editor.getSelectionRange());
var ranges = getCSSRanges(info.content, sel.start);
if (!ranges && sel.length()) {
// possible reason: user has already selected
// CSS rule from last match
try {
var rule = cssEditTree.parse(sel.substring(info.content), {
offset: sel.start
});
ranges = getCSSRanges(rule, sel.start);
} catch(e) {}
}
if (!ranges) {
return false;
}
ranges = range.sort(ranges, true);
// edge case: find match that equals current selection,
// in case if user moves inward after selecting full CSS rule
var bestMatch = utils.find(ranges, function(r) {
return r.equal(sel);
});
if (!bestMatch) {
bestMatch = utils.find(ranges, function(r) {
// Check for edge case: caret right after CSS value
// but it doesnt contains terminating semicolon.
// In this case we have to check full value range
return r._unterminated ? r.include(sel.start) : r.inside(sel.start);
});
}
if (!bestMatch) {
return false;
}
// if best match equals to current selection, move index
// one position up or down, depending on direction
var bestMatchIx = ranges.indexOf(bestMatch);
if (bestMatch.equal(sel)) {
bestMatchIx += direction == 'out' ? 1 : -1;
}
if (bestMatchIx < 0 || bestMatchIx >= ranges.length) {
if (bestMatchIx >= ranges.length && direction == 'out') {
pos = bestMatch.start - 1;
var outerRanges = getCSSRanges(content, pos);
if (outerRanges) {
bestMatch = last(outerRanges.filter(function(r) {
return r.inside(pos);
}));
}
} else if (bestMatchIx < 0 && direction == 'in') {
bestMatch = null;
} else {
bestMatch = null;
}
} else {
bestMatch = ranges[bestMatchIx];
}
if (bestMatch) {
editor.createSelection(bestMatch.start, bestMatch.end);
return true;
}
return false;
}
return {
/**
* Find and select HTML tag pair
* @param {IEmmetEditor} editor Editor instance
* @param {String} direction Direction of pair matching: 'in' or 'out'.
* Default is 'out'
*/
balance: function(editor, direction) {
direction = String((direction || 'out').toLowerCase());
var info = editorUtils.outputInfo(editor);
if (actionUtils.isSupportedCSS(info.syntax)) {
return balanceCSS(editor, direction);
}
return balanceHTML(editor, direction);
},
balanceInwardAction: function(editor) {
return this.balance(editor, 'in');
},
balanceOutwardAction: function(editor) {
return this.balance(editor, 'out');
},
/**
* Moves caret to matching opening or closing tag
* @param {IEmmetEditor} editor
*/
goToMatchingPairAction: function(editor) {
var content = String(editor.getContent());
var caretPos = editor.getCaretPos();
if (content.charAt(caretPos) == '<')
// looks like caret is outside of tag pair
caretPos++;
var tag = htmlMatcher.tag(content, caretPos);
if (tag && tag.close) { // exclude unary tags
if (tag.open.range.inside(caretPos)) {
editor.setCaretPos(tag.close.range.start);
} else {
editor.setCaretPos(tag.open.range.start);
}
return true;
}
return false;
}
};
});
},{"../assets/htmlMatcher":26,"../assets/range":30,"../editTree/css":37,"../utils/action":70,"../utils/common":73,"../utils/cssSections":74,"../utils/editor":75}],6:[function(require,module,exports){
/**
* Encodes/decodes image under cursor to/from base64
* @param {IEmmetEditor} editor
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var file = require('../plugin/file');
var base64 = require('../utils/base64');
var actionUtils = require('../utils/action');
var editorUtils = require('../utils/editor');
/**
* Test if <code>text</code> starts with <code>token</code> at <code>pos</code>
* position. If <code>pos</code> is omitted, search from beginning of text
* @param {String} token Token to test
* @param {String} text Where to search
* @param {Number} pos Position where to start search
* @return {Boolean}
* @since 0.65
*/
function startsWith(token, text, pos) {
pos = pos || 0;
return text.charAt(pos) == token.charAt(0) && text.substr(pos, token.length) == token;
}
/**
* Encodes image to base64
*
* @param {IEmmetEditor} editor
* @param {String} imgPath Path to image
* @param {Number} pos Caret position where image is located in the editor
* @return {Boolean}
*/
function encodeToBase64(editor, imgPath, pos) {
var editorFile = editor.getFilePath();
var defaultMimeType = 'application/octet-stream';
if (editorFile === null) {
throw "You should save your file before using this action";
}
// locate real image path
var realImgPath = file.locateFile(editorFile, imgPath);
if (realImgPath === null) {
throw "Can't find " + imgPath + ' file';
}
file.read(realImgPath, function(err, content) {
if (err) {
throw 'Unable to read ' + realImgPath + ': ' + err;
}
var b64 = base64.encode(String(content));
if (!b64) {
throw "Can't encode file content to base64";
}
b64 = 'data:' + (actionUtils.mimeTypes[String(file.getExt(realImgPath))] || defaultMimeType) +
';base64,' + b64;
editor.replaceContent('$0' + b64, pos, pos + imgPath.length);
});
return true;
}
/**
* Decodes base64 string back to file.
* @param {IEmmetEditor} editor
* @param {String} data Base64-encoded file content
* @param {Number} pos Caret position where image is located in the editor
*/
function decodeFromBase64(editor, data, pos) {
// ask user to enter path to file
var filePath = String(editor.prompt('Enter path to file (absolute or relative)'));
if (!filePath)
return false;
var absPath = file.createPath(editor.getFilePath(), filePath);
if (!absPath) {
throw "Can't save file";
}
file.save(absPath, base64.decode( data.replace(/^data\:.+?;.+?,/, '') ));
editor.replaceContent('$0' + filePath, pos, pos + data.length);
return true;
}
return {
/**
* Action to encode or decode file to data:url
* @param {IEmmetEditor} editor Editor instance
* @param {String} syntax Current document syntax
* @param {String} profile Output profile name
* @return {Boolean}
*/
encodeDecodeDataUrlAction: function(editor) {
var data = String(editor.getSelection());
var caretPos = editor.getCaretPos();
var info = editorUtils.outputInfo(editor);
if (!data) {
// no selection, try to find image bounds from current caret position
var text = info.content, m;
while (caretPos-- >= 0) {
if (startsWith('src=', text, caretPos)) { // found <img src="">
if ((m = text.substr(caretPos).match(/^(src=(["'])?)([^'"<>\s]+)\1?/))) {
data = m[3];
caretPos += m[1].length;
}
break;
} else if (startsWith('url(', text, caretPos)) { // found CSS url() pattern
if ((m = text.substr(caretPos).match(/^(url\((['"])?)([^'"\)\s]+)\1?/))) {
data = m[3];
caretPos += m[1].length;
}
break;
}
}
}
if (data) {
if (startsWith('data:', data)) {
return decodeFromBase64(editor, data, caretPos);
} else {
return encodeToBase64(editor, data, caretPos);
}
}
return false;
}
};
});
},{"../plugin/file":63,"../utils/action":70,"../utils/base64":71,"../utils/editor":75}],7:[function(require,module,exports){
/**
* Move between next/prev edit points. 'Edit points' are places between tags
* and quotes of empty attributes in html
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
/**
* Search for new caret insertion point
* @param {IEmmetEditor} editor Editor instance
* @param {Number} inc Search increment: -1 — search left, 1 — search right
* @param {Number} offset Initial offset relative to current caret position
* @return {Number} Returns -1 if insertion point wasn't found
*/
function findNewEditPoint(editor, inc, offset) {
inc = inc || 1;
offset = offset || 0;
var curPoint = editor.getCaretPos() + offset;
var content = String(editor.getContent());
var maxLen = content.length;
var nextPoint = -1;
var reEmptyLine = /^\s+$/;
function getLine(ix) {
var start = ix;
while (start >= 0) {
var c = content.charAt(start);
if (c == '\n' || c == '\r')
break;
start--;
}
return content.substring(start, ix);
}
while (curPoint <= maxLen && curPoint >= 0) {
curPoint += inc;
var curChar = content.charAt(curPoint);
var nextChar = content.charAt(curPoint + 1);
var prevChar = content.charAt(curPoint - 1);
switch (curChar) {
case '"':
case '\'':
if (nextChar == curChar && prevChar == '=') {
// empty attribute
nextPoint = curPoint + 1;
}
break;
case '>':
if (nextChar == '<') {
// between tags
nextPoint = curPoint + 1;
}
break;
case '\n':
case '\r':
// empty line
if (reEmptyLine.test(getLine(curPoint - 1))) {
nextPoint = curPoint;
}
break;
}
if (nextPoint != -1)
break;
}
return nextPoint;
}
return {
/**
* Move to previous edit point
* @param {IEmmetEditor} editor Editor instance
* @param {String} syntax Current document syntax
* @param {String} profile Output profile name
* @return {Boolean}
*/
previousEditPointAction: function(editor, syntax, profile) {
var curPos = editor.getCaretPos();
var newPoint = findNewEditPoint(editor, -1);
if (newPoint == curPos)
// we're still in the same point, try searching from the other place
newPoint = findNewEditPoint(editor, -1, -2);
if (newPoint != -1) {
editor.setCaretPos(newPoint);
return true;
}
return false;
},
/**
* Move to next edit point
* @param {IEmmetEditor} editor Editor instance
* @param {String} syntax Current document syntax
* @param {String} profile Output profile name
* @return {Boolean}
*/
nextEditPointAction: function(editor, syntax, profile) {
var newPoint = findNewEditPoint(editor, 1);
if (newPoint != -1) {
editor.setCaretPos(newPoint);
return true;
}
return false;
}
};
});
},{}],8:[function(require,module,exports){
/**
* Evaluates simple math expression under caret
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var actionUtils = require('../utils/action');
var utils = require('../utils/common');
var math = require('../utils/math');
var range = require('../assets/range');
return {
/**
* Evaluates math expression under the caret
* @param {IEmmetEditor} editor
* @return {Boolean}
*/
evaluateMathAction: function(editor) {
var content = editor.getContent();
var chars = '.+-*/\\';
/** @type Range */
var sel = range(editor.getSelectionRange());
if (!sel.length()) {
sel = actionUtils.findExpressionBounds(editor, function(ch) {
return utils.isNumeric(ch) || chars.indexOf(ch) != -1;
});
}
if (sel && sel.length()) {
var expr = sel.substring(content);
// replace integral division: 11\2 => Math.round(11/2)
expr = expr.replace(/([\d\.\-]+)\\([\d\.\-]+)/g, 'round($1/$2)');
try {
var result = utils.prettifyNumber(math.evaluate(expr));
editor.replaceContent(result, sel.start, sel.end);
editor.setCaretPos(sel.start + result.length);
return true;
} catch (e) {}
}
return false;
}
};
});
},{"../assets/range":30,"../utils/action":70,"../utils/common":73,"../utils/math":76}],9:[function(require,module,exports){
/**
* 'Expand abbreviation' editor action: extracts abbreviation from current caret
* position and replaces it with formatted output.
* <br><br>
* This behavior can be overridden with custom handlers which can perform
* different actions when 'Expand Abbreviation' action is called.
* For example, a CSS gradient handler that produces vendor-prefixed gradient
* definitions registers its own expand abbreviation handler.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var handlerList = require('../assets/handlerList');
var range = require('../assets/range');
var prefs = require('../assets/preferences');
var utils = require('../utils/common');
var editorUtils = require('../utils/editor');
var actionUtils = require('../utils/action');
var cssGradient = require('../resolver/cssGradient');
var parser = require('../parser/abbreviation');
/**
* Search for abbreviation in editor from current caret position
* @param {IEmmetEditor} editor Editor instance
* @return {String}
*/
function findAbbreviation(editor) {
var r = range(editor.getSelectionRange());
var content = String(editor.getContent());
if (r.length()) {
// abbreviation is selected by user
return r.substring(content);
}
// search for new abbreviation from current caret position
var curLine = editor.getCurrentLineRange();
return actionUtils.extractAbbreviation(content.substring(curLine.start, r.start));
}
/**
* @type HandlerList List of registered handlers
*/
var handlers = handlerList.create();
// XXX setup default expand handlers
/**
* Extracts abbreviation from current caret
* position and replaces it with formatted output
* @param {IEmmetEditor} editor Editor instance
* @param {String} syntax Syntax type (html, css, etc.)
* @param {String} profile Output profile name (html, xml, xhtml)
* @return {Boolean} Returns <code>true</code> if abbreviation was expanded
* successfully
*/
handlers.add(function(editor, syntax, profile) {
var caretPos = editor.getSelectionRange().end;
var abbr = findAbbreviation(editor);
if (abbr) {
var content = parser.expand(abbr, {
syntax: syntax,
profile: profile,
contextNode: actionUtils.captureContext(editor)
});
if (content) {
var replaceFrom = caretPos - abbr.length;
var replaceTo = caretPos;
// a special case for CSS: if editor already contains
// semicolon right after current caret position — replace it too
var cssSyntaxes = prefs.getArray('css.syntaxes');
if (cssSyntaxes && ~cssSyntaxes.indexOf(syntax)) {
var curContent = editor.getContent();
if (curContent.charAt(caretPos) == ';' && content.charAt(content.length - 1) == ';') {
replaceTo++;
}
}
editor.replaceContent(content, replaceFrom, replaceTo);
return true;
}
}
return false;
}, {order: -1});
handlers.add(cssGradient.expandAbbreviationHandler.bind(cssGradient));
return {
/**
* The actual “Expand Abbreviation“ action routine
* @param {IEmmetEditor} editor Editor instance
* @param {String} syntax Current document syntax
* @param {String} profile Output profile name
* @return {Boolean}
*/
expandAbbreviationAction: function(editor, syntax, profile) {
var args = utils.toArray(arguments);
// normalize incoming arguments
var info = editorUtils.outputInfo(editor, syntax, profile);
args[1] = info.syntax;
args[2] = info.profile;
return handlers.exec(false, args);
},
/**
* A special case of “Expand Abbreviation“ action, invoked by Tab key.
* In this case if abbreviation wasnt expanded successfully or theres a selecetion,
* the current line/selection will be indented.
* @param {IEmmetEditor} editor Editor instance
* @param {String} syntax Current document syntax
* @param {String} profile Output profile name
* @return {Boolean}
*/
expandAbbreviationWithTabAction: function(editor, syntax, profile) {
var sel = editor.getSelection();
var indent = '\t';
// if something is selected in editor,
// we should indent the selected content
if (sel) {
var selRange = range(editor.getSelectionRange());
var content = utils.padString(sel, indent);
editor.replaceContent(indent + '${0}', editor.getCaretPos());
var replaceRange = range(editor.getCaretPos(), selRange.length());
editor.replaceContent(content, replaceRange.start, replaceRange.end, true);
editor.createSelection(replaceRange.start, replaceRange.start + content.length);
return true;
}
// nothing selected, try to expand
if (!this.expandAbbreviationAction(editor, syntax, profile)) {
editor.replaceContent(indent, editor.getCaretPos());
}
return true;
},
_defaultHandler: function(editor, syntax, profile) {
var caretPos = editor.getSelectionRange().end;
var abbr = this.findAbbreviation(editor);
if (abbr) {
var ctx = actionUtils.captureContext(editor);
var content = parser.expand(abbr, syntax, profile, ctx);
if (content) {
editor.replaceContent(content, caretPos - abbr.length, caretPos);
return true;
}
}
return false;
},
/**
* Adds custom expand abbreviation handler. The passed function should
* return <code>true</code> if it was performed successfully,
* <code>false</code> otherwise.
*
* Added handlers will be called when 'Expand Abbreviation' is called
* in order they were added
* @memberOf expandAbbreviation
* @param {Function} fn
* @param {Object} options
*/
addHandler: function(fn, options) {
handlers.add(fn, options);
},
/**
* Removes registered handler
* @returns
*/
removeHandler: function(fn) {
handlers.remove(fn);
},
findAbbreviation: findAbbreviation
};
});
},{"../assets/handlerList":25,"../assets/preferences":28,"../assets/range":30,"../parser/abbreviation":55,"../resolver/cssGradient":65,"../utils/action":70,"../utils/common":73,"../utils/editor":75}],10:[function(require,module,exports){
/**
* Increment/decrement number under cursor
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var actionUtils = require('../utils/action');
/**
* Returns length of integer part of number
* @param {String} num
*/
function intLength(num) {
num = num.replace(/^\-/, '');
if (~num.indexOf('.')) {
return num.split('.')[0].length;
}
return num.length;
}
return {
increment01Action: function(editor) {
return this.incrementNumber(editor, .1);
},
increment1Action: function(editor) {
return this.incrementNumber(editor, 1);
},
increment10Action: function(editor) {
return this.incrementNumber(editor, 10);
},
decrement01Action: function(editor) {
return this.incrementNumber(editor, -.1);
},
decrement1Action: function(editor) {
return this.incrementNumber(editor, -1);
},
decrement10Action: function(editor) {
return this.incrementNumber(editor, -10);
},
/**
* Default method to increment/decrement number under
* caret with given step
* @param {IEmmetEditor} editor
* @param {Number} step
* @return {Boolean}
*/
incrementNumber: function(editor, step) {
var hasSign = false;
var hasDecimal = false;
var r = actionUtils.findExpressionBounds(editor, function(ch, pos, content) {
if (utils.isNumeric(ch))
return true;
if (ch == '.') {
// make sure that next character is numeric too
if (!utils.isNumeric(content.charAt(pos + 1)))
return false;
return hasDecimal ? false : hasDecimal = true;
}
if (ch == '-')
return hasSign ? false : hasSign = true;
return false;
});
if (r && r.length()) {
var strNum = r.substring(String(editor.getContent()));
var num = parseFloat(strNum);
if (!isNaN(num)) {
num = utils.prettifyNumber(num + step);
// do we have zero-padded number?
if (/^(\-?)0+[1-9]/.test(strNum)) {
var minus = '';
if (RegExp.$1) {
minus = '-';
num = num.substring(1);
}
var parts = num.split('.');
parts[0] = utils.zeroPadString(parts[0], intLength(strNum));
num = minus + parts.join('.');
}
editor.replaceContent(num, r.start, r.end);
editor.createSelection(r.start, r.start + num.length);
return true;
}
}
return false;
}
};
});
},{"../utils/action":70,"../utils/common":73}],11:[function(require,module,exports){
/**
* Actions to insert line breaks. Some simple editors (like browser's
* &lt;textarea&gt;, for example) do not provide such simple things
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var prefs = require('../assets/preferences');
var utils = require('../utils/common');
var resources = require('../assets/resources');
var htmlMatcher = require('../assets/htmlMatcher');
var editorUtils = require('../utils/editor');
var xmlSyntaxes = ['html', 'xml', 'xsl'];
// setup default preferences
prefs.define('css.closeBraceIndentation', '\n',
'Indentation before closing brace of CSS rule. Some users prefere '
+ 'indented closing brace of CSS rule for better readability. '
+ 'This preferences value will be automatically inserted before '
+ 'closing brace when user adds newline in newly created CSS rule '
+ '(e.g. when “Insert formatted linebreak” action will be performed '
+ 'in CSS file). If youre such user, you may want to write put a value '
+ 'like <code>\\n\\t</code> in this preference.');
return {
/**
* Inserts newline character with proper indentation. This action is used in
* editors that doesn't have indentation control (like textarea element) to
* provide proper indentation for inserted newlines
* @param {IEmmetEditor} editor Editor instance
*/
insertLineBreakAction: function(editor) {
if (!this.insertLineBreakOnlyAction(editor)) {
var curPadding = editorUtils.getCurrentLinePadding(editor);
var content = String(editor.getContent());
var caretPos = editor.getCaretPos();
var len = content.length;
var nl = '\n';
// check out next line padding
var lineRange = editor.getCurrentLineRange();
var nextPadding = '';
for (var i = lineRange.end + 1, ch; i < len; i++) {
ch = content.charAt(i);
if (ch == ' ' || ch == '\t')
nextPadding += ch;
else
break;
}
if (nextPadding.length > curPadding.length) {
editor.replaceContent(nl + nextPadding, caretPos, caretPos, true);
} else {
editor.replaceContent(nl, caretPos);
}
}
return true;
},
/**
* Inserts newline character with proper indentation in specific positions only.
* @param {IEmmetEditor} editor
* @return {Boolean} Returns <code>true</code> if line break was inserted
*/
insertLineBreakOnlyAction: function(editor) {
var info = editorUtils.outputInfo(editor);
var caretPos = editor.getCaretPos();
var nl = '\n';
var pad = '\t';
if (~xmlSyntaxes.indexOf(info.syntax)) {
// let's see if we're breaking newly created tag
var tag = htmlMatcher.tag(info.content, caretPos);
if (tag && !tag.innerRange.length()) {
editor.replaceContent(nl + pad + utils.getCaretPlaceholder() + nl, caretPos);
return true;
}
} else if (info.syntax == 'css') {
/** @type String */
var content = info.content;
if (caretPos && content.charAt(caretPos - 1) == '{') {
var append = prefs.get('css.closeBraceIndentation');
var hasCloseBrace = content.charAt(caretPos) == '}';
if (!hasCloseBrace) {
// do we really need special formatting here?
// check if this is really a newly created rule,
// look ahead for a closing brace
for (var i = caretPos, il = content.length, ch; i < il; i++) {
ch = content.charAt(i);
if (ch == '{') {
// ok, this is a new rule without closing brace
break;
}
if (ch == '}') {
// not a new rule, just add indentation
append = '';
hasCloseBrace = true;
break;
}
}
}
if (!hasCloseBrace) {
append += '}';
}
// defining rule set
var insValue = nl + pad + utils.getCaretPlaceholder() + append;
editor.replaceContent(insValue, caretPos);
return true;
}
}
return false;
}
};
});
},{"../assets/htmlMatcher":26,"../assets/preferences":28,"../assets/resources":31,"../utils/common":73,"../utils/editor":75}],12:[function(require,module,exports){
/**
* Module describes and performs Emmet actions. The actions themselves are
* defined in <i>actions</i> folder
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
// all registered actions
var actions = {};
// load all default actions
var actionModules = {
base64: require('./base64'),
editPoints: require('./editPoints'),
evaluateMath: require('./evaluateMath'),
expandAbbreviation: require('./expandAbbreviation'),
incrementDecrement: require('./incrementDecrement'),
lineBreaks: require('./lineBreaks'),
balance: require('./balance'),
mergeLines: require('./mergeLines'),
reflectCSSValue: require('./reflectCSSValue'),
removeTag: require('./removeTag'),
selectItem: require('./selectItem'),
selectLine: require('./selectLine'),
splitJoinTag: require('./splitJoinTag'),
toggleComment: require('./toggleComment'),
updateImageSize: require('./updateImageSize'),
wrapWithAbbreviation: require('./wrapWithAbbreviation'),
updateTag: require('./updateTag')
};
function addAction(name, fn, options) {
name = name.toLowerCase();
options = options || {};
if (typeof options === 'string') {
options = {label: options};
}
if (!options.label) {
options.label = humanizeActionName(name);
}
actions[name] = {
name: name,
fn: fn,
options: options
};
}
/**
* “Humanizes” action name, makes it more readable for people
* @param {String} name Action name (like 'expand_abbreviation')
* @return Humanized name (like 'Expand Abbreviation')
*/
function humanizeActionName(name) {
return utils.trim(name.charAt(0).toUpperCase()
+ name.substring(1).replace(/_[a-z]/g, function(str) {
return ' ' + str.charAt(1).toUpperCase();
}));
}
var bind = function(name, method) {
var m = actionModules[name];
return m[method].bind(m);
};
// XXX register default actions
addAction('encode_decode_data_url', bind('base64', 'encodeDecodeDataUrlAction'), 'Encode\\Decode data:URL image');
addAction('prev_edit_point', bind('editPoints', 'previousEditPointAction'), 'Previous Edit Point');
addAction('next_edit_point', bind('editPoints', 'nextEditPointAction'), 'Next Edit Point');
addAction('evaluate_math_expression', bind('evaluateMath', 'evaluateMathAction'), 'Numbers/Evaluate Math Expression');
addAction('expand_abbreviation_with_tab', bind('expandAbbreviation', 'expandAbbreviationWithTabAction'), {hidden: true});
addAction('expand_abbreviation', bind('expandAbbreviation', 'expandAbbreviationAction'), 'Expand Abbreviation');
addAction('insert_formatted_line_break_only', bind('lineBreaks', 'insertLineBreakOnlyAction'), {hidden: true});
addAction('insert_formatted_line_break', bind('lineBreaks', 'insertLineBreakAction'), {hidden: true});
addAction('balance_inward', bind('balance', 'balanceInwardAction'), 'Balance (inward)');
addAction('balance_outward', bind('balance', 'balanceOutwardAction'), 'Balance (outward)');
addAction('matching_pair', bind('balance', 'goToMatchingPairAction'), 'HTML/Go To Matching Tag Pair');
addAction('merge_lines', bind('mergeLines', 'mergeLinesAction'), 'Merge Lines');
addAction('reflect_css_value', bind('reflectCSSValue', 'reflectCSSValueAction'), 'CSS/Reflect Value');
addAction('remove_tag', bind('removeTag', 'removeTagAction'), 'HTML/Remove Tag');
addAction('select_next_item', bind('selectItem', 'selectNextItemAction'), 'Select Next Item');
addAction('select_previous_item', bind('selectItem', 'selectPreviousItemAction'), 'Select Previous Item');
addAction('split_join_tag', bind('splitJoinTag', 'splitJoinTagAction'), 'HTML/Split\\Join Tag Declaration');
addAction('toggle_comment', bind('toggleComment', 'toggleCommentAction'), 'Toggle Comment');
addAction('update_image_size', bind('updateImageSize', 'updateImageSizeAction'), 'Update Image Size');
addAction('wrap_with_abbreviation', bind('wrapWithAbbreviation', 'wrapWithAbbreviationAction'), 'Wrap With Abbreviation');
addAction('update_tag', bind('updateTag', 'updateTagAction'), 'HTML/Update Tag');
[1, -1, 10, -10, 0.1, -0.1].forEach(function(num) {
var prefix = num > 0 ? 'increment' : 'decrement';
var suffix = String(Math.abs(num)).replace('.', '').substring(0, 2);
var actionId = prefix + '_number_by_' + suffix;
var actionMethod = prefix + suffix + 'Action';
var actionLabel = 'Numbers/' + prefix.charAt(0).toUpperCase() + prefix.substring(1) + ' number by ' + Math.abs(num);
addAction(actionId, bind('incrementDecrement', actionMethod), actionLabel);
});
return {
/**
* Registers new action
* @param {String} name Action name
* @param {Function} fn Action function
* @param {Object} options Custom action options:<br>
* <b>label</b> : (<code>String</code>) Human-readable action name.
* May contain '/' symbols as submenu separators<br>
* <b>hidden</b> : (<code>Boolean</code>) Indicates whether action
* should be displayed in menu (<code>getMenu()</code> method)
*/
add: addAction,
/**
* Returns action object
* @param {String} name Action name
* @returns {Object}
*/
get: function(name) {
return actions[name.toLowerCase()];
},
/**
* Runs Emmet action. For list of available actions and their
* arguments see <i>actions</i> folder.
* @param {String} name Action name
* @param {Array} args Additional arguments. It may be array of arguments
* or inline arguments. The first argument should be <code>IEmmetEditor</code> instance
* @returns {Boolean} Status of performed operation, <code>true</code>
* means action was performed successfully.
* @example
* require('action/main').run('expand_abbreviation', editor);
* require('action/main').run('wrap_with_abbreviation', [editor, 'div']);
*/
run: function(name, args) {
if (!Array.isArray(args)) {
args = utils.toArray(arguments, 1);
}
var action = this.get(name);
if (!action) {
throw new Error('Action "' + name + '" is not defined');
}
return action.fn.apply(action, args);
},
/**
* Returns all registered actions as object
* @returns {Object}
*/
getAll: function() {
return actions;
},
/**
* Returns all registered actions as array
* @returns {Array}
*/
getList: function() {
var all = this.getAll();
return Object.keys(all).map(function(key) {
return all[key];
});
},
/**
* Returns actions list as structured menu. If action has <i>label</i>,
* it will be splitted by '/' symbol into submenus (for example:
* CSS/Reflect Value) and grouped with other items
* @param {Array} skipActions List of action identifiers that should be
* skipped from menu
* @returns {Array}
*/
getMenu: function(skipActions) {
var result = [];
skipActions = skipActions || [];
this.getList().forEach(function(action) {
if (action.options.hidden || ~skipActions.indexOf(action.name))
return;
var actionName = humanizeActionName(action.name);
var ctx = result;
if (action.options.label) {
var parts = action.options.label.split('/');
actionName = parts.pop();
// create submenus, if needed
var menuName, submenu;
while ((menuName = parts.shift())) {
submenu = utils.find(ctx, function(item) {
return item.type == 'submenu' && item.name == menuName;
});
if (!submenu) {
submenu = {
name: menuName,
type: 'submenu',
items: []
};
ctx.push(submenu);
}
ctx = submenu.items;
}
}
ctx.push({
type: 'action',
name: action.name,
label: actionName
});
});
return result;
},
/**
* Returns action name associated with menu item title
* @param {String} title
* @returns {String}
*/
getActionNameForMenuTitle: function(title, menu) {
return utils.find(menu || this.getMenu(), function(val) {
if (val.type == 'action') {
if (val.label == title || val.name == title) {
return val.name;
}
} else {
return this.getActionNameForMenuTitle(title, val.items);
}
}, this);
}
};
});
},{"../utils/common":73,"./balance":5,"./base64":6,"./editPoints":7,"./evaluateMath":8,"./expandAbbreviation":9,"./incrementDecrement":10,"./lineBreaks":11,"./mergeLines":13,"./reflectCSSValue":14,"./removeTag":15,"./selectItem":16,"./selectLine":17,"./splitJoinTag":18,"./toggleComment":19,"./updateImageSize":20,"./updateTag":21,"./wrapWithAbbreviation":22}],13:[function(require,module,exports){
/**
* Merges selected lines or lines between XHTML tag pairs
* @param {Function} require
* @param {Underscore} _
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var htmlMatcher = require('../assets/htmlMatcher');
var utils = require('../utils/common');
var editorUtils = require('../utils/editor');
var range = require('../assets/range');
return {
mergeLinesAction: function(editor) {
var info = editorUtils.outputInfo(editor);
var selection = range(editor.getSelectionRange());
if (!selection.length()) {
// find matching tag
var pair = htmlMatcher.find(info.content, editor.getCaretPos());
if (pair) {
selection = pair.outerRange;
}
}
if (selection.length()) {
// got range, merge lines
var text = selection.substring(info.content);
var lines = utils.splitByLines(text);
for (var i = 1; i < lines.length; i++) {
lines[i] = lines[i].replace(/^\s+/, '');
}
text = lines.join('').replace(/\s{2,}/, ' ');
var textLen = text.length;
text = utils.escapeText(text);
editor.replaceContent(text, selection.start, selection.end);
editor.createSelection(selection.start, selection.start + textLen);
return true;
}
return false;
}
};
});
},{"../assets/htmlMatcher":26,"../assets/range":30,"../utils/common":73,"../utils/editor":75}],14:[function(require,module,exports){
/**
* Reflect CSS value: takes rule's value under caret and pastes it for the same
* rules with vendor prefixes
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var handlerList = require('../assets/handlerList');
var prefs = require('../assets/preferences');
var cssResolver = require('../resolver/css');
var cssEditTree = require('../editTree/css');
var utils = require('../utils/common');
var actionUtils = require('../utils/action');
var editorUtils = require('../utils/editor');
var cssGradient = require('../resolver/cssGradient');
prefs.define('css.reflect.oldIEOpacity', false, 'Support IE6/7/8 opacity notation, e.g. <code>filter:alpha(opacity=...)</code>.\
Note that CSS3 and SVG also provides <code>filter</code> property so this option is disabled by default.')
/**
* @type HandlerList List of registered handlers
*/
var handlers = handlerList.create();
function doCSSReflection(editor) {
var outputInfo = editorUtils.outputInfo(editor);
var caretPos = editor.getCaretPos();
var cssRule = cssEditTree.parseFromPosition(outputInfo.content, caretPos);
if (!cssRule) return;
var property = cssRule.itemFromPosition(caretPos, true);
// no property under cursor, nothing to reflect
if (!property) return;
var oldRule = cssRule.source;
var offset = cssRule.options.offset;
var caretDelta = caretPos - offset - property.range().start;
handlers.exec(false, [property]);
if (oldRule !== cssRule.source) {
return {
data: cssRule.source,
start: offset,
end: offset + oldRule.length,
caret: offset + property.range().start + caretDelta
};
}
}
/**
* Returns regexp that should match reflected CSS property names
* @param {String} name Current CSS property name
* @return {RegExp}
*/
function getReflectedCSSName(name) {
name = cssEditTree.baseName(name);
var vendorPrefix = '^(?:\\-\\w+\\-)?', m;
if ((name == 'opacity' || name == 'filter') && prefs.get('css.reflect.oldIEOpacity')) {
return new RegExp(vendorPrefix + '(?:opacity|filter)$');
} else if ((m = name.match(/^border-radius-(top|bottom)(left|right)/))) {
// Mozilla-style border radius
return new RegExp(vendorPrefix + '(?:' + name + '|border-' + m[1] + '-' + m[2] + '-radius)$');
} else if ((m = name.match(/^border-(top|bottom)-(left|right)-radius/))) {
return new RegExp(vendorPrefix + '(?:' + name + '|border-radius-' + m[1] + m[2] + ')$');
}
return new RegExp(vendorPrefix + name + '$');
}
/**
* Reflects inner CSS properites in given value
* agains names vendor prefix. In other words, it tries
* to modify `transform 0.2s linear` value for `-webkit-transition`
* property
* @param {String} name Reciever CSS property name
* @param {String} value New property value
* @return {String}
*/
function reflectValueParts(name, value) {
// detects and updates vendor-specific properties in value,
// e.g. -webkit-transition: -webkit-transform
var reVendor = /^\-(\w+)\-/;
var propPrefix = reVendor.test(name) ? RegExp.$1.toLowerCase() : '';
var parts = cssEditTree.findParts(value);
parts.reverse();
parts.forEach(function(part) {
var partValue = part.substring(value).replace(reVendor, '');
var prefixes = cssResolver.vendorPrefixes(partValue);
if (prefixes) {
// if prefixes are not null then given value can
// be resolved against Can I Use database and may or
// may not contain prefixed variant
if (propPrefix && ~prefixes.indexOf(propPrefix)) {
partValue = '-' + propPrefix + '-' + partValue;
}
value = utils.replaceSubstring(value, partValue, part);
}
});
return value;
}
/**
* Reflects value from <code>donor</code> into <code>receiver</code>
* @param {CSSProperty} donor Donor CSS property from which value should
* be reflected
* @param {CSSProperty} receiver Property that should receive reflected
* value from donor
*/
function reflectValue(donor, receiver) {
var value = getReflectedValue(donor.name(), donor.value(),
receiver.name(), receiver.value());
value = reflectValueParts(receiver.name(), value);
receiver.value(value);
}
/**
* Returns value that should be reflected for <code>refName</code> CSS property
* from <code>curName</code> property. This function is used for special cases,
* when the same result must be achieved with different properties for different
* browsers. For example: opаcity:0.5; → filter:alpha(opacity=50);<br><br>
*
* This function does value conversion between different CSS properties
*
* @param {String} curName Current CSS property name
* @param {String} curValue Current CSS property value
* @param {String} refName Receiver CSS property's name
* @param {String} refValue Receiver CSS property's value
* @return {String} New value for receiver property
*/
function getReflectedValue(curName, curValue, refName, refValue) {
curName = cssEditTree.baseName(curName);
refName = cssEditTree.baseName(refName);
if (curName == 'opacity' && refName == 'filter') {
return refValue.replace(/opacity=[^)]*/i, 'opacity=' + Math.floor(parseFloat(curValue) * 100));
} else if (curName == 'filter' && refName == 'opacity') {
var m = curValue.match(/opacity=([^)]*)/i);
return m ? utils.prettifyNumber(parseInt(m[1], 10) / 100) : refValue;
}
return curValue;
}
module = module || {};
module.exports = {
reflectCSSValueAction: function(editor) {
if (editor.getSyntax() != 'css') {
return false;
}
return actionUtils.compoundUpdate(editor, doCSSReflection(editor));
},
_defaultHandler: function(property) {
var reName = getReflectedCSSName(property.name());
property.parent.list().forEach(function(p) {
if (reName.test(p.name())) {
reflectValue(property, p);
}
});
},
/**
* Adds custom reflect handler. The passed function will receive matched
* CSS property (as <code>CSSEditElement</code> object) and should
* return <code>true</code> if it was performed successfully (handled
* reflection), <code>false</code> otherwise.
* @param {Function} fn
* @param {Object} options
*/
addHandler: function(fn, options) {
handlers.add(fn, options);
},
/**
* Removes registered handler
* @returns
*/
removeHandler: function(fn) {
handlers.remove(fn);
}
};
// XXX add default handlers
handlers.add(module.exports._defaultHandler.bind(module.exports), {order: -1});
handlers.add(cssGradient.reflectValueHandler.bind(cssGradient));
return module.exports;
});
},{"../assets/handlerList":25,"../assets/preferences":28,"../editTree/css":37,"../resolver/css":64,"../resolver/cssGradient":65,"../utils/action":70,"../utils/common":73,"../utils/editor":75}],15:[function(require,module,exports){
/**
* Gracefully removes tag under cursor
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var editorUtils = require('../utils/editor');
var htmlMatcher = require('../assets/htmlMatcher');
return {
removeTagAction: function(editor) {
var info = editorUtils.outputInfo(editor);
// search for tag
var tag = htmlMatcher.tag(info.content, editor.getCaretPos());
if (tag) {
if (!tag.close) {
// simply remove unary tag
editor.replaceContent(utils.getCaretPlaceholder(), tag.range.start, tag.range.end);
} else {
// remove tag and its newlines
/** @type Range */
var tagContentRange = utils.narrowToNonSpace(info.content, tag.innerRange);
/** @type Range */
var startLineBounds = utils.findNewlineBounds(info.content, tagContentRange.start);
var startLinePad = utils.getLinePadding(startLineBounds.substring(info.content));
var tagContent = tagContentRange.substring(info.content);
tagContent = utils.unindentString(tagContent, startLinePad);
editor.replaceContent(utils.getCaretPlaceholder() + utils.escapeText(tagContent), tag.outerRange.start, tag.outerRange.end);
}
return true;
}
return false;
}
};
});
},{"../assets/htmlMatcher":26,"../utils/common":73,"../utils/editor":75}],16:[function(require,module,exports){
/**
* Actions that use stream parsers and tokenizers for traversing:
* -- Search for next/previous items in HTML
* -- Search for next/previous items in CSS
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var range = require('../assets/range');
var utils = require('../utils/common');
var editorUtils = require('../utils/editor');
var actionUtils = require('../utils/action');
var stringStream = require('../assets/stringStream');
var xmlParser = require('../parser/xml');
var cssEditTree = require('../editTree/css');
var cssSections = require('../utils/cssSections');
var startTag = /^<([\w\:\-]+)((?:\s+[\w\-:]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/;
/**
* Generic function for searching for items to select
* @param {IEmmetEditor} editor
* @param {Boolean} isBackward Search backward (search forward otherwise)
* @param {Function} extractFn Function that extracts item content
* @param {Function} rangeFn Function that search for next token range
*/
function findItem(editor, isBackward, extractFn, rangeFn) {
var content = editorUtils.outputInfo(editor).content;
var contentLength = content.length;
var itemRange, rng;
/** @type Range */
var prevRange = range(-1, 0);
/** @type Range */
var sel = range(editor.getSelectionRange());
var searchPos = sel.start, loop = 100000; // endless loop protection
while (searchPos >= 0 && searchPos < contentLength && --loop > 0) {
if ( (itemRange = extractFn(content, searchPos, isBackward)) ) {
if (prevRange.equal(itemRange)) {
break;
}
prevRange = itemRange.clone();
rng = rangeFn(itemRange.substring(content), itemRange.start, sel.clone());
if (rng) {
editor.createSelection(rng.start, rng.end);
return true;
} else {
searchPos = isBackward ? itemRange.start : itemRange.end - 1;
}
}
searchPos += isBackward ? -1 : 1;
}
return false;
}
// XXX HTML section
/**
* Find next HTML item
* @param {IEmmetEditor} editor
*/
function findNextHTMLItem(editor) {
var isFirst = true;
return findItem(editor, false, function(content, searchPos){
if (isFirst) {
isFirst = false;
return findOpeningTagFromPosition(content, searchPos);
} else {
return getOpeningTagFromPosition(content, searchPos);
}
}, function(tag, offset, selRange) {
return getRangeForHTMLItem(tag, offset, selRange, false);
});
}
/**
* Find previous HTML item
* @param {IEmmetEditor} editor
*/
function findPrevHTMLItem(editor) {
return findItem(editor, true, getOpeningTagFromPosition, function (tag, offset, selRange) {
return getRangeForHTMLItem(tag, offset, selRange, true);
});
}
/**
* Creates possible selection ranges for HTML tag
* @param {String} source Original HTML source for tokens
* @param {Array} tokens List of HTML tokens
* @returns {Array}
*/
function makePossibleRangesHTML(source, tokens, offset) {
offset = offset || 0;
var result = [];
var attrStart = -1, attrName = '', attrValue = '', attrValueRange, tagName;
tokens.forEach(function(tok) {
switch (tok.type) {
case 'tag':
tagName = source.substring(tok.start, tok.end);
if (/^<[\w\:\-]/.test(tagName)) {
// add tag name
result.push(range({
start: tok.start + 1,
end: tok.end
}));
}
break;
case 'attribute':
attrStart = tok.start;
attrName = source.substring(tok.start, tok.end);
break;
case 'string':
// attribute value
// push full attribute first
result.push(range(attrStart, tok.end - attrStart));
attrValueRange = range(tok);
attrValue = attrValueRange.substring(source);
// is this a quoted attribute?
if (isQuote(attrValue.charAt(0)))
attrValueRange.start++;
if (isQuote(attrValue.charAt(attrValue.length - 1)))
attrValueRange.end--;
result.push(attrValueRange);
if (attrName == 'class') {
result = result.concat(classNameRanges(attrValueRange.substring(source), attrValueRange.start));
}
break;
}
});
// offset ranges
result = result.filter(function(item) {
if (item.length()) {
item.shift(offset);
return true;
}
});
// remove duplicates
return utils.unique(result, function(item) {
return item.toString();
});
}
/**
* Returns ranges of class names in "class" attribute value
* @param {String} className
* @returns {Array}
*/
function classNameRanges(className, offset) {
offset = offset || 0;
var result = [];
/** @type StringStream */
var stream = stringStream.create(className);
// skip whitespace
stream.eatSpace();
stream.start = stream.pos;
var ch;
while ((ch = stream.next())) {
if (/[\s\u00a0]/.test(ch)) {
result.push(range(stream.start + offset, stream.pos - stream.start - 1));
stream.eatSpace();
stream.start = stream.pos;
}
}
result.push(range(stream.start + offset, stream.pos - stream.start));
return result;
}
/**
* Returns best HTML tag range match for current selection
* @param {String} tag Tag declaration
* @param {Number} offset Tag's position index inside content
* @param {Range} selRange Selection range
* @return {Range} Returns range if next item was found, <code>null</code> otherwise
*/
function getRangeForHTMLItem(tag, offset, selRange, isBackward) {
var ranges = makePossibleRangesHTML(tag, xmlParser.parse(tag), offset);
if (isBackward)
ranges.reverse();
// try to find selected range
var curRange = utils.find(ranges, function(r) {
return r.equal(selRange);
});
if (curRange) {
var ix = ranges.indexOf(curRange);
if (ix < ranges.length - 1)
return ranges[ix + 1];
return null;
}
// no selected range, find nearest one
if (isBackward)
// search backward
return utils.find(ranges, function(r) {
return r.start < selRange.start;
});
// search forward
// to deal with overlapping ranges (like full attribute definition
// and attribute value) let's find range under caret first
if (!curRange) {
var matchedRanges = ranges.filter(function(r) {
return r.inside(selRange.end);
});
if (matchedRanges.length > 1)
return matchedRanges[1];
}
return utils.find(ranges, function(r) {
return r.end > selRange.end;
});
}
/**
* Search for opening tag in content, starting at specified position
* @param {String} html Where to search tag
* @param {Number} pos Character index where to start searching
* @return {Range} Returns range if valid opening tag was found,
* <code>null</code> otherwise
*/
function findOpeningTagFromPosition(html, pos) {
var tag;
while (pos >= 0) {
if ((tag = getOpeningTagFromPosition(html, pos)))
return tag;
pos--;
}
return null;
}
/**
* @param {String} html Where to search tag
* @param {Number} pos Character index where to start searching
* @return {Range} Returns range if valid opening tag was found,
* <code>null</code> otherwise
*/
function getOpeningTagFromPosition(html, pos) {
var m;
if (html.charAt(pos) == '<' && (m = html.substring(pos, html.length).match(startTag))) {
return range(pos, m[0]);
}
}
function isQuote(ch) {
return ch == '"' || ch == "'";
}
/**
* Returns all ranges inside given rule, available for selection
* @param {CSSEditContainer} rule
* @return {Array}
*/
function findInnerRanges(rule) {
// rule selector
var ranges = [rule.nameRange(true)];
// find nested sections, keep selectors only
var nestedSections = cssSections.nestedSectionsInRule(rule);
nestedSections.forEach(function(section) {
ranges.push(range.create2(section.start, section._selectorEnd));
});
// add full property ranges and values
rule.list().forEach(function(property) {
ranges = ranges.concat(makePossibleRangesCSS(property));
});
ranges = range.sort(ranges);
// optimize result: remove empty ranges and duplicates
ranges = ranges.filter(function(item) {
return !!item.length();
});
return utils.unique(ranges, function(item) {
return item.toString();
});
}
/**
* Makes all possible selection ranges for specified CSS property
* @param {CSSProperty} property
* @returns {Array}
*/
function makePossibleRangesCSS(property) {
// find all possible ranges, sorted by position and size
var valueRange = property.valueRange(true);
var result = [property.range(true), valueRange];
// locate parts of complex values.
// some examples:
// 1px solid red: 3 parts
// arial, sans-serif: enumeration, 2 parts
// url(image.png): function value part
var value = property.value();
property.valueParts().forEach(function(r) {
// add absolute range
var clone = r.clone();
result.push(clone.shift(valueRange.start));
/** @type StringStream */
var stream = stringStream.create(r.substring(value));
if (stream.match(/^[\w\-]+\(/, true)) {
// we have a function, find values in it.
// but first add function contents
stream.start = stream.pos;
stream.backUp(1);
stream.skipToPair('(', ')');
stream.backUp(1);
var fnBody = stream.current();
result.push(range(clone.start + stream.start, fnBody));
// find parts
cssEditTree.findParts(fnBody).forEach(function(part) {
result.push(range(clone.start + stream.start + part.start, part.substring(fnBody)));
});
}
});
return result;
}
/**
* Tries to find matched CSS property and nearest range for selection
* @param {CSSRule} rule
* @param {Range} selRange
* @param {Boolean} isBackward
* @returns {Range}
*/
function matchedRangeForCSSProperty(rule, selRange, isBackward) {
var ranges = findInnerRanges(rule);
if (isBackward) {
ranges.reverse();
}
// return next to selected range, if possible
var r = utils.find(ranges, function(item) {
return item.equal(selRange);
});
if (r) {
return ranges[ranges.indexOf(r) + 1];
}
// find matched and (possibly) overlapping ranges
var nested = ranges.filter(function(item) {
return item.inside(selRange.end);
});
if (nested.length) {
return nested.sort(function(a, b) {
return a.length() - b.length();
})[0];
}
// return range next to caret
var test =
r = utils.find(ranges, isBackward
? function(item) {return item.end < selRange.start;}
: function(item) {return item.end > selRange.start;}
);
if (!r) {
// cant find anything, just pick first one
r = ranges[0];
}
return r;
}
function findNextCSSItem(editor) {
return findItem(editor, false, cssSections.locateRule.bind(cssSections), getRangeForNextItemInCSS);
}
function findPrevCSSItem(editor) {
return findItem(editor, true, cssSections.locateRule.bind(cssSections), getRangeForPrevItemInCSS);
}
/**
* Returns range for item to be selected in CSS after current caret
* (selection) position
* @param {String} rule CSS rule declaration
* @param {Number} offset Rule's position index inside content
* @param {Range} selRange Selection range
* @return {Range} Returns range if next item was found, <code>null</code> otherwise
*/
function getRangeForNextItemInCSS(rule, offset, selRange) {
var tree = cssEditTree.parse(rule, {
offset: offset
});
return matchedRangeForCSSProperty(tree, selRange, false);
}
/**
* Returns range for item to be selected in CSS before current caret
* (selection) position
* @param {String} rule CSS rule declaration
* @param {Number} offset Rule's position index inside content
* @param {Range} selRange Selection range
* @return {Range} Returns range if previous item was found, <code>null</code> otherwise
*/
function getRangeForPrevItemInCSS(rule, offset, selRange) {
var tree = cssEditTree.parse(rule, {
offset: offset
});
return matchedRangeForCSSProperty(tree, selRange, true);
}
return {
selectNextItemAction: function(editor) {
if (actionUtils.isSupportedCSS(editor.getSyntax())) {
return findNextCSSItem(editor);
} else {
return findNextHTMLItem(editor);
}
},
selectPreviousItemAction: function(editor) {
if (actionUtils.isSupportedCSS(editor.getSyntax())) {
return findPrevCSSItem(editor);
} else {
return findPrevHTMLItem(editor);
}
}
};
});
},{"../assets/range":30,"../assets/stringStream":32,"../editTree/css":37,"../parser/xml":62,"../utils/action":70,"../utils/common":73,"../utils/cssSections":74,"../utils/editor":75}],17:[function(require,module,exports){
/**
* Select current line (for simple editors like browser's &lt;textarea&gt;)
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
return {
selectLineAction: function(editor) {
var range = editor.getCurrentLineRange();
editor.createSelection(range.start, range.end);
return true;
}
};
});
},{}],18:[function(require,module,exports){
/**
* Splits or joins tag, e.g. transforms it into a short notation and vice versa:<br>
* &lt;div&gt;&lt;/div&gt; → &lt;div /&gt; : join<br>
* &lt;div /&gt; → &lt;div&gt;&lt;/div&gt; : split
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var resources = require('../assets/resources');
var matcher = require('../assets/htmlMatcher');
var editorUtils = require('../utils/editor');
var profile = require('../assets/profile');
/**
* @param {IEmmetEditor} editor
* @param {Object} profile
* @param {Object} tag
*/
function joinTag(editor, profile, tag) {
// empty closing slash is a nonsense for this action
var slash = profile.selfClosing() || ' /';
var content = tag.open.range.substring(tag.source).replace(/\s*>$/, slash + '>');
var caretPos = editor.getCaretPos();
// update caret position
if (content.length + tag.outerRange.start < caretPos) {
caretPos = content.length + tag.outerRange.start;
}
content = utils.escapeText(content);
editor.replaceContent(content, tag.outerRange.start, tag.outerRange.end);
editor.setCaretPos(caretPos);
return true;
}
function splitTag(editor, profile, tag) {
var caretPos = editor.getCaretPos();
// define tag content depending on profile
var tagContent = (profile.tag_nl === true) ? '\n\t\n' : '';
var content = tag.outerContent().replace(/\s*\/>$/, '>');
caretPos = tag.outerRange.start + content.length;
content += tagContent + '</' + tag.open.name + '>';
content = utils.escapeText(content);
editor.replaceContent(content, tag.outerRange.start, tag.outerRange.end);
editor.setCaretPos(caretPos);
return true;
}
return {
splitJoinTagAction: function(editor, profileName) {
var info = editorUtils.outputInfo(editor, null, profileName);
var curProfile = profile.get(info.profile);
// find tag at current position
var tag = matcher.tag(info.content, editor.getCaretPos());
if (tag) {
return tag.close
? joinTag(editor, curProfile, tag)
: splitTag(editor, curProfile, tag);
}
return false;
}
};
});
},{"../assets/htmlMatcher":26,"../assets/profile":29,"../assets/resources":31,"../utils/common":73,"../utils/editor":75}],19:[function(require,module,exports){
/**
* Toggles HTML and CSS comments depending on current caret context. Unlike
* the same action in most editors, this action toggles comment on currently
* matched item—HTML tag or CSS selector—when nothing is selected.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var prefs = require('../assets/preferences');
var range = require('../assets/range');
var utils = require('../utils/common');
var actionUtils = require('../utils/action');
var editorUtils = require('../utils/editor');
var htmlMatcher = require('../assets/htmlMatcher');
var cssEditTree = require('../editTree/css');
/**
* Toggle HTML comment on current selection or tag
* @param {IEmmetEditor} editor
* @return {Boolean} Returns <code>true</code> if comment was toggled
*/
function toggleHTMLComment(editor) {
/** @type Range */
var r = range(editor.getSelectionRange());
var info = editorUtils.outputInfo(editor);
if (!r.length()) {
// no selection, find matching tag
var tag = htmlMatcher.tag(info.content, editor.getCaretPos());
if (tag) { // found pair
r = tag.outerRange;
}
}
return genericCommentToggle(editor, '<!--', '-->', r);
}
/**
* Simple CSS commenting
* @param {IEmmetEditor} editor
* @return {Boolean} Returns <code>true</code> if comment was toggled
*/
function toggleCSSComment(editor) {
/** @type Range */
var rng = range(editor.getSelectionRange());
var info = editorUtils.outputInfo(editor);
if (!rng.length()) {
// no selection, try to get current rule
/** @type CSSRule */
var rule = cssEditTree.parseFromPosition(info.content, editor.getCaretPos());
if (rule) {
var property = cssItemFromPosition(rule, editor.getCaretPos());
rng = property
? property.range(true)
: range(rule.nameRange(true).start, rule.source);
}
}
if (!rng.length()) {
// still no selection, get current line
rng = range(editor.getCurrentLineRange());
utils.narrowToNonSpace(info.content, rng);
}
return genericCommentToggle(editor, '/*', '*/', rng);
}
/**
* Returns CSS property from <code>rule</code> that matches passed position
* @param {EditContainer} rule
* @param {Number} absPos
* @returns {EditElement}
*/
function cssItemFromPosition(rule, absPos) {
// do not use default EditContainer.itemFromPosition() here, because
// we need to make a few assumptions to make CSS commenting more reliable
var relPos = absPos - (rule.options.offset || 0);
var reSafeChar = /^[\s\n\r]/;
return utils.find(rule.list(), function(item) {
if (item.range().end === relPos) {
// at the end of property, but outside of it
// if theres a space character at current position,
// use current property
return reSafeChar.test(rule.source.charAt(relPos));
}
return item.range().inside(relPos);
});
}
/**
* Search for nearest comment in <code>str</code>, starting from index <code>from</code>
* @param {String} text Where to search
* @param {Number} from Search start index
* @param {String} start_token Comment start string
* @param {String} end_token Comment end string
* @return {Range} Returns null if comment wasn't found
*/
function searchComment(text, from, startToken, endToken) {
var commentStart = -1;
var commentEnd = -1;
var hasMatch = function(str, start) {
return text.substr(start, str.length) == str;
};
// search for comment start
while (from--) {
if (hasMatch(startToken, from)) {
commentStart = from;
break;
}
}
if (commentStart != -1) {
// search for comment end
from = commentStart;
var contentLen = text.length;
while (contentLen >= from++) {
if (hasMatch(endToken, from)) {
commentEnd = from + endToken.length;
break;
}
}
}
return (commentStart != -1 && commentEnd != -1)
? range(commentStart, commentEnd - commentStart)
: null;
}
/**
* Generic comment toggling routine
* @param {IEmmetEditor} editor
* @param {String} commentStart Comment start token
* @param {String} commentEnd Comment end token
* @param {Range} range Selection range
* @return {Boolean}
*/
function genericCommentToggle(editor, commentStart, commentEnd, range) {
var content = editorUtils.outputInfo(editor).content;
var caretPos = editor.getCaretPos();
var newContent = null;
/**
* Remove comment markers from string
* @param {Sting} str
* @return {String}
*/
function removeComment(str) {
return str
.replace(new RegExp('^' + utils.escapeForRegexp(commentStart) + '\\s*'), function(str){
caretPos -= str.length;
return '';
}).replace(new RegExp('\\s*' + utils.escapeForRegexp(commentEnd) + '$'), '');
}
// first, we need to make sure that this substring is not inside
// comment
var commentRange = searchComment(content, caretPos, commentStart, commentEnd);
if (commentRange && commentRange.overlap(range)) {
// we're inside comment, remove it
range = commentRange;
newContent = removeComment(range.substring(content));
} else {
// should add comment
// make sure that there's no comment inside selection
newContent = commentStart + ' ' +
range.substring(content)
.replace(new RegExp(utils.escapeForRegexp(commentStart) + '\\s*|\\s*' + utils.escapeForRegexp(commentEnd), 'g'), '') +
' ' + commentEnd;
// adjust caret position
caretPos += commentStart.length + 1;
}
// replace editor content
if (newContent !== null) {
newContent = utils.escapeText(newContent);
editor.setCaretPos(range.start);
editor.replaceContent(editorUtils.unindent(editor, newContent), range.start, range.end);
editor.setCaretPos(caretPos);
return true;
}
return false;
}
return {
/**
* Toggle comment on current editor's selection or HTML tag/CSS rule
* @param {IEmmetEditor} editor
*/
toggleCommentAction: function(editor) {
var info = editorUtils.outputInfo(editor);
if (actionUtils.isSupportedCSS(info.syntax)) {
// in case our editor is good enough and can recognize syntax from
// current token, we have to make sure that cursor is not inside
// 'style' attribute of html element
var caretPos = editor.getCaretPos();
var tag = htmlMatcher.tag(info.content, caretPos);
if (tag && tag.open.range.inside(caretPos)) {
info.syntax = 'html';
}
}
var cssSyntaxes = prefs.getArray('css.syntaxes');
if (~cssSyntaxes.indexOf(info.syntax)) {
return toggleCSSComment(editor);
}
return toggleHTMLComment(editor);
}
};
});
},{"../assets/htmlMatcher":26,"../assets/preferences":28,"../assets/range":30,"../editTree/css":37,"../utils/action":70,"../utils/common":73,"../utils/editor":75}],20:[function(require,module,exports){
/**
* Automatically updates image size attributes in HTML's &lt;img&gt; element or
* CSS rule
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var editorUtils = require('../utils/editor');
var actionUtils = require('../utils/action');
var xmlEditTree = require('../editTree/xml');
var cssEditTree = require('../editTree/css');
var base64 = require('../utils/base64');
var file = require('../plugin/file');
/**
* Updates image size of &lt;img src=""&gt; tag
* @param {IEmmetEditor} editor
*/
function updateImageSizeHTML(editor) {
var offset = editor.getCaretPos();
// find tag from current caret position
var info = editorUtils.outputInfo(editor);
var xmlElem = xmlEditTree.parseFromPosition(info.content, offset, true);
if (xmlElem && (xmlElem.name() || '').toLowerCase() == 'img') {
getImageSizeForSource(editor, xmlElem.value('src'), function(size) {
if (size) {
var compoundData = xmlElem.range(true);
xmlElem.value('width', size.width);
xmlElem.value('height', size.height, xmlElem.indexOf('width') + 1);
actionUtils.compoundUpdate(editor, utils.extend(compoundData, {
data: xmlElem.toString(),
caret: offset
}));
}
});
}
}
/**
* Updates image size of CSS property
* @param {IEmmetEditor} editor
*/
function updateImageSizeCSS(editor) {
var offset = editor.getCaretPos();
// find tag from current caret position
var info = editorUtils.outputInfo(editor);
var cssRule = cssEditTree.parseFromPosition(info.content, offset, true);
if (cssRule) {
// check if there is property with image under caret
var prop = cssRule.itemFromPosition(offset, true), m;
if (prop && (m = /url\((["']?)(.+?)\1\)/i.exec(prop.value() || ''))) {
getImageSizeForSource(editor, m[2], function(size) {
if (size) {
var compoundData = cssRule.range(true);
cssRule.value('width', size.width + 'px');
cssRule.value('height', size.height + 'px', cssRule.indexOf('width') + 1);
actionUtils.compoundUpdate(editor, utils.extend(compoundData, {
data: cssRule.toString(),
caret: offset
}));
}
});
}
}
}
/**
* Returns image dimensions for source
* @param {IEmmetEditor} editor
* @param {String} src Image source (path or data:url)
*/
function getImageSizeForSource(editor, src, callback) {
var fileContent;
if (src) {
// check if it is data:url
if (/^data:/.test(src)) {
fileContent = base64.decode( src.replace(/^data\:.+?;.+?,/, '') );
return callback(actionUtils.getImageSize(fileContent));
}
var absPath = file.locateFile(editor.getFilePath(), src);
if (absPath === null) {
throw "Can't find " + src + ' file';
}
file.read(absPath, function(err, content) {
if (err) {
throw 'Unable to read ' + absPath + ': ' + err;
}
content = String(content);
callback(actionUtils.getImageSize(content));
});
}
}
return {
updateImageSizeAction: function(editor) {
// this action will definitely wont work in SASS dialect,
// but may work in SCSS or LESS
if (actionUtils.isSupportedCSS(editor.getSyntax())) {
updateImageSizeCSS(editor);
} else {
updateImageSizeHTML(editor);
}
return true;
}
};
});
},{"../editTree/css":37,"../editTree/xml":38,"../plugin/file":63,"../utils/action":70,"../utils/base64":71,"../utils/common":73,"../utils/editor":75}],21:[function(require,module,exports){
/**
* Update Tag action: allows users to update existing HTML tags and add/remove
* attributes or even tag name
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var xmlEditTree = require('../editTree/xml');
var editorUtils = require('../utils/editor');
var actionUtils = require('../utils/action');
var utils = require('../utils/common');
var parser = require('../parser/abbreviation');
function updateAttributes(tag, abbrNode, ix) {
var classNames = (abbrNode.attribute('class') || '').split(/\s+/g);
if (ix) {
classNames.push('+' + abbrNode.name());
}
var r = function(str) {
return utils.replaceCounter(str, abbrNode.counter);
};
// update class
classNames.forEach(function(className) {
if (!className) {
return;
}
className = r(className);
var ch = className.charAt(0);
if (ch == '+') {
tag.addClass(className.substr(1));
} else if (ch == '-') {
tag.removeClass(className.substr(1));
} else {
tag.value('class', className);
}
});
// update attributes
abbrNode.attributeList().forEach(function(attr) {
if (attr.name.toLowerCase() == 'class') {
return;
}
var ch = attr.name.charAt(0);
if (ch == '+') {
var attrName = attr.name.substr(1);
var tagAttr = tag.get(attrName);
if (tagAttr) {
tagAttr.value(tagAttr.value() + r(attr.value));
} else {
tag.value(attrName, r(attr.value));
}
} else if (ch == '-') {
tag.remove(attr.name.substr(1));
} else {
tag.value(attr.name, r(attr.value));
}
});
}
return {
/**
* Matches HTML tag under caret and updates its definition
* according to given abbreviation
* @param {IEmmetEditor} Editor instance
* @param {String} abbr Abbreviation to update with
*/
updateTagAction: function(editor, abbr) {
abbr = abbr || editor.prompt("Enter abbreviation");
if (!abbr) {
return false;
}
var content = editor.getContent();
var ctx = actionUtils.captureContext(editor);
var tag = this.getUpdatedTag(abbr, ctx, content);
if (!tag) {
// nothing to update
return false;
}
// check if tag name was updated
if (tag.name() != ctx.name && ctx.match.close) {
editor.replaceContent('</' + tag.name() + '>', ctx.match.close.range.start, ctx.match.close.range.end, true);
}
editor.replaceContent(tag.source, ctx.match.open.range.start, ctx.match.open.range.end, true);
return true;
},
/**
* Returns XMLEditContainer node with updated tag structure
* of existing tag context.
* This data can be used to modify existing tag
* @param {String} abbr Abbreviation
* @param {Object} ctx Tag to be updated (captured with `htmlMatcher`)
* @param {String} content Original editor content
* @return {XMLEditContainer}
*/
getUpdatedTag: function(abbr, ctx, content, options) {
if (!ctx) {
// nothing to update
return null;
}
var tree = parser.parse(abbr, options || {});
// for this action some characters in abbreviation has special
// meaning. For example, `.-c2` means “remove `c2` class from
// element” and `.+c3` means “append class `c3` to exising one.
//
// But `.+c3` abbreviation will actually produce two elements:
// <div class=""> and <c3>. Thus, we have to walk on each element
// of parsed tree and use their definitions to update current element
var tag = xmlEditTree.parse(ctx.match.open.range.substring(content), {
offset: ctx.match.outerRange.start
});
tree.children.forEach(function(node, i) {
updateAttributes(tag, node, i);
});
// if tag name was resolved by implicit tag name resolver,
// then user omitted it in abbreviation and wants to keep
// original tag name
var el = tree.children[0];
if (!el.data('nameResolved')) {
tag.name(el.name());
}
return tag;
}
};
});
},{"../editTree/xml":38,"../parser/abbreviation":55,"../utils/action":70,"../utils/common":73,"../utils/editor":75}],22:[function(require,module,exports){
/**
* Action that wraps content with abbreviation. For convenience, action is
* defined as reusable module
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var range = require('../assets/range');
var htmlMatcher = require('../assets/htmlMatcher');
var utils = require('../utils/common');
var editorUtils = require('../utils/editor');
var actionUtils = require('../utils/action');
var parser = require('../parser/abbreviation');
return {
/**
* Wraps content with abbreviation
* @param {IEmmetEditor} Editor instance
* @param {String} abbr Abbreviation to wrap with
* @param {String} syntax Syntax type (html, css, etc.)
* @param {String} profile Output profile name (html, xml, xhtml)
*/
wrapWithAbbreviationAction: function(editor, abbr, syntax, profile) {
var info = editorUtils.outputInfo(editor, syntax, profile);
abbr = abbr || editor.prompt("Enter abbreviation");
if (!abbr) {
return null;
}
abbr = String(abbr);
var r = range(editor.getSelectionRange());
if (!r.length()) {
// no selection, find tag pair
var match = htmlMatcher.tag(info.content, r.start);
if (!match) { // nothing to wrap
return false;
}
r = utils.narrowToNonSpace(info.content, match.range);
}
var newContent = utils.escapeText(r.substring(info.content));
var result = parser.expand(abbr, {
pastedContent: editorUtils.unindent(editor, newContent),
syntax: info.syntax,
profile: info.profile,
contextNode: actionUtils.captureContext(editor)
});
if (result) {
editor.replaceContent(result, r.start, r.end);
return true;
}
return false;
}
};
});
},{"../assets/htmlMatcher":26,"../assets/range":30,"../parser/abbreviation":55,"../utils/action":70,"../utils/common":73,"../utils/editor":75}],23:[function(require,module,exports){
/**
* Parsed resources (snippets, abbreviations, variables, etc.) for Emmet.
* Contains convenient method to get access for snippets with respect of
* inheritance. Also provides ability to store data in different vocabularies
* ('system' and 'user') for fast and safe resource update
* @author Sergey Chikuyonok (serge.che@gmail.com)
* @link http://chikuyonok.ru
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var prefs = require('./preferences');
var utils = require('../utils/common');
prefs.define('caniuse.enabled', true, 'Enable support of Can I Use database. When enabled,\
CSS abbreviation resolver will look at Can I Use database first before detecting\
CSS properties that should be resolved');
prefs.define('caniuse.vendors', 'all', 'A comma-separated list vendor identifiers\
(as described in Can I Use database) that should be supported\
when resolving vendor-prefixed properties. Set value to <code>all</code>\
to support all available properties');
prefs.define('caniuse.era', 'e-2', 'Browser era, as defined in Can I Use database.\
Examples: <code>e0</code> (current version), <code>e1</code> (near future)\
<code>e-2</code> (2 versions back) and so on.');
var cssSections = {
'border-image': ['border-image'],
'css-boxshadow': ['box-shadow'],
'css3-boxsizing': ['box-sizing'],
'multicolumn': ['column-width', 'column-count', 'columns', 'column-gap', 'column-rule-color', 'column-rule-style', 'column-rule-width', 'column-rule', 'column-span', 'column-fill'],
'border-radius': ['border-radius', 'border-top-left-radius', 'border-top-right-radius', 'border-bottom-right-radius', 'border-bottom-left-radius'],
'transforms2d': ['transform'],
'css-hyphens': ['hyphens'],
'css-transitions': ['transition', 'transition-property', 'transition-duration', 'transition-timing-function', 'transition-delay'],
'font-feature': ['font-feature-settings'],
'css-animation': ['animation', 'animation-name', 'animation-duration', 'animation-timing-function', 'animation-iteration-count', 'animation-direction', 'animation-play-state', 'animation-delay', 'animation-fill-mode', '@keyframes'],
'css-gradients': ['linear-gradient'],
'css-masks': ['mask-image', 'mask-source-type', 'mask-repeat', 'mask-position', 'mask-clip', 'mask-origin', 'mask-size', 'mask', 'mask-type', 'mask-box-image-source', 'mask-box-image-slice', 'mask-box-image-width', 'mask-box-image-outset', 'mask-box-image-repeat', 'mask-box-image', 'clip-path', 'clip-rule'],
'css-featurequeries': ['@supports'],
'flexbox': ['flex', 'inline-flex', 'flex-direction', 'flex-wrap', 'flex-flow', 'order', 'flex'],
'calc': ['calc'],
'object-fit': ['object-fit', 'object-position'],
'css-grid': ['grid', 'inline-grid', 'grid-template-rows', 'grid-template-columns', 'grid-template-areas', 'grid-template', 'grid-auto-rows', 'grid-auto-columns', ' grid-auto-flow', 'grid-auto-position', 'grid', ' grid-row-start', 'grid-column-start', 'grid-row-end', 'grid-column-end', 'grid-column', 'grid-row', 'grid-area', 'justify-self', 'justify-items', 'align-self', 'align-items'],
'css-repeating-gradients': ['repeating-linear-gradient'],
'css-filters': ['filter'],
'user-select-none': ['user-select'],
'intrinsic-width': ['min-content', 'max-content', 'fit-content', 'fill-available'],
'css3-tabsize': ['tab-size']
};
/** @type {Object} The Can I Use database for CSS */
var cssDB = null;
/** @type {Object} A list of available vendors (browsers) and their prefixes */
var vendorsDB = null;
var erasDB = null;
function intersection(arr1, arr2) {
var result = [];
var smaller = arr1, larger = arr2;
if (smaller.length > larger.length) {
smaller = arr2;
larger = arr1;
}
larger.forEach(function(item) {
if (~smaller.indexOf(item)) {
result.push(item);
}
});
return result;
}
/**
* Parses raw Can I Use database for better lookups
* @param {String} data Raw database
* @param {Boolean} optimized Pass `true` if given `data` is already optimized
* @return {Object}
*/
function parseDB(data, optimized) {
if (typeof data == 'string') {
data = JSON.parse(data);
}
if (!optimized) {
data = optimize(data);
}
vendorsDB = data.vendors;
cssDB = data.css;
erasDB = data.era;
}
/**
* Extract required data only from CIU database
* @param {Object} data Raw Can I Use database
* @return {Object} Optimized database
*/
function optimize(data) {
if (typeof data == 'string') {
data = JSON.parse(data);
}
return {
vendors: parseVendors(data),
css: parseCSS(data),
era: parseEra(data)
};
}
/**
* Parses vendor data
* @param {Object} data
* @return {Object}
*/
function parseVendors(data) {
var out = {};
Object.keys(data.agents).forEach(function(name) {
var agent = data.agents[name];
out[name] = {
prefix: agent.prefix,
versions: agent.versions
};
});
return out;
}
/**
* Parses CSS data from Can I Use raw database
* @param {Object} data
* @return {Object}
*/
function parseCSS(data) {
var out = {};
var cssCategories = data.cats.CSS;
Object.keys(data.data).forEach(function(name) {
var section = data.data[name];
if (name in cssSections) {
cssSections[name].forEach(function(kw) {
out[kw] = section.stats;
});
}
});
return out;
}
/**
* Parses era data from Can I Use raw database
* @param {Object} data
* @return {Array}
*/
function parseEra(data) {
// some runtimes (like Mozilla Rhino) does not preserves
// key order so we have to sort values manually
return Object.keys(data.eras).sort(function(a, b) {
return parseInt(a.substr(1)) - parseInt(b.substr(1));
});
}
/**
* Returs list of supported vendors, depending on user preferences
* @return {Array}
*/
function getVendorsList() {
var allVendors = Object.keys(vendorsDB);
var vendors = prefs.getArray('caniuse.vendors');
if (!vendors || vendors[0] == 'all') {
return allVendors;
}
return intersection(allVendors, vendors);
}
/**
* Returns size of version slice as defined by era identifier
* @return {Number}
*/
function getVersionSlice() {
var era = prefs.get('caniuse.era');
var ix = erasDB.indexOf(era);
if (!~ix) {
ix = erasDB.indexOf('e-2');
}
return ix;
}
// try to load caniuse database
// hide it from Require.JS parser
var db = null;
(function(r) {
if (typeof define === 'undefined' || !define.amd) {
try {
var fs = r('fs');
var path = r('path');
db = fs.readFileSync(path.join(__dirname, '../caniuse.json'), {encoding: 'utf8'});
} catch(e) {}
}
})(require);
if (db) {
parseDB(db);
}
return {
load: parseDB,
optimize: optimize,
/**
* Resolves prefixes for given property
* @param {String} property A property to resolve. It can start with `@` symbol
* (CSS section, like `@keyframes`) or `:` (CSS value, like `flex`)
* @return {Array} Array of resolved prefixes or <code>null</code>
* if prefixes can't be resolved. Empty array means property has no vendor
* prefixes
*/
resolvePrefixes: function(property) {
if (!prefs.get('caniuse.enabled') || !cssDB || !(property in cssDB)) {
return null;
}
var prefixes = [];
var propStats = cssDB[property];
var versions = getVersionSlice();
getVendorsList().forEach(function(vendor) {
var vendorVesions = vendorsDB[vendor].versions.slice(versions);
for (var i = 0, v; i < vendorVesions.length; i++) {
v = vendorVesions[i];
if (!v) {
continue;
}
if (~propStats[vendor][v].indexOf('x')) {
prefixes.push(vendorsDB[vendor].prefix);
break;
}
}
});
return utils.unique(prefixes).sort(function(a, b) {
return b.length - a.length;
});
}
};
});
},{"../utils/common":73,"./preferences":28}],24:[function(require,module,exports){
/**
* Module that contains factories for element types used by Emmet
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var factories = {};
var reAttrs = /([@\!]?)([\w\-:]+)\s*=\s*(['"])(.*?)\3/g;
// register resource references
function commonFactory(value) {
return {data: value};
}
module = module || {};
module.exports = {
/**
* Create new element factory
* @param {String} name Element identifier
* @param {Function} factory Function that produces element of specified
* type. The object generated by this factory is automatically
* augmented with <code>type</code> property pointing to element
* <code>name</code>
* @memberOf elements
*/
add: function(name, factory) {
var that = this;
factories[name] = function() {
var elem = factory.apply(that, arguments);
if (elem)
elem.type = name;
return elem;
};
},
/**
* Returns factory for specified name
* @param {String} name
* @returns {Function}
*/
get: function(name) {
return factories[name];
},
/**
* Creates new element with specified type
* @param {String} name
* @returns {Object}
*/
create: function(name) {
var args = [].slice.call(arguments, 1);
var factory = this.get(name);
return factory ? factory.apply(this, args) : null;
},
/**
* Check if passed element is of specified type
* @param {Object} elem
* @param {String} type
* @returns {Boolean}
*/
is: function(elem, type) {
return this.type(elem) === type;
},
/**
* Returns type of element
* @param {Object} elem
* @return {String}
*/
type: function(elem) {
return elem && elem.type;
}
};
/**
* Element factory
* @param {String} elementName Name of output element
* @param {String} attrs Attributes definition. You may also pass
* <code>Array</code> where each contains object with <code>name</code>
* and <code>value</code> properties, or <code>Object</code>
* @param {Boolean} isEmpty Is expanded element should be empty
*/
module.exports.add('element', function(elementName, attrs, isEmpty) {
var ret = {
name: elementName,
is_empty: !!isEmpty
};
if (attrs) {
ret.attributes = [];
if (Array.isArray(attrs)) {
ret.attributes = attrs;
} else if (typeof attrs === 'string') {
var m;
while ((m = reAttrs.exec(attrs))) {
ret.attributes.push({
name: m[2],
value: m[4],
isDefault: m[1] == '@',
isImplied: m[1] == '!'
});
}
} else {
ret.attributes = Object.keys(attrs).map(function(name) {
return {
name: name,
value: attrs[name]
};
});
}
}
return ret;
});
module.exports.add('snippet', commonFactory);
module.exports.add('reference', commonFactory);
module.exports.add('empty', function() {
return {};
});
return module.exports;
});
},{}],25:[function(require,module,exports){
/**
* Utility module that provides ordered storage of function handlers.
* Many Emmet modules' functionality can be extended/overridden by custom
* function. This modules provides unified storage of handler functions, their
* management and execution
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
/**
* @type HandlerList
* @constructor
*/
function HandlerList() {
this._list = [];
}
HandlerList.prototype = {
/**
* Adds function handler
* @param {Function} fn Handler
* @param {Object} options Handler options. Possible values are:<br><br>
* <b>order</b> : (<code>Number</code>) order in handler list. Handlers
* with higher order value will be executed earlier.
*/
add: function(fn, options) {
// TODO hack for stable sort, remove after fixing `list()`
var order = this._list.length;
if (options && 'order' in options) {
order = options.order * 10000;
}
this._list.push(utils.extend({}, options, {order: order, fn: fn}));
},
/**
* Removes handler from list
* @param {Function} fn
*/
remove: function(fn) {
var item = utils.find(this._list, function(item) {
return item.fn === fn;
});
if (item) {
this._list.splice(this._list.indexOf(item), 1);
}
},
/**
* Returns ordered list of handlers. By default, handlers
* with the same <code>order</code> option returned in reverse order,
* i.e. the latter function was added into the handlers list, the higher
* it will be in the returned array
* @returns {Array}
*/
list: function() {
// TODO make stable sort
return this._list.sort(function(a, b) {
return b.order - a.order;
});
},
/**
* Returns ordered list of handler functions
* @returns {Array}
*/
listFn: function() {
return this.list().map(function(item) {
return item.fn;
});
},
/**
* Executes handler functions in their designated order. If function
* returns <code>skipVal</code>, meaning that function was unable to
* handle passed <code>args</code>, the next function will be executed
* and so on.
* @param {Object} skipValue If function returns this value, execute
* next handler.
* @param {Array} args Arguments to pass to handler function
* @returns {Boolean} Whether any of registered handlers performed
* successfully
*/
exec: function(skipValue, args) {
args = args || [];
var result = null;
utils.find(this.list(), function(h) {
result = h.fn.apply(h, args);
if (result !== skipValue) {
return true;
}
});
return result;
}
};
return {
/**
* Factory method that produces <code>HandlerList</code> instance
* @returns {HandlerList}
* @memberOf handlerList
*/
create: function() {
return new HandlerList();
}
};
});
},{"../utils/common":73}],26:[function(require,module,exports){
/**
* HTML matcher: takes string and searches for HTML tag pairs for given position
*
* Unlike “classic” matchers, it parses content from the specified
* position, not from the start, so it may work even outside HTML documents
* (for example, inside strings of programming languages like JavaScript, Python
* etc.)
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var range = require('./range');
// Regular Expressions for parsing tags and attributes
var reOpenTag = /^<([\w\:\-]+)((?:\s+[\w\-:]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/;
var reCloseTag = /^<\/([\w\:\-]+)[^>]*>/;
function openTag(i, match) {
return {
name: match[1],
selfClose: !!match[3],
/** @type Range */
range: range(i, match[0]),
type: 'open'
};
}
function closeTag(i, match) {
return {
name: match[1],
/** @type Range */
range: range(i, match[0]),
type: 'close'
};
}
function comment(i, match) {
return {
/** @type Range */
range: range(i, typeof match == 'number' ? match - i : match[0]),
type: 'comment'
};
}
/**
* Creates new tag matcher session
* @param {String} text
*/
function createMatcher(text) {
var memo = {}, m;
return {
/**
* Test if given position matches opening tag
* @param {Number} i
* @returns {Object} Matched tag object
*/
open: function(i) {
var m = this.matches(i);
return m && m.type == 'open' ? m : null;
},
/**
* Test if given position matches closing tag
* @param {Number} i
* @returns {Object} Matched tag object
*/
close: function(i) {
var m = this.matches(i);
return m && m.type == 'close' ? m : null;
},
/**
* Matches either opening or closing tag for given position
* @param i
* @returns
*/
matches: function(i) {
var key = 'p' + i;
if (!(key in memo)) {
memo[key] = false;
if (text.charAt(i) == '<') {
var substr = text.slice(i);
if ((m = substr.match(reOpenTag))) {
memo[key] = openTag(i, m);
} else if ((m = substr.match(reCloseTag))) {
memo[key] = closeTag(i, m);
}
}
}
return memo[key];
},
/**
* Returns original text
* @returns {String}
*/
text: function() {
return text;
},
clean: function() {
memo = text = m = null;
}
};
}
function matches(text, pos, pattern) {
return text.substring(pos, pos + pattern.length) == pattern;
}
/**
* Search for closing pair of opening tag
* @param {Object} open Open tag instance
* @param {Object} matcher Matcher instance
*/
function findClosingPair(open, matcher) {
var stack = [], tag = null;
var text = matcher.text();
for (var pos = open.range.end, len = text.length; pos < len; pos++) {
if (matches(text, pos, '<!--')) {
// skip to end of comment
for (var j = pos; j < len; j++) {
if (matches(text, j, '-->')) {
pos = j + 3;
break;
}
}
}
if ((tag = matcher.matches(pos))) {
if (tag.type == 'open' && !tag.selfClose) {
stack.push(tag.name);
} else if (tag.type == 'close') {
if (!stack.length) { // found valid pair?
return tag.name == open.name ? tag : null;
}
// check if current closing tag matches previously opened one
if (stack[stack.length - 1] == tag.name) {
stack.pop();
} else {
var found = false;
while (stack.length && !found) {
var last = stack.pop();
if (last == tag.name) {
found = true;
}
}
if (!stack.length && !found) {
return tag.name == open.name ? tag : null;
}
}
}
pos = tag.range.end - 1;
}
}
}
return {
/**
* Main function: search for tag pair in <code>text</code> for given
* position
* @memberOf htmlMatcher
* @param {String} text
* @param {Number} pos
* @returns {Object}
*/
find: function(text, pos) {
var matcher = createMatcher(text);
var open = null, close = null;
var j, jl;
for (var i = pos; i >= 0; i--) {
if ((open = matcher.open(i))) {
// found opening tag
if (open.selfClose) {
if (open.range.cmp(pos, 'lt', 'gt')) {
// inside self-closing tag, found match
break;
}
// outside self-closing tag, continue
continue;
}
close = findClosingPair(open, matcher);
if (close) {
// found closing tag.
var r = range.create2(open.range.start, close.range.end);
if (r.contains(pos)) {
break;
}
} else if (open.range.contains(pos)) {
// we inside empty HTML tag like <br>
break;
}
open = null;
} else if (matches(text, i, '-->')) {
// skip back to comment start
for (j = i - 1; j >= 0; j--) {
if (matches(text, j, '-->')) {
// found another comment end, do nothing
break;
} else if (matches(text, j, '<!--')) {
i = j;
break;
}
}
} else if (matches(text, i, '<!--')) {
// we're inside comment, match it
for (j = i + 4, jl = text.length; j < jl; j++) {
if (matches(text, j, '-->')) {
j += 3;
break;
}
}
open = comment(i, j);
break;
}
}
matcher.clean();
if (open) {
var outerRange = null;
var innerRange = null;
if (close) {
outerRange = range.create2(open.range.start, close.range.end);
innerRange = range.create2(open.range.end, close.range.start);
} else {
outerRange = innerRange = range.create2(open.range.start, open.range.end);
}
if (open.type == 'comment') {
// adjust positions of inner range for comment
var _c = outerRange.substring(text);
innerRange.start += _c.length - _c.replace(/^<\!--\s*/, '').length;
innerRange.end -= _c.length - _c.replace(/\s*-->$/, '').length;
}
return {
open: open,
close: close,
type: open.type == 'comment' ? 'comment' : 'tag',
innerRange: innerRange,
innerContent: function() {
return this.innerRange.substring(text);
},
outerRange: outerRange,
outerContent: function() {
return this.outerRange.substring(text);
},
range: !innerRange.length() || !innerRange.cmp(pos, 'lte', 'gte') ? outerRange : innerRange,
content: function() {
return this.range.substring(text);
},
source: text
};
}
},
/**
* The same as <code>find()</code> method, but restricts matched result
* to <code>tag</code> type
* @param {String} text
* @param {Number} pos
* @returns {Object}
*/
tag: function(text, pos) {
var result = this.find(text, pos);
if (result && result.type == 'tag') {
return result;
}
}
};
});
},{"./range":30}],27:[function(require,module,exports){
/**
* Simple logger for Emmet
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
return {
log: function() {
if (typeof console != 'undefined' && console.log) {
console.log.apply(console, arguments);
}
}
}
})
},{}],28:[function(require,module,exports){
/**
* Common module's preferences storage. This module
* provides general storage for all module preferences, their description and
* default values.<br><br>
*
* This module can also be used to list all available properties to create
* UI for updating properties
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var preferences = {};
var defaults = {};
var _dbgDefaults = null;
var _dbgPreferences = null;
function toBoolean(val) {
if (typeof val === 'string') {
val = val.toLowerCase();
return val == 'yes' || val == 'true' || val == '1';
}
return !!val;
}
function isValueObj(obj) {
return typeof obj === 'object'
&& !Array.isArray(obj)
&& 'value' in obj
&& Object.keys(obj).length < 3;
}
return {
/**
* Creates new preference item with default value
* @param {String} name Preference name. You can also pass object
* with many options
* @param {Object} value Preference default value
* @param {String} description Item textual description
* @memberOf preferences
*/
define: function(name, value, description) {
var prefs = name;
if (typeof name === 'string') {
prefs = {};
prefs[name] = {
value: value,
description: description
};
}
Object.keys(prefs).forEach(function(k) {
var v = prefs[k];
defaults[k] = isValueObj(v) ? v : {value: v};
});
},
/**
* Updates preference item value. Preference value should be defined
* first with <code>define</code> method.
* @param {String} name Preference name. You can also pass object
* with many options
* @param {Object} value Preference default value
* @memberOf preferences
*/
set: function(name, value) {
var prefs = name;
if (typeof name === 'string') {
prefs = {};
prefs[name] = value;
}
Object.keys(prefs).forEach(function(k) {
var v = prefs[k];
if (!(k in defaults)) {
throw new Error('Property "' + k + '" is not defined. You should define it first with `define` method of current module');
}
// do not set value if it equals to default value
if (v !== defaults[k].value) {
// make sure we have value of correct type
switch (typeof defaults[k].value) {
case 'boolean':
v = toBoolean(v);
break;
case 'number':
v = parseInt(v + '', 10) || 0;
break;
default: // convert to string
if (v !== null) {
v += '';
}
}
preferences[k] = v;
} else if (k in preferences) {
delete preferences[k];
}
});
},
/**
* Returns preference value
* @param {String} name
* @returns {String} Returns <code>undefined</code> if preference is
* not defined
*/
get: function(name) {
if (name in preferences) {
return preferences[name];
}
if (name in defaults) {
return defaults[name].value;
}
return void 0;
},
/**
* Returns comma-separated preference value as array of values
* @param {String} name
* @returns {Array} Returns <code>undefined</code> if preference is
* not defined, <code>null</code> if string cannot be converted to array
*/
getArray: function(name) {
var val = this.get(name);
if (typeof val === 'undefined' || val === null || val === '') {
return null;
}
val = val.split(',').map(utils.trim);
if (!val.length) {
return null;
}
return val;
},
/**
* Returns comma and colon-separated preference value as dictionary
* @param {String} name
* @returns {Object}
*/
getDict: function(name) {
var result = {};
this.getArray(name).forEach(function(val) {
var parts = val.split(':');
result[parts[0]] = parts[1];
});
return result;
},
/**
* Returns description of preference item
* @param {String} name Preference name
* @returns {Object}
*/
description: function(name) {
return name in defaults ? defaults[name].description : void 0;
},
/**
* Completely removes specified preference(s)
* @param {String} name Preference name (or array of names)
*/
remove: function(name) {
if (!Array.isArray(name)) {
name = [name];
}
name.forEach(function(key) {
if (key in preferences) {
delete preferences[key];
}
if (key in defaults) {
delete defaults[key];
}
});
},
/**
* Returns sorted list of all available properties
* @returns {Array}
*/
list: function() {
return Object.keys(defaults).sort().map(function(key) {
return {
name: key,
value: this.get(key),
type: typeof defaults[key].value,
description: defaults[key].description
};
}, this);
},
/**
* Loads user-defined preferences from JSON
* @param {Object} json
* @returns
*/
load: function(json) {
Object.keys(json).forEach(function(key) {
this.set(key, json[key]);
}, this);
},
/**
* Returns hash of user-modified preferences
* @returns {Object}
*/
exportModified: function() {
return utils.extend({}, preferences);
},
/**
* Reset to defaults
* @returns
*/
reset: function() {
preferences = {};
},
/**
* For unit testing: use empty storage
*/
_startTest: function() {
_dbgDefaults = defaults;
_dbgPreferences = preferences;
defaults = {};
preferences = {};
},
/**
* For unit testing: restore original storage
*/
_stopTest: function() {
defaults = _dbgDefaults;
preferences = _dbgPreferences;
}
};
});
},{"../utils/common":73}],29:[function(require,module,exports){
/**
* Output profile module.
* Profile defines how XHTML output data should look like
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var resources = require('./resources');
var prefs = require('./preferences');
prefs.define('profile.allowCompactBoolean', true,
'This option can be used to globally disable compact form of boolean ' +
'attribues (attributes where name and value are equal). With compact' +
'form enabled, HTML tags can be outputted as <code>&lt;div contenteditable&gt;</code> ' +
'instead of <code>&lt;div contenteditable="contenteditable"&gt;</code>');
prefs.define('profile.booleanAttributes', '^contenteditable|seamless$',
'A regular expression for attributes that should be boolean by default.' +
'If attribute name matches this expression, you dont have to write dot ' +
'after attribute name in Emmet abbreviation to mark it as boolean.');
var profiles = {};
var defaultProfile = {
tag_case: 'asis',
attr_case: 'asis',
attr_quotes: 'double',
// Each tag on new line
tag_nl: 'decide',
// With tag_nl === true, defines if leaf node (e.g. node with no children)
// should have formatted line breaks
tag_nl_leaf: false,
place_cursor: true,
// Indent tags
indent: true,
// How many inline elements should be to force line break
// (set to 0 to disable)
inline_break: 3,
// Produce compact notation of boolean attribues:
// attributes where name and value are equal.
// With this option enabled, HTML filter will
// produce <div contenteditable> instead of <div contenteditable="contenteditable">
compact_bool: false,
// Use self-closing style for writing empty elements, e.g. <br /> or <br>
self_closing_tag: 'xhtml',
// Profile-level output filters, re-defines syntax filters
filters: '',
// Additional filters applied to abbreviation.
// Unlike "filters", this preference doesn't override default filters
// but add the instead every time given profile is chosen
extraFilters: ''
};
/**
* @constructor
* @type OutputProfile
* @param {Object} options
*/
function OutputProfile(options) {
utils.extend(this, defaultProfile, options);
}
OutputProfile.prototype = {
/**
* Transforms tag name case depending on current profile settings
* @param {String} name String to transform
* @returns {String}
*/
tagName: function(name) {
return stringCase(name, this.tag_case);
},
/**
* Transforms attribute name case depending on current profile settings
* @param {String} name String to transform
* @returns {String}
*/
attributeName: function(name) {
return stringCase(name, this.attr_case);
},
/**
* Returns quote character for current profile
* @returns {String}
*/
attributeQuote: function() {
return this.attr_quotes == 'single' ? "'" : '"';
},
/**
* Returns self-closing tag symbol for current profile
* @returns {String}
*/
selfClosing: function() {
if (this.self_closing_tag == 'xhtml')
return ' /';
if (this.self_closing_tag === true)
return '/';
return '';
},
/**
* Returns cursor token based on current profile settings
* @returns {String}
*/
cursor: function() {
return this.place_cursor ? utils.getCaretPlaceholder() : '';
},
/**
* Check if attribute with given name is boolean,
* e.g. written as `contenteditable` instead of
* `contenteditable="contenteditable"`
* @param {String} name Attribute name
* @return {Boolean}
*/
isBoolean: function(name, value) {
if (name == value) {
return true;
}
var boolAttrs = prefs.get('profile.booleanAttributes');
if (!value && boolAttrs) {
boolAttrs = new RegExp(boolAttrs, 'i');
return boolAttrs.test(name);
}
return false;
},
/**
* Check if compact boolean attribute record is
* allowed for current profile
* @return {Boolean}
*/
allowCompactBoolean: function() {
return this.compact_bool && prefs.get('profile.allowCompactBoolean');
}
};
/**
* Helper function that converts string case depending on
* <code>caseValue</code>
* @param {String} str String to transform
* @param {String} caseValue Case value: can be <i>lower</i>,
* <i>upper</i> and <i>leave</i>
* @returns {String}
*/
function stringCase(str, caseValue) {
switch (String(caseValue || '').toLowerCase()) {
case 'lower':
return str.toLowerCase();
case 'upper':
return str.toUpperCase();
}
return str;
}
/**
* Creates new output profile
* @param {String} name Profile name
* @param {Object} options Profile options
*/
function createProfile(name, options) {
return profiles[name.toLowerCase()] = new OutputProfile(options);
}
function createDefaultProfiles() {
createProfile('xhtml');
createProfile('html', {self_closing_tag: false, compact_bool: true});
createProfile('xml', {self_closing_tag: true, tag_nl: true});
createProfile('plain', {tag_nl: false, indent: false, place_cursor: false});
createProfile('line', {tag_nl: false, indent: false, extraFilters: 's'});
createProfile('css', {tag_nl: true});
createProfile('css_line', {tag_nl: false});
}
createDefaultProfiles();
return {
/**
* Creates new output profile and adds it into internal dictionary
* @param {String} name Profile name
* @param {Object} options Profile options
* @memberOf emmet.profile
* @returns {Object} New profile
*/
create: function(name, options) {
if (arguments.length == 2)
return createProfile(name, options);
else
// create profile object only
return new OutputProfile(utils.defaults(name || {}, defaultProfile));
},
/**
* Returns profile by its name. If profile wasn't found, returns
* 'plain' profile
* @param {String} name Profile name. Might be profile itself
* @param {String} syntax. Optional. Current editor syntax. If defined,
* profile is searched in resources first, then in predefined profiles
* @returns {Object}
*/
get: function(name, syntax) {
if (!name && syntax) {
// search in user resources first
var profile = resources.findItem(syntax, 'profile');
if (profile) {
name = profile;
}
}
if (!name) {
return profiles.plain;
}
if (name instanceof OutputProfile) {
return name;
}
if (typeof name === 'string' && name.toLowerCase() in profiles) {
return profiles[name.toLowerCase()];
}
return this.create(name);
},
/**
* Deletes profile with specified name
* @param {String} name Profile name
*/
remove: function(name) {
name = (name || '').toLowerCase();
if (name in profiles)
delete profiles[name];
},
/**
* Resets all user-defined profiles
*/
reset: function() {
profiles = {};
createDefaultProfiles();
},
/**
* Helper function that converts string case depending on
* <code>caseValue</code>
* @param {String} str String to transform
* @param {String} caseValue Case value: can be <i>lower</i>,
* <i>upper</i> and <i>leave</i>
* @returns {String}
*/
stringCase: stringCase
};
});
},{"../utils/common":73,"./preferences":28,"./resources":31}],30:[function(require,module,exports){
/**
* Helper module to work with ranges
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
function cmp(a, b, op) {
switch (op) {
case 'eq':
case '==':
return a === b;
case 'lt':
case '<':
return a < b;
case 'lte':
case '<=':
return a <= b;
case 'gt':
case '>':
return a > b;
case 'gte':
case '>=':
return a >= b;
}
}
/**
* @type Range
* @constructor
* @param {Object} start
* @param {Number} len
*/
function Range(start, len) {
if (typeof start === 'object' && 'start' in start) {
// create range from object stub
this.start = Math.min(start.start, start.end);
this.end = Math.max(start.start, start.end);
} else if (Array.isArray(start)) {
this.start = start[0];
this.end = start[1];
} else {
len = typeof len === 'string' ? len.length : +len;
this.start = start;
this.end = start + len;
}
}
Range.prototype = {
length: function() {
return Math.abs(this.end - this.start);
},
/**
* Returns <code>true</code> if passed range is equals to current one
* @param {Range} range
* @returns {Boolean}
*/
equal: function(range) {
return this.cmp(range, 'eq', 'eq');
// return this.start === range.start && this.end === range.end;
},
/**
* Shifts indexes position with passed <code>delta</code>
* @param {Number} delta
* @returns {Range} range itself
*/
shift: function(delta) {
this.start += delta;
this.end += delta;
return this;
},
/**
* Check if two ranges are overlapped
* @param {Range} range
* @returns {Boolean}
*/
overlap: function(range) {
return range.start <= this.end && range.end >= this.start;
},
/**
* Finds intersection of two ranges
* @param {Range} range
* @returns {Range} <code>null</code> if ranges does not overlap
*/
intersection: function(range) {
if (this.overlap(range)) {
var start = Math.max(range.start, this.start);
var end = Math.min(range.end, this.end);
return new Range(start, end - start);
}
return null;
},
/**
* Returns the union of the thow ranges.
* @param {Range} range
* @returns {Range} <code>null</code> if ranges are not overlapped
*/
union: function(range) {
if (this.overlap(range)) {
var start = Math.min(range.start, this.start);
var end = Math.max(range.end, this.end);
return new Range(start, end - start);
}
return null;
},
/**
* Returns a Boolean value that indicates whether a specified position
* is in a given range.
* @param {Number} loc
*/
inside: function(loc) {
return this.cmp(loc, 'lte', 'gt');
// return this.start <= loc && this.end > loc;
},
/**
* Returns a Boolean value that indicates whether a specified position
* is in a given range, but not equals bounds.
* @param {Number} loc
*/
contains: function(loc) {
return this.cmp(loc, 'lt', 'gt');
},
/**
* Check if current range completely includes specified one
* @param {Range} r
* @returns {Boolean}
*/
include: function(r) {
return this.cmp(r, 'lte', 'gte');
// return this.start <= r.start && this.end >= r.end;
},
/**
* Low-level comparision method
* @param {Number} loc
* @param {String} left Left comparison operator
* @param {String} right Right comaprison operator
*/
cmp: function(loc, left, right) {
var a, b;
if (loc instanceof Range) {
a = loc.start;
b = loc.end;
} else {
a = b = loc;
}
return cmp(this.start, a, left || '<=') && cmp(this.end, b, right || '>');
},
/**
* Returns substring of specified <code>str</code> for current range
* @param {String} str
* @returns {String}
*/
substring: function(str) {
return this.length() > 0
? str.substring(this.start, this.end)
: '';
},
/**
* Creates copy of current range
* @returns {Range}
*/
clone: function() {
return new Range(this.start, this.length());
},
/**
* @returns {Array}
*/
toArray: function() {
return [this.start, this.end];
},
toString: function() {
return this.valueOf();
},
valueOf: function() {
return '{' + this.start + ', ' + this.length() + '}';
}
};
/**
* Creates new range object instance
* @param {Object} start Range start or array with 'start' and 'end'
* as two first indexes or object with 'start' and 'end' properties
* @param {Number} len Range length or string to produce range from
* @returns {Range}
*/
module.exports = function(start, len) {
if (typeof start == 'undefined' || start === null)
return null;
if (start instanceof Range)
return start;
if (typeof start == 'object' && 'start' in start && 'end' in start) {
len = start.end - start.start;
start = start.start;
}
return new Range(start, len);
};
module.exports.create = module.exports;
module.exports.isRange = function(val) {
return val instanceof Range;
};
/**
* <code>Range</code> object factory, the same as <code>this.create()</code>
* but last argument represents end of range, not length
* @returns {Range}
*/
module.exports.create2 = function(start, end) {
if (typeof start === 'number' && typeof end === 'number') {
end -= start;
}
return this.create(start, end);
};
/**
* Helper function that sorts ranges in order as they
* appear in text
* @param {Array} ranges
* @return {Array}
*/
module.exports.sort = function(ranges, reverse) {
ranges = ranges.sort(function(a, b) {
if (a.start === b.start) {
return b.end - a.end;
}
return a.start - b.start;
});
reverse && ranges.reverse();
return ranges;
};
return module.exports;
});
},{}],31:[function(require,module,exports){
/**
* Parsed resources (snippets, abbreviations, variables, etc.) for Emmet.
* Contains convenient method to get access for snippets with respect of
* inheritance. Also provides ability to store data in different vocabularies
* ('system' and 'user') for fast and safe resource update
* @author Sergey Chikuyonok (serge.che@gmail.com)
* @link http://chikuyonok.ru
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var handlerList = require('./handlerList');
var utils = require('../utils/common');
var elements = require('./elements');
var logger = require('../assets/logger');
var stringScore = require('../vendor/stringScore');
var cssResolver = require('../resolver/css');
var VOC_SYSTEM = 'system';
var VOC_USER = 'user';
var cache = {};
/** Regular expression for XML tag matching */
var reTag = /^<(\w+\:?[\w\-]*)((?:\s+[@\!]?[\w\:\-]+\s*=\s*(['"]).*?\3)*)\s*(\/?)>/;
var systemSettings = {};
var userSettings = {};
/** @type HandlerList List of registered abbreviation resolvers */
var resolvers = handlerList.create();
function each(obj, fn) {
if (!obj) {
return;
}
Object.keys(obj).forEach(function(key) {
fn(obj[key], key);
});
}
/**
* Normalizes caret plceholder in passed text: replaces | character with
* default caret placeholder
* @param {String} text
* @returns {String}
*/
function normalizeCaretPlaceholder(text) {
return utils.replaceUnescapedSymbol(text, '|', utils.getCaretPlaceholder());
}
function parseItem(name, value, type) {
value = normalizeCaretPlaceholder(value);
if (type == 'snippets') {
return elements.create('snippet', value);
}
if (type == 'abbreviations') {
return parseAbbreviation(name, value);
}
}
/**
* Parses single abbreviation
* @param {String} key Abbreviation name
* @param {String} value Abbreviation value
* @return {Object}
*/
function parseAbbreviation(key, value) {
key = utils.trim(key);
var m;
if ((m = reTag.exec(value))) {
return elements.create('element', m[1], m[2], m[4] == '/');
} else {
// assume it's reference to another abbreviation
return elements.create('reference', value);
}
}
/**
* Normalizes snippet key name for better fuzzy search
* @param {String} str
* @returns {String}
*/
function normalizeName(str) {
return str.replace(/:$/, '').replace(/:/g, '-');
}
function expandSnippetsDefinition(snippets) {
var out = {};
each(snippets, function(val, key) {
var items = key.split('|');
// do not use iterators for better performance
for (var i = items.length - 1; i >= 0; i--) {
out[items[i]] = val;
}
});
return out;
}
utils.extend(exports, {
/**
* Sets new unparsed data for specified settings vocabulary
* @param {Object} data
* @param {String} type Vocabulary type ('system' or 'user')
* @memberOf resources
*/
setVocabulary: function(data, type) {
cache = {};
// sections like "snippets" and "abbreviations" could have
// definitions like `"f|fs": "fieldset"` which is the same as distinct
// "f" and "fs" keys both equals to "fieldset".
// We should parse these definitions first
var voc = {};
each(data, function(section, syntax) {
var _section = {};
each(section, function(subsection, name) {
if (name == 'abbreviations' || name == 'snippets') {
subsection = expandSnippetsDefinition(subsection);
}
_section[name] = subsection;
});
voc[syntax] = _section;
});
if (type == VOC_SYSTEM) {
systemSettings = voc;
} else {
userSettings = voc;
}
},
/**
* Returns resource vocabulary by its name
* @param {String} name Vocabulary name ('system' or 'user')
* @return {Object}
*/
getVocabulary: function(name) {
return name == VOC_SYSTEM ? systemSettings : userSettings;
},
/**
* Returns resource (abbreviation, snippet, etc.) matched for passed
* abbreviation
* @param {AbbreviationNode} node
* @param {String} syntax
* @returns {Object}
*/
getMatchedResource: function(node, syntax) {
return resolvers.exec(null, utils.toArray(arguments))
|| this.findSnippet(syntax, node.name());
},
/**
* Returns variable value
* @return {String}
*/
getVariable: function(name) {
return (this.getSection('variables') || {})[name];
},
/**
* Store runtime variable in user storage
* @param {String} name Variable name
* @param {String} value Variable value
*/
setVariable: function(name, value){
var voc = this.getVocabulary('user') || {};
if (!('variables' in voc))
voc.variables = {};
voc.variables[name] = value;
this.setVocabulary(voc, 'user');
},
/**
* Check if there are resources for specified syntax
* @param {String} syntax
* @return {Boolean}
*/
hasSyntax: function(syntax) {
return syntax in this.getVocabulary(VOC_USER)
|| syntax in this.getVocabulary(VOC_SYSTEM);
},
/**
* Registers new abbreviation resolver.
* @param {Function} fn Abbreviation resolver which will receive
* abbreviation as first argument and should return parsed abbreviation
* object if abbreviation has handled successfully, <code>null</code>
* otherwise
* @param {Object} options Options list as described in
* {@link HandlerList#add()} method
*/
addResolver: function(fn, options) {
resolvers.add(fn, options);
},
removeResolver: function(fn) {
resolvers.remove(fn);
},
/**
* Returns actual section data, merged from both
* system and user data
* @param {String} name Section name (syntax)
* @param {String} ...args Subsections
* @returns
*/
getSection: function(name) {
if (!name)
return null;
if (!(name in cache)) {
cache[name] = utils.deepMerge({}, systemSettings[name], userSettings[name]);
}
var data = cache[name], subsections = utils.toArray(arguments, 1), key;
while (data && (key = subsections.shift())) {
if (key in data) {
data = data[key];
} else {
return null;
}
}
return data;
},
/**
* Recursively searches for a item inside top level sections (syntaxes)
* with respect of `extends` attribute
* @param {String} topSection Top section name (syntax)
* @param {String} subsection Inner section name
* @returns {Object}
*/
findItem: function(topSection, subsection) {
var data = this.getSection(topSection);
while (data) {
if (subsection in data)
return data[subsection];
data = this.getSection(data['extends']);
}
},
/**
* Recursively searches for a snippet definition inside syntax section.
* Definition is searched inside `snippets` and `abbreviations`
* subsections
* @param {String} syntax Top-level section name (syntax)
* @param {String} name Snippet name
* @returns {Object}
*/
findSnippet: function(syntax, name, memo) {
if (!syntax || !name)
return null;
memo = memo || [];
var names = [name];
// create automatic aliases to properties with colons,
// e.g. pos-a == pos:a
if (~name.indexOf('-')) {
names.push(name.replace(/\-/g, ':'));
}
var data = this.getSection(syntax), matchedItem = null;
['snippets', 'abbreviations'].some(function(sectionName) {
var data = this.getSection(syntax, sectionName);
if (data) {
return names.some(function(n) {
if (data[n]) {
return matchedItem = parseItem(n, data[n], sectionName);
}
});
}
}, this);
memo.push(syntax);
if (!matchedItem && data['extends'] && !~memo.indexOf(data['extends'])) {
// try to find item in parent syntax section
return this.findSnippet(data['extends'], name, memo);
}
return matchedItem;
},
/**
* Performs fuzzy search of snippet definition
* @param {String} syntax Top-level section name (syntax)
* @param {String} name Snippet name
* @returns
*/
fuzzyFindSnippet: function(syntax, name, minScore) {
var result = this.fuzzyFindMatches(syntax, name, minScore)[0];
if (result) {
return result.value.parsedValue;
}
},
fuzzyFindMatches: function(syntax, name, minScore) {
minScore = minScore || 0.3;
name = normalizeName(name);
var snippets = this.getAllSnippets(syntax);
return Object.keys(snippets)
.map(function(key) {
var value = snippets[key];
return {
key: key,
score: stringScore.score(value.nk, name, 0.1),
value: value
};
})
.filter(function(item) {
return item.score >= minScore;
})
.sort(function(a, b) {
return a.score - b.score;
})
.reverse();
},
/**
* Returns plain dictionary of all available abbreviations and snippets
* for specified syntax with respect of inheritance
* @param {String} syntax
* @returns {Object}
*/
getAllSnippets: function(syntax) {
var cacheKey = 'all-' + syntax;
if (!cache[cacheKey]) {
var stack = [], sectionKey = syntax;
var memo = [];
do {
var section = this.getSection(sectionKey);
if (!section)
break;
['snippets', 'abbreviations'].forEach(function(sectionName) {
var stackItem = {};
each(section[sectionName] || null, function(v, k) {
stackItem[k] = {
nk: normalizeName(k),
value: v,
parsedValue: parseItem(k, v, sectionName),
type: sectionName
};
});
stack.push(stackItem);
});
memo.push(sectionKey);
sectionKey = section['extends'];
} while (sectionKey && !~memo.indexOf(sectionKey));
cache[cacheKey] = utils.extend.apply(utils, stack.reverse());
}
return cache[cacheKey];
},
/**
* Returns newline character
* @returns {String}
*/
getNewline: function() {
var nl = this.getVariable('newline');
return typeof nl === 'string' ? nl : '\n';
},
/**
* Sets new newline character that will be used in output
* @param {String} str
*/
setNewline: function(str) {
this.setVariable('newline', str);
this.setVariable('nl', str);
}
});
// XXX add default resolvers
exports.addResolver(cssResolver.resolve.bind(cssResolver));
// try to load snippets
// hide it from Require.JS parser
(function(r) {
if (typeof define === 'undefined' || !define.amd) {
try {
var fs = r('fs');
var path = r('path');
var defaultSnippets = fs.readFileSync(path.join(__dirname, '../snippets.json'), {encoding: 'utf8'});
exports.setVocabulary(JSON.parse(defaultSnippets), VOC_SYSTEM);
} catch (e) {}
}
})(require);
return exports;
});
},{"../assets/logger":27,"../resolver/css":64,"../utils/common":73,"../vendor/stringScore":79,"./elements":24,"./handlerList":25}],32:[function(require,module,exports){
/**
* A trimmed version of CodeMirror's StringStream module for string parsing
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
/**
* @type StringStream
* @constructor
* @param {String} string Assuming that bound string should be
* immutable
*/
function StringStream(string) {
this.pos = this.start = 0;
this.string = string;
this._length = string.length;
}
StringStream.prototype = {
/**
* Returns true only if the stream is at the end of the line.
* @returns {Boolean}
*/
eol: function() {
return this.pos >= this._length;
},
/**
* Returns true only if the stream is at the start of the line
* @returns {Boolean}
*/
sol: function() {
return this.pos === 0;
},
/**
* Returns the next character in the stream without advancing it.
* Will return <code>undefined</code> at the end of the line.
* @returns {String}
*/
peek: function() {
return this.string.charAt(this.pos);
},
/**
* Returns the next character in the stream and advances it.
* Also returns <code>undefined</code> when no more characters are available.
* @returns {String}
*/
next: function() {
if (this.pos < this._length)
return this.string.charAt(this.pos++);
},
/**
* match can be a character, a regular expression, or a function that
* takes a character and returns a boolean. If the next character in the
* stream 'matches' the given argument, it is consumed and returned.
* Otherwise, undefined is returned.
* @param {Object} match
* @returns {String}
*/
eat: function(match) {
var ch = this.string.charAt(this.pos), ok;
if (typeof match == "string")
ok = ch == match;
else
ok = ch && (match.test ? match.test(ch) : match(ch));
if (ok) {
++this.pos;
return ch;
}
},
/**
* Repeatedly calls <code>eat</code> with the given argument, until it
* fails. Returns <code>true</code> if any characters were eaten.
* @param {Object} match
* @returns {Boolean}
*/
eatWhile: function(match) {
var start = this.pos;
while (this.eat(match)) {}
return this.pos > start;
},
/**
* Shortcut for <code>eatWhile</code> when matching white-space.
* @returns {Boolean}
*/
eatSpace: function() {
var start = this.pos;
while (/[\s\u00a0]/.test(this.string.charAt(this.pos)))
++this.pos;
return this.pos > start;
},
/**
* Moves the position to the end of the line.
*/
skipToEnd: function() {
this.pos = this._length;
},
/**
* Skips to the next occurrence of the given character, if found on the
* current line (doesn't advance the stream if the character does not
* occur on the line). Returns true if the character was found.
* @param {String} ch
* @returns {Boolean}
*/
skipTo: function(ch) {
var found = this.string.indexOf(ch, this.pos);
if (found > -1) {
this.pos = found;
return true;
}
},
/**
* Skips to <code>close</code> character which is pair to <code>open</code>
* character, considering possible pair nesting. This function is used
* to consume pair of characters, like opening and closing braces
* @param {String} open
* @param {String} close
* @returns {Boolean} Returns <code>true</code> if pair was successfully
* consumed
*/
skipToPair: function(open, close, skipString) {
var braceCount = 0, ch;
var pos = this.pos, len = this._length;
while (pos < len) {
ch = this.string.charAt(pos++);
if (ch == open) {
braceCount++;
} else if (ch == close) {
braceCount--;
if (braceCount < 1) {
this.pos = pos;
return true;
}
} else if (skipString && (ch == '"' || ch == "'")) {
this.skipString(ch);
}
}
return false;
},
/**
* A helper function which, in case of either single or
* double quote was found in current position, skips entire
* string (quoted value)
* @return {Boolean} Wether quoted string was skipped
*/
skipQuoted: function(noBackup) {
var ch = this.string.charAt(noBackup ? this.pos : this.pos - 1);
if (ch === '"' || ch === "'") {
if (noBackup) {
this.pos++;
}
return this.skipString(ch);
}
},
/**
* A custom function to skip string literal, e.g. a "double-quoted"
* or 'single-quoted' value
* @param {String} quote An opening quote
* @return {Boolean}
*/
skipString: function(quote) {
var pos = this.pos, len = this._length, ch;
while (pos < len) {
ch = this.string.charAt(pos++);
if (ch == '\\') {
continue;
} else if (ch == quote) {
this.pos = pos;
return true;
}
}
return false;
},
/**
* Backs up the stream n characters. Backing it up further than the
* start of the current token will cause things to break, so be careful.
* @param {Number} n
*/
backUp : function(n) {
this.pos -= n;
},
/**
* Act like a multi-character <code>eat</code>—if <code>consume</code> is true or
* not given—or a look-ahead that doesn't update the stream position—if
* it is false. <code>pattern</code> can be either a string or a
* regular expression starting with ^. When it is a string,
* <code>caseInsensitive</code> can be set to true to make the match
* case-insensitive. When successfully matching a regular expression,
* the returned value will be the array returned by <code>match</code>,
* in case you need to extract matched groups.
*
* @param {RegExp} pattern
* @param {Boolean} consume
* @param {Boolean} caseInsensitive
* @returns
*/
match: function(pattern, consume, caseInsensitive) {
if (typeof pattern == "string") {
var cased = caseInsensitive
? function(str) {return str.toLowerCase();}
: function(str) {return str;};
if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
if (consume !== false)
this.pos += pattern.length;
return true;
}
} else {
var match = this.string.slice(this.pos).match(pattern);
if (match && consume !== false)
this.pos += match[0].length;
return match;
}
},
/**
* Get the string between the start of the current token and the
* current stream position.
* @returns {String}
*/
current: function(backUp) {
return this.string.slice(this.start, this.pos - (backUp ? 1 : 0));
}
};
module.exports = function(string) {
return new StringStream(string);
};
/** @deprecated */
module.exports.create = module.exports;
return module.exports;
});
},{}],33:[function(require,module,exports){
/**
* Utility module for handling tabstops tokens generated by Emmet's
* "Expand Abbreviation" action. The main <code>extract</code> method will take
* raw text (for example: <i>${0} some ${1:text}</i>), find all tabstops
* occurrences, replace them with tokens suitable for your editor of choice and
* return object with processed text and list of found tabstops and their ranges.
* For sake of portability (Objective-C/Java) the tabstops list is a plain
* sorted array with plain objects.
*
* Placeholders with the same are meant to be <i>linked</i> in your editor.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var stringStream = require('./stringStream');
var resources = require('./resources');
/**
* Global placeholder value, automatically incremented by
* <code>variablesResolver()</code> function
*/
var startPlaceholderNum = 100;
var tabstopIndex = 0;
var defaultOptions = {
replaceCarets: false,
escape: function(ch) {
return '\\' + ch;
},
tabstop: function(data) {
return data.token;
},
variable: function(data) {
return data.token;
}
};
return {
/**
* Main function that looks for a tabstops in provided <code>text</code>
* and returns a processed version of <code>text</code> with expanded
* placeholders and list of tabstops found.
* @param {String} text Text to process
* @param {Object} options List of processor options:<br>
*
* <b>replaceCarets</b> : <code>Boolean</code> — replace all default
* caret placeholders (like <i>{%::emmet-caret::%}</i>) with <i>${0:caret}</i><br>
*
* <b>escape</b> : <code>Function</code> — function that handle escaped
* characters (mostly '$'). By default, it returns the character itself
* to be displayed as is in output, but sometimes you will use
* <code>extract</code> method as intermediate solution for further
* processing and want to keep character escaped. Thus, you should override
* <code>escape</code> method to return escaped symbol (e.g. '\\$')<br>
*
* <b>tabstop</b> : <code>Function</code> a tabstop handler. Receives
* a single argument an object describing token: its position, number
* group, placeholder and token itself. Should return a replacement
* string that will appear in final output
*
* <b>variable</b> : <code>Function</code> variable handler. Receives
* a single argument an object describing token: its position, name
* and original token itself. Should return a replacement
* string that will appear in final output
*
* @returns {Object} Object with processed <code>text</code> property
* and array of <code>tabstops</code> found
* @memberOf tabStops
*/
extract: function(text, options) {
// prepare defaults
var placeholders = {carets: ''};
var marks = [];
options = utils.extend({}, defaultOptions, options, {
tabstop: function(data) {
var token = data.token;
var ret = '';
if (data.placeholder == 'cursor') {
marks.push({
start: data.start,
end: data.start + token.length,
group: 'carets',
value: ''
});
} else {
// unify placeholder value for single group
if ('placeholder' in data)
placeholders[data.group] = data.placeholder;
if (data.group in placeholders)
ret = placeholders[data.group];
marks.push({
start: data.start,
end: data.start + token.length,
group: data.group,
value: ret
});
}
return token;
}
});
if (options.replaceCarets) {
text = text.replace(new RegExp( utils.escapeForRegexp( utils.getCaretPlaceholder() ), 'g'), '${0:cursor}');
}
// locate tabstops and unify group's placeholders
text = this.processText(text, options);
// now, replace all tabstops with placeholders
var buf = '', lastIx = 0;
var tabStops = marks.map(function(mark) {
buf += text.substring(lastIx, mark.start);
var pos = buf.length;
var ph = placeholders[mark.group] || '';
buf += ph;
lastIx = mark.end;
return {
group: mark.group,
start: pos,
end: pos + ph.length
};
});
buf += text.substring(lastIx);
return {
text: buf,
tabstops: tabStops.sort(function(a, b) {
return a.start - b.start;
})
};
},
/**
* Text processing routine. Locates escaped characters and tabstops and
* replaces them with values returned by handlers defined in
* <code>options</code>
* @param {String} text
* @param {Object} options See <code>extract</code> method options
* description
* @returns {String}
*/
processText: function(text, options) {
options = utils.extend({}, defaultOptions, options);
var buf = '';
/** @type StringStream */
var stream = stringStream.create(text);
var ch, m, a;
while ((ch = stream.next())) {
if (ch == '\\' && !stream.eol()) {
// handle escaped character
buf += options.escape(stream.next());
continue;
}
a = ch;
if (ch == '$') {
// looks like a tabstop
stream.start = stream.pos - 1;
if ((m = stream.match(/^[0-9]+/))) {
// it's $N
a = options.tabstop({
start: buf.length,
group: stream.current().substr(1),
token: stream.current()
});
} else if ((m = stream.match(/^\{([a-z_\-][\w\-]*)\}/))) {
// ${variable}
a = options.variable({
start: buf.length,
name: m[1],
token: stream.current()
});
} else if ((m = stream.match(/^\{([0-9]+)(:.+?)?\}/, false))) {
// ${N:value} or ${N} placeholder
// parse placeholder, including nested ones
stream.skipToPair('{', '}');
var obj = {
start: buf.length,
group: m[1],
token: stream.current()
};
var placeholder = obj.token.substring(obj.group.length + 2, obj.token.length - 1);
if (placeholder) {
obj.placeholder = placeholder.substr(1);
}
a = options.tabstop(obj);
}
}
buf += a;
}
return buf;
},
/**
* Upgrades tabstops in output node in order to prevent naming conflicts
* @param {AbbreviationNode} node
* @param {Number} offset Tab index offset
* @returns {Number} Maximum tabstop index in element
*/
upgrade: function(node, offset) {
var maxNum = 0;
var options = {
tabstop: function(data) {
var group = parseInt(data.group, 10);
if (group > maxNum) maxNum = group;
if (data.placeholder)
return '${' + (group + offset) + ':' + data.placeholder + '}';
else
return '${' + (group + offset) + '}';
}
};
['start', 'end', 'content'].forEach(function(p) {
node[p] = this.processText(node[p], options);
}, this);
return maxNum;
},
/**
* Helper function that produces a callback function for
* <code>replaceVariables()</code> method from {@link utils}
* module. This callback will replace variable definitions (like
* ${var_name}) with their value defined in <i>resource</i> module,
* or outputs tabstop with variable name otherwise.
* @param {AbbreviationNode} node Context node
* @returns {Function}
*/
variablesResolver: function(node) {
var placeholderMemo = {};
return function(str, varName) {
// do not mark `child` variable as placeholder its a reserved
// variable name
if (varName == 'child') {
return str;
}
if (varName == 'cursor') {
return utils.getCaretPlaceholder();
}
var attr = node.attribute(varName);
if (typeof attr !== 'undefined' && attr !== str) {
return attr;
}
var varValue = resources.getVariable(varName);
if (varValue) {
return varValue;
}
// output as placeholder
if (!placeholderMemo[varName]) {
placeholderMemo[varName] = startPlaceholderNum++;
}
return '${' + placeholderMemo[varName] + ':' + varName + '}';
};
},
/**
* Replace variables like ${var} in string
* @param {String} str
* @param {Object} vars Variable set (defaults to variables defined in
* <code>snippets.json</code>) or variable resolver (<code>Function</code>)
* @return {String}
*/
replaceVariables: function(str, vars) {
vars = vars || {};
var resolver = typeof vars === 'function' ? vars : function(str, p1) {
return p1 in vars ? vars[p1] : null;
};
return this.processText(str, {
variable: function(data) {
var newValue = resolver(data.token, data.name, data);
if (newValue === null) {
// try to find variable in resources
newValue = resources.getVariable(data.name);
}
if (newValue === null || typeof newValue === 'undefined')
// nothing found, return token itself
newValue = data.token;
return newValue;
}
});
},
/**
* Resets global tabstop index. When parsed tree is converted to output
* string (<code>AbbreviationNode.toString()</code>), all tabstops
* defined in snippets and elements are upgraded in order to prevent
* naming conflicts of nested. For example, <code>${1}</code> of a node
* should not be linked with the same placehilder of the child node.
* By default, <code>AbbreviationNode.toString()</code> automatically
* upgrades tabstops of the same index for each node and writes maximum
* tabstop index into the <code>tabstopIndex</code> variable. To keep
* this variable at reasonable value, it is recommended to call
* <code>resetTabstopIndex()</code> method each time you expand variable
* @returns
*/
resetTabstopIndex: function() {
tabstopIndex = 0;
startPlaceholderNum = 100;
},
/**
* Output processor for abbreviation parser that will upgrade tabstops
* of parsed node in order to prevent tabstop index conflicts
*/
abbrOutputProcessor: function(text, node, type) {
var maxNum = 0;
var that = this;
var tsOptions = {
tabstop: function(data) {
var group = parseInt(data.group, 10);
if (group === 0)
return '${0}';
if (group > maxNum) maxNum = group;
if (data.placeholder) {
// respect nested placeholders
var ix = group + tabstopIndex;
var placeholder = that.processText(data.placeholder, tsOptions);
return '${' + ix + ':' + placeholder + '}';
} else {
return '${' + (group + tabstopIndex) + '}';
}
}
};
// upgrade tabstops
text = this.processText(text, tsOptions);
// resolve variables
text = this.replaceVariables(text, this.variablesResolver(node));
tabstopIndex += maxNum + 1;
return text;
}
};
});
},{"../utils/common":73,"./resources":31,"./stringStream":32}],34:[function(require,module,exports){
/**
* Helper class for convenient token iteration
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
/**
* @type TokenIterator
* @param {Array} tokens
* @type TokenIterator
* @constructor
*/
function TokenIterator(tokens) {
/** @type Array */
this.tokens = tokens;
this._position = 0;
this.reset();
}
TokenIterator.prototype = {
next: function() {
if (this.hasNext()) {
var token = this.tokens[++this._i];
this._position = token.start;
return token;
} else {
this._i = this._il;
}
return null;
},
current: function() {
return this.tokens[this._i];
},
peek: function() {
return this.tokens[this._i + i];
},
position: function() {
return this._position;
},
hasNext: function() {
return this._i < this._il - 1;
},
reset: function() {
this._i = 0;
this._il = this.tokens.length;
},
item: function() {
return this.tokens[this._i];
},
itemNext: function() {
return this.tokens[this._i + 1];
},
itemPrev: function() {
return this.tokens[this._i - 1];
},
nextUntil: function(type, callback) {
var token;
var test = typeof type == 'string'
? function(t){return t.type == type;}
: type;
while ((token = this.next())) {
if (callback)
callback.call(this, token);
if (test.call(this, token))
break;
}
}
};
return {
create: function(tokens) {
return new TokenIterator(tokens);
}
};
});
},{}],35:[function(require,module,exports){
module.exports={
"eras": {
"e-26": "26 versions back",
"e-25": "25 versions back",
"e-24": "24 versions back",
"e-23": "23 versions back",
"e-22": "22 versions back",
"e-21": "21 versions back",
"e-20": "20 versions back",
"e-19": "19 versions back",
"e-18": "18 versions back",
"e-17": "17 versions back",
"e-16": "16 versions back",
"e-15": "15 versions back",
"e-14": "14 versions back",
"e-13": "13 versions back",
"e-12": "12 versions back",
"e-11": "11 versions back",
"e-10": "10 versions back",
"e-9": "9 versions back",
"e-8": "8 versions back",
"e-7": "7 versions back",
"e-6": "6 versions back",
"e-5": "5 versions back",
"e-4": "4 versions back",
"e-3": "3 versions back",
"e-2": "2 versions back",
"e-1": "Previous version",
"e0": "Current",
"e1": "Near future",
"e2": "Farther future"
},
"agents": {
"ie": {
"browser": "IE",
"abbr": "IE",
"prefix": "ms",
"type": "desktop",
"usage_global": {
"10": 10.7866,
"11": 0.114751,
"5.5": 0.009298,
"6": 0.204912,
"7": 0.508182,
"8": 8.31124,
"9": 5.21297
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "5.5", "6", "7", "8", "9", "10", "11", null, null],
"current_version": ""
},
"firefox": {
"browser": "Firefox",
"abbr": "FF",
"prefix": "moz",
"type": "desktop",
"usage_global": {
"10": 0.112406,
"11": 0.088319,
"12": 0.208754,
"13": 0.096348,
"14": 0.096348,
"15": 0.136493,
"16": 0.264957,
"17": 0.192696,
"18": 0.112406,
"19": 0.128464,
"2": 0.016058,
"20": 0.16058,
"21": 0.216783,
"22": 0.256928,
"23": 0.907277,
"24": 11.0318,
"25": 0.529914,
"26": 0.016058,
"27": 0.016058,
"3": 0.088319,
"3.5": 0.040145,
"3.6": 0.305102,
"4": 0.072261,
"5": 0.048174,
"6": 0.048174,
"7": 0.040145,
"8": 0.072261,
"9": 0.056203
},
"versions": [null, "2", "3", "3.5", "3.6", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27"],
"current_version": ""
},
"chrome": {
"browser": "Chrome",
"abbr": "Chr.",
"prefix": "webkit",
"type": "desktop",
"usage_global": {
"10": 0.048174,
"11": 0.112406,
"12": 0.064232,
"13": 0.056203,
"14": 0.056203,
"15": 0.072261,
"16": 0.048174,
"17": 0.040145,
"18": 0.08029,
"19": 0.040145,
"20": 0.040145,
"21": 0.48174,
"22": 0.248899,
"23": 0.216783,
"24": 0.200725,
"25": 0.361305,
"26": 0.353276,
"27": 0.369334,
"28": 0.610204,
"29": 5.08236,
"30": 24.6089,
"31": 0.16058,
"32": 0.064232,
"4": 0.024087,
"5": 0.024087,
"6": 0.032116,
"7": 0.024087,
"8": 0.032116,
"9": 0.024087
},
"versions": ["4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"],
"current_version": ""
},
"safari": {
"browser": "Safari",
"abbr": "Saf.",
"prefix": "webkit",
"type": "desktop",
"usage_global": {
"3.1": 0,
"3.2": 0.008692,
"4": 0.104377,
"5": 0.305102,
"5.1": 1.28464,
"6": 2.04739,
"6.1": 0.064232,
"7": 0.16058
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "3.1", "3.2", "4", "5", "5.1", "6", "6.1", "7", null, null],
"current_version": ""
},
"opera": {
"browser": "Opera",
"abbr": "Op.",
"prefix": "o",
"type": "desktop",
"usage_global": {
"10.0-10.1": 0.016058,
"10.5": 0.008392,
"10.6": 0.008029,
"11": 0.008219,
"11.1": 0.008219,
"11.5": 0.016058,
"11.6": 0.032116,
"12": 0.040145,
"12.1": 0.48174,
"15": 0.032116,
"16": 0.104377,
"17": 0.16058,
"18": 0,
"9.5-9.6": 0.008219
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, "9.5-9.6", "10.0-10.1", "10.5", "10.6", "11", "11.1", "11.5", "11.6", "12", "12.1", "15", "16", "17", "18", null],
"current_version": "",
"prefix_exceptions": {
"15": "webkit",
"16": "webkit",
"17": "webkit",
"18": "webkit"
}
},
"ios_saf": {
"browser": "iOS Safari",
"abbr": "iOS",
"prefix": "webkit",
"type": "mobile",
"usage_global": {
"3.2": 0.00400113,
"4.0-4.1": 0.00800226,
"4.2-4.3": 0.0280079,
"5.0-5.1": 0.28408,
"6.0-6.1": 1.15633,
"7.0": 2.52071
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "3.2", "4.0-4.1", "4.2-4.3", "5.0-5.1", "6.0-6.1", "7.0", null, null],
"current_version": ""
},
"op_mini": {
"browser": "Opera Mini",
"abbr": "O.Mini",
"prefix": "o",
"type": "mobile",
"usage_global": {
"5.0-7.0": 4.58374
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "5.0-7.0", null, null],
"current_version": ""
},
"android": {
"browser": "Android Browser",
"abbr": "And.",
"prefix": "webkit",
"type": "mobile",
"usage_global": {
"2.1": 0.0251229,
"2.2": 0.0854178,
"2.3": 1.32146,
"3": 0.00502458,
"4": 0.994867,
"4.1": 1.87417,
"4.2-4.3": 0.743638,
"4.4": 0
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "2.1", "2.2", "2.3", "3", "4", "4.1", "4.2-4.3", "4.4", null],
"current_version": ""
},
"op_mob": {
"browser": "Opera Mobile",
"abbr": "O.Mob",
"prefix": "o",
"type": "mobile",
"usage_global": {
"0": 0,
"10": 0,
"11.5": 0.00726525,
"12": 0.0363263,
"12.1": 0.101714
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "10", null, null, "11.5", "12", "12.1", "0", null, null],
"current_version": "16",
"prefix_exceptions": {
"0": "webkit"
}
},
"bb": {
"browser": "Blackberry Browser",
"abbr": "BB",
"prefix": "webkit",
"type": "mobile",
"usage_global": {
"10": 0,
"7": 0.141419
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "7", "10", null, null],
"current_version": ""
},
"and_chr": {
"browser": "Chrome for Android",
"abbr": "Chr/And.",
"prefix": "webkit",
"type": "mobile",
"usage_global": {
"0": 1.38176
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "0", null, null],
"current_version": "30"
},
"and_ff": {
"browser": "Firefox for Android",
"abbr": "FF/And.",
"prefix": "moz",
"type": "mobile",
"usage_global": {
"0": 0.070956
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "0", null, null],
"current_version": "25"
},
"ie_mob": {
"browser": "IE Mobile",
"abbr": "IE.Mob",
"prefix": "ms",
"type": "mobile",
"usage_global": {
"10": 0.205595
},
"versions": [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "10", null, null],
"current_version": ""
}
},
"statuses": {
"rec": "Recommendation",
"pr": "Proposed Recommendation",
"cr": "Candidate Recommendation",
"wd": "Working Draft",
"other": "Other",
"unoff": "Unofficial / Note"
},
"cats": {
"CSS": ["CSS", "CSS2", "CSS3"],
"HTML5": ["Canvas", "HTML5"],
"JS API": ["JS API"],
"Other": ["PNG", "Other", "DOM"],
"SVG": ["SVG"]
},
"updated": 1383587152,
"data": {
"png-alpha": {
"title": "PNG alpha transparency",
"description": "Semi-transparent areas in PNG files",
"spec": "http://www.w3.org/TR/PNG/",
"status": "rec",
"links": [{
"url": "http://dillerdesign.com/experiment/DD_belatedPNG/",
"title": "Workaround for IE6"
}, {
"url": "http://en.wikipedia.org/wiki/Portable_Network_Graphics",
"title": "Wikipedia"
}],
"categories": ["PNG"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "IE6 does support full transparency in 8-bit PNGs, which can sometimes be an alternative to 24-bit PNGs.",
"usage_perc_y": 94.36,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"apng": {
"title": "Animated PNG (APNG)",
"description": "Like animated GIFs, but allowing 24-bit colors and alpha transparency",
"spec": "https://wiki.mozilla.org/APNG_Specification",
"status": "unoff",
"links": [{
"url": "http://en.wikipedia.org/wiki/APNG",
"title": "Wikipedia"
}, {
"url": "https://github.com/davidmz/apng-canvas",
"title": "Polyfill using canvas"
}, {
"url": "https://chrome.google.com/webstore/detail/ehkepjiconegkhpodgoaeamnpckdbblp",
"title": "Chrome extension providing support"
}, {
"url": "http://www.truekolor.net/learn-how-to-create-an-animated-png/",
"title": "APNG tutorial"
}],
"categories": ["PNG"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "n",
"32": "n"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Where support for APNG is missing, only the first frame is displayed",
"usage_perc_y": 16.19,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"video": {
"title": "Video element",
"description": "Method of playing videos on webpages (without requiring a plug-in)",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#video",
"status": "wd",
"links": [{
"url": "https://raw.github.com/phiggins42/has.js/master/detect/video.js#video",
"title": "has.js test"
}, {
"url": "http://webmproject.org",
"title": "WebM format information"
}, {
"url": "http://docs.webplatform.org/wiki/html/elements/video",
"title": "WebPlatform Docs"
}, {
"url": "http://camendesign.co.uk/code/video_for_everybody",
"title": "Video for Everybody"
}, {
"url": "http://diveinto.org/html5/video.html",
"title": "Video on the Web - includes info on Android support"
}, {
"url": "http://dev.opera.com/articles/view/everything-you-need-to-know-about-html5-video-and-audio/",
"title": "Detailed article on video/audio elements"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a",
"2.2": "a",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Different browsers have support for different video formats, see sub-features for details. \r\n\r\nThe Android browser (before 2.3) requires <a href=\"http://www.broken-links.com/2010/07/08/making-html5-video-work-on-android-phones/\">specific handling</a> to run the video element.",
"usage_perc_y": 80.71,
"usage_perc_a": 0.11,
"ucprefix": false,
"parent": "",
"keywords": "<video>"
},
"audio": {
"title": "Audio element",
"description": "Method of playing sound on webpages (without requiring a plug-in)",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#audio",
"status": "wd",
"links": [{
"url": "http://html5doctor.com/native-audio-in-the-browser/",
"title": "HTML5 Doctor article"
}, {
"url": "http://textopia.org/androidsoundformats.html",
"title": "File format test page"
}, {
"url": "http://www.jplayer.org/latest/demos/",
"title": "Demos of audio player that uses &lt;audio>"
}, {
"url": "http://www.phoboslab.org/log/2011/03/the-state-of-html5-audio",
"title": "The State of HTML5 Audio"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/audio.js#audio",
"title": "has.js test"
}, {
"url": "http://dev.opera.com/articles/view/everything-you-need-to-know-about-html5-video-and-audio/",
"title": "Detailed article on video/audio elements"
}, {
"url": "http://docs.webplatform.org/wiki/html/elements/audio",
"title": "WebPlatform Docs"
}, {
"url": "http://24ways.org/2010/the-state-of-html5-audio",
"title": "Detailed article on support"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "a",
"10.0-10.1": "a",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 80.7,
"usage_perc_a": 0.02,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"contenteditable": {
"title": "contenteditable attribute (basic support)",
"description": "Method of making any HTML element editable",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#contenteditable",
"status": "wd",
"links": [{
"url": "http://accessgarage.wordpress.com/2009/05/08/how-to-hack-your-app-to-make-contenteditable-work/",
"title": "Blog post on usage problems"
}, {
"url": "http://html5demos.com/contenteditable",
"title": "Demo page"
}, {
"url": "http://blog.whatwg.org/the-road-to-html-5-contenteditable",
"title": "WHATWG blog post"
}, {
"url": "http://docs.webplatform.org/wiki/html/attributes/contentEditable",
"title": "WebPlatform Docs"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "a",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "This support only refers to very basic editing capability, implementations vary significantly on how certain elements can be edited.",
"usage_perc_y": 88.37,
"usage_perc_a": 0.09,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"dragndrop": {
"title": "Drag and Drop",
"description": "Method of easily dragging and dropping elements on a page, requiring minimal JavaScript.",
"spec": "http://www.w3.org/TR/html5/editing.html#dnd",
"status": "wd",
"links": [{
"url": "http://html5demos.com/drag",
"title": "Demo with link blocks"
}, {
"url": "http://html5doctor.com/native-drag-and-drop/",
"title": "HTML5 Doctor article"
}, {
"url": "http://docs.webplatform.org/wiki/dom/events/drag",
"title": "WebPlatform Docs"
}, {
"url": "http://nettutsplus.s3.amazonaws.com/64_html5dragdrop/demo/index.html",
"title": "Shopping cart demo"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "p",
"9.5-9.6": "p",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"11.6": "p",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"12": "p",
"12.1": "y",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support in older IE refers to no support for the dataTransfer.files or .types objects and limited supported formats for dataTransfer.setData/getData.",
"usage_perc_y": 64.83,
"usage_perc_a": 14.25,
"ucprefix": false,
"parent": "",
"keywords": "draganddrop"
},
"queryselector": {
"title": "querySelector/querySelectorAll",
"description": "Method of accessing DOM elements using CSS selectors",
"spec": "http://www.w3.org/TR/selectors-api/",
"status": "rec",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/selectors_api/querySelector",
"title": "WebPlatform Docs"
}, {
"url": "http://cjihrig.com/blog/javascripts-selectors-api/",
"title": "Blog post"
}, {
"url": "https://developer.mozilla.org/En/DOM/Element.querySelectorAll",
"title": "MDN article on querySelectorAll"
}, {
"url": "https://developer.mozilla.org/en/DOM/element.querySelector",
"title": "MDN article on querySelector"
}],
"categories": ["DOM"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "p",
"9.5-9.6": "p",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Only works for the CSS selectors available. Thus the IE8 implementation is limited to the CSS 2.1 selectors",
"usage_perc_y": 93.74,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "query,selectors,selectors api"
},
"getelementsbyclassname": {
"title": "getElementsByClassName",
"description": "Method of accessing DOM elements by class name",
"spec": "http://www.w3.org/TR/dom/#dom-document-getelementsbyclassname",
"status": "wd",
"links": [{
"url": "http://www.quirksmode.org/dom/tests/basics.html#getElementsByClassName",
"title": "Test page"
}, {
"url": "http://docs.webplatform.org/wiki/dom/methods/getElementsByClassName",
"title": "WebPlatform Docs"
}],
"categories": ["DOM", "HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 85.52,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "byclassname"
},
"forms": {
"title": "HTML5 form features",
"description": "Expanded form options, including things like date pickers, sliders, validation, placeholders and multiple file uploads. Previously known as \"Web forms 2.0\".",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html",
"status": "wd",
"links": [{
"url": "https://github.com/westonruter/webforms2",
"title": "Cross-browser JS implementation (based on original spec)"
}, {
"url": "http://www.miketaylr.com/code/input-type-attr.html",
"title": "HTML5 inputs and attribute support page"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "a",
"11": "a"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "p",
"3.6": "p",
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a"
},
"chrome": {
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a",
"28": "a",
"29": "a",
"30": "a",
"31": "a",
"32": "a"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "a",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "a",
"16": "a",
"17": "a",
"18": "a"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "a"
},
"bb": {
"7": "n",
"10": "a"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "a"
},
"and_chr": {
"0": "a"
},
"and_ff": {
"0": "a"
},
"ie_mob": {
"10": "a"
}
},
"notes": "",
"usage_perc_y": 4.75,
"usage_perc_a": 65.35,
"ucprefix": false,
"parent": "",
"keywords": "input,datepicker"
},
"html5semantic": {
"title": "New semantic elements",
"description": "HTML5 offers some new elements, primarily for semantic purposes. The elements include: section, article, aside, header, footer, nav, figure, figcaption, time, mark.",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#sections",
"status": "wd",
"links": [{
"url": "http://oli.jp/2009/html5-structure3/",
"title": "Article on structural elements"
}, {
"url": "http://blog.whatwg.org/supporting-new-elements-in-ie",
"title": "Workaround for IE"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/dom.js#dom-html5-elements",
"title": "has.js test"
}, {
"url": "http://blog.whatwg.org/styling-ie-noscript",
"title": "Alternate workaround"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "a",
"3.5": "a",
"3.6": "a",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "a",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a",
"3.2": "a",
"4": "a",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "a",
"9.5-9.6": "a",
"10.0-10.1": "a",
"10.5": "a",
"10.6": "a",
"11": "a",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "a",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "a",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support refers to missing the default styling. This is easily taken care of by using display:block for all new elements (except time and mark, these should be display:inline anyway).",
"usage_perc_y": 80.26,
"usage_perc_a": 5.26,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"offline-apps": {
"title": "Offline web applications",
"description": "Method of defining web page files to be cached using a cache manifest file, allowing them to work offline on subsequent visits to the page",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html",
"status": "wd",
"links": [{
"url": "http://www.sitepoint.com/offline-web-application-tutorial/",
"title": "Sitepoint tutorial"
}, {
"url": "http://diveinto.org/html5/offline.html",
"title": "Dive Into HTML5 article"
}, {
"url": "http://docs.webplatform.org/wiki/apis/appcache/ApplicationCache",
"title": "WebPlatform Docs"
}, {
"url": "http://hacks.mozilla.org/2010/01/offline-web-applications/",
"title": "Mozilla Hacks article/demo"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "a",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 75.59,
"usage_perc_a": 0.09,
"ucprefix": false,
"parent": "",
"keywords": "appcache,app cache,application cache,online"
},
"webworkers": {
"title": "Web Workers",
"description": "Method of running scripts in the background, isolated from the web page",
"spec": "http://www.w3.org/TR/workers/",
"status": "cr",
"links": [{
"url": "http://code.google.com/p/ie-web-worker/",
"title": "Polyfill for IE (single threaded)"
}, {
"url": "http://net.tutsplus.com/tutorials/javascript-ajax/getting-started-with-web-workers/",
"title": "Tutorial"
}, {
"url": "https://developer.mozilla.org/En/Using_web_workers",
"title": "MDN article"
}, {
"url": "http://nerget.com/rayjs-mt/rayjs.html",
"title": "Web Worker demo"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "p",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 70.53,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"fontface": {
"title": "@font-face Web fonts",
"description": "Method of displaying fonts downloaded from websites",
"spec": "http://www.w3.org/TR/css3-webfonts/",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/atrules/@font-face",
"title": "WebPlatform Docs"
}, {
"url": "http://www.css3files.com/font/",
"title": "Information page"
}, {
"url": "http://webfonts.info",
"title": "News and information site"
}, {
"url": "http://en.wikipedia.org/wiki/Web_typography",
"title": "Wikipedia"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "a",
"2.3": "a",
"3": "a",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "a",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support before IE8 refers to only supporting EOT fonts. Safari for iOS 4.1 and below only supports SVG fonts.",
"usage_perc_y": 79.25,
"usage_perc_a": 10.6,
"ucprefix": false,
"parent": "",
"keywords": "font face"
},
"eot": {
"title": "EOT - Embedded OpenType fonts",
"description": "Type of font that can be derived from a regular font, allowing small files and legal use of high-quality fonts. Usage is restricted by the file being tied to the website",
"spec": "http://www.w3.org/Submission/EOT/",
"status": "unoff",
"links": [{
"url": "http://www.microsoft.com/typography/web/embedding/default.aspx",
"title": "Example pages"
}, {
"url": "http://en.wikipedia.org/wiki/Embedded_OpenType",
"title": "Wikipedia"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "n",
"32": "n"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Proposal by Microsoft, being considered for W3C standardization.",
"usage_perc_y": 25.14,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "fontface",
"keywords": ""
},
"woff": {
"title": "WOFF - Web Open Font Format",
"description": "Compressed TrueType/OpenType font that contains information about the font's source.",
"spec": "http://www.w3.org/TR/WOFF/",
"status": "rec",
"links": [{
"url": "http://hacks.mozilla.org/2009/10/woff/",
"title": "Mozilla hacks blog post"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Reported to be supported in some modified versions of the Android 4.0 browser.",
"usage_perc_y": 75.23,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "fontface",
"keywords": ""
},
"multibackgrounds": {
"title": "CSS3 Multiple backgrounds",
"description": "Method of using multiple images as a background",
"spec": "http://www.w3.org/TR/css3-background/",
"status": "cr",
"links": [{
"url": "http://www.css3.info/preview/multiple-backgrounds/",
"title": "Demo & information page"
}, {
"url": "http://www.css3files.com/background/",
"title": "Information page"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/background-image",
"title": "WebPlatform Docs"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 85.37,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"border-image": {
"title": "CSS3 Border images",
"description": "Method of using images for borders",
"spec": "http://www.w3.org/TR/css3-background/#the-border-image",
"status": "cr",
"links": [{
"url": "http://www.css3files.com/border/",
"title": "Information page"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/border-image",
"title": "WebPlatform Docs"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "a x",
"3.6": "a x",
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "y x",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a x",
"3.2": "a x",
"4": "a x",
"5": "a x",
"5.1": "a x",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "a",
"10.6": "a",
"11": "a x",
"11.1": "a x",
"11.5": "a x",
"11.6": "a x",
"12": "a x",
"12.1": "a x",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a x",
"4.0-4.1": "a x",
"4.2-4.3": "a x",
"5.0-5.1": "a x",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a x",
"2.2": "a x",
"2.3": "a x",
"3": "a x",
"4": "a x",
"4.1": "a x",
"4.2-4.3": "a x",
"4.4": "y"
},
"bb": {
"7": "a x",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "a x",
"11.1": "a x",
"11.5": "a x",
"12": "a x",
"12.1": "a x",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "In Firefox both the border-style and border-width must be specified for border-images to work. Partial support refers to supporting the shorthand syntax, but not the individual properties (border-image-source, border-image-slice, etc).",
"usage_perc_y": 54.86,
"usage_perc_a": 9.76,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"background-img-opts": {
"title": "CSS3 Background-image options",
"description": "New properties to affect background images, including background-clip, background-origin and background-size",
"spec": "http://www.w3.org/TR/css3-background/#backgrounds",
"status": "cr",
"links": [{
"url": "https://github.com/louisremi/background-size-polyfill",
"title": "Polyfill for IE7-8"
}, {
"url": "http://www.standardista.com/css3/css3-background-properties",
"title": "Detailed compatibility tables and demos"
}, {
"url": "http://www.css3files.com/background/",
"title": "Information page"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "a x",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a",
"3.2": "a",
"4": "a",
"5": "y",
"5.1": "y",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "a x",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "a x",
"2.2": "y x",
"2.3": "y x",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support in Opera Mini refers to not supporting background sizing or background attachments. Partial support in Safari 6 refers to not supporting background sizing offset from edges syntax.",
"usage_perc_y": 78.07,
"usage_perc_a": 7.32,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"css-table": {
"title": "CSS Table display",
"description": "Method of displaying elements as tables, rows, and cells",
"spec": "http://www.w3.org/TR/CSS21/tables.html",
"status": "rec",
"links": [{
"url": "http://blog.12spokes.com/web-design-development/when-to-choose-between-the-html-table-element-and-css-displaytable-property/",
"title": "Deciding on HTML or CSS tables"
}, {
"url": "http://www.onenaught.com/posts/201/use-css-displaytable-for-layout",
"title": "Blog post on usage"
}],
"categories": ["CSS2"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 93.86,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "display:table, display: table,table-cell,table-row,table-layout"
},
"css-gencontent": {
"title": "CSS Generated content",
"description": "Method of displaying text or images before or after the given element's contents using the :before and :after pseudo-elements",
"spec": "http://www.w3.org/TR/CSS21/generate.html",
"status": "rec",
"links": [{
"url": "http://www.westciv.com/style_master/academy/css_tutorial/advanced/generated_content.html",
"title": "Guide on usage"
}, {
"url": "http://docs.webplatform.org/wiki/css/generated_and_replaced_content",
"title": "WebPlatform Docs"
}, {
"url": "http://dev.opera.com/articles/view/css-generated-content-techniques/",
"title": "Dev.Opera article"
}],
"categories": ["CSS2", "CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "a",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "IE8 only supports the single-colon CSS 2.1 syntax (i.e. pseudo-class). It does not support the double-colon CSS3 syntax (i.e. pseudo-element)",
"usage_perc_y": 85.55,
"usage_perc_a": 8.31,
"ucprefix": false,
"parent": "",
"keywords": "before,after"
},
"css-fixed": {
"title": "CSS position:fixed",
"description": "Method of keeping an element in a fixed location regardless of scroll position",
"spec": "http://www.w3.org/TR/CSS21/visuren.html#fixed-positioning",
"status": "rec",
"links": [{
"url": "http://www.css-101.org/fixed-positioning/05.php",
"title": "Workaround for IE6"
}, {
"url": "http://bradfrostweb.com/blog/mobile/fixed-position/",
"title": "Article on mobile support"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/position",
"title": "WebPlatform Docs"
}],
"categories": ["CSS"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a",
"2.2": "a",
"2.3": "a",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Only works in Android 2.2+ by using the following meta tag: &lt;meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">. Partial support in iOS Safari refers to <a href=\"http://remysharp.com/2012/05/24/issues-with-position-fixed-scrolling-on-ios/\">buggy behavior</a>.",
"usage_perc_y": 84.35,
"usage_perc_a": 5.39,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"hashchange": {
"title": "Hashchange event",
"description": "Event triggered in JavaScript when the URL's hash has changed (for example: page.html#foo to page.html#bar) ",
"spec": "http://www.w3.org/TR/html5/history.html#event-hashchange",
"status": "cr",
"links": [{
"url": "http://www.quirksmode.org/dom/events/tests/hashchange.html",
"title": "Simple demo"
}, {
"url": "http://docs.webplatform.org/wiki/dom/events/hashchange",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/en/DOM/window.onhashchange",
"title": "MDN article"
}, {
"url": "http://github.com/3nr1c/jUri.js",
"title": "Polyfill"
}, {
"url": "http://msdn.microsoft.com/en-us/library/cc288209(VS.85).aspx",
"title": "MSDN article"
}],
"categories": ["HTML5", "JS API"],
"stats": {
"ie": {
"5.5": "p",
"6": "p",
"7": "p",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "p",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "p",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "p",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "p",
"9.5-9.6": "p",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "p",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 88.92,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "onhashchange,HashChangeEvent"
},
"css-sel2": {
"title": "CSS 2.1 selectors",
"description": "Allows more accurate element selecting, using >, +, [attr], :first-child, etc.",
"spec": "http://www.w3.org/TR/CSS21/selector.html",
"status": "rec",
"links": [{
"url": "http://www.quirksmode.org/css/contents.html",
"title": "Detailed support information"
}, {
"url": "http://docs.webplatform.org/wiki/css/selectors",
"title": "WebPlatform Docs"
}, {
"url": "http://selectivizr.com",
"title": "Selectivizr: Polyfill for IE6-8"
}, {
"url": "http://www.yourhtmlsource.com/stylesheets/advancedselectors.html",
"title": "Examples of advanced selectors"
}],
"categories": ["CSS2"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 94.36,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "child selector,:hover,adjacent,sibling,adjacent sibling"
},
"css-sel3": {
"title": "CSS3 selectors",
"description": "Advanced element selection using selectors like :nth-child(), :last-child, :first-of-type, etc.",
"spec": "http://www.w3.org/TR/css3-selectors/",
"status": "rec",
"links": [{
"url": "http://www.css3.info/selectors-test/",
"title": "Automated CSS3 selector test"
}, {
"url": "http://docs.webplatform.org/wiki/css/selectors",
"title": "WebPlatform Docs"
}, {
"url": "http://www.quirksmode.org/css/contents.html",
"title": "Detailed support information"
}, {
"url": "http://selectivizr.com",
"title": "Selectivizr: Polyfill for IE6-8"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 85.43,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ":target,:not"
},
"css-textshadow": {
"title": "CSS3 Text-shadow",
"description": "Method of applying one or more shadow or blur effects to text",
"spec": "http://www.w3.org/TR/css-text-decor-3/#text-shadow-property",
"status": "wd",
"links": [{
"url": "http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_text-shadow.htm",
"title": "Live editor"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/text-shadow",
"title": "WebPlatform Docs"
}, {
"url": "http://hacks.mozilla.org/2009/06/text-shadow/",
"title": "Mozilla hacks article"
}, {
"url": "http://www.css3files.com/shadow/#textshadow",
"title": "Information page"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a",
"3.2": "a",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "a",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Opera Mini ignores the blur-radius set, so no blur effect is visible. Text-shadow behavior can be somewhat emulated in older IE versions using the non-standard \"dropshadow\" or \"glow\" filters. ",
"usage_perc_y": 75.49,
"usage_perc_a": 4.73,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"css-boxshadow": {
"title": "CSS3 Box-shadow",
"description": "Method of displaying an inner or outer shadow effect to elements",
"spec": "http://www.w3.org/TR/css3-background/#box-shadow",
"status": "cr",
"links": [{
"url": "http://www.css3files.com/shadow/",
"title": "Information page"
}, {
"url": "https://developer.mozilla.org/En/CSS/-moz-box-shadow",
"title": "MDN article"
}, {
"url": "http://westciv.com/tools/boxshadows/index.html",
"title": "Live editor"
}, {
"url": "http://tests.themasta.com/blogstuff/boxshadowdemo.html",
"title": "Demo of various effects"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/box-shadow",
"title": "WebPlatform Docs"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y x",
"3.6": "y x",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a x",
"3.2": "a x",
"4": "a x",
"5": "y x",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a x",
"4.0-4.1": "y x",
"4.2-4.3": "y x",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a x",
"2.2": "a x",
"2.3": "a x",
"3": "a x",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y x",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Can be partially emulated in older IE versions using the non-standard \"shadow\" filter. Partial support in Safari, iOS Safari and Android Browser refers to missing \"inset\" and blur radius value support.",
"usage_perc_y": 79.27,
"usage_perc_a": 1.55,
"ucprefix": false,
"parent": "",
"keywords": "box-shadows,boxshadows,box shadow,shaow"
},
"css3-colors": {
"title": "CSS3 Colors",
"description": "Method of describing colors using Hue, Saturation and Lightness (hsl()) rather than just RGB, as well as allowing alpha-transparency with rgba() and hsla().",
"spec": "http://www.w3.org/TR/css3-color/",
"status": "rec",
"links": [{
"url": "http://www.zenelements.com/blog/css3-rgb-rgba-color-opacity/",
"title": "Guide to RGB & RGBA"
}, {
"url": "http://www.css3files.com/color/",
"title": "Information page"
}, {
"url": "http://www.zenelements.com/blog/css3-hsl-hsla-color-opacity/",
"title": "Guide to HSL & HSLA"
}, {
"url": "http://docs.webplatform.org/wiki/css/color#RGBA_Notation",
"title": "WebPlatform Docs"
}, {
"url": "http://dev.opera.com/articles/view/color-in-opera-10-hsl-rgb-and-alpha-transparency/",
"title": "Dev.Opera article"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "a",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "a",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 85.51,
"usage_perc_a": 0.02,
"ucprefix": false,
"parent": "",
"keywords": "rgb,hsl,rgba,hsla"
},
"css3-boxsizing": {
"title": "CSS3 Box-sizing",
"description": "Method of specifying whether or not an element's borders and padding should be included in size units",
"spec": "http://www.w3.org/TR/css3-ui/#box-sizing",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/properties/box-sizing",
"title": "WebPlatform Docs"
}, {
"url": "http://css-tricks.com/box-sizing/",
"title": "CSS Tricks"
}, {
"url": "https://github.com/Schepp/box-sizing-polyfill",
"title": "Polyfill for IE"
}, {
"url": "https://developer.mozilla.org/En/CSS/Box-sizing",
"title": "MDN article"
}, {
"url": "http://www.456bereastreet.com/archive/201104/controlling_width_with_css3_box-sizing/",
"title": "Blog post"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "p",
"6": "p",
"7": "p",
"8": "a",
"9": "a",
"10": "a",
"11": "a"
},
"firefox": {
"2": "y x",
"3": "y x",
"3.5": "y x",
"3.6": "y x",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x"
},
"chrome": {
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a",
"28": "a",
"29": "a",
"30": "a",
"31": "a",
"32": "a"
},
"safari": {
"3.1": "a x",
"3.2": "a x",
"4": "a x",
"5": "a x",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "n",
"9.5-9.6": "a",
"10.0-10.1": "a",
"10.5": "a",
"10.6": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"11.6": "a",
"12": "a",
"12.1": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a"
},
"ios_saf": {
"3.2": "a x",
"4.0-4.1": "a x",
"4.2-4.3": "a x",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "a x",
"2.2": "a x",
"2.3": "a x",
"3": "a x",
"4": "a",
"4.1": "a",
"4.2-4.3": "a",
"4.4": "a"
},
"bb": {
"7": "a x",
"10": "a"
},
"op_mob": {
"10": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"12": "a",
"12.1": "a",
"0": "a"
},
"and_chr": {
"0": "a"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "a"
}
},
"notes": "Partial support refers to supporting only the \"border-box\" value, not \"padding-box\" (which was added to the spec later).",
"usage_perc_y": 15.43,
"usage_perc_a": 78.42,
"ucprefix": false,
"parent": "",
"keywords": "border-box,content-box,padding-box"
},
"css-mediaqueries": {
"title": "CSS3 Media Queries",
"description": "Method of applying styles based on media information. Includes things like page and device dimensions",
"spec": "http://www.w3.org/TR/css3-mediaqueries/",
"status": "rec",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/atrules/@media",
"title": "WebPlatform Docs"
}, {
"url": "http://ie.microsoft.com/testdrive/HTML5/85CSS3_MediaQueries/",
"title": "IE demo page with information"
}, {
"url": "https://github.com/scottjehl/Respond",
"title": "Polyfill for IE"
}, {
"url": "http://webdesignerwall.com/tutorials/responsive-design-with-css3-media-queries",
"title": "Media Queries tutorial"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a",
"3.2": "a",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Incomplete support by older webkit browsers refers to only acknowledging different media rules on page reload",
"usage_perc_y": 85.42,
"usage_perc_a": 0.01,
"ucprefix": false,
"parent": "",
"keywords": "@media"
},
"multicolumn": {
"title": "CSS3 Multiple column layout",
"description": "Method of flowing information in multiple columns",
"spec": "http://www.w3.org/TR/css3-multicol/",
"status": "cr",
"links": [{
"url": "http://dev.opera.com/articles/view/css3-multi-column-layout/",
"title": "Dev.Opera article"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/column-width",
"title": "WebPlatform Docs"
}, {
"url": "http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/an-introduction-to-the-css3-multiple-column-layout-module/",
"title": "Introduction page"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "a x",
"3": "a x",
"3.5": "a x",
"3.6": "a x",
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "a x",
"21": "a x",
"22": "a x",
"23": "a x",
"24": "a x",
"25": "a x",
"26": "a x",
"27": "a x"
},
"chrome": {
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "a x",
"21": "a x",
"22": "a x",
"23": "a x",
"24": "a x",
"25": "a x",
"26": "a x",
"27": "a x",
"28": "a x",
"29": "a x",
"30": "a x",
"31": "a x",
"32": "a x"
},
"safari": {
"3.1": "a x",
"3.2": "a x",
"4": "a x",
"5": "a x",
"5.1": "a x",
"6": "a x",
"6.1": "a x",
"7": "a x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x"
},
"ios_saf": {
"3.2": "a x",
"4.0-4.1": "a x",
"4.2-4.3": "a x",
"5.0-5.1": "a x",
"6.0-6.1": "a x",
"7.0": "a x"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "a x",
"2.2": "a x",
"2.3": "a x",
"3": "a x",
"4": "a x",
"4.1": "a x",
"4.2-4.3": "a x",
"4.4": "a x"
},
"bb": {
"7": "a x",
"10": "a x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "a x"
},
"and_chr": {
"0": "a x"
},
"and_ff": {
"0": "a x"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support refers to not supporting the break-before, break-after, break-inside properties. Webkit browsers do have equivalent support for the non-standard -webkit-column-break-* properties.",
"usage_perc_y": 16.41,
"usage_perc_a": 63.85,
"ucprefix": false,
"parent": "",
"keywords": "column-count"
},
"border-radius": {
"title": "CSS3 Border-radius (rounded corners)",
"description": "Method of making the border corners round",
"spec": "http://www.w3.org/TR/css3-background/#the-border-radius",
"status": "cr",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/properties/border-radius",
"title": "WebPlatform Docs"
}, {
"url": "http://muddledramblings.com/table-of-css3-border-radius-compliance",
"title": "Detailed compliance table"
}, {
"url": "http://www.css3files.com/border/#borderradius",
"title": "Information page"
}, {
"url": "http://css3pie.com/",
"title": "Polyfill which includes border-radius"
}, {
"url": "http://border-radius.com",
"title": "Border-radius CSS Generator"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "a x",
"3": "y x",
"3.5": "y x",
"3.6": "y x",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y x",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y x",
"3.2": "y x",
"4": "y x",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y x",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y x",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 80.91,
"usage_perc_a": 0.02,
"ucprefix": false,
"parent": "",
"keywords": "roundedcorners, border radius,-moz-border-radius"
},
"transforms2d": {
"title": "CSS3 Transforms",
"description": "Method of transforming an element including rotating, scaling, etc.",
"spec": "http://www.w3.org/TR/css3-2d-transforms/",
"status": "wd",
"links": [{
"url": "http://www.westciv.com/tools/transforms/",
"title": "Live editor"
}, {
"url": "http://www.useragentman.com/IETransformsTranslator/",
"title": "Converter for IE"
}, {
"url": "http://docs.webplatform.org/wiki/css/transforms/transform",
"title": "WebPlatform Docs"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/css.js#css-transform",
"title": "has.js test"
}, {
"url": "https://developer.mozilla.org/en/CSS/-moz-transform",
"title": "MDN article"
}, {
"url": "http://www.webresourcesdepot.com/cross-browser-css-transforms-csssandpaper/",
"title": "Workaround script for IE"
}, {
"url": "http://www.css3files.com/transform/",
"title": "Information page"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y x",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y x",
"3.6": "y x",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "y x",
"3.2": "y x",
"4": "y x",
"5": "y x",
"5.1": "y x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y x",
"10.6": "y x",
"11": "y x",
"11.1": "y x",
"11.5": "y x",
"11.6": "y x",
"12": "y x",
"12.1": "y",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "y x",
"4.0-4.1": "y x",
"4.2-4.3": "y x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y x",
"2.2": "y x",
"2.3": "y x",
"3": "y x",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y x"
},
"bb": {
"7": "y x",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "The scale transform can be emulated in IE < 9 using Microsoft's \"zoom\" extension, others are (not easily) possible using the MS Matrix filter",
"usage_perc_y": 80.82,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "transformation,translate,rotation,rotate,scale,css-transforms"
},
"use-strict": {
"title": "ECMAScript 5 Strict Mode",
"description": "Method of placing code in a \"strict\" operating context.",
"spec": "http://ecma-international.org/ecma-262/5.1/#sec-14.1",
"status": "other",
"links": [{
"url": "http://javascriptweblog.wordpress.com/2011/05/03/javascript-strict-mode/",
"title": "Article with test suite"
}, {
"url": "http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/",
"title": "Information page"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "a",
"5.1": "a",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support in older Safari refers to strict mode still accepting a lot of JS that should be considered invalid.",
"usage_perc_y": 71.65,
"usage_perc_a": 1.59,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"transforms3d": {
"title": "CSS3 3D Transforms",
"description": "Method of transforming an element in the third dimension",
"spec": "http://www.w3.org/TR/css3-3d-transforms/",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/transforms/transform",
"title": "WebPlatform Docs"
}, {
"url": "http://css3.bradshawenterprises.com/flip/",
"title": "Multi-browser demo"
}, {
"url": "http://thewebrocks.com/demos/3D-css-tester/",
"title": "3D CSS Tester"
}, {
"url": "http://hacks.mozilla.org/2011/10/css-3d-transformations-in-firefox-nightly/",
"title": "Mozilla hacks article"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/css.js#css-transform",
"title": "has.js test"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "a",
"11": "a"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y x",
"5": "y x",
"5.1": "y x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "y x",
"4.0-4.1": "y x",
"4.2-4.3": "y x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y x",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y x"
},
"bb": {
"7": "y x",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "a"
}
},
"notes": "Partial support in IE10 refers to not supporting <a href=\"http://msdn.microsoft.com/en-us/library/ie/hh673529%28v=vs.85%29.aspx#the_ms_transform_style_property\">the transform-style: preserve-3d property</a>. This prevents nesting 3D transformed elements.",
"usage_perc_y": 61.31,
"usage_perc_a": 11.11,
"ucprefix": false,
"parent": "",
"keywords": "css 3d,3dtransforms,translate3d,transform3d"
},
"sharedworkers": {
"title": "Shared Web Workers",
"description": "Method of allowing multiple scripts to communicate with a single web worker.",
"spec": "http://www.w3.org/TR/workers/#shared-workers-introduction",
"status": "cr",
"links": [{
"url": "http://www.sitepoint.com/javascript-shared-web-workers-html5/",
"title": "Sitepoint article"
}, {
"url": "http://greenido.wordpress.com/2011/11/03/web-workers-part-3-out-of-3-shared-wrokers/",
"title": "Blog post"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "u",
"27": "u"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "u",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Expected to be supported in Firefox 27.",
"usage_perc_y": 40.07,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "webworkers",
"keywords": "shared worker"
},
"css-hyphens": {
"title": "CSS Hyphenation",
"description": "Method of controlling when words at the end of lines should be hyphenated using the \"hyphens\" property.",
"spec": "http://www.w3.org/TR/css3-text/#hyphenation",
"status": "wd",
"links": [{
"url": "https://developer.mozilla.org/en/CSS/hyphens",
"title": "MDN article"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/hyphens",
"title": "WebPlatform Docs"
}, {
"url": "http://blog.fontdeck.com/post/9037028497/hyphens",
"title": "Blog post"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y x",
"11": "y x"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "n",
"32": "n"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "y x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "y x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Chrome 29- and Android 4.0 Browser support \"-webkit-hyphens: none\", but not the \"auto\" property. Chrome 30+ doesn't support it either.",
"usage_perc_y": 33.31,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "hyphen,shy"
},
"css-transitions": {
"title": "CSS3 Transitions",
"description": "Simple method of animating certain properties of an element",
"spec": "http://www.w3.org/TR/css3-transitions/",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/properties/transition",
"title": "WebPlatform Docs"
}, {
"url": "http://www.webdesignerdepot.com/2010/01/css-transitions-101/",
"title": "Article on usage"
}, {
"url": "http://www.opera.com/docs/specs/presto2.12/css/transitions/#anima",
"title": "Animation of property types support in Opera"
}, {
"url": "http://www.css3files.com/transition/",
"title": "Information page"
}, {
"url": "http://www.the-art-of-web.com/css/timing-function/",
"title": "Examples on timing functions"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y x",
"3.2": "y x",
"4": "y x",
"5": "y x",
"5.1": "y x",
"6": "y x",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y x",
"10.6": "y x",
"11": "y x",
"11.1": "y x",
"11.5": "y x",
"11.6": "y x",
"12": "y x",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y x",
"4.0-4.1": "y x",
"4.2-4.3": "y x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y x",
"2.2": "y x",
"2.3": "y x",
"3": "y x",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y"
},
"bb": {
"7": "y x",
"10": "y x"
},
"op_mob": {
"10": "y x",
"11": "y x",
"11.1": "y x",
"11.5": "y x",
"12": "y x",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 75.27,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "css transition"
},
"font-feature": {
"title": "Font feature settings",
"description": "Method of applying advanced typographic and language-specific font features to supported OpenType fonts.",
"spec": "http://w3.org/TR/css3-fonts/#font-rend-props",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/properties/font-feature-settings",
"title": "WebPlatform Docs"
}, {
"url": "http://hacks.mozilla.org/2010/11/firefox-4-font-feature-support/",
"title": "Mozilla hacks article"
}, {
"url": "http://html5accessibility.com/",
"title": "Detailed tables on accessability support"
}, {
"url": "http://ie.microsoft.com/testdrive/Graphics/opentype/",
"title": "Demo pages (IE/Firefox only)"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "a x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "a",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y x"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Partial support in older Firefox versions refers to using an older syntax. Partial support in older Chrome versions refers to lacking support in Mac OS X. ",
"usage_perc_y": 62.13,
"usage_perc_a": 6.41,
"ucprefix": false,
"parent": "",
"keywords": "font-feature,font-feature-settings,kern,kerning,font-variant-alternates,ligatures,font-variant-ligatures"
},
"css-animation": {
"title": "CSS3 Animation",
"description": "Complex method of animating certain properties of an element",
"spec": "http://www.w3.org/TR/css3-animations/",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/properties/animations",
"title": "WebPlatform Docs"
}, {
"url": "http://www.css3files.com/animation/",
"title": "Information page"
}, {
"url": "http://robertnyman.com/2010/05/06/css3-animations/",
"title": "Blog post on usage"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y x",
"5": "y x",
"5.1": "y x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "y x",
"12.1": "y",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "y x",
"4.0-4.1": "y x",
"4.2-4.3": "y x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a x",
"2.2": "a x",
"2.3": "a x",
"3": "a x",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y x"
},
"bb": {
"7": "y x",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "y",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support in Android browser refers to buggy behavior in different scenarios.",
"usage_perc_y": 73.62,
"usage_perc_a": 1.44,
"ucprefix": false,
"parent": "",
"keywords": "animations,css-animations,keyframe,keyframes"
},
"css-gradients": {
"title": "CSS Gradients",
"description": "Method of defining a linear or radial color gradient as a CSS image.",
"spec": "http://www.w3.org/TR/css3-images/",
"status": "cr",
"links": [{
"url": "http://www.colorzilla.com/gradient-editor/",
"title": "Cross-browser editor"
}, {
"url": "http://docs.webplatform.org/wiki/css/functions/linear-gradient",
"title": "WebPlatform Docs"
}, {
"url": "http://www.css3files.com/gradient/",
"title": "Information page"
}, {
"url": "http://css3pie.com/",
"title": "Tool to emulate support in IE"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "y x",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "a x",
"5": "a x",
"5.1": "y x",
"6": "y x",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "a x",
"11.5": "a x",
"11.6": "y x",
"12": "y x",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a x",
"4.0-4.1": "a x",
"4.2-4.3": "a x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a x",
"2.2": "a x",
"2.3": "a x",
"3": "a x",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y"
},
"bb": {
"7": "a x",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "a x",
"11.5": "a x",
"12": "y x",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support in Opera 11.10 and 11.50 also refers to only having support for linear gradients. Support can be somewhat emulated in older IE versions using the non-standard \"gradient\" filter. Firefox 10+, Opera 11.6+, Chrome 26+ and IE10 also support the new \"to (side)\" syntax.",
"usage_perc_y": 73.31,
"usage_perc_a": 2.22,
"ucprefix": false,
"parent": "",
"keywords": "linear,linear-gradient,gradiant"
},
"css-canvas": {
"title": "CSS Canvas Drawings",
"description": "Method of using HTML5 Canvas as a background image",
"spec": "http://webkit.org/blog/176/css-canvas-drawing/",
"status": "unoff",
"links": [{
"url": "http://webkit.org/blog/176/css-canvas-drawing/",
"title": "Webkit blog post"
}],
"categories": ["CSS"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "u",
"27": "u"
},
"chrome": {
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y x",
"5": "y x",
"5.1": "y x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "y x",
"4.0-4.1": "y x",
"4.2-4.3": "y x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y x",
"2.2": "y x",
"2.3": "y x",
"3": "y x",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y x"
},
"bb": {
"7": "y x",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Proposal by Webkit, being considered for W3C standardization. A similar effect can be achieved in Firefox 4+ using the -moz-element() background property",
"usage_perc_y": 48.41,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"css-reflections": {
"title": "CSS Reflections",
"description": "Method of displaying a reflection of an element",
"spec": "http://webkit.org/blog/182/css-reflections/",
"status": "unoff",
"links": [{
"url": "http://webkit.org/blog/182/css-reflections/",
"title": "Webkit blog post"
}],
"categories": ["CSS"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y x",
"5": "y x",
"5.1": "y x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "y x",
"4.0-4.1": "y x",
"4.2-4.3": "y x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y x",
"2.2": "y x",
"2.3": "y x",
"3": "y x",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y x"
},
"bb": {
"7": "y x",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Similar effect can be achieved in Firefox 4+ using the -moz-element() background property",
"usage_perc_y": 48.41,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "box-reflect"
},
"css-masks": {
"title": "CSS Masks",
"description": "Method of displaying part of an element, using a selected image as a mask",
"spec": "http://www.w3.org/TR/css-masking/",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/properties/mask",
"title": "WebPlatform Docs"
}, {
"url": "http://www.html5rocks.com/en/tutorials/masking/adobe/",
"title": "HTML5 Rocks article"
}, {
"url": "http://thenittygritty.co/css-masking",
"title": "Detailed blog post"
}],
"categories": ["CSS"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "u",
"27": "u"
},
"chrome": {
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "a x",
"21": "a x",
"22": "a x",
"23": "a x",
"24": "a x",
"25": "a x",
"26": "a x",
"27": "a x",
"28": "a x",
"29": "a x",
"30": "a x",
"31": "a x",
"32": "a x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "a x",
"5": "a x",
"5.1": "a x",
"6": "a x",
"6.1": "a x",
"7": "a x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x"
},
"ios_saf": {
"3.2": "a x",
"4.0-4.1": "a x",
"4.2-4.3": "a x",
"5.0-5.1": "a x",
"6.0-6.1": "a x",
"7.0": "a x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a x",
"2.2": "a x",
"2.3": "a x",
"3": "a x",
"4": "a x",
"4.1": "a x",
"4.2-4.3": "a x",
"4.4": "a x"
},
"bb": {
"7": "a x",
"10": "a x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "a x"
},
"and_chr": {
"0": "a x"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Previously a WebKit-only property, now a W3C specification. Partial support refers to not yet fully supporting the new spec (details currently unknown).",
"usage_perc_y": 0,
"usage_perc_a": 48.41,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"svg": {
"title": "SVG (basic support)",
"description": "Method of displaying basic Vector Graphics features using the embed or object elements",
"spec": "http://www.w3.org/Graphics/SVG/",
"status": "rec",
"links": [{
"url": "http://en.wikipedia.org/wiki/Scalable_Vector_Graphics",
"title": "Wikipedia"
}, {
"url": "http://code.google.com/p/svgweb/",
"title": "SVG Web: Flash-based polyfill"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/graphics.js#svg",
"title": "has.js test"
}, {
"url": "http://svg-edit.googlecode.com",
"title": "Web-based SVG editor"
}, {
"url": "http://www.alistapart.com/articles/using-svg-for-flexible-scalable-and-fun-backgrounds-part-i",
"title": "A List Apart article"
}, {
"url": "http://svg-wow.org/",
"title": "SVG showcase site"
}],
"categories": ["SVG"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "a",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 84.1,
"usage_perc_a": 0.02,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"svg-css": {
"title": "SVG in CSS backgrounds",
"description": "Method of using SVG images as CSS backgrounds",
"spec": "http://www.w3.org/TR/css3-background/#background-image",
"status": "cr",
"links": [{
"url": "http://designfestival.com/a-farewell-to-css3-gradients/",
"title": "Tutorial for advanced effects"
}],
"categories": ["SVG", "CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "a",
"4": "a",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"12": "a",
"12.1": "a",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support in older Firefox and Opera Mini/Mobile refers to SVG images being blurry when scaled. Partial support in iOS Safari and older Safari versions refers to failing to support tiling or the background-position property.",
"usage_perc_y": 75.45,
"usage_perc_a": 8.2,
"ucprefix": false,
"parent": "",
"keywords": "svg-in-css,svgincss,css-svg"
},
"svg-smil": {
"title": "SVG SMIL animation",
"description": "Method of using animation elements to animate SVG images",
"spec": "http://www.w3.org/TR/SVG/animate.html",
"status": "rec",
"links": [{
"url": "https://github.com/madsgraphics/SVGEventListener",
"title": "Polyfill for SMIL animate events on SVG"
}, {
"url": "https://developer.mozilla.org/en/SVG/SVG_animation_with_SMIL",
"title": "MDN article"
}, {
"url": "http://svg-wow.org/blog/category/animation/",
"title": "Examples on SVG WOW"
}, {
"url": "http://leunen.me/fakesmile/",
"title": "JS library to support SMIL in SVG"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/graphics.js#svg-smil",
"title": "has.js test"
}],
"categories": ["SVG"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "p",
"3.6": "p",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "a",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "p"
}
},
"notes": "Partial support in Safari refers to not working in HTML files.",
"usage_perc_y": 54.76,
"usage_perc_a": 7.99,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"svg-fonts": {
"title": "SVG fonts",
"description": "Method of using fonts defined as SVG shapes",
"spec": "http://www.w3.org/TR/SVG/fonts.html",
"status": "rec",
"links": [{
"url": "http://opentype.info/blog/2010/04/13/the-ipad-and-svg-fonts-in-mobile-safari/",
"title": "Blog post on usage for iPad"
}, {
"url": "http://jeremie.patonnier.net/post/2011/02/07/Why-are-SVG-Fonts-so-different",
"title": "Blog post"
}],
"categories": ["SVG"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Supported in Opera Mini in SVG images only, not in HTML.",
"usage_perc_y": 47.78,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "fontface",
"keywords": ""
},
"svg-filters": {
"title": "SVG filters",
"description": "Method of using photoshop-like effects on SVG objects including blurring and color manipulation.",
"spec": "http://www.w3.org/TR/SVG/filters.html",
"status": "rec",
"links": [{
"url": "http://electricbeach.org/?p=950",
"title": "Experiments with filter effects"
}, {
"url": "http://svg-wow.org/blog/category/filters/",
"title": "SVG filter demos"
}, {
"url": "http://docs.webplatform.org/wiki/svg/elements/filter",
"title": "WebPlatform Docs"
}],
"categories": ["SVG"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "a",
"6": "a",
"7": "a",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 72.99,
"usage_perc_a": 0.08,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"svg-html": {
"title": "SVG effects for HTML",
"description": "Method of using SVG transforms, filters, etc on HTML elements using either CSS or the foreignObject element",
"spec": "http://www.w3.org/TR/SVG11/extend.html#ForeignObjectElement",
"status": "wd",
"links": [{
"url": "https://developer.mozilla.org/En/Applying_SVG_effects_to_HTML_content",
"title": "MDN Reference page"
}, {
"url": "https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html",
"title": "Filter Effects draft"
}, {
"url": "https://developer.mozilla.org/en/SVG/Tutorial/Other_content_in_SVG",
"title": "MDN Tutorial"
}],
"categories": ["SVG"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "a",
"10": "a",
"11": "a"
},
"firefox": {
"2": "n",
"3": "a",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a",
"28": "a",
"29": "a",
"30": "a",
"31": "a",
"32": "a"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "a",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "a",
"9.5-9.6": "a",
"10.0-10.1": "a",
"10.5": "a",
"10.6": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"11.6": "a",
"12": "a",
"12.1": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "a"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"12": "a",
"12.1": "a",
"0": "a"
},
"and_chr": {
"0": "a"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Partial support refers to lack of filter support or buggy result from effects. A <a href=\"https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html\">CSS Filter Effects</a> specification is in the works that would replace this method.",
"usage_perc_y": 15.33,
"usage_perc_a": 60.21,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"svg-html5": {
"title": "Inline SVG in HTML5",
"description": "Method of using SVG tags directly in HTML documents. Requires HTML5 parser.",
"spec": "http://www.w3.org/TR/html5/embedded-content-0.html#svg-0",
"status": "cr",
"links": [{
"url": "http://hacks.mozilla.org/2010/05/firefox-4-the-html5-parser-inline-svg-speed-and-more/",
"title": "Mozilla Hacks blog post"
}, {
"url": "http://samples.msdn.microsoft.com/ietestcenter/html5/svghtml_harness.htm?url=SVG_HTML_Elements_001",
"title": "Test suite"
}],
"categories": ["SVG", "HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "p",
"3.6": "p",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "p",
"5": "p",
"6": "p",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "p",
"5": "p",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "p",
"9.5-9.6": "p",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "p",
"4.0-4.1": "p",
"4.2-4.3": "p",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 78.45,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"canvas": {
"title": "Canvas (basic support)",
"description": "Method of generating fast, dynamic graphics using JavaScript",
"spec": "http://www.w3.org/TR/html5/embedded-content-0.html#the-canvas-element",
"status": "cr",
"links": [{
"url": "https://developer.mozilla.org/en/Canvas_tutorial",
"title": "Tutorial by Mozilla"
}, {
"url": "http://explorercanvas.googlecode.com/",
"title": "Implementation for Internet Explorer"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/graphics.js#canvas",
"title": "has.js test"
}, {
"url": "http://www.diveinto.org/html5/canvas.html",
"title": "Another tutorial"
}, {
"url": "http://glimr.rubyforge.org/cake/canvas.html",
"title": "Animation kit "
}, {
"url": "http://www.canvasdemos.com/",
"title": "Showcase site"
}],
"categories": ["Canvas", "HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "a",
"2.2": "a",
"2.3": "a",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Opera Mini supports the canvas element, but is unable to play animations or run other more complex applications. Android 2.x supports canvas except the toDataURL() function. See http://code.google.com/p/android/issues/detail?id=7901 Some (slow) workarounds are described here: http://stackoverflow.com/q/10488033/841830",
"usage_perc_y": 79.53,
"usage_perc_a": 6.02,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"canvas-text": {
"title": "Text API for Canvas",
"description": "Method of displaying text on Canvas elements",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-0",
"status": "wd",
"links": [{
"url": "http://code.google.com/p/canvas-text/",
"title": "Support library"
}, {
"url": "http://docs.webplatform.org/wiki/apis/canvas/CanvasRenderingContext2D/fillText",
"title": "WebPlatform Docs"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/graphics.js#canvas-text",
"title": "has.js test"
}, {
"url": "https://developer.mozilla.org/en/Drawing_text_using_a_canvas#Additional_examples",
"title": "Examples by Mozilla"
}],
"categories": ["Canvas", "HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "p",
"9.5-9.6": "p",
"10.0-10.1": "p",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "p",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 80.82,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "canvas",
"keywords": ""
},
"namevalue-storage": {
"title": "Web Storage - name/value pairs",
"description": "Method of storing data locally like cookies, but for larger amounts of data (sessionStorage and localStorage, used to fall under HTML5).",
"spec": "http://www.w3.org/TR/webstorage/#storage",
"status": "rec",
"links": [{
"url": "http://html5demos.com/storage",
"title": "Simple demo"
}, {
"url": "http://docs.webplatform.org/wiki/apis/web-storage/Storage/localStorage",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/En/DOM/Storage",
"title": "Gecko reference"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-localstorage;native-sessionstorage",
"title": "has.js test"
}, {
"url": "http://code.google.com/p/sessionstorage/",
"title": "Support library"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "a",
"3": "a",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "In private browsing mode Safari and iOS Safari don't support setting localStorage.",
"usage_perc_y": 89.13,
"usage_perc_a": 0.1,
"ucprefix": false,
"parent": "",
"keywords": "webstorage,local storage"
},
"sql-storage": {
"title": "Web SQL Database",
"description": "Method of storing data client-side, allows Sqlite database queries for access and manipulation",
"spec": "http://www.w3.org/TR/webdatabase/",
"status": "unoff",
"links": [{
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-sql-db",
"title": "has.js test"
}, {
"url": "http://html5doctor.com/introducing-web-sql-databases/",
"title": "HTML5 Doctor article"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "The Web SQL Database specification is no longer being maintained and support may be dropped in future versions.",
"usage_perc_y": 49.18,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "db-storage,websql"
},
"indexeddb": {
"title": "IndexedDB",
"description": "Method of storing data client-side, allows indexed database queries. Previously known as WebSimpleDB API.",
"spec": "http://www.w3.org/TR/IndexedDB/",
"status": "wd",
"links": [{
"url": "http://hacks.mozilla.org/2010/06/comparing-indexeddb-and-webdatabase/",
"title": "Mozilla Hacks article"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-indexeddb",
"title": "has.js test"
}, {
"url": "http://docs.webplatform.org/wiki/apis/indexedDB",
"title": "WebPlatform Docs"
}, {
"url": "https://github.com/axemclion/IndexedDBShim",
"title": "Polyfill for browsers supporting WebSQL"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "a x",
"21": "a x",
"22": "a x",
"23": "y x",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "a x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support in BB10 refers to an <a href=\"http://www.w3.org/TR/2011/WD-IndexedDB-20110419/\">outdated specification</a> being implemented. Code targeting the <a href=\"http://www.w3.org/TR/IndexedDB/\">current state of the specification</a> might not work.",
"usage_perc_y": 59.46,
"usage_perc_a": 1.68,
"ucprefix": false,
"parent": "",
"keywords": "indexdb"
},
"eventsource": {
"title": "Server-sent DOM events",
"description": "Method of continuously sending data from a server to the browser, rather than repeatedly requesting it (EventSource interface, used to fall under HTML5)",
"spec": "http://www.w3.org/TR/eventsource/",
"status": "cr",
"links": [{
"url": "http://www.html5rocks.com/tutorials/eventsource/basics/",
"title": "HTML5 Rocks tutorial"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-eventsource",
"title": "has.js test"
}, {
"url": "http://samshull.blogspot.com/2010/10/ajax-push-in-ios-safari-and-chrome-with.html",
"title": "Blog post with demo"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "a",
"9.5-9.6": "a",
"10.0-10.1": "a",
"10.5": "a",
"10.6": "a",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "a",
"11": "a",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 58.8,
"usage_perc_a": 0.06,
"ucprefix": false,
"parent": "",
"keywords": "serversent,s-sent-events"
},
"x-doc-messaging": {
"title": "Cross-document messaging",
"description": "Method of sending information from a page on one domain to a page on a different one (using postMessage)",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages",
"status": "wd",
"links": [{
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-crosswindowmessaging",
"title": "has.js test"
}, {
"url": "http://html5demos.com/postmessage2",
"title": "Simple demo"
}, {
"url": "https://developer.mozilla.org/en/DOM/window.postMessage",
"title": "MDN article"
}, {
"url": "http://docs.webplatform.org/wiki/apis/web-messaging/methods/postMessage_%28window%29",
"title": "WebPlatform Docs"
}, {
"url": "http://72lions.com/2011/05/cross-origin-communication-with-html5",
"title": "Article and demo"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "a",
"9": "a",
"10": "a",
"11": "y"
},
"firefox": {
"2": "n",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "a"
}
},
"notes": "Partial support in IE8-9 refers to only working in frames/iframes (not other tabs/windows). Also in IE 9 and below an object cannot be sent using postMessage. Partial support in IE10 refers to <a href=\"http://stackoverflow.com/questions/16226924/is-cross-origin-postmessage-broken-in-ie10\">limitations in certain conditions</a>",
"usage_perc_y": 69.31,
"usage_perc_a": 24.52,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"datauri": {
"title": "Data URIs",
"description": "Method of embedding images and other files in webpages as a string of text",
"spec": "http://www.ietf.org/rfc/rfc2397.txt",
"status": "other",
"links": [{
"url": "http://www.websiteoptimization.com/speed/tweak/inline-images/",
"title": "Data URL converter"
}, {
"url": "http://css-tricks.com/5970-data-uris/",
"title": "Information page"
}, {
"url": "http://en.wikipedia.org/wiki/data_URI_scheme",
"title": "Wikipedia"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "a",
"9": "a",
"10": "a",
"11": "a"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "a"
}
},
"notes": "Support in Internet Explorer 8 is limited to images and linked resources like CSS files, not HTML files. Max URI length in IE8 is 32KB. In IE9+ JavaScript files are supported too and the maximum size limit set to 4GB.",
"usage_perc_y": 69.23,
"usage_perc_a": 24.63,
"ucprefix": false,
"parent": "",
"keywords": "data url,datauris,data uri,dataurl,dataurls"
},
"mathml": {
"title": "MathML",
"description": "An XML language that allows mathematical formulas and notations to be written on web pages.",
"spec": "http://www.w3.org/TR/MathML/",
"status": "rec",
"links": [{
"url": "http://www.mozilla.org/projects/mathml/demo/",
"title": "MathML demos"
}, {
"url": "http://en.wikipedia.org/wiki/MathML",
"title": "Wikipedia"
}, {
"url": "http://www.mathjax.org",
"title": "Cross-browser support script"
}, {
"url": "https://developer.mozilla.org/en/MathML/Element",
"title": "MDN element reference"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "p",
"5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p",
"12": "p",
"13": "p",
"14": "p",
"15": "p",
"16": "p",
"17": "p",
"18": "p",
"19": "p",
"20": "p",
"21": "p",
"22": "p",
"23": "p",
"24": "y",
"25": "p",
"26": "p",
"27": "p",
"28": "p",
"29": "p",
"30": "p",
"31": "p",
"32": "p"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "p",
"5": "p",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "a",
"10.0-10.1": "a",
"10.5": "a",
"10.6": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"11.6": "a",
"12": "a",
"12.1": "a",
"15": "p",
"16": "p",
"17": "p",
"18": "p"
},
"ios_saf": {
"3.2": "p",
"4.0-4.1": "p",
"4.2-4.3": "p",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "p"
},
"android": {
"2.1": "p",
"2.2": "p",
"2.3": "p",
"3": "p",
"4": "p",
"4.1": "p",
"4.2-4.3": "p",
"4.4": "p"
},
"bb": {
"7": "p",
"10": "y"
},
"op_mob": {
"10": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"12": "p",
"12.1": "p",
"0": "p"
},
"and_chr": {
"0": "p"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Opera's support is limited to a CSS profile of MathML. Support was added in Chrome 24, but removed afterwards due to instability.",
"usage_perc_y": 23.15,
"usage_perc_a": 0.63,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"css-featurequeries": {
"title": "CSS Feature Queries",
"description": "CSS Feature Queries allow authors to condition rules based on whether particular property declarations are supported in CSS using the @supports at rule.",
"spec": "http://www.w3.org/TR/css3-conditional/#at-supports",
"status": "cr",
"links": [{
"url": "http://dabblet.com/gist/3895764",
"title": "Test case"
}, {
"url": "http://mcc.id.au/blog/2012/08/supports",
"title": "@supports in Firefox"
}, {
"url": "https://developer.mozilla.org/en-US/docs/Web/CSS/@supports",
"title": "MDN Article"
}, {
"url": "http://docs.webplatform.org/wiki/css/atrules/@supports",
"title": "WebPlatform Docs"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 45.52,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "supports,conditional"
},
"xhtml": {
"title": "XHTML served as application/xhtml+xml",
"description": "A strict form of HTML, and allows embedding of other XML languages",
"spec": "http://www.w3.org/TR/xhtml1/",
"status": "rec",
"links": [{
"url": "http://en.wikipedia.org/wiki/XHTML",
"title": "Wikipedia"
}, {
"url": "http://docs.webplatform.org/wiki/concepts/internet_and_web/the_web_standards_model#What_is_XHTML.3F",
"title": "WebPlatform Docs"
}, {
"url": "http://www.xmlplease.com/xhtml/xhtml5polyglot/",
"title": "Information on XHTML5"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "The XHTML syntax is very close to HTML, and thus is almost always (<a href=\"https://developer.mozilla.org/en-US/docs/XHTML#MIME_type_versus_DOCTYPE\">incorrectly</a>) served as text/html on the web.",
"usage_perc_y": 85.55,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "xhtml+xml"
},
"xhtmlsmil": {
"title": "XHTML+SMIL animation",
"description": "Method of using SMIL animation in web pages",
"spec": "http://www.w3.org/TR/XHTMLplusSMIL/",
"status": "unoff",
"links": [{
"url": "http://en.wikipedia.org/wiki/XHTML%2BSMIL",
"title": "Wikipedia"
}, {
"url": "http://leunen.me/fakesmile/",
"title": "JS library to support XHTML+SMIL"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "a",
"7": "a",
"8": "a",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "p",
"3.6": "p",
"4": "p",
"5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p",
"12": "p",
"13": "p",
"14": "p",
"15": "p",
"16": "p",
"17": "p",
"18": "p",
"19": "p",
"20": "p",
"21": "p",
"22": "p",
"23": "p",
"24": "p",
"25": "p",
"26": "p",
"27": "p"
},
"chrome": {
"4": "p",
"5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p",
"12": "p",
"13": "p",
"14": "p",
"15": "p",
"16": "p",
"17": "p",
"18": "p",
"19": "p",
"20": "p",
"21": "p",
"22": "p",
"23": "p",
"24": "p",
"25": "p",
"26": "p",
"27": "p",
"28": "p",
"29": "p",
"30": "p",
"31": "p",
"32": "p"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "p",
"5": "p",
"5.1": "p",
"6": "p",
"6.1": "p",
"7": "p"
},
"opera": {
"9": "p",
"9.5-9.6": "p",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"11.6": "p",
"12": "p",
"12.1": "p",
"15": "p",
"16": "p",
"17": "p",
"18": "p"
},
"ios_saf": {
"3.2": "p",
"4.0-4.1": "p",
"4.2-4.3": "p",
"5.0-5.1": "p",
"6.0-6.1": "p",
"7.0": "p"
},
"op_mini": {
"5.0-7.0": "p"
},
"android": {
"2.1": "p",
"2.2": "p",
"2.3": "p",
"3": "p",
"4": "p",
"4.1": "p",
"4.2-4.3": "p",
"4.4": "p"
},
"bb": {
"7": "p",
"10": "p"
},
"op_mob": {
"10": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"12": "p",
"12.1": "p",
"0": "p"
},
"and_chr": {
"0": "p"
},
"and_ff": {
"0": "p"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Internet Explorer supports the W3C proposal HTML+TIME, which is largely the same as XHTML+SMIL",
"usage_perc_y": 0,
"usage_perc_a": 9.02,
"ucprefix": false,
"parent": "xhtml",
"keywords": ""
},
"wai-aria": {
"title": "WAI-ARIA Accessibility features",
"description": "Method of providing ways for people with disabilities to use dynamic web content and web applications.",
"spec": "http://www.w3.org/TR/wai-aria/",
"status": "cr",
"links": [{
"url": "http://www.alistapart.com/articles/the-accessibility-of-wai-aria/",
"title": "ALA Article"
}, {
"url": "http://en.wikipedia.org/wiki/WAI-ARIA",
"title": "Wikipedia"
}, {
"url": "http://zufelt.ca/blog/are-you-confused-html5-and-wai-aria-yet",
"title": "HTML5/WAI-ARIA information"
}, {
"url": "http://www.w3.org/WAI/intro/aria",
"title": "Information page"
}, {
"url": "http://www.paciellogroup.com/blog/2011/10/browser-assistive-technology-tests-redux/",
"title": "Links to various test results"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "a",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a",
"28": "a",
"29": "a",
"30": "a",
"31": "a",
"32": "a"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "a",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "n",
"9.5-9.6": "a",
"10.0-10.1": "a",
"10.5": "a",
"10.6": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"11.6": "a",
"12": "a",
"12.1": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "a"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"12": "a",
"12.1": "a",
"0": "a"
},
"and_chr": {
"0": "a"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 40.05,
"usage_perc_a": 48.6,
"ucprefix": false,
"parent": "",
"keywords": "wai,aria"
},
"geolocation": {
"title": "Geolocation",
"description": "Method of informing a website of the user's geographical location",
"spec": "http://www.w3.org/TR/geolocation-API/",
"status": "cr",
"links": [{
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-geolocation",
"title": "has.js test"
}, {
"url": "http://docs.webplatform.org/wiki/apis/geolocation",
"title": "WebPlatform Docs"
}, {
"url": "http://html5demos.com/geo",
"title": "Simple demo"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "p",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "n",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "p",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 80.65,
"usage_perc_a": 0.02,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"flexbox": {
"title": "Flexible Box Layout Module",
"description": "Method of positioning elements in horizontal or vertical stacks.",
"spec": "http://www.w3.org/TR/css3-flexbox/",
"status": "cr",
"links": [{
"url": "http://css-tricks.com/snippets/css/a-guide-to-flexbox/",
"title": "A Complete Guide to Flexbox"
}, {
"url": "http://bennettfeely.com/flexplorer/",
"title": "Flexbox CSS generator"
}, {
"url": "http://www.adobe.com/devnet/html5/articles/working-with-flexbox-the-new-spec.html",
"title": "Article on using the latest spec"
}, {
"url": "http://philipwalton.github.io/solved-by-flexbox/",
"title": "Examples on how to solve common layout problems with flexbox"
}, {
"url": "http://dev.opera.com/articles/view/advanced-cross-browser-flexbox/",
"title": "Tutorial on cross-browser support"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "a x #2",
"11": "y"
},
"firefox": {
"2": "a x #1",
"3": "a x #1",
"3.5": "a x #1",
"3.6": "a x #1",
"4": "a x #1",
"5": "a x #1",
"6": "a x #1",
"7": "a x #1",
"8": "a x #1",
"9": "a x #1",
"10": "a x #1",
"11": "a x #1",
"12": "a x #1",
"13": "a x #1",
"14": "a x #1",
"15": "a x #1",
"16": "a x #1",
"17": "a x #1",
"18": "a x #1",
"19": "a x #1",
"20": "a x #1",
"21": "a x #1",
"22": "a #3",
"23": "a #3",
"24": "a #3",
"25": "a #3",
"26": "a #3",
"27": "a #3"
},
"chrome": {
"4": "a x #1",
"5": "a x #1",
"6": "a x #1",
"7": "a x #1",
"8": "a x #1",
"9": "a x #1",
"10": "a x #1",
"11": "a x #1",
"12": "a x #1",
"13": "a x #1",
"14": "a x #1",
"15": "a x #1",
"16": "a x #1",
"17": "a x #1",
"18": "a x #1",
"19": "a x #1",
"20": "a x #1",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a x #1",
"3.2": "a x #1",
"4": "a x #1",
"5": "a x #1",
"5.1": "a x #1",
"6": "a x #1",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "y",
"15": "y x",
"16": "y x",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a x #1",
"4.0-4.1": "a x #1",
"4.2-4.3": "a x #1",
"5.0-5.1": "a x #1",
"6.0-6.1": "a x #1",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a x #1",
"2.2": "a x #1",
"2.3": "a x #1",
"3": "a x #1",
"4": "a x #1",
"4.1": "a x #1",
"4.2-4.3": "a x #1",
"4.4": "y"
},
"bb": {
"7": "a x #1",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "a x #1"
},
"ie_mob": {
"10": "a x #2"
}
},
"notes": "Most partial support refers to supporting an <a href=\"http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/\">older version</a> of the specification or an <a href=\"http://www.w3.org/TR/2012/WD-css3-flexbox-20120322/\">older syntax</a>. For Firefox 21+ it refers to lack of flex-wrap & flex-flow support.",
"usage_perc_y": 37.88,
"usage_perc_a": 37.66,
"ucprefix": false,
"parent": "",
"keywords": "flex"
},
"webgl": {
"title": "WebGL - 3D Canvas graphics",
"description": "Method of generating dynamic 3D graphics using JavaScript, accelerated through hardware",
"spec": "https://www.khronos.org/registry/webgl/specs/1.0/",
"status": "other",
"links": [{
"url": "http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation",
"title": "Instructions on enabling WebGL"
}, {
"url": "http://webkit.org/blog/603/webgl-now-available-in-webkit-nightlies/",
"title": "Webkit blog post"
}, {
"url": "http://www.khronos.org/webgl/wiki/Tutorial",
"title": "Tutorial"
}, {
"url": "http://hacks.mozilla.org/2009/12/webgl-draft-released-today/",
"title": "Firefox blog post"
}, {
"url": "http://iewebgl.com/",
"title": "Polyfill for IE"
}],
"categories": ["Canvas"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "a",
"12.1": "a",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "a",
"12.1": "a",
"0": "y"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "p"
}
},
"notes": "Support listed as \"partial\" refers to the fact that not all users with these browsers have WebGL access. This is due to the additional requirement for users to have <a href=\"http://www.khronos.org/webgl/wiki/BlacklistsAndWhitelists\">up to date video drivers</a>. This problem was <a href=\"http://blog.chromium.org/2012/02/gpu-accelerating-2d-canvas-and-enabling.html\">solved in Chrome</a> as of version 18.\r\n\r\nNote that WebGL is part of the <a href=\"http://www.khronos.org/webgl/\">Khronos Group</a>, not the W3C. On Chrome for Android, WebGL is disabled by default, but can be enabled by enabling the \"Enable WebGL\" flag under chrome://flags",
"usage_perc_y": 33.4,
"usage_perc_a": 19.68,
"ucprefix": false,
"parent": "canvas",
"keywords": "web gl"
},
"fileapi": {
"title": "File API",
"description": "Method of manipulating file objects in web applications client-side, as well as programmatically selecting them and accessing their data.",
"spec": "http://www.w3.org/TR/FileAPI/",
"status": "wd",
"links": [{
"url": "https://developer.mozilla.org/en/Using_files_from_web_applications",
"title": "MDN article"
}, {
"url": "http://docs.webplatform.org/wiki/apis/file",
"title": "WebPlatform Docs"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "a",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "a",
"4": "a",
"4.1": "a",
"4.2-4.3": "a",
"4.4": "y"
},
"bb": {
"7": "a",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Partial support in older Safari refers to lacking FileReader support. ",
"usage_perc_y": 67.73,
"usage_perc_a": 5.38,
"ucprefix": false,
"parent": "",
"keywords": "FileReader"
},
"shadowdom": {
"title": "Shadow DOM",
"description": "Method of establishing and maintaining functional boundaries between DOM trees and how these trees interact with each other within a document, thus enabling better functional encapsulation within the DOM.",
"spec": "http://www.w3.org/TR/shadow-dom/",
"status": "wd",
"links": [{
"url": "http://www.html5rocks.com/tutorials/webcomponents/shadowdom/",
"title": "HTML5Rocks - Shadow DOM 101 article"
}, {
"url": "http://html5-demos.appspot.com/static/shadowdom-visualizer/index.html",
"title": "Shadow DOM Visualizer"
}],
"categories": ["DOM", "HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "y x",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y x"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 33.29,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "web components"
},
"websockets": {
"title": "Web Sockets",
"description": "Bidirectional communication technology for web apps",
"spec": "http://www.w3.org/TR/websockets/",
"status": "cr",
"links": [{
"url": "http://docs.webplatform.org/wiki/apis/websocket",
"title": "WebPlatform Docs"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-websockets",
"title": "has.js test"
}, {
"url": "http://websocket.org/aboutwebsocket.html",
"title": "WebSockets information"
}, {
"url": "http://en.wikipedia.org/wiki/WebSocket",
"title": "Wikipedia"
}, {
"url": "http://updates.html5rocks.com/2011/08/What-s-different-in-the-new-WebSocket-protocol",
"title": "Details on newer protocol"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "a",
"5": "a",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "a",
"5.1": "a",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "a",
"11.1": "a",
"11.5": "a",
"11.6": "a",
"12": "a",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "a",
"5.0-5.1": "a",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "a",
"11.1": "a",
"11.5": "a",
"12": "a",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support refers to the websockets implementation using an older version of the protocol and/or the implementation being disabled by default (due to security issues with the older protocol).",
"usage_perc_y": 67.46,
"usage_perc_a": 2.62,
"ucprefix": true,
"parent": "",
"keywords": ""
},
"script-async": {
"title": "async attribute for external scripts",
"description": "The boolean async attribute on script elements allows the external JavaScript file to run when it's available, without delaying page load first.",
"spec": "http://www.w3.org/TR/html5/scripting-1.html#attr-script-async",
"status": "cr",
"links": [{
"url": "https://developer.mozilla.org/en/HTML/Element/script#Attributes",
"title": "MDN article"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/script.js#script-async",
"title": "has.js test"
}, {
"url": "http://ie.microsoft.com/testdrive/Performance/AsyncScripts/Default.html",
"title": "Demo"
}],
"categories": ["HTML5", "DOM"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "a",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Using script.async = false; to maintain execution order for dynamically-added scripts isn't supported in Safari 5.0",
"usage_perc_y": 72.82,
"usage_perc_a": 0.31,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"cors": {
"title": "Cross-Origin Resource Sharing",
"description": "Method of performing XMLHttpRequests across domains",
"spec": "http://www.w3.org/TR/cors/",
"status": "cr",
"links": [{
"url": "http://saltybeagle.com/2009/09/cross-origin-resource-sharing-demo/",
"title": "Demo and script with cross-browser support"
}, {
"url": "http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/",
"title": "Mozilla Hacks blog post"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-cors-xhr",
"title": "has.js test"
}, {
"url": "http://msdn.microsoft.com/en-us/library/cc288060(VS.85).aspx",
"title": "Alternative implementation by IE8"
}, {
"url": "http://dev.opera.com/articles/view/dom-access-control-using-cross-origin-resource-sharing/",
"title": "DOM access using CORS"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "a",
"9": "a",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Supported somewhat in IE8 and IE9 using the XDomainRequest object (but has <a href=\" http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx\">limitations</a>)",
"usage_perc_y": 75.51,
"usage_perc_a": 13.52,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"calc": {
"title": "calc() as CSS unit value",
"description": "Method of allowing calculated values for length units, i.e. width: calc(100% - 3em)",
"spec": "http://www.w3.org/TR/css3-values/#calc",
"status": "cr",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/functions/calc",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/en/CSS/-moz-calc",
"title": "MDN article"
}, {
"url": "http://hacks.mozilla.org/2010/06/css3-calc/",
"title": "Mozilla Hacks article"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y x",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y x",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Support can be somewhat emulated in older versions of IE using the non-standard expression() syntax. ",
"usage_perc_y": 71.77,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"ruby": {
"title": "Ruby annotation",
"description": "Method of adding pronunciation or other annotations using ruby elements (primarily used in East Asian typography)",
"spec": "http://www.w3.org/TR/html-markup/ruby.html",
"status": "wd",
"links": [{
"url": "https://addons.mozilla.org/firefox/addon/6812/",
"title": "Addon \"HTML Ruby\" for Firefox support"
}, {
"url": "http://html5doctor.com/ruby-rt-rp-element/",
"title": "HTML5 Doctor article"
}, {
"url": "http://docs.webplatform.org/wiki/html/elements/ruby",
"title": "WebPlatform Docs"
}, {
"url": "https://addons.mozilla.org/firefox/addon/1935/",
"title": "Add-on \"XHTML Ruby Support\" for Firefox"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "p",
"3.6": "p",
"4": "p",
"5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p",
"12": "p",
"13": "p",
"14": "p",
"15": "p",
"16": "p",
"17": "p",
"18": "p",
"19": "p",
"20": "p",
"21": "p",
"22": "p",
"23": "p",
"24": "p",
"25": "p",
"26": "p",
"27": "p"
},
"chrome": {
"4": "p",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a",
"28": "a",
"29": "a",
"30": "a",
"31": "a",
"32": "a"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "p",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "p",
"9.5-9.6": "p",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"11.6": "p",
"12": "p",
"12.1": "p",
"15": "a",
"16": "a",
"17": "a",
"18": "a"
},
"ios_saf": {
"3.2": "p",
"4.0-4.1": "p",
"4.2-4.3": "p",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "p"
},
"android": {
"2.1": "p",
"2.2": "p",
"2.3": "p",
"3": "a",
"4": "a",
"4.1": "a",
"4.2-4.3": "a",
"4.4": "a"
},
"bb": {
"7": "p",
"10": "a"
},
"op_mob": {
"10": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"12": "p",
"12.1": "p",
"0": "a"
},
"and_chr": {
"0": "a"
},
"and_ff": {
"0": "p"
},
"ie_mob": {
"10": "a"
}
},
"notes": "Browsers without native support can still simulate support using CSS. Partial support refers to only supporting basic ruby, may still be missing writing-mode, Complex ruby and CSS3 Ruby",
"usage_perc_y": 0,
"usage_perc_a": 72.03,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"css-opacity": {
"title": "CSS3 Opacity",
"description": "Method of setting the transparency level of an element",
"spec": "http://www.w3.org/TR/css3-color/",
"status": "rec",
"links": [{
"url": "http://www.css3files.com/color/#opacity",
"title": "Information page"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/opacity",
"title": "WebPlatform Docs"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Transparency for elements in IE8 and older can be achieved using the proprietary \"filter\" property and does not work well with PNG images using alpha transparency.",
"usage_perc_y": 85.55,
"usage_perc_a": 9.03,
"ucprefix": false,
"parent": "",
"keywords": "transparent,transparency,alpha"
},
"form-validation": {
"title": "Form validation",
"description": "Method of setting required fields and field types without requiring JavaScript",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#client-side-form-validation",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/html/attributes/required",
"title": "WebPlatform Docs"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "a"
}
},
"notes": "Partial support in Safari refers to lack of notice when form with required fields is attempted to be submitted. Partial support in IE10 mobile refers to lack of warning when blocking submission.",
"usage_perc_y": 61.75,
"usage_perc_a": 4.07,
"ucprefix": false,
"parent": "forms",
"keywords": ""
},
"history": {
"title": "Session history management",
"description": "Method of manipulating the user's browser's session history in JavaScript using history.pushState, history.replaceState and the popstate event",
"spec": "http://www.w3.org/TR/html5/browsers.html#history-1",
"status": "cr",
"links": [{
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-history-state",
"title": "has.js test"
}, {
"url": "https://github.com/browserstate/history.js",
"title": "History.js polyfill "
}, {
"url": "http://docs.webplatform.org/wiki/dom/history",
"title": "WebPlatform Docs"
}, {
"url": "http://html5demos.com/history",
"title": "Demo page"
}, {
"url": "http://www.adequatelygood.com/2010/7/Saner-HTML5-History-Management",
"title": "Introduction to history management"
}, {
"url": "https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history",
"title": "MDN article"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "a",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "y",
"2.3": "y",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Older iOS versions and Android 4.0.4 claim support, but implementation is too buggy to be useful. Partial support in other Safari browsers refers to other buggy behavior.",
"usage_perc_y": 68.29,
"usage_perc_a": 3.89,
"ucprefix": false,
"parent": "",
"keywords": "onpushstate,onreplacestate"
},
"json": {
"title": "JSON parsing",
"description": "Method of converting JavaScript objects to JSON strings and JSON back to objects using JSON.stringify() and JSON.parse()",
"spec": "http://es5.github.com/#x15.12",
"status": "other",
"links": [{
"url": "http://docs.webplatform.org/wiki/apis/json",
"title": "WebPlatform Docs"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/json.js#json",
"title": "has.js test"
}, {
"url": "http://www.json.org/js.html",
"title": "JSON in JS (includes script w/support)"
}, {
"url": "https://developer.mozilla.org/En/Using_native_JSON",
"title": "MDN article"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Requires document to be in IE8+ <a href=\"http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx\">standards mode</a> to work in IE8.",
"usage_perc_y": 93.71,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"classlist": {
"title": "classList (DOMTokenList )",
"description": "Method of easily manipulating classes on elements, using the DOMTokenList object.",
"spec": "http://www.w3.org/TR/dom/#dom-element-classlist",
"status": "wd",
"links": [{
"url": "https://github.com/eligrey/classList.js",
"title": "Polyfill script"
}, {
"url": "http://hacks.mozilla.org/2010/01/classlist-in-firefox-3-6/",
"title": "Mozilla Hacks article"
}, {
"url": "http://docs.webplatform.org/wiki/dom/properties/classList",
"title": "WebPlatform Docs"
}, {
"url": "https://github.com/eligrey/classList.js/pull/12",
"title": "Polyfill script for classList on SVG elements on WebKit"
}],
"categories": ["DOM", "HTML5"],
"stats": {
"ie": {
"5.5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "p",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "p",
"5": "p",
"6": "p",
"7": "p",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "p",
"5": "p",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "p",
"9.5-9.6": "p",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "p",
"11": "p",
"11.1": "p",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "p",
"4.0-4.1": "p",
"4.2-4.3": "p",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "p"
},
"android": {
"2.1": "p",
"2.2": "p",
"2.3": "p",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "p",
"11": "p",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 73.54,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"text-overflow": {
"title": "CSS3 Text-overflow",
"description": "Append ellipsis when text overflows its containing element",
"spec": "http://www.w3.org/TR/css3-ui/#text-overflow0",
"status": "wd",
"links": [{
"url": "http://www.css3files.com/text/",
"title": "Information page"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/css.js#css-text-overflow",
"title": "has.js test"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/text-overflow",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/En/CSS/Text-overflow",
"title": "MDN article"
}, {
"url": "https://github.com/rmorse/AutoEllipsis",
"title": "jQuery polyfill for Firefox"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "p",
"3.6": "p",
"4": "p",
"5": "p",
"6": "p",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y x",
"9.5-9.6": "y x",
"10.0-10.1": "y x",
"10.5": "y x",
"10.6": "y x",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y x"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y x",
"11": "y x",
"11.1": "y x",
"11.5": "y x",
"12": "y x",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 93.95,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "textoverflow,ellipsis"
},
"webm": {
"title": "WebM/VP8 video format",
"description": "Multimedia format designed to provide a royalty-free, high-quality open video compression format for use with HTML5 video.",
"spec": "http://www.webmproject.org/",
"status": "other",
"links": [{
"url": "http://perian.org/",
"title": "Perian :Mac OSX Webm Codec install"
}, {
"url": "https://tools.google.com/dlpage/webmmf",
"title": "Codec for IE9 support"
}, {
"url": "http://webmproject.org",
"title": "Officical website"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/video.js#video-webm",
"title": "has.js test"
}, {
"url": "http://www.broken-links.com/2010/09/01/playing-webm-in-safari-with-plugins/",
"title": "Info on supporting WebM in Safari"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "p",
"10": "p",
"11": "p"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "p",
"4": "p",
"5": "p",
"5.1": "p",
"6": "p",
"6.1": "p",
"7": "p"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "p"
}
},
"notes": "Will work in IE9+ and Safari/MacOSX provided the user has the WebM codecs installed.",
"usage_perc_y": 55.72,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "video",
"keywords": "matroska"
},
"mpeg4": {
"title": "MPEG-4/H.264 video format",
"description": "Commonly used video compression format (not royalty-free)",
"spec": "http://ip.hhi.de/imagecom_G1/assets/pdfs/csvt_overview_0305.pdf",
"status": "other",
"links": [{
"url": "http://www.interoperabilitybridges.com/html5-extension-for-wmp-plugin",
"title": "Firefox extension allowing support in Win7"
}, {
"url": "http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC",
"title": "Wikipedia article"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a",
"2.2": "a",
"2.3": "a",
"3": "a",
"4": "a",
"4.1": "a",
"4.2-4.3": "a",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "a"
},
"ie_mob": {
"10": "y"
}
},
"notes": "The Android 2.3 browser currently requires <a href=\"http://www.broken-links.com/2010/07/08/making-html5-video-work-on-android-phones/\">specific handling</a> to play videos. Firefox <a href=\"http://blog.lizardwrangler.com/2012/03/18/video-user-experience-and-our-mission/\">will include support</a> on some platforms in upcoming versions. Firefox supports H.264 on Windows 7 and later since version 21. Partial support for Firefox refers to the lack of support in OSX & Linux platforms, for Android Firefox it refers to the inability of hardware acceleration.",
"usage_perc_y": 59.55,
"usage_perc_a": 18.1,
"ucprefix": false,
"parent": "video",
"keywords": "avc,mp4,mpv,mov,aac"
},
"ogv": {
"title": "Ogg/Theora video format",
"description": "Free lossy video compression format.",
"spec": "http://theora.org/doc/",
"status": "other",
"links": [{
"url": "http://en.wikipedia.org/wiki/Theora",
"title": "Wikipedia article"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "p",
"10": "p",
"11": "p"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "p"
}
},
"notes": "",
"usage_perc_y": 49.8,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "video",
"keywords": "xiph"
},
"wordwrap": {
"title": "CSS3 Overflow-wrap",
"description": "Allows lines to be broken within words if an otherwise unbreakable string is too long to fit.",
"spec": "http://www.w3.org/TR/css3-text/#overflow-wrap",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/properties/word-wrap",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/En/CSS/Word-wrap",
"title": "MDN article"
}, {
"url": "http://www.css3files.com/text/#wordwrap",
"title": "Information page"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "a",
"3.6": "a",
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a"
},
"chrome": {
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a",
"3.2": "a",
"4": "a",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "a",
"10.6": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"11.6": "a",
"12": "a",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "a",
"2.2": "a",
"2.3": "a",
"3": "a",
"4": "a",
"4.1": "a",
"4.2-4.3": "a",
"4.4": "y"
},
"bb": {
"7": "a",
"10": "y"
},
"op_mob": {
"10": "a",
"11": "a",
"11.1": "a",
"11.5": "a",
"12": "a",
"12.1": "a",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "a"
},
"ie_mob": {
"10": "a"
}
},
"notes": "Partial support refers to requiring the legacy name \"word-wrap\" (rather than overflow-wrap) to work.",
"usage_perc_y": 36.93,
"usage_perc_a": 57.51,
"ucprefix": false,
"parent": "",
"keywords": "wordwrap,word-wrap"
},
"progressmeter": {
"title": "Progress & Meter",
"description": "Method of indicating a progress state (progress element) or the current level of a gauge (meter element).\r\n",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#the-progress-element",
"status": "wd",
"links": [{
"url": "http://dev.opera.com/articles/view/new-form-features-in-HTML5/#newoutput",
"title": "Dev.Opera article"
}, {
"url": "http://peter.sh/examples/?/html/meter-progress.html",
"title": "Examples of progress and meter elements"
}, {
"url": "http://docs.webplatform.org/wiki/html/elements/progress",
"title": "WebPlatform Docs"
}, {
"url": "http://html5doctor.com/measure-up-with-the-meter-tag/",
"title": "HTML5 Doctor on meter element "
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "a",
"11": "a"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "a"
}
},
"notes": "Partial support in Firefox 6-15, IE10 & iOS7 Safari refers to supporting the progress element, but not the meter element. iOS7 Safari also does not support \"indeterminate\" progress elements.",
"usage_perc_y": 52.21,
"usage_perc_a": 14.58,
"ucprefix": false,
"parent": "forms",
"keywords": ""
},
"object-fit": {
"title": "CSS3 object-fit/object-position",
"description": "Method of specifying how an object (image or video) should fit inside its box. object-fit options include \"contain\" (fit according to aspect ratio), \"fill\" (stretches object to fill) and \"cover\" (overflows box but maintains ratio), where object-position allows the object to be repositioned like background-image does.",
"spec": "http://www.w3.org/TR/css3-images/",
"status": "cr",
"links": [{
"url": "http://dev.opera.com/articles/view/css3-object-fit-object-position/",
"title": "Dev.Opera article"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/object-fit",
"title": "WebPlatform Docs"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "u",
"27": "u"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "n",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "y x",
"11": "y x",
"11.1": "y x",
"11.5": "y x",
"11.6": "y x",
"12": "y x",
"12.1": "y x",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "y x",
"11.1": "y x",
"11.5": "y x",
"12": "y x",
"12.1": "y x",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Can be enabled in Chrome 31+ and Opera 18+ by enabling experimental Web Platform features under chrome://flags/ or opera://flags/.",
"usage_perc_y": 0.81,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "objectfit,objectposition"
},
"xhr2": {
"title": "XMLHttpRequest 2",
"description": "Adds more functionality to AJAX requests like file uploads, transfer progress information and the ability to send form data.",
"spec": "http://www.w3.org/TR/XMLHttpRequest2/",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/apis/xhr/XMLHttpRequest",
"title": "WebPlatform Docs"
}, {
"url": "http://www.profilepicture.co.uk/tutorials/ajax-file-upload-xmlhttprequest-level-2/",
"title": "Article with file upload demo"
}, {
"url": "https://developer.mozilla.org/en/XMLHttpRequest/FormData",
"title": "MDN article on FormData"
}, {
"url": "https://github.com/3nr1c/jUri.js",
"title": "Polyfill for FormData object"
}],
"categories": ["DOM", "JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "a",
"3.6": "a",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "u",
"5": "u",
"6": "u",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 73.51,
"usage_perc_a": 0.35,
"ucprefix": false,
"parent": "",
"keywords": "formdata"
},
"minmaxwh": {
"title": "CSS min/max-width/height",
"description": "Method of setting a minimum or maximum width or height to an element. ",
"spec": "http://www.w3.org/TR/CSS21/visudet.html#min-max-widths",
"status": "rec",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/properties/min-width",
"title": "WebPlatform Docs"
}, {
"url": "http://code.google.com/p/ie7-js/",
"title": "JS library with support"
}, {
"url": "http://www.impressivewebs.com/min-max-width-height-css/",
"title": "CSS Basics post"
}],
"categories": ["CSS2"],
"stats": {
"ie": {
"5.5": "p",
"6": "p",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "IE7 does not support \"inherit\" as a value on any of these properties. IE8 has some bugs with max-width/height combined with overflow: auto/scroll.",
"usage_perc_y": 94.36,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "min-width,min-height,max-width,max-height"
},
"details": {
"title": "Details & Summary elements",
"description": "The &lt;details> element generates a simple no-JavaScript widget to show/hide element contents, optionally by clicking on its child &lt;summary> element.",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#the-details-element",
"status": "wd",
"links": [{
"url": "http://html5doctor.com/summary-figcaption-element/",
"title": "HTML5 Doctor article"
}, {
"url": "http://mathiasbynens.be/notes/html5-details-jquery",
"title": "jQuery fallback script"
}, {
"url": "http://docs.webplatform.org/wiki/html/elements/details",
"title": "WebPlatform Docs"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-details",
"title": "has.js test"
}, {
"url": "https://gist.github.com/370590",
"title": "Fallback script"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "p",
"3.5": "p",
"3.6": "p",
"4": "p",
"5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p",
"12": "p",
"13": "p",
"14": "p",
"15": "p",
"16": "p",
"17": "p",
"18": "p",
"19": "p",
"20": "p",
"21": "p",
"22": "p",
"23": "p",
"24": "p",
"25": "p",
"26": "p",
"27": "p"
},
"chrome": {
"4": "p",
"5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "p",
"5": "p",
"5.1": "p",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "p",
"9.5-9.6": "p",
"10.0-10.1": "p",
"10.5": "p",
"10.6": "p",
"11": "p",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "p",
"4.0-4.1": "p",
"4.2-4.3": "p",
"5.0-5.1": "p",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "p"
},
"android": {
"2.1": "p",
"2.2": "p",
"2.3": "p",
"3": "p",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "p",
"10": "y"
},
"op_mob": {
"10": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"12": "p",
"12.1": "p",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 44.5,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"text-stroke": {
"title": "CSS text-stroke",
"description": "Method of declaring the outline (stroke) width and color for text.",
"spec": "http://developer.apple.com/library/safari/documentation/appleapplications/reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/doc/uid/TP30001266-_webkit_text_stroke",
"status": "unoff",
"links": [{
"url": "http://www.westciv.com/tools/textStroke/",
"title": "Live editor"
}, {
"url": "http://css-tricks.com/7405-adding-stroke-to-web-text/",
"title": "Information & workarounds"
}],
"categories": ["CSS"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "u",
"27": "u"
},
"chrome": {
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "y x",
"3.2": "y x",
"4": "y x",
"5": "y x",
"5.1": "y x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "a x",
"4.0-4.1": "y x",
"4.2-4.3": "y x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y x",
"2.2": "y x",
"2.3": "y x",
"3": "n",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y x"
},
"bb": {
"7": "y x",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Does not yet appear in any W3C specification. Was briefly included in a spec as the \"text-outline\" property, but this was removed.",
"usage_perc_y": 48.41,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "textstroke,stroke-color,stroke-width,fill-color"
},
"inline-block": {
"title": "CSS inline-block",
"description": "Method of displaying an element as a block while flowing it with text. ",
"spec": "http://www.w3.org/TR/CSS21/visuren.html#fixed-positioning",
"status": "rec",
"links": [{
"url": "http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/",
"title": "Blog post w/info"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/display",
"title": "WebPlatform Docs"
}, {
"url": "http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/",
"title": "Info on cross browser support"
}],
"categories": ["CSS2"],
"stats": {
"ie": {
"5.5": "a",
"6": "a",
"7": "a",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "a x",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Only supported in IE6 and IE7 on elements with a display of \"inline\" by default. <a href=\"http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/\">Alternative properties</a> are available to provide complete cross-browser support.",
"usage_perc_y": 93.84,
"usage_perc_a": 0.74,
"ucprefix": false,
"parent": "",
"keywords": "inlineblock"
},
"notifications": {
"title": "Web Notifications",
"description": "Method of alerting the user outside of a web page by displaying notifications (that do not require interaction by the user).",
"spec": "http://www.w3.org/TR/notifications/",
"status": "wd",
"links": [{
"url": "http://www.html5rocks.com/tutorials/notifications/quick/",
"title": "HTML5 Rocks tutorial"
}, {
"url": "http://www.chromium.org/developers/design-documents/desktop-notifications/api-specification",
"title": "Chromium API"
}, {
"url": "https://addons.mozilla.org/en-us/firefox/addon/221523/",
"title": "Add-on "
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "a x",
"21": "a x",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "a x"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "a x"
},
"and_chr": {
"0": "a x"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 45.27,
"usage_perc_a": 2.66,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"stream": {
"title": "getUserMedia/Stream API",
"description": "Method of accessing external device data (such as a webcam video stream). Formerly this was envisioned as the &lt;device> element.",
"spec": "http://www.w3.org/TR/mediacapture-streams/",
"status": "wd",
"links": [{
"url": "http://my.opera.com/core/blog/2011/03/23/webcam-orientation-preview",
"title": "Technology preview from Opera"
}, {
"url": "http://docs.webplatform.org/wiki/dom/methods/getUserMedia",
"title": "WebPlatform Docs"
}],
"categories": ["HTML5", "JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "y",
"12.1": "y",
"15": "n",
"16": "n",
"17": "n",
"18": "y x"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "y",
"12.1": "y",
"0": "y x"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 48.44,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "camera,device,getUserMedia,media stream,Media Capture API"
},
"svg-img": {
"title": "SVG in HTML img element",
"description": "Method of displaying SVG images in HTML using &lt;img>",
"spec": "http://www.w3.org/TR/html5/embedded-content-1.html#the-img-element",
"status": "cr",
"links": [{
"url": "http://www.codedread.com/blog/",
"title": "Blog with SVGs an images"
}, {
"url": "http://blog.dholbert.org/2010/10/svg-as-image.html",
"title": "Blog post with examples"
}],
"categories": ["SVG"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "a",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 83.65,
"usage_perc_a": 0.01,
"ucprefix": false,
"parent": "",
"keywords": "svg-as-img,svg-in-img"
},
"datalist": {
"title": "Datalist element",
"description": "Method of setting a list of options for a user to select in a text field, while leaving the ability to enter a custom value.",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#the-datalist-element",
"status": "wd",
"links": [{
"url": "http://demo.agektmr.com/datalist/",
"title": "Eiji Kitamura's options demos & tests"
}, {
"url": "http://docs.webplatform.org/wiki/html/elements/datalist",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/en/HTML/Element/datalist",
"title": "MDN reference"
}, {
"url": "http://afarkas.github.com/webshim/demos/",
"title": "HTML5 Library including datalist support"
}, {
"url": "http://hacks.mozilla.org/2010/11/firefox-4-html5-forms/",
"title": "Mozilla Hacks article"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "a",
"11": "a"
},
"firefox": {
"2": "p",
"3": "p",
"3.5": "p",
"3.6": "p",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "p",
"5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p",
"12": "p",
"13": "p",
"14": "p",
"15": "p",
"16": "p",
"17": "p",
"18": "p",
"19": "n",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "p",
"3.2": "p",
"4": "p",
"5": "p",
"5.1": "p",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "p",
"4.0-4.1": "p",
"4.2-4.3": "p",
"5.0-5.1": "p",
"6.0-6.1": "p",
"7.0": "p"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "p",
"2.2": "p",
"2.3": "p",
"3": "p",
"4": "p",
"4.1": "p",
"4.2-4.3": "p",
"4.4": "p"
},
"bb": {
"7": "p",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "p"
},
"and_chr": {
"0": "p"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "p"
}
},
"notes": "Partial support in IE10 refers to <a href=\"http://playground.onereason.eu/2013/04/ie10s-lousy-support-for-datalists/\">significantly buggy behavior</a>.",
"usage_perc_y": 48.86,
"usage_perc_a": 10.9,
"ucprefix": false,
"parent": "forms",
"keywords": "list attribute"
},
"dataset": {
"title": "dataset & data-* attributes",
"description": "Method of applying and accessing custom data to elements.",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#embedding-custom-non-visible-data-with-the-data-*-attributes",
"status": "wd",
"links": [{
"url": "http://www.orangesoda.net/jquery.dataset.html",
"title": "jQuery polyfill for dataset support"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/dom.js#dom-dataset",
"title": "has.js test"
}, {
"url": "http://html5demos.com/dataset",
"title": "Demo using dataset"
}, {
"url": "http://html5doctor.com/html5-custom-data-attributes/",
"title": "HTML5 Doctor article"
}, {
"url": "http://docs.webplatform.org/wiki/html/attributes/data-*",
"title": "WebPlatform Docs"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "y"
},
"firefox": {
"2": "a",
"3": "a",
"3.5": "a",
"3.6": "a",
"4": "a",
"5": "a",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "a",
"6": "a",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a",
"3.2": "a",
"4": "a",
"5": "a",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "a",
"9.5-9.6": "a",
"10.0-10.1": "a",
"10.5": "a",
"10.6": "a",
"11": "a",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "a",
"2.2": "a",
"2.3": "a",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "a",
"11": "a",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "a"
}
},
"notes": "All browsers can already use data-* attributes and access them using getAttribute. \"Supported\" refers to accessing the values using the dataset property. Current spec only refers to support on HTML elements, only some browsers also have support for SVG/MathML elements.",
"usage_perc_y": 62.15,
"usage_perc_a": 32.43,
"ucprefix": false,
"parent": "",
"keywords": "DOMStringMap"
},
"css-grid": {
"title": "CSS Grid Layout",
"description": "Method of using a grid concept to lay out content, providing a mechanism for authors to divide available space for lay out into columns and rows using a set of predictable sizing behaviors",
"spec": "http://www.w3.org/TR/css3-grid-layout/",
"status": "wd",
"links": [{
"url": "https://bugzilla.mozilla.org/show_bug.cgi?id=616605",
"title": "Mozilla (Firefox) feature request"
}, {
"url": "http://blogs.msdn.com/b/ie/archive/2011/04/14/ie10-platform-preview-and-css-features-for-adaptive-layouts.aspx",
"title": "IE Blog post"
}, {
"url": "https://github.com/codler/Grid-Layout-Polyfill",
"title": "Grid Layout Polyfill"
}, {
"url": "https://bugs.webkit.org/show_bug.cgi?id=60731",
"title": "Webkit (Chrome, Safari, etc.) feature request"
}],
"categories": ["CSS"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "p",
"10": "y x",
"11": "y x"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "p",
"20": "p",
"21": "p",
"22": "p",
"23": "p",
"24": "p",
"25": "p",
"26": "u",
"27": "u"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "p",
"26": "p",
"27": "p",
"28": "p",
"29": "p",
"30": "p",
"31": "u",
"32": "u"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "p",
"6.1": "p",
"7": "p"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "p",
"7.0": "p"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "p",
"4.4": "p"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "p"
},
"and_chr": {
"0": "p"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "y x"
}
},
"notes": "",
"usage_perc_y": 11.11,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "grids,grid-row,grid-column"
},
"menu": {
"title": "Toolbar/context menu",
"description": "Method of defining a toolbar menu, a context menu or a list of (interactive) options using the &lt;menu> element.",
"spec": "http://www.w3.org/TR/html5/interactive-elements.html#context-menus",
"status": "cr",
"links": [{
"url": "https://raw.github.com/phiggins42/has.js/master/detect/events.js#event-contextmenu",
"title": "has.js test"
}, {
"url": "https://bug617528.bugzilla.mozilla.org/attachment.cgi?id=554309",
"title": "Demo"
}, {
"url": "http://addyosmani.github.com/jQuery-contextMenu/",
"title": "jQuery polyfill"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "u",
"32": "u"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Partial support in Firefox refers to using the non-standard \"menuitem\" child elements, where the current spec uses \"<a href=\"http://www.w3.org/TR/html5/interactive-elements.html#the-command-element\">command</a>\" child elements. It is also currently limited to context menus, not toolbar menus.",
"usage_perc_y": 0,
"usage_perc_a": 14.7,
"ucprefix": false,
"parent": "",
"keywords": "contextmenu,menuitem,command"
},
"rem": {
"title": "rem (root em) units",
"description": "Type of unit similar to \"em\", but relative only to the root element, not any parent element. Thus compounding does not occur as it does with \"em\" units.",
"spec": "http://www.w3.org/TR/css3-values/#font-relative-lengths",
"status": "cr",
"links": [{
"url": "http://snook.ca/archives/html_and_css/font-size-with-rem",
"title": "Article on usage"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "u",
"5": "u",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 80.56,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"ttf": {
"title": "TTF/OTF - TrueType and OpenType font support",
"description": "Support for the TrueType (.ttf)and OpenType (.otf) outline font formats in @font-face. ",
"spec": "http://developer.apple.com/fonts/TTRefMan/index.html",
"status": "other",
"links": [{
"url": "http://stackoverflow.com/questions/17694143/what-is-the-status-of-ttf-support-in-internet-explorer",
"title": "What is the status of TTF support in Internet Explorer?"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "a",
"10": "a",
"11": "a"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "u"
}
},
"notes": "Partial support in IE9 refers to the fonts only working <a href=\"http://blogs.msdn.com/b/ie/archive/2010/07/15/the-css-corner-better-web-typography-for-better-design.aspx\">when set to be \"installable\"</a>.",
"usage_perc_y": 64.48,
"usage_perc_a": 16.11,
"ucprefix": false,
"parent": "fontface",
"keywords": ""
},
"touch": {
"title": "Touch events",
"description": "Method of registering when, where and how the interface is touched, for devices with a touch screen. These DOM events are similar to mousedown, mousemove, etc.",
"spec": "http://www.w3.org/TR/touch-events/",
"status": "rec",
"links": [{
"url": "http://schepers.cc/getintouch",
"title": "Information on the spec development"
}, {
"url": "http://www.quirksmode.org/mobile/tableTouch.html",
"title": "Detailed support tables"
}, {
"url": "http://www.quirksmode.org/m/tests/drag2.html",
"title": "Multi-touch demo"
}, {
"url": "http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx",
"title": "Internet Explorer's gesture and touch implementation."
}],
"categories": ["DOM", "JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "p",
"11": "p"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "a",
"5": "a",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "p"
}
},
"notes": "Internet Explorer implements Pointer Events specification which supports more input devices than Touch Events one.",
"usage_perc_y": 58.16,
"usage_perc_a": 0.12,
"ucprefix": false,
"parent": "",
"keywords": "touchstart,touchend,touchmove,touchenter,touchleave,touchcancel"
},
"matchesselector": {
"title": "matches() DOM method",
"description": "Method of testing whether or not a DOM element matches a given selector. Formerly known (and largely supported with prefix) as matchesSelector.",
"spec": "http://www.w3.org/TR/selectors-api2/",
"status": "wd",
"links": [{
"url": "https://developer.mozilla.org/en/DOM/Element.mozMatchesSelector",
"title": "MDN article"
}, {
"url": "http://docs.webplatform.org/wiki/dom/methods/matchesSelector",
"title": "WebPlatform Docs"
}],
"categories": ["DOM", "JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "a x",
"10": "a x",
"11": "a x"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "a x",
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "a x",
"21": "a x",
"22": "a x",
"23": "a x",
"24": "a x",
"25": "a x",
"26": "a x",
"27": "a x"
},
"chrome": {
"4": "a x",
"5": "a x",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "a x",
"21": "a x",
"22": "a x",
"23": "a x",
"24": "a x",
"25": "a x",
"26": "a x",
"27": "a x",
"28": "a x",
"29": "a x",
"30": "a x",
"31": "a x",
"32": "a x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "a x",
"5.1": "a x",
"6": "a x",
"6.1": "a x",
"7": "a x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "a x",
"11.6": "a x",
"12": "a x",
"12.1": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "a x",
"4.2-4.3": "a x",
"5.0-5.1": "a x",
"6.0-6.1": "a x",
"7.0": "a x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "a x",
"2.3": "a x",
"3": "a x",
"4": "a x",
"4.1": "a x",
"4.2-4.3": "a x",
"4.4": "a x"
},
"bb": {
"7": "a x",
"10": "a x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "a x",
"11.5": "a x",
"12": "a x",
"12.1": "a x",
"0": "a x"
},
"and_chr": {
"0": "a x"
},
"and_ff": {
"0": "a x"
},
"ie_mob": {
"10": "a x"
}
},
"notes": "Partial support refers to supporting the older specification's \"matchesSelector\" name rather than just \"matches\".",
"usage_perc_y": 0,
"usage_perc_a": 80.6,
"ucprefix": false,
"parent": "",
"keywords": " matchesSelector"
},
"pointer-events": {
"title": "CSS pointer-events (for HTML)",
"description": "This CSS property, when set to \"none\" allows elements to not receive hover/click events, instead the event will occur on anything behind it. ",
"spec": "http://wiki.csswg.org/spec/css4-ui#pointer-events",
"status": "unoff",
"links": [{
"url": "http://robertnyman.com/2010/03/22/css-pointer-events-to-allow-clicks-on-underlying-elements/",
"title": "Article & tutorial"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/css.js#css-pointerevents",
"title": "has.js test"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Already part of the SVG specification, and all SVG-supporting browsers appear to support the property on SVG elements.",
"usage_perc_y": 63.82,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "pointerevents"
},
"blobbuilder": {
"title": "Blob constructing",
"description": "Construct Blobs (binary large objects) either using the BlobBuilder API (deprecated) or the Blob constructor.",
"spec": "http://www.w3.org/TR/file-writer-api/#the-blobbuilder-interface",
"status": "wd",
"links": [{
"url": "https://developer.mozilla.org/en/DOM/BlobBuilder",
"title": "MDN article on BlobBuilder"
}, {
"url": "https://developer.mozilla.org/en-US/docs/DOM/Blob",
"title": "MDN article on Blobs"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "a x",
"7": "a x",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "a x",
"4": "a x",
"4.1": "a x",
"4.2-4.3": "a x",
"4.4": "a x"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "a x"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support refers to only supporting the now deprecated BlobBuilder to create blobs.",
"usage_perc_y": 64.97,
"usage_perc_a": 6.3,
"ucprefix": true,
"parent": "fileapi",
"keywords": ""
},
"filereader": {
"title": "FileReader API",
"description": "Method of reading the contents of a File or Blob object into memory",
"spec": "http://www.w3.org/TR/FileAPI/#dfn-filereader",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/apis/file/FileReader",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/en/DOM/FileReader",
"title": "FileReader API"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 71.89,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "fileapi",
"keywords": ""
},
"filesystem": {
"title": "Filesystem & FileWriter API",
"description": "Method of reading and writing files to a sandboxed file system.\r\n",
"spec": "http://www.w3.org/TR/file-system-api/",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/apis/filesystem",
"title": "WebPlatform Docs"
}, {
"url": "http://www.html5rocks.com/en/tutorials/file/filesystem/",
"title": "HTML5 Rocks tutorial"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "a x",
"9": "a x",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y x"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 34.87,
"usage_perc_a": 0.28,
"ucprefix": false,
"parent": "",
"keywords": "filewriter"
},
"bloburls": {
"title": "Blob URLs",
"description": "Method of creating URL handles to the specified File or Blob object.",
"spec": "http://www.w3.org/TR/FileAPI/#url",
"status": "wd",
"links": [{
"url": "https://developer.mozilla.org/en/DOM/window.URL.createObjectURL",
"title": "MDN article"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y x",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y x",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 70.6,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "fileapi",
"keywords": "createobjecturl"
},
"typedarrays": {
"title": "Typed Arrays",
"description": "JavaScript typed arrays provide a mechanism for accessing raw binary data much more efficiently.\r\n",
"spec": "http://www.khronos.org/registry/typedarray/specs/latest/",
"status": "other",
"links": [{
"url": "https://developer.mozilla.org/en/javascript_typed_arrays",
"title": "MDN article"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 73.11,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "float64array,dataview,uint8array"
},
"deviceorientation": {
"title": "DeviceOrientation events",
"description": "API for detecting orientation and motion events from the device running the browser.",
"spec": "http://www.w3.org/TR/orientation-event/",
"status": "wd",
"links": [{
"url": "http://html5labs.interoperabilitybridges.com/prototypes/device-orientation-events/device-orientation-events/info",
"title": "DeviceOrientation implementation prototype for IE10"
}, {
"url": "http://www.html5rocks.com/en/tutorials/device/orientation/",
"title": "HTML5 Rocks tutorial"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/features.js#native-orientation",
"title": "has.js test"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "a"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "p",
"4": "p",
"5": "p",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a",
"28": "a",
"29": "a",
"30": "a",
"31": "a",
"32": "a"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "a",
"16": "a",
"17": "a",
"18": "a"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "a",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "a",
"4": "a",
"4.1": "a",
"4.2-4.3": "a",
"4.4": "a"
},
"bb": {
"7": "n",
"10": "a"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "y",
"12.1": "y",
"0": "a"
},
"and_chr": {
"0": "a"
},
"and_ff": {
"0": "a"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Partial support refers to the lack of compassneedscalibration event. Partial support also refers to the lack of devicemotion event support for Chrome 30- and Opera. Opera Mobile 14 lost the ondevicemotion event support. Firefox 3.6, 4 and 5 support the non-standard <a href=\"https://developer.mozilla.org/en/DOM/MozOrientation\">MozOrientation</a> event.",
"usage_perc_y": 0.14,
"usage_perc_a": 57.76,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"script-defer": {
"title": "defer attribute for external scripts",
"description": "The boolean defer attribute on script elements allows the external JavaScript file to run when the DOM is loaded, without delaying page load first.",
"spec": "http://www.w3.org/TR/html5/the-script-element.html#attr-script-defer",
"status": "cr",
"links": [{
"url": "https://developer.mozilla.org/en/HTML/Element/script#Attributes",
"title": "MDN article"
}, {
"url": "http://docs.webplatform.org/wiki/html/attributes/defer",
"title": "WebPlatform Docs"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/script.js#script-defer",
"title": "has.js test"
}],
"categories": ["DOM", "HTML5"],
"stats": {
"ie": {
"5.5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support refers to a buggy implementation in IE<10",
"usage_perc_y": 73.17,
"usage_perc_a": 14.25,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"nav-timing": {
"title": "Navigation Timing API",
"description": "API for accessing timing information related to navigation and elements.",
"spec": "http://www.w3.org/TR/navigation-timing/",
"status": "cr",
"links": [{
"url": "https://developer.mozilla.org/en/API/navigationTiming",
"title": "MDN article"
}, {
"url": "http://www.html5rocks.com/en/tutorials/webperformance/basics/",
"title": "HTML5 Rocks tutorial"
}, {
"url": "http://docs.webplatform.org/wiki/apis/navigation_timing",
"title": "WebPlatform Docs"
}],
"categories": ["DOM", "JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 69.95,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "performance,performance.timing"
},
"audio-api": {
"title": "Web Audio API",
"description": "High-level JavaScript API for processing and synthesizing audio",
"spec": "http://www.w3.org/TR/webaudio/",
"status": "wd",
"links": [{
"url": "http://www.doboism.com/projects/webaudio-compatibility/",
"title": "Additional browser compatibility tests for specific features"
}, {
"url": "http://docs.webplatform.org/wiki/apis/webaudio",
"title": "WebPlatform Docs"
}, {
"url": "https://github.com/corbanbrook/audionode.js",
"title": "Polyfill to support Web Audio API in Firefox"
}, {
"url": "https://github.com/g200kg/WAAPISim",
"title": "Polyfill to enable Web Audio API through Firefox Audio Data api or flash"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Firefox versions < 25 support an alternative, deprecated audio API.",
"usage_perc_y": 41.68,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "web-audio"
},
"css-regions": {
"title": "CSS Regions",
"description": "Method of flowing content into multiple elements.",
"spec": "http://www.w3.org/TR/css3-regions/",
"status": "wd",
"links": [{
"url": "http://msdn.microsoft.com/en-us/ie/hh272902#_CSSConnected",
"title": "IE10 developer guide info"
}, {
"url": "http://html.adobe.com/webstandards/cssregions/",
"title": "Adobe demos and samples"
}, {
"url": "http://docs.webplatform.org/wiki/css/atrules/@region",
"title": "WebPlatform Docs"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "a x",
"11": "a x"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "n",
"32": "n"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "a x"
}
},
"notes": "Currently supported in WebKit Nightly using <code>-webkit-flow-into: flow_name;</code> and <code>-webkit-from-flow: flow_name;</code>. Support in Chrome 19+ is disabled by default and can be enabled using a runtime flag (see <code>about:flags</code>) or a command line flag (see <a href=\"http://peter.sh/experiments/chromium-command-line-switches/#enable-css-regions\">this list</a>). For Chrome 19-22 the flag is named \"Enable CSS Regions\" / <code>--enable-css-regions</code>, while for Chrome 23+ the flag is named \"Enable experimental WebKit features\" / <code>--enable-experimental-webkit-features</code>. Support in IE10 is limited to using an iframe as a content source with the <code>-ms-flow-into: flow_name;</code> and <code>-ms-flow-from: flow_name;</code> syntax. Support for Safari 6.1&7 is <a href=\"http://www.broken-links.com/2013/07/10/web-platform-technologies-in-safari-6-1-and-7/\">likely</a> but not official.",
"usage_perc_y": 2.75,
"usage_perc_a": 11.35,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"fullscreen": {
"title": "Full Screen API",
"description": "API for allowing content (like a video or canvas element) to take up the entire screen.",
"spec": "http://www.w3.org/TR/fullscreen/",
"status": "wd",
"links": [{
"url": "https://developer.mozilla.org/en/DOM/Using_full-screen_mode",
"title": "MDN article"
}, {
"url": "http://jlongster.com/2011/11/21/canvas.html",
"title": "Blog post"
}, {
"url": "http://hacks.mozilla.org/2012/01/using-the-fullscreen-api-in-web-browsers/",
"title": "Mozilla hacks article"
}, {
"url": "http://docs.webplatform.org/wiki/dom/methods/requestFullscreen",
"title": "WebPlatform Docs"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "y x"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "a x",
"11": "a x",
"12": "a x",
"13": "a x",
"14": "a x",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "a x",
"21": "a x",
"22": "a x",
"23": "a x",
"24": "a x",
"25": "a x",
"26": "a x",
"27": "a x"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "a x",
"16": "a x",
"17": "a x",
"18": "a x",
"19": "a x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "a x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "y",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "a"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "a x"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Partial support refers to supporting an earlier draft of the spec.",
"usage_perc_y": 37.35,
"usage_perc_a": 16.21,
"ucprefix": false,
"parent": "",
"keywords": "full-screen"
},
"requestanimationframe": {
"title": "requestAnimationFrame",
"description": "API allowing a more efficient way of running script-based animation, compared to traditional methods using timeouts.",
"spec": "http://www.w3.org/TR/animation-timing/#requestAnimationFrame",
"status": "wd",
"links": [{
"url": "http://hacks.mozilla.org/2011/08/animating-with-javascript-from-setinterval-to-requestanimationframe/",
"title": "Mozilla Hacks article"
}, {
"url": "http://paulirish.com/2011/requestanimationframe-for-smart-animating/",
"title": "Blog post"
}, {
"url": "http://docs.webplatform.org/wiki/apis/timing/methods/requestAnimationFrame",
"title": "WebPlatform Docs"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y x",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y x",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 67.13,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"input-range": {
"title": "Range input type",
"description": "Form field type that allows the user to select a value using a slider widget.",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#range-state-(type=range)",
"status": "wd",
"links": [{
"url": "https://github.com/fryn/html5slider",
"title": "Polyfill for Firefox"
}, {
"url": "http://docs.webplatform.org/wiki/html/elements/input/type/range",
"title": "WebPlatform Docs"
}, {
"url": "http://tutorialzine.com/2011/12/what-you-need-to-know-html5-range-input/",
"title": "Tutorial"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/form.js#input-type-range",
"title": "has.js test"
}, {
"url": "https://github.com/freqdec/fd-slider",
"title": "Cross-browser polyfill"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "u",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a",
"2.2": "a",
"2.3": "a",
"3": "a",
"4": "a",
"4.1": "a",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Currently all Android browsers with partial support hide the slider input field by default. However, the element <a href=\"http://tiffanybbrown.com/2012/02/07/input-typerange-and-androids-stock-browser/\">can be styled</a> to be made visible and usable.",
"usage_perc_y": 68.52,
"usage_perc_a": 4.31,
"ucprefix": false,
"parent": "forms",
"keywords": ""
},
"matchmedia": {
"title": "matchMedia",
"description": "API for finding out whether or not a media query applies to the document.",
"spec": "http://www.w3.org/TR/cssom-view/#dom-window-matchmedia",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/media_queries/apis/matchMedia",
"title": "WebPlatform Docs"
}, {
"url": "https://github.com/paulirish/matchMedia.js/",
"title": "matchMedia.js polyfill"
}, {
"url": "https://developer.mozilla.org/en/DOM/window.matchMedia",
"title": "MDN article"
}, {
"url": "https://developer.mozilla.org/en/CSS/Using_media_queries_from_code",
"title": "MDN tutorial"
}],
"categories": ["JS API", "DOM"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 72.81,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "mediaquerylist"
},
"input-datetime": {
"title": "Date/time input types",
"description": "Form field widget to easily allow users to enter dates and/or times, generally by using a calendar widget.",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#date-state-(type=date)",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/html/elements/input/type/date",
"title": "WebPlatform Docs"
}, {
"url": "http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-cross-browser-datepickers-within-minutes/",
"title": "Datepicker tutorial w/polyfill"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/form.js#input-type-datetime;input-type-datetime-local",
"title": "has.js test"
}, {
"url": "https://github.com/zoltan-dulac/html5Forms.js",
"title": "Polyfill for HTML5 forms"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a",
"28": "a",
"29": "a",
"30": "a",
"31": "a",
"32": "a"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "a",
"16": "a",
"17": "a",
"18": "a"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "a"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Safari provides date-formatted text fields, but no real calendar widget. Partial support in Chrome refers to a missing calendar widget for the \"datetime\" type (and other types in older versions). Some modified versions of the Android 4.x browser do have support for date/time fields. ",
"usage_perc_y": 6.13,
"usage_perc_a": 33.1,
"ucprefix": false,
"parent": "forms",
"keywords": "datepicker,timepicker"
},
"input-color": {
"title": "Color input type",
"description": "Form field allowing the user to select a color.",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#color-state-(type=color)",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/html/elements/input/type/color",
"title": "WebPlatform Docs"
}, {
"url": "http://www.html5tutorial.info/html5-color.php",
"title": "Tutorial"
}, {
"url": "https://github.com/jonstipe/color-polyfill",
"title": "Polyfill"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "n",
"16": "n",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 35.22,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "forms",
"keywords": "colour"
},
"input-number": {
"title": "Number input type",
"description": "Form field type for numbers.",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#number-state-(type=number)",
"status": "wd",
"links": [{
"url": "https://raw.github.com/phiggins42/has.js/master/detect/form.js#input-type-number",
"title": "has.js test"
}, {
"url": "http://www.html5tutorial.info/html5-number.php",
"title": "Tutorial"
}, {
"url": "https://github.com/jonstipe/number-polyfill",
"title": "Polyfill"
}, {
"url": "http://docs.webplatform.org/wiki/html/elements/input/type/number",
"title": "WebPlatform Docs"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "a",
"11": "a"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "n",
"5": "n",
"6": "u",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "a",
"4.1": "a",
"4.2-4.3": "a",
"4.4": "a"
},
"bb": {
"7": "n",
"10": "a"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "a"
},
"and_chr": {
"0": "a"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "a"
}
},
"notes": "iOS Safari, Android 4 and Chrome for Android show number input, but do not use \"step\", \"min\" or \"max\" attributes or show increment/decrement buttons. Internet Explorer 10 does not show increment/decrement buttons.",
"usage_perc_y": 38.44,
"usage_perc_a": 20.1,
"ucprefix": false,
"parent": "forms",
"keywords": "spinner"
},
"iframe-sandbox": {
"title": "sandbox attribute for iframes",
"description": "Method of running external site pages with reduced privileges (e.g. no JavaScript) in iframes",
"spec": "http://www.w3.org/TR/html5/the-iframe-element.html#attr-iframe-sandbox",
"status": "cr",
"links": [{
"url": "http://msdn.microsoft.com/en-us/hh563496",
"title": "MSDN article"
}, {
"url": "http://blog.chromium.org/2010/05/security-in-depth-html5s-sandbox.html",
"title": "Chromium blog article"
}, {
"url": "http://docs.webplatform.org/wiki/html/attributes/sandbox",
"title": "WebPlatform Docs"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 59.45,
"usage_perc_a": 13.57,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"css-counters": {
"title": "CSS Counters",
"description": "Method of controlling number values in generated content, using the counter-reset and counter-increment properties.",
"spec": "http://www.w3.org/TR/CSS21/generate.html#counters",
"status": "wd",
"links": [{
"url": "http://onwebdev.blogspot.com/2012/02/css-counters-tutorial.html",
"title": "Tutorial and information"
}, {
"url": "http://docs.webplatform.org/wiki/css/properties/counter-reset",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/en/CSS_Counters",
"title": "MDN article"
}],
"categories": ["CSS2"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "y"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 93.86,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"css-resize": {
"title": "CSS resize property",
"description": "Method of allowing an element to be resized by the user, with options to limit to a given direction. ",
"spec": "http://www.w3.org/TR/css3-ui/#resize",
"status": "wd",
"links": [{
"url": "http://css-tricks.com/almanac/properties/r/resize/",
"title": "CSS Tricks info"
}, {
"url": "http://davidwalsh.name/textarea-resize",
"title": "On textarea resizing"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y x",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "a",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Opera 12.10+ currently only supports the resize property for textarea elements.",
"usage_perc_y": 52.82,
"usage_perc_a": 0.48,
"ucprefix": false,
"parent": "",
"keywords": "horizontal,vertical"
},
"input-placeholder": {
"title": "input placeholder attribute",
"description": "Method of setting placeholder text for text-like input fields, to suggest the expected inserted information.",
"spec": "http://dev.w3.org/html5/spec/Overview.html#attr-input-placeholder",
"status": "cr",
"links": [{
"url": "http://docs.webplatform.org/wiki/html/attributes/placeholder",
"title": "WebPlatform Docs"
}, {
"url": "https://raw.github.com/phiggins42/has.js/master/detect/form.js#input-attr-placeholder",
"title": "has.js test"
}, {
"url": "http://www.zachleat.com/web/placeholder/",
"title": "Article on usage"
}, {
"url": "https://github.com/mathiasbynens/jquery-placeholder",
"title": "Polyfill"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a",
"3.2": "a",
"4": "a",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "a",
"11.1": "a",
"11.5": "a",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support in older Safari and Opera versions refers to lacking placeholder support on textarea elements. ",
"usage_perc_y": 75.1,
"usage_perc_a": 0.15,
"ucprefix": false,
"parent": "forms",
"keywords": ""
},
"spdy": {
"title": "SPDY networking protocol",
"description": "Networking protocol for low-latency transport of content over the web.",
"spec": "http://tools.ietf.org/html/draft-mbelshe-httpbis-spdy-00",
"status": "unoff",
"links": [{
"url": "http://en.wikipedia.org/wiki/SPDY",
"title": "Wikipedia"
}, {
"url": "http://dev.chromium.org/spdy/spdy-whitepaper",
"title": "SPDY whitepaper"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "a"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "u"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 53.69,
"usage_perc_a": 0.11,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"css-repeating-gradients": {
"title": "CSS Repeating Gradients",
"description": "Method of defining a repeating linear or radial color gradient as a CSS image.",
"spec": "http://www.w3.org/TR/css3-images/#repeating-gradients",
"status": "cr",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/repeating-linear-gradient",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/en/CSS/repeating-linear-gradient",
"title": "MDN article"
}, {
"url": "http://www.css3files.com/gradient/#repeatinglineargradient",
"title": "Information page"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "y x",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "y x",
"6": "y x",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "a x",
"11.5": "a x",
"11.6": "y x",
"12": "y x",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "a x",
"11.5": "a x",
"12": "y x",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Firefox 10+, Chrome 26+ and Opera 11.6+ also support the new \"to (side)\" syntax.",
"usage_perc_y": 73.31,
"usage_perc_a": 0.03,
"ucprefix": false,
"parent": "css-gradients",
"keywords": ""
},
"css-filters": {
"title": "CSS Filter Effects",
"description": "Method of applying filter effects (like blur, grayscale, brightness, contrast and hue) to elements, previously only possible by using SVG.",
"spec": "http://www.w3.org/TR/filter-effects/",
"status": "wd",
"links": [{
"url": "http://dl.dropbox.com/u/3260327/angular/CSS3ImageManipulation.html",
"title": "Filter editor"
}, {
"url": "http://bennettfeely.com/filters/",
"title": "Filter Playground"
}, {
"url": "http://html5-demos.appspot.com/static/css/filters/index.html",
"title": "Demo file for WebKit browsers"
}, {
"url": "http://www.html5rocks.com/en/tutorials/filters/understanding-css/",
"title": "Mozilla hacks article"
}],
"categories": ["CSS3", "CSS"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "u",
"27": "u"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y x"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Note that this property is significantly different from and incompatible with Microsoft's <a href=\"http://msdn.microsoft.com/en-us/library/ie/ms530752%28v=vs.85%29.aspx\">older \"filter\" property</a>.",
"usage_perc_y": 40.55,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "sepia,hue-rotate,invert,saturate"
},
"getcomputedstyle": {
"title": "getComputedStyle",
"description": "API to get the current computed CSS styles applied to an element. This may be the current value applied by an animation or as set by a stylesheet.",
"spec": "http://www.w3.org/TR/cssom/#dom-window-getcomputedstyle",
"status": "rec",
"links": [{
"url": "http://ie.microsoft.com/testdrive/HTML5/getComputedStyle/",
"title": "Demo"
}, {
"url": "http://snipplr.com/view/13523/",
"title": "Polyfill for IE"
}, {
"url": "https://developer.mozilla.org/en/DOM/window.getComputedStyle",
"title": "MDN article"
}, {
"url": "http://docs.webplatform.org/wiki/css/cssom/methods/getComputedStyle",
"title": "WebPlatform Docs"
}],
"categories": ["JS API", "CSS3", "DOM"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "a",
"3.5": "a",
"3.6": "a",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "a",
"3.2": "a",
"4": "a",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "a",
"9.5-9.6": "a",
"10.0-10.1": "a",
"10.5": "a",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "a"
},
"android": {
"2.1": "a",
"2.2": "a",
"2.3": "a",
"3": "a",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "a",
"10": "y"
},
"op_mob": {
"10": "a",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support in older Firefox versions refers to requiring the second parameter to be included. Partial support in all other browsers refers to not supporting getComputedStyle on pseudo-elements.",
"usage_perc_y": 78.53,
"usage_perc_a": 7,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"word-break": {
"title": "CSS3 word-break",
"description": "Property to prevent or allow words to be broken over multiple lines between letters.",
"spec": "http://www.w3.org/TR/css3-text/#word-break",
"status": "wd",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/properties/word-break",
"title": "WebPlatform Docs"
}, {
"url": "https://developer.mozilla.org/en/CSS/word-break",
"title": "MDN article"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "a",
"5": "a",
"6": "a",
"7": "a",
"8": "a",
"9": "a",
"10": "a",
"11": "a",
"12": "a",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a",
"28": "a",
"29": "a",
"30": "a",
"31": "a",
"32": "a"
},
"safari": {
"3.1": "a",
"3.2": "a",
"4": "a",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "a",
"16": "a",
"17": "a",
"18": "a"
},
"ios_saf": {
"3.2": "a",
"4.0-4.1": "a",
"4.2-4.3": "a",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "a",
"2.2": "a",
"2.3": "a",
"3": "a",
"4": "a",
"4.1": "a",
"4.2-4.3": "a",
"4.4": "a"
},
"bb": {
"7": "a",
"10": "a"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "a"
},
"and_chr": {
"0": "a"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "Partial support refers to supporting the \"break-all\" value, but not the \"keep-all\" value.",
"usage_perc_y": 39.39,
"usage_perc_a": 48.42,
"ucprefix": false,
"parent": "",
"keywords": "break-all,keep-all"
},
"viewport-units": {
"title": "Viewport units: vw, vh, vmin, vmax",
"description": "Length units representing 1% of the viewport size for viewport width (vw), height (vh), the smaller of the two (vmin), or the larger of the two (vmax).",
"spec": "http://www.w3.org/TR/css3-values/#viewport-relative-lengths",
"status": "cr",
"links": [{
"url": "http://css-tricks.com/viewport-sized-typography/",
"title": "Blog post"
}, {
"url": "https://github.com/saabi/vminpoly",
"title": "Polyfill"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "a",
"10": "a",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "a",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "a"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "a"
}
},
"notes": "Partial support in IE9 refers to supporting \"vm\" instead of \"vmin\". All other partial support refers to not supporting the \"vmax\" unit.",
"usage_perc_y": 48.9,
"usage_perc_a": 21.18,
"ucprefix": false,
"parent": "",
"keywords": "vm,viewport-percentage"
},
"contentsecuritypolicy": {
"title": "Content Security Policy",
"description": "Mitigate cross-site scripting attacks by whitelisting allowed sources of script, style, and other resources.",
"spec": "http://www.w3.org/TR/CSP/",
"status": "cr",
"links": [{
"url": "http://content-security-policy.com/",
"title": "CSP Examples & Quick Reference"
}, {
"url": "http://html5rocks.com/en/tutorials/security/content-security-policy/",
"title": "HTML5Rocks article"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "a x",
"11": "a x"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "a x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "a x",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "a x"
}
},
"notes": "The HTTP header is 'X-Content-Security-Policy' for Firefox and IE 10&11, and 'X-WebKit-CSP' for Safari and Chrome. IE 10&11's support is limited to the 'sandbox' directive.",
"usage_perc_y": 55.74,
"usage_perc_a": 12.68,
"ucprefix": false,
"parent": "",
"keywords": "csp,security,header"
},
"pagevisibility": {
"title": "PageVisibility",
"description": "JavaScript API for determining whether a document is visible on the display",
"spec": "http://www.w3.org/TR/page-visibility/",
"status": "cr",
"links": [{
"url": "https://developer.mozilla.org/en-US/docs/DOM/Using_the_Page_Visibility_API",
"title": "MDN article"
}, {
"url": "http://docs.webplatform.org/wiki/apis/timing/properties/visibilityState",
"title": "WebPlatform Docs"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "y",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y x"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "y",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 63.89,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "visibilitystate"
},
"stricttransportsecurity": {
"title": "Strict Transport Security",
"description": "Declare that a website is only accessible over a secure connection (HTTPS).",
"spec": "http://tools.ietf.org/html/rfc6797",
"status": "other",
"links": [{
"url": "http://dev.chromium.org/sts",
"title": "Strict Transport Security @ Chromium"
}, {
"url": "https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security",
"title": "Strict Transport Security @ Mozilla Developer Network"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "u"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "The HTTP header is 'Strict-Transport-Security'.",
"usage_perc_y": 50.76,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "sts,hsts,security,header"
},
"style-scoped": {
"title": "Scoped CSS",
"description": "Allows CSS rules to be scoped to part of the document, based on the position of the style element.",
"spec": "http://www.w3.org/TR/html5/document-metadata.html#attr-style-scoped",
"status": "cr",
"links": [{
"url": "https://github.com/PM5544/scoped-polyfill",
"title": "Polyfill"
}, {
"url": "http://html5doctor.com/the-scoped-attribute/",
"title": "HTML5 Doctor article"
}, {
"url": "http://updates.html5rocks.com/2012/03/A-New-Experimental-Feature-style-scoped",
"title": "HTML5Rocks article"
}],
"categories": ["CSS", "HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "u",
"32": "u"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "u",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Supported in Chrome 20+ by enabling the \"experimental WebKit features\" flag in chrome://flags.",
"usage_perc_y": 13.05,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "scope"
},
"svg-fragment": {
"title": "SVG fragment identifiers",
"description": "Method of displaying only a part of an SVG image by defining a view ID or view box dimensions as the file's fragment identifier.",
"spec": "http://www.w3.org/TR/SVG/linking.html#SVGFragmentIdentifiers",
"status": "rec",
"links": [{
"url": "http://www.broken-links.com/2012/08/14/better-svg-sprites-with-fragment-identifiers/",
"title": "Blog post"
}],
"categories": ["SVG"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "u",
"32": "u"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "u",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 25.15,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "fragments,sprite"
},
"outline": {
"title": "CSS outline",
"description": "The CSS outline property is a shorthand property for setting one or more of the individual outline properties outline-style, outline-width and outline-color in a single rule. In most cases the use of this shortcut is preferable and more convenient.",
"spec": "http://www.w3.org/TR/CSS2/ui.html#propdef-outline",
"status": "rec",
"links": [{
"url": "https://developer.mozilla.org/en-US/docs/CSS/outline",
"title": "Mozilla Developer Network: outline"
}, {
"url": "http://dev.w3.org/csswg/css3-ui/#outline",
"title": "CSS Basic User Interface Module Level 3"
}],
"categories": ["CSS2"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "y",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y",
"3": "y",
"3.5": "y",
"3.6": "y",
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "y",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "y",
"4.0-4.1": "y",
"4.2-4.3": "y",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y",
"2.2": "y",
"2.3": "y",
"3": "y",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 89.27,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "-moz-outline,outline-width,outline-style,outline-color"
},
"download": {
"title": "Download attribute",
"description": "When used on an anchor, this attribute signifies that the resource it points to should be downloaded by the browser rather than navigate to it.",
"spec": "http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#downloading-resources",
"status": "wd",
"links": [{
"url": "http://html5-demos.appspot.com/static/a.download.html",
"title": "Demo: creating a text file and downloading it."
}, {
"url": "http://updates.html5rocks.com/2011/08/Downloading-resources-in-HTML5-a-download",
"title": "HTML5Rocks post"
}],
"categories": ["HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 48.02,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "download,a.download,a[download],download attribute"
},
"pointer": {
"title": "Pointer events",
"description": "This specification integrates various inputs from mice, touchscreens, and pens, making separate implementations no longer necessary and authoring for cross-device pointers easier. Not to be mistaken with the unrelated \"pointer-events\" CSS property.",
"spec": "http://www.w3.org/TR/pointerevents/",
"status": "cr",
"links": [{
"url": "http://blogs.msdn.com/b/eternalcoding/archive/2013/01/16/hand-js-a-polyfill-for-supporting-pointer-events-on-every-browser.aspx",
"title": "Hand.js, the polyfill for browsers only supporting Touch Events"
}, {
"url": "http://blogs.msdn.com/b/ie/archive/2011/09/20/touch-input-for-ie10-and-metro-style-apps.aspx",
"title": "Implementation of Pointer Events in IE10"
}, {
"url": "http://blogs.msdn.com/b/davrous/archive/2013/02/20/handling-touch-in-your-html5-apps-thanks-to-the-pointer-events-of-ie10-and-windows-8.aspx",
"title": "Article & tutorial"
}],
"categories": ["DOM", "JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "a x",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p",
"12": "p",
"13": "p",
"14": "p",
"15": "p",
"16": "p",
"17": "p",
"18": "p",
"19": "p",
"20": "p",
"21": "p",
"22": "p",
"23": "p",
"24": "p",
"25": "p",
"26": "p",
"27": "p"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "p",
"23": "p",
"24": "p",
"25": "p",
"26": "p",
"27": "p",
"28": "p",
"29": "p",
"30": "p",
"31": "p",
"32": "p"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "p",
"16": "p",
"17": "p",
"18": "p"
},
"ios_saf": {
"3.2": "p",
"4.0-4.1": "p",
"4.2-4.3": "p",
"5.0-5.1": "p",
"6.0-6.1": "p",
"7.0": "p"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "p",
"2.2": "p",
"2.3": "p",
"3": "p",
"4": "p",
"4.1": "p",
"4.2-4.3": "p",
"4.4": "p"
},
"bb": {
"7": "p",
"10": "p"
},
"op_mob": {
"10": "n",
"11": "p",
"11.1": "p",
"11.5": "p",
"12": "p",
"12.1": "p",
"0": "p"
},
"and_chr": {
"0": "p"
},
"and_ff": {
"0": "p"
},
"ie_mob": {
"10": "a x"
}
},
"notes": "Partial support in IE10 refers the lack of pointerenter and pointerleave events.",
"usage_perc_y": 0.11,
"usage_perc_a": 10.99,
"ucprefix": false,
"parent": "",
"keywords": "pointerdown,pointermove,pointerup,pointercancel,pointerover,pointerout,pointerenter,pointerleave"
},
"user-select-none": {
"title": "CSS user-select: none",
"description": "Method of preventing text/element selection using CSS. ",
"spec": "https://developer.mozilla.org/en-US/docs/CSS/user-select",
"status": "unoff",
"links": [{
"url": "http://msdn.microsoft.com/en-us/library/ie/hh781492(v=vs.85).aspx",
"title": "MSDN Documentation"
}, {
"url": "https://developer.mozilla.org/en-US/docs/CSS/user-select",
"title": "MDN article"
}, {
"url": "http://css-tricks.com/almanac/properties/u/user-select/",
"title": "CSS Tricks article"
}],
"categories": ["CSS"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y x",
"11": "y x"
},
"firefox": {
"2": "y x",
"3": "y x",
"3.5": "y x",
"3.6": "y x",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x"
},
"chrome": {
"4": "u",
"5": "u",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "y x",
"3.2": "y x",
"4": "y x",
"5": "y x",
"5.1": "y x",
"6": "y x",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "y x",
"4.0-4.1": "y x",
"4.2-4.3": "y x",
"5.0-5.1": "y x",
"6.0-6.1": "y x",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "y x",
"2.2": "y x",
"2.3": "y x",
"3": "y x",
"4": "y x",
"4.1": "y x",
"4.2-4.3": "y x",
"4.4": "y x"
},
"bb": {
"7": "y x",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "y x"
}
},
"notes": "Currently the user-select property does not appear in any W3C specification. Support information here is only for \"none\" value, not others.",
"usage_perc_y": 74.91,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"webp": {
"title": "WebP image format",
"description": "Image format that supports lossy and lossless compression, as well as animation and alpha transparency.",
"spec": "https://developers.google.com/speed/webp/",
"status": "other",
"links": [{
"url": "http://libwebpjs.appspot.com/",
"title": "Decoder in JS"
}, {
"url": "https://developers.google.com/speed/webp/",
"title": "Official website"
}, {
"url": "http://antimatter15.github.io/weppy/demo.html",
"title": "Polyfill for browsers with WebM support"
}, {
"url": "http://webpjs.appspot.com/",
"title": "Polyfill for browsers with or without WebM support (i.e. IE6-IE9, Safari/iOS version 6.1 and below; Firefox versions 24 and bel"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "p",
"5": "p",
"6": "p",
"7": "p",
"8": "p",
"9": "p",
"10": "p",
"11": "p",
"12": "p",
"13": "p",
"14": "p",
"15": "p",
"16": "p",
"17": "p",
"18": "p",
"19": "p",
"20": "p",
"21": "p",
"22": "p",
"23": "p",
"24": "p",
"25": "p",
"26": "p",
"27": "p"
},
"chrome": {
"4": "n",
"5": "n",
"6": "p",
"7": "p",
"8": "p",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "p",
"11": "p",
"11.1": "p",
"11.5": "p",
"11.6": "p",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "y",
"4.1": "y",
"4.2-4.3": "y",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "a",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Animated webp images are supported in Chrome 32+ and Opera 19+.",
"usage_perc_y": 39.4,
"usage_perc_a": 0.01,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"intrinsic-width": {
"title": "Intrinsic & Extrinsic Sizing",
"description": "Allows for the heights and widths to be specified in intrinsic values using the fill-available, max-content, min-content, and fit-content properties.",
"spec": "http://www.w3.org/TR/css3-sizing/",
"status": "wd",
"links": [{
"url": "http://demosthenes.info/blog/662/Design-From-the-Inside-Out-With-CSS-MinContent",
"title": "Min-Content tutorial"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "y x",
"7": "y x"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "y x"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y x"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Prefixes are on the values, not the property names (e.g. -webkit-min-content) Firefox currently supports the \"-moz-available\" property rather than \"-moz-fill-available\".",
"usage_perc_y": 51.68,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "fill-available,max-content,min-content,fit-content,contain-floats"
},
"template": {
"title": "HTML templates",
"description": "Method of declaring a portion of reusable markup that is parsed but not rendered until cloned.",
"spec": "http://www.w3.org/TR/html-templates/",
"status": "wd",
"links": [{
"url": "http://www.html5rocks.com/en/tutorials/webcomponents/template/",
"title": "HTML5Rocks - HTML's New template Tag"
}, {
"url": "http://polymer-project.org",
"title": "Polymer project (polyfill & web compontents framework)"
}],
"categories": ["DOM", "HTML5"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 45.76,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "web components, template"
},
"opus": {
"title": "Opus",
"description": "Royalty-free open audio codec by IETF, which incorporated SILK from Skype and CELT from Xiph.org, to serve higher sound quality and lower latency at the same bitrate.",
"spec": "http://tools.ietf.org/html/rfc6716",
"status": "other",
"links": [{
"url": "https://hacks.mozilla.org/2012/07/firefox-beta-15-supports-the-new-opus-audio-format/",
"title": "Introduction of Opus by Mozilla"
}, {
"url": "http://www.ietf.org/mail-archive/web/rtcweb/current/msg04953.html",
"title": "Google's statement about the use of VP8 and Opus codec for WebRTC standard"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "n",
"32": "n"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "u"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Chrome does not support Opus by default but users can enable it via the 'enable-opus-playback' flag. When it comes to Opera, it is said that the Linux version may be able to play it when the GStreamer module is up to date and the served mime-type is 'audio/ogg'.",
"usage_perc_y": 14.04,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "audio",
"keywords": ""
},
"jpegxr": {
"title": "JPEG XR image format",
"description": "The latest JPEG image format of Joint Photographic Experts Group which boasts better compression and supports lossless compression, alpha channel, and 48-bit deep color over normal jpg format.",
"spec": "http://www.itu.int/rec/T-REC-T.832",
"status": "other",
"links": [{
"url": "http://msdn.microsoft.com/en-us/library/windows/desktop/hh707223(v=vs.85).aspx",
"title": "Microsoft JPEG XR Codec Overview"
}],
"categories": ["Other"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "n",
"31": "n",
"32": "n"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "n",
"7": "n"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "n"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 16.32,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
},
"channel-messaging": {
"title": "Channel messaging",
"description": "Method for having two-way communication between browsing contexts (using MessageChannel)",
"spec": "http://www.w3.org/TR/webmessaging/#channel-messaging",
"status": "cr",
"links": [{
"url": "http://dev.opera.com/articles/view/window-postmessage-messagechannel/#channel",
"title": "An Introduction to HTML5 web messaging"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "y",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "u",
"10.0-10.1": "u",
"10.5": "u",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "y",
"6.0-6.1": "y",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "u",
"11": "y",
"11.1": "y",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 55.07,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "x-doc-messaging",
"keywords": ""
},
"css3-tabsize": {
"title": "CSS3 tab-size",
"description": "Method of customizing the width of a tab character. Only effective using 'white-space: pre'.",
"spec": "http://www.w3.org/TR/css3-text/#tab-size1",
"status": "wd",
"links": [{
"url": "https://developer.mozilla.org/en-US/docs/Web/CSS/tab-size",
"title": "MDN article"
}],
"categories": ["CSS3"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "y x",
"11": "y x",
"11.1": "y x",
"11.5": "y x",
"11.6": "y x",
"12": "y x",
"12.1": "y x",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "y",
"10": "y"
},
"op_mob": {
"10": "n",
"11": "y x",
"11.1": "y x",
"11.5": "y x",
"12": "y x",
"12.1": "y x",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 53.05,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "tab-size,tab-width"
},
"mutationobserver": {
"title": "Mutation Observer",
"description": "Method for observing and reacting to changes to the DOM. Replaces MutationEvents, which is deprecated.",
"spec": "http://www.w3.org/TR/dom/",
"status": "wd",
"links": [{
"url": "https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver",
"title": "MutationObserver from MDN"
}, {
"url": "https://github.com/Polymer/MutationObservers",
"title": "Polyfill"
}],
"categories": ["DOM", "JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "p",
"10": "p",
"11": "y"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "y x",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "y x",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "p",
"4.1": "p",
"4.2-4.3": "p",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "y x"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "p"
}
},
"notes": "When the content of a node with a single CharacterData child node is changed by innerHTML attribute and the node have a single different one as a result, WebKit browsers consider it as a characterData mutation of the child CharacterData node, while other browsers think it as a childList mutation of the parent node.",
"usage_perc_y": 54.8,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "MutationObserver"
},
"css-selection": {
"title": "::selection CSS pseudo-element",
"description": "The ::selection CSS pseudo-element applies rules to the portion of a document that has been highlighted (e.g., selected with the mouse or another pointing device) by the user.",
"spec": "https://developer.mozilla.org/en-US/docs/Web/CSS/::selection",
"status": "unoff",
"links": [{
"url": "http://docs.webplatform.org/wiki/css/selectors/pseudo-elements/::selection",
"title": "WebPlatform Docs"
}, {
"url": "http://quirksmode.org/css/selectors/selection.html",
"title": "::selection test"
}],
"categories": ["CSS"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "y",
"10": "y",
"11": "y"
},
"firefox": {
"2": "y x",
"3": "y x",
"3.5": "y x",
"3.6": "y x",
"4": "y x",
"5": "y x",
"6": "y x",
"7": "y x",
"8": "y x",
"9": "y x",
"10": "y x",
"11": "y x",
"12": "y x",
"13": "y x",
"14": "y x",
"15": "y x",
"16": "y x",
"17": "y x",
"18": "y x",
"19": "y x",
"20": "y x",
"21": "y x",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x"
},
"chrome": {
"4": "y",
"5": "y",
"6": "y",
"7": "y",
"8": "y",
"9": "y",
"10": "y",
"11": "y",
"12": "y",
"13": "y",
"14": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y",
"19": "y",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y",
"28": "y",
"29": "y",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "y",
"3.2": "y",
"4": "y",
"5": "y",
"5.1": "y",
"6": "y",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "y",
"10.0-10.1": "y",
"10.5": "y",
"10.6": "y",
"11": "y",
"11.1": "y",
"11.5": "y",
"11.6": "y",
"12": "y",
"12.1": "y",
"15": "y",
"16": "y",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "u",
"11": "u",
"11.1": "u",
"11.5": "y",
"12": "y",
"12.1": "y",
"0": "y"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "n"
},
"ie_mob": {
"10": "y"
}
},
"notes": "",
"usage_perc_y": 71.68,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": "::selection,selection"
},
"canvas-blending": {
"title": "Canvas blend modes",
"description": "Method of defining the effect resulting from overlaying two layers on a Canvas element. ",
"spec": "http://www.w3.org/TR/compositing-1/#blending",
"status": "wd",
"links": [{
"url": "http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/",
"title": "Blog post"
}],
"categories": ["Canvas"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "y",
"21": "y",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "n",
"24": "n",
"25": "n",
"26": "n",
"27": "n",
"28": "n",
"29": "n",
"30": "y",
"31": "y",
"32": "y"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "y",
"7": "y"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "y",
"18": "y"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "y"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "y"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "n"
},
"and_chr": {
"0": "y"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "",
"usage_perc_y": 42.33,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "canvas",
"keywords": ""
},
"clipboard": {
"title": "Clipboard API",
"description": "API to provide copy, cut and paste functionality using the OS clipboard.",
"spec": "http://www.w3.org/TR/clipboard-apis/",
"status": "wd",
"links": [{
"url": "http://www.deluxeblogtips.com/2010/06/javascript-copy-to-clipboard.html",
"title": "Blog post on cross-browser usage"
}, {
"url": "https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent",
"title": "MDN page on ClipboardEvent"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "a #1",
"6": "a #1",
"7": "a #1",
"8": "a #1",
"9": "a #1",
"10": "a #1",
"11": "a #1"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "y",
"23": "y",
"24": "y",
"25": "y",
"26": "y",
"27": "y"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "a",
"14": "a",
"15": "a",
"16": "a",
"17": "a",
"18": "a",
"19": "a",
"20": "a",
"21": "a",
"22": "a",
"23": "a",
"24": "a",
"25": "a",
"26": "a",
"27": "a",
"28": "a",
"29": "a",
"30": "a",
"31": "a",
"32": "a"
},
"safari": {
"3.1": "u",
"3.2": "u",
"4": "a",
"5": "a",
"5.1": "a",
"6": "a",
"6.1": "a",
"7": "a"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "a",
"17": "a",
"18": "a"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "a",
"6.0-6.1": "a",
"7.0": "a"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "a"
},
"bb": {
"7": "n",
"10": "a"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "a"
},
"and_chr": {
"0": "a"
},
"and_ff": {
"0": "y"
},
"ie_mob": {
"10": "n"
}
},
"notes": "Partial support in IE refers using <a href=\"http://msdn.microsoft.com/en-us/library/ie/ms535220%28v=vs.85%29.aspx\">a non-standard method</a> of interacting with the clipboard. For other browsers it refers to not supporting the ClipboardEvent constructor.",
"usage_perc_y": 12.83,
"usage_perc_a": 67.91,
"ucprefix": false,
"parent": "",
"keywords": "cut,copy,paste,clipboarddata"
},
"rtcpeerconnection": {
"title": "WebRTC Peer-to-peer connections",
"description": "Method of allowing two users to communicate directly, browser to browser using the RTCPeerConnection API.",
"spec": "http://www.w3.org/TR/webrtc/#peer-to-peer-connections",
"status": "wd",
"links": [{
"url": "http://www.webrtc.org/",
"title": "WebRTC Project site"
}],
"categories": ["JS API"],
"stats": {
"ie": {
"5.5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n"
},
"firefox": {
"2": "n",
"3": "n",
"3.5": "n",
"3.6": "n",
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "y x",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x"
},
"chrome": {
"4": "n",
"5": "n",
"6": "n",
"7": "n",
"8": "n",
"9": "n",
"10": "n",
"11": "n",
"12": "n",
"13": "n",
"14": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n",
"19": "n",
"20": "n",
"21": "n",
"22": "n",
"23": "y x",
"24": "y x",
"25": "y x",
"26": "y x",
"27": "y x",
"28": "y x",
"29": "y x",
"30": "y x",
"31": "y x",
"32": "y x"
},
"safari": {
"3.1": "n",
"3.2": "n",
"4": "n",
"5": "n",
"5.1": "n",
"6": "n",
"6.1": "u",
"7": "u"
},
"opera": {
"9": "n",
"9.5-9.6": "n",
"10.0-10.1": "n",
"10.5": "n",
"10.6": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"11.6": "n",
"12": "n",
"12.1": "n",
"15": "n",
"16": "n",
"17": "n",
"18": "n"
},
"ios_saf": {
"3.2": "n",
"4.0-4.1": "n",
"4.2-4.3": "n",
"5.0-5.1": "n",
"6.0-6.1": "n",
"7.0": "n"
},
"op_mini": {
"5.0-7.0": "n"
},
"android": {
"2.1": "n",
"2.2": "n",
"2.3": "n",
"3": "n",
"4": "n",
"4.1": "n",
"4.2-4.3": "n",
"4.4": "n"
},
"bb": {
"7": "n",
"10": "n"
},
"op_mob": {
"10": "n",
"11": "n",
"11.1": "n",
"11.5": "n",
"12": "n",
"12.1": "n",
"0": "y x"
},
"and_chr": {
"0": "y x"
},
"and_ff": {
"0": "y x"
},
"ie_mob": {
"10": "n"
}
},
"notes": "BlackBerry 10 recognizes RTCPeerConnection but real support is unconfirmed.",
"usage_perc_y": 46.24,
"usage_perc_a": 0,
"ucprefix": false,
"parent": "",
"keywords": ""
}
}
}
},{}],36:[function(require,module,exports){
/**
* Abstract implementation of edit tree interface.
* Edit tree is a named container of editable “name-value” child elements,
* parsed from <code>source</code>. This container provides convenient methods
* for editing/adding/removing child elements. All these update actions are
* instantly reflected in the <code>source</code> code with respect of formatting.
* <br><br>
* For example, developer can create an edit tree from CSS rule and add or
* remove properties from itall changes will be immediately reflected in the
* original source.
* <br><br>
* All classes defined in this module should be extended the same way as in
* Backbone framework: using <code>extend</code> method to create new class and
* <code>initialize</code> method to define custom class constructor.
*
* @example
* <pre><code>
* var MyClass = require('editTree/base').EditElement.extend({
* initialize: function() {
* // constructor code here
* }
* });
*
* var elem = new MyClass();
* </code></pre>
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var range = require('../assets/range');
var utils = require('../utils/common');
var klass = require('../vendor/klass');
/**
* Named container of edited source
* @type EditContainer
* @param {String} source
* @param {Object} options
*/
function EditContainer(source, options) {
this.options = utils.extend({offset: 0}, options);
/**
* Source code of edited structure. All changes in the structure are
* immediately reflected into this property
*/
this.source = source;
/**
* List of all editable children
* @private
*/
this._children = [];
/**
* Hash of all positions of container
* @private
*/
this._positions = {
name: 0
};
this.initialize.apply(this, arguments);
}
/**
* The self-propagating extend function for classes.
* @type Function
*/
EditContainer.extend = klass.extend;
EditContainer.prototype = {
type: 'container',
/**
* Child class constructor
*/
initialize: function() {},
/**
* Make position absolute
* @private
* @param {Number} num
* @param {Boolean} isAbsolute
* @returns {Boolean}
*/
_pos: function(num, isAbsolute) {
return num + (isAbsolute ? this.options.offset : 0);
},
/**
* Replace substring of tag's source
* @param {String} value
* @param {Number} start
* @param {Number} end
* @private
*/
_updateSource: function(value, start, end) {
// create modification range
var r = range.create(start, typeof end === 'undefined' ? 0 : end - start);
var delta = value.length - r.length();
var update = function(obj) {
Object.keys(obj).forEach(function(k) {
if (obj[k] >= r.end) {
obj[k] += delta;
}
});
};
// update affected positions of current container
update(this._positions);
// update affected positions of children
var recursiveUpdate = function(items) {
items.forEach(function(item) {
update(item._positions);
if (item.type == 'container') {
recursiveUpdate(item.list());
}
});
};
recursiveUpdate(this.list());
this.source = utils.replaceSubstring(this.source, value, r);
},
/**
* Adds new attribute
* @param {String} name Property name
* @param {String} value Property value
* @param {Number} pos Position at which to insert new property. By
* default the property is inserted at the end of rule
* @returns {EditElement} Newly created element
*/
add: function(name, value, pos) {
// this is abstract implementation
var item = new EditElement(name, value);
this._children.push(item);
return item;
},
/**
* Returns attribute object
* @param {String} name Attribute name or its index
* @returns {EditElement}
*/
get: function(name) {
if (typeof name === 'number') {
return this.list()[name];
}
if (typeof name === 'string') {
return utils.find(this.list(), function(prop) {
return prop.name() === name;
});
}
return name;
},
/**
* Returns all children by name or indexes
* @param {Object} name Element name(s) or indexes (<code>String</code>,
* <code>Array</code>, <code>Number</code>)
* @returns {Array}
*/
getAll: function(name) {
if (!Array.isArray(name))
name = [name];
// split names and indexes
var names = [], indexes = [];
name.forEach(function(item) {
if (typeof item === 'string') {
names.push(item);
} else if (typeof item === 'number') {
indexes.push(item);
}
});
return this.list().filter(function(attribute, i) {
return ~indexes.indexOf(i) || ~names.indexOf(attribute.name());
});
},
/**
* Returns list of all editable child elements
* @returns {Array}
*/
list: function() {
return this._children;
},
/**
* Remove child element
* @param {String} name Property name or its index
*/
remove: function(name) {
var element = this.get(name);
if (element) {
this._updateSource('', element.fullRange());
var ix = this._children.indexOf(element);
if (~ix) {
this._children.splice(ix, 1);
}
}
},
/**
* Returns index of editble child in list
* @param {Object} item
* @returns {Number}
*/
indexOf: function(item) {
return this.list().indexOf(this.get(item));
},
/**
* Returns or updates element value. If such element doesn't exists,
* it will be created automatically and added at the end of child list.
* @param {String} name Element name or its index
* @param {String} value New element value
* @returns {String}
*/
value: function(name, value, pos) {
var element = this.get(name);
if (element)
return element.value(value);
if (typeof value !== 'undefined') {
// no such element — create it
return this.add(name, value, pos);
}
},
/**
* Returns all values of child elements found by <code>getAll()</code>
* method
* @param {Object} name Element name(s) or indexes (<code>String</code>,
* <code>Array</code>, <code>Number</code>)
* @returns {Array}
*/
values: function(name) {
return this.getAll(name).map(function(element) {
return element.value();
});
},
/**
* Sets or gets container name
* @param {String} val New name. If not passed, current
* name is returned
* @return {String}
*/
name: function(val) {
if (typeof val !== 'undefined' && this._name !== (val = String(val))) {
this._updateSource(val, this._positions.name, this._positions.name + this._name.length);
this._name = val;
}
return this._name;
},
/**
* Returns name range object
* @param {Boolean} isAbsolute Return absolute range (with respect of
* rule offset)
* @returns {Range}
*/
nameRange: function(isAbsolute) {
return range.create(this._positions.name + (isAbsolute ? this.options.offset : 0), this.name());
},
/**
* Returns range of current source
* @param {Boolean} isAbsolute
*/
range: function(isAbsolute) {
return range.create(isAbsolute ? this.options.offset : 0, this.valueOf());
},
/**
* Returns element that belongs to specified position
* @param {Number} pos
* @param {Boolean} isAbsolute
* @returns {EditElement}
*/
itemFromPosition: function(pos, isAbsolute) {
return utils.find(this.list(), function(elem) {
return elem.range(isAbsolute).inside(pos);
});
},
/**
* Returns source code of current container
* @returns {String}
*/
toString: function() {
return this.valueOf();
},
valueOf: function() {
return this.source;
}
};
/**
* @param {EditContainer} parent
* @param {Object} nameToken
* @param {Object} valueToken
*/
function EditElement(parent, nameToken, valueToken) {
/** @type EditContainer */
this.parent = parent;
this._name = nameToken.value;
this._value = valueToken ? valueToken.value : '';
this._positions = {
name: nameToken.start,
value: valueToken ? valueToken.start : -1
};
this.initialize.apply(this, arguments);
}
/**
* The self-propagating extend function for classes.
* @type Function
*/
EditElement.extend = klass.extend;
EditElement.prototype = {
type: 'element',
/**
* Child class constructor
*/
initialize: function() {},
/**
* Make position absolute
* @private
* @param {Number} num
* @param {Boolean} isAbsolute
* @returns {Boolean}
*/
_pos: function(num, isAbsolute) {
return num + (isAbsolute ? this.parent.options.offset : 0);
},
/**
* Sets of gets element value
* @param {String} val New element value. If not passed, current
* value is returned
* @returns {String}
*/
value: function(val) {
if (typeof val !== 'undefined' && this._value !== (val = String(val))) {
this.parent._updateSource(val, this.valueRange());
this._value = val;
}
return this._value;
},
/**
* Sets of gets element name
* @param {String} val New element name. If not passed, current
* name is returned
* @returns {String}
*/
name: function(val) {
if (typeof val !== 'undefined' && this._name !== (val = String(val))) {
this.parent._updateSource(val, this.nameRange());
this._name = val;
}
return this._name;
},
/**
* Returns position of element name token
* @param {Boolean} isAbsolute Return absolute position
* @returns {Number}
*/
namePosition: function(isAbsolute) {
return this._pos(this._positions.name, isAbsolute);
},
/**
* Returns position of element value token
* @param {Boolean} isAbsolute Return absolute position
* @returns {Number}
*/
valuePosition: function(isAbsolute) {
return this._pos(this._positions.value, isAbsolute);
},
/**
* Returns element name
* @param {Boolean} isAbsolute Return absolute range
* @returns {Range}
*/
range: function(isAbsolute) {
return range.create(this.namePosition(isAbsolute), this.valueOf());
},
/**
* Returns full element range, including possible indentation
* @param {Boolean} isAbsolute Return absolute range
* @returns {Range}
*/
fullRange: function(isAbsolute) {
return this.range(isAbsolute);
},
/**
* Returns element name range
* @param {Boolean} isAbsolute Return absolute range
* @returns {Range}
*/
nameRange: function(isAbsolute) {
return range.create(this.namePosition(isAbsolute), this.name());
},
/**
* Returns element value range
* @param {Boolean} isAbsolute Return absolute range
* @returns {Range}
*/
valueRange: function(isAbsolute) {
return range.create(this.valuePosition(isAbsolute), this.value());
},
/**
* Returns current element string representation
* @returns {String}
*/
toString: function() {
return this.valueOf();
},
valueOf: function() {
return this.name() + this.value();
}
};
return {
EditContainer: EditContainer,
EditElement: EditElement,
/**
* Creates token that can be fed to <code>EditElement</code>
* @param {Number} start
* @param {String} value
* @param {String} type
* @returns
*/
createToken: function(start, value, type) {
var obj = {
start: start || 0,
value: value || '',
type: type
};
obj.end = obj.start + obj.value.length;
return obj;
}
};
});
},{"../assets/range":30,"../utils/common":73,"../vendor/klass":78}],37:[function(require,module,exports){
/**
* CSS EditTree is a module that can parse a CSS rule into a tree with
* convenient methods for adding, modifying and removing CSS properties. These
* changes can be written back to string with respect of code formatting.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var editTree = require('./base');
var cssParser = require('../parser/css');
var cssSections = require('../utils/cssSections');
var range = require('../assets/range');
var stringStream = require('../assets/stringStream');
var tokenIterator = require('../assets/tokenIterator');
var defaultOptions = {
styleBefore: '\n\t',
styleSeparator: ': ',
offset: 0
};
var reSpaceStart = /^\s+/;
var reSpaceEnd = /\s+$/;
var WHITESPACE_REMOVE_FROM_START = 1;
var WHITESPACE_REMOVE_FROM_END = 2;
/**
* Modifies given range to remove whitespace from beginning
* and/or from the end
* @param {Range} rng Range to modify
* @param {String} text Text that range belongs to
* @param {Number} mask Mask indicating from which end
* whitespace should be removed
* @return {Range}
*/
function trimWhitespaceInRange(rng, text, mask) {
mask = mask || (WHITESPACE_REMOVE_FROM_START | WHITESPACE_REMOVE_FROM_END);
text = rng.substring(text);
var m;
if ((mask & WHITESPACE_REMOVE_FROM_START) && (m = text.match(reSpaceStart))) {
rng.start += m[0].length;
}
if ((mask & WHITESPACE_REMOVE_FROM_END) && (m = text.match(reSpaceEnd))) {
rng.end -= m[0].length;
}
// in case given range is just a whatespace
if (rng.end < rng.start) {
rng.end = rng.start;
}
return rng;
}
/**
* Consumes CSS property and value from current token
* iterator state. Offsets iterator pointer into token
* that can be used for next value consmption
* @param {TokenIterator} it
* @param {String} text
* @return {Object} Object with `name` and `value` properties
* ar ranges. Value range can be zero-length.
*/
function consumeSingleProperty(it, text) {
var name, value, end;
var token = it.current();
if (!token) {
return null;
}
// skip whitespace
var ws = {'white': 1, 'line': 1, 'comment': 1};
while ((token = it.current())) {
if (!(token.type in ws)) {
break;
}
it.next();
}
if (!it.hasNext()) {
return null;
}
// consume property name
token = it.current();
name = range(token.start, token.value);
var isAtProperty = token.value.charAt(0) == '@';
while (token = it.next()) {
name.end = token.end;
if (token.type == ':' || token.type == 'white') {
name.end = token.start;
it.next();
if (token.type == ':' || isAtProperty) {
// XXX I really ashame of this hardcode, but I need
// to stop parsing if this is an SCSS mixin call,
// for example: @include border-radius(10px)
break;
}
} else if (token.type == ';' || token.type == 'line') {
// theres no value, looks like a mixin
// or a special use case:
// user is writing a new property or abbreviation
name.end = token.start;
value = range(token.start, 0);
it.next();
break;
}
}
token = it.current();
if (!value && token) {
if (token.type == 'line') {
lastNewline = token;
}
// consume value
value = range(token.start, token.value);
var lastNewline;
while ((token = it.next())) {
value.end = token.end;
if (token.type == 'line') {
lastNewline = token;
} else if (token.type == '}' || token.type == ';') {
value.end = token.start;
if (token.type == ';') {
end = range(token.start, token.value);
}
it.next();
break;
} else if (token.type == ':' && lastNewline) {
// A special case:
// user is writing a value before existing
// property, but didnt inserted closing semi-colon.
// In this case, limit value range to previous
// newline
value.end = lastNewline.start;
it._i = it.tokens.indexOf(lastNewline);
break;
}
}
}
if (!value) {
value = range(name.end, 0);
}
return {
name: trimWhitespaceInRange(name, text),
value: trimWhitespaceInRange(value, text, WHITESPACE_REMOVE_FROM_START | (end ? WHITESPACE_REMOVE_FROM_END : 0)),
end: end || range(value.end, 0)
};
}
/**
* Finds parts of complex CSS value
* @param {String} str
* @returns {Array} Returns list of <code>Range</code>'s
*/
function findParts(str) {
/** @type StringStream */
var stream = stringStream.create(str);
var ch;
var result = [];
var sep = /[\s\u00a0,;]/;
var add = function() {
stream.next();
result.push(range(stream.start, stream.current()));
stream.start = stream.pos;
};
// skip whitespace
stream.eatSpace();
stream.start = stream.pos;
while ((ch = stream.next())) {
if (ch == '"' || ch == "'") {
stream.next();
if (!stream.skipTo(ch)) break;
add();
} else if (ch == '(') {
// function found, may have nested function
stream.backUp(1);
if (!stream.skipToPair('(', ')')) break;
stream.backUp(1);
add();
} else {
if (sep.test(ch)) {
result.push(range(stream.start, stream.current().length - 1));
stream.eatWhile(sep);
stream.start = stream.pos;
}
}
}
add();
return utils.unique(result.filter(function(item) {
return !!item.length();
}));
}
/**
* Parses CSS properties from given CSS source
* and adds them to CSSEditContainer node
* @param {CSSEditContainer} node
* @param {String} source CSS source
* @param {Number} offset Offset of properties subset from original source
*/
function consumeProperties(node, source, offset) {
var list = extractPropertiesFromSource(source, offset);
list.forEach(function(property) {
node._children.push(new CSSEditElement(node,
editTree.createToken(property.name.start, property.nameText),
editTree.createToken(property.value.start, property.valueText),
editTree.createToken(property.end.start, property.endText)
));
});
}
/**
* Parses given CSS source and returns list of ranges of located CSS properties.
* Normally, CSS source must contain properties only, it must be,
* for example, a content of CSS selector or text between nested
* CSS sections
* @param {String} source CSS source
* @param {Number} offset Offset of properties subset from original source.
* Used to provide proper ranges of locates items
*/
function extractPropertiesFromSource(source, offset) {
offset = offset || 0;
source = source.replace(reSpaceEnd, '');
var out = [];
if (!source) {
return out;
}
var tokens = cssParser.parse(source);
var it = tokenIterator.create(tokens);
var property;
while ((property = consumeSingleProperty(it, source))) {
out.push({
nameText: property.name.substring(source),
name: property.name.shift(offset),
valueText: property.value.substring(source),
value: property.value.shift(offset),
endText: property.end.substring(source),
end: property.end.shift(offset)
});
}
return out;
}
/**
* @class
* @extends EditContainer
*/
var CSSEditContainer = editTree.EditContainer.extend({
initialize: function(source, options) {
utils.extend(this.options, defaultOptions, options);
if (Array.isArray(source)) {
source = cssParser.toSource(source);
}
var allRules = cssSections.findAllRules(source);
var currentRule = allRules.shift();
// keep top-level rules only since they will
// be parsed by nested CSSEditContainer call
var topLevelRules = [];
allRules.forEach(function(r) {
var isTopLevel = !utils.find(topLevelRules, function(tr) {
return tr.contains(r);
});
if (isTopLevel) {
topLevelRules.push(r);
}
});
var selectorRange = range.create2(currentRule.start, currentRule._selectorEnd);
this._name = selectorRange.substring(source);
this._positions.name = selectorRange.start;
this._positions.contentStart = currentRule._contentStart + 1;
var sectionOffset = currentRule._contentStart + 1;
var sectionEnd = currentRule.end - 1;
// parse properties between nested rules
// and add nested rules as children
var that = this;
topLevelRules.forEach(function(r) {
consumeProperties(that, source.substring(sectionOffset, r.start), sectionOffset);
var opt = utils.extend({}, that.options, {offset: r.start + that.options.offset});
// XXX I think I dont need nested containers here
// They should be handled separately
// that._children.push(new CSSEditContainer(r.substring(source), opt));
sectionOffset = r.end;
});
// consume the rest of data
consumeProperties(this, source.substring(sectionOffset, currentRule.end - 1), sectionOffset);
this._saveStyle();
},
/**
* Remembers all styles of properties
* @private
*/
_saveStyle: function() {
var start = this._positions.contentStart;
var source = this.source;
this.list().forEach(function(p) {
if (p.type === 'container') {
return;
}
p.styleBefore = source.substring(start, p.namePosition());
// a small hack here:
// Sometimes users add empty lines before properties to logically
// separate groups of properties. In this case, a blind copy of
// characters between rules may lead to undesired behavior,
// especially when current rule is duplicated or used as a donor
// to create new rule.
// To solve this issue, well take only last newline indentation
var lines = utils.splitByLines(p.styleBefore);
if (lines.length > 1) {
p.styleBefore = '\n' + lines[lines.length - 1];
}
p.styleSeparator = source.substring(p.nameRange().end, p.valuePosition());
// graceful and naive comments removal
var parts = p.styleBefore.split('*/');
p.styleBefore = parts[parts.length - 1];
p.styleSeparator = p.styleSeparator.replace(/\/\*.*?\*\//g, '');
start = p.range().end;
});
},
/**
* Returns position of element name token
* @param {Boolean} isAbsolute Return absolute position
* @returns {Number}
*/
namePosition: function(isAbsolute) {
return this._pos(this._positions.name, isAbsolute);
},
/**
* Returns position of element value token
* @param {Boolean} isAbsolute Return absolute position
* @returns {Number}
*/
valuePosition: function(isAbsolute) {
return this._pos(this._positions.contentStart, isAbsolute);
},
/**
* Returns element value range
* @param {Boolean} isAbsolute Return absolute range
* @returns {Range}
*/
valueRange: function(isAbsolute) {
return range.create2(this.valuePosition(isAbsolute), this._pos(this.valueOf().length, isAbsolute) - 1);
},
/**
* Adds new CSS property
* @param {String} name Property name
* @param {String} value Property value
* @param {Number} pos Position at which to insert new property. By
* default the property is inserted at the end of rule
* @returns {CSSEditProperty}
*/
add: function(name, value, pos) {
var list = this.list();
var start = this._positions.contentStart;
var styles = utils.pick(this.options, 'styleBefore', 'styleSeparator');
if (typeof pos === 'undefined') {
pos = list.length;
}
/** @type CSSEditProperty */
var donor = list[pos];
if (donor) {
start = donor.fullRange().start;
} else if ((donor = list[pos - 1])) {
// make sure that donor has terminating semicolon
donor.end(';');
start = donor.range().end;
}
if (donor) {
styles = utils.pick(donor, 'styleBefore', 'styleSeparator');
}
var nameToken = editTree.createToken(start + styles.styleBefore.length, name);
var valueToken = editTree.createToken(nameToken.end + styles.styleSeparator.length, value);
var property = new CSSEditElement(this, nameToken, valueToken,
editTree.createToken(valueToken.end, ';'));
utils.extend(property, styles);
// write new property into the source
this._updateSource(property.styleBefore + property.toString(), start);
// insert new property
this._children.splice(pos, 0, property);
return property;
}
});
/**
* @class
* @type CSSEditElement
* @constructor
*/
var CSSEditElement = editTree.EditElement.extend({
initialize: function(rule, name, value, end) {
this.styleBefore = rule.options.styleBefore;
this.styleSeparator = rule.options.styleSeparator;
this._end = end.value;
this._positions.end = end.start;
},
/**
* Returns ranges of complex value parts
* @returns {Array} Returns <code>null</code> if value is not complex
*/
valueParts: function(isAbsolute) {
var parts = findParts(this.value());
if (isAbsolute) {
var offset = this.valuePosition(true);
parts.forEach(function(p) {
p.shift(offset);
});
}
return parts;
},
/**
* Sets of gets element value.
* When setting value, this implementation will ensure that your have
* proper name-value separator
* @param {String} val New element value. If not passed, current
* value is returned
* @returns {String}
*/
value: function(val) {
var isUpdating = typeof val !== 'undefined';
var allItems = this.parent.list();
if (isUpdating && this.isIncomplete()) {
var self = this;
var donor = utils.find(allItems, function(item) {
return item !== self && !item.isIncomplete();
});
this.styleSeparator = donor
? donor.styleSeparator
: this.parent.options.styleSeparator;
this.parent._updateSource(this.styleSeparator, range(this.valueRange().start, 0));
}
var value = this.constructor.__super__.value.apply(this, arguments);
if (isUpdating) {
// make sure current property has terminating semi-colon
// if its not the last one
var ix = allItems.indexOf(this);
if (ix !== allItems.length - 1 && !this.end()) {
this.end(';');
}
}
return value;
},
/**
* Test if current element is incomplete, e.g. has no explicit
* name-value separator
* @return {Boolean} [description]
*/
isIncomplete: function() {
return this.nameRange().end === this.valueRange().start;
},
/**
* Sets of gets property end value (basically, it's a semicolon)
* @param {String} val New end value. If not passed, current
* value is returned
*/
end: function(val) {
if (typeof val !== 'undefined' && this._end !== val) {
this.parent._updateSource(val, this._positions.end, this._positions.end + this._end.length);
this._end = val;
}
return this._end;
},
/**
* Returns full rule range, with indentation
* @param {Boolean} isAbsolute Return absolute range (with respect of
* rule offset)
* @returns {Range}
*/
fullRange: function(isAbsolute) {
var r = this.range(isAbsolute);
r.start -= this.styleBefore.length;
return r;
},
/**
* Returns item string representation
* @returns {String}
*/
valueOf: function() {
return this.name() + this.styleSeparator + this.value() + this.end();
}
});
return {
/**
* Parses CSS rule into editable tree
* @param {String} source
* @param {Object} options
* @memberOf emmet.cssEditTree
* @returns {EditContainer}
*/
parse: function(source, options) {
return new CSSEditContainer(source, options);
},
/**
* Extract and parse CSS rule from specified position in <code>content</code>
* @param {String} content CSS source code
* @param {Number} pos Character position where to start source code extraction
* @returns {EditContainer}
*/
parseFromPosition: function(content, pos, isBackward) {
var bounds = cssSections.locateRule(content, pos, isBackward);
if (!bounds || !bounds.inside(pos)) {
// no matching CSS rule or caret outside rule bounds
return null;
}
return this.parse(bounds.substring(content), {
offset: bounds.start
});
},
/**
* Locates CSS property in given CSS code fragment under specified character position
* @param {String} css CSS code or parsed CSSEditContainer
* @param {Number} pos Character position where to search CSS property
* @return {CSSEditElement}
*/
propertyFromPosition: function(css, pos) {
var cssProp = null;
/** @type EditContainer */
var cssRule = typeof css === 'string' ? this.parseFromPosition(css, pos, true) : css;
if (cssRule) {
cssProp = cssRule.itemFromPosition(pos, true);
if (!cssProp) {
// in case user just started writing CSS property
// and didn't include semicolontry another approach
cssProp = utils.find(cssRule.list(), function(elem) {
return elem.range(true).end == pos;
});
}
}
return cssProp;
},
/**
* Removes vendor prefix from CSS property
* @param {String} name CSS property
* @return {String}
*/
baseName: function(name) {
return name.replace(/^\s*\-\w+\-/, '');
},
/**
* Finds parts of complex CSS value
* @param {String} str
* @returns {Array}
*/
findParts: findParts,
extractPropertiesFromSource: extractPropertiesFromSource
};
});
},{"../assets/range":30,"../assets/stringStream":32,"../assets/tokenIterator":34,"../parser/css":56,"../utils/common":73,"../utils/cssSections":74,"./base":36}],38:[function(require,module,exports){
/**
* XML EditTree is a module that can parse an XML/HTML element into a tree with
* convenient methods for adding, modifying and removing attributes. These
* changes can be written back to string with respect of code formatting.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var editTree = require('./base');
var xmlParser = require('../parser/xml');
var range = require('../assets/range');
var utils = require('../utils/common');
var defaultOptions = {
styleBefore: ' ',
styleSeparator: '=',
styleQuote: '"',
offset: 0
};
var startTag = /^<([\w\:\-]+)((?:\s+[\w\-:]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/m;
var XMLEditContainer = editTree.EditContainer.extend({
initialize: function(source, options) {
utils.defaults(this.options, defaultOptions);
this._positions.name = 1;
var attrToken = null;
var tokens = xmlParser.parse(source);
tokens.forEach(function(token) {
token.value = range.create(token).substring(source);
switch (token.type) {
case 'tag':
if (/^<[^\/]+/.test(token.value)) {
this._name = token.value.substring(1);
}
break;
case 'attribute':
// add empty attribute
if (attrToken) {
this._children.push(new XMLEditElement(this, attrToken));
}
attrToken = token;
break;
case 'string':
this._children.push(new XMLEditElement(this, attrToken, token));
attrToken = null;
break;
}
}, this);
if (attrToken) {
this._children.push(new XMLEditElement(this, attrToken));
}
this._saveStyle();
},
/**
* Remembers all styles of properties
* @private
*/
_saveStyle: function() {
var start = this.nameRange().end;
var source = this.source;
this.list().forEach(function(p) {
p.styleBefore = source.substring(start, p.namePosition());
if (p.valuePosition() !== -1) {
p.styleSeparator = source.substring(p.namePosition() + p.name().length, p.valuePosition() - p.styleQuote.length);
}
start = p.range().end;
});
},
/**
* Adds new attribute
* @param {String} name Property name
* @param {String} value Property value
* @param {Number} pos Position at which to insert new property. By
* default the property is inserted at the end of rule
*/
add: function(name, value, pos) {
var list = this.list();
var start = this.nameRange().end;
var styles = utils.pick(this.options, 'styleBefore', 'styleSeparator', 'styleQuote');
if (typeof pos === 'undefined') {
pos = list.length;
}
/** @type XMLEditAttribute */
var donor = list[pos];
if (donor) {
start = donor.fullRange().start;
} else if ((donor = list[pos - 1])) {
start = donor.range().end;
}
if (donor) {
styles = utils.pick(donor, 'styleBefore', 'styleSeparator', 'styleQuote');
}
value = styles.styleQuote + value + styles.styleQuote;
var attribute = new XMLEditElement(this,
editTree.createToken(start + styles.styleBefore.length, name),
editTree.createToken(start + styles.styleBefore.length + name.length
+ styles.styleSeparator.length, value)
);
utils.extend(attribute, styles);
// write new attribute into the source
this._updateSource(attribute.styleBefore + attribute.toString(), start);
// insert new attribute
this._children.splice(pos, 0, attribute);
return attribute;
},
/**
* A special case of attribute editing: adds class value to existing
* `class` attribute
* @param {String} value
*/
addClass: function(value) {
var attr = this.get('class');
value = utils.trim(value);
if (!attr) {
return this.add('class', value);
}
var classVal = attr.value();
var classList = ' ' + classVal.replace(/\n/g, ' ') + ' ';
if (!~classList.indexOf(' ' + value + ' ')) {
attr.value(classVal + ' ' + value);
}
},
/**
* A special case of attribute editing: removes class value from existing
* `class` attribute
* @param {String} value
*/
removeClass: function(value) {
var attr = this.get('class');
value = utils.trim(value);
if (!attr) {
return;
}
var reClass = new RegExp('(^|\\s+)' + utils.escapeForRegexp(value));
var classVal = attr.value().replace(reClass, '');
if (!utils.trim(classVal)) {
this.remove('class');
} else {
attr.value(classVal);
}
}
});
var XMLEditElement = editTree.EditElement.extend({
initialize: function(parent, nameToken, valueToken) {
this.styleBefore = parent.options.styleBefore;
this.styleSeparator = parent.options.styleSeparator;
var value = '', quote = parent.options.styleQuote;
if (valueToken) {
value = valueToken.value;
quote = value.charAt(0);
if (quote == '"' || quote == "'") {
value = value.substring(1);
} else {
quote = '';
}
if (quote && value.charAt(value.length - 1) == quote) {
value = value.substring(0, value.length - 1);
}
}
this.styleQuote = quote;
this._value = value;
this._positions.value = valueToken ? valueToken.start + quote.length : -1;
},
/**
* Returns full rule range, with indentation
* @param {Boolean} isAbsolute Return absolute range (with respect of
* rule offset)
* @returns {Range}
*/
fullRange: function(isAbsolute) {
var r = this.range(isAbsolute);
r.start -= this.styleBefore.length;
return r;
},
valueOf: function() {
return this.name() + this.styleSeparator
+ this.styleQuote + this.value() + this.styleQuote;
}
});
return {
/**
* Parses HTML element into editable tree
* @param {String} source
* @param {Object} options
* @memberOf emmet.htmlEditTree
* @returns {EditContainer}
*/
parse: function(source, options) {
return new XMLEditContainer(source, options);
},
/**
* Extract and parse HTML from specified position in <code>content</code>
* @param {String} content CSS source code
* @param {Number} pos Character position where to start source code extraction
* @returns {XMLEditElement}
*/
parseFromPosition: function(content, pos, isBackward) {
var bounds = this.extractTag(content, pos, isBackward);
if (!bounds || !bounds.inside(pos))
// no matching HTML tag or caret outside tag bounds
return null;
return this.parse(bounds.substring(content), {
offset: bounds.start
});
},
/**
* Extracts nearest HTML tag range from <code>content</code>, starting at
* <code>pos</code> position
* @param {String} content
* @param {Number} pos
* @param {Boolean} isBackward
* @returns {Range}
*/
extractTag: function(content, pos, isBackward) {
var len = content.length, i;
// max extraction length. I don't think there may be tags larger
// than 2000 characters length
var maxLen = Math.min(2000, len);
/** @type Range */
var r = null;
var match = function(pos) {
var m;
if (content.charAt(pos) == '<' && (m = content.substr(pos, maxLen).match(startTag)))
return range.create(pos, m[0]);
};
// lookup backward, in case we are inside tag already
for (i = pos; i >= 0; i--) {
if ((r = match(i))) break;
}
if (r && (r.inside(pos) || isBackward))
return r;
if (!r && isBackward)
return null;
// search forward
for (i = pos; i < len; i++) {
if ((r = match(i)))
return r;
}
}
};
});
},{"../assets/range":30,"../parser/xml":62,"../utils/common":73,"./base":36}],39:[function(require,module,exports){
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var global = typeof self != 'undefined' ? self : this;
var utils = require('./utils/common');
var actions = require('./action/main');
var parser = require('./parser/abbreviation');
var file = require('./plugin/file');
var preferences = require('./assets/preferences');
var resources = require('./assets/resources');
var profile = require('./assets/profile');
var ciu = require('./assets/caniuse');
var logger = require('./assets/logger');
var sliceFn = Array.prototype.slice;
/**
* Returns file name part from path
* @param {String} path Path to file
* @return {String}
*/
function getFileName(path) {
var re = /([\w\.\-]+)$/i;
var m = re.exec(path);
return m ? m[1] : '';
}
/**
* Normalizes profile definition: converts some
* properties to valid data types
* @param {Object} profile
* @return {Object}
*/
function normalizeProfile(profile) {
if (typeof profile === 'object') {
if ('indent' in profile) {
profile.indent = !!profile.indent;
}
if ('self_closing_tag' in profile) {
if (typeof profile.self_closing_tag === 'number') {
profile.self_closing_tag = !!profile.self_closing_tag;
}
}
}
return profile;
}
return {
/**
* The essential function that expands Emmet abbreviation
* @param {String} abbr Abbreviation to parse
* @param {String} syntax Abbreviation's context syntax
* @param {String} profile Output profile (or its name)
* @param {Object} contextNode Contextual node where abbreviation is
* written
* @return {String}
*/
expandAbbreviation: function(abbr, syntax, profile, contextNode) {
return parser.expand(abbr, {
syntax: syntax,
profile: profile,
contextNode: contextNode
});
},
/**
* Runs given action
* @param {String} name Action name
* @param {IEmmetEditor} editor Editor instance
* @return {Boolean} Returns true if action was performed successfully
*/
run: function(name) {
return actions.run.apply(actions, sliceFn.call(arguments, 0));
},
/**
* Loads Emmet extensions. Extensions are simple .js files that
* uses Emmet modules and resources to create new actions, modify
* existing ones etc.
* @param {Array} fileList List of absolute paths to files in extensions
* folder. Back-end app should not filter this list (e.g. by extension)
* but return it "as-is" so bootstrap can decide how to load contents
* of each file.
* This method requires a <code>file</code> module of <code>IEmmetFile</code>
* interface to be implemented.
* @memberOf bootstrap
*/
loadExtensions: function(fileList) {
var payload = {};
var userSnippets = null;
var that = this;
// make sure file list contians only valid extension files
fileList = fileList.filter(function(f) {
var ext = file.getExt(f);
return ext === 'json' || ext === 'js';
});
var reader = (file.readText || file.read).bind(file);
var next = function() {
if (fileList.length) {
var f = fileList.shift();
reader(f, function(err, content) {
if (err) {
logger.log('Unable to read "' + f + '" file: '+ err);
return next();
}
switch (file.getExt(f)) {
case 'js':
try {
eval(content);
} catch (e) {
logger.log('Unable to eval "' + f + '" file: '+ e);
}
break;
case 'json':
var fileName = getFileName(f).toLowerCase().replace(/\.json$/, '');
if (/^snippets/.test(fileName)) {
if (fileName === 'snippets') {
// data in snippets.json is more important to user
userSnippets = utils.parseJSON(content);
} else {
payload.snippets = utils.deepMerge(payload.snippets || {}, utils.parseJSON(content));
}
} else {
payload[fileName] = content;
}
break;
}
next();
});
} else {
// complete
if (userSnippets) {
payload.snippets = utils.deepMerge(payload.snippets || {}, userSnippets);
}
that.loadUserData(payload);
}
};
next();
},
/**
* Loads preferences from JSON object (or string representation of JSON)
* @param {Object} data
* @returns
*/
loadPreferences: function(data) {
preferences.load(utils.parseJSON(data));
},
/**
* Loads user snippets and abbreviations. It doesnt replace current
* user resource vocabulary but merges it with passed one. If you need
* to <i>replaces</i> user snippets you should call
* <code>resetSnippets()</code> method first
*/
loadSnippets: function(data) {
data = utils.parseJSON(data);
var userData = resources.getVocabulary('user') || {};
resources.setVocabulary(utils.deepMerge(userData, data), 'user');
},
/**
* Helper function that loads default snippets, defined in projects
* <i>snippets.json</i>
* @param {Object} data
*/
loadSystemSnippets: function(data) {
resources.setVocabulary(utils.parseJSON(data), 'system');
},
/**
* Helper function that loads Can I Use database
* @param {Object} data
*/
loadCIU: function(data) {
ciu.load(utils.parseJSON(data));
},
/**
* Removes all user-defined snippets
*/
resetSnippets: function() {
resources.setVocabulary({}, 'user');
},
/**
* Helper function that loads all user data (snippets and preferences)
* defined as a single JSON object. This is useful for loading data
* stored in a common storage, for example <code>NSUserDefaults</code>
* @param {Object} data
*/
loadUserData: function(data) {
data = utils.parseJSON(data);
if (data.snippets) {
this.loadSnippets(data.snippets);
}
if (data.preferences) {
this.loadPreferences(data.preferences);
}
if (data.profiles) {
this.loadProfiles(data.profiles);
}
if (data.caniuse) {
this.loadCIU(data.caniuse);
}
var profiles = data.syntaxProfiles || data.syntaxprofiles;
if (profiles) {
this.loadSyntaxProfiles(profiles);
}
},
/**
* Resets all user-defined data: preferences, snippets etc.
* @returns
*/
resetUserData: function() {
this.resetSnippets();
preferences.reset();
profile.reset();
},
/**
* Load syntax-specific output profiles. These are essentially
* an extension to syntax snippets
* @param {Object} profiles Dictionary of profiles
*/
loadSyntaxProfiles: function(profiles) {
profiles = utils.parseJSON(profiles);
var snippets = {};
Object.keys(profiles).forEach(function(syntax) {
var options = profiles[syntax];
if (!(syntax in snippets)) {
snippets[syntax] = {};
}
snippets[syntax].profile = normalizeProfile(options);
});
this.loadSnippets(snippets);
},
/**
* Load named profiles
* @param {Object} profiles
*/
loadProfiles: function(profiles) {
profiles = utils.parseJSON(profiles);
Object.keys(profiles).forEach(function(name) {
profile.create(name, normalizeProfile(profiles[name]));
});
},
require: require,
// expose some useful data for plugin authors
actions: actions,
file: file,
preferences: preferences,
resources: resources,
profile: profile,
tabStops: require('./assets/tabStops'),
htmlMatcher: require('./assets/htmlMatcher'),
utils: {
common: utils,
action: require('./utils/action'),
editor: require('./utils/editor')
}
};
});
},{"./action/main":12,"./assets/caniuse":23,"./assets/htmlMatcher":26,"./assets/logger":27,"./assets/preferences":28,"./assets/profile":29,"./assets/resources":31,"./assets/tabStops":33,"./parser/abbreviation":55,"./plugin/file":63,"./utils/action":70,"./utils/common":73,"./utils/editor":75}],40:[function(require,module,exports){
/**
* Filter for aiding of writing elements with complex class names as described
* in Yandex's BEM (Block, Element, Modifier) methodology. This filter will
* automatically inherit block and element names from parent elements and insert
* them into child element classes
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var htmlFilter = require('./html');
var prefs = require('../assets/preferences');
var abbreviationUtils = require('../utils/abbreviation');
var utils = require('../utils/common');
prefs.define('bem.elementSeparator', '__', 'Class names element separator.');
prefs.define('bem.modifierSeparator', '_', 'Class names modifier separator.');
prefs.define('bem.shortElementPrefix', '-',
'Symbol for describing short “block-element” notation. Class names '
+ 'prefixed with this symbol will be treated as element name for parents '
+ 'block name. Each symbol instance traverses one level up in parsed '
+ 'tree for block name lookup. Empty value will disable short notation.');
var shouldRunHtmlFilter = false;
function getSeparators() {
return {
element: prefs.get('bem.elementSeparator'),
modifier: prefs.get('bem.modifierSeparator')
};
}
/**
* @param {AbbreviationNode} item
*/
function bemParse(item) {
if (abbreviationUtils.isSnippet(item))
return item;
// save BEM stuff in cache for faster lookups
item.__bem = {
block: '',
element: '',
modifier: ''
};
var classNames = normalizeClassName(item.attribute('class')).split(' ');
// guess best match for block name
var reBlockName = /^[a-z]\-/i;
item.__bem.block = utils.find(classNames, function(name) {
return reBlockName.test(name);
});
// guessing doesn't worked, pick first class name as block name
if (!item.__bem.block) {
reBlockName = /^[a-z]/i;
item.__bem.block = utils.find(classNames, function(name) {
return reBlockName.test(name);
}) || '';
}
classNames = classNames.map(function(name) {
return processClassName(name, item);
});
classNames = utils.unique(utils.flatten(classNames)).join(' ');
if (classNames) {
item.attribute('class', classNames);
}
return item;
}
/**
* @param {String} className
* @returns {String}
*/
function normalizeClassName(className) {
className = (' ' + (className || '') + ' ').replace(/\s+/g, ' ');
var shortSymbol = prefs.get('bem.shortElementPrefix');
if (shortSymbol) {
var re = new RegExp('\\s(' + utils.escapeForRegexp(shortSymbol) + '+)', 'g');
className = className.replace(re, function(str, p1) {
return ' ' + utils.repeatString(getSeparators().element, p1.length);
});
}
return utils.trim(className);
}
/**
* Processes class name
* @param {String} name Class name item to process
* @param {AbbreviationNode} item Host node for provided class name
* @returns Processed class name. May return <code>Array</code> of
* class names
*/
function processClassName(name, item) {
name = transformClassName(name, item, 'element');
name = transformClassName(name, item, 'modifier');
// expand class name
// possible values:
// * block__element
// * block__element_modifier
// * block__element_modifier1_modifier2
// * block_modifier
var block = '', element = '', modifier = '';
var separators = getSeparators();
if (~name.indexOf(separators.element)) {
var elements = name.split(separators.element);
block = elements.shift();
var modifiers = elements.pop().split(separators.modifier);
elements.push(modifiers.shift());
element = elements.join(separators.element);
modifier = modifiers.join(separators.modifier);
} else if (~name.indexOf(separators.modifier)) {
var blockModifiers = name.split(separators.modifier);
block = blockModifiers.shift();
modifier = blockModifiers.join(separators.modifier);
}
if (block || element || modifier) {
if (!block) {
block = item.__bem.block;
}
// inherit parent bem element, if exists
// if (item.parent && item.parent.__bem && item.parent.__bem.element)
// element = item.parent.__bem.element + separators.element + element;
// produce multiple classes
var prefix = block;
var result = [];
if (element) {
prefix += separators.element + element;
result.push(prefix);
} else {
result.push(prefix);
}
if (modifier) {
result.push(prefix + separators.modifier + modifier);
}
item.__bem.block = block;
item.__bem.element = element;
item.__bem.modifier = modifier;
return result;
}
// ...otherwise, return processed or original class name
return name;
}
/**
* Low-level function to transform user-typed class name into full BEM class
* @param {String} name Class name item to process
* @param {AbbreviationNode} item Host node for provided class name
* @param {String} entityType Type of entity to be tried to transform
* ('element' or 'modifier')
* @returns {String} Processed class name or original one if it can't be
* transformed
*/
function transformClassName(name, item, entityType) {
var separators = getSeparators();
var reSep = new RegExp('^(' + separators[entityType] + ')+', 'g');
if (reSep.test(name)) {
var depth = 0; // parent lookup depth
var cleanName = name.replace(reSep, function(str) {
depth = str.length / separators[entityType].length;
return '';
});
// find donor element
var donor = item;
while (donor.parent && depth--) {
donor = donor.parent;
}
if (!donor || !donor.__bem)
donor = item;
if (donor && donor.__bem) {
var prefix = donor.__bem.block;
// decide if we should inherit element name
// if (entityType == 'element') {
// var curElem = cleanName.split(separators.modifier, 1)[0];
// if (donor.__bem.element && donor.__bem.element != curElem)
// prefix += separators.element + donor.__bem.element;
// }
if (entityType == 'modifier' && donor.__bem.element)
prefix += separators.element + donor.__bem.element;
return prefix + separators[entityType] + cleanName;
}
}
return name;
}
/**
* Recursive function for processing tags, which extends class names
* according to BEM specs: http://bem.github.com/bem-method/pages/beginning/beginning.ru.html
* <br><br>
* It does several things:<br>
* <ul>
* <li>Expands complex class name (according to BEM symbol semantics):
* .block__elem_modifier → .block.block__elem.block__elem_modifier
* </li>
* <li>Inherits block name on child elements:
* .b-block > .__el > .__el → .b-block > .b-block__el > .b-block__el__el
* </li>
* <li>Treats first dash symbol as '__'</li>
* <li>Double underscore (or typographic '') is also treated as an element
* level lookup, e.g. ____el will search for element definition in parents
* parent element:
* .b-block > .__el1 > .____el2 → .b-block > .b-block__el1 > .b-block__el2
* </li>
* </ul>
*
* @param {AbbreviationNode} tree
* @param {Object} profile
*/
function process(tree, profile) {
if (tree.name) {
bemParse(tree, profile);
}
tree.children.forEach(function(item) {
process(item, profile);
if (!abbreviationUtils.isSnippet(item) && item.start) {
shouldRunHtmlFilter = true;
}
});
return tree;
}
return function(tree, profile) {
shouldRunHtmlFilter = false;
tree = process(tree, profile);
// in case 'bem' filter is applied after 'html' filter: run it again
// to update output
if (shouldRunHtmlFilter) {
tree = htmlFilter(tree, profile);
}
return tree;
};
});
},{"../assets/preferences":28,"../utils/abbreviation":69,"../utils/common":73,"./html":46}],41:[function(require,module,exports){
/**
* Comment important tags (with 'id' and 'class' attributes)
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var prefs = require('../assets/preferences');
var utils = require('../utils/common');
var template = require('../utils/template');
var abbrUtils = require('../utils/abbreviation');
var filterCore = require('./main');
prefs.define('filter.commentAfter',
'\n<!-- /<%= attr("id", "#") %><%= attr("class", ".") %> -->',
'A definition of comment that should be placed <i>after</i> matched '
+ 'element when <code>comment</code> filter is applied. This definition '
+ 'is an ERB-style template passed to <code>_.template()</code> '
+ 'function (see Underscore.js docs for details). In template context, '
+ 'the following properties and functions are availabe:\n'
+ '<ul>'
+ '<li><code>attr(name, before, after)</code> a function that outputs'
+ 'specified attribute value concatenated with <code>before</code> '
+ 'and <code>after</code> strings. If attribute doesn\'t exists, the '
+ 'empty string will be returned.</li>'
+ '<li><code>node</code> current node (instance of <code>AbbreviationNode</code>)</li>'
+ '<li><code>name</code> name of current tag</li>'
+ '<li><code>padding</code> current string padding, can be used '
+ 'for formatting</li>'
+'</ul>');
prefs.define('filter.commentBefore',
'',
'A definition of comment that should be placed <i>before</i> matched '
+ 'element when <code>comment</code> filter is applied. '
+ 'For more info, read description of <code>filter.commentAfter</code> '
+ 'property');
prefs.define('filter.commentTrigger', 'id, class',
'A comma-separated list of attribute names that should exist in abbreviatoin '
+ 'where comment should be added. If you wish to add comment for '
+ 'every element, set this option to <code>*</code>');
/**
* Add comments to tag
* @param {AbbreviationNode} node
*/
function addComments(node, templateBefore, templateAfter) {
// check if comments should be added
var trigger = prefs.get('filter.commentTrigger');
if (trigger != '*') {
var shouldAdd = utils.find(trigger.split(','), function(name) {
return !!node.attribute(utils.trim(name));
});
if (!shouldAdd) {
return;
}
}
var ctx = {
node: node,
name: node.name(),
padding: node.parent ? node.parent.padding : '',
attr: function(name, before, after) {
var attr = node.attribute(name);
if (attr) {
return (before || '') + attr + (after || '');
}
return '';
}
};
var nodeBefore = templateBefore ? templateBefore(ctx) : '';
var nodeAfter = templateAfter ? templateAfter(ctx) : '';
node.start = node.start.replace(/</, nodeBefore + '<');
node.end = node.end.replace(/>/, '>' + nodeAfter);
}
function process(tree, before, after) {
tree.children.forEach(function(item) {
if (abbrUtils.isBlock(item)) {
addComments(item, before, after);
}
process(item, before, after);
});
return tree;
}
return function(tree) {
var templateBefore = template(prefs.get('filter.commentBefore'));
var templateAfter = template(prefs.get('filter.commentAfter'));
return process(tree, templateBefore, templateAfter);
};
});
},{"../assets/preferences":28,"../utils/abbreviation":69,"../utils/common":73,"../utils/template":77,"./main":49}],42:[function(require,module,exports){
/**
* Filter for outputting CSS and alike
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
/**
* Test if passed item is very first child in parsed tree
* @param {AbbreviationNode} item
*/
function isVeryFirstChild(item) {
return item.parent && !item.parent.parent && !item.index();
}
return function process(tree, profile, level) {
level = level || 0;
tree.children.forEach(function(item) {
if (!isVeryFirstChild(item) && profile.tag_nl !== false) {
item.start = '\n' + item.start;
}
process(item, profile, level + 1);
});
return tree;
};
});
},{}],43:[function(require,module,exports){
/**
* Filter for escaping unsafe XML characters: <, >, &
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var charMap = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;'
};
function escapeChars(str) {
return str.replace(/([<>&])/g, function(str, p1){
return charMap[p1];
});
}
return function process(tree) {
tree.children.forEach(function(item) {
item.start = escapeChars(item.start);
item.end = escapeChars(item.end);
item.content = escapeChars(item.content);
process(item);
});
return tree;
};
});
},{}],44:[function(require,module,exports){
/**
* Generic formatting filter: creates proper indentation for each tree node,
* placing "%s" placeholder where the actual output should be. You can use
* this filter to preformat tree and then replace %s placeholder to whatever you
* need. This filter should't be called directly from editor as a part
* of abbreviation.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var abbrUtils = require('../utils/abbreviation');
var prefs = require('../assets/preferences');
var resources = require('../assets/resources');
prefs.define('format.noIndentTags', 'html',
'A comma-separated list of tag names that should not get inner indentation.');
prefs.define('format.forceIndentationForTags', 'body',
'A comma-separated list of tag names that should <em>always</em> get inner indentation.');
var placeholder = '%s';
/**
* Get indentation for given node
* @param {AbbreviationNode} node
* @returns {String}
*/
function getIndentation(node) {
var items = prefs.getArray('format.noIndentTags') || [];
if (~items.indexOf(node.name())) {
return '';
}
return '\t';
}
/**
* Test if passed node has block-level sibling element
* @param {AbbreviationNode} item
* @return {Boolean}
*/
function hasBlockSibling(item) {
return item.parent && abbrUtils.hasBlockChildren(item.parent);
}
/**
* Test if passed item is very first child in parsed tree
* @param {AbbreviationNode} item
*/
function isVeryFirstChild(item) {
return item.parent && !item.parent.parent && !item.index();
}
/**
* Check if a newline should be added before element
* @param {AbbreviationNode} node
* @param {OutputProfile} profile
* @return {Boolean}
*/
function shouldAddLineBreak(node, profile) {
if (profile.tag_nl === true || abbrUtils.isBlock(node))
return true;
if (!node.parent || !profile.inline_break)
return false;
// check if there are required amount of adjacent inline element
return shouldFormatInline(node.parent, profile);
}
/**
* Need to add newline because <code>item</code> has too many inline children
* @param {AbbreviationNode} node
* @param {OutputProfile} profile
*/
function shouldBreakChild(node, profile) {
// we need to test only one child element, because
// hasBlockChildren() method will do the rest
return node.children.length && shouldAddLineBreak(node.children[0], profile);
}
function shouldFormatInline(node, profile) {
var nodeCount = 0;
return !!utils.find(node.children, function(child) {
if (child.isTextNode() || !abbrUtils.isInline(child))
nodeCount = 0;
else if (abbrUtils.isInline(child))
nodeCount++;
if (nodeCount >= profile.inline_break)
return true;
});
}
function isRoot(item) {
return !item.parent;
}
/**
* Processes element with matched resource of type <code>snippet</code>
* @param {AbbreviationNode} item
* @param {OutputProfile} profile
*/
function processSnippet(item, profile) {
item.start = item.end = '';
if (!isVeryFirstChild(item) && profile.tag_nl !== false && shouldAddLineBreak(item, profile)) {
// check if were not inside inline element
if (isRoot(item.parent) || !abbrUtils.isInline(item.parent)) {
item.start = '\n' + item.start;
}
}
return item;
}
/**
* Check if we should add line breaks inside inline element
* @param {AbbreviationNode} node
* @param {OutputProfile} profile
* @return {Boolean}
*/
function shouldBreakInsideInline(node, profile) {
var hasBlockElems = node.children.some(function(child) {
if (abbrUtils.isSnippet(child))
return false;
return !abbrUtils.isInline(child);
});
if (!hasBlockElems) {
return shouldFormatInline(node, profile);
}
return true;
}
/**
* Processes element with <code>tag</code> type
* @param {AbbreviationNode} item
* @param {OutputProfile} profile
*/
function processTag(item, profile) {
item.start = item.end = placeholder;
var isUnary = abbrUtils.isUnary(item);
var nl = '\n';
var indent = getIndentation(item);
// formatting output
if (profile.tag_nl !== false) {
var forceNl = profile.tag_nl === true && (profile.tag_nl_leaf || item.children.length);
if (!forceNl) {
var forceIndentTags = prefs.getArray('format.forceIndentationForTags') || [];
forceNl = ~forceIndentTags.indexOf(item.name());
}
// formatting block-level elements
if (!item.isTextNode()) {
if (shouldAddLineBreak(item, profile)) {
// - do not indent the very first element
// - do not indent first child of a snippet
if (!isVeryFirstChild(item) && (!abbrUtils.isSnippet(item.parent) || item.index()))
item.start = nl + item.start;
if (abbrUtils.hasBlockChildren(item) || shouldBreakChild(item, profile) || (forceNl && !isUnary))
item.end = nl + item.end;
if (abbrUtils.hasTagsInContent(item) || (forceNl && !item.children.length && !isUnary))
item.start += nl + indent;
} else if (abbrUtils.isInline(item) && hasBlockSibling(item) && !isVeryFirstChild(item)) {
item.start = nl + item.start;
} else if (abbrUtils.isInline(item) && shouldBreakInsideInline(item, profile)) {
item.end = nl + item.end;
}
item.padding = indent;
}
}
return item;
}
/**
* Processes simplified tree, making it suitable for output as HTML structure
* @param {AbbreviationNode} tree
* @param {OutputProfile} profile
* @param {Number} level Depth level
*/
return function process(tree, profile, level) {
level = level || 0;
tree.children.forEach(function(item) {
if (abbrUtils.isSnippet(item)) {
processSnippet(item, profile, level);
} else {
processTag(item, profile, level);
}
process(item, profile, level + 1);
});
return tree;
};
});
},{"../assets/preferences":28,"../assets/resources":31,"../utils/abbreviation":69,"../utils/common":73}],45:[function(require,module,exports){
/**
* Filter for producing HAML code from abbreviation.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var abbrUtils = require('../utils/abbreviation');
var formatFilter = require('./format');
function transformClassName(className) {
return utils.trim(className).replace(/\s+/g, '.');
}
/**
* Condenses all "data-" attributes into a single entry.
* HAML allows data attributes to be ouputted as a sub-hash
* of `:data` key
* @param {Array} attrs
* @return {Array}
*/
function condenseDataAttrs(attrs) {
var out = [], data = null;
var reData = /^data-/i;
attrs.forEach(function(attr) {
if (reData.test(attr.name)) {
if (!data) {
data = [];
out.push({
name: 'data',
value: data
});
}
data.push(utils.extend({}, attr, {name: attr.name.replace(reData, '')}));
} else {
out.push(attr);
}
});
return out;
}
function stringifyAttrs(attrs, profile) {
var attrQuote = profile.attributeQuote();
return '{' + attrs.map(function(attr) {
var value = attrQuote + attr.value + attrQuote;
if (Array.isArray(attr.value)) {
value = stringifyAttrs(attr.value, profile);
} else if (attr.isBoolean) {
value = 'true';
}
return ':' + attr.name + ' => ' + value
}).join(', ') + '}';
}
/**
* Creates HAML attributes string from tag according to profile settings
* @param {AbbreviationNode} tag
* @param {Object} profile
*/
function makeAttributesString(tag, profile) {
var attrs = '';
var otherAttrs = [];
var attrQuote = profile.attributeQuote();
var cursor = profile.cursor();
tag.attributeList().forEach(function(a) {
var attrName = profile.attributeName(a.name);
switch (attrName.toLowerCase()) {
// use short notation for ID and CLASS attributes
case 'id':
attrs += '#' + (a.value || cursor);
break;
case 'class':
attrs += '.' + transformClassName(a.value || cursor);
break;
// process other attributes
default:
otherAttrs.push({
name: attrName,
value: a.value || cursor,
isBoolean: profile.isBoolean(a.name, a.value)
});
}
});
if (otherAttrs.length) {
attrs += stringifyAttrs(condenseDataAttrs(otherAttrs), profile);
}
return attrs;
}
/**
* Processes element with <code>tag</code> type
* @param {AbbreviationNode} item
* @param {OutputProfile} profile
*/
function processTag(item, profile) {
if (!item.parent)
// looks like it's root element
return item;
var attrs = makeAttributesString(item, profile);
var cursor = profile.cursor();
var isUnary = abbrUtils.isUnary(item);
var selfClosing = profile.self_closing_tag && isUnary ? '/' : '';
var start= '';
// define tag name
var tagName = '%' + profile.tagName(item.name());
if (tagName.toLowerCase() == '%div' && attrs && attrs.indexOf('{') == -1)
// omit div tag
tagName = '';
item.end = '';
start = tagName + attrs + selfClosing;
if (item.content && !/^\s/.test(item.content)) {
item.content = ' ' + item.content;
}
var placeholder = '%s';
// We can't just replace placeholder with new value because
// JavaScript will treat double $ character as a single one, assuming
// we're using RegExp literal.
item.start = utils.replaceSubstring(item.start, start, item.start.indexOf(placeholder), placeholder);
if (!item.children.length && !isUnary)
item.start += cursor;
return item;
}
return function process(tree, profile, level) {
level = level || 0;
if (!level) {
tree = formatFilter(tree, '_format', profile);
}
tree.children.forEach(function(item) {
if (!abbrUtils.isSnippet(item)) {
processTag(item, profile, level);
}
process(item, profile, level + 1);
});
return tree;
};
});
},{"../utils/abbreviation":69,"../utils/common":73,"./format":44}],46:[function(require,module,exports){
/**
* Filter that produces HTML tree
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var abbrUtils = require('../utils/abbreviation');
var utils = require('../utils/common');
var tabStops = require('../assets/tabStops');
var formatFilter = require('./format');
/**
* Creates HTML attributes string from tag according to profile settings
* @param {AbbreviationNode} node
* @param {OutputProfile} profile
*/
function makeAttributesString(node, profile) {
var attrQuote = profile.attributeQuote();
var cursor = profile.cursor();
return node.attributeList().map(function(a) {
var isBoolean = profile.isBoolean(a.name, a.value);
var attrName = profile.attributeName(a.name);
var attrValue = isBoolean ? attrName : a.value;
if (isBoolean && profile.allowCompactBoolean()) {
return ' ' + attrName;
}
return ' ' + attrName + '=' + attrQuote + (attrValue || cursor) + attrQuote;
}).join('');
}
/**
* Processes element with <code>tag</code> type
* @param {AbbreviationNode} item
* @param {OutputProfile} profile
*/
function processTag(item, profile) {
if (!item.parent) { // looks like it's root element
return item;
}
var attrs = makeAttributesString(item, profile);
var cursor = profile.cursor();
var isUnary = abbrUtils.isUnary(item);
var start = '';
var end = '';
// define opening and closing tags
if (!item.isTextNode()) {
var tagName = profile.tagName(item.name());
if (isUnary) {
start = '<' + tagName + attrs + profile.selfClosing() + '>';
item.end = '';
} else {
start = '<' + tagName + attrs + '>';
end = '</' + tagName + '>';
}
}
var placeholder = '%s';
// We can't just replace placeholder with new value because
// JavaScript will treat double $ character as a single one, assuming
// we're using RegExp literal.
item.start = utils.replaceSubstring(item.start, start, item.start.indexOf(placeholder), placeholder);
item.end = utils.replaceSubstring(item.end, end, item.end.indexOf(placeholder), placeholder);
// should we put caret placeholder after opening tag?
if (
!item.children.length
&& !isUnary
&& !~item.content.indexOf(cursor)
&& !tabStops.extract(item.content).tabstops.length
) {
item.start += cursor;
}
return item;
}
return function process(tree, profile, level) {
level = level || 0;
if (!level) {
tree = formatFilter(tree, profile, level)
}
tree.children.forEach(function(item) {
if (!abbrUtils.isSnippet(item)) {
processTag(item, profile, level);
}
process(item, profile, level + 1);
});
return tree;
};
});
},{"../assets/tabStops":33,"../utils/abbreviation":69,"../utils/common":73,"./format":44}],47:[function(require,module,exports){
/**
* Filter for producing Jade code from abbreviation.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var abbrUtils = require('../utils/abbreviation');
var formatFilter = require('./format');
var tabStops = require('../assets/tabStops');
var profile = require('../assets/profile');
var reNl = /[\n\r]/;
var reIndentedText = /^\s*\|/;
var reSpace = /^\s/;
function transformClassName(className) {
return utils.trim(className).replace(/\s+/g, '.');
}
function stringifyAttrs(attrs, profile) {
var attrQuote = profile.attributeQuote();
return '(' + attrs.map(function(attr) {
if (attr.isBoolean) {
return attr.name;
}
return attr.name + '=' + attrQuote + attr.value + attrQuote;
}).join(', ') + ')';
}
/**
* Creates HAML attributes string from tag according to profile settings
* @param {AbbreviationNode} tag
* @param {Object} profile
*/
function makeAttributesString(tag, profile) {
var attrs = '';
var otherAttrs = [];
var attrQuote = profile.attributeQuote();
var cursor = profile.cursor();
tag.attributeList().forEach(function(a) {
var attrName = profile.attributeName(a.name);
switch (attrName.toLowerCase()) {
// use short notation for ID and CLASS attributes
case 'id':
attrs += '#' + (a.value || cursor);
break;
case 'class':
attrs += '.' + transformClassName(a.value || cursor);
break;
// process other attributes
default:
otherAttrs.push({
name: attrName,
value: a.value || cursor,
isBoolean: profile.isBoolean(a.name, a.value)
});
}
});
if (otherAttrs.length) {
attrs += stringifyAttrs(otherAttrs, profile);
}
return attrs;
}
function processTagContent(item) {
if (!item.content) {
return;
}
var content = tabStops.replaceVariables(item.content, function(str, name) {
if (name === 'nl' || name === 'newline') {
return '\n';
}
return str;
});
if (reNl.test(content) && !reIndentedText.test(content)) {
// multiline content: pad it with indentation and pipe
var pad = '| ';
item.content = '\n' + pad + utils.padString(content, pad);
} else if (!reSpace.test(content)) {
item.content = ' ' + content;
}
}
/**
* Processes element with <code>tag</code> type
* @param {AbbreviationNode} item
* @param {OutputProfile} profile
*/
function processTag(item, profile) {
if (!item.parent)
// looks like it's a root (empty) element
return item;
var attrs = makeAttributesString(item, profile);
var cursor = profile.cursor();
var isUnary = abbrUtils.isUnary(item);
// define tag name
var tagName = profile.tagName(item.name());
if (tagName.toLowerCase() == 'div' && attrs && attrs.charAt(0) != '(')
// omit div tag
tagName = '';
item.end = '';
var start = tagName + attrs;
processTagContent(item);
var placeholder = '%s';
// We can't just replace placeholder with new value because
// JavaScript will treat double $ character as a single one, assuming
// we're using RegExp literal.
item.start = utils.replaceSubstring(item.start, start, item.start.indexOf(placeholder), placeholder);
if (!item.children.length && !isUnary)
item.start += cursor;
return item;
}
return function process(tree, curProfile, level) {
level = level || 0;
if (!level) {
// always format with `xml` profile since
// Jade requires all tags to be on separate lines
tree = formatFilter(tree, profile.get('xml'));
}
tree.children.forEach(function(item) {
if (!abbrUtils.isSnippet(item)) {
processTag(item, curProfile, level);
}
process(item, curProfile, level + 1);
});
return tree;
};
});
},{"../assets/profile":29,"../assets/tabStops":33,"../utils/abbreviation":69,"../utils/common":73,"./format":44}],48:[function(require,module,exports){
/**
* A filter for React.js (JSX):
* ranames attributes like `class` and `for`
* for proper representation in JSX
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var attrMap = {
'class': 'className',
'for': 'htmlFor'
};
return function process(tree) {
tree.children.forEach(function(item) {
item._attributes.forEach(function(attr) {
if (attr.name in attrMap) {
attr.name = attrMap[attr.name]
}
});
process(item);
});
return tree;
};
});
},{}],49:[function(require,module,exports){
/**
* Module for handling filters
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var profile = require('../assets/profile');
var resources = require('../assets/resources');
/** List of registered filters */
var registeredFilters = {
html: require('./html'),
haml: require('./haml'),
jade: require('./jade'),
jsx: require('./jsx'),
slim: require('./slim'),
xsl: require('./xsl'),
css: require('./css'),
bem: require('./bem'),
c: require('./comment'),
e: require('./escape'),
s: require('./singleLine'),
t: require('./trim')
};
/** Filters that will be applied for unknown syntax */
var basicFilters = 'html';
function list(filters) {
if (!filters)
return [];
if (typeof filters === 'string') {
return filters.split(/[\|,]/g);
}
return filters;
}
return {
/**
* Register new filter
* @param {String} name Filter name
* @param {Function} fn Filter function
*/
add: function(name, fn) {
registeredFilters[name] = fn;
},
/**
* Apply filters for final output tree
* @param {AbbreviationNode} tree Output tree
* @param {Array} filters List of filters to apply. Might be a
* <code>String</code>
* @param {Object} profile Output profile, defined in <i>profile</i>
* module. Filters defined it profile are not used, <code>profile</code>
* is passed to filter function
* @memberOf emmet.filters
* @returns {AbbreviationNode}
*/
apply: function(tree, filters, profileName) {
profileName = profile.get(profileName);
list(filters).forEach(function(filter) {
var name = utils.trim(filter.toLowerCase());
if (name && name in registeredFilters) {
tree = registeredFilters[name](tree, profileName);
}
});
return tree;
},
/**
* Composes list of filters that should be applied to a tree, based on
* passed data
* @param {String} syntax Syntax name ('html', 'css', etc.)
* @param {Object} profile Output profile
* @param {String} additionalFilters List or pipe-separated
* string of additional filters to apply
* @returns {Array}
*/
composeList: function(syntax, profileName, additionalFilters) {
profileName = profile.get(profileName);
var filters = list(profileName.filters || resources.findItem(syntax, 'filters') || basicFilters);
if (profileName.extraFilters) {
filters = filters.concat(list(profileName.extraFilters));
}
if (additionalFilters) {
filters = filters.concat(list(additionalFilters));
}
if (!filters || !filters.length) {
// looks like unknown syntax, apply basic filters
filters = list(basicFilters);
}
return filters;
},
/**
* Extracts filter list from abbreviation
* @param {String} abbr
* @returns {Array} Array with cleaned abbreviation and list of
* extracted filters
*/
extract: function(abbr) {
var filters = '';
abbr = abbr.replace(/\|([\w\|\-]+)$/, function(str, p1){
filters = p1;
return '';
});
return [abbr, list(filters)];
}
};
});
},{"../assets/profile":29,"../assets/resources":31,"../utils/common":73,"./bem":40,"./comment":41,"./css":42,"./escape":43,"./haml":45,"./html":46,"./jade":47,"./jsx":48,"./singleLine":50,"./slim":51,"./trim":52,"./xsl":53}],50:[function(require,module,exports){
/**
* Output abbreviation on a single line (i.e. no line breaks)
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var abbrUtils = require('../utils/abbreviation');
var rePad = /^\s+/;
var reNl = /[\n\r]/g;
return function process(tree) {
tree.children.forEach(function(item) {
if (!abbrUtils.isSnippet(item)) {
// remove padding from item
item.start = item.start.replace(rePad, '');
item.end = item.end.replace(rePad, '');
}
// remove newlines
item.start = item.start.replace(reNl, '');
item.end = item.end.replace(reNl, '');
item.content = item.content.replace(reNl, '');
process(item);
});
return tree;
};
});
},{"../utils/abbreviation":69}],51:[function(require,module,exports){
/**
* Filter for producing Jade code from abbreviation.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var abbrUtils = require('../utils/abbreviation');
var formatFilter = require('./format');
var tabStops = require('../assets/tabStops');
var prefs = require('../assets/preferences');
var profile = require('../assets/profile');
var reNl = /[\n\r]/;
var reIndentedText = /^\s*\|/;
var reSpace = /^\s/;
prefs.define('slim.attributesWrapper', 'none',
'Defines how attributes will be wrapped:' +
'<ul>' +
'<li><code>none</code> no wrapping;</li>' +
'<li><code>round</code> — wrap attributes with round braces;</li>' +
'<li><code>square</code> — wrap attributes with round braces;</li>' +
'<li><code>curly</code> — wrap attributes with curly braces.</li>' +
'</ul>');
function transformClassName(className) {
return utils.trim(className).replace(/\s+/g, '.');
}
function getAttrWrapper() {
var start = ' ', end = '';
switch (prefs.get('slim.attributesWrapper')) {
case 'round':
start = '(';
end = ')';
break;
case 'square':
start = '[';
end = ']';
break;
case 'curly':
start = '{';
end = '}';
break;
}
return {
start: start,
end: end
};
}
function stringifyAttrs(attrs, profile) {
var attrQuote = profile.attributeQuote();
var attrWrap = getAttrWrapper();
return attrWrap.start + attrs.map(function(attr) {
var value = attrQuote + attr.value + attrQuote;
if (attr.isBoolean) {
if (!attrWrap.end) {
value = 'true';
} else {
return attr.name;
}
}
return attr.name + '=' + value;
}).join(' ') + attrWrap.end;
}
/**
* Creates HAML attributes string from tag according to profile settings
* @param {AbbreviationNode} tag
* @param {Object} profile
*/
function makeAttributesString(tag, profile) {
var attrs = '';
var otherAttrs = [];
var attrQuote = profile.attributeQuote();
var cursor = profile.cursor();
tag.attributeList().forEach(function(a) {
var attrName = profile.attributeName(a.name);
switch (attrName.toLowerCase()) {
// use short notation for ID and CLASS attributes
case 'id':
attrs += '#' + (a.value || cursor);
break;
case 'class':
attrs += '.' + transformClassName(a.value || cursor);
break;
// process other attributes
default:
otherAttrs.push({
name: attrName,
value: a.value || cursor,
isBoolean: profile.isBoolean(a.name, a.value)
});
}
});
if (otherAttrs.length) {
attrs += stringifyAttrs(otherAttrs, profile);
}
return attrs;
}
function processTagContent(item) {
if (!item.content) {
return;
}
var content = tabStops.replaceVariables(item.content, function(str, name) {
if (name === 'nl' || name === 'newline') {
return '\n';
}
return str;
});
if (reNl.test(content) && !reIndentedText.test(content)) {
// multiline content: pad it with indentation and pipe
var pad = ' ';
item.content = '\n| ' + utils.padString(content, pad);
} else if (!reSpace.test(content)) {
item.content = ' ' + content;
}
}
/**
* Processes element with <code>tag</code> type
* @param {AbbreviationNode} item
* @param {OutputProfile} profile
*/
function processTag(item, profile) {
if (!item.parent)
// looks like it's a root (empty) element
return item;
var attrs = makeAttributesString(item, profile);
var cursor = profile.cursor();
var isUnary = abbrUtils.isUnary(item);
var selfClosing = profile.self_closing_tag && isUnary ? '/' : '';
// define tag name
var tagName = profile.tagName(item.name());
if (tagName.toLowerCase() == 'div' && attrs && '([{'.indexOf(attrs.charAt(0)) == -1)
// omit div tag
tagName = '';
item.end = '';
var start = tagName + attrs + selfClosing;
processTagContent(item);
var placeholder = '%s';
// We can't just replace placeholder with new value because
// JavaScript will treat double $ character as a single one, assuming
// we're using RegExp literal.
item.start = utils.replaceSubstring(item.start, start, item.start.indexOf(placeholder), placeholder);
if (!item.children.length && !isUnary)
item.start += cursor;
return item;
}
return function process(tree, curProfile, level) {
level = level || 0;
if (!level) {
// always format with `xml` profile since
// Slim requires all tags to be on separate lines
tree = formatFilter(tree, profile.get('xml'));
}
tree.children.forEach(function(item) {
if (!abbrUtils.isSnippet(item)) {
processTag(item, curProfile, level);
}
process(item, curProfile, level + 1);
});
return tree;
};
});
},{"../assets/preferences":28,"../assets/profile":29,"../assets/tabStops":33,"../utils/abbreviation":69,"../utils/common":73,"./format":44}],52:[function(require,module,exports){
/**
* Trim filter: removes characters at the beginning of the text
* content that indicates lists: numbers, #, *, -, etc.
*
* Useful for wrapping lists with abbreviation.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var prefs = require('../assets/preferences');
prefs.define('filter.trimRegexp',
'[\\s|\\u00a0]*[\\d|#|\\-|\*|\\u2022]+\\.?\\s*',
'Regular expression used to remove list markers (numbers, dashes, '
+ 'bullets, etc.) in <code>t</code> (trim) filter. The trim filter '
+ 'is useful for wrapping with abbreviation lists, pased from other '
+ 'documents (for example, Word documents).');
function process(tree, re) {
tree.children.forEach(function(item) {
if (item.content) {
item.content = item.content.replace(re, '');
}
process(item, re);
});
return tree;
}
return function(tree) {
var re = new RegExp(prefs.get('filter.trimRegexp'));
return process(tree, re);
};
});
},{"../assets/preferences":28}],53:[function(require,module,exports){
/**
* Filter for trimming "select" attributes from some tags that contains
* child elements
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var abbrUtils = require('../utils/abbreviation');
var tags = {
'xsl:variable': 1,
'xsl:with-param': 1
};
/**
* Removes "select" attribute from node
* @param {AbbreviationNode} node
*/
function trimAttribute(node) {
node.start = node.start.replace(/\s+select\s*=\s*(['"]).*?\1/, '');
}
return function process(tree) {
tree.children.forEach(function(item) {
if (!abbrUtils.isSnippet(item)
&& (item.name() || '').toLowerCase() in tags
&& item.children.length)
trimAttribute(item);
process(item);
});
return tree;
};
});
},{"../utils/abbreviation":69}],54:[function(require,module,exports){
/**
* "Lorem ipsum" text generator. Matches <code>lipsum(num)?</code> or
* <code>lorem(num)?</code> abbreviation.
* This code is based on Django's contribution:
* https://code.djangoproject.com/browser/django/trunk/django/contrib/webdesign/lorem_ipsum.py
* <br><br>
* Examples to test:<br>
* <code>lipsum</code> generates 30 words text.<br>
* <code>lipsum*6</code> generates 6 paragraphs (autowrapped with &lt;p&gt; element) of text.<br>
* <code>ol>lipsum10*5</code> — generates ordered list with 5 list items (autowrapped with &lt;li&gt; tag)
* with text of 10 words on each line.<br>
* <code>span*3>lipsum20</code> generates 3 paragraphs of 20-words text, each wrapped with &lt;span&gt; element.
* Each paragraph phrase is unique.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var prefs = require('../assets/preferences');
var langs = {
en: {
common: ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit'],
words: ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet',
'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi',
'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi',
'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos',
'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum',
'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus',
'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus',
'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum',
'placeat', 'aliquid', 'fuga', 'provident', 'praesentium', 'rem',
'necessitatibus', 'suscipit', 'adipisci', 'quidem', 'possimus',
'voluptas', 'debitis', 'sint', 'accusantium', 'unde', 'sapiente',
'voluptate', 'qui', 'aspernatur', 'laudantium', 'soluta', 'amet',
'quo', 'aliquam', 'saepe', 'culpa', 'libero', 'ipsa', 'dicta',
'reiciendis', 'nesciunt', 'doloribus', 'autem', 'impedit', 'minima',
'maiores', 'repudiandae', 'ipsam', 'obcaecati', 'ullam', 'enim',
'totam', 'delectus', 'ducimus', 'quis', 'voluptates', 'dolores',
'molestiae', 'harum', 'dolorem', 'quia', 'voluptatem', 'molestias',
'magni', 'distinctio', 'omnis', 'illum', 'dolorum', 'voluptatum', 'ea',
'quas', 'quam', 'corporis', 'quae', 'blanditiis', 'atque', 'deserunt',
'laboriosam', 'earum', 'consequuntur', 'hic', 'cupiditate',
'quibusdam', 'accusamus', 'ut', 'rerum', 'error', 'minus', 'eius',
'ab', 'ad', 'nemo', 'fugit', 'officia', 'at', 'in', 'id', 'quos',
'reprehenderit', 'numquam', 'iste', 'fugiat', 'sit', 'inventore',
'beatae', 'repellendus', 'magnam', 'recusandae', 'quod', 'explicabo',
'doloremque', 'aperiam', 'consequatur', 'asperiores', 'commodi',
'optio', 'dolor', 'labore', 'temporibus', 'repellat', 'veniam',
'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique',
'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere',
'maxime', 'corrupti']
},
sp: {
common: ['mujer', 'uno', 'dolor', 'más', 'de', 'poder', 'mismo', 'si'],
words: ['ejercicio', 'preferencia', 'perspicacia', 'laboral', 'paño',
'suntuoso', 'molde', 'namibia', 'planeador', 'mirar', 'demás', 'oficinista', 'excepción',
'odio', 'consecuencia', 'casi', 'auto', 'chicharra', 'velo', 'elixir',
'ataque', 'no', 'odio', 'temporal', 'cuórum', 'dignísimo',
'facilismo', 'letra', 'nihilista', 'expedición', 'alma', 'alveolar', 'aparte',
'león', 'animal', 'como', 'paria', 'belleza', 'modo', 'natividad',
'justo', 'ataque', 'séquito', 'pillo', 'sed', 'ex', 'y', 'voluminoso',
'temporalidad', 'verdades', 'racional', 'asunción', 'incidente', 'marejada',
'placenta', 'amanecer', 'fuga', 'previsor', 'presentación', 'lejos',
'necesariamente', 'sospechoso', 'adiposidad', 'quindío', 'pócima',
'voluble', 'débito', 'sintió', 'accesorio', 'falda', 'sapiencia',
'volutas', 'queso', 'permacultura', 'laudo', 'soluciones', 'entero',
'pan', 'litro', 'tonelada', 'culpa', 'libertario', 'mosca', 'dictado',
'reincidente', 'nascimiento', 'dolor', 'escolar', 'impedimento', 'mínima',
'mayores', 'repugnante', 'dulce', 'obcecado', 'montaña', 'enigma',
'total', 'deletéreo', 'décima', 'cábala', 'fotografía', 'dolores',
'molesto', 'olvido', 'paciencia', 'resiliencia', 'voluntad', 'molestias',
'magnífico', 'distinción', 'ovni', 'marejada', 'cerro', 'torre', 'y',
'abogada', 'manantial', 'corporal', 'agua', 'crepúsculo', 'ataque', 'desierto',
'laboriosamente', 'angustia', 'afortunado', 'alma', 'encefalograma',
'materialidad', 'cosas', 'o', 'renuncia', 'error', 'menos', 'conejo',
'abadía', 'analfabeto', 'remo', 'fugacidad', 'oficio', 'en', 'almácigo', 'vos', 'pan',
'represión', 'números', 'triste', 'refugiado', 'trote', 'inventor',
'corchea', 'repelente', 'magma', 'recusado', 'patrón', 'explícito',
'paloma', 'síndrome', 'inmune', 'autoinmune', 'comodidad',
'ley', 'vietnamita', 'demonio', 'tasmania', 'repeler', 'apéndice',
'arquitecto', 'columna', 'yugo', 'computador', 'mula', 'a', 'propósito',
'fantasía', 'alias', 'rayo', 'tenedor', 'deleznable', 'ventana', 'cara',
'anemia', 'corrupto']
},
ru: {
common: ['далеко-далеко', 'за', 'словесными', 'горами', 'в стране', 'гласных', 'и согласных', 'живут', 'рыбные', 'тексты'],
words: ['вдали', 'от всех', 'они', 'буквенных', 'домах', 'на берегу', 'семантика',
'большого', 'языкового', 'океана', 'маленький', 'ручеек', 'даль',
'журчит', 'по всей', 'обеспечивает', 'ее','всеми', 'необходимыми',
'правилами', 'эта', 'парадигматическая', 'страна', 'которой', 'жаренные',
'предложения', 'залетают', 'прямо', 'рот', 'даже', 'всемогущая',
'пунктуация', 'не', 'имеет', 'власти', 'над', 'рыбными', 'текстами',
'ведущими', 'безорфографичный', 'образ', 'жизни', 'однажды', 'одна',
'маленькая', 'строчка','рыбного', 'текста', 'имени', 'lorem', 'ipsum',
'решила', 'выйти', 'большой', 'мир', 'грамматики', 'великий', 'оксмокс',
'предупреждал', 'о', 'злых', 'запятых', 'диких', 'знаках', 'вопроса',
'коварных', 'точках', 'запятой', 'но', 'текст', 'дал', 'сбить',
'себя', 'толку', 'он', 'собрал', 'семь', 'своих', 'заглавных', 'букв',
'подпоясал', 'инициал', 'за', 'пояс', 'пустился', 'дорогу',
'взобравшись', 'первую', 'вершину', 'курсивных', 'гор', 'бросил',
'последний', 'взгляд', 'назад', 'силуэт', 'своего', 'родного', 'города',
'буквоград', 'заголовок', 'деревни', 'алфавит', 'подзаголовок', 'своего',
'переулка', 'грустный', 'реторический', 'вопрос', 'скатился', 'его',
'щеке', 'продолжил', 'свой', 'путь', 'дороге', 'встретил', 'рукопись',
'она', 'предупредила', 'моей', 'все', 'переписывается', 'несколько',
'раз', 'единственное', 'что', 'меня', 'осталось', 'это', 'приставка',
'возвращайся', 'ты', 'лучше', 'свою', 'безопасную', 'страну', 'послушавшись',
'рукописи', 'наш', 'продолжил', 'свой', 'путь', 'вскоре', 'ему',
'повстречался', 'коварный', 'составитель', 'рекламных', 'текстов',
'напоивший', 'языком', 'речью', 'заманивший', 'свое', 'агенство',
'которое', 'использовало', 'снова', 'снова', 'своих', 'проектах',
'если', 'переписали', 'то', 'живет', 'там', 'до', 'сих', 'пор']
}
};
prefs.define('lorem.defaultLang', 'en',
'Default language of generated dummy text. Currently, <code>en</code>\
and <code>ru</code> are supported, but users can add their own syntaxes\
see <a href="http://docs.emmet.io/abbreviations/lorem-ipsum/">docs</a>.');
prefs.define('lorem.omitCommonPart', false,
'Omit commonly used part (e.g. “Lorem ipsum dolor sit amet“) from generated text.');
/**
* Returns random integer between <code>from</code> and <code>to</code> values
* @param {Number} from
* @param {Number} to
* @returns {Number}
*/
function randint(from, to) {
return Math.round(Math.random() * (to - from) + from);
}
/**
* @param {Array} arr
* @param {Number} count
* @returns {Array}
*/
function sample(arr, count) {
var len = arr.length;
var iterations = Math.min(len, count);
var result = [];
while (result.length < iterations) {
var randIx = randint(0, len - 1);
if (!~result.indexOf(randIx)) {
result.push(randIx);
}
}
return result.map(function(ix) {
return arr[ix];
});
}
function choice(val) {
if (typeof val === 'string')
return val.charAt(randint(0, val.length - 1));
return val[randint(0, val.length - 1)];
}
function sentence(words, end) {
if (words.length) {
words[0] = words[0].charAt(0).toUpperCase() + words[0].substring(1);
}
return words.join(' ') + (end || choice('?!...')); // more dots than question marks
}
/**
* Insert commas at randomly selected words. This function modifies values
* inside <code>words</code> array
* @param {Array} words
*/
function insertCommas(words) {
var len = words.length;
if (len < 2) {
return;
}
var totalCommas = 0;
if (len > 3 && len <= 6) {
totalCommas = randint(0, 1);
} else if (len > 6 && len <= 12) {
totalCommas = randint(0, 2);
} else {
totalCommas = randint(1, 4);
}
for (var i = 0, pos, word; i < totalCommas; i++) {
pos = randint(0, words.length - 2);
word = words[pos];
if (word.charAt(word.length - 1) !== ',') {
words[pos] += ',';
}
}
}
/**
* Generate a paragraph of "Lorem ipsum" text
* @param {Number} wordCount Words count in paragraph
* @param {Boolean} startWithCommon Should paragraph start with common
* "lorem ipsum" sentence.
* @returns {String}
*/
function paragraph(lang, wordCount, startWithCommon) {
var data = langs[lang];
if (!data) {
return '';
}
var result = [];
var totalWords = 0;
var words;
wordCount = parseInt(wordCount, 10);
if (startWithCommon && data.common) {
words = data.common.slice(0, wordCount);
if (words.length > 5) {
words[4] += ',';
}
totalWords += words.length;
result.push(sentence(words, '.'));
}
while (totalWords < wordCount) {
words = sample(data.words, Math.min(randint(2, 30), wordCount - totalWords));
totalWords += words.length;
insertCommas(words);
result.push(sentence(words));
}
return result.join(' ');
}
return {
/**
* Adds new language words for Lorem Ipsum generator
* @param {String} lang Two-letter lang definition
* @param {Object} data Words for language. Maight be either a space-separated
* list of words (String), Array of words or object with <code>text</code> and
* <code>common</code> properties
*/
addLang: function(lang, data) {
if (typeof data === 'string') {
data = {
words: data.split(' ').filter(function(item) {
return !!item;
})
};
} else if (Array.isArray(data)) {
data = {words: data};
}
langs[lang] = data;
},
preprocessor: function(tree) {
var re = /^(?:lorem|lipsum)([a-z]{2})?(\d*)$/i, match;
var allowCommon = !prefs.get('lorem.omitCommonPart');
/** @param {AbbreviationNode} node */
tree.findAll(function(node) {
if (node._name && (match = node._name.match(re))) {
var wordCound = match[2] || 30;
var lang = match[1] || prefs.get('lorem.defaultLang') || 'en';
// force node name resolving if node should be repeated
// or contains attributes. In this case, node should be outputed
// as tag, otherwise as text-only node
node._name = '';
node.data('forceNameResolving', node.isRepeating() || node.attributeList().length);
node.data('pasteOverwrites', true);
node.data('paste', function(i) {
return paragraph(lang, wordCound, !i && allowCommon);
});
}
});
}
};
});
},{"../assets/preferences":28}],55:[function(require,module,exports){
/**
* Emmet abbreviation parser.
* Takes string abbreviation and recursively parses it into a tree. The parsed
* tree can be transformed into a string representation with
* <code>toString()</code> method. Note that string representation is defined
* by custom processors (called <i>filters</i>), not by abbreviation parser
* itself.
*
* This module can be extended with custom pre-/post-processors to shape-up
* final tree or its representation. Actually, many features of abbreviation
* engine are defined in other modules as tree processors
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var tabStops = require('../assets/tabStops');
var profile = require('../assets/profile');
var filters = require('../filter/main');
var utils = require('../utils/common');
var abbreviationUtils = require('../utils/abbreviation');
var stringStream = require('../assets/stringStream');
// pre- and post-processorcs
var lorem = require('../generator/lorem');
var procPastedContent = require('./processor/pastedContent');
var procTagName = require('./processor/tagName');
var procResourceMatcher = require('./processor/resourceMatcher');
var procAttributes = require('./processor/attributes');
var procHref = require('./processor/href');
var reValidName = /^[\w\-\$\:@\!%]+\+?$/i;
var reWord = /[\w\-:\$@]/;
var DEFAULT_ATTR_NAME = '%default';
var pairs = {
'[': ']',
'(': ')',
'{': '}'
};
var spliceFn = Array.prototype.splice;
var preprocessors = [];
var postprocessors = [];
var outputProcessors = [];
/**
* @type AbbreviationNode
*/
function AbbreviationNode(parent) {
/** @type AbbreviationNode */
this.parent = null;
this.children = [];
this._attributes = [];
/** @type String Raw abbreviation for current node */
this.abbreviation = '';
this.counter = 1;
this._name = null;
this._text = '';
this.repeatCount = 1;
this.hasImplicitRepeat = false;
/** Custom data dictionary */
this._data = {};
// output properties
this.start = '';
this.end = '';
this.content = '';
this.padding = '';
}
AbbreviationNode.prototype = {
/**
* Adds passed node as child or creates new child
* @param {AbbreviationNode} child
* @param {Number} position Index in children array where child should
* be inserted
* @return {AbbreviationNode}
*/
addChild: function(child, position) {
child = child || new AbbreviationNode();
child.parent = this;
if (typeof position === 'undefined') {
this.children.push(child);
} else {
this.children.splice(position, 0, child);
}
return child;
},
/**
* Creates a deep copy of current node
* @returns {AbbreviationNode}
*/
clone: function() {
var node = new AbbreviationNode();
var attrs = ['abbreviation', 'counter', '_name', '_text', 'repeatCount', 'hasImplicitRepeat', 'start', 'end', 'content', 'padding'];
attrs.forEach(function(a) {
node[a] = this[a];
}, this);
// clone attributes
node._attributes = this._attributes.map(function(attr) {
return utils.extend({}, attr);
});
node._data = utils.extend({}, this._data);
// clone children
node.children = this.children.map(function(child) {
child = child.clone();
child.parent = node;
return child;
});
return node;
},
/**
* Removes current node from parents child list
* @returns {AbbreviationNode} Current node itself
*/
remove: function() {
if (this.parent) {
var ix = this.parent.children.indexOf(this);
if (~ix) {
this.parent.children.splice(ix, 1);
}
}
return this;
},
/**
* Replaces current node in parents children list with passed nodes
* @param {AbbreviationNode} node Replacement node or array of nodes
*/
replace: function() {
var parent = this.parent;
var ix = parent.children.indexOf(this);
var items = utils.flatten(arguments);
spliceFn.apply(parent.children, [ix, 1].concat(items));
// update parent
items.forEach(function(item) {
item.parent = parent;
});
},
/**
* Recursively sets <code>property</code> to <code>value</code> of current
* node and its children
* @param {String} name Property to update
* @param {Object} value New property value
*/
updateProperty: function(name, value) {
this[name] = value;
this.children.forEach(function(child) {
child.updateProperty(name, value);
});
return this;
},
/**
* Finds first child node that matches truth test for passed
* <code>fn</code> function
* @param {Function} fn
* @returns {AbbreviationNode}
*/
find: function(fn) {
return this.findAll(fn, {amount: 1})[0];
},
/**
* Finds all child nodes that matches truth test for passed
* <code>fn</code> function
* @param {Function} fn
* @returns {Array}
*/
findAll: function(fn, state) {
state = utils.extend({amount: 0, found: 0}, state || {});
if (typeof fn !== 'function') {
var elemName = fn.toLowerCase();
fn = function(item) {return item.name().toLowerCase() == elemName;};
}
var result = [];
this.children.forEach(function(child) {
if (fn(child)) {
result.push(child);
state.found++;
if (state.amount && state.found >= state.amount) {
return;
}
}
result = result.concat(child.findAll(fn));
});
return result.filter(function(item) {
return !!item;
});
},
/**
* Sets/gets custom data
* @param {String} name
* @param {Object} value
* @returns {Object}
*/
data: function(name, value) {
if (arguments.length == 2) {
this._data[name] = value;
}
return this._data[name];
},
/**
* Returns name of current node
* @returns {String}
*/
name: function() {
return this._name;
},
/**
* Returns list of attributes for current node
* @returns {Array}
*/
attributeList: function() {
return optimizeAttributes(this._attributes.slice(0));
},
/**
* Returns or sets attribute value
* @param {String} name Attribute name
* @param {String} value New attribute value. `Null` value
* will remove attribute
* @returns {String}
*/
attribute: function(name, value) {
if (arguments.length == 2) {
if (value === null) {
// remove attribute
var vals = this._attributes.filter(function(attr) {
return attr.name === name;
});
var that = this;
vals.forEach(function(attr) {
var ix = that._attributes.indexOf(attr);
if (~ix) {
that._attributes.splice(ix, 1);
}
});
return;
}
// modify attribute
var attrNames = this._attributes.map(function(attr) {
return attr.name;
});
var ix = attrNames.indexOf(name.toLowerCase());
if (~ix) {
this._attributes[ix].value = value;
} else {
this._attributes.push({
name: name,
value: value
});
}
}
return (utils.find(this.attributeList(), function(attr) {
return attr.name == name;
}) || {}).value;
},
/**
* Returns index of current node in parents children list
* @returns {Number}
*/
index: function() {
return this.parent ? this.parent.children.indexOf(this) : -1;
},
/**
* Sets how many times current element should be repeated
* @private
*/
_setRepeat: function(count) {
if (count) {
this.repeatCount = parseInt(count, 10) || 1;
} else {
this.hasImplicitRepeat = true;
}
},
/**
* Sets abbreviation that belongs to current node
* @param {String} abbr
*/
setAbbreviation: function(abbr) {
abbr = abbr || '';
var that = this;
// find multiplier
abbr = abbr.replace(/\*(\d+)?$/, function(str, repeatCount) {
that._setRepeat(repeatCount);
return '';
});
this.abbreviation = abbr;
var abbrText = extractText(abbr);
if (abbrText) {
abbr = abbrText.element;
this.content = this._text = abbrText.text;
}
var abbrAttrs = parseAttributes(abbr);
if (abbrAttrs) {
abbr = abbrAttrs.element;
this._attributes = abbrAttrs.attributes;
}
this._name = abbr;
// validate name
if (this._name && !reValidName.test(this._name)) {
throw new Error('Invalid abbreviation');
}
},
/**
* Returns string representation of current node
* @return {String}
*/
valueOf: function() {
var start = this.start;
var end = this.end;
var content = this.content;
// apply output processors
var node = this;
outputProcessors.forEach(function(fn) {
start = fn(start, node, 'start');
content = fn(content, node, 'content');
end = fn(end, node, 'end');
});
var innerContent = this.children.map(function(child) {
return child.valueOf();
}).join('');
content = abbreviationUtils.insertChildContent(content, innerContent, {
keepVariable: false
});
return start + utils.padString(content, this.padding) + end;
},
toString: function() {
return this.valueOf();
},
/**
* Check if current node contains children with empty <code>expr</code>
* property
* @return {Boolean}
*/
hasEmptyChildren: function() {
return !!utils.find(this.children, function(child) {
return child.isEmpty();
});
},
/**
* Check if current node has implied name that should be resolved
* @returns {Boolean}
*/
hasImplicitName: function() {
return !this._name && !this.isTextNode();
},
/**
* Indicates that current element is a grouping one, e.g. has no
* representation but serves as a container for other nodes
* @returns {Boolean}
*/
isGroup: function() {
return !this.abbreviation;
},
/**
* Indicates empty node (i.e. without abbreviation). It may be a
* grouping node and should not be outputted
* @return {Boolean}
*/
isEmpty: function() {
return !this.abbreviation && !this.children.length;
},
/**
* Indicates that current node should be repeated
* @returns {Boolean}
*/
isRepeating: function() {
return this.repeatCount > 1 || this.hasImplicitRepeat;
},
/**
* Check if current node is a text-only node
* @return {Boolean}
*/
isTextNode: function() {
return !this.name() && !this.attributeList().length;
},
/**
* Indicates whether this node may be used to build elements or snippets
* @returns {Boolean}
*/
isElement: function() {
return !this.isEmpty() && !this.isTextNode();
},
/**
* Returns latest and deepest child of current tree
* @returns {AbbreviationNode}
*/
deepestChild: function() {
if (!this.children.length)
return null;
var deepestChild = this;
while (deepestChild.children.length) {
deepestChild = deepestChild.children[deepestChild.children.length - 1];
}
return deepestChild;
}
};
/**
* Returns stripped string: a string without first and last character.
* Used for “unquoting” strings
* @param {String} str
* @returns {String}
*/
function stripped(str) {
return str.substring(1, str.length - 1);
}
function consumeQuotedValue(stream, quote) {
var ch;
while ((ch = stream.next())) {
if (ch === quote)
return true;
if (ch == '\\')
continue;
}
return false;
}
/**
* Parses abbreviation into a tree
* @param {String} abbr
* @returns {AbbreviationNode}
*/
function parseAbbreviation(abbr) {
abbr = utils.trim(abbr);
var root = new AbbreviationNode();
var context = root.addChild(), ch;
/** @type StringStream */
var stream = stringStream.create(abbr);
var loopProtector = 1000, multiplier;
var addChild = function(child) {
context.addChild(child);
};
var consumeAbbr = function() {
stream.start = stream.pos;
stream.eatWhile(function(c) {
if (c == '[' || c == '{') {
if (stream.skipToPair(c, pairs[c])) {
stream.backUp(1);
return true;
}
throw new Error('Invalid abbreviation: mo matching "' + pairs[c] + '" found for character at ' + stream.pos);
}
if (c == '+') {
// let's see if this is an expando marker
stream.next();
var isMarker = stream.eol() || ~'+>^*'.indexOf(stream.peek());
stream.backUp(1);
return isMarker;
}
return c != '(' && isAllowedChar(c);
});
};
while (!stream.eol() && --loopProtector > 0) {
ch = stream.peek();
switch (ch) {
case '(': // abbreviation group
stream.start = stream.pos;
if (stream.skipToPair('(', ')')) {
var inner = parseAbbreviation(stripped(stream.current()));
if ((multiplier = stream.match(/^\*(\d+)?/, true))) {
context._setRepeat(multiplier[1]);
}
inner.children.forEach(addChild);
} else {
throw new Error('Invalid abbreviation: mo matching ")" found for character at ' + stream.pos);
}
break;
case '>': // child operator
context = context.addChild();
stream.next();
break;
case '+': // sibling operator
context = context.parent.addChild();
stream.next();
break;
case '^': // climb up operator
var parent = context.parent || context;
context = (parent.parent || parent).addChild();
stream.next();
break;
default: // consume abbreviation
consumeAbbr();
context.setAbbreviation(stream.current());
stream.start = stream.pos;
}
}
if (loopProtector < 1) {
throw new Error('Endless loop detected');
}
return root;
}
/**
* Splits attribute set into a list of attributes string
* @param {String} attrSet
* @return {Array}
*/
function splitAttributes(attrSet) {
attrSet = utils.trim(attrSet);
var parts = [];
// split attribute set by spaces
var stream = stringStream(attrSet), ch;
while ((ch = stream.next())) {
if (ch == ' ') {
parts.push(utils.trim(stream.current()));
// skip spaces
while (stream.peek() == ' ') {
stream.next();
}
stream.start = stream.pos;
} else if (ch == '"' || ch == "'") {
// skip values in strings
if (!stream.skipString(ch)) {
throw new Error('Invalid attribute set');
}
}
}
parts.push(utils.trim(stream.current()));
return parts;
}
/**
* Removes opening and closing quotes from given string
* @param {String} str
* @return {String}
*/
function unquote(str) {
var ch = str.charAt(0);
if (ch == '"' || ch == "'") {
str = str.substr(1);
var last = str.charAt(str.length - 1);
if (last === ch) {
str = str.substr(0, str.length - 1);
}
}
return str;
}
/**
* Extract attributes and their values from attribute set:
* <code>[attr col=3 title="Quoted string"]</code> (without square braces)
* @param {String} attrSet
* @returns {Array}
*/
function extractAttributes(attrSet) {
var reAttrName = /^[\w\-:\$@]+\.?$/;
return splitAttributes(attrSet).map(function(attr) {
// attribute name: [attr]
if (reAttrName.test(attr)) {
var value = '';
if (attr.charAt(attr.length - 1) == '.') {
// a boolean attribute
attr = attr.substr(0, attr.length - 1);
value = attr;
}
return {
name: attr,
value: value
};
}
// attribute with value: [name=val], [name="val"]
if (~attr.indexOf('=')) {
var parts = attr.split('=');
return {
name: parts.shift(),
value: unquote(parts.join('='))
};
}
// looks like its implied attribute
return {
name: DEFAULT_ATTR_NAME,
value: unquote(attr)
};
});
}
/**
* Parses tag attributes extracted from abbreviation. If attributes found,
* returns object with <code>element</code> and <code>attributes</code>
* properties
* @param {String} abbr
* @returns {Object} Returns <code>null</code> if no attributes found in
* abbreviation
*/
function parseAttributes(abbr) {
/*
* Example of incoming data:
* #header
* .some.data
* .some.data#header
* [attr]
* #item[attr=Hello other="World"].class
*/
var result = [];
var attrMap = {'#': 'id', '.': 'class'};
var nameEnd = null;
/** @type StringStream */
var stream = stringStream.create(abbr);
while (!stream.eol()) {
switch (stream.peek()) {
case '#': // id
case '.': // class
if (nameEnd === null)
nameEnd = stream.pos;
var attrName = attrMap[stream.peek()];
stream.next();
stream.start = stream.pos;
stream.eatWhile(reWord);
result.push({
name: attrName,
value: stream.current()
});
break;
case '[': //begin attribute set
if (nameEnd === null)
nameEnd = stream.pos;
stream.start = stream.pos;
if (!stream.skipToPair('[', ']')) {
throw new Error('Invalid attribute set definition');
}
result = result.concat(
extractAttributes(stripped(stream.current()))
);
break;
default:
stream.next();
}
}
if (!result.length)
return null;
return {
element: abbr.substring(0, nameEnd),
attributes: optimizeAttributes(result)
};
}
/**
* Optimize attribute set: remove duplicates and merge class attributes
* @param attrs
*/
function optimizeAttributes(attrs) {
// clone all attributes to make sure that original objects are
// not modified
attrs = attrs.map(function(attr) {
return utils.clone(attr);
});
var lookup = {};
return attrs.filter(function(attr) {
if (!(attr.name in lookup)) {
return lookup[attr.name] = attr;
}
var la = lookup[attr.name];
if (attr.name.toLowerCase() == 'class') {
la.value += (la.value.length ? ' ' : '') + attr.value;
} else {
la.value = attr.value;
la.isImplied = !!attr.isImplied;
}
return false;
});
}
/**
* Extract text data from abbreviation: if <code>a{hello}</code> abbreviation
* is passed, returns object <code>{element: 'a', text: 'hello'}</code>.
* If nothing found, returns <code>null</code>
* @param {String} abbr
*
*/
function extractText(abbr) {
if (!~abbr.indexOf('{'))
return null;
/** @type StringStream */
var stream = stringStream.create(abbr);
while (!stream.eol()) {
switch (stream.peek()) {
case '[':
case '(':
stream.skipToPair(stream.peek(), pairs[stream.peek()]); break;
case '{':
stream.start = stream.pos;
stream.skipToPair('{', '}');
return {
element: abbr.substring(0, stream.start),
text: stripped(stream.current())
};
default:
stream.next();
}
}
}
/**
* “Un-rolls“ contents of current node: recursively replaces all repeating
* children with their repeated clones
* @param {AbbreviationNode} node
* @returns {AbbreviationNode}
*/
function unroll(node) {
for (var i = node.children.length - 1, j, child, maxCount; i >= 0; i--) {
child = node.children[i];
if (child.isRepeating()) {
maxCount = j = child.repeatCount;
child.repeatCount = 1;
child.updateProperty('counter', 1);
child.updateProperty('maxCount', maxCount);
while (--j > 0) {
child.parent.addChild(child.clone(), i + 1)
.updateProperty('counter', j + 1)
.updateProperty('maxCount', maxCount);
}
}
}
// to keep proper 'counter' property, we need to walk
// on children once again
node.children.forEach(unroll);
return node;
}
/**
* Optimizes tree node: replaces empty nodes with their children
* @param {AbbreviationNode} node
* @return {AbbreviationNode}
*/
function squash(node) {
for (var i = node.children.length - 1; i >= 0; i--) {
/** @type AbbreviationNode */
var n = node.children[i];
if (n.isGroup()) {
n.replace(squash(n).children);
} else if (n.isEmpty()) {
n.remove();
}
}
node.children.forEach(squash);
return node;
}
function isAllowedChar(ch) {
var charCode = ch.charCodeAt(0);
var specialChars = '#.*:$-_!@|%';
return (charCode > 64 && charCode < 91) // uppercase letter
|| (charCode > 96 && charCode < 123) // lowercase letter
|| (charCode > 47 && charCode < 58) // number
|| specialChars.indexOf(ch) != -1; // special character
}
// XXX add counter replacer function as output processor
outputProcessors.push(function(text, node) {
return utils.replaceCounter(text, node.counter, node.maxCount);
});
// XXX add tabstop updater
outputProcessors.push(tabStops.abbrOutputProcessor.bind(tabStops));
// include default pre- and postprocessors
[lorem, procResourceMatcher, procAttributes, procPastedContent, procTagName, procHref].forEach(function(mod) {
if (mod.preprocessor) {
preprocessors.push(mod.preprocessor.bind(mod));
}
if (mod.postprocessor) {
postprocessors.push(mod.postprocessor.bind(mod));
}
});
return {
DEFAULT_ATTR_NAME: DEFAULT_ATTR_NAME,
/**
* Parses abbreviation into tree with respect of groups,
* text nodes and attributes. Each node of the tree is a single
* abbreviation. Tree represents actual structure of the outputted
* result
* @memberOf abbreviationParser
* @param {String} abbr Abbreviation to parse
* @param {Object} options Additional options for parser and processors
*
* @return {AbbreviationNode}
*/
parse: function(abbr, options) {
options = options || {};
var tree = parseAbbreviation(abbr);
var that = this;
if (options.contextNode) {
// add info about context node
// a parent XHTML node in editor inside which abbreviation is
// expanded
tree._name = options.contextNode.name;
var attrLookup = {};
tree._attributes.forEach(function(attr) {
attrLookup[attr.name] = attr;
});
options.contextNode.attributes.forEach(function(attr) {
if (attr.name in attrLookup) {
attrLookup[attr.name].value = attr.value;
} else {
attr = utils.clone(attr);
tree._attributes.push(attr);
attrLookup[attr.name] = attr;
}
});
}
// apply preprocessors
preprocessors.forEach(function(fn) {
fn(tree, options, that);
});
if ('counter' in options) {
tree.updateProperty('counter', options.counter);
}
tree = squash(unroll(tree));
// apply postprocessors
postprocessors.forEach(function(fn) {
fn(tree, options, that);
});
return tree;
},
/**
* Expands given abbreviation into a formatted code structure.
* This is the main method that is used for expanding abbreviation
* @param {String} abbr Abbreviation to expand
* @param {Options} options Additional options for abbreviation
* expanding and transformation: `syntax`, `profile`, `contextNode` etc.
* @return {String}
*/
expand: function(abbr, options) {
if (!abbr) return '';
if (typeof options == 'string') {
throw new Error('Deprecated use of `expand` method: `options` must be object');
}
options = options || {};
if (!options.syntax) {
options.syntax = utils.defaultSyntax();
}
var p = profile.get(options.profile, options.syntax);
tabStops.resetTabstopIndex();
var data = filters.extract(abbr);
var outputTree = this.parse(data[0], options);
var filtersList = filters.composeList(options.syntax, p, data[1]);
filters.apply(outputTree, filtersList, p);
return outputTree.valueOf();
},
AbbreviationNode: AbbreviationNode,
/**
* Add new abbreviation preprocessor. <i>Preprocessor</i> is a function
* that applies to a parsed abbreviation tree right after it get parsed.
* The passed tree is in unoptimized state.
* @param {Function} fn Preprocessor function. This function receives
* two arguments: parsed abbreviation tree (<code>AbbreviationNode</code>)
* and <code>options</code> hash that was passed to <code>parse</code>
* method
*/
addPreprocessor: function(fn) {
if (!~preprocessors.indexOf(fn)) {
preprocessors.push(fn);
}
},
/**
* Removes registered preprocessor
*/
removeFilter: function(fn) {
var ix = preprocessors.indexOf(fn);
if (~ix) {
preprocessors.splice(ix, 1);
}
},
/**
* Adds new abbreviation postprocessor. <i>Postprocessor</i> is a
* functinon that applies to <i>optimized</i> parsed abbreviation tree
* right before it returns from <code>parse()</code> method
* @param {Function} fn Postprocessor function. This function receives
* two arguments: parsed abbreviation tree (<code>AbbreviationNode</code>)
* and <code>options</code> hash that was passed to <code>parse</code>
* method
*/
addPostprocessor: function(fn) {
if (!~postprocessors.indexOf(fn)) {
postprocessors.push(fn);
}
},
/**
* Removes registered postprocessor function
*/
removePostprocessor: function(fn) {
var ix = postprocessors.indexOf(fn);
if (~ix) {
postprocessors.splice(ix, 1);
}
},
/**
* Registers output postprocessor. <i>Output processor</i> is a
* function that applies to output part (<code>start</code>,
* <code>end</code> and <code>content</code>) when
* <code>AbbreviationNode.toString()</code> method is called
*/
addOutputProcessor: function(fn) {
if (!~outputProcessors.indexOf(fn)) {
outputProcessors.push(fn);
}
},
/**
* Removes registered output processor
*/
removeOutputProcessor: function(fn) {
var ix = outputProcessors.indexOf(fn);
if (~ix) {
outputProcessors.splice(ix, 1);
}
},
/**
* Check if passed symbol is valid symbol for abbreviation expression
* @param {String} ch
* @return {Boolean}
*/
isAllowedChar: function(ch) {
ch = String(ch); // convert Java object to JS
return isAllowedChar(ch) || ~'>+^[](){}'.indexOf(ch);
}
};
});
},{"../assets/profile":29,"../assets/stringStream":32,"../assets/tabStops":33,"../filter/main":49,"../generator/lorem":54,"../utils/abbreviation":69,"../utils/common":73,"./processor/attributes":57,"./processor/href":58,"./processor/pastedContent":59,"./processor/resourceMatcher":60,"./processor/tagName":61}],56:[function(require,module,exports){
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var session = {tokens: null};
// walks around the source
var walker = {
init: function (source) {
// this.source = source.replace(/\r\n?/g, '\n');
this.source = source;
this.ch = '';
this.chnum = -1;
// advance
this.nextChar();
},
nextChar: function () {
return this.ch = this.source.charAt(++this.chnum);
},
peek: function() {
return this.source.charAt(this.chnum + 1);
}
};
// utility helpers
function isNameChar(c, cc) {
cc = cc || c.charCodeAt(0);
return (
(cc >= 97 && cc <= 122 /* a-z */) ||
(cc >= 65 && cc <= 90 /* A-Z */) ||
/*
Experimental: include cyrillic ranges
since some letters, similar to latin ones, can
accidentally appear in CSS tokens
*/
(cc >= 1024 && cc <= 1279) ||
c === '&' || /* selector placeholder (LESS, SCSS) */
c === '_' ||
c === '<' || /* comparisons (LESS, SCSS) */
c === '>' ||
c === '=' ||
c === '-'
);
}
function isDigit(c, cc) {
cc = cc || c.charCodeAt(0);
return (cc >= 48 && cc <= 57);
}
var isOp = (function () {
var opsa = "{}[]()+*=.,;:>~|\\%$#@^!".split(''),
opsmatcha = "*^|$~".split(''),
ops = {},
opsmatch = {},
i = 0;
for (; i < opsa.length; i += 1) {
ops[opsa[i]] = true;
}
for (i = 0; i < opsmatcha.length; i += 1) {
opsmatch[opsmatcha[i]] = true;
}
return function (ch, matchattr) {
if (matchattr) {
return ch in opsmatch;
}
return ch in ops;
};
}());
// creates token objects and pushes them to a list
function tokener(value, type) {
session.tokens.push({
value: value,
type: type || value,
start: null,
end: null
});
}
function getPosInfo(w) {
var errPos = w.chnum;
var source = w.source.replace(/\r\n?/g, '\n');
var part = w.source.substring(0, errPos + 1).replace(/\r\n?/g, '\n');
var lines = part.split('\n');
var ch = (lines[lines.length - 1] || '').length;
var fullLine = source.split('\n')[lines.length - 1] || '';
var chunkSize = 100;
var offset = Math.max(0, ch - chunkSize);
var formattedLine = fullLine.substr(offset, chunkSize * 2) + '\n';
for (var i = 0; i < ch - offset - 1; i++) {
formattedLine += '-';
}
formattedLine += '^';
return {
line: lines.length,
ch: ch,
text: fullLine,
hint: formattedLine
};
}
function raiseError(message) {
var err = error(message);
var errObj = new Error(err.message, '', err.line);
errObj.line = err.line;
errObj.ch = err.ch;
errObj.name = err.name;
errObj.hint = err.hint;
throw errObj;
}
// oops
function error(m) {
var w = walker;
var info = getPosInfo(walker);
var tokens = session.tokens;
session.tokens = null;
var message = 'CSS parsing error at line ' + info.line + ', char ' + info.ch + ': ' + m;
message += '\n' + info.hint;
return {
name: "ParseError",
message: message,
hint: info.hint,
line: info.line,
ch: info.ch
};
}
// token handlers follow for:
// white space, comment, string, identifier, number, operator
function white() {
var c = walker.ch,
token = '';
while (c === " " || c === "\t") {
token += c;
c = walker.nextChar();
}
tokener(token, 'white');
}
function comment() {
var w = walker,
c = w.ch,
token = c,
cnext;
cnext = w.nextChar();
if (cnext === '/') {
// inline comment in SCSS and LESS
while (c && !(cnext === "\n" || cnext === "\r")) {
token += cnext;
c = cnext;
cnext = w.nextChar();
}
} else if (cnext === '*') {
// multiline CSS commment
while (c && !(c === "*" && cnext === "/")) {
token += cnext;
c = cnext;
cnext = w.nextChar();
}
} else {
// oops, not a comment, just a /
return tokener(token, token);
}
token += cnext;
w.nextChar();
tokener(token, 'comment');
}
function eatString() {
var w = walker,
c = w.ch,
q = c,
token = c,
cnext;
c = w.nextChar();
while (c !== q) {
if (c === '\n') {
cnext = w.nextChar();
if (cnext === "\\") {
token += c + cnext;
} else {
// end of line with no \ escape = bad
raiseError("Unterminated string");
}
} else {
if (c === "\\") {
token += c + w.nextChar();
} else {
token += c;
}
}
c = w.nextChar();
}
token += c;
return token;
}
function str() {
var token = eatString();
walker.nextChar();
tokener(token, 'string');
}
function brace() {
var w = walker,
c = w.ch,
depth = 1,
token = c,
stop = false;
c = w.nextChar();
while (c && !stop) {
if (c === '(') {
depth++;
} else if (c === ')') {
depth--;
if (!depth) {
stop = true;
}
} else if (c === '"' || c === "'") {
c = eatString();
} else if (c === '') {
raiseError("Unterminated brace");
}
token += c;
c = w.nextChar();
}
tokener(token, 'brace');
}
function identifier(pre) {
var c = walker.ch;
var token = pre ? pre + c : c;
c = walker.nextChar();
var cc = c.charCodeAt(0);
while (isNameChar(c, cc) || isDigit(c, cc)) {
token += c;
c = walker.nextChar();
cc = c.charCodeAt(0);
}
tokener(token, 'identifier');
}
function num() {
var w = walker,
c = w.ch,
token = c,
point = token === '.',
nondigit;
c = w.nextChar();
nondigit = !isDigit(c);
// .2px or .classname?
if (point && nondigit) {
// meh, NaN, could be a class name, so it's an operator for now
return tokener(token, '.');
}
// -2px or -moz-something
if (token === '-' && nondigit) {
return identifier('-');
}
while (c !== '' && (isDigit(c) || (!point && c === '.'))) { // not end of source && digit or first instance of .
if (c === '.') {
point = true;
}
token += c;
c = w.nextChar();
}
tokener(token, 'number');
}
function op() {
var w = walker,
c = w.ch,
token = c,
next = w.nextChar();
if (next === "=" && isOp(token, true)) {
token += next;
tokener(token, 'match');
w.nextChar();
return;
}
tokener(token, token);
}
// call the appropriate handler based on the first character in a token suspect
function tokenize() {
var ch = walker.ch;
if (ch === " " || ch === "\t") {
return white();
}
if (ch === '/') {
return comment();
}
if (ch === '"' || ch === "'") {
return str();
}
if (ch === '(') {
return brace();
}
if (ch === '-' || ch === '.' || isDigit(ch)) { // tricky - char: minus (-1px) or dash (-moz-stuff)
return num();
}
if (isNameChar(ch)) {
return identifier();
}
if (isOp(ch)) {
return op();
}
if (ch === '\r') {
if (walker.peek() === '\n') {
ch += walker.nextChar();
}
tokener(ch, 'line');
walker.nextChar();
return;
}
if (ch === '\n') {
tokener(ch, 'line');
walker.nextChar();
return;
}
raiseError("Unrecognized character '" + ch + "'");
}
return {
/**
* Sprits given source into tokens
* @param {String} source
* @returns {Array}
*/
lex: function (source) {
walker.init(source);
session.tokens = [];
// for empty source, return single space token
if (!source) {
session.tokens.push(this.white());
} else {
while (walker.ch !== '') {
tokenize();
}
}
var tokens = session.tokens;
session.tokens = null;
return tokens;
},
/**
* Tokenizes CSS source. It's like `lex()` method,
* but also stores proper token indexes in source,
* so it's a bit slower
* @param {String} source
* @returns {Array}
*/
parse: function(source) {
// transform tokens
var tokens = this.lex(source), pos = 0, token;
for (var i = 0, il = tokens.length; i < il; i++) {
token = tokens[i];
token.start = pos;
token.end = (pos += token.value.length);
}
return tokens;
},
white: function() {
return {
value: '',
type: 'white',
start: 0,
end: 0
};
},
toSource: function(toks) {
var i = 0, max = toks.length, src = '';
for (; i < max; i++) {
src += toks[i].value;
}
return src;
}
};
});
},{}],57:[function(require,module,exports){
/**
* Resolves node attribute names: moves `default` attribute value
* from stub to real attribute.
*
* This resolver should be applied *after* resource matcher
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../../utils/common');
var findDefault = function(attr) {
return attr.isDefault;
};
var findImplied = function(attr) {
return attr.isImplied;
};
var findEmpty = function(attr) {
return !attr.value;
};
function resolveDefaultAttrs(node, parser) {
node.children.forEach(function(item) {
var attrList = item.attributeList();
var defaultAttrValue = item.attribute(parser.DEFAULT_ATTR_NAME);
if (typeof defaultAttrValue !== 'undefined') {
// remove stub attribute
item.attribute(parser.DEFAULT_ATTR_NAME, null);
if (attrList.length) {
// target for default value:
// 1. default attribute
// 2. implied attribute
// 3. first empty attribute
// find attribute marked as default
var defaultAttr = utils.find(attrList, findDefault)
|| utils.find(attrList, findImplied)
|| utils.find(attrList, findEmpty);
if (defaultAttr) {
var oldVal = item.attribute(defaultAttr.name);
var newVal = utils.replaceUnescapedSymbol(oldVal, '|', defaultAttrValue);
// no replacement, e.g. default value does not contains | symbol
if (oldVal == newVal) {
newVal = defaultAttrValue
}
item.attribute(defaultAttr.name, newVal);
}
}
} else {
// if no default attribute value, remove implied attributes
attrList.forEach(function(attr) {
if (attr.isImplied) {
item.attribute(attr.name, null);
}
});
}
resolveDefaultAttrs(item, parser);
});
}
return {
/**
* @param {AbbreviationNode} tree
* @param {Object} options
* @param {abbreviation} parser
*/
preprocessor: function(tree, options, parser) {
resolveDefaultAttrs(tree, parser);
}
};
});
},{"../../utils/common":73}],58:[function(require,module,exports){
/**
* A preptocessor for &lt;a&gt; tag: tests wrapped content
* for common URL patterns and, if matched, inserts it as
* `href` attribute
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var prefs = require('../../assets/preferences');
var utils = require('../../utils/common');
var pc = require('./pastedContent');
prefs.define('href.autodetect', true,
'Enables or disables automatic URL recognition when wrapping\
text with <code>&lt;a&gt;</code> tag. With this option enabled,\
if wrapped text matches URL or e-mail pattern it will be automatically\
inserted into <code>href</code> attribute.');
prefs.define('href.urlPattern', '^(?:(?:https?|ftp|file)://|www\\.|ftp\\.)(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[A-Z0-9+&@#/%=~_|$])',
'RegExp pattern to match wrapped URLs. Matched content will be inserts\
as-is into <code>href</code> attribute, only whitespace will be trimmed.');
prefs.define('href.emailPattern', '^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,5}$',
'RegExp pattern to match wrapped e-mails. Unlike <code>href.urlPattern</code>,\
wrapped content will be prefixed with <code>mailto:</code> in <code>href</code>\
attribute');
return {
/**
* @param {AbbreviationNode} tree
* @param {Object} options
*/
postprocessor: function(tree, options) {
if (!prefs.get('href.autodetect')) {
return;
}
var reUrl = new RegExp(prefs.get('href.urlPattern'), 'i');
var reEmail = new RegExp(prefs.get('href.emailPattern'), 'i');
var reProto = /^([a-z]+:)?\/\//i;
tree.findAll(function(item) {
if (item.name().toLowerCase() != 'a' || item.attribute('href')) {
return;
}
var pastedContent = utils.trim(pc.pastedContent(item) || options.pastedContent);
if (pastedContent) {
if (reUrl.test(pastedContent)) {
// do we have protocol?
if (!reProto.test(pastedContent)) {
pastedContent = 'http://' + pastedContent;
}
item.attribute('href', pastedContent);
} else if (reEmail.test(pastedContent)) {
item.attribute('href', 'mailto:' + pastedContent);
}
}
});
}
};
});
},{"../../assets/preferences":28,"../../utils/common":73,"./pastedContent":59}],59:[function(require,module,exports){
/**
* Pasted content abbreviation processor. A pasted content is a content that
* should be inserted into implicitly repeated abbreviation nodes.
* This processor powers “Wrap With Abbreviation” action
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../../utils/common');
var abbrUtils = require('../../utils/abbreviation');
var stringStream = require('../../assets/stringStream');
var range = require('../../assets/range');
var outputPlaceholder = '$#';
/**
* Locates output placeholders inside text
* @param {String} text
* @returns {Array} Array of ranges of output placeholder in text
*/
function locateOutputPlaceholder(text) {
var result = [];
var stream = stringStream.create(text);
while (!stream.eol()) {
if (stream.peek() == '\\') {
stream.next();
} else {
stream.start = stream.pos;
if (stream.match(outputPlaceholder, true)) {
result.push(range.create(stream.start, outputPlaceholder));
continue;
}
}
stream.next();
}
return result;
}
/**
* Replaces output placeholders inside <code>source</code> with
* <code>value</code>
* @param {String} source
* @param {String} value
* @returns {String}
*/
function replaceOutputPlaceholders(source, value) {
var ranges = locateOutputPlaceholder(source);
ranges.reverse().forEach(function(r) {
source = utils.replaceSubstring(source, value, r);
});
return source;
}
/**
* Check if parsed node contains output placeholder a target where
* pasted content should be inserted
* @param {AbbreviationNode} node
* @returns {Boolean}
*/
function hasOutputPlaceholder(node) {
if (locateOutputPlaceholder(node.content).length)
return true;
// check if attributes contains placeholder
return !!utils.find(node.attributeList(), function(attr) {
return !!locateOutputPlaceholder(attr.value).length;
});
}
/**
* Insert pasted content into correct positions of parsed node
* @param {AbbreviationNode} node
* @param {String} content
* @param {Boolean} overwrite Overwrite node content if no value placeholders
* found instead of appending to existing content
*/
function insertPastedContent(node, content, overwrite) {
var nodesWithPlaceholders = node.findAll(function(item) {
return hasOutputPlaceholder(item);
});
if (hasOutputPlaceholder(node))
nodesWithPlaceholders.unshift(node);
if (nodesWithPlaceholders.length) {
nodesWithPlaceholders.forEach(function(item) {
item.content = replaceOutputPlaceholders(item.content, content);
item._attributes.forEach(function(attr) {
attr.value = replaceOutputPlaceholders(attr.value, content);
});
});
} else {
// on output placeholders in subtree, insert content in the deepest
// child node
var deepest = node.deepestChild() || node;
if (overwrite) {
deepest.content = content;
} else {
deepest.content = abbrUtils.insertChildContent(deepest.content, content);
}
}
}
return {
pastedContent: function(item) {
var content = item.data('paste');
if (Array.isArray(content)) {
return content[item.counter - 1];
} else if (typeof content === 'function') {
return content(item.counter - 1, item.content);
} else if (content) {
return content;
}
},
/**
* @param {AbbreviationNode} tree
* @param {Object} options
*/
preprocessor: function(tree, options) {
if (options.pastedContent) {
var lines = utils.splitByLines(options.pastedContent, true).map(utils.trim);
// set repeat count for implicitly repeated elements before
// tree is unrolled
tree.findAll(function(item) {
if (item.hasImplicitRepeat) {
item.data('paste', lines);
return item.repeatCount = lines.length;
}
});
}
},
/**
* @param {AbbreviationNode} tree
* @param {Object} options
*/
postprocessor: function(tree, options) {
var that = this;
// for each node with pasted content, update text data
var targets = tree.findAll(function(item) {
var pastedContent = that.pastedContent(item);
if (pastedContent) {
insertPastedContent(item, pastedContent, !!item.data('pasteOverwrites'));
}
return !!pastedContent;
});
if (!targets.length && options.pastedContent) {
// no implicitly repeated elements, put pasted content in
// the deepest child
insertPastedContent(tree, options.pastedContent);
}
}
};
});
},{"../../assets/range":30,"../../assets/stringStream":32,"../../utils/abbreviation":69,"../../utils/common":73}],60:[function(require,module,exports){
/**
* Processor function that matches parsed <code>AbbreviationNode</code>
* against resources defined in <code>resource</code> module
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var resources = require('../../assets/resources');
var elements = require('../../assets/elements');
var utils = require('../../utils/common');
var abbreviationUtils = require('../../utils/abbreviation');
/**
* Finds matched resources for child nodes of passed <code>node</code>
* element. A matched resource is a reference to <i>snippets.json</i> entry
* that describes output of parsed node
* @param {AbbreviationNode} node
* @param {String} syntax
*/
function matchResources(node, syntax, parser) {
// do a shallow copy because the children list can be modified during
// resource matching
node.children.slice(0).forEach(function(child) {
var r = resources.getMatchedResource(child, syntax);
if (typeof r === 'string') {
r = elements.create('snippet', r);
}
child.data('resource', r);
var elemType = elements.type(r);
if (elemType == 'snippet') {
var content = r.data;
var curContent = child._text || child.content;
if (curContent) {
content = abbreviationUtils.insertChildContent(content, curContent);
}
child.content = content;
} else if (elemType == 'element') {
child._name = r.name;
if (Array.isArray(r.attributes)) {
child._attributes = [].concat(r.attributes, child._attributes);
}
} else if (elemType == 'reference') {
// its a reference to another abbreviation:
// parse it and insert instead of current child
/** @type AbbreviationNode */
var subtree = parser.parse(r.data, {
syntax: syntax
});
// if context element should be repeated, check if we need to
// transfer repeated element to specific child node
if (child.repeatCount > 1) {
var repeatedChildren = subtree.findAll(function(node) {
return node.hasImplicitRepeat;
});
if (!repeatedChildren.length) {
repeatedChildren = subtree.children
}
repeatedChildren.forEach(function(node) {
node.repeatCount = child.repeatCount;
node.hasImplicitRepeat = false;
});
}
// move childs children into the deepest child of new subtree
var deepestChild = subtree.deepestChild();
if (deepestChild) {
child.children.forEach(function(c) {
deepestChild.addChild(c);
});
deepestChild.content = child.content;
}
// copy current attributes to children
subtree.children.forEach(function(node) {
child.attributeList().forEach(function(attr) {
node.attribute(attr.name, attr.value);
});
});
child.replace(subtree.children);
}
matchResources(child, syntax, parser);
});
}
return {
preprocessor: function(tree, options, parser) {
var syntax = options.syntax || utils.defaultSyntax();
matchResources(tree, syntax, parser);
}
};
});
},{"../../assets/elements":24,"../../assets/resources":31,"../../utils/abbreviation":69,"../../utils/common":73}],61:[function(require,module,exports){
/**
* Resolves tag names in abbreviations with implied name
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var tagName = require('../../resolver/tagName');
/**
* Resolves implicit node names in parsed tree
* @param {AbbreviationNode} tree
*/
function resolveNodeNames(tree) {
tree.children.forEach(function(node) {
if (node.hasImplicitName() || node.data('forceNameResolving')) {
node._name = tagName.resolve(node.parent.name());
node.data('nameResolved', true);
}
resolveNodeNames(node);
});
return tree;
}
return {
postprocessor: resolveNodeNames
};
});
},{"../../resolver/tagName":67}],62:[function(require,module,exports){
/**
* HTML tokenizer by Marijn Haverbeke
* http://codemirror.net/
* @constructor
* @memberOf __xmlParseDefine
* @param {Function} require
* @param {Underscore} _
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var stringStream = require('../assets/stringStream');
var Kludges = {
autoSelfClosers : {},
implicitlyClosed : {},
contextGrabbers : {},
doNotIndent : {},
allowUnquoted : true,
allowMissing : true
};
// Return variables for tokenizers
var tagName = null, type = null;
function inText(stream, state) {
function chain(parser) {
state.tokenize = parser;
return parser(stream, state);
}
var ch = stream.next();
if (ch == "<") {
if (stream.eat("!")) {
if (stream.eat("[")) {
if (stream.match("CDATA["))
return chain(inBlock("atom", "]]>"));
else
return null;
} else if (stream.match("--"))
return chain(inBlock("comment", "-->"));
else if (stream.match("DOCTYPE", true, true)) {
stream.eatWhile(/[\w\._\-]/);
return chain(doctype(1));
} else
return null;
} else if (stream.eat("?")) {
stream.eatWhile(/[\w\._\-]/);
state.tokenize = inBlock("meta", "?>");
return "meta";
} else {
type = stream.eat("/") ? "closeTag" : "openTag";
stream.eatSpace();
tagName = "";
var c;
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/)))
tagName += c;
state.tokenize = inTag;
return "tag";
}
} else if (ch == "&") {
var ok;
if (stream.eat("#")) {
if (stream.eat("x")) {
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
} else {
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
}
} else {
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
}
return ok ? "atom" : "error";
} else {
stream.eatWhile(/[^&<]/);
return "text";
}
}
function inTag(stream, state) {
var ch = stream.next();
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
state.tokenize = inText;
type = ch == ">" ? "endTag" : "selfcloseTag";
return "tag";
} else if (ch == "=") {
type = "equals";
return null;
} else if (/[\'\"]/.test(ch)) {
state.tokenize = inAttribute(ch);
return state.tokenize(stream, state);
} else {
stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);
return "word";
}
}
function inAttribute(quote) {
return function(stream, state) {
while (!stream.eol()) {
if (stream.next() == quote) {
state.tokenize = inTag;
break;
}
}
return "string";
};
}
function inBlock(style, terminator) {
return function(stream, state) {
while (!stream.eol()) {
if (stream.match(terminator)) {
state.tokenize = inText;
break;
}
stream.next();
}
return style;
};
}
function doctype(depth) {
return function(stream, state) {
var ch;
while ((ch = stream.next()) !== null) {
if (ch == "<") {
state.tokenize = doctype(depth + 1);
return state.tokenize(stream, state);
} else if (ch == ">") {
if (depth == 1) {
state.tokenize = inText;
break;
} else {
state.tokenize = doctype(depth - 1);
return state.tokenize(stream, state);
}
}
}
return "meta";
};
}
var curState = null, setStyle;
function pass() {
for (var i = arguments.length - 1; i >= 0; i--)
curState.cc.push(arguments[i]);
}
function cont() {
pass.apply(null, arguments);
return true;
}
function pushContext(tagName, startOfLine) {
var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName)
|| (curState.context && curState.context.noIndent);
curState.context = {
prev : curState.context,
tagName : tagName,
indent : curState.indented,
startOfLine : startOfLine,
noIndent : noIndent
};
}
function popContext() {
if (curState.context)
curState.context = curState.context.prev;
}
function element(type) {
if (type == "openTag") {
curState.tagName = tagName;
return cont(attributes, endtag(curState.startOfLine));
} else if (type == "closeTag") {
var err = false;
if (curState.context) {
if (curState.context.tagName != tagName) {
if (Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())) {
popContext();
}
err = !curState.context || curState.context.tagName != tagName;
}
} else {
err = true;
}
if (err)
setStyle = "error";
return cont(endclosetag(err));
}
return cont();
}
function endtag(startOfLine) {
return function(type) {
if (type == "selfcloseTag"
|| (type == "endTag" && Kludges.autoSelfClosers
.hasOwnProperty(curState.tagName
.toLowerCase()))) {
maybePopContext(curState.tagName.toLowerCase());
return cont();
}
if (type == "endTag") {
maybePopContext(curState.tagName.toLowerCase());
pushContext(curState.tagName, startOfLine);
return cont();
}
return cont();
};
}
function endclosetag(err) {
return function(type) {
if (err)
setStyle = "error";
if (type == "endTag") {
popContext();
return cont();
}
setStyle = "error";
return cont(arguments.callee);
};
}
function maybePopContext(nextTagName) {
var parentTagName;
while (true) {
if (!curState.context) {
return;
}
parentTagName = curState.context.tagName.toLowerCase();
if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName)
|| !Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
return;
}
popContext();
}
}
function attributes(type) {
if (type == "word") {
setStyle = "attribute";
return cont(attribute, attributes);
}
if (type == "endTag" || type == "selfcloseTag")
return pass();
setStyle = "error";
return cont(attributes);
}
function attribute(type) {
if (type == "equals")
return cont(attvalue, attributes);
if (!Kludges.allowMissing)
setStyle = "error";
return (type == "endTag" || type == "selfcloseTag") ? pass()
: cont();
}
function attvalue(type) {
if (type == "string")
return cont(attvaluemaybe);
if (type == "word" && Kludges.allowUnquoted) {
setStyle = "string";
return cont();
}
setStyle = "error";
return (type == "endTag" || type == "selfCloseTag") ? pass()
: cont();
}
function attvaluemaybe(type) {
if (type == "string")
return cont(attvaluemaybe);
else
return pass();
}
function startState() {
return {
tokenize : inText,
cc : [],
indented : 0,
startOfLine : true,
tagName : null,
context : null
};
}
function token(stream, state) {
if (stream.sol()) {
state.startOfLine = true;
state.indented = 0;
}
if (stream.eatSpace())
return null;
setStyle = type = tagName = null;
var style = state.tokenize(stream, state);
state.type = type;
if ((style || type) && style != "comment") {
curState = state;
while (true) {
var comb = state.cc.pop() || element;
if (comb(type || style))
break;
}
}
state.startOfLine = false;
return setStyle || style;
}
return {
/**
* @memberOf emmet.xmlParser
* @returns
*/
parse: function(data, offset) {
offset = offset || 0;
var state = startState();
var stream = stringStream.create(data);
var tokens = [];
while (!stream.eol()) {
tokens.push({
type: token(stream, state),
start: stream.start + offset,
end: stream.pos + offset
});
stream.start = stream.pos;
}
return tokens;
}
};
});
},{"../assets/stringStream":32}],63:[function(require,module,exports){
/**
* Module for working with file. Shall implement
* IEmmetFile interface.
*
* Since implementation of this module depends
* greatly on current runtime, this module must be
* initialized with actual implementation first
* before use. E.g.
* require('./plugin/file')({
* read: function() {...}
* })
*
* By default, this module provides Node.JS implementation
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
// hide it from Require.JS parser
(function(r) {
if (typeof define === 'undefined' || !define.amd) {
try {
fs = r('fs');
path = r('path');
} catch(e) {}
}
})(require);
// module is a function that can extend itself
module.exports = function(obj) {
if (obj) {
utils.extend(module.exports, obj);
}
};
function bts(bytes) {
var out = [];
for (var i = 0, il = bytes.length; i < il; i++) {
out.push(String.fromCharCode(bytes[i]));
}
return out.join('');
}
function isURL(path) {
var re = /^https?:\/\//;
return re.test(path);
}
return utils.extend(module.exports, {
_parseParams: function(args) {
var params = {
path: args[0],
size: 0
};
args = utils.toArray(args, 1);
params.callback = args[args.length - 1];
args = args.slice(0, args.length - 1);
if (args.length) {
params.size = args[0];
}
return params;
},
_read: function(params, callback) {
if (isURL(params.path)) {
var req = require(/^https:/.test(params.path) ? 'https' : 'http').get(params.path, function(res) {
var bufs = [];
var totalLength = 0;
var finished = false;
res
.on('data', function(chunk) {
totalLength += chunk.length;
bufs.push(chunk);
if (params.size && totalLength >= params.size) {
finished = true;
callback(null, Buffer.concat(bufs));
req.abort();
}
})
.on('end', function() {
if (!finished) {
finished = true;
callback(null, Buffer.concat(bufs));
}
});
}).on('error', callback);
} else {
if (params.size) {
var fd = fs.openSync(params.path, 'r');
var buf = new Buffer(params.size);
fs.read(fd, buf, 0, params.size, null, function(err, bytesRead) {
callback(err, buf)
});
} else {
callback(null, fs.readFileSync(params.path));
}
}
},
/**
* Reads binary file content and return it
* @param {String} path File's relative or absolute path
* @return {String}
*/
read: function(path, size, callback) {
var params = this._parseParams(arguments);
this._read(params, function(err, buf) {
params.callback(err, err ? '' : bts(buf));
});
},
/**
* Read file content and return it
* @param {String} path File's relative or absolute path
* @return {String}
*/
readText: function(path, size, callback) {
var params = this._parseParams(arguments);
this._read(params, function(err, buf) {
params.callback(err, err ? '' : buf.toString());
});
},
/**
* Locate <code>file_name</code> file that relates to <code>editor_file</code>.
* File name may be absolute or relative path
*
* <b>Dealing with absolute path.</b>
* Many modern editors have a "project" support as information unit, but you
* should not rely on project path to find file with absolute path. First,
* it requires user to create a project before using this method (and this
* is not very convenient). Second, project path doesn't always points to
* to website's document root folder: it may point, for example, to an
* upper folder which contains server-side scripts.
*
* For better result, you should use the following algorithm in locating
* absolute resources:
* 1) Get parent folder for <code>editorFile</code> as a start point
* 2) Append required <code>fileName</code> to start point and test if
* file exists
* 3) If it doesn't exists, move start point one level up (to parent folder)
* and repeat step 2.
*
* @param {String} editorFile
* @param {String} fileName
* @return {String} Returns null if <code>fileName</code> cannot be located
*/
locateFile: function(editorFile, fileName) {
if (isURL(fileName)) {
return fileName;
}
var dirname = editorFile, f;
fileName = fileName.replace(/^\/+/, '');
while (dirname && dirname !== path.dirname(dirname)) {
dirname = path.dirname(dirname);
f = path.join(dirname, fileName);
if (fs.existsSync(f))
return f;
}
return '';
},
/**
* Creates absolute path by concatenating <code>parent</code> and <code>fileName</code>.
* If <code>parent</code> points to file, its parent directory is used
* @param {String} parent
* @param {String} fileName
* @return {String}
*/
createPath: function(parent, fileName, callback) {
var stat = fs.statSync(parent);
if (stat && !stat.isDirectory()) {
parent = path.dirname(parent);
}
return callback(path.resolve(parent, fileName));
},
/**
* Saves <code>content</code> as <code>file</code>
* @param {String} file File's absolute path
* @param {String} content File content
*/
save: function(file, content) {
fs.writeFileSync(file, content, 'ascii');
},
/**
* Returns file extension in lower case
* @param {String} file
* @return {String}
*/
getExt: function(file) {
var m = (file || '').match(/\.([\w\-]+)$/);
return m ? m[1].toLowerCase() : '';
}
});
});
},{"../utils/common":73}],64:[function(require,module,exports){
/**
* Resolver for fast CSS typing. Handles abbreviations with the following
* notation:<br>
*
* <code>(-vendor prefix)?property(value)*(!)?</code>
*
* <br><br>
* <b>Abbreviation handling</b><br>
*
* By default, Emmet searches for matching snippet definition for provided abbreviation.
* If snippet wasn't found, Emmet automatically generates element with
* abbreviation's name. For example, <code>foo</code> abbreviation will generate
* <code>&lt;foo&gt;&lt;/foo&gt;</code> output.
* <br><br>
* This module will capture all expanded properties and upgrade them with values,
* vendor prefixes and !important declarations. All unmatched abbreviations will
* be automatically transformed into <code>property-name: ${1}</code> snippets.
*
* <b>Vendor prefixes<b><br>
*
* If CSS-property is preceded with dash, resolver should output property with
* all <i>known</i> vendor prefixes. For example, if <code>brad</code>
* abbreviation generates <code>border-radius: ${value};</code> snippet,
* the <code>-brad</code> abbreviation should generate:
* <pre><code>
* -webkit-border-radius: ${value};
* -moz-border-radius: ${value};
* border-radius: ${value};
* </code></pre>
* Note that <i>o</i> and <i>ms</i> prefixes are omitted since Opera and IE
* supports unprefixed property.<br><br>
*
* Users can also provide an explicit list of one-character prefixes for any
* CSS property. For example, <code>-wm-float</code> will produce
*
* <pre><code>
* -webkit-float: ${1};
* -moz-float: ${1};
* float: ${1};
* </code></pre>
*
* Although this example looks pointless, users can use this feature to write
* cutting-edge properties implemented by browser vendors recently.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var prefs = require('../assets/preferences');
var resources = require('../assets/resources');
var stringStream = require('../assets/stringStream');
var ciu = require('../assets/caniuse');
var utils = require('../utils/common');
var template = require('../utils/template');
var cssEditTree = require('../editTree/css');
var prefixObj = {
/** Real vendor prefix name */
prefix: 'emmet',
/**
* Indicates this prefix is obsolete and should't be used when user
* wants to generate all-prefixed properties
*/
obsolete: false,
/**
* Returns prefixed CSS property name
* @param {String} name Unprefixed CSS property
*/
transformName: function(name) {
return '-' + this.prefix + '-' + name;
},
/**
* List of unprefixed CSS properties that supported by
* current prefix. This list is used to generate all-prefixed property
* @returns {Array}
*/
properties: function() {
return getProperties('css.' + this.prefix + 'Properties') || [];
},
/**
* Check if given property is supported by current prefix
* @param name
*/
supports: function(name) {
return ~this.properties().indexOf(name);
}
};
/**
* List of registered one-character prefixes. Key is a one-character prefix,
* value is an <code>prefixObj</code> object
*/
var vendorPrefixes = {};
var defaultValue = '${1};';
// XXX module preferences
prefs.define('css.valueSeparator', ': ',
'Defines a symbol that should be placed between CSS property and '
+ 'value when expanding CSS abbreviations.');
prefs.define('css.propertyEnd', ';',
'Defines a symbol that should be placed at the end of CSS property '
+ 'when expanding CSS abbreviations.');
prefs.define('stylus.valueSeparator', ' ',
'Defines a symbol that should be placed between CSS property and '
+ 'value when expanding CSS abbreviations in Stylus dialect.');
prefs.define('stylus.propertyEnd', '',
'Defines a symbol that should be placed at the end of CSS property '
+ 'when expanding CSS abbreviations in Stylus dialect.');
prefs.define('sass.propertyEnd', '',
'Defines a symbol that should be placed at the end of CSS property '
+ 'when expanding CSS abbreviations in SASS dialect.');
prefs.define('css.syntaxes', 'css, less, sass, scss, stylus, styl',
'List of syntaxes that should be treated as CSS dialects.');
prefs.define('css.autoInsertVendorPrefixes', true,
'Automatically generate vendor-prefixed copies of expanded CSS '
+ 'property. By default, Emmet will generate vendor-prefixed '
+ 'properties only when you put dash before abbreviation '
+ '(e.g. <code>-bxsh</code>). With this option enabled, you dont '
+ 'need dashes before abbreviations: Emmet will produce '
+ 'vendor-prefixed properties for you.');
prefs.define('less.autoInsertVendorPrefixes', false, 'Same as <code>css.autoInsertVendorPrefixes</code> but for LESS syntax');
prefs.define('scss.autoInsertVendorPrefixes', false, 'Same as <code>css.autoInsertVendorPrefixes</code> but for SCSS syntax');
prefs.define('sass.autoInsertVendorPrefixes', false, 'Same as <code>css.autoInsertVendorPrefixes</code> but for SASS syntax');
prefs.define('stylus.autoInsertVendorPrefixes', false, 'Same as <code>css.autoInsertVendorPrefixes</code> but for Stylus syntax');
var descTemplate = template('A comma-separated list of CSS properties that may have '
+ '<code><%= vendor %></code> vendor prefix. This list is used to generate '
+ 'a list of prefixed properties when expanding <code>-property</code> '
+ 'abbreviations. Empty list means that all possible CSS values may '
+ 'have <code><%= vendor %></code> prefix.');
var descAddonTemplate = template('A comma-separated list of <em>additional</em> CSS properties '
+ 'for <code>css.<%= vendor %>Preperties</code> preference. '
+ 'You should use this list if you want to add or remove a few CSS '
+ 'properties to original set. To add a new property, simply write its name, '
+ 'to remove it, precede property with hyphen.<br>'
+ 'For example, to add <em>foo</em> property and remove <em>border-radius</em> one, '
+ 'the preference value will look like this: <code>foo, -border-radius</code>.');
// properties list is created from cssFeatures.html file
var props = {
'webkit': 'animation, animation-delay, animation-direction, animation-duration, animation-fill-mode, animation-iteration-count, animation-name, animation-play-state, animation-timing-function, appearance, backface-visibility, background-clip, background-composite, background-origin, background-size, border-fit, border-horizontal-spacing, border-image, border-vertical-spacing, box-align, box-direction, box-flex, box-flex-group, box-lines, box-ordinal-group, box-orient, box-pack, box-reflect, box-shadow, color-correction, column-break-after, column-break-before, column-break-inside, column-count, column-gap, column-rule-color, column-rule-style, column-rule-width, column-span, column-width, dashboard-region, font-smoothing, highlight, hyphenate-character, hyphenate-limit-after, hyphenate-limit-before, hyphens, line-box-contain, line-break, line-clamp, locale, margin-before-collapse, margin-after-collapse, marquee-direction, marquee-increment, marquee-repetition, marquee-style, mask-attachment, mask-box-image, mask-box-image-outset, mask-box-image-repeat, mask-box-image-slice, mask-box-image-source, mask-box-image-width, mask-clip, mask-composite, mask-image, mask-origin, mask-position, mask-repeat, mask-size, nbsp-mode, perspective, perspective-origin, rtl-ordering, text-combine, text-decorations-in-effect, text-emphasis-color, text-emphasis-position, text-emphasis-style, text-fill-color, text-orientation, text-security, text-stroke-color, text-stroke-width, transform, transition, transform-origin, transform-style, transition-delay, transition-duration, transition-property, transition-timing-function, user-drag, user-modify, user-select, writing-mode, svg-shadow, box-sizing, border-radius',
'moz': 'animation-delay, animation-direction, animation-duration, animation-fill-mode, animation-iteration-count, animation-name, animation-play-state, animation-timing-function, appearance, backface-visibility, background-inline-policy, binding, border-bottom-colors, border-image, border-left-colors, border-right-colors, border-top-colors, box-align, box-direction, box-flex, box-ordinal-group, box-orient, box-pack, box-shadow, box-sizing, column-count, column-gap, column-rule-color, column-rule-style, column-rule-width, column-width, float-edge, font-feature-settings, font-language-override, force-broken-image-icon, hyphens, image-region, orient, outline-radius-bottomleft, outline-radius-bottomright, outline-radius-topleft, outline-radius-topright, perspective, perspective-origin, stack-sizing, tab-size, text-blink, text-decoration-color, text-decoration-line, text-decoration-style, text-size-adjust, transform, transform-origin, transform-style, transition, transition-delay, transition-duration, transition-property, transition-timing-function, user-focus, user-input, user-modify, user-select, window-shadow, background-clip, border-radius',
'ms': 'accelerator, backface-visibility, background-position-x, background-position-y, behavior, block-progression, box-align, box-direction, box-flex, box-line-progression, box-lines, box-ordinal-group, box-orient, box-pack, content-zoom-boundary, content-zoom-boundary-max, content-zoom-boundary-min, content-zoom-chaining, content-zoom-snap, content-zoom-snap-points, content-zoom-snap-type, content-zooming, filter, flow-from, flow-into, font-feature-settings, grid-column, grid-column-align, grid-column-span, grid-columns, grid-layer, grid-row, grid-row-align, grid-row-span, grid-rows, high-contrast-adjust, hyphenate-limit-chars, hyphenate-limit-lines, hyphenate-limit-zone, hyphens, ime-mode, interpolation-mode, layout-flow, layout-grid, layout-grid-char, layout-grid-line, layout-grid-mode, layout-grid-type, line-break, overflow-style, perspective, perspective-origin, perspective-origin-x, perspective-origin-y, scroll-boundary, scroll-boundary-bottom, scroll-boundary-left, scroll-boundary-right, scroll-boundary-top, scroll-chaining, scroll-rails, scroll-snap-points-x, scroll-snap-points-y, scroll-snap-type, scroll-snap-x, scroll-snap-y, scrollbar-arrow-color, scrollbar-base-color, scrollbar-darkshadow-color, scrollbar-face-color, scrollbar-highlight-color, scrollbar-shadow-color, scrollbar-track-color, text-align-last, text-autospace, text-justify, text-kashida-space, text-overflow, text-size-adjust, text-underline-position, touch-action, transform, transform-origin, transform-origin-x, transform-origin-y, transform-origin-z, transform-style, transition, transition-delay, transition-duration, transition-property, transition-timing-function, user-select, word-break, wrap-flow, wrap-margin, wrap-through, writing-mode',
'o': 'dashboard-region, animation, animation-delay, animation-direction, animation-duration, animation-fill-mode, animation-iteration-count, animation-name, animation-play-state, animation-timing-function, border-image, link, link-source, object-fit, object-position, tab-size, table-baseline, transform, transform-origin, transition, transition-delay, transition-duration, transition-property, transition-timing-function, accesskey, input-format, input-required, marquee-dir, marquee-loop, marquee-speed, marquee-style'
};
Object.keys(props).forEach(function(k) {
prefs.define('css.' + k + 'Properties', props[k], descTemplate({vendor: k}));
prefs.define('css.' + k + 'PropertiesAddon', '', descAddonTemplate({vendor: k}));
});
prefs.define('css.unitlessProperties', 'z-index, line-height, opacity, font-weight, zoom',
'The list of properties whose values must not contain units.');
prefs.define('css.intUnit', 'px', 'Default unit for integer values');
prefs.define('css.floatUnit', 'em', 'Default unit for float values');
prefs.define('css.keywords', 'auto, inherit, all',
'A comma-separated list of valid keywords that can be used in CSS abbreviations.');
prefs.define('css.keywordAliases', 'a:auto, i:inherit, s:solid, da:dashed, do:dotted, t:transparent',
'A comma-separated list of keyword aliases, used in CSS abbreviation. '
+ 'Each alias should be defined as <code>alias:keyword_name</code>.');
prefs.define('css.unitAliases', 'e:em, p:%, x:ex, r:rem',
'A comma-separated list of unit aliases, used in CSS abbreviation. '
+ 'Each alias should be defined as <code>alias:unit_value</code>.');
prefs.define('css.color.short', true,
'Should color values like <code>#ffffff</code> be shortened to '
+ '<code>#fff</code> after abbreviation with color was expanded.');
prefs.define('css.color.case', 'keep',
'Letter case of color values generated by abbreviations with color '
+ '(like <code>c#0</code>). Possible values are <code>upper</code>, '
+ '<code>lower</code> and <code>keep</code>.');
prefs.define('css.fuzzySearch', true,
'Enable fuzzy search among CSS snippet names. When enabled, every '
+ '<em>unknown</em> snippet will be scored against available snippet '
+ 'names (not values or CSS properties!). The match with best score '
+ 'will be used to resolve snippet value. For example, with this '
+ 'preference enabled, the following abbreviations are equal: '
+ '<code>ov:h</code> == <code>ov-h</code> == <code>o-h</code> == '
+ '<code>oh</code>');
prefs.define('css.fuzzySearchMinScore', 0.3,
'The minium score (from 0 to 1) that fuzzy-matched abbreviation should '
+ 'achive. Lower values may produce many false-positive matches, '
+ 'higher values may reduce possible matches.');
prefs.define('css.alignVendor', false,
'If set to <code>true</code>, all generated vendor-prefixed properties '
+ 'will be aligned by real property name.');
function isNumeric(ch) {
var code = ch && ch.charCodeAt(0);
return (ch && ch == '.' || (code > 47 && code < 58));
}
/**
* Check if provided snippet contains only one CSS property and value.
* @param {String} snippet
* @returns {Boolean}
*/
function isSingleProperty(snippet) {
snippet = utils.trim(snippet);
// check if it doesn't contain a comment and a newline
if (/\/\*|\n|\r/.test(snippet)) {
return false;
}
// check if it's a valid snippet definition
if (!/^[a-z0-9\-]+\s*\:/i.test(snippet)) {
return false;
}
return snippet.replace(/\$\{.+?\}/g, '').split(':').length == 2;
}
/**
* Normalizes abbreviated value to final CSS one
* @param {String} value
* @returns {String}
*/
function normalizeValue(value) {
if (value.charAt(0) == '-' && !/^\-[\.\d]/.test(value)) {
value = value.replace(/^\-+/, '');
}
var ch = value.charAt(0);
if (ch == '#') {
return normalizeHexColor(value);
}
if (ch == '$') {
return utils.escapeText(value);
}
return getKeyword(value);
}
function normalizeHexColor(value) {
var hex = value.replace(/^#+/, '') || '0';
if (hex.toLowerCase() == 't') {
return 'transparent';
}
var opacity = '';
hex = hex.replace(/\.(\d+)$/, function(str) {
opacity = '0' + str;
return '';
});
var repeat = utils.repeatString;
var color = null;
switch (hex.length) {
case 1:
color = repeat(hex, 6);
break;
case 2:
color = repeat(hex, 3);
break;
case 3:
color = hex.charAt(0) + hex.charAt(0) + hex.charAt(1) + hex.charAt(1) + hex.charAt(2) + hex.charAt(2);
break;
case 4:
color = hex + hex.substr(0, 2);
break;
case 5:
color = hex + hex.charAt(0);
break;
default:
color = hex.substr(0, 6);
}
if (opacity) {
return toRgba(color, opacity);
}
// color must be shortened?
if (prefs.get('css.color.short')) {
var p = color.split('');
if (p[0] == p[1] && p[2] == p[3] && p[4] == p[5]) {
color = p[0] + p[2] + p[4];
}
}
// should transform case?
switch (prefs.get('css.color.case')) {
case 'upper':
color = color.toUpperCase();
break;
case 'lower':
color = color.toLowerCase();
break;
}
return '#' + color;
}
/**
* Transforms HEX color definition into RGBA one
* @param {String} color HEX color, 6 characters
* @param {String} opacity Opacity value
* @return {String}
*/
function toRgba(color, opacity) {
var r = parseInt(color.substr(0, 2), 16);
var g = parseInt(color.substr(2, 2), 16);
var b = parseInt(color.substr(4, 2), 16);
return 'rgba(' + [r, g, b, opacity].join(', ') + ')';
}
function getKeyword(name) {
var aliases = prefs.getDict('css.keywordAliases');
return name in aliases ? aliases[name] : name;
}
function getUnit(name) {
var aliases = prefs.getDict('css.unitAliases');
return name in aliases ? aliases[name] : name;
}
function isValidKeyword(keyword) {
return ~prefs.getArray('css.keywords').indexOf(getKeyword(keyword));
}
/**
* Check if passed CSS property support specified vendor prefix
* @param {String} property
* @param {String} prefix
*/
function hasPrefix(property, prefix) {
var info = vendorPrefixes[prefix];
if (!info)
info = utils.find(vendorPrefixes, function(data) {
return data.prefix == prefix;
});
return info && info.supports(property);
}
/**
* Finds available vendor prefixes for given CSS property.
* Search is performed within Can I Use database and internal
* property list
* @param {String} property CSS property name
* @return {Array} Array of resolved prefixes or null if
* prefixes are not available for this property at all.
* Empty array means prefixes are not available for current
* user-define era
*/
function findVendorPrefixes(property) {
var prefixes = ciu.resolvePrefixes(property);
if (!prefixes) {
// Can I Use database is disabled or prefixes are not
// available for this property
prefixes = [];
Object.keys(vendorPrefixes).forEach(function(key) {
if (hasPrefix(property, key)) {
prefixes.push(vendorPrefixes[key].prefix);
}
});
if (!prefixes.length) {
prefixes = null;
}
}
return prefixes;
}
/**
* Search for a list of supported prefixes for CSS property. This list
* is used to generate all-prefixed snippet
* @param {String} property CSS property name
* @returns {Array}
*/
function findInternalPrefixes(property, noAutofill) {
var result = [];
var prefixes = findVendorPrefixes(property);
if (prefixes) {
var prefixMap = {};
Object.keys(vendorPrefixes).forEach(function(key) {
prefixMap[vendorPrefixes[key].prefix] = key;
});
result = prefixes.map(function(prefix) {
return prefixMap[prefix];
});
}
if (!result.length && !noAutofill) {
// add all non-obsolete prefixes
Object.keys(vendorPrefixes).forEach(function(prefix) {
if (!vendorPrefixes[prefix].obsolete) {
result.push(prefix);
}
});
}
return result;
}
function addPrefix(name, obj) {
if (typeof obj === 'string') {
obj = {prefix: obj};
}
vendorPrefixes[name] = utils.extend({}, prefixObj, obj);
}
function getSyntaxPreference(name, syntax) {
if (syntax) {
// hacky alias for Stylus dialect
if (syntax == 'styl') {
syntax = 'stylus';
}
var val = prefs.get(syntax + '.' + name);
if (typeof val !== 'undefined') {
return val;
}
}
return prefs.get('css.' + name);
}
/**
* Format CSS property according to current syntax dialect
* @param {String} property
* @param {String} syntax
* @returns {String}
*/
function formatProperty(property, syntax) {
var ix = property.indexOf(':');
property = property.substring(0, ix).replace(/\s+$/, '')
+ getSyntaxPreference('valueSeparator', syntax)
+ utils.trim(property.substring(ix + 1));
return property.replace(/\s*;\s*$/, getSyntaxPreference('propertyEnd', syntax));
}
/**
* Transforms snippet value if required. For example, this transformation
* may add <i>!important</i> declaration to CSS property
* @param {String} snippet
* @param {Boolean} isImportant
* @returns {String}
*/
function transformSnippet(snippet, isImportant, syntax) {
if (typeof snippet !== 'string') {
snippet = snippet.data;
}
if (!isSingleProperty(snippet)) {
return snippet;
}
if (isImportant) {
if (~snippet.indexOf(';')) {
snippet = snippet.split(';').join(' !important;');
} else {
snippet += ' !important';
}
}
return formatProperty(snippet, syntax);
}
function getProperties(key) {
var list = prefs.getArray(key);
var addon = prefs.getArray(key + 'Addon');
if (addon) {
addon.forEach(function(prop) {
if (prop.charAt(0) == '-') {
list = utils.without(list, prop.substr(1));
} else {
if (prop.charAt(0) == '+')
prop = prop.substr(1);
list.push(prop);
}
});
}
return list;
}
/**
* Tries to produce properties with vendor-prefixed value
* @param {Object} snippetObj Parsed snippet object
* @return {Array} Array of properties with prefixed values
*/
function resolvePrefixedValues(snippetObj, isImportant, syntax) {
var prefixes = [];
var lookup = {};
var parts = cssEditTree.findParts(snippetObj.value);
parts.reverse();
parts.forEach(function(p) {
var partValue = p.substring(snippetObj.value);
(findVendorPrefixes(partValue) || []).forEach(function(prefix) {
if (!lookup[prefix]) {
lookup[prefix] = snippetObj.value;
prefixes.push(prefix);
}
lookup[prefix] = utils.replaceSubstring(lookup[prefix], '-' + prefix + '-' + partValue, p);
});
});
return prefixes.map(function(prefix) {
return transformSnippet(snippetObj.name + ':' + lookup[prefix], isImportant, syntax);
});
}
// TODO refactor, this looks awkward now
addPrefix('w', {
prefix: 'webkit'
});
addPrefix('m', {
prefix: 'moz'
});
addPrefix('s', {
prefix: 'ms'
});
addPrefix('o', {
prefix: 'o'
});
module = module || {};
module.exports = {
/**
* Adds vendor prefix
* @param {String} name One-character prefix name
* @param {Object} obj Object describing vendor prefix
* @memberOf cssResolver
*/
addPrefix: addPrefix,
/**
* Check if passed CSS property supports specified vendor prefix
* @param {String} property
* @param {String} prefix
*/
supportsPrefix: hasPrefix,
resolve: function(node, syntax) {
var cssSyntaxes = prefs.getArray('css.syntaxes');
if (cssSyntaxes && ~cssSyntaxes.indexOf(syntax) && node.isElement()) {
return this.expandToSnippet(node.abbreviation, syntax);
}
return null;
},
/**
* Returns prefixed version of passed CSS property, only if this
* property supports such prefix
* @param {String} property
* @param {String} prefix
* @returns
*/
prefixed: function(property, prefix) {
return hasPrefix(property, prefix)
? '-' + prefix + '-' + property
: property;
},
/**
* Returns list of all registered vendor prefixes
* @returns {Array}
*/
listPrefixes: function() {
return vendorPrefixes.map(function(obj) {
return obj.prefix;
});
},
/**
* Returns object describing vendor prefix
* @param {String} name
* @returns {Object}
*/
getPrefix: function(name) {
return vendorPrefixes[name];
},
/**
* Removes prefix object
* @param {String} name
*/
removePrefix: function(name) {
if (name in vendorPrefixes)
delete vendorPrefixes[name];
},
/**
* Extract vendor prefixes from abbreviation
* @param {String} abbr
* @returns {Object} Object containing array of prefixes and clean
* abbreviation name
*/
extractPrefixes: function(abbr) {
if (abbr.charAt(0) != '-') {
return {
property: abbr,
prefixes: null
};
}
// abbreviation may either contain sequence of one-character prefixes
// or just dash, meaning that user wants to produce all possible
// prefixed properties
var i = 1, il = abbr.length, ch;
var prefixes = [];
while (i < il) {
ch = abbr.charAt(i);
if (ch == '-') {
// end-sequence character found, stop searching
i++;
break;
}
if (ch in vendorPrefixes) {
prefixes.push(ch);
} else {
// no prefix found, meaning user want to produce all
// vendor-prefixed properties
prefixes.length = 0;
i = 1;
break;
}
i++;
}
// reached end of abbreviation and no property name left
if (i == il -1) {
i = 1;
prefixes.length = 1;
}
return {
property: abbr.substring(i),
prefixes: prefixes.length ? prefixes : 'all'
};
},
/**
* Search for value substring in abbreviation
* @param {String} abbr
* @returns {String} Value substring
*/
findValuesInAbbreviation: function(abbr, syntax) {
syntax = syntax || 'css';
var i = 0, il = abbr.length, value = '', ch;
while (i < il) {
ch = abbr.charAt(i);
if (isNumeric(ch) || ch == '#' || ch == '$' || (ch == '-' && isNumeric(abbr.charAt(i + 1)))) {
value = abbr.substring(i);
break;
}
i++;
}
// try to find keywords in abbreviation
var property = abbr.substring(0, abbr.length - value.length);
var keywords = [];
// try to extract some commonly-used properties
while (~property.indexOf('-') && !resources.findSnippet(syntax, property)) {
var parts = property.split('-');
var lastPart = parts.pop();
if (!isValidKeyword(lastPart)) {
break;
}
keywords.unshift(lastPart);
property = parts.join('-');
}
return keywords.join('-') + value;
},
parseValues: function(str) {
/** @type StringStream */
var stream = stringStream.create(str);
var values = [];
var ch = null;
while ((ch = stream.next())) {
if (ch == '$') {
stream.match(/^[^\$]+/, true);
values.push(stream.current());
} else if (ch == '#') {
stream.match(/^t|[0-9a-f]+(\.\d+)?/i, true);
values.push(stream.current());
} else if (ch == '-') {
if (isValidKeyword(utils.last(values)) ||
( stream.start && isNumeric(str.charAt(stream.start - 1)) )
) {
stream.start = stream.pos;
}
stream.match(/^\-?[0-9]*(\.[0-9]+)?[a-z%\.]*/, true);
values.push(stream.current());
} else {
stream.match(/^[0-9]*(\.[0-9]*)?[a-z%]*/, true);
values.push(stream.current());
}
stream.start = stream.pos;
}
return values
.filter(function(item) {
return !!item;
})
.map(normalizeValue);
},
/**
* Extracts values from abbreviation
* @param {String} abbr
* @returns {Object} Object containing array of values and clean
* abbreviation name
*/
extractValues: function(abbr) {
// search for value start
var abbrValues = this.findValuesInAbbreviation(abbr);
if (!abbrValues) {
return {
property: abbr,
values: null
};
}
return {
property: abbr.substring(0, abbr.length - abbrValues.length).replace(/-$/, ''),
values: this.parseValues(abbrValues)
};
},
/**
* Normalizes value, defined in abbreviation.
* @param {String} value
* @param {String} property
* @returns {String}
*/
normalizeValue: function(value, property) {
property = (property || '').toLowerCase();
var unitlessProps = prefs.getArray('css.unitlessProperties');
return value.replace(/^(\-?[0-9\.]+)([a-z]*)$/, function(str, val, unit) {
if (!unit && (val == '0' || ~unitlessProps.indexOf(property)))
return val;
if (!unit)
return val.replace(/\.$/, '') + prefs.get(~val.indexOf('.') ? 'css.floatUnit' : 'css.intUnit');
return val + getUnit(unit);
});
},
/**
* Expands abbreviation into a snippet
* @param {String} abbr Abbreviation name to expand
* @param {String} value Abbreviation value
* @param {String} syntax Currect syntax or dialect. Default is 'css'
* @returns {Object} Array of CSS properties and values or predefined
* snippet (string or element)
*/
expand: function(abbr, value, syntax) {
syntax = syntax || 'css';
var autoInsertPrefixes = prefs.get(syntax + '.autoInsertVendorPrefixes');
// check if snippet should be transformed to !important
var isImportant = /^(.+)\!$/.test(abbr);
if (isImportant) {
abbr = RegExp.$1;
}
// check if we have abbreviated resource
var snippet = resources.findSnippet(syntax, abbr);
if (snippet && !autoInsertPrefixes) {
return transformSnippet(snippet, isImportant, syntax);
}
// no abbreviated resource, parse abbreviation
var prefixData = this.extractPrefixes(abbr);
var valuesData = this.extractValues(prefixData.property);
var abbrData = utils.extend(prefixData, valuesData);
if (!snippet) {
snippet = resources.findSnippet(syntax, abbrData.property);
} else {
abbrData.values = null;
}
if (!snippet && prefs.get('css.fuzzySearch')) {
// lets try fuzzy search
snippet = resources.fuzzyFindSnippet(syntax, abbrData.property, parseFloat(prefs.get('css.fuzzySearchMinScore')));
}
if (!snippet) {
if (!abbrData.property) {
return null;
}
snippet = abbrData.property + ':' + defaultValue;
} else if (typeof snippet !== 'string') {
snippet = snippet.data;
}
if (!isSingleProperty(snippet)) {
return snippet;
}
var snippetObj = this.splitSnippet(snippet);
var result = [];
if (!value && abbrData.values) {
value = abbrData.values.map(function(val) {
return this.normalizeValue(val, snippetObj.name);
}, this).join(' ') + ';';
}
snippetObj.value = value || snippetObj.value;
var prefixes = abbrData.prefixes == 'all' || (!abbrData.prefixes && autoInsertPrefixes)
? findInternalPrefixes(snippetObj.name, autoInsertPrefixes && abbrData.prefixes != 'all')
: abbrData.prefixes;
var names = [], propName;
(prefixes || []).forEach(function(p) {
if (p in vendorPrefixes) {
propName = vendorPrefixes[p].transformName(snippetObj.name);
names.push(propName);
result.push(transformSnippet(propName + ':' + snippetObj.value,
isImportant, syntax));
}
});
// put the original property
result.push(transformSnippet(snippetObj.name + ':' + snippetObj.value, isImportant, syntax));
names.push(snippetObj.name);
result = resolvePrefixedValues(snippetObj, isImportant, syntax).concat(result);
if (prefs.get('css.alignVendor')) {
var pads = utils.getStringsPads(names);
result = result.map(function(prop, i) {
return pads[i] + prop;
});
}
return result;
},
/**
* Same as <code>expand</code> method but transforms output into
* Emmet snippet
* @param {String} abbr
* @param {String} syntax
* @returns {String}
*/
expandToSnippet: function(abbr, syntax) {
var snippet = this.expand(abbr, null, syntax);
if (snippet === null) {
return null;
}
if (Array.isArray(snippet)) {
return snippet.join('\n');
}
if (typeof snippet !== 'string') {
return snippet.data;
}
return snippet + '';
},
/**
* Split snippet into a CSS property-value pair
* @param {String} snippet
*/
splitSnippet: function(snippet) {
snippet = utils.trim(snippet);
if (snippet.indexOf(':') == -1) {
return {
name: snippet,
value: defaultValue
};
}
var pair = snippet.split(':');
return {
name: utils.trim(pair.shift()),
// replace ${0} tabstop to produce valid vendor-prefixed values
// where possible
value: utils.trim(pair.join(':')).replace(/^(\$\{0\}|\$0)(\s*;?)$/, '${1}$2')
};
},
getSyntaxPreference: getSyntaxPreference,
transformSnippet: transformSnippet,
vendorPrefixes: findVendorPrefixes
};
return module.exports;
});
},{"../assets/caniuse":23,"../assets/preferences":28,"../assets/resources":31,"../assets/stringStream":32,"../editTree/css":37,"../utils/common":73,"../utils/template":77}],65:[function(require,module,exports){
/**
* 'Expand Abbreviation' handler that parses gradient definition from under
* cursor and updates CSS rule with vendor-prefixed values.
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var prefs = require('../assets/preferences');
var resources = require('../assets/resources');
var utils = require('../utils/common');
var stringStream = require('../assets/stringStream');
var cssResolver = require('./css');
var range = require('../assets/range');
var cssEditTree = require('../editTree/css');
var editorUtils = require('../utils/editor');
var linearGradient = require('./gradient/linear');
var cssSyntaxes = ['css', 'less', 'sass', 'scss', 'stylus', 'styl'];
// XXX define preferences
prefs.define('css.gradient.prefixes', 'webkit, moz, o',
'A comma-separated list of vendor-prefixes for which values should '
+ 'be generated.');
prefs.define('css.gradient.oldWebkit', false,
'Generate gradient definition for old Webkit implementations');
prefs.define('css.gradient.omitDefaultDirection', true,
'Do not output default direction definition in generated gradients.');
prefs.define('css.gradient.defaultProperty', 'background-image',
'When gradient expanded outside CSS value context, it will produce '
+ 'properties with this name.');
prefs.define('css.gradient.fallback', false,
'With this option enabled, CSS gradient generator will produce '
+ '<code>background-color</code> property with gradient first color '
+ 'as fallback for old browsers.');
/**
* Resolves property name (abbreviation): searches for snippet definition in
* 'resources' and returns new name of matched property
*/
function resolvePropertyName(name, syntax) {
var snippet = resources.findSnippet(syntax, name);
if (!snippet && prefs.get('css.fuzzySearch')) {
var minScore = parseFloat(prefs.get('css.fuzzySearchMinScore'));
snippet = resources.fuzzyFindSnippet(syntax, name, minScore);
}
if (snippet) {
if (typeof snippet !== 'string') {
snippet = snippet.data;
}
return cssResolver.splitSnippet(snippet).name;
}
}
/**
* Returns vendor prefixes for given gradient type
* @param {String} type Gradient type (currently, 'linear-gradient'
* is the only supported value)
* @return {Array}
*/
function getGradientPrefixes(type) {
var prefixes = cssResolver.vendorPrefixes(type);
if (!prefixes) {
// disabled Can I Use, fallback to property list
prefixes = prefs.getArray('css.gradient.prefixes');
}
return prefixes || [];
}
function getPrefixedNames(type) {
var prefixes = getGradientPrefixes(type);
var names = prefixes
? prefixes.map(function(p) {
return '-' + p + '-' + type;
})
: [];
names.push(type);
return names;
}
/**
* Returns list of CSS properties with gradient
* @param {Array} gradient List of gradient objects
* @param {CSSEditElement} property Original CSS property
* @returns {Array}
*/
function getPropertiesForGradient(gradients, property) {
var props = [];
var propertyName = property.name();
var omitDir = prefs.get('css.gradient.omitDefaultDirection');
if (prefs.get('css.gradient.fallback') && ~propertyName.toLowerCase().indexOf('background')) {
props.push({
name: 'background-color',
value: '${1:' + gradients[0].gradient.colorStops[0].color + '}'
});
}
var value = property.value();
getGradientPrefixes('linear-gradient').forEach(function(prefix) {
var name = cssResolver.prefixed(propertyName, prefix);
if (prefix == 'webkit' && prefs.get('css.gradient.oldWebkit')) {
try {
props.push({
name: name,
value: insertGradientsIntoCSSValue(gradients, value, {
prefix: prefix,
oldWebkit: true,
omitDefaultDirection: omitDir
})
});
} catch(e) {}
}
props.push({
name: name,
value: insertGradientsIntoCSSValue(gradients, value, {
prefix: prefix,
omitDefaultDirection: omitDir
})
});
});
return props.sort(function(a, b) {
return b.name.length - a.name.length;
});
}
/**
* Replaces old gradient definitions in given CSS property value
* with new ones, preserving original formatting
* @param {Array} gradients List of CSS gradients
* @param {String} value Original CSS value
* @param {Object} options Options for gradients stringify() method
* @return {String}
*/
function insertGradientsIntoCSSValue(gradients, value, options) {
// gradients *should* passed in order they actually appear in CSS property
// iterate over it in backward direction to preserve gradient locations
options = options || {};
gradients = utils.clone(gradients);
gradients.reverse().forEach(function(item, i) {
var suffix = !i && options.placeholder ? options.placeholder : '';
var str = options.oldWebkit ? item.gradient.stringifyOldWebkit(options) : item.gradient.stringify(options);
value = utils.replaceSubstring(value, str + suffix, item.matchedPart);
});
return value;
}
/**
* Returns list of properties with the same meaning
* (e.g. vendor-prefixed + original name)
* @param {String} property CSS property name
* @return {Array}
*/
function similarPropertyNames(property) {
if (typeof property !== 'string') {
property = property.name();
}
var similarProps = (cssResolver.vendorPrefixes(property) || []).map(function(prefix) {
return '-' + prefix + '-' + property;
});
similarProps.push(property);
return similarProps;
}
/**
* Pastes gradient definition into CSS rule with correct vendor-prefixes
* @param {EditElement} property Matched CSS property
* @param {Array} gradients List of gradients to insert
*/
function pasteGradient(property, gradients) {
var rule = property.parent;
var alignVendor = prefs.get('css.alignVendor');
var omitDir = prefs.get('css.gradient.omitDefaultDirection');
// we may have aligned gradient definitions: find the smallest value
// separator
var sep = property.styleSeparator;
var before = property.styleBefore;
// first, remove all properties within CSS rule with the same name and
// gradient definition
rule.getAll(similarPropertyNames(property)).forEach(function(item) {
if (item != property && /gradient/i.test(item.value())) {
if (item.styleSeparator.length < sep.length) {
sep = item.styleSeparator;
}
if (item.styleBefore.length < before.length) {
before = item.styleBefore;
}
rule.remove(item);
}
});
if (alignVendor) {
// update prefix
if (before != property.styleBefore) {
var fullRange = property.fullRange();
rule._updateSource(before, fullRange.start, fullRange.start + property.styleBefore.length);
property.styleBefore = before;
}
// update separator value
if (sep != property.styleSeparator) {
rule._updateSource(sep, property.nameRange().end, property.valueRange().start);
property.styleSeparator = sep;
}
}
var value = property.value();
// create list of properties to insert
var propsToInsert = getPropertiesForGradient(gradients, property);
// align prefixed values
if (alignVendor) {
var names = [], values = [];
propsToInsert.forEach(function(item) {
names.push(item.name);
values.push(item.value);
});
values.push(property.value());
names.push(property.name());
var valuePads = utils.getStringsPads(values.map(function(v) {
return v.substring(0, v.indexOf('('));
}));
var namePads = utils.getStringsPads(names);
property.name(namePads[namePads.length - 1] + property.name());
propsToInsert.forEach(function(prop, i) {
prop.name = namePads[i] + prop.name;
prop.value = valuePads[i] + prop.value;
});
property.value(valuePads[valuePads.length - 1] + property.value());
}
// put vendor-prefixed definitions before current rule
propsToInsert.forEach(function(prop) {
rule.add(prop.name, prop.value, rule.indexOf(property));
});
// put vanilla-clean gradient definition into current rule
property.value(insertGradientsIntoCSSValue(gradients, value, {
placeholder: '${2}',
omitDefaultDirection: omitDir
}));
}
/**
* Validates caret position relatively to located gradients
* in CSS rule. In other words, it checks if its safe to
* expand gradients for current caret position or not.
*
* See issue https://github.com/sergeche/emmet-sublime/issues/411
*
* @param {Array} gradients List of parsed gradients
* @param {Number} caretPos Current caret position
* @param {String} syntax Current document syntax
* @return {Boolean}
*/
function isValidCaretPosition(gradients, caretPos, syntax) {
syntax = syntax || 'css';
if (syntax == 'css' || syntax == 'less' || syntax == 'scss') {
return true;
}
var offset = gradients.property.valueRange(true).start;
var parts = gradients.gradients;
// in case of preprocessors where properties are separated with
// newlines, make sure theres no gradient definition past
// current caret position.
for (var i = parts.length - 1; i >= 0; i--) {
if (parts[i].matchedPart.start + offset >= caretPos) {
return false;
}
}
return true;
}
module = module || {};
return module.exports = {
/**
* Search for gradient definitions inside CSS property value
* @returns {Array} Array of matched gradients
*/
findGradients: function(cssProp) {
var value = cssProp.value();
var gradients = [];
var that = this;
cssProp.valueParts().forEach(function(part) {
var partValue = part.substring(value);
if (linearGradient.isLinearGradient(partValue)) {
var gradient = linearGradient.parse(partValue);
if (gradient) {
gradients.push({
gradient: gradient,
matchedPart: part
});
}
}
});
return gradients.length ? gradients : null;
},
/**
* Returns list of gradients found in CSS property
* of given CSS code in specified (caret) position
* @param {String} css CSS code snippet
* @param {Number} pos Character index where to start searching for CSS property
* @return {Array}
*/
gradientsFromCSSProperty: function(css, pos) {
var cssProp = cssEditTree.propertyFromPosition(css, pos);
if (cssProp) {
var grd = this.findGradients(cssProp);
if (grd) {
return {
property: cssProp,
gradients: grd
};
}
}
return null;
},
/**
* Handler for “Expand Abbreviation” action
* @param {IEmmetEditor} editor
* @param {String} syntax
* @param {String} profile
* return {Boolean}
*/
expandAbbreviationHandler: function(editor, syntax, profile) {
var info = editorUtils.outputInfo(editor, syntax, profile);
if (!~cssSyntaxes.indexOf(info.syntax)) {
return false;
}
// let's see if we are expanding gradient definition
var caret = editor.getCaretPos();
var content = info.content;
var gradients = this.gradientsFromCSSProperty(content, caret);
if (gradients) {
if (!isValidCaretPosition(gradients, caret, info.syntax)) {
return false;
}
var cssProperty = gradients.property;
var cssRule = cssProperty.parent;
var ruleStart = cssRule.options.offset || 0;
var ruleEnd = ruleStart + cssRule.toString().length;
// Handle special case:
// user wrote gradient definition between existing CSS
// properties and did not finished it with semicolon.
// In this case, we have semicolon right after gradient
// definition and re-parse rule again
if (/[\n\r]/.test(cssProperty.value())) {
// insert semicolon at the end of gradient definition
var insertPos = cssProperty.valueRange(true).start + utils.last(gradients.gradients).matchedPart.end;
content = utils.replaceSubstring(content, ';', insertPos);
var _gradients = this.gradientsFromCSSProperty(content, caret);
if (_gradients) {
gradients = _gradients;
cssProperty = gradients.property;
cssRule = cssProperty.parent;
}
}
// make sure current property has terminating semicolon
cssProperty.end(';');
// resolve CSS property name
var resolvedName = resolvePropertyName(cssProperty.name(), syntax);
if (resolvedName) {
cssProperty.name(resolvedName);
}
pasteGradient(cssProperty, gradients.gradients);
editor.replaceContent(cssRule.toString(), ruleStart, ruleEnd, true);
return true;
}
return this.expandGradientOutsideValue(editor, syntax);
},
/**
* Tries to expand gradient outside CSS value
* @param {IEmmetEditor} editor
* @param {String} syntax
*/
expandGradientOutsideValue: function(editor, syntax) {
var propertyName = prefs.get('css.gradient.defaultProperty');
var omitDir = prefs.get('css.gradient.omitDefaultDirection');
if (!propertyName) {
return false;
}
// assuming that gradient definition is written on new line,
// do a simplified parsing
var content = String(editor.getContent());
/** @type Range */
var lineRange = range.create(editor.getCurrentLineRange());
// get line content and adjust range with padding
var line = lineRange.substring(content)
.replace(/^\s+/, function(pad) {
lineRange.start += pad.length;
return '';
})
.replace(/\s+$/, function(pad) {
lineRange.end -= pad.length;
return '';
});
// trick parser: make it think that were parsing actual CSS property
var fakeCSS = 'a{' + propertyName + ': ' + line + ';}';
var gradients = this.gradientsFromCSSProperty(fakeCSS, fakeCSS.length - 2);
if (gradients) {
var props = getPropertiesForGradient(gradients.gradients, gradients.property);
props.push({
name: gradients.property.name(),
value: insertGradientsIntoCSSValue(gradients.gradients, gradients.property.value(), {
placeholder: '${2}',
omitDefaultDirection: omitDir
})
});
var sep = cssResolver.getSyntaxPreference('valueSeparator', syntax);
var end = cssResolver.getSyntaxPreference('propertyEnd', syntax);
if (prefs.get('css.alignVendor')) {
var pads = utils.getStringsPads(props.map(function(prop) {
return prop.value.substring(0, prop.value.indexOf('('));
}));
props.forEach(function(prop, i) {
prop.value = pads[i] + prop.value;
});
}
props = props.map(function(item) {
return item.name + sep + item.value + end;
});
editor.replaceContent(props.join('\n'), lineRange.start, lineRange.end);
return true;
}
return false;
},
/**
* Handler for “Reflect CSS Value“ action
* @param {String} property
*/
reflectValueHandler: function(property) {
var omitDir = prefs.get('css.gradient.omitDefaultDirection');
var gradients = this.findGradients(property);
if (!gradients) {
return false;
}
var that = this;
var value = property.value();
// reflect value for properties with the same name
property.parent.getAll(similarPropertyNames(property)).forEach(function(prop) {
if (prop === property) {
return;
}
// make sure current property contains gradient definition,
// otherwise skip it
var localGradients = that.findGradients(prop);
if (localGradients) {
// detect vendor prefix for current property
var localValue = prop.value();
var dfn = localGradients[0].matchedPart.substring(localValue);
var prefix = '';
if (/^\s*\-([a-z]+)\-/.test(dfn)) {
prefix = RegExp.$1;
}
prop.value(insertGradientsIntoCSSValue(gradients, value, {
prefix: prefix,
omitDefaultDirection: omitDir
}));
}
});
return true;
}
};
});
},{"../assets/preferences":28,"../assets/range":30,"../assets/resources":31,"../assets/stringStream":32,"../editTree/css":37,"../utils/common":73,"../utils/editor":75,"./css":64,"./gradient/linear":66}],66:[function(require,module,exports){
/**
* CSS linear gradient definition
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var stringStream = require('../../assets/stringStream');
var utils = require('../../utils/common');
// all directions are expressed in “new style” degrees
var directions = {
'bottom': 0,
'bottom left': 45,
'left': 90,
'top left': 135,
'top': 180,
'top right': 225,
'right': 270,
'bottom right': 315,
'to top': 0,
'to top right': 45,
'to right': 90,
'to bottom right': 135,
'to bottom': 180,
'to bottom left': 225,
'to left': 270,
'to top left': 315
};
var defaultDirections = ['top', 'to bottom', '0deg'];
var reLinearGradient = /^\s*(\-[a-z]+\-)?(lg|linear\-gradient)\s*\(/i;
var reDeg = /(\d+)deg/i;
var reKeyword = /top|bottom|left|right/i;
function LinearGradient(dfn) {
this.colorStops = [];
this.direction = 180;
// extract tokens
var stream = stringStream.create(utils.trim(dfn));
var ch, cur;
while ((ch = stream.next())) {
if (stream.peek() == ',') {
// Is it a first entry? Check if its a direction
cur = stream.current();
if (!this.colorStops.length && (reDeg.test(cur) || reKeyword.test(cur))) {
this.direction = resolveDirection(cur);
} else {
this.addColorStop(cur);
}
stream.next();
stream.eatSpace();
stream.start = stream.pos;
} else if (ch == '(') { // color definition, like 'rgb(0,0,0)'
stream.skipTo(')');
}
}
// add last token
this.addColorStop(stream.current());
}
LinearGradient.prototype = {
type: 'linear-gradient',
addColorStop: function(color, ix) {
color = normalizeSpace(color || '');
if (!color) {
return;
}
color = this.parseColorStop(color);
if (typeof ix === 'undefined') {
this.colorStops.push(color);
} else {
this.colorStops.splice(ix, 0, color);
}
},
/**
* Parses color stop definition
* @param {String} colorStop
* @returns {Object}
*/
parseColorStop: function(colorStop) {
colorStop = normalizeSpace(colorStop);
// find color declaration
// first, try complex color declaration, like rgb(0,0,0)
var color = null;
colorStop = colorStop.replace(/^(\w+\(.+?\))\s*/, function(str, c) {
color = c;
return '';
});
if (!color) {
// try simple declaration, like yellow, #fco, #ffffff, etc.
var parts = colorStop.split(' ');
color = parts[0];
colorStop = parts[1] || '';
}
var result = {
color: color
};
if (colorStop) {
// there's position in color stop definition
colorStop.replace(/^(\-?[\d\.]+)([a-z%]+)?$/, function(str, pos, unit) {
result.position = pos;
if (~pos.indexOf('.')) {
unit = '';
} else if (!unit) {
unit = '%';
}
if (unit) {
result.unit = unit;
}
});
}
return result;
},
stringify: function(options) {
options = options || {};
var fn = 'linear-gradient';
if (options.prefix) {
fn = '-' + options.prefix + '-' + fn;
}
// transform color-stops
var parts = this.colorStops.map(function(cs) {
var pos = cs.position ? ' ' + cs.position + (cs.unit || '') : '';
return cs.color + pos;
});
var dir = stringifyDirection(this.direction, !!options.prefix);
if (!options.omitDefaultDirection || !~defaultDirections.indexOf(dir)) {
parts.unshift(dir);
}
return fn + '(' + parts.join(', ') + ')';
},
stringifyOldWebkit: function() {
var colorStops = this.colorStops.map(function(item) {
return utils.clone(item);
});
// normalize color-stops position
colorStops.forEach(function(cs) {
if (!('position' in cs)) // implied position
return;
if (~cs.position.indexOf('.') || cs.unit == '%') {
cs.position = parseFloat(cs.position) / (cs.unit == '%' ? 100 : 1);
} else {
throw "Can't convert color stop '" + (cs.position + (cs.unit || '')) + "'";
}
});
this._fillImpliedPositions(colorStops);
// transform color-stops into string representation
colorStops = colorStops.map(function(cs, i) {
if (!cs.position && !i) {
return 'from(' + cs.color + ')';
}
if (cs.position == 1 && i == colorStops.length - 1) {
return 'to(' + cs.color + ')';
}
return 'color-stop(' + (cs.position.toFixed(2).replace(/\.?0+$/, '')) + ', ' + cs.color + ')';
});
return '-webkit-gradient(linear, '
+ oldWebkitDirection((this.direction + 180) % 360)
+ ', '
+ colorStops.join(', ')
+ ')';
},
/**
* Fills-out implied positions in color-stops. This function is useful for
* old Webkit gradient definitions
*/
_fillImpliedPositions: function(colorStops) {
var from = 0;
colorStops.forEach(function(cs, i) {
// make sure that first and last positions are defined
if (!i) {
return cs.position = cs.position || 0;
}
if (i == colorStops.length - 1 && !('position' in cs)) {
cs.position = 1;
}
if ('position' in cs) {
var start = colorStops[from].position || 0;
var step = (cs.position - start) / (i - from);
colorStops.slice(from, i).forEach(function(cs2, j) {
cs2.position = start + step * j;
});
from = i;
}
});
},
valueOf: function() {
return this.stringify();
}
};
function normalizeSpace(str) {
return utils.trim(str).replace(/\s+/g, ' ');
}
/**
* Resolves textual direction to degrees
* @param {String} dir Direction to resolve
* @return {Number}
*/
function resolveDirection(dir) {
if (typeof dir == 'number') {
return dir;
}
dir = normalizeSpace(dir).toLowerCase();
if (reDeg.test(dir)) {
return +RegExp.$1;
}
var prefix = /^to\s/.test(dir) ? 'to ' : '';
var left = ~dir.indexOf('left') && 'left';
var right = ~dir.indexOf('right') && 'right';
var top = ~dir.indexOf('top') && 'top';
var bottom = ~dir.indexOf('bottom') && 'bottom';
var key = normalizeSpace(prefix + (top || bottom || '') + ' ' + (left || right || ''));
return directions[key] || 0;
}
/**
* Tries to find keyword for given direction, expressed in degrees
* @param {Number} dir Direction (degrees)
* @param {Boolean} oldStyle Use old style keywords (e.g. "top" instead of "to bottom")
* @return {String} Keyword or <code>Ndeg</code> expression
*/
function stringifyDirection(dir, oldStyle) {
var reNewStyle = /^to\s/;
var keys = Object.keys(directions).filter(function(k) {
var hasPrefix = reNewStyle.test(k);
return oldStyle ? !hasPrefix : hasPrefix;
});
for (var i = 0; i < keys.length; i++) {
if (directions[keys[i]] == dir) {
return keys[i];
}
}
if (oldStyle) {
dir = (dir + 270) % 360;
}
return dir + 'deg';
}
/**
* Creates direction definition for old Webkit gradients
* @param {String} direction
* @returns {String}
*/
function oldWebkitDirection(dir) {
dir = stringifyDirection(dir, true);
if(reDeg.test(dir)) {
throw "The direction is an angle that cant be converted.";
}
var v = function(pos) {
return ~dir.indexOf(pos) ? '100%' : '0';
};
return v('left') + ' ' + v('top') + ', ' + v('right') + ' ' + v('bottom');
}
return {
/**
* Parses gradient definition into an object.
* This object can be used to transform gradient into various
* forms
* @param {String} gradient Gradient definition
* @return {LinearGradient}
*/
parse: function(gradient) {
// cut out all redundant data
if (this.isLinearGradient(gradient)) {
gradient = gradient.replace(/^\s*[\-a-z]+\s*\(|\)\s*$/ig, '');
} else {
throw 'Invalid linear gradient definition:\n' + gradient;
}
return new LinearGradient(gradient);
},
/**
* Check if given string can be parsed as linear gradient
* @param {String} str
* @return {Boolean}
*/
isLinearGradient: function(str) {
return reLinearGradient.test(str);
},
resolveDirection: resolveDirection,
stringifyDirection: stringifyDirection
};
});
},{"../../assets/stringStream":32,"../../utils/common":73}],67:[function(require,module,exports){
/**
* Module for resolving tag names: returns best matched tag name for child
* element based on passed parent's tag name. Also provides utility function
* for element type detection (inline, block-level, empty)
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
var elementTypes = {
// empty: 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,keygen,command'.split(','),
empty: [],
blockLevel: 'address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,link,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul,h1,h2,h3,h4,h5,h6'.split(','),
inlineLevel: 'a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'.split(',')
};
var elementMap = {
'p': 'span',
'ul': 'li',
'ol': 'li',
'table': 'tr',
'tr': 'td',
'tbody': 'tr',
'thead': 'tr',
'tfoot': 'tr',
'colgroup': 'col',
'select': 'option',
'optgroup': 'option',
'audio': 'source',
'video': 'source',
'object': 'param',
'map': 'area'
};
return {
/**
* Returns best matched child element name for passed parent's
* tag name
* @param {String} name
* @returns {String}
* @memberOf tagName
*/
resolve: function(name) {
name = (name || '').toLowerCase();
if (name in elementMap)
return this.getMapping(name);
if (this.isInlineLevel(name))
return 'span';
return 'div';
},
/**
* Returns mapped child element name for passed parent's name
* @param {String} name
* @returns {String}
*/
getMapping: function(name) {
return elementMap[name.toLowerCase()];
},
/**
* Check if passed element name belongs to inline-level element
* @param {String} name
* @returns {Boolean}
*/
isInlineLevel: function(name) {
return this.isTypeOf(name, 'inlineLevel');
},
/**
* Check if passed element belongs to block-level element.
* For better matching of unknown elements (for XML, for example),
* you should use <code>!this.isInlineLevel(name)</code>
* @returns {Boolean}
*/
isBlockLevel: function(name) {
return this.isTypeOf(name, 'blockLevel');
},
/**
* Check if passed element is void (i.e. should not have closing tag).
* @returns {Boolean}
*/
isEmptyElement: function(name) {
return this.isTypeOf(name, 'empty');
},
/**
* Generic function for testing if element name belongs to specified
* elements collection
* @param {String} name Element name
* @param {String} type Collection name
* @returns {Boolean}
*/
isTypeOf: function(name, type) {
return ~elementTypes[type].indexOf(name);
},
/**
* Adds new parentchild mapping
* @param {String} parent
* @param {String} child
*/
addMapping: function(parent, child) {
elementMap[parent] = child;
},
/**
* Removes parent-child mapping
*/
removeMapping: function(parent) {
if (parent in elementMap)
delete elementMap[parent];
},
/**
* Adds new element into collection
* @param {String} name Element name
* @param {String} collection Collection name
*/
addElementToCollection: function(name, collection) {
if (!elementTypes[collection])
elementTypes[collection] = [];
var col = this.getCollection(collection);
if (!~col.indexOf(name)) {
col.push(name);
}
},
/**
* Removes element name from specified collection
* @param {String} name Element name
* @param {String} collection Collection name
* @returns
*/
removeElementFromCollection: function(name, collection) {
if (collection in elementTypes) {
elementTypes[collection] = utils.without(this.getCollection(collection), name);
}
},
/**
* Returns elements name collection
* @param {String} name Collection name
* @returns {Array}
*/
getCollection: function(name) {
return elementTypes[name];
}
};
});
},{"../utils/common":73}],68:[function(require,module,exports){
module.exports={
"variables": {
"lang": "en",
"locale": "en-US",
"charset": "UTF-8",
"indentation": "\t",
"newline": "\n"
},
"css": {
"filters": "css",
"profile": "css",
"snippets": {
"@i": "@import url(|);",
"@import": "@import url(|);",
"@m": "@media ${1:screen} {\n\t|\n}",
"@media": "@media ${1:screen} {\n\t|\n}",
"@f": "@font-face {\n\tfont-family:|;\n\tsrc:url(|);\n}",
"@f+": "@font-face {\n\tfont-family: '${1:FontName}';\n\tsrc: url('${2:FileName}.eot');\n\tsrc: url('${2:FileName}.eot?#iefix') format('embedded-opentype'),\n\t\t url('${2:FileName}.woff') format('woff'),\n\t\t url('${2:FileName}.ttf') format('truetype'),\n\t\t url('${2:FileName}.svg#${1:FontName}') format('svg');\n\tfont-style: ${3:normal};\n\tfont-weight: ${4:normal};\n}",
"@kf": "@-webkit-keyframes ${1:identifier} {\n\t${2:from} { ${3} }${6}\n\t${4:to} { ${5} }\n}\n@-o-keyframes ${1:identifier} {\n\t${2:from} { ${3} }${6}\n\t${4:to} { ${5} }\n}\n@-moz-keyframes ${1:identifier} {\n\t${2:from} { ${3} }${6}\n\t${4:to} { ${5} }\n}\n@keyframes ${1:identifier} {\n\t${2:from} { ${3} }${6}\n\t${4:to} { ${5} }\n}",
"anim": "animation:|;",
"anim-": "animation:${1:name} ${2:duration} ${3:timing-function} ${4:delay} ${5:iteration-count} ${6:direction} ${7:fill-mode};",
"animdel": "animation-delay:${1:time};",
"animdir": "animation-direction:${1:normal};",
"animdir:n": "animation-direction:normal;",
"animdir:r": "animation-direction:reverse;",
"animdir:a": "animation-direction:alternate;",
"animdir:ar": "animation-direction:alternate-reverse;",
"animdur": "animation-duration:${1:0}s;",
"animfm": "animation-fill-mode:${1:both};",
"animfm:f": "animation-fill-mode:forwards;",
"animfm:b": "animation-fill-mode:backwards;",
"animfm:bt": "animation-fill-mode:both;",
"animfm:bh": "animation-fill-mode:both;",
"animic": "animation-iteration-count:${1:1};",
"animic:i": "animation-iteration-count:infinite;",
"animn": "animation-name:${1:none};",
"animps": "animation-play-state:${1:running};",
"animps:p": "animation-play-state:paused;",
"animps:r": "animation-play-state:running;",
"animtf": "animation-timing-function:${1:linear};",
"animtf:e": "animation-timing-function:ease;",
"animtf:ei": "animation-timing-function:ease-in;",
"animtf:eo": "animation-timing-function:ease-out;",
"animtf:eio": "animation-timing-function:ease-in-out;",
"animtf:l": "animation-timing-function:linear;",
"animtf:cb": "animation-timing-function:cubic-bezier(${1:0.1}, ${2:0.7}, ${3:1.0}, ${3:0.1});",
"ap": "appearance:${none};",
"!": "!important",
"pos": "position:${1:relative};",
"pos:s": "position:static;",
"pos:a": "position:absolute;",
"pos:r": "position:relative;",
"pos:f": "position:fixed;",
"t": "top:|;",
"t:a": "top:auto;",
"r": "right:|;",
"r:a": "right:auto;",
"b": "bottom:|;",
"b:a": "bottom:auto;",
"l": "left:|;",
"l:a": "left:auto;",
"z": "z-index:|;",
"z:a": "z-index:auto;",
"fl": "float:${1:left};",
"fl:n": "float:none;",
"fl:l": "float:left;",
"fl:r": "float:right;",
"cl": "clear:${1:both};",
"cl:n": "clear:none;",
"cl:l": "clear:left;",
"cl:r": "clear:right;",
"cl:b": "clear:both;",
"colm": "columns:|;",
"colmc": "column-count:|;",
"colmf": "column-fill:|;",
"colmg": "column-gap:|;",
"colmr": "column-rule:|;",
"colmrc": "column-rule-color:|;",
"colmrs": "column-rule-style:|;",
"colmrw": "column-rule-width:|;",
"colms": "column-span:|;",
"colmw": "column-width:|;",
"d": "display:${1:block};",
"d:n": "display:none;",
"d:b": "display:block;",
"d:f": "display:flex;",
"d:if": "display:inline-flex;",
"d:i": "display:inline;",
"d:ib": "display:inline-block;",
"d:ib+": "display: inline-block;\n*display: inline;\n*zoom: 1;",
"d:li": "display:list-item;",
"d:ri": "display:run-in;",
"d:cp": "display:compact;",
"d:tb": "display:table;",
"d:itb": "display:inline-table;",
"d:tbcp": "display:table-caption;",
"d:tbcl": "display:table-column;",
"d:tbclg": "display:table-column-group;",
"d:tbhg": "display:table-header-group;",
"d:tbfg": "display:table-footer-group;",
"d:tbr": "display:table-row;",
"d:tbrg": "display:table-row-group;",
"d:tbc": "display:table-cell;",
"d:rb": "display:ruby;",
"d:rbb": "display:ruby-base;",
"d:rbbg": "display:ruby-base-group;",
"d:rbt": "display:ruby-text;",
"d:rbtg": "display:ruby-text-group;",
"v": "visibility:${1:hidden};",
"v:v": "visibility:visible;",
"v:h": "visibility:hidden;",
"v:c": "visibility:collapse;",
"ov": "overflow:${1:hidden};",
"ov:v": "overflow:visible;",
"ov:h": "overflow:hidden;",
"ov:s": "overflow:scroll;",
"ov:a": "overflow:auto;",
"ovx": "overflow-x:${1:hidden};",
"ovx:v": "overflow-x:visible;",
"ovx:h": "overflow-x:hidden;",
"ovx:s": "overflow-x:scroll;",
"ovx:a": "overflow-x:auto;",
"ovy": "overflow-y:${1:hidden};",
"ovy:v": "overflow-y:visible;",
"ovy:h": "overflow-y:hidden;",
"ovy:s": "overflow-y:scroll;",
"ovy:a": "overflow-y:auto;",
"ovs": "overflow-style:${1:scrollbar};",
"ovs:a": "overflow-style:auto;",
"ovs:s": "overflow-style:scrollbar;",
"ovs:p": "overflow-style:panner;",
"ovs:m": "overflow-style:move;",
"ovs:mq": "overflow-style:marquee;",
"zoo": "zoom:1;",
"zm": "zoom:1;",
"cp": "clip:|;",
"cp:a": "clip:auto;",
"cp:r": "clip:rect(${1:top} ${2:right} ${3:bottom} ${4:left});",
"bxz": "box-sizing:${1:border-box};",
"bxz:cb": "box-sizing:content-box;",
"bxz:bb": "box-sizing:border-box;",
"bxsh": "box-shadow:${1:inset }${2:hoff} ${3:voff} ${4:blur} ${5:color};",
"bxsh:r": "box-shadow:${1:inset }${2:hoff} ${3:voff} ${4:blur} ${5:spread }rgb(${6:0}, ${7:0}, ${8:0});",
"bxsh:ra": "box-shadow:${1:inset }${2:h} ${3:v} ${4:blur} ${5:spread }rgba(${6:0}, ${7:0}, ${8:0}, .${9:5});",
"bxsh:n": "box-shadow:none;",
"m": "margin:|;",
"m:a": "margin:auto;",
"mt": "margin-top:|;",
"mt:a": "margin-top:auto;",
"mr": "margin-right:|;",
"mr:a": "margin-right:auto;",
"mb": "margin-bottom:|;",
"mb:a": "margin-bottom:auto;",
"ml": "margin-left:|;",
"ml:a": "margin-left:auto;",
"p": "padding:|;",
"pt": "padding-top:|;",
"pr": "padding-right:|;",
"pb": "padding-bottom:|;",
"pl": "padding-left:|;",
"w": "width:|;",
"w:a": "width:auto;",
"h": "height:|;",
"h:a": "height:auto;",
"maw": "max-width:|;",
"maw:n": "max-width:none;",
"mah": "max-height:|;",
"mah:n": "max-height:none;",
"miw": "min-width:|;",
"mih": "min-height:|;",
"mar": "max-resolution:${1:res};",
"mir": "min-resolution:${1:res};",
"ori": "orientation:|;",
"ori:l": "orientation:landscape;",
"ori:p": "orientation:portrait;",
"ol": "outline:|;",
"ol:n": "outline:none;",
"olo": "outline-offset:|;",
"olw": "outline-width:|;",
"olw:tn": "outline-width:thin;",
"olw:m": "outline-width:medium;",
"olw:tc": "outline-width:thick;",
"ols": "outline-style:|;",
"ols:n": "outline-style:none;",
"ols:dt": "outline-style:dotted;",
"ols:ds": "outline-style:dashed;",
"ols:s": "outline-style:solid;",
"ols:db": "outline-style:double;",
"ols:g": "outline-style:groove;",
"ols:r": "outline-style:ridge;",
"ols:i": "outline-style:inset;",
"ols:o": "outline-style:outset;",
"olc": "outline-color:#${1:000};",
"olc:i": "outline-color:invert;",
"bfv": "backface-visibility:|;",
"bfv:h": "backface-visibility:hidden;",
"bfv:v": "backface-visibility:visible;",
"bd": "border:|;",
"bd+": "border:${1:1px} ${2:solid} ${3:#000};",
"bd:n": "border:none;",
"bdbk": "border-break:${1:close};",
"bdbk:c": "border-break:close;",
"bdcl": "border-collapse:|;",
"bdcl:c": "border-collapse:collapse;",
"bdcl:s": "border-collapse:separate;",
"bdc": "border-color:#${1:000};",
"bdc:t": "border-color:transparent;",
"bdi": "border-image:url(|);",
"bdi:n": "border-image:none;",
"bdti": "border-top-image:url(|);",
"bdti:n": "border-top-image:none;",
"bdri": "border-right-image:url(|);",
"bdri:n": "border-right-image:none;",
"bdbi": "border-bottom-image:url(|);",
"bdbi:n": "border-bottom-image:none;",
"bdli": "border-left-image:url(|);",
"bdli:n": "border-left-image:none;",
"bdci": "border-corner-image:url(|);",
"bdci:n": "border-corner-image:none;",
"bdci:c": "border-corner-image:continue;",
"bdtli": "border-top-left-image:url(|);",
"bdtli:n": "border-top-left-image:none;",
"bdtli:c": "border-top-left-image:continue;",
"bdtri": "border-top-right-image:url(|);",
"bdtri:n": "border-top-right-image:none;",
"bdtri:c": "border-top-right-image:continue;",
"bdbri": "border-bottom-right-image:url(|);",
"bdbri:n": "border-bottom-right-image:none;",
"bdbri:c": "border-bottom-right-image:continue;",
"bdbli": "border-bottom-left-image:url(|);",
"bdbli:n": "border-bottom-left-image:none;",
"bdbli:c": "border-bottom-left-image:continue;",
"bdf": "border-fit:${1:repeat};",
"bdf:c": "border-fit:clip;",
"bdf:r": "border-fit:repeat;",
"bdf:sc": "border-fit:scale;",
"bdf:st": "border-fit:stretch;",
"bdf:ow": "border-fit:overwrite;",
"bdf:of": "border-fit:overflow;",
"bdf:sp": "border-fit:space;",
"bdlen": "border-length:|;",
"bdlen:a": "border-length:auto;",
"bdsp": "border-spacing:|;",
"bds": "border-style:|;",
"bds:n": "border-style:none;",
"bds:h": "border-style:hidden;",
"bds:dt": "border-style:dotted;",
"bds:ds": "border-style:dashed;",
"bds:s": "border-style:solid;",
"bds:db": "border-style:double;",
"bds:dtds": "border-style:dot-dash;",
"bds:dtdtds": "border-style:dot-dot-dash;",
"bds:w": "border-style:wave;",
"bds:g": "border-style:groove;",
"bds:r": "border-style:ridge;",
"bds:i": "border-style:inset;",
"bds:o": "border-style:outset;",
"bdw": "border-width:|;",
"bdtw": "border-top-width:|;",
"bdrw": "border-right-width:|;",
"bdbw": "border-bottom-width:|;",
"bdlw": "border-left-width:|;",
"bdt": "border-top:|;",
"bt": "border-top:|;",
"bdt+": "border-top:${1:1px} ${2:solid} ${3:#000};",
"bdt:n": "border-top:none;",
"bdts": "border-top-style:|;",
"bdts:n": "border-top-style:none;",
"bdtc": "border-top-color:#${1:000};",
"bdtc:t": "border-top-color:transparent;",
"bdr": "border-right:|;",
"br": "border-right:|;",
"bdr+": "border-right:${1:1px} ${2:solid} ${3:#000};",
"bdr:n": "border-right:none;",
"bdrst": "border-right-style:|;",
"bdrst:n": "border-right-style:none;",
"bdrc": "border-right-color:#${1:000};",
"bdrc:t": "border-right-color:transparent;",
"bdb": "border-bottom:|;",
"bb": "border-bottom:|;",
"bdb+": "border-bottom:${1:1px} ${2:solid} ${3:#000};",
"bdb:n": "border-bottom:none;",
"bdbs": "border-bottom-style:|;",
"bdbs:n": "border-bottom-style:none;",
"bdbc": "border-bottom-color:#${1:000};",
"bdbc:t": "border-bottom-color:transparent;",
"bdl": "border-left:|;",
"bl": "border-left:|;",
"bdl+": "border-left:${1:1px} ${2:solid} ${3:#000};",
"bdl:n": "border-left:none;",
"bdls": "border-left-style:|;",
"bdls:n": "border-left-style:none;",
"bdlc": "border-left-color:#${1:000};",
"bdlc:t": "border-left-color:transparent;",
"bdrs": "border-radius:|;",
"bdtrrs": "border-top-right-radius:|;",
"bdtlrs": "border-top-left-radius:|;",
"bdbrrs": "border-bottom-right-radius:|;",
"bdblrs": "border-bottom-left-radius:|;",
"bg": "background:#${1:000};",
"bg+": "background:${1:#fff} url(${2}) ${3:0} ${4:0} ${5:no-repeat};",
"bg:n": "background:none;",
"bg:ie": "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='${1:x}.png',sizingMethod='${2:crop}');",
"bgc": "background-color:#${1:fff};",
"bgc:t": "background-color:transparent;",
"bgi": "background-image:url(|);",
"bgi:n": "background-image:none;",
"bgr": "background-repeat:|;",
"bgr:n": "background-repeat:no-repeat;",
"bgr:x": "background-repeat:repeat-x;",
"bgr:y": "background-repeat:repeat-y;",
"bgr:sp": "background-repeat:space;",
"bgr:rd": "background-repeat:round;",
"bga": "background-attachment:|;",
"bga:f": "background-attachment:fixed;",
"bga:s": "background-attachment:scroll;",
"bgp": "background-position:${1:0} ${2:0};",
"bgpx": "background-position-x:|;",
"bgpy": "background-position-y:|;",
"bgbk": "background-break:|;",
"bgbk:bb": "background-break:bounding-box;",
"bgbk:eb": "background-break:each-box;",
"bgbk:c": "background-break:continuous;",
"bgcp": "background-clip:${1:padding-box};",
"bgcp:bb": "background-clip:border-box;",
"bgcp:pb": "background-clip:padding-box;",
"bgcp:cb": "background-clip:content-box;",
"bgcp:nc": "background-clip:no-clip;",
"bgo": "background-origin:|;",
"bgo:pb": "background-origin:padding-box;",
"bgo:bb": "background-origin:border-box;",
"bgo:cb": "background-origin:content-box;",
"bgsz": "background-size:|;",
"bgsz:a": "background-size:auto;",
"bgsz:ct": "background-size:contain;",
"bgsz:cv": "background-size:cover;",
"c": "color:#${1:000};",
"c:r": "color:rgb(${1:0}, ${2:0}, ${3:0});",
"c:ra": "color:rgba(${1:0}, ${2:0}, ${3:0}, .${4:5});",
"cm": "/* |${child} */",
"cnt": "content:'|';",
"cnt:n": "content:normal;",
"cnt:oq": "content:open-quote;",
"cnt:noq": "content:no-open-quote;",
"cnt:cq": "content:close-quote;",
"cnt:ncq": "content:no-close-quote;",
"cnt:a": "content:attr(|);",
"cnt:c": "content:counter(|);",
"cnt:cs": "content:counters(|);",
"tbl": "table-layout:|;",
"tbl:a": "table-layout:auto;",
"tbl:f": "table-layout:fixed;",
"cps": "caption-side:|;",
"cps:t": "caption-side:top;",
"cps:b": "caption-side:bottom;",
"ec": "empty-cells:|;",
"ec:s": "empty-cells:show;",
"ec:h": "empty-cells:hide;",
"lis": "list-style:|;",
"lis:n": "list-style:none;",
"lisp": "list-style-position:|;",
"lisp:i": "list-style-position:inside;",
"lisp:o": "list-style-position:outside;",
"list": "list-style-type:|;",
"list:n": "list-style-type:none;",
"list:d": "list-style-type:disc;",
"list:c": "list-style-type:circle;",
"list:s": "list-style-type:square;",
"list:dc": "list-style-type:decimal;",
"list:dclz": "list-style-type:decimal-leading-zero;",
"list:lr": "list-style-type:lower-roman;",
"list:ur": "list-style-type:upper-roman;",
"lisi": "list-style-image:|;",
"lisi:n": "list-style-image:none;",
"q": "quotes:|;",
"q:n": "quotes:none;",
"q:ru": "quotes:'\\00AB' '\\00BB' '\\201E' '\\201C';",
"q:en": "quotes:'\\201C' '\\201D' '\\2018' '\\2019';",
"ct": "content:|;",
"ct:n": "content:normal;",
"ct:oq": "content:open-quote;",
"ct:noq": "content:no-open-quote;",
"ct:cq": "content:close-quote;",
"ct:ncq": "content:no-close-quote;",
"ct:a": "content:attr(|);",
"ct:c": "content:counter(|);",
"ct:cs": "content:counters(|);",
"coi": "counter-increment:|;",
"cor": "counter-reset:|;",
"va": "vertical-align:${1:top};",
"va:sup": "vertical-align:super;",
"va:t": "vertical-align:top;",
"va:tt": "vertical-align:text-top;",
"va:m": "vertical-align:middle;",
"va:bl": "vertical-align:baseline;",
"va:b": "vertical-align:bottom;",
"va:tb": "vertical-align:text-bottom;",
"va:sub": "vertical-align:sub;",
"ta": "text-align:${1:left};",
"ta:l": "text-align:left;",
"ta:c": "text-align:center;",
"ta:r": "text-align:right;",
"ta:j": "text-align:justify;",
"ta-lst": "text-align-last:|;",
"tal:a": "text-align-last:auto;",
"tal:l": "text-align-last:left;",
"tal:c": "text-align-last:center;",
"tal:r": "text-align-last:right;",
"td": "text-decoration:${1:none};",
"td:n": "text-decoration:none;",
"td:u": "text-decoration:underline;",
"td:o": "text-decoration:overline;",
"td:l": "text-decoration:line-through;",
"te": "text-emphasis:|;",
"te:n": "text-emphasis:none;",
"te:ac": "text-emphasis:accent;",
"te:dt": "text-emphasis:dot;",
"te:c": "text-emphasis:circle;",
"te:ds": "text-emphasis:disc;",
"te:b": "text-emphasis:before;",
"te:a": "text-emphasis:after;",
"th": "text-height:|;",
"th:a": "text-height:auto;",
"th:f": "text-height:font-size;",
"th:t": "text-height:text-size;",
"th:m": "text-height:max-size;",
"ti": "text-indent:|;",
"ti:-": "text-indent:-9999px;",
"tj": "text-justify:|;",
"tj:a": "text-justify:auto;",
"tj:iw": "text-justify:inter-word;",
"tj:ii": "text-justify:inter-ideograph;",
"tj:ic": "text-justify:inter-cluster;",
"tj:d": "text-justify:distribute;",
"tj:k": "text-justify:kashida;",
"tj:t": "text-justify:tibetan;",
"tov": "text-overflow:${ellipsis};",
"tov:e": "text-overflow:ellipsis;",
"tov:c": "text-overflow:clip;",
"to": "text-outline:|;",
"to+": "text-outline:${1:0} ${2:0} ${3:#000};",
"to:n": "text-outline:none;",
"tr": "text-replace:|;",
"tr:n": "text-replace:none;",
"tt": "text-transform:${1:uppercase};",
"tt:n": "text-transform:none;",
"tt:c": "text-transform:capitalize;",
"tt:u": "text-transform:uppercase;",
"tt:l": "text-transform:lowercase;",
"tw": "text-wrap:|;",
"tw:n": "text-wrap:normal;",
"tw:no": "text-wrap:none;",
"tw:u": "text-wrap:unrestricted;",
"tw:s": "text-wrap:suppress;",
"tsh": "text-shadow:${1:hoff} ${2:voff} ${3:blur} ${4:#000};",
"tsh:r": "text-shadow:${1:h} ${2:v} ${3:blur} rgb(${4:0}, ${5:0}, ${6:0});",
"tsh:ra": "text-shadow:${1:h} ${2:v} ${3:blur} rgba(${4:0}, ${5:0}, ${6:0}, .${7:5});",
"tsh+": "text-shadow:${1:0} ${2:0} ${3:0} ${4:#000};",
"tsh:n": "text-shadow:none;",
"trf": "transform:|;",
"trf:skx": "transform: skewX(${1:angle});",
"trf:sky": "transform: skewY(${1:angle});",
"trf:sc": "transform: scale(${1:x}, ${2:y});",
"trf:scx": "transform: scaleX(${1:x});",
"trf:scy": "transform: scaleY(${1:y});",
"trf:scz": "transform: scaleZ(${1:z});",
"trf:sc3": "transform: scale3d(${1:x}, ${2:y}, ${3:z});",
"trf:r": "transform: rotate(${1:angle});",
"trf:rx": "transform: rotateX(${1:angle});",
"trf:ry": "transform: rotateY(${1:angle});",
"trf:rz": "transform: rotateZ(${1:angle});",
"trf:t": "transform: translate(${1:x}, ${2:y});",
"trf:tx": "transform: translateX(${1:x});",
"trf:ty": "transform: translateY(${1:y});",
"trf:tz": "transform: translateZ(${1:z});",
"trf:t3": "transform: translate3d(${1:tx}, ${2:ty}, ${3:tz});",
"trfo": "transform-origin:|;",
"trfs": "transform-style:${1:preserve-3d};",
"trs": "transition:${1:prop} ${2:time};",
"trsde": "transition-delay:${1:time};",
"trsdu": "transition-duration:${1:time};",
"trsp": "transition-property:${1:prop};",
"trstf": "transition-timing-function:${1:tfunc};",
"lh": "line-height:|;",
"whs": "white-space:|;",
"whs:n": "white-space:normal;",
"whs:p": "white-space:pre;",
"whs:nw": "white-space:nowrap;",
"whs:pw": "white-space:pre-wrap;",
"whs:pl": "white-space:pre-line;",
"whsc": "white-space-collapse:|;",
"whsc:n": "white-space-collapse:normal;",
"whsc:k": "white-space-collapse:keep-all;",
"whsc:l": "white-space-collapse:loose;",
"whsc:bs": "white-space-collapse:break-strict;",
"whsc:ba": "white-space-collapse:break-all;",
"wob": "word-break:|;",
"wob:n": "word-break:normal;",
"wob:k": "word-break:keep-all;",
"wob:ba": "word-break:break-all;",
"wos": "word-spacing:|;",
"wow": "word-wrap:|;",
"wow:nm": "word-wrap:normal;",
"wow:n": "word-wrap:none;",
"wow:u": "word-wrap:unrestricted;",
"wow:s": "word-wrap:suppress;",
"wow:b": "word-wrap:break-word;",
"wm": "writing-mode:${1:lr-tb};",
"wm:lrt": "writing-mode:lr-tb;",
"wm:lrb": "writing-mode:lr-bt;",
"wm:rlt": "writing-mode:rl-tb;",
"wm:rlb": "writing-mode:rl-bt;",
"wm:tbr": "writing-mode:tb-rl;",
"wm:tbl": "writing-mode:tb-lr;",
"wm:btl": "writing-mode:bt-lr;",
"wm:btr": "writing-mode:bt-rl;",
"lts": "letter-spacing:|;",
"lts-n": "letter-spacing:normal;",
"f": "font:|;",
"f+": "font:${1:1em} ${2:Arial,sans-serif};",
"fw": "font-weight:|;",
"fw:n": "font-weight:normal;",
"fw:b": "font-weight:bold;",
"fw:br": "font-weight:bolder;",
"fw:lr": "font-weight:lighter;",
"fs": "font-style:${italic};",
"fs:n": "font-style:normal;",
"fs:i": "font-style:italic;",
"fs:o": "font-style:oblique;",
"fv": "font-variant:|;",
"fv:n": "font-variant:normal;",
"fv:sc": "font-variant:small-caps;",
"fz": "font-size:|;",
"fza": "font-size-adjust:|;",
"fza:n": "font-size-adjust:none;",
"ff": "font-family:|;",
"ff:s": "font-family:serif;",
"ff:ss": "font-family:sans-serif;",
"ff:c": "font-family:cursive;",
"ff:f": "font-family:fantasy;",
"ff:m": "font-family:monospace;",
"ff:a": "font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif;",
"ff:t": "font-family: \"Times New Roman\", Times, Baskerville, Georgia, serif;",
"ff:v": "font-family: Verdana, Geneva, sans-serif;",
"fef": "font-effect:|;",
"fef:n": "font-effect:none;",
"fef:eg": "font-effect:engrave;",
"fef:eb": "font-effect:emboss;",
"fef:o": "font-effect:outline;",
"fem": "font-emphasize:|;",
"femp": "font-emphasize-position:|;",
"femp:b": "font-emphasize-position:before;",
"femp:a": "font-emphasize-position:after;",
"fems": "font-emphasize-style:|;",
"fems:n": "font-emphasize-style:none;",
"fems:ac": "font-emphasize-style:accent;",
"fems:dt": "font-emphasize-style:dot;",
"fems:c": "font-emphasize-style:circle;",
"fems:ds": "font-emphasize-style:disc;",
"fsm": "font-smooth:|;",
"fsm:a": "font-smooth:auto;",
"fsm:n": "font-smooth:never;",
"fsm:aw": "font-smooth:always;",
"fst": "font-stretch:|;",
"fst:n": "font-stretch:normal;",
"fst:uc": "font-stretch:ultra-condensed;",
"fst:ec": "font-stretch:extra-condensed;",
"fst:c": "font-stretch:condensed;",
"fst:sc": "font-stretch:semi-condensed;",
"fst:se": "font-stretch:semi-expanded;",
"fst:e": "font-stretch:expanded;",
"fst:ee": "font-stretch:extra-expanded;",
"fst:ue": "font-stretch:ultra-expanded;",
"op": "opacity:|;",
"op+": "opacity: $1;\nfilter: alpha(opacity=$2);",
"op:ie": "filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=100);",
"op:ms": "-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=100)';",
"rsz": "resize:|;",
"rsz:n": "resize:none;",
"rsz:b": "resize:both;",
"rsz:h": "resize:horizontal;",
"rsz:v": "resize:vertical;",
"cur": "cursor:${pointer};",
"cur:a": "cursor:auto;",
"cur:d": "cursor:default;",
"cur:c": "cursor:crosshair;",
"cur:ha": "cursor:hand;",
"cur:he": "cursor:help;",
"cur:m": "cursor:move;",
"cur:p": "cursor:pointer;",
"cur:t": "cursor:text;",
"fxd": "flex-direction:|;",
"fxd:r": "flex-direction:row;",
"fxd:rr": "flex-direction:row-reverse;",
"fxd:c": "flex-direction:column;",
"fxd:cr": "flex-direction:column-reverse;",
"fxw": "flex-wrap: |;",
"fxw:n": "flex-wrap:nowrap;",
"fxw:w": "flex-wrap:wrap;",
"fxw:wr": "flex-wrap:wrap-reverse;",
"fxf": "flex-flow:|;",
"jc": "justify-content:|;",
"jc:fs": "justify-content:flex-start;",
"jc:fe": "justify-content:flex-end;",
"jc:c": "justify-content:center;",
"jc:sb": "justify-content:space-between;",
"jc:sa": "justify-content:space-around;",
"ai": "align-items:|;",
"ai:fs": "align-items:flex-start;",
"ai:fe": "align-items:flex-end;",
"ai:c": "align-items:center;",
"ai:b": "align-items:baseline;",
"ai:s": "align-items:stretch;",
"ac": "align-content:|;",
"ac:fs": "align-content:flex-start;",
"ac:fe": "align-content:flex-end;",
"ac:c": "align-content:center;",
"ac:sb": "align-content:space-between;",
"ac:sa": "align-content:space-around;",
"ac:s": "align-content:stretch;",
"ord": "order:|;",
"fxg": "flex-grow:|;",
"fxsh": "flex-shrink:|;",
"fxb": "flex-basis:|;",
"fx": "flex:|;",
"as": "align-self:|;",
"as:a": "align-self:auto;",
"as:fs": "align-self:flex-start;",
"as:fe": "align-self:flex-end;",
"as:c": "align-self:center;",
"as:b": "align-self:baseline;",
"as:s": "align-self:stretch;",
"pgbb": "page-break-before:|;",
"pgbb:au": "page-break-before:auto;",
"pgbb:al": "page-break-before:always;",
"pgbb:l": "page-break-before:left;",
"pgbb:r": "page-break-before:right;",
"pgbi": "page-break-inside:|;",
"pgbi:au": "page-break-inside:auto;",
"pgbi:av": "page-break-inside:avoid;",
"pgba": "page-break-after:|;",
"pgba:au": "page-break-after:auto;",
"pgba:al": "page-break-after:always;",
"pgba:l": "page-break-after:left;",
"pgba:r": "page-break-after:right;",
"orp": "orphans:|;",
"us": "user-select:${none};",
"wid": "widows:|;",
"wfsm": "-webkit-font-smoothing:${antialiased};",
"wfsm:a": "-webkit-font-smoothing:antialiased;",
"wfsm:s": "-webkit-font-smoothing:subpixel-antialiased;",
"wfsm:sa": "-webkit-font-smoothing:subpixel-antialiased;",
"wfsm:n": "-webkit-font-smoothing:none;"
}
},
"html": {
"filters": "html",
"profile": "html",
"snippets": {
"!!!": "<!DOCTYPE html>",
"!!!4t": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
"!!!4s": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">",
"!!!xt": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
"!!!xs": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">",
"!!!xxs": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">",
"c": "<!-- |${child} -->",
"cc:ie6": "<!--[if lte IE 6]>\n\t${child}|\n<![endif]-->",
"cc:ie": "<!--[if IE]>\n\t${child}|\n<![endif]-->",
"cc:noie": "<!--[if !IE]><!-->\n\t${child}|\n<!--<![endif]-->"
},
"abbreviations": {
"!": "html:5",
"a": "<a href=\"\">",
"a:link": "<a href=\"http://|\">",
"a:mail": "<a href=\"mailto:|\">",
"abbr": "<abbr title=\"\">",
"acr|acronym": "<acronym title=\"\">",
"base": "<base href=\"\" />",
"basefont": "<basefont/>",
"br": "<br/>",
"frame": "<frame/>",
"hr": "<hr/>",
"bdo": "<bdo dir=\"\">",
"bdo:r": "<bdo dir=\"rtl\">",
"bdo:l": "<bdo dir=\"ltr\">",
"col": "<col/>",
"link": "<link rel=\"stylesheet\" href=\"\" />",
"link:css": "<link rel=\"stylesheet\" href=\"${1:style}.css\" />",
"link:print": "<link rel=\"stylesheet\" href=\"${1:print}.css\" media=\"print\" />",
"link:favicon": "<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"${1:favicon.ico}\" />",
"link:touch": "<link rel=\"apple-touch-icon\" href=\"${1:favicon.png}\" />",
"link:rss": "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"${1:rss.xml}\" />",
"link:atom": "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"Atom\" href=\"${1:atom.xml}\" />",
"link:im|link:import": "<link rel=\"import\" href=\"${1:component}.html\" />",
"meta": "<meta/>",
"meta:utf": "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\" />",
"meta:win": "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1251\" />",
"meta:vp": "<meta name=\"viewport\" content=\"width=${1:device-width}, user-scalable=${2:no}, initial-scale=${3:1.0}, maximum-scale=${4:1.0}, minimum-scale=${5:1.0}\" />",
"meta:compat": "<meta http-equiv=\"X-UA-Compatible\" content=\"${1:IE=7}\" />",
"style": "<style>",
"script": "<script !src=\"\">",
"script:src": "<script src=\"\">",
"img": "<img src=\"\" alt=\"\" />",
"img:s|img:srcset": "<img srcset=\"\" src=\"\" alt=\"\" />",
"img:z|img:sizes": "<img sizes=\"\" srcset=\"\" src=\"\" alt=\"\" />",
"picture": "<picture>",
"src|source": "<source/>",
"src:sc|source:src": "<source src=\"\" type=\"\"/>",
"src:s|source:srcset": "<source srcset=\"\"/>",
"src:m|source:media": "<source media=\"(${1:min-width: })\" srcset=\"\"/>",
"src:t|source:type": "<source srcset=\"|\" type=\"${1:image/}\"/>",
"src:z|source:sizes": "<source sizes=\"\" srcset=\"\"/>",
"src:mt|source:media:type": "<source media=\"(${1:min-width: })\" srcset=\"\" type=\"${2:image/}\"/>",
"src:mz|source:media:sizes": "<source media=\"(${1:min-width: })\" sizes=\"\" srcset=\"\"/>",
"src:zt|source:sizes:type": "<source sizes=\"\" srcset=\"\" type=\"${1:image/}\"/>",
"iframe": "<iframe src=\"\" frameborder=\"0\">",
"embed": "<embed src=\"\" type=\"\" />",
"object": "<object data=\"\" type=\"\">",
"param": "<param name=\"\" value=\"\" />",
"map": "<map name=\"\">",
"area": "<area shape=\"\" coords=\"\" href=\"\" alt=\"\" />",
"area:d": "<area shape=\"default\" href=\"\" alt=\"\" />",
"area:c": "<area shape=\"circle\" coords=\"\" href=\"\" alt=\"\" />",
"area:r": "<area shape=\"rect\" coords=\"\" href=\"\" alt=\"\" />",
"area:p": "<area shape=\"poly\" coords=\"\" href=\"\" alt=\"\" />",
"form": "<form action=\"\">",
"form:get": "<form action=\"\" method=\"get\">",
"form:post": "<form action=\"\" method=\"post\">",
"label": "<label for=\"\">",
"input": "<input type=\"${1:text}\" />",
"inp": "<input type=\"${1:text}\" name=\"\" id=\"\" />",
"input:h|input:hidden": "input[type=hidden name]",
"input:t|input:text": "inp",
"input:search": "inp[type=search]",
"input:email": "inp[type=email]",
"input:url": "inp[type=url]",
"input:p|input:password": "inp[type=password]",
"input:datetime": "inp[type=datetime]",
"input:date": "inp[type=date]",
"input:datetime-local": "inp[type=datetime-local]",
"input:month": "inp[type=month]",
"input:week": "inp[type=week]",
"input:time": "inp[type=time]",
"input:tel": "inp[type=tel]",
"input:number": "inp[type=number]",
"input:color": "inp[type=color]",
"input:c|input:checkbox": "inp[type=checkbox]",
"input:r|input:radio": "inp[type=radio]",
"input:range": "inp[type=range]",
"input:f|input:file": "inp[type=file]",
"input:s|input:submit": "<input type=\"submit\" value=\"\" />",
"input:i|input:image": "<input type=\"image\" src=\"\" alt=\"\" />",
"input:b|input:button": "<input type=\"button\" value=\"\" />",
"isindex": "<isindex/>",
"input:reset": "input:button[type=reset]",
"select": "<select name=\"\" id=\"\">",
"select:d|select:disabled": "select[disabled.]",
"opt|option": "<option value=\"\">",
"textarea": "<textarea name=\"\" id=\"\" cols=\"${1:30}\" rows=\"${2:10}\">",
"marquee": "<marquee behavior=\"\" direction=\"\">",
"menu:c|menu:context": "menu[type=context]>",
"menu:t|menu:toolbar": "menu[type=toolbar]>",
"video": "<video src=\"\">",
"audio": "<audio src=\"\">",
"html:xml": "<html xmlns=\"http://www.w3.org/1999/xhtml\">",
"keygen": "<keygen/>",
"command": "<command/>",
"btn:s|button:s|button:submit" : "button[type=submit]",
"btn:r|button:r|button:reset" : "button[type=reset]",
"btn:d|button:d|button:disabled" : "button[disabled.]",
"fst:d|fset:d|fieldset:d|fieldset:disabled" : "fieldset[disabled.]",
"bq": "blockquote",
"fig": "figure",
"figc": "figcaption",
"pic": "picture",
"ifr": "iframe",
"emb": "embed",
"obj": "object",
"cap": "caption",
"colg": "colgroup",
"fst": "fieldset",
"btn": "button",
"optg": "optgroup",
"tarea": "textarea",
"leg": "legend",
"sect": "section",
"art": "article",
"hdr": "header",
"ftr": "footer",
"adr": "address",
"dlg": "dialog",
"str": "strong",
"prog": "progress",
"mn": "main",
"tem": "template",
"fset": "fieldset",
"datag": "datagrid",
"datal": "datalist",
"kg": "keygen",
"out": "output",
"det": "details",
"cmd": "command",
"doc": "html>(head>meta[charset=${charset}]+title{${1:Document}})+body",
"doc4": "html>(head>meta[http-equiv=\"Content-Type\" content=\"text/html;charset=${charset}\"]+title{${1:Document}})+body",
"ri:d|ri:dpr": "img:s",
"ri:v|ri:viewport": "img:z",
"ri:a|ri:art": "pic>src:m+img",
"ri:t|ri:type": "pic>src:t+img",
"html:4t": "!!!4t+doc4[lang=${lang}]",
"html:4s": "!!!4s+doc4[lang=${lang}]",
"html:xt": "!!!xt+doc4[xmlns=http://www.w3.org/1999/xhtml xml:lang=${lang}]",
"html:xs": "!!!xs+doc4[xmlns=http://www.w3.org/1999/xhtml xml:lang=${lang}]",
"html:xxs": "!!!xxs+doc4[xmlns=http://www.w3.org/1999/xhtml xml:lang=${lang}]",
"html:5": "!!!+doc[lang=${lang}]",
"ol+": "ol>li",
"ul+": "ul>li",
"dl+": "dl>dt+dd",
"map+": "map>area",
"table+": "table>tr>td",
"colgroup+": "colgroup>col",
"colg+": "colgroup>col",
"tr+": "tr>td",
"select+": "select>option",
"optgroup+": "optgroup>option",
"optg+": "optgroup>option",
"pic+": "picture>source:srcset+img"
}
},
"xml": {
"extends": "html",
"profile": "xml",
"filters": "html"
},
"xsl": {
"extends": "html",
"profile": "xml",
"filters": "html, xsl",
"abbreviations": {
"tm|tmatch": "<xsl:template match=\"\" mode=\"\">",
"tn|tname": "<xsl:template name=\"\">",
"call": "<xsl:call-template name=\"\"/>",
"ap": "<xsl:apply-templates select=\"\" mode=\"\"/>",
"api": "<xsl:apply-imports/>",
"imp": "<xsl:import href=\"\"/>",
"inc": "<xsl:include href=\"\"/>",
"ch": "<xsl:choose>",
"wh|xsl:when": "<xsl:when test=\"\">",
"ot": "<xsl:otherwise>",
"if": "<xsl:if test=\"\">",
"par": "<xsl:param name=\"\">",
"pare": "<xsl:param name=\"\" select=\"\"/>",
"var": "<xsl:variable name=\"\">",
"vare": "<xsl:variable name=\"\" select=\"\"/>",
"wp": "<xsl:with-param name=\"\" select=\"\"/>",
"key": "<xsl:key name=\"\" match=\"\" use=\"\"/>",
"elem": "<xsl:element name=\"\">",
"attr": "<xsl:attribute name=\"\">",
"attrs": "<xsl:attribute-set name=\"\">",
"cp": "<xsl:copy select=\"\"/>",
"co": "<xsl:copy-of select=\"\"/>",
"val": "<xsl:value-of select=\"\"/>",
"for|each": "<xsl:for-each select=\"\">",
"tex": "<xsl:text></xsl:text>",
"com": "<xsl:comment>",
"msg": "<xsl:message terminate=\"no\">",
"fall": "<xsl:fallback>",
"num": "<xsl:number value=\"\"/>",
"nam": "<namespace-alias stylesheet-prefix=\"\" result-prefix=\"\"/>",
"pres": "<xsl:preserve-space elements=\"\"/>",
"strip": "<xsl:strip-space elements=\"\"/>",
"proc": "<xsl:processing-instruction name=\"\">",
"sort": "<xsl:sort select=\"\" order=\"\"/>",
"choose+": "xsl:choose>xsl:when+xsl:otherwise",
"xsl": "!!!+xsl:stylesheet[version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform]>{\n|}"
},
"snippets": {
"!!!": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
}
},
"haml": {
"filters": "haml",
"extends": "html",
"profile": "xml"
},
"jade": {
"filters": "jade",
"extends": "html",
"profile": "xml"
},
"jsx": {
"filters": "jsx, html",
"extends": "html",
"profile": "xml"
},
"slim": {
"filters": "slim",
"extends": "html",
"profile": "xml"
},
"scss": {
"extends": "css"
},
"sass": {
"extends": "css"
},
"less": {
"extends": "css"
},
"stylus": {
"extends": "css"
},
"styl": {
"extends": "stylus"
}
}
},{}],69:[function(require,module,exports){
/**
* Utility functions to work with <code>AbbreviationNode</code> as HTML element
* @param {Function} require
* @param {Underscore} _
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var elements = require('../assets/elements');
var tabStops = require('../assets/tabStops');
var utils = require('../utils/common');
var tagName = require('../resolver/tagName');
return {
/**
* Test if passed node is unary (no closing tag)
* @param {AbbreviationNode} node
* @return {Boolean}
*/
isUnary: function(node) {
if (node.children.length || node._text || this.isSnippet(node)) {
return false;
}
var r = node.data('resource');
return r && r.is_empty;
},
/**
* Test if passed node is inline-level (like &lt;strong&gt;, &lt;img&gt;)
* @param {AbbreviationNode} node
* @return {Boolean}
*/
isInline: function(node) {
return node.isTextNode()
|| !node.name()
|| tagName.isInlineLevel(node.name());
},
/**
* Test if passed node is block-level
* @param {AbbreviationNode} node
* @return {Boolean}
*/
isBlock: function(node) {
return this.isSnippet(node) || !this.isInline(node);
},
/**
* Test if given node is a snippet
* @param {AbbreviationNode} node
* @return {Boolean}
*/
isSnippet: function(node) {
return elements.is(node.data('resource'), 'snippet');
},
/**
* This function tests if passed node content contains HTML tags.
* This function is mostly used for output formatting
* @param {AbbreviationNode} node
* @returns {Boolean}
*/
hasTagsInContent: function(node) {
return utils.matchesTag(node.content);
},
/**
* Test if current element contains block-level children
* @param {AbbreviationNode} node
* @return {Boolean}
*/
hasBlockChildren: function(node) {
return (this.hasTagsInContent(node) && this.isBlock(node))
|| node.children.some(function(child) {
return this.isBlock(child);
}, this);
},
/**
* Utility function that inserts content instead of <code>${child}</code>
* variables on <code>text</code>
* @param {String} text Text where child content should be inserted
* @param {String} childContent Content to insert
* @param {Object} options
* @returns {String
*/
insertChildContent: function(text, childContent, options) {
options = utils.extend({
keepVariable: true,
appendIfNoChild: true
}, options || {});
var childVariableReplaced = false;
text = tabStops.replaceVariables(text, function(variable, name, data) {
var output = variable;
if (name == 'child') {
// add correct indentation
output = utils.padString(childContent, utils.getLinePaddingFromPosition(text, data.start));
childVariableReplaced = true;
if (options.keepVariable)
output += variable;
}
return output;
});
if (!childVariableReplaced && options.appendIfNoChild) {
text += childContent;
}
return text;
}
};
});
},{"../assets/elements":24,"../assets/tabStops":33,"../resolver/tagName":67,"../utils/common":73}],70:[function(require,module,exports){
/**
* Utility methods for Emmet actions
* @author Sergey Chikuyonok (serge.che@gmail.com) <http://chikuyonok.ru>
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('./common');
var cssSections = require('./cssSections');
var abbreviationParser = require('../parser/abbreviation');
var htmlMatcher = require('../assets/htmlMatcher');
var xmlEditTree = require('../editTree/xml');
var range = require('../assets/range');
var resources = require('../assets/resources');
return {
mimeTypes: {
'gif' : 'image/gif',
'png' : 'image/png',
'jpg' : 'image/jpeg',
'jpeg': 'image/jpeg',
'svg' : 'image/svg+xml',
'html': 'text/html',
'htm' : 'text/html'
},
/**
* Extracts abbreviations from text stream, starting from the end
* @param {String} str
* @return {String} Abbreviation or empty string
* @memberOf emmet.actionUtils
*/
extractAbbreviation: function(str) {
var curOffset = str.length;
var startIndex = -1;
var groupCount = 0;
var braceCount = 0;
var textCount = 0;
while (true) {
curOffset--;
if (curOffset < 0) {
// moved to the beginning of the line
startIndex = 0;
break;
}
var ch = str.charAt(curOffset);
if (ch == ']') {
braceCount++;
} else if (ch == '[') {
if (!braceCount) { // unexpected brace
startIndex = curOffset + 1;
break;
}
braceCount--;
} else if (ch == '}') {
textCount++;
} else if (ch == '{') {
if (!textCount) { // unexpected brace
startIndex = curOffset + 1;
break;
}
textCount--;
} else if (ch == ')') {
groupCount++;
} else if (ch == '(') {
if (!groupCount) { // unexpected brace
startIndex = curOffset + 1;
break;
}
groupCount--;
} else {
if (braceCount || textCount)
// respect all characters inside attribute sets or text nodes
continue;
else if (!abbreviationParser.isAllowedChar(ch) || (ch == '>' && utils.endsWithTag(str.substring(0, curOffset + 1)))) {
// found stop symbol
startIndex = curOffset + 1;
break;
}
}
}
if (startIndex != -1 && !textCount && !braceCount && !groupCount)
// found something, remove some invalid symbols from the
// beginning and return abbreviation
return str.substring(startIndex).replace(/^[\*\+\>\^]+/, '');
else
return '';
},
/**
* Gets image size from image byte stream.
* @author http://romeda.org/rePublish/
* @param {String} stream Image byte stream (use <code>IEmmetFile.read()</code>)
* @return {Object} Object with <code>width</code> and <code>height</code> properties
*/
getImageSize: function(stream) {
var pngMagicNum = "\211PNG\r\n\032\n",
jpgMagicNum = "\377\330",
gifMagicNum = "GIF8",
pos = 0,
nextByte = function() {
return stream.charCodeAt(pos++);
};
if (stream.substr(0, 8) === pngMagicNum) {
// PNG. Easy peasy.
pos = stream.indexOf('IHDR') + 4;
return {
width: (nextByte() << 24) | (nextByte() << 16) | (nextByte() << 8) | nextByte(),
height: (nextByte() << 24) | (nextByte() << 16) | (nextByte() << 8) | nextByte()
};
} else if (stream.substr(0, 4) === gifMagicNum) {
pos = 6;
return {
width: nextByte() | (nextByte() << 8),
height: nextByte() | (nextByte() << 8)
};
} else if (stream.substr(0, 2) === jpgMagicNum) {
pos = 2;
var l = stream.length;
while (pos < l) {
if (nextByte() != 0xFF) return;
var marker = nextByte();
if (marker == 0xDA) break;
var size = (nextByte() << 8) | nextByte();
if (marker >= 0xC0 && marker <= 0xCF && !(marker & 0x4) && !(marker & 0x8)) {
pos += 1;
return {
height: (nextByte() << 8) | nextByte(),
width: (nextByte() << 8) | nextByte()
};
} else {
pos += size - 2;
}
}
}
},
/**
* Captures context XHTML element from editor under current caret position.
* This node can be used as a helper for abbreviation extraction
* @param {IEmmetEditor} editor
* @returns {Object}
*/
captureContext: function(editor, pos) {
var allowedSyntaxes = {'html': 1, 'xml': 1, 'xsl': 1};
var syntax = editor.getSyntax();
if (syntax in allowedSyntaxes) {
var content = editor.getContent();
if (typeof pos === 'undefined') {
pos = editor.getCaretPos();
}
var tag = htmlMatcher.find(content, pos);
if (tag && tag.type == 'tag') {
var startTag = tag.open;
var contextNode = {
name: startTag.name,
attributes: [],
match: tag
};
// parse attributes
var tagTree = xmlEditTree.parse(startTag.range.substring(content));
if (tagTree) {
contextNode.attributes = tagTree.getAll().map(function(item) {
return {
name: item.name(),
value: item.value()
};
});
}
return contextNode;
}
}
return null;
},
/**
* Find expression bounds in current editor at caret position.
* On each character a <code>fn</code> function will be called and must
* return <code>true</code> if current character meets requirements,
* <code>false</code> otherwise
* @param {IEmmetEditor} editor
* @param {Function} fn Function to test each character of expression
* @return {Range}
*/
findExpressionBounds: function(editor, fn) {
var content = String(editor.getContent());
var il = content.length;
var exprStart = editor.getCaretPos() - 1;
var exprEnd = exprStart + 1;
// start by searching left
while (exprStart >= 0 && fn(content.charAt(exprStart), exprStart, content)) exprStart--;
// then search right
while (exprEnd < il && fn(content.charAt(exprEnd), exprEnd, content)) exprEnd++;
if (exprEnd > exprStart) {
return range([++exprStart, exprEnd]);
}
},
/**
* @param {IEmmetEditor} editor
* @param {Object} data
* @returns {Boolean}
*/
compoundUpdate: function(editor, data) {
if (data) {
var sel = editor.getSelectionRange();
editor.replaceContent(data.data, data.start, data.end, true);
editor.createSelection(data.caret, data.caret + sel.end - sel.start);
return true;
}
return false;
},
/**
* Common syntax detection method for editors that doesnt provide any
* info about current syntax scope.
* @param {IEmmetEditor} editor Current editor
* @param {String} hint Any syntax hint that editor can provide
* for syntax detection. Default is 'html'
* @returns {String}
*/
detectSyntax: function(editor, hint) {
var syntax = hint || 'html';
if (!resources.hasSyntax(syntax)) {
syntax = 'html';
}
if (syntax == 'html' && (this.isStyle(editor) || this.isInlineCSS(editor))) {
syntax = 'css';
}
if (syntax == 'styl') {
syntax = 'stylus';
}
return syntax;
},
/**
* Common method for detecting output profile
* @param {IEmmetEditor} editor
* @returns {String}
*/
detectProfile: function(editor) {
var syntax = editor.getSyntax();
// get profile from syntax definition
var profile = resources.findItem(syntax, 'profile');
if (profile) {
return profile;
}
switch(syntax) {
case 'xml':
case 'xsl':
return 'xml';
case 'css':
if (this.isInlineCSS(editor)) {
return 'line';
}
break;
case 'html':
profile = resources.getVariable('profile');
if (!profile) { // no forced profile, guess from content
// html or xhtml?
profile = this.isXHTML(editor) ? 'xhtml': 'html';
}
return profile;
}
return 'xhtml';
},
/**
* Tries to detect if current document is XHTML one.
* @param {IEmmetEditor} editor
* @returns {Boolean}
*/
isXHTML: function(editor) {
return editor.getContent().search(/<!DOCTYPE[^>]+XHTML/i) != -1;
},
/**
* Check if current caret position is inside &lt;style&gt; tag
* @param {IEmmetEditor} editor
* @returns {Range} Inner range of &lt;style&gt; tag
*/
isStyle: function(editor) {
return !!cssSections.styleTagRange(editor.getContent(), editor.getCaretPos());
},
/**
* Check if given CSS dialect is supported by CSS actions
* @param {String} syntax
* @return {Boolean}
*/
isSupportedCSS: function(syntax) {
return syntax == 'css' || syntax == 'less' || syntax == 'scss';
},
/**
* Check if current caret position is inside "style" attribute of HTML
* element
* @param {IEmmetEditor} editor
* @returns {Range} Inner range of style attribute
*/
isInlineCSS: function(editor) {
return !!cssSections.styleAttrRange(editor.getContent(), editor.getCaretPos());
}
};
});
},{"../assets/htmlMatcher":26,"../assets/range":30,"../assets/resources":31,"../editTree/xml":38,"../parser/abbreviation":55,"./common":73,"./cssSections":74}],71:[function(require,module,exports){
/**
* @author Sergey Chikuyonok (serge.che@gmail.com)
* @link http://chikuyonok.ru
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
return {
/**
* Encodes data using base64 algorithm
* @author Tyler Akins (http://rumkin.com)
* @param {String} input
* @returns {String}
*/
encode : function(input) {
var output = [];
var chr1, chr2, chr3, enc1, enc2, enc3, enc4, cdp1, cdp2, cdp3;
var i = 0, il = input.length, b64 = chars;
while (i < il) {
cdp1 = input.charCodeAt(i++);
cdp2 = input.charCodeAt(i++);
cdp3 = input.charCodeAt(i++);
chr1 = cdp1 & 0xff;
chr2 = cdp2 & 0xff;
chr3 = cdp3 & 0xff;
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(cdp2)) {
enc3 = enc4 = 64;
} else if (isNaN(cdp3)) {
enc4 = 64;
}
output.push(b64.charAt(enc1) + b64.charAt(enc2) + b64.charAt(enc3) + b64.charAt(enc4));
}
return output.join('');
},
/**
* Decodes string using MIME base64 algorithm
*
* @author Tyler Akins (http://rumkin.com)
* @param {String} data
* @return {String}
*/
decode : function(data) {
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, tmpArr = [];
var b64 = chars, il = data.length;
if (!data) {
return data;
}
data += '';
do { // unpack four hexets into three octets using index points in b64
h1 = b64.indexOf(data.charAt(i++));
h2 = b64.indexOf(data.charAt(i++));
h3 = b64.indexOf(data.charAt(i++));
h4 = b64.indexOf(data.charAt(i++));
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
o1 = bits >> 16 & 0xff;
o2 = bits >> 8 & 0xff;
o3 = bits & 0xff;
if (h3 == 64) {
tmpArr[ac++] = String.fromCharCode(o1);
} else if (h4 == 64) {
tmpArr[ac++] = String.fromCharCode(o1, o2);
} else {
tmpArr[ac++] = String.fromCharCode(o1, o2, o3);
}
} while (i < il);
return tmpArr.join('');
}
};
});
},{}],72:[function(require,module,exports){
/**
* Utility module for working with comments in source code
* (mostly stripping it from source)
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('./common');
var range = require('../assets/range');
var stringStream = require('../assets/stringStream');
var reHasComment = /\/\*|\/\//;
return {
/**
* Replaces all comments in given CSS source with spaces,
* which allows more reliable (and faster) token search
* in CSS content
* @param {String} content CSS content
* @return {String}
*/
strip: function(content) {
if (!reHasComment.test(content)) {
return content;
}
var stream = stringStream(content);
var replaceRanges = [];
var ch, ch2;
while ((ch = stream.next())) {
if (ch === '/') {
ch2 = stream.peek();
if (ch2 === '*') { // multiline CSS comment
stream.start = stream.pos - 1;
if (stream.skipTo('*/')) {
stream.pos += 2;
} else {
// unclosed comment
stream.skipToEnd();
}
replaceRanges.push([stream.start, stream.pos]);
} else if (ch2 === '/') {
// preprocessors single line comments
stream.start = stream.pos - 1;
while ((ch2 = stream.next())) {
if (ch2 === '\n' || ch2 == '\r') {
break
}
}
replaceRanges.push([stream.start, stream.pos]);
}
} else {
stream.skipQuoted();
}
}
return utils.replaceWith(content, replaceRanges, ' ');
}
};
});
},{"../assets/range":30,"../assets/stringStream":32,"./common":73}],73:[function(require,module,exports){
/**
* Common utility helper for Emmet
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var range = require('../assets/range');
/**
* Special token used as a placeholder for caret positions inside
* generated output
*/
var caretPlaceholder = '${0}';
return {
reTag: /<\/?[\w:\-]+(?:\s+[\w\-:]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*\s*(\/?)>$/,
defaultSyntax: function() {
return 'html';
},
defaultProfile: function() {
return 'plain';
},
/**
* Test if passed string ends with XHTML tag. This method is used for testing
* '>' character: it belongs to tag or it's a part of abbreviation?
* @param {String} str
* @return {Boolean}
*/
endsWithTag: function(str) {
return this.reTag.test(str);
},
/**
* Check if passed symbol is a number
* @param {String} ch
* @returns {Boolean}
*/
isNumeric: function(ch) {
if (typeof(ch) == 'string')
ch = ch.charCodeAt(0);
return (ch && ch > 47 && ch < 58);
},
/**
* Trim whitespace from string
* @param {String} text
* @return {String}
*/
trim: (function() {
if (String.prototype.trim) {
return function(text) {
return text ? text.trim() : '';
};
}
return function(text) {
return (text || "").replace(/^\s+|\s+$/g, "");
}
})(),
/**
* Split text into lines. Set <code>remove_empty</code> to true to filter
* empty lines
* @param {String} text Text to split
* @param {Boolean} removeEmpty Remove empty lines from result
* @return {Array}
*/
splitByLines: function(text, removeEmpty) {
// IE fails to split string by regexp,
// need to normalize newlines first
// Also, Mozilla's Rhiho JS engine has a weird newline bug
var nl = '\n';
var lines = (text || '')
.replace(/\r\n/g, '\n')
.replace(/\n\r/g, '\n')
.replace(/\r/g, '\n')
.replace(/\n/g, nl)
.split(nl);
if (removeEmpty) {
lines = lines.filter(function(line) {
return line.length && !!this.trim(line);
}, this);
}
return lines;
},
/**
* Repeats string <code>howMany</code> times
* @param {String} str
* @param {Number} how_many
* @return {String}
*/
repeatString: function(str, howMany) {
var out = '';
while (howMany--) {
out += str;
}
return out;
},
/**
* Returns list of paddings that should be used to align passed string
* @param {Array} strings
* @returns {Array}
*/
getStringsPads: function(strings) {
var lengths = strings.map(function(s) {
return typeof s === 'string' ? s.length : +s;
});
var max = lengths.reduce(function(prev, cur) {
return typeof prev === 'undefined' ? cur : Math.max(prev, cur);
});
return lengths.map(function(l) {
var pad = max - l;
return pad ? this.repeatString(' ', pad) : '';
}, this);
},
/**
* Indents text with padding
* @param {String} text Text to indent
* @param {String} pad Padding size (number) or padding itself (string)
* @return {String}
*/
padString: function(text, pad) {
var result = [];
var lines = this.splitByLines(text);
var nl = '\n';
result.push(lines[0]);
for (var j = 1; j < lines.length; j++)
result.push(nl + pad + lines[j]);
return result.join('');
},
/**
* Pad string with zeroes
* @param {String} str String to pad
* @param {Number} pad Desired string length
* @return {String}
*/
zeroPadString: function(str, pad) {
var padding = '';
var il = str.length;
while (pad > il++) padding += '0';
return padding + str;
},
/**
* Removes padding at the beginning of each text's line
* @param {String} text
* @param {String} pad
*/
unindentString: function(text, pad) {
var lines = this.splitByLines(text);
var pl = pad.length;
for (var i = 0, il = lines.length, line; i < il; i++) {
line = lines[i];
if (line.substr(0, pl) === pad) {
lines[i] = line.substr(pl);
}
}
return lines.join('\n');
},
/**
* Replaces unescaped symbols in <code>str</code>. For example, the '$' symbol
* will be replaced in 'item$count', but not in 'item\$count'.
* @param {String} str Original string
* @param {String} symbol Symbol to replace
* @param {String} replace Symbol replacement. Might be a function that
* returns new value
* @return {String}
*/
replaceUnescapedSymbol: function(str, symbol, replace) {
var i = 0;
var il = str.length;
var sl = symbol.length;
var matchCount = 0;
while (i < il) {
if (str.charAt(i) == '\\') {
// escaped symbol, skip next character
i += sl + 1;
} else if (str.substr(i, sl) == symbol) {
// have match
var curSl = sl;
matchCount++;
var newValue = replace;
if (typeof replace === 'function') {
var replaceData = replace(str, symbol, i, matchCount);
if (replaceData) {
curSl = replaceData[0].length;
newValue = replaceData[1];
} else {
newValue = false;
}
}
if (newValue === false) { // skip replacement
i++;
continue;
}
str = str.substring(0, i) + newValue + str.substring(i + curSl);
// adjust indexes
il = str.length;
i += newValue.length;
} else {
i++;
}
}
return str;
},
/**
* Replaces '$' character in string assuming it might be escaped with '\'
* @param {String} str String where character should be replaced
* @param {String} value New value
* @return {String}
*/
replaceCounter: function(str, value, total) {
var symbol = '$';
// in case we received strings from Java, convert the to native strings
str = String(str);
value = String(value);
if (/^\-?\d+$/.test(value)) {
value = +value;
}
var that = this;
return this.replaceUnescapedSymbol(str, symbol, function(str, symbol, pos, matchNum){
if (str.charAt(pos + 1) == '{' || that.isNumeric(str.charAt(pos + 1)) ) {
// it's a variable, skip it
return false;
}
// replace sequense of $ symbols with padded number
var j = pos + 1;
while(str.charAt(j) == '$' && str.charAt(j + 1) != '{') j++;
var pad = j - pos;
// get counter base
var base = 0, decrement = false, m;
if ((m = str.substr(j).match(/^@(\-?)(\d*)/))) {
j += m[0].length;
if (m[1]) {
decrement = true;
}
base = parseInt(m[2] || 1, 10) - 1;
}
if (decrement && total && typeof value === 'number') {
value = total - value + 1;
}
value += base;
return [str.substring(pos, j), that.zeroPadString(value + '', pad)];
});
},
/**
* Check if string matches against <code>reTag</code> regexp. This
* function may be used to test if provided string contains HTML tags
* @param {String} str
* @returns {Boolean}
*/
matchesTag: function(str) {
return this.reTag.test(str || '');
},
/**
* Escapes special characters used in Emmet, like '$', '|', etc.
* Use this method before passing to actions like "Wrap with Abbreviation"
* to make sure that existing special characters won't be altered
* @param {String} text
* @return {String}
*/
escapeText: function(text) {
return text.replace(/([\$\\])/g, '\\$1');
},
/**
* Unescapes special characters used in Emmet, like '$', '|', etc.
* @param {String} text
* @return {String}
*/
unescapeText: function(text) {
return text.replace(/\\(.)/g, '$1');
},
/**
* Returns caret placeholder
* @returns {String}
*/
getCaretPlaceholder: function() {
return typeof caretPlaceholder === 'function'
? caretPlaceholder.apply(this, arguments)
: caretPlaceholder;
},
/**
* Sets new representation for carets in generated output
* @param {String} value New caret placeholder. Might be a
* <code>Function</code>
*/
setCaretPlaceholder: function(value) {
caretPlaceholder = value;
},
/**
* Returns line padding
* @param {String} line
* @return {String}
*/
getLinePadding: function(line) {
return (line.match(/^(\s+)/) || [''])[0];
},
/**
* Helper function that returns padding of line of <code>pos</code>
* position in <code>content</code>
* @param {String} content
* @param {Number} pos
* @returns {String}
*/
getLinePaddingFromPosition: function(content, pos) {
var lineRange = this.findNewlineBounds(content, pos);
return this.getLinePadding(lineRange.substring(content));
},
/**
* Escape special regexp chars in string, making it usable for creating dynamic
* regular expressions
* @param {String} str
* @return {String}
*/
escapeForRegexp: function(str) {
var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\
return str.replace(specials, "\\$&");
},
/**
* Make decimal number look good: convert it to fixed precision end remove
* traling zeroes
* @param {Number} num
* @param {Number} fracion Fraction numbers (default is 2)
* @return {String}
*/
prettifyNumber: function(num, fraction) {
return num.toFixed(typeof fraction == 'undefined' ? 2 : fraction).replace(/\.?0+$/, '');
},
/**
* Replace substring of <code>str</code> with <code>value</code>
* @param {String} str String where to replace substring
* @param {String} value New substring value
* @param {Number} start Start index of substring to replace. May also
* be a <code>Range</code> object: in this case, the <code>end</code>
* argument is not required
* @param {Number} end End index of substring to replace. If ommited,
* <code>start</code> argument is used
*/
replaceSubstring: function(str, value, start, end) {
if (typeof start === 'object' && 'end' in start) {
end = start.end;
start = start.start;
}
if (typeof end === 'string') {
end = start + end.length;
}
if (typeof end === 'undefined') {
end = start;
}
if (start < 0 || start > str.length)
return str;
return str.substring(0, start) + value + str.substring(end);
},
/**
* Fills substrings in `content`, defined by given ranges,
* wich `ch` character
* @param {String} content
* @param {Array} ranges
* @return {String}
*/
replaceWith: function(content, ranges, ch, noRepeat) {
if (ranges.length) {
var offset = 0, fragments = [];
ranges.forEach(function(r) {
var repl = noRepeat ? ch : this.repeatString(ch, r[1] - r[0]);
fragments.push(content.substring(offset, r[0]), repl);
offset = r[1];
}, this);
content = fragments.join('') + content.substring(offset);
}
return content;
},
/**
* Narrows down text range, adjusting selection to non-space characters
* @param {String} text
* @param {Number} start Starting range in <code>text</code> where
* slection should be adjusted. Can also be any object that is accepted
* by <code>Range</code> class
* @return {Range}
*/
narrowToNonSpace: function(text, start, end) {
var rng = range.create(start, end);
var reSpace = /[\s\n\r\u00a0]/;
// narrow down selection until first non-space character
while (rng.start < rng.end) {
if (!reSpace.test(text.charAt(rng.start)))
break;
rng.start++;
}
while (rng.end > rng.start) {
rng.end--;
if (!reSpace.test(text.charAt(rng.end))) {
rng.end++;
break;
}
}
return rng;
},
/**
* Find start and end index of text line for <code>from</code> index
* @param {String} text
* @param {Number} from
*/
findNewlineBounds: function(text, from) {
var len = text.length,
start = 0,
end = len - 1,
ch;
// search left
for (var i = from - 1; i > 0; i--) {
ch = text.charAt(i);
if (ch == '\n' || ch == '\r') {
start = i + 1;
break;
}
}
// search right
for (var j = from; j < len; j++) {
ch = text.charAt(j);
if (ch == '\n' || ch == '\r') {
end = j;
break;
}
}
return range.create(start, end - start);
},
/**
* Deep merge of two or more objects. Taken from jQuery.extend()
*/
deepMerge: function() {
var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length;
// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== 'object' && typeof target !== 'function') {
target = {};
}
for ( ; i < length; i++ ) {
// Only deal with non-null/undefined values
if ( (options = arguments[ i ]) !== null ) {
// Extend the base object
for ( name in options ) {
src = target[ name ];
copy = options[ name ];
// Prevent never-ending loop
if ( target === copy ) {
continue;
}
// Recurse if we're merging plain objects or arrays
if ( copy && ( typeof copy === 'object' || (copyIsArray = Array.isArray(copy)) ) ) {
if ( copyIsArray ) {
copyIsArray = false;
clone = src && Array.isArray(src) ? src : [];
} else {
clone = src && typeof src === 'object' ? src : {};
}
// Never move original objects, clone them
target[ name ] = this.deepMerge(clone, copy );
// Don't bring in undefined values
} else if ( copy !== undefined ) {
target[ name ] = copy;
}
}
}
}
// Return the modified object
return target;
},
/**
* Dead simple string-to-JSON parser
* @param {String} str
* @returns {Object}
*/
parseJSON: function(str) {
if (typeof str == 'object') {
return str;
}
try {
return JSON.parse(str);
} catch(e) {
return {};
}
},
/**************************
* Utility belt
**************************/
unique: function(arr, comparator) {
var lookup = [];
return arr.filter(function(item) {
var val = comparator ? comparator(item) : item;
if (lookup.indexOf(val) < 0) {
lookup.push(val);
return true;
}
});
},
/**
* Return a copy of the object, filtered to only have values for
* the whitelisted keys.
* @param {Object} obj
* @return {Object}
*/
pick: function(obj) {
var result = {};
var keys = this.toArray(arguments, 1);
Object.keys(obj).forEach(function(key) {
if (~keys.indexOf(key)) {
result[key] = obj[key];
}
});
return result;
},
find: function(arr, comparator, ctx) {
var result;
if (ctx) {
comparator = comparator.bind(ctx);
}
if (Array.isArray(arr)) {
arr.some(function(item, i) {
if (comparator(item, i)) {
return result = item;
}
});
} else {
Object.keys(arr).some(function(key, i) {
if (comparator(arr[key], i)) {
return result = arr[key];
}
});
}
return result;
},
toArray: function(obj, sliceIx) {
if (Array.isArray(obj) && !sliceIx) {
return obj;
}
return Array.prototype.slice.call(obj, sliceIx || 0);
},
extend: function(obj) {
for (var i = 1, il = arguments.length, a; i < il; i++) {
a = arguments[i];
if (a) {
Object.keys(a).forEach(function(key) {
obj[key] = a[key];
});
}
}
return obj;
},
defaults: function(obj) {
for (var i = 1, il = arguments.length, a; i < il; i++) {
a = arguments[i];
if (a) {
Object.keys(a).forEach(function(key) {
if (!(key in obj)) {
obj[key] = a[key];
}
});
}
}
return obj;
},
flatten: function(arr, out) {
out = out || [];
var self = this;
self.toArray(arr).forEach(function(item) {
if (Array.isArray(item)) {
self.flatten(item, out);
} else {
out.push(item);
}
});
return out;
},
clone: function(obj) {
if (Array.isArray(obj)) {
return obj.slice(0);
}
return this.extend({}, obj);
},
without: function(arr) {
this.toArray(arguments, 1).forEach(function(item) {
var ix;
while (~(ix = arr.indexOf(item))) {
arr.splice(ix, 1);
}
});
return arr;
},
last: function(arr) {
return arr[arr.length - 1];
}
};
});
},{"../assets/range":30}],74:[function(require,module,exports){
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('./common');
var commentsUtils = require('./comments');
var range = require('../assets/range');
var stringStream = require('../assets/stringStream');
var cssParser = require('../parser/css');
var htmlMatcher = require('../assets/htmlMatcher');
var xmlEditTree = require('../editTree/xml');
var idCounter = 1;
var maxId = 1000000;
var reSpaceTrim = /^(\s*).+?(\s*)$/;
var reSpace = /\s/g;
var reComma = /,/;
function isQuote(ch) {
return ch == '"' || ch == "'";
}
function getId() {
idCounter = (idCounter + 1) % maxId;
return 's' + idCounter;
}
/**
* @param {Range} range Full selector range with additional
* properties for matching name and content (@see findAllRules())
* @param {String} source CSS source
*/
function CSSSection(rng, source) {
this.id = getId();
/** @type {CSSSection} */
this.parent = null;
/** @type {CSSSection} */
this.nextSibling = null;
/** @type {CSSSection} */
this.previousSibling = null;
this._source = source;
this._name = null;
this._content = null;
/**
* Custom data for current nodes, used by other modules for
* caching etc.
* @type {Object}
*/
this._data = {};
if (!rng && source) {
rng = range(0, source);
}
this.range = rng;
this.children = [];
}
CSSSection.prototype = {
addChild: function(section) {
if (!(section instanceof CSSSection)) {
section = new CSSSection(section);
}
var lastChild = utils.last(this.children);
if (lastChild) {
lastChild.nextSibling = section;
section.previousSibling = lastChild;
}
section.parent = this;
this.children.push(section);
return section;
},
/**
* Returns root node
* @return {CSSSection}
*/
root: function() {
var root = this;
do {
if (!root.parent) {
return root;
}
} while(root = root.parent);
return root;
},
/**
* Returns currect CSS source
* @return {String}
*/
source: function() {
return this._source || this.root()._source;
},
/**
* Returns section name
* @return {String}
*/
name: function() {
if (this._name === null) {
var range = this.nameRange();
if (range) {
this._name = range.substring(this.source());
}
}
return this._name;
},
/**
* Returns section name range
* @return {[type]} [description]
*/
nameRange: function() {
if (this.range && '_selectorEnd' in this.range) {
return range.create2(this.range.start, this.range._selectorEnd);
}
},
/**
* Returns deepest child of current section (or section itself)
* which includes given position.
* @param {Number} pos
* @return {CSSSection}
*/
matchDeep: function(pos) {
if (!this.range.inside(pos)) {
return null;
}
for (var i = 0, il = this.children.length, m; i < il; i++) {
m = this.children[i].matchDeep(pos);
if (m) {
return m;
}
};
return this.parent ? this : null;
},
/**
* Returns current and all nested sections ranges
* @return {Array}
*/
allRanges: function() {
var out = [];
if (this.parent) {
// add current range if it is not root node
out.push(this.range);
}
this.children.forEach(function(child) {
out = out.concat(child.allRanges());
});
return out;
},
data: function(key, value) {
if (typeof value !== 'undefined') {
this._data[key] = value;
}
return this._data[key];
},
stringify: function(indent) {
indent = indent || '';
var out = '';
this.children.forEach(function(item) {
out += indent + item.name().replace(/\n/g, '\\n') + '\n';
out += item.stringify(indent + '--');
});
return out;
},
/**
* Returns current sections actual content,
* e.g. content without nested sections
* @return {String}
*/
content: function() {
if (this._content !== null) {
return this._content;
}
if (!this.range || !('_contentStart' in this.range)) {
return '';
}
var r = range.create2(this.range._contentStart + 1, this.range.end - 1);
var source = this.source();
var start = r.start;
var out = '';
this.children.forEach(function(child) {
out += source.substring(start, child.range.start);
start = child.range.end;
});
out += source.substring(start, r.end);
return this._content = utils.trim(out);
}
};
return {
/**
* Finds all CSS rules ranges in given CSS source
* @param {String} content CSS source
* @return {Array} Array of ranges
*/
findAllRules: function(content) {
content = this.sanitize(content);
var stream = stringStream(content);
var ranges = [], matchedRanges;
var self = this;
var saveRule = function(r) {
var selRange = self.extractSelector(content, r.start);
var rule = range.create2(selRange.start, r.end);
rule._selectorEnd = selRange.end;
rule._contentStart = r.start;
ranges.push(rule);
};
var ch;
while (ch = stream.next()) {
if (isQuote(ch)) {
if (!stream.skipString(ch)) {
break; // unterminated string
}
continue;
}
if (ch == '{') {
matchedRanges = this.matchBracesRanges(content, stream.pos - 1);
matchedRanges.forEach(saveRule);
if (matchedRanges.length) {
stream.pos = utils.last(matchedRanges).end;
continue;
}
}
}
return ranges.sort(function(a, b) {
return a.start - b.start;
});
},
/**
* Matches curly braces content right after given position
* @param {String} content CSS content. Must not contain comments!
* @param {Number} pos Search start position
* @return {Range}
*/
matchBracesRanges: function(content, pos, sanitize) {
if (sanitize) {
content = this.sanitize(content);
}
var stream = stringStream(content);
stream.start = stream.pos = pos;
var stack = [], ranges = [];
var ch;
while (ch = stream.next()) {
if (ch == '{') {
stack.push(stream.pos - 1);
} else if (ch == '}') {
if (!stack.length) {
throw 'Invalid source structure (check for curly braces)';
}
ranges.push(range.create2(stack.pop(), stream.pos));
if (!stack.length) {
return ranges;
}
} else {
stream.skipQuoted();
}
}
return ranges;
},
/**
* Extracts CSS selector from CSS document from
* given position. The selector is located by moving backward
* from given position which means that passed position
* must point to the end of selector
* @param {String} content CSS source
* @param {Number} pos Search position
* @param {Boolean} sanitize Sanitize CSS source before processing.
* Off by default and assumes that CSS must be comment-free already
* (for performance)
* @return {Range}
*/
extractSelector: function(content, pos, sanitize) {
if (sanitize) {
content = this.sanitize(content);
}
var skipString = function() {
var quote = content.charAt(pos);
if (quote == '"' || quote == "'") {
while (--pos >= 0) {
if (content.charAt(pos) == quote && content.charAt(pos - 1) != '\\') {
break;
}
}
return true;
}
return false;
};
// find CSS selector
var ch;
var endPos = pos;
while (--pos >= 0) {
if (skipString()) continue;
ch = content.charAt(pos);
if (ch == ')') {
// looks like its a preprocessor thing,
// most likely a mixin arguments list, e.g.
// .mixin (@arg1; @arg2) {...}
while (--pos >= 0) {
if (skipString()) continue;
if (content.charAt(pos) == '(') {
break;
}
}
continue;
}
if (ch == '{' || ch == '}' || ch == ';') {
pos++;
break;
}
}
if (pos < 0) {
pos = 0;
}
var selector = content.substring(pos, endPos);
// trim whitespace from matched selector
var m = selector.replace(reSpace, ' ').match(reSpaceTrim);
if (m) {
pos += m[1].length;
endPos -= m[2].length;
}
return range.create2(pos, endPos);
},
/**
* Search for nearest CSS rule/section that contains
* given position
* @param {String} content CSS content or matched CSS rules (array of ranges)
* @param {Number} pos Search position
* @return {Range}
*/
matchEnclosingRule: function(content, pos) {
if (typeof content === 'string') {
content = this.findAllRules(content);
}
var rules = content.filter(function(r) {
return r.inside(pos);
});
return utils.last(rules);
},
/**
* Locates CSS rule next or before given position
* @param {String} content CSS content
* @param {Number} pos Search start position
* @param {Boolean} isBackward Search backward (find previous rule insteaf of next one)
* @return {Range}
*/
locateRule: function(content, pos, isBackward) {
// possible case: editor reported that current syntax is
// CSS, but its actually a HTML document (either `style` tag or attribute)
var offset = 0;
var subrange = this.styleTagRange(content, pos);
if (subrange) {
offset = subrange.start;
pos -= subrange.start;
content = subrange.substring(content);
}
var rules = this.findAllRules(content);
var ctxRule = this.matchEnclosingRule(rules, pos);
if (ctxRule) {
return ctxRule.shift(offset);
}
for (var i = 0, il = rules.length; i < il; i++) {
if (rules[i].start > pos) {
return rules[isBackward ? i - 1 : i].shift(offset);
}
}
},
/**
* Sanitizes given CSS content: replaces content that may
* interfere with parsing (comments, interpolations, etc.)
* with spaces. Sanitized content MUST NOT be used for
* editing or outputting, it just simplifies searching
* @param {String} content CSS content
* @return {String}
*/
sanitize: function(content) {
content = commentsUtils.strip(content);
// remove preprocessor string interpolations like #{var}
var stream = stringStream(content);
var replaceRanges = [];
var ch, ch2;
while ((ch = stream.next())) {
if (isQuote(ch)) {
// skip string
stream.skipString(ch)
continue;
} else if (ch === '#' || ch === '@') {
ch2 = stream.peek();
if (ch2 === '{') { // string interpolation
stream.start = stream.pos - 1;
if (stream.skipTo('}')) {
stream.pos += 1;
} else {
throw 'Invalid string interpolation at ' + stream.start;
}
replaceRanges.push([stream.start, stream.pos]);
}
}
}
return utils.replaceWith(content, replaceRanges, 'a');
},
/**
* Parses and returns all sections in given CSS
* as tree-like structure, e.g. provides nesting
* info
* @param {String} content CSS content
* @return {CSSSection}
*/
sectionTree: function(content) {
var root = new CSSSection(null, content);
var rules = this.findAllRules(content);
// rules are sorted in order they appear in CSS source
// so we can optimize their nesting routine
var insert = function(range, ctx) {
while (ctx && ctx.range) {
if (ctx.range.contains(range)) {
return ctx.addChild(range);
}
ctx = ctx.parent;
}
// if we are here then given range is a top-level section
return root.addChild(range);
};
var ctx = root;
rules.forEach(function(r) {
ctx = insert(r, ctx);
});
return root;
},
/**
* Returns ranges for all nested sections, available in
* given CSS rule
* @param {CSSEditContainer} rule
* @return {Array}
*/
nestedSectionsInRule: function(rule) {
var offset = rule.valueRange(true).start;
var nestedSections = this.findAllRules(rule.valueRange().substring(rule.source));
nestedSections.forEach(function(section) {
section.start += offset;
section.end += offset;
section._selectorEnd += offset;
section._contentStart += offset;
});
return nestedSections;
},
styleTagRange: function(content, pos) {
var tag = htmlMatcher.tag(content, pos);
return tag && tag.open.name.toLowerCase() == 'style'
&& tag.innerRange.cmp(pos, 'lte', 'gte')
&& tag.innerRange;
},
styleAttrRange: function(content, pos) {
var tree = xmlEditTree.parseFromPosition(content, pos, true);
if (tree) {
var attr = tree.itemFromPosition(pos, true);
return attr && attr.name().toLowerCase() == 'style'
&& attr.valueRange(true).cmp(pos, 'lte', 'gte')
&& attr.valueRange(true);
}
},
CSSSection: CSSSection
};
});
},{"../assets/htmlMatcher":26,"../assets/range":30,"../assets/stringStream":32,"../editTree/xml":38,"../parser/css":56,"./comments":72,"./common":73}],75:[function(require,module,exports){
/**
* Utility module used to prepare text for pasting into back-end editor
* @author Sergey Chikuyonok (serge.che@gmail.com) <http://chikuyonok.ru>
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('./common');
var resources = require('../assets/resources');
return {
/**
* Check if cursor is placed inside XHTML tag
* @param {String} html Contents of the document
* @param {Number} caretPos Current caret position inside tag
* @return {Boolean}
*/
isInsideTag: function(html, caretPos) {
var reTag = /^<\/?\w[\w\:\-]*.*?>/;
// search left to find opening brace
var pos = caretPos;
while (pos > -1) {
if (html.charAt(pos) == '<')
break;
pos--;
}
if (pos != -1) {
var m = reTag.exec(html.substring(pos));
if (m && caretPos > pos && caretPos < pos + m[0].length)
return true;
}
return false;
},
/**
* Sanitizes incoming editor data and provides default values for
* output-specific info
* @param {IEmmetEditor} editor
* @param {String} syntax
* @param {String} profile
*/
outputInfo: function(editor, syntax, profile) {
// most of this code makes sense for Java/Rhino environment
// because string that comes from Java are not actually JS string
// but Java String object so the have to be explicitly converted
// to native string
profile = profile || editor.getProfileName();
return {
/** @memberOf outputInfo */
syntax: String(syntax || editor.getSyntax()),
profile: profile || null,
content: String(editor.getContent())
};
},
/**
* Unindent content, thus preparing text for tag wrapping
* @param {IEmmetEditor} editor Editor instance
* @param {String} text
* @return {String}
*/
unindent: function(editor, text) {
return utils.unindentString(text, this.getCurrentLinePadding(editor));
},
/**
* Returns padding of current editor's line
* @param {IEmmetEditor} Editor instance
* @return {String}
*/
getCurrentLinePadding: function(editor) {
return utils.getLinePadding(editor.getCurrentLine());
},
/**
* Normalizes content according to given preferences, e.g.
* replaces newlines and indentation with ones defined in
* `options`. If options are not provided or incomplete,
* values will be taken from current user environment
* @param {String} text
* @param {Object} options
* @return {String}
*/
normalize: function(text, options) {
options = utils.extend({
newline: resources.getNewline(),
indentation: resources.getVariable('indentation')
}, options);
var indent = function(tabs) {
return utils.repeatString(options.indentation, tabs.length);
};
var lines = utils.splitByLines(text);
// normailze indentation if its not tabs
if (options.indentation !== '\t') {
lines = lines.map(function(line) {
return line.replace(/^\s+/, function(space) {
return space.replace(/\t/g, indent);
});
});
}
// normalize newlines
return lines.join(options.newline);
}
};
});
},{"../assets/resources":31,"./common":73}],76:[function(require,module,exports){
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
/*
Source: https://github.com/silentmatt/js-expression-eval
Based on ndef.parser, by Raphael Graf(r@undefined.ch)
http://www.undefined.ch/mparser/index.html
Ported to JavaScript and modified by Matthew Crumley (email@matthewcrumley.com, http://silentmatt.com/)
You are free to use and modify this code in anyway you find useful. Please leave this comment in the code
to acknowledge its original source. If you feel like it, I enjoy hearing about projects that use my code,
but don't feel like you have to let me know or ask permission.
*/
function object(o) {
function F() {}
F.prototype = o;
return new F();
}
var TNUMBER = 0;
var TOP1 = 1;
var TOP2 = 2;
var TVAR = 3;
var TFUNCALL = 4;
function Token(type_, index_, prio_, number_) {
this.type_ = type_;
this.index_ = index_ || 0;
this.prio_ = prio_ || 0;
this.number_ = (number_ !== undefined && number_ !== null) ? number_ : 0;
this.toString = function () {
switch (this.type_) {
case TNUMBER:
return this.number_;
case TOP1:
case TOP2:
case TVAR:
return this.index_;
case TFUNCALL:
return "CALL";
default:
return "Invalid Token";
}
};
}
function Expression(tokens, ops1, ops2, functions) {
this.tokens = tokens;
this.ops1 = ops1;
this.ops2 = ops2;
this.functions = functions;
}
// Based on http://www.json.org/json2.js
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\'\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
"'" : "\\'",
'\\': '\\\\'
};
function escapeValue(v) {
if (typeof v === "string") {
escapable.lastIndex = 0;
return escapable.test(v) ?
"'" + v.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string' ? c :
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + "'" :
"'" + v + "'";
}
return v;
}
Expression.prototype = {
simplify: function (values) {
values = values || {};
var nstack = [];
var newexpression = [];
var n1;
var n2;
var f;
var L = this.tokens.length;
var item;
var i = 0;
for (i = 0; i < L; i++) {
item = this.tokens[i];
var type_ = item.type_;
if (type_ === TNUMBER) {
nstack.push(item);
}
else if (type_ === TVAR && (item.index_ in values)) {
item = new Token(TNUMBER, 0, 0, values[item.index_]);
nstack.push(item);
}
else if (type_ === TOP2 && nstack.length > 1) {
n2 = nstack.pop();
n1 = nstack.pop();
f = this.ops2[item.index_];
item = new Token(TNUMBER, 0, 0, f(n1.number_, n2.number_));
nstack.push(item);
}
else if (type_ === TOP1 && nstack.length > 0) {
n1 = nstack.pop();
f = this.ops1[item.index_];
item = new Token(TNUMBER, 0, 0, f(n1.number_));
nstack.push(item);
}
else {
while (nstack.length > 0) {
newexpression.push(nstack.shift());
}
newexpression.push(item);
}
}
while (nstack.length > 0) {
newexpression.push(nstack.shift());
}
return new Expression(newexpression, object(this.ops1), object(this.ops2), object(this.functions));
},
substitute: function (variable, expr) {
if (!(expr instanceof Expression)) {
expr = new Parser().parse(String(expr));
}
var newexpression = [];
var L = this.tokens.length;
var item;
var i = 0;
for (i = 0; i < L; i++) {
item = this.tokens[i];
var type_ = item.type_;
if (type_ === TVAR && item.index_ === variable) {
for (var j = 0; j < expr.tokens.length; j++) {
var expritem = expr.tokens[j];
var replitem = new Token(expritem.type_, expritem.index_, expritem.prio_, expritem.number_);
newexpression.push(replitem);
}
}
else {
newexpression.push(item);
}
}
var ret = new Expression(newexpression, object(this.ops1), object(this.ops2), object(this.functions));
return ret;
},
evaluate: function (values) {
values = values || {};
var nstack = [];
var n1;
var n2;
var f;
var L = this.tokens.length;
var item;
var i = 0;
for (i = 0; i < L; i++) {
item = this.tokens[i];
var type_ = item.type_;
if (type_ === TNUMBER) {
nstack.push(item.number_);
}
else if (type_ === TOP2) {
n2 = nstack.pop();
n1 = nstack.pop();
f = this.ops2[item.index_];
nstack.push(f(n1, n2));
}
else if (type_ === TVAR) {
if (item.index_ in values) {
nstack.push(values[item.index_]);
}
else if (item.index_ in this.functions) {
nstack.push(this.functions[item.index_]);
}
else {
throw new Error("undefined variable: " + item.index_);
}
}
else if (type_ === TOP1) {
n1 = nstack.pop();
f = this.ops1[item.index_];
nstack.push(f(n1));
}
else if (type_ === TFUNCALL) {
n1 = nstack.pop();
f = nstack.pop();
if (f.apply && f.call) {
if (Object.prototype.toString.call(n1) == "[object Array]") {
nstack.push(f.apply(undefined, n1));
}
else {
nstack.push(f.call(undefined, n1));
}
}
else {
throw new Error(f + " is not a function");
}
}
else {
throw new Error("invalid Expression");
}
}
if (nstack.length > 1) {
throw new Error("invalid Expression (parity)");
}
return nstack[0];
},
toString: function (toJS) {
var nstack = [];
var n1;
var n2;
var f;
var L = this.tokens.length;
var item;
var i = 0;
for (i = 0; i < L; i++) {
item = this.tokens[i];
var type_ = item.type_;
if (type_ === TNUMBER) {
nstack.push(escapeValue(item.number_));
}
else if (type_ === TOP2) {
n2 = nstack.pop();
n1 = nstack.pop();
f = item.index_;
if (toJS && f == "^") {
nstack.push("Math.pow(" + n1 + "," + n2 + ")");
}
else {
nstack.push("(" + n1 + f + n2 + ")");
}
}
else if (type_ === TVAR) {
nstack.push(item.index_);
}
else if (type_ === TOP1) {
n1 = nstack.pop();
f = item.index_;
if (f === "-") {
nstack.push("(" + f + n1 + ")");
}
else {
nstack.push(f + "(" + n1 + ")");
}
}
else if (type_ === TFUNCALL) {
n1 = nstack.pop();
f = nstack.pop();
nstack.push(f + "(" + n1 + ")");
}
else {
throw new Error("invalid Expression");
}
}
if (nstack.length > 1) {
throw new Error("invalid Expression (parity)");
}
return nstack[0];
},
variables: function () {
var L = this.tokens.length;
var vars = [];
for (var i = 0; i < L; i++) {
var item = this.tokens[i];
if (item.type_ === TVAR && (vars.indexOf(item.index_) == -1)) {
vars.push(item.index_);
}
}
return vars;
},
toJSFunction: function (param, variables) {
var f = new Function(param, "with(Parser.values) { return " + this.simplify(variables).toString(true) + "; }");
return f;
}
};
function add(a, b) {
return Number(a) + Number(b);
}
function sub(a, b) {
return a - b;
}
function mul(a, b) {
return a * b;
}
function div(a, b) {
return a / b;
}
function mod(a, b) {
return a % b;
}
function concat(a, b) {
return "" + a + b;
}
function neg(a) {
return -a;
}
function random(a) {
return Math.random() * (a || 1);
}
function fac(a) { //a!
a = Math.floor(a);
var b = a;
while (a > 1) {
b = b * (--a);
}
return b;
}
// TODO: use hypot that doesn't overflow
function pyt(a, b) {
return Math.sqrt(a * a + b * b);
}
function append(a, b) {
if (Object.prototype.toString.call(a) != "[object Array]") {
return [a, b];
}
a = a.slice();
a.push(b);
return a;
}
function Parser() {
this.success = false;
this.errormsg = "";
this.expression = "";
this.pos = 0;
this.tokennumber = 0;
this.tokenprio = 0;
this.tokenindex = 0;
this.tmpprio = 0;
this.ops1 = {
"sin": Math.sin,
"cos": Math.cos,
"tan": Math.tan,
"asin": Math.asin,
"acos": Math.acos,
"atan": Math.atan,
"sqrt": Math.sqrt,
"log": Math.log,
"abs": Math.abs,
"ceil": Math.ceil,
"floor": Math.floor,
"round": Math.round,
"-": neg,
"exp": Math.exp
};
this.ops2 = {
"+": add,
"-": sub,
"*": mul,
"/": div,
"%": mod,
"^": Math.pow,
",": append,
"||": concat
};
this.functions = {
"random": random,
"fac": fac,
"min": Math.min,
"max": Math.max,
"pyt": pyt,
"pow": Math.pow,
"atan2": Math.atan2
};
this.consts = {
"E": Math.E,
"PI": Math.PI
};
}
Parser.parse = function (expr) {
return new Parser().parse(expr);
};
Parser.evaluate = function (expr, variables) {
return Parser.parse(expr).evaluate(variables);
};
Parser.Expression = Expression;
Parser.values = {
sin: Math.sin,
cos: Math.cos,
tan: Math.tan,
asin: Math.asin,
acos: Math.acos,
atan: Math.atan,
sqrt: Math.sqrt,
log: Math.log,
abs: Math.abs,
ceil: Math.ceil,
floor: Math.floor,
round: Math.round,
random: random,
fac: fac,
exp: Math.exp,
min: Math.min,
max: Math.max,
pyt: pyt,
pow: Math.pow,
atan2: Math.atan2,
E: Math.E,
PI: Math.PI
};
var PRIMARY = 1 << 0;
var OPERATOR = 1 << 1;
var FUNCTION = 1 << 2;
var LPAREN = 1 << 3;
var RPAREN = 1 << 4;
var COMMA = 1 << 5;
var SIGN = 1 << 6;
var CALL = 1 << 7;
var NULLARY_CALL = 1 << 8;
Parser.prototype = {
parse: function (expr) {
this.errormsg = "";
this.success = true;
var operstack = [];
var tokenstack = [];
this.tmpprio = 0;
var expected = (PRIMARY | LPAREN | FUNCTION | SIGN);
var noperators = 0;
this.expression = expr;
this.pos = 0;
while (this.pos < this.expression.length) {
if (this.isOperator()) {
if (this.isSign() && (expected & SIGN)) {
if (this.isNegativeSign()) {
this.tokenprio = 2;
this.tokenindex = "-";
noperators++;
this.addfunc(tokenstack, operstack, TOP1);
}
expected = (PRIMARY | LPAREN | FUNCTION | SIGN);
}
else if (this.isComment()) {
}
else {
if ((expected & OPERATOR) === 0) {
this.error_parsing(this.pos, "unexpected operator");
}
noperators += 2;
this.addfunc(tokenstack, operstack, TOP2);
expected = (PRIMARY | LPAREN | FUNCTION | SIGN);
}
}
else if (this.isNumber()) {
if ((expected & PRIMARY) === 0) {
this.error_parsing(this.pos, "unexpected number");
}
var token = new Token(TNUMBER, 0, 0, this.tokennumber);
tokenstack.push(token);
expected = (OPERATOR | RPAREN | COMMA);
}
else if (this.isString()) {
if ((expected & PRIMARY) === 0) {
this.error_parsing(this.pos, "unexpected string");
}
var token = new Token(TNUMBER, 0, 0, this.tokennumber);
tokenstack.push(token);
expected = (OPERATOR | RPAREN | COMMA);
}
else if (this.isLeftParenth()) {
if ((expected & LPAREN) === 0) {
this.error_parsing(this.pos, "unexpected \"(\"");
}
if (expected & CALL) {
noperators += 2;
this.tokenprio = -2;
this.tokenindex = -1;
this.addfunc(tokenstack, operstack, TFUNCALL);
}
expected = (PRIMARY | LPAREN | FUNCTION | SIGN | NULLARY_CALL);
}
else if (this.isRightParenth()) {
if (expected & NULLARY_CALL) {
var token = new Token(TNUMBER, 0, 0, []);
tokenstack.push(token);
}
else if ((expected & RPAREN) === 0) {
this.error_parsing(this.pos, "unexpected \")\"");
}
expected = (OPERATOR | RPAREN | COMMA | LPAREN | CALL);
}
else if (this.isComma()) {
if ((expected & COMMA) === 0) {
this.error_parsing(this.pos, "unexpected \",\"");
}
this.addfunc(tokenstack, operstack, TOP2);
noperators += 2;
expected = (PRIMARY | LPAREN | FUNCTION | SIGN);
}
else if (this.isConst()) {
if ((expected & PRIMARY) === 0) {
this.error_parsing(this.pos, "unexpected constant");
}
var consttoken = new Token(TNUMBER, 0, 0, this.tokennumber);
tokenstack.push(consttoken);
expected = (OPERATOR | RPAREN | COMMA);
}
else if (this.isOp2()) {
if ((expected & FUNCTION) === 0) {
this.error_parsing(this.pos, "unexpected function");
}
this.addfunc(tokenstack, operstack, TOP2);
noperators += 2;
expected = (LPAREN);
}
else if (this.isOp1()) {
if ((expected & FUNCTION) === 0) {
this.error_parsing(this.pos, "unexpected function");
}
this.addfunc(tokenstack, operstack, TOP1);
noperators++;
expected = (LPAREN);
}
else if (this.isVar()) {
if ((expected & PRIMARY) === 0) {
this.error_parsing(this.pos, "unexpected variable");
}
var vartoken = new Token(TVAR, this.tokenindex, 0, 0);
tokenstack.push(vartoken);
expected = (OPERATOR | RPAREN | COMMA | LPAREN | CALL);
}
else if (this.isWhite()) {
}
else {
if (this.errormsg === "") {
this.error_parsing(this.pos, "unknown character");
}
else {
this.error_parsing(this.pos, this.errormsg);
}
}
}
if (this.tmpprio < 0 || this.tmpprio >= 10) {
this.error_parsing(this.pos, "unmatched \"()\"");
}
while (operstack.length > 0) {
var tmp = operstack.pop();
tokenstack.push(tmp);
}
if (noperators + 1 !== tokenstack.length) {
//print(noperators + 1);
//print(tokenstack);
this.error_parsing(this.pos, "parity");
}
return new Expression(tokenstack, object(this.ops1), object(this.ops2), object(this.functions));
},
evaluate: function (expr, variables) {
return this.parse(expr).evaluate(variables);
},
error_parsing: function (column, msg) {
this.success = false;
this.errormsg = "parse error [column " + (column) + "]: " + msg;
throw new Error(this.errormsg);
},
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
addfunc: function (tokenstack, operstack, type_) {
var operator = new Token(type_, this.tokenindex, this.tokenprio + this.tmpprio, 0);
while (operstack.length > 0) {
if (operator.prio_ <= operstack[operstack.length - 1].prio_) {
tokenstack.push(operstack.pop());
}
else {
break;
}
}
operstack.push(operator);
},
isNumber: function () {
var r = false;
var str = "";
while (this.pos < this.expression.length) {
var code = this.expression.charCodeAt(this.pos);
if ((code >= 48 && code <= 57) || code === 46) {
str += this.expression.charAt(this.pos);
this.pos++;
this.tokennumber = parseFloat(str);
r = true;
}
else {
break;
}
}
return r;
},
// Ported from the yajjl JSON parser at http://code.google.com/p/yajjl/
unescape: function(v, pos) {
var buffer = [];
var escaping = false;
for (var i = 0; i < v.length; i++) {
var c = v.charAt(i);
if (escaping) {
switch (c) {
case "'":
buffer.push("'");
break;
case '\\':
buffer.push('\\');
break;
case '/':
buffer.push('/');
break;
case 'b':
buffer.push('\b');
break;
case 'f':
buffer.push('\f');
break;
case 'n':
buffer.push('\n');
break;
case 'r':
buffer.push('\r');
break;
case 't':
buffer.push('\t');
break;
case 'u':
// interpret the following 4 characters as the hex of the unicode code point
var codePoint = parseInt(v.substring(i + 1, i + 5), 16);
buffer.push(String.fromCharCode(codePoint));
i += 4;
break;
default:
throw this.error_parsing(pos + i, "Illegal escape sequence: '\\" + c + "'");
}
escaping = false;
} else {
if (c == '\\') {
escaping = true;
} else {
buffer.push(c);
}
}
}
return buffer.join('');
},
isString: function () {
var r = false;
var str = "";
var startpos = this.pos;
if (this.pos < this.expression.length && this.expression.charAt(this.pos) == "'") {
this.pos++;
while (this.pos < this.expression.length) {
var code = this.expression.charAt(this.pos);
if (code != "'" || str.slice(-1) == "\\") {
str += this.expression.charAt(this.pos);
this.pos++;
}
else {
this.pos++;
this.tokennumber = this.unescape(str, startpos);
r = true;
break;
}
}
}
return r;
},
isConst: function () {
var str;
for (var i in this.consts) {
if (true) {
var L = i.length;
str = this.expression.substr(this.pos, L);
if (i === str) {
this.tokennumber = this.consts[i];
this.pos += L;
return true;
}
}
}
return false;
},
isOperator: function () {
var code = this.expression.charCodeAt(this.pos);
if (code === 43) { // +
this.tokenprio = 0;
this.tokenindex = "+";
}
else if (code === 45) { // -
this.tokenprio = 0;
this.tokenindex = "-";
}
else if (code === 124) { // |
if (this.expression.charCodeAt(this.pos + 1) === 124) {
this.pos++;
this.tokenprio = 0;
this.tokenindex = "||";
}
else {
return false;
}
}
else if (code === 42) { // *
this.tokenprio = 1;
this.tokenindex = "*";
}
else if (code === 47) { // /
this.tokenprio = 2;
this.tokenindex = "/";
}
else if (code === 37) { // %
this.tokenprio = 2;
this.tokenindex = "%";
}
else if (code === 94) { // ^
this.tokenprio = 3;
this.tokenindex = "^";
}
else {
return false;
}
this.pos++;
return true;
},
isSign: function () {
var code = this.expression.charCodeAt(this.pos - 1);
if (code === 45 || code === 43) { // -
return true;
}
return false;
},
isPositiveSign: function () {
var code = this.expression.charCodeAt(this.pos - 1);
if (code === 43) { // -
return true;
}
return false;
},
isNegativeSign: function () {
var code = this.expression.charCodeAt(this.pos - 1);
if (code === 45) { // -
return true;
}
return false;
},
isLeftParenth: function () {
var code = this.expression.charCodeAt(this.pos);
if (code === 40) { // (
this.pos++;
this.tmpprio += 10;
return true;
}
return false;
},
isRightParenth: function () {
var code = this.expression.charCodeAt(this.pos);
if (code === 41) { // )
this.pos++;
this.tmpprio -= 10;
return true;
}
return false;
},
isComma: function () {
var code = this.expression.charCodeAt(this.pos);
if (code === 44) { // ,
this.pos++;
this.tokenprio = -1;
this.tokenindex = ",";
return true;
}
return false;
},
isWhite: function () {
var code = this.expression.charCodeAt(this.pos);
if (code === 32 || code === 9 || code === 10 || code === 13) {
this.pos++;
return true;
}
return false;
},
isOp1: function () {
var str = "";
for (var i = this.pos; i < this.expression.length; i++) {
var c = this.expression.charAt(i);
if (c.toUpperCase() === c.toLowerCase()) {
if (i === this.pos || (c != '_' && (c < '0' || c > '9'))) {
break;
}
}
str += c;
}
if (str.length > 0 && (str in this.ops1)) {
this.tokenindex = str;
this.tokenprio = 5;
this.pos += str.length;
return true;
}
return false;
},
isOp2: function () {
var str = "";
for (var i = this.pos; i < this.expression.length; i++) {
var c = this.expression.charAt(i);
if (c.toUpperCase() === c.toLowerCase()) {
if (i === this.pos || (c != '_' && (c < '0' || c > '9'))) {
break;
}
}
str += c;
}
if (str.length > 0 && (str in this.ops2)) {
this.tokenindex = str;
this.tokenprio = 5;
this.pos += str.length;
return true;
}
return false;
},
isVar: function () {
var str = "";
for (var i = this.pos; i < this.expression.length; i++) {
var c = this.expression.charAt(i);
if (c.toUpperCase() === c.toLowerCase()) {
if (i === this.pos || (c != '_' && (c < '0' || c > '9'))) {
break;
}
}
str += c;
}
if (str.length > 0) {
this.tokenindex = str;
this.tokenprio = 4;
this.pos += str.length;
return true;
}
return false;
},
isComment: function () {
var code = this.expression.charCodeAt(this.pos - 1);
if (code === 47 && this.expression.charCodeAt(this.pos) === 42) {
this.pos = this.expression.indexOf("*/", this.pos) + 2;
if (this.pos === 1) {
this.pos = this.expression.length;
}
return true;
}
return false;
}
};
return Parser;
});
},{}],77:[function(require,module,exports){
/**
* A very simple, ERB-style templating. Basically, just as string substitution.
* The reason to not use default Lo-dashes `_.template()` implementation
* is because it fails to run in CSP-enabled environments (Chrome extension, Atom)
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var stringStream = require('../assets/stringStream');
var utils = require('./common');
function parseArgs(str) {
var args = [];
var stream = stringStream(str);
while (!stream.eol()) {
if (stream.peek() == ',') {
args.push(utils.trim(stream.current()));
stream.next();
stream.start = stream.pos;
}
stream.next();
}
args.push(utils.trim(stream.current()));
return args.filter(function(a) {
return !!a;
});
}
function parseFunctionCall(str) {
var fnName = null, args;
var stream = stringStream(str);
while (!stream.eol()) {
if (stream.peek() == '(') {
fnName = stream.current();
stream.start = stream.pos;
stream.skipToPair('(', ')', true);
args = stream.current();
args = parseArgs(args.substring(1, args.length - 1));
break;
}
stream.next();
}
return fnName && {
name: fnName,
args: args
};
}
function evalArg(arg, context) {
if (/^['"]/.test(arg)) {
// plain string
return arg.replace(/^(['"])(.+?)\1$/, '$2');
}
if (!isNaN(+arg)) {
// a number
return +arg;
}
// otherwise, treat argument as a property name
if (arg) {
var parts = arg.split('.');
var prop = context;
while (parts.length) {
prop = prop[parts.shift()];
}
return prop;
}
}
function process(template, context) {
return template.replace(/<%[=\-](.+?)%>/g, function(str, match) {
match = utils.trim(match);
var fn = parseFunctionCall(match);
if (fn) {
var fnArgs = fn.args.map(function(arg) {
return evalArg(arg, context);
});
return context[fn.name].apply(context, fnArgs);
}
return evalArg(match, context);
});
}
return function(template, context) {
return context ? process(template, context) : function(context) {
return process(template, context);
};
};
});
},{"../assets/stringStream":32,"./common":73}],78:[function(require,module,exports){
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
var utils = require('../utils/common');
/**
* Shared empty constructor function to aid in prototype-chain creation.
*/
var ctor = function(){};
/**
* Helper function to correctly set up the prototype chain, for subclasses.
* Similar to `goog.inherits`, but uses a hash of prototype properties and
* class properties to be extended.
* Took it from Backbone.
* @param {Object} parent
* @param {Object} protoProps
* @param {Object} staticProps
* @returns {Object}
*/
function inherits(parent, protoProps, staticProps) {
var child;
// The constructor function for the new subclass is either defined by
// you (the "constructor" property in your `extend` definition), or
// defaulted by us to simply call the parent's constructor.
if (protoProps && protoProps.hasOwnProperty('constructor')) {
child = protoProps.constructor;
} else {
child = function() {
parent.apply(this, arguments);
};
}
// Inherit class (static) properties from parent.
utils.extend(child, parent);
// Set the prototype chain to inherit from `parent`, without calling
// `parent`'s constructor function.
ctor.prototype = parent.prototype;
child.prototype = new ctor();
// Add prototype properties (instance properties) to the subclass,
// if supplied.
if (protoProps)
utils.extend(child.prototype, protoProps);
// Add static properties to the constructor function, if supplied.
if (staticProps)
utils.extend(child, staticProps);
// Correctly set child's `prototype.constructor`.
child.prototype.constructor = child;
// Set a convenience property in case the parent's prototype is needed
// later.
child.__super__ = parent.prototype;
return child;
}
return {
/**
* The self-propagating extend function for classes.
* Took it from Backbone
* @param {Object} protoProps
* @param {Object} classProps
* @returns {Object}
*/
extend: function(protoProps, classProps) {
var child = inherits(this, protoProps, classProps);
child.extend = this.extend;
// a hack required to WSH inherit `toString` method
if (protoProps.hasOwnProperty('toString'))
child.prototype.toString = protoProps.toString;
return child;
}
};
});
},{"../utils/common":73}],79:[function(require,module,exports){
/*!
* string_score.js: String Scoring Algorithm 0.1.10
*
* http://joshaven.com/string_score
* https://github.com/joshaven/string_score
*
* Copyright (C) 2009-2011 Joshaven Potter <yourtech@gmail.com>
* Special thanks to all of the contributors listed here https://github.com/joshaven/string_score
* MIT license: http://www.opensource.org/licenses/mit-license.php
*
* Date: Tue Mar 1 2011
*/
/**
* Scores a string against another string.
* 'Hello World'.score('he'); //=> 0.5931818181818181
* 'Hello World'.score('Hello'); //=> 0.7318181818181818
*/
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function(require, exports, module) {
return {
score: function(string, abbreviation, fuzziness) {
// If the string is equal to the abbreviation, perfect match.
if (string == abbreviation) {return 1;}
//if it's not a perfect match and is empty return 0
if(abbreviation == "") {return 0;}
var total_character_score = 0,
abbreviation_length = abbreviation.length,
string_length = string.length,
start_of_string_bonus,
abbreviation_score,
fuzzies=1,
final_score;
// Walk through abbreviation and add up scores.
for (var i = 0,
character_score/* = 0*/,
index_in_string/* = 0*/,
c/* = ''*/,
index_c_lowercase/* = 0*/,
index_c_uppercase/* = 0*/,
min_index/* = 0*/;
i < abbreviation_length;
++i) {
// Find the first case-insensitive match of a character.
c = abbreviation.charAt(i);
index_c_lowercase = string.indexOf(c.toLowerCase());
index_c_uppercase = string.indexOf(c.toUpperCase());
min_index = Math.min(index_c_lowercase, index_c_uppercase);
index_in_string = (min_index > -1) ? min_index : Math.max(index_c_lowercase, index_c_uppercase);
if (index_in_string === -1) {
if (fuzziness) {
fuzzies += 1-fuzziness;
continue;
} else {
return 0;
}
} else {
character_score = 0.1;
}
// Set base score for matching 'c'.
// Same case bonus.
if (string[index_in_string] === c) {
character_score += 0.1;
}
// Consecutive letter & start-of-string Bonus
if (index_in_string === 0) {
// Increase the score when matching first character of the remainder of the string
character_score += 0.6;
if (i === 0) {
// If match is the first character of the string
// & the first character of abbreviation, add a
// start-of-string match bonus.
start_of_string_bonus = 1; //true;
}
}
else {
// Acronym Bonus
// Weighing Logic: Typing the first character of an acronym is as if you
// preceded it with two perfect character matches.
if (string.charAt(index_in_string - 1) === ' ') {
character_score += 0.8; // * Math.min(index_in_string, 5); // Cap bonus at 0.4 * 5
}
}
// Left trim the already matched part of the string
// (forces sequential matching).
string = string.substring(index_in_string + 1, string_length);
total_character_score += character_score;
} // end of for loop
// Uncomment to weigh smaller words higher.
// return total_character_score / string_length;
abbreviation_score = total_character_score / abbreviation_length;
//percentage_of_matched_string = abbreviation_length / string_length;
//word_score = abbreviation_score * percentage_of_matched_string;
// Reduce penalty for longer strings.
//final_score = (word_score + abbreviation_score) / 2;
final_score = ((abbreviation_score * (abbreviation_length / string_length)) + abbreviation_score) / 2;
final_score = final_score / fuzzies;
if (start_of_string_bonus && (final_score + 0.15 < 1)) {
final_score += 0.15;
}
return final_score;
}
};
});
},{}],80:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
/**
* Setup Emmet on given CodeMirror editor instance
* @param {CodeMirror} cm
* @param {Object} keymap
*/
module.exports = main;
/**
* Emmet plugin for CodeMirror
*/
var EmmetEditor = _interopRequire(require("./editor"));
var emmet = _interopRequire(require("./emmet"));
var defaultKeymap = {
"Cmd-E": "emmet.expand_abbreviation",
Tab: "emmet.expand_abbreviation_with_tab",
"Cmd-D": "emmet.balance_outward",
"Shift-Cmd-D": "emmet.balance_inward",
"Cmd-M": "emmet.matching_pair",
"Shift-Cmd-A": "emmet.wrap_with_abbreviation",
"Ctrl-Alt-Right": "emmet.next_edit_point",
"Ctrl-Alt-Left": "emmet.prev_edit_point",
"Cmd-L": "emmet.select_line",
"Cmd-Shift-M": "emmet.merge_lines",
"Cmd-/": "emmet.toggle_comment",
"Cmd-J": "emmet.split_join_tag",
"Cmd-K": "emmet.remove_tag",
"Shift-Cmd-Y": "emmet.evaluate_math_expression",
"Ctrl-Up": "emmet.increment_number_by_1",
"Ctrl-Down": "emmet.decrement_number_by_1",
"Ctrl-Alt-Up": "emmet.increment_number_by_01",
"Ctrl-Alt-Down": "emmet.decrement_number_by_01",
"Shift-Ctrl-Up": "emmet.increment_number_by_10",
"Shift-Ctrl-Down": "emmet.decrement_number_by_10",
"Shift-Cmd-.": "emmet.select_next_item",
"Shift-Cmd-,": "emmet.select_previous_item",
"Cmd-B": "emmet.reflect_css_value",
Enter: "emmet.insert_formatted_line_break_only"
};
// actions that should be performed in single selection mode
var singleSelectionActions = ["prev_edit_point", "next_edit_point", "merge_lines", "reflect_css_value", "select_next_item", "select_previous_item", "wrap_with_abbreviation", "update_tag", "insert_formatted_line_break_only"];
function main(cm) {
var keymap = arguments[1] === undefined ? defaultKeymap : arguments[1];
keymap = systemKeymap(keymap);
cm.__emmetKeymap = keymap;
cm.addKeyMap(keymap);
return cm;
}
main.dispose = function (cm) {
if (cm.__emmetKeymap) {
cm.removeKeyMap(cm.__emmetKeymap);
delete cm.__emmetKeymap;
}
};
main.defaultKeymap = defaultKeymap;
main.systemKeymap = systemKeymap;
main.emmet = emmet;
main.EmmetEditor = EmmetEditor;
main.setup = function (CodeMirror) {
// setup default Emmet actions
emmet.actions.getList().forEach(function (obj) {
var action = obj.name;
var command = "emmet." + action;
if (!CodeMirror.commands[command]) {
CodeMirror.commands[command] = ~singleSelectionActions.indexOf(action) ? actionDecorator(action) : multiSelectionActionDecorator(action);
}
});
// add “profile” property to CodeMirror defaults so in wont be lost
// then CM instance is instantiated with “profile” property
if (CodeMirror.defineOption) {
CodeMirror.defineOption("profile", "html");
} else {
CodeMirror.defaults.profile = "html";
}
};
if (typeof CodeMirror !== "undefined") {
main.setup(CodeMirror);
}
function noop() {
if (CodeMirror.version >= "3.1") {
return CodeMirror.Pass;
}
throw CodeMirror.Pass;
}
/**
* Emmet action decorator: creates a command function
* for CodeMirror and executes Emmet action as single
* undo command
* @param {String} name Action name
* @return {Function}
*/
function actionDecorator(name) {
return function (cm) {
var result;
cm.operation(function () {
return result = runAction(name, new EmmetEditor(cm));
});
return result;
};
}
/**
* Same as `actionDecorator()` but executes action
* with multiple selections
* @param {String} name Action name
* @return {Function}
*/
function multiSelectionActionDecorator(name) {
return function (cm) {
var editor = new EmmetEditor(cm);
var selections = editor.selectionList();
var result = null;
cm.operation(function () {
for (var i = 0, il = selections.length; i < il; i++) {
editor.selectionIndex = i;
result = runAction(name, editor);
if (result === CodeMirror.Pass) {
break;
}
}
});
return result;
};
}
/**
* Runs Emmet action
* @param {String} name Action name
* @param {EmmetEditor} editor EmmetEditor instance
* @return {Boolean} Returns `true` if action is performed
* successfully
*/
function runAction(name, editor) {
if (name == "expand_abbreviation_with_tab" && (editor.context.somethingSelected() || !editor.isValidSyntax())) {
// pass through Tab key handler if there's a selection
return noop();
}
var result = false;
try {
result = emmet.run(name, editor);
if (!result && name == "insert_formatted_line_break_only") {
return noop();
}
} catch (e) {
console.error(e);
}
return result;
}
function systemKeymap(keymap) {
var mac = /Mac/.test(navigator.platform);
var out = {};
Object.keys(keymap).forEach(function (key) {
return out[!mac ? key.replace("Cmd", "Ctrl") : key] = keymap[key];
});
return out;
}
},{"./editor":1,"./emmet":2}]},{},[80])(80)
});
/*
Based on Joel Besada's lovely experiment
https://twitter.com/JoelBesada/status/670343885655293952
*/
;(function () {
var shakeTime = 0,
shakeTimeMax = 0,
shakeIntensity = 5,
lastTime = 0,
particles = [],
particlePointer = 0,
MAX_PARTICLES = 100,
PARTICLE_NUM_RANGE = { min: 2, max: 7 },
PARTICLE_GRAVITY = 0.08,
PARTICLE_ALPHA_FADEOUT = 0.96,
PARTICLE_VELOCITY_RANGE = {
x: [-1, 1],
y: [-3.5, -1.5]
},
w = window.innerWidth,
h = window.innerHeight,
effect,
isActive = false;
var codemirrors = [], cmNode;
var canvas, ctx;
var current_time, dt, magnitude, shakeX, shakeY; // loop vars
var throttledShake = throttle(shake, 100);
var throttledSpawnParticles = throttle(spawnParticles, 100);
function getRGBComponents(node) {
var color = getComputedStyle(node).color;
if (color) {
try {
return color.match(/(\d+), (\d+), (\d+)/).slice(1);
} catch(e) {
return [255, 255, 255];
}
} else {
return [255, 255, 255];
}
}
function spawnParticles(cm, type) {
var cursorPos = cm.getCursor();
var pos = cm.cursorCoords();
var node = document.elementFromPoint(pos.left - 5, pos.top + 5);
type = cm.getTokenAt(cursorPos);
if (type) { type = type.type; };
var numParticles = random(PARTICLE_NUM_RANGE.min, PARTICLE_NUM_RANGE.max);
var color = getRGBComponents(node);
for (var i = numParticles; i--;) {
particles[particlePointer] = createParticle(pos.left + 10, pos.top, color);
particlePointer = (particlePointer + 1) % MAX_PARTICLES;
}
}
function createParticle(x, y, color) {
var p = {
x: x,
y: y + 10,
alpha: 1,
color: color
};
if (effect === 1) {
p.size = random(2, 4);
p.vx = PARTICLE_VELOCITY_RANGE.x[0] + Math.random() *
(PARTICLE_VELOCITY_RANGE.x[1] - PARTICLE_VELOCITY_RANGE.x[0]);
p.vy = PARTICLE_VELOCITY_RANGE.y[0] + Math.random() *
(PARTICLE_VELOCITY_RANGE.y[1] - PARTICLE_VELOCITY_RANGE.y[0]);
} else if (effect === 2) {
p.size = random(2, 8);
p.drag = 0.92;
p.vx = random(-3, 3);
p.vy = random(-3, 3);
p.wander = 0.15;
p.theta = random(0, 360) * Math.PI / 180;
}
return p;
}
function effect1(particle) {
particle.vy += PARTICLE_GRAVITY;
particle.x += particle.vx;
particle.y += particle.vy;
particle.alpha *= PARTICLE_ALPHA_FADEOUT;
ctx.fillStyle = 'rgba('+ particle.color[0] +','+ particle.color[1] +','+ particle.color[2] + ',' + particle.alpha + ')';
ctx.fillRect(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, particle.size);
}
// Effect based on Soulwire's demo: http://codepen.io/soulwire/pen/foktm
function effect2(particle) {
particle.x += particle.vx;
particle.y += particle.vy;
particle.vx *= particle.drag;
particle.vy *= particle.drag;
particle.theta += random( -0.5, 0.5 );
particle.vx += Math.sin( particle.theta ) * 0.1;
particle.vy += Math.cos( particle.theta ) * 0.1;
particle.size *= 0.96;
ctx.fillStyle = 'rgba('+ particle.color[0] +','+ particle.color[1] +','+ particle.color[2] + ',' + particle.alpha + ')';
ctx.beginPath();
ctx.arc(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, 0, 2 * Math.PI);
ctx.fill();
}
function drawParticles(timeDelta) {
var particle;
for (var i = particles.length; i--;) {
particle = particles[i];
if (!particle || particle.alpha < 0.01 || particle.size <= 0.5) { continue; }
if (effect === 1) { effect1(particle); }
else if (effect === 2) { effect2(particle); }
}
}
function shake(editor, time) {
cmNode = editor.getWrapperElement();
shakeTime = shakeTimeMax = time;
}
function random(min, max) {
if (!max) { max = min; min = 0; }
return min + ~~(Math.random() * (max - min + 1))
}
function throttle (callback, limit) {
var wait = false;
return function () {
if (!wait) {
callback.apply(this, arguments);
wait = true;
setTimeout(function () {
wait = false;
}, limit);
}
}
}
function loop() {
if (!isActive) { return; }
ctx.clearRect(0, 0, w, h);
// get the time past the previous frame
current_time = new Date().getTime();
if(!lastTime) lastTime = current_time;
dt = (current_time - lastTime) / 1000;
lastTime = current_time;
if (shakeTime > 0) {
shakeTime -= dt;
magnitude = (shakeTime / shakeTimeMax) * shakeIntensity;
shakeX = random(-magnitude, magnitude);
shakeY = random(-magnitude, magnitude);
cmNode.style.transform = 'translate(' + shakeX + 'px,' + shakeY + 'px)';
}
drawParticles();
requestAnimationFrame(loop);
}
function onCodeMirrorChange(editor, change) {
if (change.origin !== '+input' && change.origin !== '+delete') { return; }
if (editor.getOption('blastCode') === true || editor.getOption('blastCode').shake === undefined) {
throttledShake(editor, 0.3);
}
throttledSpawnParticles(editor);
}
function init(editor) {
isActive = true;
if (!canvas) {
canvas = document.createElement('canvas');
ctx = canvas.getContext('2d'),
canvas.id = 'code-blast-canvas'
canvas.style.position = 'absolute';
canvas.style.top = 0;
canvas.style.left = 0;
canvas.style.zIndex = 1;
canvas.style.pointerEvents = 'none';
canvas.width = w;
canvas.height = h;
document.body.appendChild(canvas);
loop();
}
editor.on("change", onCodeMirrorChange);
}
function destroy(editor) {
editor.off('change', onCodeMirrorChange);
codemirrors.splice(codemirrors.indexOf(editor), 1);
if (!codemirrors.length) {
isActive = false;
if (canvas) {
canvas.remove();
canvas = null;
}
}
}
CodeMirror.defineOption('blastCode', false, function(editor, val, old) {
if (val) {
codemirrors.push(editor);
effect = val.effect || 2;
init(editor);
} else {
destroy(editor);
}
});
})();
// The programming goals of Split.js are to deliver readable, understandable and
// maintainable code, while at the same time manually optimizing for tiny minified file size,
// browser compatibility without additional requirements, graceful fallback (IE8 is supported)
// and very few assumptions about the user's page layout.
//
// Make sure all browsers handle this JS library correctly with ES5.
// More information here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
'use strict';
// A wrapper function that does a couple things:
//
// 1. Doesn't pollute the global namespace. This is important for a library.
// 2. Allows us to mount the library in different module systems, as well as
// directly in the browser.
(function() {
// Save the global `this` for use later. In this case, since the library only
// runs in the browser, it will refer to `window`. Also, figure out if we're in IE8
// or not. IE8 will still render correctly, but will be static instead of draggable.
//
// Save a couple long function names that are used frequently.
// This optimization saves around 400 bytes.
var global = this
, isIE8 = global.attachEvent && !global[addEventListener]
, document = global.document
, addEventListener = 'addEventListener'
, removeEventListener = 'removeEventListener'
, getBoundingClientRect = 'getBoundingClientRect'
// This library only needs two helper functions:
//
// The first determines which prefixes of CSS calc we need.
// We only need to do this once on startup, when this anonymous function is called.
//
// Tests -webkit, -moz and -o prefixes. Modified from StackOverflow:
// http://stackoverflow.com/questions/16625140/js-feature-detection-to-detect-the-usage-of-webkit-calc-over-calc/16625167#16625167
, calc = (function () {
var el
, prefixes = ["", "-webkit-", "-moz-", "-o-"]
for (var i = 0; i < prefixes.length; i++) {
el = document.createElement('div')
el.style.cssText = "width:" + prefixes[i] + "calc(9px)"
if (el.style.length) {
return prefixes[i] + "calc"
}
}
})()
// The second helper function allows elements and string selectors to be used
// interchangeably. In either case an element is returned. This allows us to
// do `Split(elem1, elem2)` as well as `Split('#id1', '#id2')`.
, elementOrSelector = function (el) {
if (typeof el === 'string' || el instanceof String) {
return document.querySelector(el)
} else {
return el
}
}
// The main function to initialize a split. Split.js thinks about each pair
// of elements as an independant pair. Dragging the gutter between two elements
// only changes the dimensions of elements in that pair. This is key to understanding
// how the following functions operate, since each function is bound to a pair.
//
// A pair object is shaped like this:
//
// {
// a: DOM element,
// b: DOM element,
// aMin: Number,
// bMin: Number,
// dragging: Boolean,
// parent: DOM element,
// isFirst: Boolean,
// isLast: Boolean,
// direction: 'horizontal' | 'vertical'
// }
//
// The basic sequence:
//
// 1. Set defaults to something sane. `options` doesn't have to be passed at all.
// 2. Initialize a bunch of strings based on the direction we're splitting.
// A lot of the behavior in the rest of the library is paramatized down to
// rely on CSS strings and classes.
// 3. Define the dragging helper functions, and a few helpers to go with them.
// 4. Define a few more functions that "balance" the entire split instance.
// Split.js tries it's best to cope with min sizes that don't add up.
// 5. Loop through the elements while pairing them off. Every pair gets an
// `pair` object, a gutter, and special isFirst/isLast properties.
// 6. Actually size the pair elements, insert gutters and attach event listeners.
// 7. Balance all of the pairs to accomodate min sizes as best as possible.
, Split = function (ids, options) {
var dimension
, i
, clientDimension
, clientAxis
, position
, gutterClass
, paddingA
, paddingB
, pairs = []
// 1. Set defaults to something sane. `options` doesn't have to be passed at all,
// so create an options object if none exists. Pixel values 10, 100 and 30 are
// arbitrary but feel natural.
options = typeof options !== 'undefined' ? options : {}
if (typeof options.gutterSize === 'undefined') options.gutterSize = 10
if (typeof options.minSize === 'undefined') options.minSize = 100
if (typeof options.snapOffset === 'undefined') options.snapOffset = 30
if (typeof options.direction === 'undefined') options.direction = 'horizontal'
// 2. Initialize a bunch of strings based on the direction we're splitting.
// A lot of the behavior in the rest of the library is paramatized down to
// rely on CSS strings and classes.
if (options.direction == 'horizontal') {
dimension = 'width'
clientDimension = 'clientWidth'
clientAxis = 'clientX'
position = 'left'
gutterClass = 'gutter gutter-horizontal'
paddingA = 'paddingLeft'
paddingB = 'paddingRight'
if (!options.cursor) options.cursor = 'ew-resize'
} else if (options.direction == 'vertical') {
dimension = 'height'
clientDimension = 'clientHeight'
clientAxis = 'clientY'
position = 'top'
gutterClass = 'gutter gutter-vertical'
paddingA = 'paddingTop'
paddingB = 'paddingBottom'
if (!options.cursor) options.cursor = 'ns-resize'
}
// 3. Define the dragging helper functions, and a few helpers to go with them.
// Each helper is bound to a pair object that contains it's metadata. This
// also makes it easy to store references to listeners that that will be
// added and removed.
//
// Even though there are no other functions contained in them, aliasing
// this to self saves 50 bytes or so since it's used so frequently.
//
// The pair object saves metadata like dragging state, position and
// event listener references.
//
// startDragging calls `calculateSizes` to store the inital size in the pair object.
// It also adds event listeners for mouse/touch events,
// and prevents selection while dragging so avoid the selecting text.
var startDragging = function (e) {
// Alias frequently used variables to save space. 200 bytes.
var self = this
, a = self.a
, b = self.b
// Call the onDragStart callback.
if (!self.dragging && options.onDragStart) {
options.onDragStart()
}
// Don't actually drag the element. We emulate that in the drag function.
e.preventDefault()
// Set the dragging property of the pair object.
self.dragging = true
// Create two event listeners bound to the same pair object and store
// them in the pair object.
self.move = drag.bind(self)
self.stop = stopDragging.bind(self)
// All the binding. `window` gets the stop events in case we drag out of the elements.
global[addEventListener]('mouseup', self.stop)
global[addEventListener]('touchend', self.stop)
global[addEventListener]('touchcancel', self.stop)
self.parent[addEventListener]('mousemove', self.move)
self.parent[addEventListener]('touchmove', self.move)
// Disable selection. Disable!
a[addEventListener]('selectstart', noop)
a[addEventListener]('dragstart', noop)
b[addEventListener]('selectstart', noop)
b[addEventListener]('dragstart', noop)
a.style.userSelect = 'none'
a.style.webkitUserSelect = 'none'
a.style.MozUserSelect = 'none'
a.style.pointerEvents = 'none'
b.style.userSelect = 'none'
b.style.webkitUserSelect = 'none'
b.style.MozUserSelect = 'none'
b.style.pointerEvents = 'none'
// Set the cursor, both on the gutter and the parent element.
// Doing only a, b and gutter causes flickering.
self.gutter.style.cursor = options.cursor
self.parent.style.cursor = options.cursor
// Cache the initial sizes of the pair.
calculateSizes.call(self)
}
// stopDragging is very similar to startDragging in reverse.
, stopDragging = function () {
var self = this
, a = self.a
, b = self.b
if (self.dragging && options.onDragEnd) {
options.onDragEnd()
}
self.dragging = false
// Remove the stored event listeners. This is why we store them.
global[removeEventListener]('mouseup', self.stop)
global[removeEventListener]('touchend', self.stop)
global[removeEventListener]('touchcancel', self.stop)
self.parent[removeEventListener]('mousemove', self.move)
self.parent[removeEventListener]('touchmove', self.move)
// Delete them once they are removed. I think this makes a difference
// in memory usage with a lot of splits on one page. But I don't know for sure.
delete self.stop
delete self.move
a[removeEventListener]('selectstart', noop)
a[removeEventListener]('dragstart', noop)
b[removeEventListener]('selectstart', noop)
b[removeEventListener]('dragstart', noop)
a.style.userSelect = ''
a.style.webkitUserSelect = ''
a.style.MozUserSelect = ''
a.style.pointerEvents = ''
b.style.userSelect = ''
b.style.webkitUserSelect = ''
b.style.MozUserSelect = ''
b.style.pointerEvents = ''
self.gutter.style.cursor = ''
self.parent.style.cursor = ''
}
// drag, where all the magic happens. The logic is really quite simple:
//
// 1. Ignore if the pair is not dragging.
// 2. Get the offset of the event.
// 3. Snap offset to min if within snappable range (within min + snapOffset).
// 4. Actually adjust each element in the pair to offset.
//
// ---------------------------------------------------------------------
// | | <- this.aMin || this.bMin -> | |
// | | | <- this.snapOffset || this.snapOffset -> | | |
// | | | || | | |
// | | | || | | |
// ---------------------------------------------------------------------
// | <- this.start this.size -> |
, drag = function (e) {
var offset
if (!this.dragging) return
// Get the offset of the event from the first side of the
// pair `this.start`. Supports touch events, but not multitouch, so only the first
// finger `touches[0]` is counted.
if ('touches' in e) {
offset = e.touches[0][clientAxis] - this.start
} else {
offset = e[clientAxis] - this.start
}
// If within snapOffset of min or max, set offset to min or max.
// snapOffset buffers aMin and bMin, so logic is opposite for both.
// Include the appropriate gutter sizes to prevent overflows.
if (offset <= this.aMin + options.snapOffset + this.aGutterSize) {
offset = this.aMin + this.aGutterSize
} else if (offset >= this.size - (this.bMin + options.snapOffset + this.bGutterSize)) {
offset = this.size - (this.bMin + this.bGutterSize)
}
// Actually adjust the size.
adjust.call(this, offset)
// Call the drag callback continously. Don't do anything too intensive
// in this callback.
if (options.onDrag) {
options.onDrag()
}
}
// Cache some important sizes when drag starts, so we don't have to do that
// continously:
//
// `size`: The total size of the pair. First element + second element + first gutter + second gutter.
// `percentage`: The percentage between 0-100 that the pair occupies in the parent.
// `start`: The leading side of the first element.
//
// ------------------------------------------------ - - - - - - - - - - -
// | aGutterSize -> ||| | |
// | ||| | |
// | ||| | |
// | ||| <- bGutterSize | |
// ------------------------------------------------ - - - - - - - - - - -
// | <- start size -> | parentSize -> |
, calculateSizes = function () {
// Figure out the parent size minus padding.
var computedStyle = global.getComputedStyle(this.parent)
, parentSize = this.parent[clientDimension] - parseFloat(computedStyle[paddingA]) - parseFloat(computedStyle[paddingB])
this.size = this.a[getBoundingClientRect]()[dimension] + this.b[getBoundingClientRect]()[dimension] + this.aGutterSize + this.bGutterSize
this.percentage = Math.min(this.size / parentSize * 100, 100)
this.start = this.a[getBoundingClientRect]()[position]
}
// Actually adjust the size of elements `a` and `b` to `offset` while dragging.
// calc is used to allow calc(percentage + gutterpx) on the whole split instance,
// which allows the viewport to be resized without additional logic.
// Element a's size is the same as offset. b's size is total size - a size.
// Both sizes are calculated from the initial parent percentage, then the gutter size is subtracted.
, adjust = function (offset) {
this.a.style[dimension] = calc + '(' + (offset / this.size * this.percentage) + '% - ' + this.aGutterSize + 'px)'
this.b.style[dimension] = calc + '(' + (this.percentage - (offset / this.size * this.percentage)) + '% - ' + this.bGutterSize + 'px)'
}
// 4. Define a few more functions that "balance" the entire split instance.
// Split.js tries it's best to cope with min sizes that don't add up.
// At some point this should go away since it breaks out of the calc(% - px) model.
// Maybe it's a user error if you pass uncomputable minSizes.
, fitMin = function () {
var self = this
, a = self.a
, b = self.b
if (a[getBoundingClientRect]()[dimension] < self.aMin) {
a.style[dimension] = (self.aMin - self.aGutterSize) + 'px'
b.style[dimension] = (self.size - self.aMin - self.aGutterSize) + 'px'
} else if (b[getBoundingClientRect]()[dimension] < self.bMin) {
a.style[dimension] = (self.size - self.bMin - self.bGutterSize) + 'px'
b.style[dimension] = (self.bMin - self.bGutterSize) + 'px'
}
}
, fitMinReverse = function () {
var self = this
, a = self.a
, b = self.b
if (b[getBoundingClientRect]()[dimension] < self.bMin) {
a.style[dimension] = (self.size - self.bMin - self.bGutterSize) + 'px'
b.style[dimension] = (self.bMin - self.bGutterSize) + 'px'
} else if (a[getBoundingClientRect]()[dimension] < self.aMin) {
a.style[dimension] = (self.aMin - self.aGutterSize) + 'px'
b.style[dimension] = (self.size - self.aMin - self.aGutterSize) + 'px'
}
}
, balancePairs = function (pairs) {
for (var i = 0; i < pairs.length; i++) {
calculateSizes.call(pairs[i])
fitMin.call(pairs[i])
}
for (i = pairs.length - 1; i >= 0; i--) {
calculateSizes.call(pairs[i])
fitMinReverse.call(pairs[i])
}
}
, setElementSize = function (el, size, gutterSize) {
// Split.js allows setting sizes via numbers (ideally), or if you must,
// by string, like '300px'. This is less than ideal, because it breaks
// the fluid layout that `calc(% - px)` provides. You're on your own if you do that,
// make sure you calculate the gutter size by hand.
if (typeof size !== 'string' && !(size instanceof String)) {
if (!isIE8) {
size = calc + '(' + size + '% - ' + gutterSize + 'px)'
} else {
size = options.sizes[i] + '%'
}
}
el.style[dimension] = size
}
// No-op function to prevent default. Used to prevent selection.
, noop = function () { return false }
// All DOM elements in the split should have a common parent. We can grab
// the first elements parent and hope users read the docs because the
// behavior will be whacky otherwise.
, parent = elementOrSelector(ids[0]).parentNode
// Set default options.sizes to equal percentages of the parent element.
if (!options.sizes) {
var percent = 100 / ids.length
options.sizes = []
for (i = 0; i < ids.length; i++) {
options.sizes.push(percent)
}
}
// Standardize minSize to an array if it isn't already. This allows minSize
// to be passed as a number.
if (!Array.isArray(options.minSize)) {
var minSizes = []
for (i = 0; i < ids.length; i++) {
minSizes.push(options.minSize)
}
options.minSize = minSizes
}
// 5. Loop through the elements while pairing them off. Every pair gets a
// `pair` object, a gutter, and isFirst/isLast properties.
//
// Basic logic:
//
// - Starting with the second element `i > 0`, create `pair` objects with
// `a = ids[i - 1]` and `b = ids[i]`
// - Set gutter sizes based on the _pair_ being first/last. The first and last
// pair have gutterSize / 2, since they only have one half gutter, and not two.
// - Create gutter elements and add event listeners.
// - Set the size of the elements, minus the gutter sizes.
//
// -----------------------------------------------------------------------
// | i=0 | i=1 | i=2 | i=3 |
// | | isFirst | | isLast |
// | pair 0 pair 1 pair 2 |
// | | | | |
// -----------------------------------------------------------------------
for (i = 0; i < ids.length; i++) {
var el = elementOrSelector(ids[i])
, isFirstPair = (i == 1)
, isLastPair = (i == ids.length - 1)
, size = options.sizes[i]
, gutterSize = options.gutterSize
, pair
, parentFlexDirection = window.getComputedStyle(parent).flexDirection
, temp
if (i > 0) {
// Create the pair object with it's metadata.
pair = {
a: elementOrSelector(ids[i - 1]),
b: el,
aMin: options.minSize[i - 1],
bMin: options.minSize[i],
dragging: false,
parent: parent,
isFirst: isFirstPair,
isLast: isLastPair,
direction: options.direction
}
// For first and last pairs, first and last gutter width is half.
pair.aGutterSize = options.gutterSize
pair.bGutterSize = options.gutterSize
if (isFirstPair) {
pair.aGutterSize = options.gutterSize / 2
}
if (isLastPair) {
pair.bGutterSize = options.gutterSize / 2
}
// if the parent has a reverse flex-direction, switch the pair elements.
if (parentFlexDirection === 'row-reverse' || parentFlexDirection === 'column-reverse') {
temp = pair.a;
pair.a = pair.b;
pair.b = temp;
}
}
// Determine the size of the current element. IE8 is supported by
// staticly assigning sizes without draggable gutters. Assigns a string
// to `size`.
//
// IE9 and above
if (!isIE8) {
// Create gutter elements for each pair.
if (i > 0) {
var gutter = document.createElement('div')
gutter.className = gutterClass
gutter.style[dimension] = options.gutterSize + 'px'
gutter[addEventListener]('mousedown', startDragging.bind(pair))
gutter[addEventListener]('touchstart', startDragging.bind(pair))
parent.insertBefore(gutter, el)
pair.gutter = gutter
}
// Half-size gutters for first and last elements.
if (i === 0 || i == ids.length - 1) {
gutterSize = options.gutterSize / 2
}
}
// Set the element size to our determined size.
setElementSize(el, size, gutterSize)
// After the first iteration, and we have a pair object, append it to the
// list of pairs.
if (i > 0) {
pairs.push(pair)
}
}
// Balance the pairs to try to accomodate min sizes.
balancePairs(pairs)
return {
setSizes: function (sizes) {
for (var i = 0; i < sizes.length; i++) {
if (i > 0) {
var pair = pairs[i - 1]
setElementSize(pair.a, sizes[i - 1], pair.aGutterSize)
setElementSize(pair.b, sizes[i], pair.bGutterSize)
}
}
},
collapse: function (i) {
var pair
if (i === pairs.length) {
pair = pairs[i - 1]
calculateSizes.call(pair)
adjust.call(pair, pair.size - Math.max(pair.bGutterSize, pair.aMin))
} else {
pair = pairs[i]
calculateSizes.call(pair)
adjust.call(pair, Math.max(pair.aGutterSize, pair.aMin))
}
},
destroy: function () {
for (var i = 0; i < pairs.length; i++) {
pairs[i].parent.removeChild(pairs[i].gutter)
pairs[i].a.style[dimension] = ''
pairs[i].b.style[dimension] = ''
}
}
}
}
// Play nicely with module systems, and the browser too if you include it raw.
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = Split
}
exports.Split = Split
} else {
global.Split = Split
}
// Call our wrapper function with the current global. In this case, `window`.
}).call(window);
// Generated by CoffeeScript 1.12.7
((function(){var a,b,c,d,e,f,g,h,i,j,k,l,m=[].slice;g=function(a,b,c){return c=c<0?c+1:c>1?c-1:c,c*6<1?a+(b-a)*c*6:c*2<1?b:c*3<2?a+(b-a)*(.66666-c)*6:a},f=function(a,b,c){var d,e;return e=c<=.5?c*(b+1):c+b-c*b,d=c*2-e,{r:g(d,e,a+.33333),g:g(d,e,a),b:g(d,e,a-.33333)}},k=function(a,b,c){var d,e,f,g,h,i,j;return g=Math.max(a,b,c),h=Math.min(a,b,c),d=g-h,j=g+h,e=h===g?0:a===g?(60*(b-c)/d+360)%360:b===g?60*(c-a)/d+120:60*(a-b)/d+240,f=j/2,i=f===0?0:f===1?1:f<=.5?d/j:d/(2-j),{h:e,s:i,l:f}},e=function(a,b,c,e){return e!=null?"hsla("+d(Math.round(a*180/Math.PI),360)+","+Math.round(b*100)+"%,"+Math.round(c*100)+"%,"+e+")":"hsl("+d(Math.round(a*180/Math.PI),360)+","+Math.round(b*100)+"%,"+Math.round(c*100)+"%)"},c=function(a){var b,c,d,e,f,g;return g=document.createElement("span"),document.body.appendChild(g),g.style.backgroundColor=a,f=getComputedStyle(g).backgroundColor,document.body.removeChild(g),d=/^rgb\((\d+), (\d+), (\d+)\)$/.exec(f),d||(d=/^rgba\((\d+), (\d+), (\d+), ([\d.]+)\)$/.exec(f)),e=parseInt(d[1]),c=parseInt(d[2]),b=parseInt(d[3]),d[4]?{r:e/255,g:c/255,b:b/255,a:parseFloat(d[4])}:{r:e/255,g:c/255,b:b/255}},h=function(a){var b,c;return c=document.createElement("span"),document.body.appendChild(c),c.style.backgroundColor=a,b=c.style.backgroundColor.length>0,c.remove(),b},l=function(a,b){var c,d;for(c in b)d=b[c],a.style[c]=d;return a},d=function(a,b){return a%=b,a<0&&(a+=b),a},i=function(a,b,c){return b+(c-b)*Math.min(1,Math.max(0,a))},a=function(){function a(a,b,c){var d,e,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;this.radius=a,this.width=b,this.lightness=c,r=this.radius,w=this.width,e=this.canvas=document.createElement("canvas"),e.width=e.height=r*2,g=e.getContext("2d"),o=g.createImageData(e.width,e.height),i=o.data;for(y=n=0,s=e.height;0<=s?n<s:n>s;y=0<=s?++n:--n)for(x=p=0,t=e.width;0<=t?p<t:p>t;x=0<=t?++p:--p){k=y-r,j=x-r,h=Math.sqrt(k*k+j*j);if(h>r+1.5)continue;h-=10,v=Math.max(0,Math.min(1,h/(r-w/2-10))),m=Math.atan2(k,j)/(Math.PI*2),u=f(m,v,this.lightness),q=u.r,l=u.g,d=u.b,i[(y*e.width+x)*4+0]=q*255,i[(y*e.width+x)*4+1]=l*255,i[(y*e.width+x)*4+2]=d*255,i[(y*e.width+x)*4+3]=255}g.putImageData(o,0,0)}return a.prototype.drawHSLCircle=function(a,b){var c,d,e,f;return a.width=a.height=2*this.radius,c=a.getContext("2d"),f=this.width,e=this.radius,d=i(b,f,e),c.save(),c.fillStyle="rgba(0,0,0,0.3)",c.beginPath(),c.arc(e,e,e,0,Math.PI*2),c.fill(),c.fillStyle="black",c.beginPath(),c.arc(e,e,d,0,Math.PI*2),c.arc(e,e,d-f,0,Math.PI*2,!0),c.fill(),c.globalCompositeOperation="source-in",c.drawImage(this.canvas,0,0),c.restore()},a}(),j=function(a){return typeof a=="string"&&(a=c(a)),a.r!=null&&a.g!=null&&a.b!=null?(a=k(a.r,a.g,a.b),a.h=a.h*Math.PI/180):a.h!=null&&a.s!=null&&a.l!=null&&(a.h=a.h*Math.PI/180),a},b=function(){function s(a){this.color=j(a),this.refColor=this.color,this.el=p(),this.circleContainer=this.el.appendChild(g.call(this)),this.lSlider=this.el.appendChild(o.call(this)),this.colorPreview=this.el.appendChild(h.call(this)),b.call(this),this.setLightness(this.color.l)}var b,g,h,n,o,p,q,r;return q=80,r=25,s.prototype.setHue=function(a){var b,c,d;return this.color.h=a,d=i(this.color.s,r,q)-r/2,c=q-r/2,l(this.hueKnob,{left:Math.round(c+Math.cos(a)*d+6-1)+"px",top:Math.round(c+Math.sin(a)*d+6-1)+"px"}),this.colorPreview.style.backgroundColor=this.lKnob.style.backgroundColor=this.hueKnob.style.backgroundColor=e(this.color.h,this.color.s,this.color.l),b=e(this.color.h,this.color.s,.5),this.lSlider.style.backgroundImage="-webkit-linear-gradient(bottom, black, "+b+" 50%, white)",this.lSlider.style.backgroundImage="-moz-linear-gradient(bottom, black, "+b+" 50%, white)",this.emit("changed")},s.prototype.setSaturation=function(a){return this.color.s=a,this.circle.drawHSLCircle(this.circleCanvas,a),this.setHue(this.color.h)},s.prototype.setLightness=function(b){return this.color.l=b,this.circle=new a(q,r,b),this.lKnob.style.top=(1-b)*this.lSlider._height-11+"px",this.setSaturation(this.color.s)},s.prototype.setHSL=function(a,b,c){return this.color.h=d(a,360)*Math.PI/180,this.color.s=Math.max(0,Math.min(1,b)),c=Math.max(0,Math.min(1,c)),this.setLightness(c)},s.prototype.getHSL=function(){return{h:d(this.color.h*180/Math.PI,360),s:this.color.s,l:this.color.l}},s.prototype.setRGB=function(a,b,c){var d,e,f,g;return f=k(a,b,c),d=f.h,g=f.s,e=f.l,this.setHSL(d,g,e)},s.prototype.getRGB=function(){return f(this.color.h/(Math.PI*2),this.color.s,this.color.l)},s.prototype.getCSS=function(){return e(this.color.h,this.color.s,this.color.l)},s.prototype.setCSS=function(a){var b,d,e,f;return f=c(a),e=f.r,d=f.g,b=f.b,this.setRGB(e,d,b)},s.prototype.on=function(a,b){var c;return this._listeners==null&&(this._listeners={}),((c=this._listeners)[a]!=null?c[a]:c[a]=[]).push(b)},s.prototype.emit=function(){var a,b,c,d,e,f,g,h;b=arguments[0],a=2<=arguments.length?m.call(arguments,1):[];if(this._listeners){g=(f=this._listeners[b])!=null?f:[],h=[];for(c=0,e=g.length;c<e;c++)d=g[c],h.push(d.call.apply(d,[this].concat(m.call(a))));return h}},s.prototype.removeListener=function(a,b){var c;if(this._listeners[a])return this._listeners[a]=function(){var d,e,f,g;f=this._listeners[a],g=[];for(d=0,e=f.length;d<e;d++)c=f[d],c!==b&&g.push(c);return g}.call(this)},b=function(){var a,b;return this.lKnob.onmousedown=function(a){return function(b){var c,d;return document.documentElement.style.cursor="pointer",window.addEventListener("mousemove",c=function(b){var c,d;return c=a.lSlider.getBoundingClientRect(),d=b.clientY-c.top,a.setLightness(Math.max(0,Math.min(1,1-d/a.lSlider._height)))}),window.addEventListener("mouseup",d=function(a){return window.removeEventListener("mousemove",c),window.removeEventListener("mouseup",d),window.removeEventListener("blur",d),document.documentElement.style.cursor=""}),window.addEventListener("blur",d),b.preventDefault(),b.stopPropagation()}}(this),a=this.circleContainer,b=function(b){return function(c){var d,e,f,g,h,j,k;j=c.layerX,k=c.layerY,e=j-q,f=k-q,d=Math.sqrt(e*e+f*f),h=Math.atan2(f,e),g=i(b.color.s,r,q);if(!(g-r<d&&d<g))return a.style.cursor="";if(-Math.PI/8<h&&h<Math.PI/8||h>=7*Math.PI/8||h<=-7*Math.PI/8)return a.style.cursor="ew-resize";if(Math.PI/8<=h&&h<3*Math.PI/8||-7*Math.PI/8<h&&h<=-5*Math.PI/8)return a.style.cursor="nwse-resize";if(3*Math.PI/8<=h&&h<5*Math.PI/8||-5*Math.PI/8<h&&h<=-3*Math.PI/8)return a.style.cursor="ns-resize";if(5*Math.PI/8<=h&&h<7*Math.PI/8||-3*Math.PI/8<h&&h<=-Math.PI/8)return a.style.cursor="nesw-resize"}}(this),a.addEventListener("mouseover",function(c){var d,e;return b(c),a.addEventListener("mousemove",d=function(a){return b(a)}),a.addEventListener("mouseout",e=function(b){return a.style.cursor="",a.removeEventListener("mousemove",d),a.removeEventListener("mouseout",e),window.removeEventListener("blur",e)}),window.addEventListener("blur",e)}),a.addEventListener("mousedown",function(b){return function(c){var d,e,f,g,h,j,k,l,m;c.preventDefault(),l=c.layerX,m=c.layerY,e=l-q,f=m-q,d=Math.sqrt(e*e+f*f),j=Math.atan2(f,e),h=i(b.color.s,r,q);if(h-r<d&&d<h)return document.documentElement.style.cursor=a.style.cursor,window.addEventListener("mousemove",g=function(a){var c,g,i;return h=b.circleCanvas.getBoundingClientRect(),c=h.left+h.width/2,g=h.top+h.height/2,e=a.clientX-c,f=a.clientY-g,d=Math.sqrt(e*e+f*f),d-=10,i=Math.max(0,Math.min(1,d/(q-r/2-10))),b.setSaturation(i)}),window.addEventListener("mouseup",k=function(a){return window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",k),window.removeEventListener("blur",k),document.documentElement.style.cursor=""}),window.addEventListener("blur",k);return}}(this)),this.hueKnob.onmousedown=function(a){return function(b){var c,d;return document.documentElement.style.cursor="pointer",window.addEventListener("mousemove",c=function(b){var c,d,e;return e=a.circleCanvas.getBoundingClientRect(),c=e.left+e.width/2,d=e.top+e.height/2,a.setHue(Math.atan2(b.clientY-d,b.clientX-c))}),window.addEventListener("mouseup",d=function(a){return window.removeEventListener("mousemove",c),window.removeEventListener("mouseup",d),window.removeEventListener("blur",d),document.documentElement.style.cursor=""}),window.addEventListener("blur",d),b.preventDefault(),b.stopPropagation()}}(this)},p=function(){var a;return a=document.createElement("div"),a.className="picker",l(a,{display:"inline-block",background:"hsl(0, 0%, 97%)",padding:"6px",borderRadius:"6px",boxShadow:"1px 1px 5px hsla(0, 0%, 39%, 0.2), hsla(0, 0%, 100%, 0.9) 0px 0px 1em 0.3em inset",border:"1px solid hsla(0, 0%, 59%, 0.2)",position:"absolute",backgroundImage:"-webkit-linear-gradient(left top, hsla(0, 0%, 0%, 0.05) 25%, transparent 25%, transparent 50%, hsla(0, 0%, 0%, 0.05) 50%, hsla(0, 0%, 0%, 0.05) 75%, transparent 75%, transparent)",backgroundSize:"40px 40px"}),l(a,{backgroundImage:"-moz-linear-gradient(left top, hsla(0, 0%, 0%, 0.05) 25%, transparent 25%, transparent 50%, hsla(0, 0%, 0%, 0.05) 50%, hsla(0, 0%, 0%, 0.05) 75%, transparent 75%, transparent)",zIndex:"1000"}),a},g=function(){var a,b;return a=document.createElement("div"),l(a,{display:"inline-block",width:q*2+"px",height:q*2+"px",borderRadius:q+"px",boxShadow:"0px 0px 7px rgba(0,0,0,0.3)"}),a.appendChild(this.circleCanvas=document.createElement("canvas")),this.hueKnob=b=n(27),a.appendChild(b),a},o=function(){var a,b;return b=document.createElement("div"),l(b,{display:"inline-block",width:"20px",height:q*2-22+"px",marginLeft:"6px",borderRadius:"10px",boxShadow:"hsla(0, 100%, 100%, 0.1) 0 1px 2px 1px inset, hsla(0, 100%, 100%, 0.2) 0 1px inset, hsla(0, 0%, 0%, 0.4) 0 -1px 1px inset, hsla(0, 0%, 0%, 0.4) 0 1px 1px",position:"relative",top:"-11px"}),b._height=q*2-22,this.lKnob=a=n(22),l(a,{left:"-1px"}),b.appendChild(a),b},h=function(){var a,b,c;return a=document.createElement("div"),b=e(this.refColor.h,this.refColor.s,this.refColor.l),c=e(this.refColor.h,this.refColor.s,this.refColor.l,0),l(a,{boxShadow:"hsla(0, 0%, 0%, 0.5) 0 1px 5px, hsla(0, 100%, 100%, 0.4) 0 1px 1px inset, hsla(0, 0%, 0%, 0.3) 0 -1px 1px inset",height:"25px",marginTop:"6px",borderRadius:"3px",backgroundImage:"-webkit-linear-gradient(-20deg, "+c+", "+c+" 69%, "+b+" 70%, "+b+")"}),l(a,{backgroundImage:"-moz-linear-gradient(-20deg, "+c+", "+c+" 69%, "+b+" 70%, "+b+")"}),a},n=function(a){var b;return b=document.createElement("div"),b.className="knob",l(b,{position:"absolute",width:a+"px",height:a+"px",backgroundColor:"red",borderRadius:Math.floor(a/2)+"px",cursor:"pointer",backgroundImage:"-webkit-gradient(radial, 50% 0%, 0, 50% 0%, 15, color-stop(0%, rgba(255, 255, 255, 0.8)), color-stop(100%, rgba(255, 255, 255, 0.2)))",boxShadow:"white 0px 1px 1px inset, rgba(0, 0, 0, 0.4) 0px -1px 1px inset, rgba(0, 0, 0, 0.4) 0px 1px 4px 0px, rgba(0, 0, 0, 0.6) 0 0 2px"}),l(b,{backgroundImage:"radial-gradient(circle at center top, rgba(255,255,255,0.8), rgba(255, 255, 255, 0.2) 15px"}),b},s.prototype.presentModal=function(a,b){var c;return l(this.el,{left:a+"px",top:b-10+"px",opacity:"0",webkitTransition:"0.15s",MozTransition:"0.15s"}),c=document.createElement("div"),c.style.position="fixed",c.style.top=c.style.left=c.style.bottom=c.style.right="0",c.style.zIndex="999",c.onclick=function(a){return function(){var d;return document.body.removeChild(c),a.el.style.top=b+10+"px",a.el.style.opacity=0,d=function(){return document.body.removeChild(a.el),a.el.removeEventListener("webkitTransitionEnd",d),a.el.removeEventListener("transitionend",d)},a.el.addEventListener("webkitTransitionEnd",d),a.el.addEventListener("transitionend",d),a.emit("closed")}}(this),document.body.appendChild(c),document.body.appendChild(this.el),this.el.offsetHeight,this.el.style.opacity="1",this.el.style.top=b+"px",this},s.prototype.presentModalBeneath=function(a){var b,c,d;return b=a.getBoundingClientRect(),c=b.left+window.scrollX,d=b.bottom+window.scrollY+4,this.presentModal(c,d)},s}(),window.thistle={Picker:b,isValidCSSColor:h}})).call(this);if(typeof Color=="undefined")var Color={};typeof Color.Space=="undefined"&&(Color.Space={}),function(){"use strict";var useEval=!1,functions={},shortcuts={"HEX24>HSL":"HEX24>RGB>HSL","HEX32>HSLA":"HEX32>RGBA>HSLA","HEX24>CMYK":"HEX24>RGB>CMY>CMYK","RGB>CMYK":"RGB>CMY>CMYK"},root=Color.Space=function(color,route){shortcuts[route]&&(route=shortcuts[route]);var r=route.split(">");if(typeof color=="object"&&color[0]>=0){var type=r[0],tmp={};for(var i=0;i<type.length;i++){var str=type.substr(i,1);tmp[str]=color[i]}color=tmp}if(functions[route])return functions[route](color);var f="color";for(var pos=1,key=r[0];pos<r.length;pos++)pos>1&&(key=key.substr(key.indexOf("_")+1)),key+=(pos===0?"":"_")+r[pos],color=root[key](color),useEval&&(f="Color.Space."+key+"("+f+")");return useEval&&(functions[route]=eval("(function(color) { return "+f+" })")),color};root.RGB_W3=function(a){return"rgb("+(a.R>>0)+","+(a.G>>0)+","+(a.B>>0)+")"},root.RGBA_W3=function(a){var b=typeof a.A=="number"?a.A/255:1;return"rgba("+(a.R>>0)+","+(a.G>>0)+","+(a.B>>0)+","+b+")"},root.W3_RGB=function(a){return a=a.substr(4,a.length-5).split(","),{R:parseInt(a[0],10),G:parseInt(a[1],10),B:parseInt(a[2],10)}},root.W3_RGBA=function(a){return a=a.substr(5,a.length-6).split(","),{R:parseInt(a[0],10),G:parseInt(a[1],10),B:parseInt(a[2],10),A:parseFloat(a[3])*255}},root.HSL_W3=function(a){return"hsl("+(a.H+.5>>0)+","+(a.S+.5>>0)+"%,"+(a.L+.5>>0)+"%)"},root.HSLA_W3=function(a){var b=typeof a.A=="number"?a.A/255:1;return"hsla("+(a.H+.5>>0)+","+(a.S+.5>>0)+"%,"+(a.L+.5>>0)+"%,"+b+")"},root.W3_HSL=function(a){var b=a.indexOf("(")+1,c=a.indexOf(")");return a=a.substr(b,c-b).split(","),{H:parseInt(a[0],10),S:parseInt(a[1],10),L:parseInt(a[2],10)}},root.W3_HSLA=function(a){var b=a.indexOf("(")+1,c=a.indexOf(")");return a=a.substr(b,c-b).split(","),{H:parseInt(a[0],10),S:parseInt(a[1],10),L:parseInt(a[2],10),A:parseFloat(a[3],10)*255}},root.W3_HEX=root.W3_HEX24=function(a){return a.substr(0,1)==="#"&&(a=a.substr(1)),a.length===3&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),parseInt("0x"+a,16)},root.W3_HEX32=function(a){return a.substr(0,1)==="#"&&(a=a.substr(1)),a.length===6?parseInt("0xFF"+a,10):parseInt("0x"+a,16)},root.HEX_W3=root.HEX24_W3=function(a,b){b||(b=6),a||(a=0);var c,d=a.toString(16);c=d.length;while(c<b)d="0"+d,c++;c=d.length;while(c>b)d=d.substr(1),c--;return"#"+d},root.HEX32_W3=function(a){return root.HEX_W3(a,8)},root.HEX_RGB=root.HEX24_RGB=function(a){return{R:a>>16,G:a>>8&255,B:a&255}},root.HEX32_RGBA=function(a){return{R:a>>>16&255,G:a>>>8&255,B:a&255,A:a>>>24}},root.RGBA_HEX32=function(a){return(a.A<<24|a.R<<16|a.G<<8|a.B)>>>0},root.RGB_HEX24=root.RGB_HEX=function(a){return a.R<0&&(a.R=0),a.G<0&&(a.G=0),a.B<0&&(a.B=0),a.R>255&&(a.R=255),a.G>255&&(a.G=255),a.B>255&&(a.B=255),a.R<<16|a.G<<8|a.B},root.RGB_CMY=function(a){return{C:1-a.R/255,M:1-a.G/255,Y:1-a.B/255}},root.RGBA_HSLA=root.RGB_HSL=function(a){var b=a.R/255,c=a.G/255,d=a.B/255,e=Math.min(b,c,d),f=Math.max(b,c,d),g=f-e,h,i,j=(f+e)/2;if(g===0)h=0,i=0;else{j<.5?i=g/(f+e):i=g/(2-f-e);var k=((f-b)/6+g/2)/g,l=((f-c)/6+g/2)/g,m=((f-d)/6+g/2)/g;b===f?h=m-l:c===f?h=1/3+k-m:d===f&&(h=2/3+l-k),h<0&&(h+=1),h>1&&(h-=1)}return{H:h*360,S:i*100,L:j*100,A:a.A}},root.RGBA_HSVA=root.RGB_HSV=function(a){var b=a.R/255,c=a.G/255,d=a.B/255,e=Math.min(b,c,d),f=Math.max(b,c,d),g=f-e,h,i,j=f;if(g===0)h=0,i=0;else{i=g/f;var k=((f-b)/6+g/2)/g,l=((f-c)/6+g/2)/g,m=((f-d)/6+g/2)/g;b===f?h=m-l:c===f?h=1/3+k-m:d===f&&(h=2/3+l-k),h<0&&(h+=1),h>1&&(h-=1)}return{H:h*360,S:i*100,V:j*100,A:a.A}},root.CMY_RGB=function(a){return{R:Math.max(0,(1-a.C)*255),G:Math.max(0,(1-a.M)*255),B:Math.max(0,(1-a.Y)*255)}},root.CMY_CMYK=function(a){var b=a.C,c=a.M,d=a.Y,e=Math.min(d,Math.min(c,Math.min(b,1)));return b=Math.round((b-e)/(1-e)*100),c=Math.round((c-e)/(1-e)*100),d=Math.round((d-e)/(1-e)*100),e=Math.round(e*100),{C:b,M:c,Y:d,K:e}},root.CMYK_CMY=function(a){return{C:a.C*(1-a.K)+a.K,M:a.M*(1-a.K)+a.K,Y:a.Y*(1-a.K)+a.K}},root.HSLA_RGBA=root.HSL_RGB=function(a){var b=a.H/360,c=a.S/100,d=a.L/100,e,f,g,h,i,j;return c===0?e=f=g=d:(d<.5?i=d*(1+c):i=d+c-c*d,h=2*d-i,j=b+1/3,j<0&&(j+=1),j>1&&(j-=1),6*j<1?e=h+(i-h)*6*j:2*j<1?e=i:3*j<2?e=h+(i-h)*(2/3-j)*6:e=h,j=b,j<0&&(j+=1),j>1&&(j-=1),6*j<1?f=h+(i-h)*6*j:2*j<1?f=i:3*j<2?f=h+(i-h)*(2/3-j)*6:f=h,j=b-1/3,j<0&&(j+=1),j>1&&(j-=1),6*j<1?g=h+(i-h)*6*j:2*j<1?g=i:3*j<2?g=h+(i-h)*(2/3-j)*6:g=h),{R:e*255,G:f*255,B:g*255,A:a.A}},root.HSVA_RGBA=root.HSV_RGB=function(a){var b=a.H/360,c=a.S/100,d=a.V/100,e,f,g,h,i,j;if(c===0)e=f=g=Math.round(d*255);else{b>=1&&(b=0),b=6*b,h=b-Math.floor(b),i=Math.round(255*d*(1-c)),g=Math.round(255*d*(1-c*h)),j=Math.round(255*d*(1-c*(1-h))),d=Math.round(255*d);switch(Math.floor(b)){case 0:e=d,f=j,g=i;break;case 1:e=g,f=d,g=i;break;case 2:e=i,f=d,g=j;break;case 3:e=i,f=g,g=d;break;case 4:e=j,f=i,g=d;break;case 5:e=d,f=i,g=g}}return{R:e,G:f,B:g,A:a.A}}}(),Inlet=function(){function a(a,c){function w(a){var b=String(g.checked),c=d.getCursor(!0),e=L(c,"boolean");if(!e)return;var f={line:c.line,ch:e.start},h={line:c.line,ch:e.end};d.replaceRange(b,f,h)}function z(a){var b=String(e.value),c=d.getCursor(!0),f=L(c,"number");if(!f)return;var g={line:c.line,ch:f.start},h={line:c.line,ch:f.end};d.dragging=!0,d.replaceRange(b,g,h)}function A(a){e.value=0;var b=d.getCursor(!0),c=L(b,"number");if(!c)return;var f=parseFloat(c.string),g=K(f);e.setAttribute("value",f),e.setAttribute("step",g.step),e.setAttribute("min",g.min),e.setAttribute("max",g.max),e.value=f,d.dragging=!1}function C(a){if(a.target===B||a.target===x||a.target===e||a.target===v||a.target===g)return;x.style.visibility="hidden",v.style.visibility="hidden"}function H(){arguments.length==1?event=arguments[0]:event=arguments[1];if(event.keyCode==D||event.keyCode==G){if(x.style.visibility==="visible")return e.stepDown(1),z(),!0;event.altKey&&J()}else if(event.keyCode==F||event.keyCode==E){if(x.style.visibility==="visible")return e.stepUp(1),z(),!0;event.altKey&&J()}else x.style.visibility="hidden"}function J(a){if(d.somethingSelected())return;B=a.target;var c=d.getCursor(!0),h=d.getTokenAt(c);cursorOffset=d.cursorCoords(!0,"page");var o=d.cursorCoords(!0,p).left,q=L(c,"number"),r=L(c,"hsl"),s=L(c,"hex"),t=L(c,"rgb"),u=L(c,"boolean"),y=cursorOffset.top-i;cursorOffset.top<k&&(y=cursorOffset.top+j);var z=o-l;x.style.visibility="hidden",v.style.visibility="hidden";if(s){var A=s.string;f=new thistle.Picker(A),f.setCSS(A),f.presentModal(z,y),f.on("changed",function(){picked=f.getCSS(),picked=Color.Space(picked,"W3>HSL>RGB>HEX24>W3"),I(picked,"hex")})}else if(r){var A=r.string;f=new thistle.Picker(A),f.setCSS(A),f.presentModal(z,y),f.on("changed",function(){picked=f.getCSS(),I(picked,"hsl")})}else if(t){var A=t.string;f=new thistle.Picker(A),f.setCSS(A),f.presentModal(z,y),f.on("changed",function(){picked=f.getCSS(),picked=Color.Space(picked,"W3>HSL>RGB>W3"),I(picked,"rgb")})}}function K(a){var b,c,d,e;return a===0?b=[-100,100]:b=[-a*3,a*5],b[0]<b[1]?(min=b[0],max=b[1]):(min=b[1],max=b[0]),max-min>20?c=1:c=(max-min)/200,{min:min,max:max,step:c}}function L(a,b){if(!b)return;var c;switch(b.toLowerCase()){case"boolean":c=/true|false/g;break;case"hsl":c=/hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)/g;break;case"rgb":c=/rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)/g;break;case"hex":c=/#[a-fA-F0-9]{3,6}/g;break;case"number":c=/[-]?\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g;break;default:throw new Error("invalid match selection")}var e=d.getLine(a.line),f=c.exec(e);while(f){var g=f[0],h=g.length,i=f.index,j=f.index+h;if(a.ch>=i&&a.ch<=j)return f=null,{start:i,end:j,string:g};f=c.exec(e)}return}var d=a,e,f,g;c||(c={}),c.picker||(c.picker={}),c.slider||(c.slider={}),c.clicker||(c.clicker={});var h=c.container||document.body,i=c.picker.topOffset||220,j=c.picker.bottomOffset||16,k=c.picker.topBoundary||250,l=c.picker.leftOffset||75,m=c.slider.yOffset||15,n=c.slider.xOffset||0,o=c.slider.width,p=c.horizontalMode||"page",q=c.fixedContainer,r=c.slider.callback||function(a){},s=c.picker.callback||function(a){},t=c.clicker.callback||function(a){},u=d.getWrapperElement();u.addEventListener("mouseup",J),document.body.addEventListener("mouseup",C),d.setOption("onKeyEvent",H);var v=document.createElement("div");v.className="inlet_clicker",v.style.visibility="hidden",v.style.position="absolute",h.appendChild(v);var g=document.createElement("input");g.className="checkbox",g.setAttribute("type","checkbox"),g.addEventListener("change",w),v.appendChild(g);var x=document.createElement("div");x.className="inlet_slider",x.style.visibility="hidden",o&&(x.style.width=o),q?x.style.position="fixed":x.style.position="absolute",x.style.top=0,h.appendChild(x);var e=document.createElement("input");e.className="range",e.setAttribute("type","range"),e.addEventListener("input",z),e.addEventListener("change",z);var y=navigator.userAgent.toLowerCase().indexOf("firefox")>-1;y||e.addEventListener("mouseup",A),x.appendChild(e);var B,D=37,E=38,F=39,G=40,I=function(a,b){var c=d.getCursor();if(!b)return;var e=L(c,b),f={line:c.line,ch:e.start},g={line:c.line,ch:e.end};d.picking=!0,d.replaceRange(a,f,g),setTimeout(function(){d.picking=!1},100)};f=new thistle.Picker("#ffffff")}function b(a){var b=0;return a.length>2&&(b=parseFloat(a.slice(0,a.length-2))),b||(b=0),b}function c(a){var b=0,c=0;while(a&&!isNaN(a.offsetLeft)&&!isNaN(a.offsetTop))b+=a.offsetLeft-a.scrollLeft,c+=a.offsetTop-a.scrollTop,a=a.offsetParent;return{top:c,left:b}}return a}();
(function webpackUniversalModuleDefinition(root, factory) {
/* istanbul ignore next */
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
/* istanbul ignore next */
else if(typeof exports === 'object')
exports["esprima"] = factory();
else
root["esprima"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/* istanbul ignore if */
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/*
Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
var comment_handler_1 = __webpack_require__(1);
var parser_1 = __webpack_require__(3);
var jsx_parser_1 = __webpack_require__(11);
var tokenizer_1 = __webpack_require__(15);
function parse(code, options, delegate) {
var commentHandler = null;
var proxyDelegate = function (node, metadata) {
if (delegate) {
delegate(node, metadata);
}
if (commentHandler) {
commentHandler.visit(node, metadata);
}
};
var parserDelegate = (typeof delegate === 'function') ? proxyDelegate : null;
var collectComment = false;
if (options) {
collectComment = (typeof options.comment === 'boolean' && options.comment);
var attachComment = (typeof options.attachComment === 'boolean' && options.attachComment);
if (collectComment || attachComment) {
commentHandler = new comment_handler_1.CommentHandler();
commentHandler.attach = attachComment;
options.comment = true;
parserDelegate = proxyDelegate;
}
}
var parser;
if (options && typeof options.jsx === 'boolean' && options.jsx) {
parser = new jsx_parser_1.JSXParser(code, options, parserDelegate);
}
else {
parser = new parser_1.Parser(code, options, parserDelegate);
}
var ast = (parser.parseProgram());
if (collectComment) {
ast.comments = commentHandler.comments;
}
if (parser.config.tokens) {
ast.tokens = parser.tokens;
}
if (parser.config.tolerant) {
ast.errors = parser.errorHandler.errors;
}
return ast;
}
exports.parse = parse;
function tokenize(code, options, delegate) {
var tokenizer = new tokenizer_1.Tokenizer(code, options);
var tokens;
tokens = [];
try {
while (true) {
var token = tokenizer.getNextToken();
if (!token) {
break;
}
if (delegate) {
token = delegate(token);
}
tokens.push(token);
}
}
catch (e) {
tokenizer.errorHandler.tolerate(e);
}
if (tokenizer.errorHandler.tolerant) {
tokens.errors = tokenizer.errors();
}
return tokens;
}
exports.tokenize = tokenize;
var syntax_1 = __webpack_require__(2);
exports.Syntax = syntax_1.Syntax;
// Sync with *.json manifests.
exports.version = '3.1.1';
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var syntax_1 = __webpack_require__(2);
var CommentHandler = (function () {
function CommentHandler() {
this.attach = false;
this.comments = [];
this.stack = [];
this.leading = [];
this.trailing = [];
}
CommentHandler.prototype.insertInnerComments = function (node, metadata) {
// innnerComments for properties empty block
// `function a() {/** comments **\/}`
if (node.type === syntax_1.Syntax.BlockStatement && node.body.length === 0) {
var innerComments = [];
for (var i = this.leading.length - 1; i >= 0; --i) {
var entry = this.leading[i];
if (metadata.end.offset >= entry.start) {
innerComments.unshift(entry.comment);
this.leading.splice(i, 1);
this.trailing.splice(i, 1);
}
}
if (innerComments.length) {
node.innerComments = innerComments;
}
}
};
CommentHandler.prototype.findTrailingComments = function (node, metadata) {
var trailingComments = [];
if (this.trailing.length > 0) {
for (var i = this.trailing.length - 1; i >= 0; --i) {
var entry_1 = this.trailing[i];
if (entry_1.start >= metadata.end.offset) {
trailingComments.unshift(entry_1.comment);
}
}
this.trailing.length = 0;
return trailingComments;
}
var entry = this.stack[this.stack.length - 1];
if (entry && entry.node.trailingComments) {
var firstComment = entry.node.trailingComments[0];
if (firstComment && firstComment.range[0] >= metadata.end.offset) {
trailingComments = entry.node.trailingComments;
delete entry.node.trailingComments;
}
}
return trailingComments;
};
CommentHandler.prototype.findLeadingComments = function (node, metadata) {
var leadingComments = [];
var target;
while (this.stack.length > 0) {
var entry = this.stack[this.stack.length - 1];
if (entry && entry.start >= metadata.start.offset) {
target = this.stack.pop().node;
}
else {
break;
}
}
if (target) {
var count = target.leadingComments ? target.leadingComments.length : 0;
for (var i = count - 1; i >= 0; --i) {
var comment = target.leadingComments[i];
if (comment.range[1] <= metadata.start.offset) {
leadingComments.unshift(comment);
target.leadingComments.splice(i, 1);
}
}
if (target.leadingComments && target.leadingComments.length === 0) {
delete target.leadingComments;
}
return leadingComments;
}
for (var i = this.leading.length - 1; i >= 0; --i) {
var entry = this.leading[i];
if (entry.start <= metadata.start.offset) {
leadingComments.unshift(entry.comment);
this.leading.splice(i, 1);
}
}
return leadingComments;
};
CommentHandler.prototype.visitNode = function (node, metadata) {
if (node.type === syntax_1.Syntax.Program && node.body.length > 0) {
return;
}
this.insertInnerComments(node, metadata);
var trailingComments = this.findTrailingComments(node, metadata);
var leadingComments = this.findLeadingComments(node, metadata);
if (leadingComments.length > 0) {
node.leadingComments = leadingComments;
}
if (trailingComments.length > 0) {
node.trailingComments = trailingComments;
}
this.stack.push({
node: node,
start: metadata.start.offset
});
};
CommentHandler.prototype.visitComment = function (node, metadata) {
var type = (node.type[0] === 'L') ? 'Line' : 'Block';
var comment = {
type: type,
value: node.value
};
if (node.range) {
comment.range = node.range;
}
if (node.loc) {
comment.loc = node.loc;
}
this.comments.push(comment);
if (this.attach) {
var entry = {
comment: {
type: type,
value: node.value,
range: [metadata.start.offset, metadata.end.offset]
},
start: metadata.start.offset
};
if (node.loc) {
entry.comment.loc = node.loc;
}
node.type = type;
this.leading.push(entry);
this.trailing.push(entry);
}
};
CommentHandler.prototype.visit = function (node, metadata) {
if (node.type === 'LineComment') {
this.visitComment(node, metadata);
}
else if (node.type === 'BlockComment') {
this.visitComment(node, metadata);
}
else if (this.attach) {
this.visitNode(node, metadata);
}
};
return CommentHandler;
}());
exports.CommentHandler = CommentHandler;
/***/ },
/* 2 */
/***/ function(module, exports) {
"use strict";
exports.Syntax = {
AssignmentExpression: 'AssignmentExpression',
AssignmentPattern: 'AssignmentPattern',
ArrayExpression: 'ArrayExpression',
ArrayPattern: 'ArrayPattern',
ArrowFunctionExpression: 'ArrowFunctionExpression',
BlockStatement: 'BlockStatement',
BinaryExpression: 'BinaryExpression',
BreakStatement: 'BreakStatement',
CallExpression: 'CallExpression',
CatchClause: 'CatchClause',
ClassBody: 'ClassBody',
ClassDeclaration: 'ClassDeclaration',
ClassExpression: 'ClassExpression',
ConditionalExpression: 'ConditionalExpression',
ContinueStatement: 'ContinueStatement',
DoWhileStatement: 'DoWhileStatement',
DebuggerStatement: 'DebuggerStatement',
EmptyStatement: 'EmptyStatement',
ExportAllDeclaration: 'ExportAllDeclaration',
ExportDefaultDeclaration: 'ExportDefaultDeclaration',
ExportNamedDeclaration: 'ExportNamedDeclaration',
ExportSpecifier: 'ExportSpecifier',
ExpressionStatement: 'ExpressionStatement',
ForStatement: 'ForStatement',
ForOfStatement: 'ForOfStatement',
ForInStatement: 'ForInStatement',
FunctionDeclaration: 'FunctionDeclaration',
FunctionExpression: 'FunctionExpression',
Identifier: 'Identifier',
IfStatement: 'IfStatement',
ImportDeclaration: 'ImportDeclaration',
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
ImportSpecifier: 'ImportSpecifier',
Literal: 'Literal',
LabeledStatement: 'LabeledStatement',
LogicalExpression: 'LogicalExpression',
MemberExpression: 'MemberExpression',
MetaProperty: 'MetaProperty',
MethodDefinition: 'MethodDefinition',
NewExpression: 'NewExpression',
ObjectExpression: 'ObjectExpression',
ObjectPattern: 'ObjectPattern',
Program: 'Program',
Property: 'Property',
RestElement: 'RestElement',
ReturnStatement: 'ReturnStatement',
SequenceExpression: 'SequenceExpression',
SpreadElement: 'SpreadElement',
Super: 'Super',
SwitchCase: 'SwitchCase',
SwitchStatement: 'SwitchStatement',
TaggedTemplateExpression: 'TaggedTemplateExpression',
TemplateElement: 'TemplateElement',
TemplateLiteral: 'TemplateLiteral',
ThisExpression: 'ThisExpression',
ThrowStatement: 'ThrowStatement',
TryStatement: 'TryStatement',
UnaryExpression: 'UnaryExpression',
UpdateExpression: 'UpdateExpression',
VariableDeclaration: 'VariableDeclaration',
VariableDeclarator: 'VariableDeclarator',
WhileStatement: 'WhileStatement',
WithStatement: 'WithStatement',
YieldExpression: 'YieldExpression'
};
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var assert_1 = __webpack_require__(4);
var messages_1 = __webpack_require__(5);
var error_handler_1 = __webpack_require__(6);
var token_1 = __webpack_require__(7);
var scanner_1 = __webpack_require__(8);
var syntax_1 = __webpack_require__(2);
var Node = __webpack_require__(10);
var ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder';
var Parser = (function () {
function Parser(code, options, delegate) {
if (options === void 0) { options = {}; }
this.config = {
range: (typeof options.range === 'boolean') && options.range,
loc: (typeof options.loc === 'boolean') && options.loc,
source: null,
tokens: (typeof options.tokens === 'boolean') && options.tokens,
comment: (typeof options.comment === 'boolean') && options.comment,
tolerant: (typeof options.tolerant === 'boolean') && options.tolerant
};
if (this.config.loc && options.source && options.source !== null) {
this.config.source = String(options.source);
}
this.delegate = delegate;
this.errorHandler = new error_handler_1.ErrorHandler();
this.errorHandler.tolerant = this.config.tolerant;
this.scanner = new scanner_1.Scanner(code, this.errorHandler);
this.scanner.trackComment = this.config.comment;
this.operatorPrecedence = {
')': 0,
';': 0,
',': 0,
'=': 0,
']': 0,
'||': 1,
'&&': 2,
'|': 3,
'^': 4,
'&': 5,
'==': 6,
'!=': 6,
'===': 6,
'!==': 6,
'<': 7,
'>': 7,
'<=': 7,
'>=': 7,
'<<': 8,
'>>': 8,
'>>>': 8,
'+': 9,
'-': 9,
'*': 11,
'/': 11,
'%': 11
};
this.sourceType = (options && options.sourceType === 'module') ? 'module' : 'script';
this.lookahead = null;
this.hasLineTerminator = false;
this.context = {
allowIn: true,
allowYield: true,
firstCoverInitializedNameError: null,
isAssignmentTarget: false,
isBindingElement: false,
inFunctionBody: false,
inIteration: false,
inSwitch: false,
labelSet: {},
strict: (this.sourceType === 'module')
};
this.tokens = [];
this.startMarker = {
index: 0,
lineNumber: this.scanner.lineNumber,
lineStart: 0
};
this.lastMarker = {
index: 0,
lineNumber: this.scanner.lineNumber,
lineStart: 0
};
this.nextToken();
this.lastMarker = {
index: this.scanner.index,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart
};
}
Parser.prototype.throwError = function (messageFormat) {
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
var args = Array.prototype.slice.call(arguments, 1);
var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
assert_1.assert(idx < args.length, 'Message reference must be in range');
return args[idx];
});
var index = this.lastMarker.index;
var line = this.lastMarker.lineNumber;
var column = this.lastMarker.index - this.lastMarker.lineStart + 1;
throw this.errorHandler.createError(index, line, column, msg);
};
Parser.prototype.tolerateError = function (messageFormat) {
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
var args = Array.prototype.slice.call(arguments, 1);
var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
assert_1.assert(idx < args.length, 'Message reference must be in range');
return args[idx];
});
var index = this.lastMarker.index;
var line = this.scanner.lineNumber;
var column = this.lastMarker.index - this.lastMarker.lineStart + 1;
this.errorHandler.tolerateError(index, line, column, msg);
};
// Throw an exception because of the token.
Parser.prototype.unexpectedTokenError = function (token, message) {
var msg = message || messages_1.Messages.UnexpectedToken;
var value;
if (token) {
if (!message) {
msg = (token.type === token_1.Token.EOF) ? messages_1.Messages.UnexpectedEOS :
(token.type === token_1.Token.Identifier) ? messages_1.Messages.UnexpectedIdentifier :
(token.type === token_1.Token.NumericLiteral) ? messages_1.Messages.UnexpectedNumber :
(token.type === token_1.Token.StringLiteral) ? messages_1.Messages.UnexpectedString :
(token.type === token_1.Token.Template) ? messages_1.Messages.UnexpectedTemplate :
messages_1.Messages.UnexpectedToken;
if (token.type === token_1.Token.Keyword) {
if (this.scanner.isFutureReservedWord(token.value)) {
msg = messages_1.Messages.UnexpectedReserved;
}
else if (this.context.strict && this.scanner.isStrictModeReservedWord(token.value)) {
msg = messages_1.Messages.StrictReservedWord;
}
}
}
value = (token.type === token_1.Token.Template) ? token.value.raw : token.value;
}
else {
value = 'ILLEGAL';
}
msg = msg.replace('%0', value);
if (token && typeof token.lineNumber === 'number') {
var index = token.start;
var line = token.lineNumber;
var column = token.start - this.lastMarker.lineStart + 1;
return this.errorHandler.createError(index, line, column, msg);
}
else {
var index = this.lastMarker.index;
var line = this.lastMarker.lineNumber;
var column = index - this.lastMarker.lineStart + 1;
return this.errorHandler.createError(index, line, column, msg);
}
};
Parser.prototype.throwUnexpectedToken = function (token, message) {
throw this.unexpectedTokenError(token, message);
};
Parser.prototype.tolerateUnexpectedToken = function (token, message) {
this.errorHandler.tolerate(this.unexpectedTokenError(token, message));
};
Parser.prototype.collectComments = function () {
if (!this.config.comment) {
this.scanner.scanComments();
}
else {
var comments = this.scanner.scanComments();
if (comments.length > 0 && this.delegate) {
for (var i = 0; i < comments.length; ++i) {
var e = comments[i];
var node = void 0;
node = {
type: e.multiLine ? 'BlockComment' : 'LineComment',
value: this.scanner.source.slice(e.slice[0], e.slice[1])
};
if (this.config.range) {
node.range = e.range;
}
if (this.config.loc) {
node.loc = e.loc;
}
var metadata = {
start: {
line: e.loc.start.line,
column: e.loc.start.column,
offset: e.range[0]
},
end: {
line: e.loc.end.line,
column: e.loc.end.column,
offset: e.range[1]
}
};
this.delegate(node, metadata);
}
}
}
};
// From internal representation to an external structure
Parser.prototype.getTokenRaw = function (token) {
return this.scanner.source.slice(token.start, token.end);
};
Parser.prototype.convertToken = function (token) {
var t;
t = {
type: token_1.TokenName[token.type],
value: this.getTokenRaw(token)
};
if (this.config.range) {
t.range = [token.start, token.end];
}
if (this.config.loc) {
t.loc = {
start: {
line: this.startMarker.lineNumber,
column: this.startMarker.index - this.startMarker.lineStart
},
end: {
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
}
};
}
if (token.regex) {
t.regex = token.regex;
}
return t;
};
Parser.prototype.nextToken = function () {
var token = this.lookahead;
this.lastMarker.index = this.scanner.index;
this.lastMarker.lineNumber = this.scanner.lineNumber;
this.lastMarker.lineStart = this.scanner.lineStart;
this.collectComments();
this.startMarker.index = this.scanner.index;
this.startMarker.lineNumber = this.scanner.lineNumber;
this.startMarker.lineStart = this.scanner.lineStart;
var next;
next = this.scanner.lex();
this.hasLineTerminator = (token && next) ? (token.lineNumber !== next.lineNumber) : false;
if (next && this.context.strict && next.type === token_1.Token.Identifier) {
if (this.scanner.isStrictModeReservedWord(next.value)) {
next.type = token_1.Token.Keyword;
}
}
this.lookahead = next;
if (this.config.tokens && next.type !== token_1.Token.EOF) {
this.tokens.push(this.convertToken(next));
}
return token;
};
Parser.prototype.nextRegexToken = function () {
this.collectComments();
var token = this.scanner.scanRegExp();
if (this.config.tokens) {
// Pop the previous token, '/' or '/='
// This is added from the lookahead token.
this.tokens.pop();
this.tokens.push(this.convertToken(token));
}
// Prime the next lookahead.
this.lookahead = token;
this.nextToken();
return token;
};
Parser.prototype.createNode = function () {
return {
index: this.startMarker.index,
line: this.startMarker.lineNumber,
column: this.startMarker.index - this.startMarker.lineStart
};
};
Parser.prototype.startNode = function (token) {
return {
index: token.start,
line: token.lineNumber,
column: token.start - token.lineStart
};
};
Parser.prototype.finalize = function (meta, node) {
if (this.config.range) {
node.range = [meta.index, this.lastMarker.index];
}
if (this.config.loc) {
node.loc = {
start: {
line: meta.line,
column: meta.column
},
end: {
line: this.lastMarker.lineNumber,
column: this.lastMarker.index - this.lastMarker.lineStart
}
};
if (this.config.source) {
node.loc.source = this.config.source;
}
}
if (this.delegate) {
var metadata = {
start: {
line: meta.line,
column: meta.column,
offset: meta.index
},
end: {
line: this.lastMarker.lineNumber,
column: this.lastMarker.index - this.lastMarker.lineStart,
offset: this.lastMarker.index
}
};
this.delegate(node, metadata);
}
return node;
};
// Expect the next token to match the specified punctuator.
// If not, an exception will be thrown.
Parser.prototype.expect = function (value) {
var token = this.nextToken();
if (token.type !== token_1.Token.Punctuator || token.value !== value) {
this.throwUnexpectedToken(token);
}
};
// Quietly expect a comma when in tolerant mode, otherwise delegates to expect().
Parser.prototype.expectCommaSeparator = function () {
if (this.config.tolerant) {
var token = this.lookahead;
if (token.type === token_1.Token.Punctuator && token.value === ',') {
this.nextToken();
}
else if (token.type === token_1.Token.Punctuator && token.value === ';') {
this.nextToken();
this.tolerateUnexpectedToken(token);
}
else {
this.tolerateUnexpectedToken(token, messages_1.Messages.UnexpectedToken);
}
}
else {
this.expect(',');
}
};
// Expect the next token to match the specified keyword.
// If not, an exception will be thrown.
Parser.prototype.expectKeyword = function (keyword) {
var token = this.nextToken();
if (token.type !== token_1.Token.Keyword || token.value !== keyword) {
this.throwUnexpectedToken(token);
}
};
// Return true if the next token matches the specified punctuator.
Parser.prototype.match = function (value) {
return this.lookahead.type === token_1.Token.Punctuator && this.lookahead.value === value;
};
// Return true if the next token matches the specified keyword
Parser.prototype.matchKeyword = function (keyword) {
return this.lookahead.type === token_1.Token.Keyword && this.lookahead.value === keyword;
};
// Return true if the next token matches the specified contextual keyword
// (where an identifier is sometimes a keyword depending on the context)
Parser.prototype.matchContextualKeyword = function (keyword) {
return this.lookahead.type === token_1.Token.Identifier && this.lookahead.value === keyword;
};
// Return true if the next token is an assignment operator
Parser.prototype.matchAssign = function () {
if (this.lookahead.type !== token_1.Token.Punctuator) {
return false;
}
var op = this.lookahead.value;
return op === '=' ||
op === '*=' ||
op === '**=' ||
op === '/=' ||
op === '%=' ||
op === '+=' ||
op === '-=' ||
op === '<<=' ||
op === '>>=' ||
op === '>>>=' ||
op === '&=' ||
op === '^=' ||
op === '|=';
};
// Cover grammar support.
//
// When an assignment expression position starts with an left parenthesis, the determination of the type
// of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
// or the first comma. This situation also defers the determination of all the expressions nested in the pair.
//
// There are three productions that can be parsed in a parentheses pair that needs to be determined
// after the outermost pair is closed. They are:
//
// 1. AssignmentExpression
// 2. BindingElements
// 3. AssignmentTargets
//
// In order to avoid exponential backtracking, we use two flags to denote if the production can be
// binding element or assignment target.
//
// The three productions have the relationship:
//
// BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
//
// with a single exception that CoverInitializedName when used directly in an Expression, generates
// an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
// first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
//
// isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
// effect the current flags. This means the production the parser parses is only used as an expression. Therefore
// the CoverInitializedName check is conducted.
//
// inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
// the flags outside of the parser. This means the production the parser parses is used as a part of a potential
// pattern. The CoverInitializedName check is deferred.
Parser.prototype.isolateCoverGrammar = function (parseFunction) {
var previousIsBindingElement = this.context.isBindingElement;
var previousIsAssignmentTarget = this.context.isAssignmentTarget;
var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
this.context.isBindingElement = true;
this.context.isAssignmentTarget = true;
this.context.firstCoverInitializedNameError = null;
var result = parseFunction.call(this);
if (this.context.firstCoverInitializedNameError !== null) {
this.throwUnexpectedToken(this.context.firstCoverInitializedNameError);
}
this.context.isBindingElement = previousIsBindingElement;
this.context.isAssignmentTarget = previousIsAssignmentTarget;
this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError;
return result;
};
Parser.prototype.inheritCoverGrammar = function (parseFunction) {
var previousIsBindingElement = this.context.isBindingElement;
var previousIsAssignmentTarget = this.context.isAssignmentTarget;
var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
this.context.isBindingElement = true;
this.context.isAssignmentTarget = true;
this.context.firstCoverInitializedNameError = null;
var result = parseFunction.call(this);
this.context.isBindingElement = this.context.isBindingElement && previousIsBindingElement;
this.context.isAssignmentTarget = this.context.isAssignmentTarget && previousIsAssignmentTarget;
this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError || this.context.firstCoverInitializedNameError;
return result;
};
Parser.prototype.consumeSemicolon = function () {
if (this.match(';')) {
this.nextToken();
}
else if (!this.hasLineTerminator) {
if (this.lookahead.type !== token_1.Token.EOF && !this.match('}')) {
this.throwUnexpectedToken(this.lookahead);
}
this.lastMarker.index = this.startMarker.index;
this.lastMarker.lineNumber = this.startMarker.lineNumber;
this.lastMarker.lineStart = this.startMarker.lineStart;
}
};
// ECMA-262 12.2 Primary Expressions
Parser.prototype.parsePrimaryExpression = function () {
var node = this.createNode();
var expr;
var value, token, raw;
switch (this.lookahead.type) {
case token_1.Token.Identifier:
if (this.sourceType === 'module' && this.lookahead.value === 'await') {
this.tolerateUnexpectedToken(this.lookahead);
}
expr = this.finalize(node, new Node.Identifier(this.nextToken().value));
break;
case token_1.Token.NumericLiteral:
case token_1.Token.StringLiteral:
if (this.context.strict && this.lookahead.octal) {
this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.StrictOctalLiteral);
}
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
token = this.nextToken();
raw = this.getTokenRaw(token);
expr = this.finalize(node, new Node.Literal(token.value, raw));
break;
case token_1.Token.BooleanLiteral:
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
token = this.nextToken();
token.value = (token.value === 'true');
raw = this.getTokenRaw(token);
expr = this.finalize(node, new Node.Literal(token.value, raw));
break;
case token_1.Token.NullLiteral:
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
token = this.nextToken();
token.value = null;
raw = this.getTokenRaw(token);
expr = this.finalize(node, new Node.Literal(token.value, raw));
break;
case token_1.Token.Template:
expr = this.parseTemplateLiteral();
break;
case token_1.Token.Punctuator:
value = this.lookahead.value;
switch (value) {
case '(':
this.context.isBindingElement = false;
expr = this.inheritCoverGrammar(this.parseGroupExpression);
break;
case '[':
expr = this.inheritCoverGrammar(this.parseArrayInitializer);
break;
case '{':
expr = this.inheritCoverGrammar(this.parseObjectInitializer);
break;
case '/':
case '/=':
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
this.scanner.index = this.startMarker.index;
token = this.nextRegexToken();
raw = this.getTokenRaw(token);
expr = this.finalize(node, new Node.RegexLiteral(token.value, raw, token.regex));
break;
default:
this.throwUnexpectedToken(this.nextToken());
}
break;
case token_1.Token.Keyword:
if (!this.context.strict && this.context.allowYield && this.matchKeyword('yield')) {
expr = this.parseIdentifierName();
}
else if (!this.context.strict && this.matchKeyword('let')) {
expr = this.finalize(node, new Node.Identifier(this.nextToken().value));
}
else {
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
if (this.matchKeyword('function')) {
expr = this.parseFunctionExpression();
}
else if (this.matchKeyword('this')) {
this.nextToken();
expr = this.finalize(node, new Node.ThisExpression());
}
else if (this.matchKeyword('class')) {
expr = this.parseClassExpression();
}
else {
this.throwUnexpectedToken(this.nextToken());
}
}
break;
default:
this.throwUnexpectedToken(this.nextToken());
}
return expr;
};
// ECMA-262 12.2.5 Array Initializer
Parser.prototype.parseSpreadElement = function () {
var node = this.createNode();
this.expect('...');
var arg = this.inheritCoverGrammar(this.parseAssignmentExpression);
return this.finalize(node, new Node.SpreadElement(arg));
};
Parser.prototype.parseArrayInitializer = function () {
var node = this.createNode();
var elements = [];
this.expect('[');
while (!this.match(']')) {
if (this.match(',')) {
this.nextToken();
elements.push(null);
}
else if (this.match('...')) {
var element = this.parseSpreadElement();
if (!this.match(']')) {
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
this.expect(',');
}
elements.push(element);
}
else {
elements.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
if (!this.match(']')) {
this.expect(',');
}
}
}
this.expect(']');
return this.finalize(node, new Node.ArrayExpression(elements));
};
// ECMA-262 12.2.6 Object Initializer
Parser.prototype.parsePropertyMethod = function (params) {
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var previousStrict = this.context.strict;
var body = this.isolateCoverGrammar(this.parseFunctionSourceElements);
if (this.context.strict && params.firstRestricted) {
this.tolerateUnexpectedToken(params.firstRestricted, params.message);
}
if (this.context.strict && params.stricted) {
this.tolerateUnexpectedToken(params.stricted, params.message);
}
this.context.strict = previousStrict;
return body;
};
Parser.prototype.parsePropertyMethodFunction = function () {
var isGenerator = false;
var node = this.createNode();
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
var params = this.parseFormalParameters();
var method = this.parsePropertyMethod(params);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
};
Parser.prototype.parseObjectPropertyKey = function () {
var node = this.createNode();
var token = this.nextToken();
var key = null;
switch (token.type) {
case token_1.Token.StringLiteral:
case token_1.Token.NumericLiteral:
if (this.context.strict && token.octal) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictOctalLiteral);
}
var raw = this.getTokenRaw(token);
key = this.finalize(node, new Node.Literal(token.value, raw));
break;
case token_1.Token.Identifier:
case token_1.Token.BooleanLiteral:
case token_1.Token.NullLiteral:
case token_1.Token.Keyword:
key = this.finalize(node, new Node.Identifier(token.value));
break;
case token_1.Token.Punctuator:
if (token.value === '[') {
key = this.isolateCoverGrammar(this.parseAssignmentExpression);
this.expect(']');
}
else {
this.throwUnexpectedToken(token);
}
break;
default:
this.throwUnexpectedToken(token);
}
return key;
};
Parser.prototype.isPropertyKey = function (key, value) {
return (key.type === syntax_1.Syntax.Identifier && key.name === value) ||
(key.type === syntax_1.Syntax.Literal && key.value === value);
};
Parser.prototype.parseObjectProperty = function (hasProto) {
var node = this.createNode();
var token = this.lookahead;
var kind;
var key;
var value;
var computed = false;
var method = false;
var shorthand = false;
if (token.type === token_1.Token.Identifier) {
this.nextToken();
key = this.finalize(node, new Node.Identifier(token.value));
}
else if (this.match('*')) {
this.nextToken();
}
else {
computed = this.match('[');
key = this.parseObjectPropertyKey();
}
var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
if (token.type === token_1.Token.Identifier && token.value === 'get' && lookaheadPropertyKey) {
kind = 'get';
computed = this.match('[');
key = this.parseObjectPropertyKey();
this.context.allowYield = false;
value = this.parseGetterMethod();
}
else if (token.type === token_1.Token.Identifier && token.value === 'set' && lookaheadPropertyKey) {
kind = 'set';
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseSetterMethod();
}
else if (token.type === token_1.Token.Punctuator && token.value === '*' && lookaheadPropertyKey) {
kind = 'init';
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseGeneratorMethod();
method = true;
}
else {
if (!key) {
this.throwUnexpectedToken(this.lookahead);
}
kind = 'init';
if (this.match(':')) {
if (!computed && this.isPropertyKey(key, '__proto__')) {
if (hasProto.value) {
this.tolerateError(messages_1.Messages.DuplicateProtoProperty);
}
hasProto.value = true;
}
this.nextToken();
value = this.inheritCoverGrammar(this.parseAssignmentExpression);
}
else if (this.match('(')) {
value = this.parsePropertyMethodFunction();
method = true;
}
else if (token.type === token_1.Token.Identifier) {
var id = this.finalize(node, new Node.Identifier(token.value));
if (this.match('=')) {
this.context.firstCoverInitializedNameError = this.lookahead;
this.nextToken();
shorthand = true;
var init = this.isolateCoverGrammar(this.parseAssignmentExpression);
value = this.finalize(node, new Node.AssignmentPattern(id, init));
}
else {
shorthand = true;
value = id;
}
}
else {
this.throwUnexpectedToken(this.nextToken());
}
}
return this.finalize(node, new Node.Property(kind, key, computed, value, method, shorthand));
};
Parser.prototype.parseObjectInitializer = function () {
var node = this.createNode();
this.expect('{');
var properties = [];
var hasProto = { value: false };
while (!this.match('}')) {
properties.push(this.parseObjectProperty(hasProto));
if (!this.match('}')) {
this.expectCommaSeparator();
}
}
this.expect('}');
return this.finalize(node, new Node.ObjectExpression(properties));
};
// ECMA-262 12.2.9 Template Literals
Parser.prototype.parseTemplateHead = function () {
assert_1.assert(this.lookahead.head, 'Template literal must start with a template head');
var node = this.createNode();
var token = this.nextToken();
var value = {
raw: token.value.raw,
cooked: token.value.cooked
};
return this.finalize(node, new Node.TemplateElement(value, token.tail));
};
Parser.prototype.parseTemplateElement = function () {
if (this.lookahead.type !== token_1.Token.Template) {
this.throwUnexpectedToken();
}
var node = this.createNode();
var token = this.nextToken();
var value = {
raw: token.value.raw,
cooked: token.value.cooked
};
return this.finalize(node, new Node.TemplateElement(value, token.tail));
};
Parser.prototype.parseTemplateLiteral = function () {
var node = this.createNode();
var expressions = [];
var quasis = [];
var quasi = this.parseTemplateHead();
quasis.push(quasi);
while (!quasi.tail) {
expressions.push(this.parseExpression());
quasi = this.parseTemplateElement();
quasis.push(quasi);
}
return this.finalize(node, new Node.TemplateLiteral(quasis, expressions));
};
// ECMA-262 12.2.10 The Grouping Operator
Parser.prototype.reinterpretExpressionAsPattern = function (expr) {
switch (expr.type) {
case syntax_1.Syntax.Identifier:
case syntax_1.Syntax.MemberExpression:
case syntax_1.Syntax.RestElement:
case syntax_1.Syntax.AssignmentPattern:
break;
case syntax_1.Syntax.SpreadElement:
expr.type = syntax_1.Syntax.RestElement;
this.reinterpretExpressionAsPattern(expr.argument);
break;
case syntax_1.Syntax.ArrayExpression:
expr.type = syntax_1.Syntax.ArrayPattern;
for (var i = 0; i < expr.elements.length; i++) {
if (expr.elements[i] !== null) {
this.reinterpretExpressionAsPattern(expr.elements[i]);
}
}
break;
case syntax_1.Syntax.ObjectExpression:
expr.type = syntax_1.Syntax.ObjectPattern;
for (var i = 0; i < expr.properties.length; i++) {
this.reinterpretExpressionAsPattern(expr.properties[i].value);
}
break;
case syntax_1.Syntax.AssignmentExpression:
expr.type = syntax_1.Syntax.AssignmentPattern;
delete expr.operator;
this.reinterpretExpressionAsPattern(expr.left);
break;
default:
// Allow other node type for tolerant parsing.
break;
}
};
Parser.prototype.parseGroupExpression = function () {
var expr;
this.expect('(');
if (this.match(')')) {
this.nextToken();
if (!this.match('=>')) {
this.expect('=>');
}
expr = {
type: ArrowParameterPlaceHolder,
params: []
};
}
else {
var startToken = this.lookahead;
var params = [];
if (this.match('...')) {
expr = this.parseRestElement(params);
this.expect(')');
if (!this.match('=>')) {
this.expect('=>');
}
expr = {
type: ArrowParameterPlaceHolder,
params: [expr]
};
}
else {
var arrow = false;
this.context.isBindingElement = true;
expr = this.inheritCoverGrammar(this.parseAssignmentExpression);
if (this.match(',')) {
var expressions = [];
this.context.isAssignmentTarget = false;
expressions.push(expr);
while (this.startMarker.index < this.scanner.length) {
if (!this.match(',')) {
break;
}
this.nextToken();
if (this.match('...')) {
if (!this.context.isBindingElement) {
this.throwUnexpectedToken(this.lookahead);
}
expressions.push(this.parseRestElement(params));
this.expect(')');
if (!this.match('=>')) {
this.expect('=>');
}
this.context.isBindingElement = false;
for (var i = 0; i < expressions.length; i++) {
this.reinterpretExpressionAsPattern(expressions[i]);
}
arrow = true;
expr = {
type: ArrowParameterPlaceHolder,
params: expressions
};
}
else {
expressions.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
}
if (arrow) {
break;
}
}
if (!arrow) {
expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
}
}
if (!arrow) {
this.expect(')');
if (this.match('=>')) {
if (expr.type === syntax_1.Syntax.Identifier && expr.name === 'yield') {
arrow = true;
expr = {
type: ArrowParameterPlaceHolder,
params: [expr]
};
}
if (!arrow) {
if (!this.context.isBindingElement) {
this.throwUnexpectedToken(this.lookahead);
}
if (expr.type === syntax_1.Syntax.SequenceExpression) {
for (var i = 0; i < expr.expressions.length; i++) {
this.reinterpretExpressionAsPattern(expr.expressions[i]);
}
}
else {
this.reinterpretExpressionAsPattern(expr);
}
var params_1 = (expr.type === syntax_1.Syntax.SequenceExpression ? expr.expressions : [expr]);
expr = {
type: ArrowParameterPlaceHolder,
params: params_1
};
}
}
this.context.isBindingElement = false;
}
}
}
return expr;
};
// ECMA-262 12.3 Left-Hand-Side Expressions
Parser.prototype.parseArguments = function () {
this.expect('(');
var args = [];
if (!this.match(')')) {
while (true) {
var expr = this.match('...') ? this.parseSpreadElement() :
this.isolateCoverGrammar(this.parseAssignmentExpression);
args.push(expr);
if (this.match(')')) {
break;
}
this.expectCommaSeparator();
}
}
this.expect(')');
return args;
};
Parser.prototype.isIdentifierName = function (token) {
return token.type === token_1.Token.Identifier ||
token.type === token_1.Token.Keyword ||
token.type === token_1.Token.BooleanLiteral ||
token.type === token_1.Token.NullLiteral;
};
Parser.prototype.parseIdentifierName = function () {
var node = this.createNode();
var token = this.nextToken();
if (!this.isIdentifierName(token)) {
this.throwUnexpectedToken(token);
}
return this.finalize(node, new Node.Identifier(token.value));
};
Parser.prototype.parseNewExpression = function () {
var node = this.createNode();
var id = this.parseIdentifierName();
assert_1.assert(id.name === 'new', 'New expression must start with `new`');
var expr;
if (this.match('.')) {
this.nextToken();
if (this.lookahead.type === token_1.Token.Identifier && this.context.inFunctionBody && this.lookahead.value === 'target') {
var property = this.parseIdentifierName();
expr = new Node.MetaProperty(id, property);
}
else {
this.throwUnexpectedToken(this.lookahead);
}
}
else {
var callee = this.isolateCoverGrammar(this.parseLeftHandSideExpression);
var args = this.match('(') ? this.parseArguments() : [];
expr = new Node.NewExpression(callee, args);
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
}
return this.finalize(node, expr);
};
Parser.prototype.parseLeftHandSideExpressionAllowCall = function () {
var startToken = this.lookahead;
var previousAllowIn = this.context.allowIn;
this.context.allowIn = true;
var expr;
if (this.matchKeyword('super') && this.context.inFunctionBody) {
expr = this.createNode();
this.nextToken();
expr = this.finalize(expr, new Node.Super());
if (!this.match('(') && !this.match('.') && !this.match('[')) {
this.throwUnexpectedToken(this.lookahead);
}
}
else {
expr = this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
}
while (true) {
if (this.match('.')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
this.expect('.');
var property = this.parseIdentifierName();
expr = this.finalize(this.startNode(startToken), new Node.StaticMemberExpression(expr, property));
}
else if (this.match('(')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = false;
var args = this.parseArguments();
expr = this.finalize(this.startNode(startToken), new Node.CallExpression(expr, args));
}
else if (this.match('[')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
this.expect('[');
var property = this.isolateCoverGrammar(this.parseExpression);
this.expect(']');
expr = this.finalize(this.startNode(startToken), new Node.ComputedMemberExpression(expr, property));
}
else if (this.lookahead.type === token_1.Token.Template && this.lookahead.head) {
var quasi = this.parseTemplateLiteral();
expr = this.finalize(this.startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi));
}
else {
break;
}
}
this.context.allowIn = previousAllowIn;
return expr;
};
Parser.prototype.parseSuper = function () {
var node = this.createNode();
this.expectKeyword('super');
if (!this.match('[') && !this.match('.')) {
this.throwUnexpectedToken(this.lookahead);
}
return this.finalize(node, new Node.Super());
};
Parser.prototype.parseLeftHandSideExpression = function () {
assert_1.assert(this.context.allowIn, 'callee of new expression always allow in keyword.');
var node = this.startNode(this.lookahead);
var expr = (this.matchKeyword('super') && this.context.inFunctionBody) ? this.parseSuper() :
this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
while (true) {
if (this.match('[')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
this.expect('[');
var property = this.isolateCoverGrammar(this.parseExpression);
this.expect(']');
expr = this.finalize(node, new Node.ComputedMemberExpression(expr, property));
}
else if (this.match('.')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
this.expect('.');
var property = this.parseIdentifierName();
expr = this.finalize(node, new Node.StaticMemberExpression(expr, property));
}
else if (this.lookahead.type === token_1.Token.Template && this.lookahead.head) {
var quasi = this.parseTemplateLiteral();
expr = this.finalize(node, new Node.TaggedTemplateExpression(expr, quasi));
}
else {
break;
}
}
return expr;
};
// ECMA-262 12.4 Update Expressions
Parser.prototype.parseUpdateExpression = function () {
var expr;
var startToken = this.lookahead;
if (this.match('++') || this.match('--')) {
var node = this.startNode(startToken);
var token = this.nextToken();
expr = this.inheritCoverGrammar(this.parseUnaryExpression);
if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
this.tolerateError(messages_1.Messages.StrictLHSPrefix);
}
if (!this.context.isAssignmentTarget) {
this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
}
var prefix = true;
expr = this.finalize(node, new Node.UpdateExpression(token.value, expr, prefix));
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
}
else {
expr = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
if (!this.hasLineTerminator && this.lookahead.type === token_1.Token.Punctuator) {
if (this.match('++') || this.match('--')) {
if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
this.tolerateError(messages_1.Messages.StrictLHSPostfix);
}
if (!this.context.isAssignmentTarget) {
this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
}
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var operator = this.nextToken().value;
var prefix = false;
expr = this.finalize(this.startNode(startToken), new Node.UpdateExpression(operator, expr, prefix));
}
}
}
return expr;
};
// ECMA-262 12.5 Unary Operators
Parser.prototype.parseUnaryExpression = function () {
var expr;
if (this.match('+') || this.match('-') || this.match('~') || this.match('!') ||
this.matchKeyword('delete') || this.matchKeyword('void') || this.matchKeyword('typeof')) {
var node = this.startNode(this.lookahead);
var token = this.nextToken();
expr = this.inheritCoverGrammar(this.parseUnaryExpression);
expr = this.finalize(node, new Node.UnaryExpression(token.value, expr));
if (this.context.strict && expr.operator === 'delete' && expr.argument.type === syntax_1.Syntax.Identifier) {
this.tolerateError(messages_1.Messages.StrictDelete);
}
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
}
else {
expr = this.parseUpdateExpression();
}
return expr;
};
Parser.prototype.parseExponentiationExpression = function () {
var startToken = this.lookahead;
var expr = this.inheritCoverGrammar(this.parseUnaryExpression);
if (expr.type !== syntax_1.Syntax.UnaryExpression && this.match('**')) {
this.nextToken();
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var left = expr;
var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
expr = this.finalize(this.startNode(startToken), new Node.BinaryExpression('**', left, right));
}
return expr;
};
// ECMA-262 12.6 Exponentiation Operators
// ECMA-262 12.7 Multiplicative Operators
// ECMA-262 12.8 Additive Operators
// ECMA-262 12.9 Bitwise Shift Operators
// ECMA-262 12.10 Relational Operators
// ECMA-262 12.11 Equality Operators
// ECMA-262 12.12 Binary Bitwise Operators
// ECMA-262 12.13 Binary Logical Operators
Parser.prototype.binaryPrecedence = function (token) {
var op = token.value;
var precedence;
if (token.type === token_1.Token.Punctuator) {
precedence = this.operatorPrecedence[op] || 0;
}
else if (token.type === token_1.Token.Keyword) {
precedence = (op === 'instanceof' || (this.context.allowIn && op === 'in')) ? 7 : 0;
}
else {
precedence = 0;
}
return precedence;
};
Parser.prototype.parseBinaryExpression = function () {
var startToken = this.lookahead;
var expr = this.inheritCoverGrammar(this.parseExponentiationExpression);
var token = this.lookahead;
var prec = this.binaryPrecedence(token);
if (prec > 0) {
this.nextToken();
token.prec = prec;
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var markers = [startToken, this.lookahead];
var left = expr;
var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
var stack = [left, token, right];
while (true) {
prec = this.binaryPrecedence(this.lookahead);
if (prec <= 0) {
break;
}
// Reduce: make a binary expression from the three topmost entries.
while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
right = stack.pop();
var operator = stack.pop().value;
left = stack.pop();
markers.pop();
var node = this.startNode(markers[markers.length - 1]);
stack.push(this.finalize(node, new Node.BinaryExpression(operator, left, right)));
}
// Shift.
token = this.nextToken();
token.prec = prec;
stack.push(token);
markers.push(this.lookahead);
stack.push(this.isolateCoverGrammar(this.parseExponentiationExpression));
}
// Final reduce to clean-up the stack.
var i = stack.length - 1;
expr = stack[i];
markers.pop();
while (i > 1) {
var node = this.startNode(markers.pop());
expr = this.finalize(node, new Node.BinaryExpression(stack[i - 1].value, stack[i - 2], expr));
i -= 2;
}
}
return expr;
};
// ECMA-262 12.14 Conditional Operator
Parser.prototype.parseConditionalExpression = function () {
var startToken = this.lookahead;
var expr = this.inheritCoverGrammar(this.parseBinaryExpression);
if (this.match('?')) {
this.nextToken();
var previousAllowIn = this.context.allowIn;
this.context.allowIn = true;
var consequent = this.isolateCoverGrammar(this.parseAssignmentExpression);
this.context.allowIn = previousAllowIn;
this.expect(':');
var alternate = this.isolateCoverGrammar(this.parseAssignmentExpression);
expr = this.finalize(this.startNode(startToken), new Node.ConditionalExpression(expr, consequent, alternate));
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
}
return expr;
};
// ECMA-262 12.15 Assignment Operators
Parser.prototype.checkPatternParam = function (options, param) {
switch (param.type) {
case syntax_1.Syntax.Identifier:
this.validateParam(options, param, param.name);
break;
case syntax_1.Syntax.RestElement:
this.checkPatternParam(options, param.argument);
break;
case syntax_1.Syntax.AssignmentPattern:
this.checkPatternParam(options, param.left);
break;
case syntax_1.Syntax.ArrayPattern:
for (var i = 0; i < param.elements.length; i++) {
if (param.elements[i] !== null) {
this.checkPatternParam(options, param.elements[i]);
}
}
break;
case syntax_1.Syntax.YieldExpression:
break;
default:
assert_1.assert(param.type === syntax_1.Syntax.ObjectPattern, 'Invalid type');
for (var i = 0; i < param.properties.length; i++) {
this.checkPatternParam(options, param.properties[i].value);
}
break;
}
};
Parser.prototype.reinterpretAsCoverFormalsList = function (expr) {
var params = [expr];
var options;
switch (expr.type) {
case syntax_1.Syntax.Identifier:
break;
case ArrowParameterPlaceHolder:
params = expr.params;
break;
default:
return null;
}
options = {
paramSet: {}
};
for (var i = 0; i < params.length; ++i) {
var param = params[i];
if (param.type === syntax_1.Syntax.AssignmentPattern) {
if (param.right.type === syntax_1.Syntax.YieldExpression) {
if (param.right.argument) {
this.throwUnexpectedToken(this.lookahead);
}
param.right.type = syntax_1.Syntax.Identifier;
param.right.name = 'yield';
delete param.right.argument;
delete param.right.delegate;
}
}
this.checkPatternParam(options, param);
params[i] = param;
}
if (this.context.strict || !this.context.allowYield) {
for (var i = 0; i < params.length; ++i) {
var param = params[i];
if (param.type === syntax_1.Syntax.YieldExpression) {
this.throwUnexpectedToken(this.lookahead);
}
}
}
if (options.message === messages_1.Messages.StrictParamDupe) {
var token = this.context.strict ? options.stricted : options.firstRestricted;
this.throwUnexpectedToken(token, options.message);
}
return {
params: params,
stricted: options.stricted,
firstRestricted: options.firstRestricted,
message: options.message
};
};
Parser.prototype.parseAssignmentExpression = function () {
var expr;
if (!this.context.allowYield && this.matchKeyword('yield')) {
expr = this.parseYieldExpression();
}
else {
var startToken = this.lookahead;
var token = startToken;
expr = this.parseConditionalExpression();
if (expr.type === ArrowParameterPlaceHolder || this.match('=>')) {
// ECMA-262 14.2 Arrow Function Definitions
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var list = this.reinterpretAsCoverFormalsList(expr);
if (list) {
if (this.hasLineTerminator) {
this.tolerateUnexpectedToken(this.lookahead);
}
this.context.firstCoverInitializedNameError = null;
var previousStrict = this.context.strict;
var previousAllowYield = this.context.allowYield;
this.context.allowYield = true;
var node = this.startNode(startToken);
this.expect('=>');
var body = this.match('{') ? this.parseFunctionSourceElements() :
this.isolateCoverGrammar(this.parseAssignmentExpression);
var expression = body.type !== syntax_1.Syntax.BlockStatement;
if (this.context.strict && list.firstRestricted) {
this.throwUnexpectedToken(list.firstRestricted, list.message);
}
if (this.context.strict && list.stricted) {
this.tolerateUnexpectedToken(list.stricted, list.message);
}
expr = this.finalize(node, new Node.ArrowFunctionExpression(list.params, body, expression));
this.context.strict = previousStrict;
this.context.allowYield = previousAllowYield;
}
}
else {
if (this.matchAssign()) {
if (!this.context.isAssignmentTarget) {
this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
}
if (this.context.strict && expr.type === syntax_1.Syntax.Identifier) {
var id = (expr);
if (this.scanner.isRestrictedWord(id.name)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictLHSAssignment);
}
if (this.scanner.isStrictModeReservedWord(id.name)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
}
}
if (!this.match('=')) {
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
}
else {
this.reinterpretExpressionAsPattern(expr);
}
token = this.nextToken();
var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
expr = this.finalize(this.startNode(startToken), new Node.AssignmentExpression(token.value, expr, right));
this.context.firstCoverInitializedNameError = null;
}
}
}
return expr;
};
// ECMA-262 12.16 Comma Operator
Parser.prototype.parseExpression = function () {
var startToken = this.lookahead;
var expr = this.isolateCoverGrammar(this.parseAssignmentExpression);
if (this.match(',')) {
var expressions = [];
expressions.push(expr);
while (this.startMarker.index < this.scanner.length) {
if (!this.match(',')) {
break;
}
this.nextToken();
expressions.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
}
expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
}
return expr;
};
// ECMA-262 13.2 Block
Parser.prototype.parseStatementListItem = function () {
var statement = null;
this.context.isAssignmentTarget = true;
this.context.isBindingElement = true;
if (this.lookahead.type === token_1.Token.Keyword) {
switch (this.lookahead.value) {
case 'export':
if (this.sourceType !== 'module') {
this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalExportDeclaration);
}
statement = this.parseExportDeclaration();
break;
case 'import':
if (this.sourceType !== 'module') {
this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalImportDeclaration);
}
statement = this.parseImportDeclaration();
break;
case 'const':
statement = this.parseLexicalDeclaration({ inFor: false });
break;
case 'function':
statement = this.parseFunctionDeclaration();
break;
case 'class':
statement = this.parseClassDeclaration();
break;
case 'let':
statement = this.isLexicalDeclaration() ? this.parseLexicalDeclaration({ inFor: false }) : this.parseStatement();
break;
default:
statement = this.parseStatement();
break;
}
}
else {
statement = this.parseStatement();
}
return statement;
};
Parser.prototype.parseBlock = function () {
var node = this.createNode();
this.expect('{');
var block = [];
while (true) {
if (this.match('}')) {
break;
}
block.push(this.parseStatementListItem());
}
this.expect('}');
return this.finalize(node, new Node.BlockStatement(block));
};
// ECMA-262 13.3.1 Let and Const Declarations
Parser.prototype.parseLexicalBinding = function (kind, options) {
var node = this.createNode();
var params = [];
var id = this.parsePattern(params, kind);
// ECMA-262 12.2.1
if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
if (this.scanner.isRestrictedWord((id).name)) {
this.tolerateError(messages_1.Messages.StrictVarName);
}
}
var init = null;
if (kind === 'const') {
if (!this.matchKeyword('in') && !this.matchContextualKeyword('of')) {
this.expect('=');
init = this.isolateCoverGrammar(this.parseAssignmentExpression);
}
}
else if ((!options.inFor && id.type !== syntax_1.Syntax.Identifier) || this.match('=')) {
this.expect('=');
init = this.isolateCoverGrammar(this.parseAssignmentExpression);
}
return this.finalize(node, new Node.VariableDeclarator(id, init));
};
Parser.prototype.parseBindingList = function (kind, options) {
var list = [this.parseLexicalBinding(kind, options)];
while (this.match(',')) {
this.nextToken();
list.push(this.parseLexicalBinding(kind, options));
}
return list;
};
Parser.prototype.isLexicalDeclaration = function () {
var previousIndex = this.scanner.index;
var previousLineNumber = this.scanner.lineNumber;
var previousLineStart = this.scanner.lineStart;
this.collectComments();
var next = this.scanner.lex();
this.scanner.index = previousIndex;
this.scanner.lineNumber = previousLineNumber;
this.scanner.lineStart = previousLineStart;
return (next.type === token_1.Token.Identifier) ||
(next.type === token_1.Token.Punctuator && next.value === '[') ||
(next.type === token_1.Token.Punctuator && next.value === '{') ||
(next.type === token_1.Token.Keyword && next.value === 'let') ||
(next.type === token_1.Token.Keyword && next.value === 'yield');
};
Parser.prototype.parseLexicalDeclaration = function (options) {
var node = this.createNode();
var kind = this.nextToken().value;
assert_1.assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');
var declarations = this.parseBindingList(kind, options);
this.consumeSemicolon();
return this.finalize(node, new Node.VariableDeclaration(declarations, kind));
};
// ECMA-262 13.3.3 Destructuring Binding Patterns
Parser.prototype.parseBindingRestElement = function (params, kind) {
var node = this.createNode();
this.expect('...');
params.push(this.lookahead);
var arg = this.parseVariableIdentifier(kind);
return this.finalize(node, new Node.RestElement(arg));
};
Parser.prototype.parseArrayPattern = function (params, kind) {
var node = this.createNode();
this.expect('[');
var elements = [];
while (!this.match(']')) {
if (this.match(',')) {
this.nextToken();
elements.push(null);
}
else {
if (this.match('...')) {
elements.push(this.parseBindingRestElement(params, kind));
break;
}
else {
elements.push(this.parsePatternWithDefault(params, kind));
}
if (!this.match(']')) {
this.expect(',');
}
}
}
this.expect(']');
return this.finalize(node, new Node.ArrayPattern(elements));
};
Parser.prototype.parsePropertyPattern = function (params, kind) {
var node = this.createNode();
var computed = false;
var shorthand = false;
var method = false;
var key;
var value;
if (this.lookahead.type === token_1.Token.Identifier) {
var keyToken = this.lookahead;
key = this.parseVariableIdentifier();
var init = this.finalize(node, new Node.Identifier(keyToken.value));
if (this.match('=')) {
params.push(keyToken);
shorthand = true;
this.nextToken();
var expr = this.parseAssignmentExpression();
value = this.finalize(this.startNode(keyToken), new Node.AssignmentPattern(init, expr));
}
else if (!this.match(':')) {
params.push(keyToken);
shorthand = true;
value = init;
}
else {
this.expect(':');
value = this.parsePatternWithDefault(params, kind);
}
}
else {
computed = this.match('[');
key = this.parseObjectPropertyKey();
this.expect(':');
value = this.parsePatternWithDefault(params, kind);
}
return this.finalize(node, new Node.Property('init', key, computed, value, method, shorthand));
};
Parser.prototype.parseObjectPattern = function (params, kind) {
var node = this.createNode();
var properties = [];
this.expect('{');
while (!this.match('}')) {
properties.push(this.parsePropertyPattern(params, kind));
if (!this.match('}')) {
this.expect(',');
}
}
this.expect('}');
return this.finalize(node, new Node.ObjectPattern(properties));
};
Parser.prototype.parsePattern = function (params, kind) {
var pattern;
if (this.match('[')) {
pattern = this.parseArrayPattern(params, kind);
}
else if (this.match('{')) {
pattern = this.parseObjectPattern(params, kind);
}
else {
if (this.matchKeyword('let') && (kind === 'const' || kind === 'let')) {
this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.UnexpectedToken);
}
params.push(this.lookahead);
pattern = this.parseVariableIdentifier(kind);
}
return pattern;
};
Parser.prototype.parsePatternWithDefault = function (params, kind) {
var startToken = this.lookahead;
var pattern = this.parsePattern(params, kind);
if (this.match('=')) {
this.nextToken();
var previousAllowYield = this.context.allowYield;
this.context.allowYield = true;
var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
this.context.allowYield = previousAllowYield;
pattern = this.finalize(this.startNode(startToken), new Node.AssignmentPattern(pattern, right));
}
return pattern;
};
// ECMA-262 13.3.2 Variable Statement
Parser.prototype.parseVariableIdentifier = function (kind) {
var node = this.createNode();
var token = this.nextToken();
if (token.type === token_1.Token.Keyword && token.value === 'yield') {
if (this.context.strict) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
}
if (!this.context.allowYield) {
this.throwUnexpectedToken(token);
}
}
else if (token.type !== token_1.Token.Identifier) {
if (this.context.strict && token.type === token_1.Token.Keyword && this.scanner.isStrictModeReservedWord(token.value)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
}
else {
if (this.context.strict || token.value !== 'let' || kind !== 'var') {
this.throwUnexpectedToken(token);
}
}
}
else if (this.sourceType === 'module' && token.type === token_1.Token.Identifier && token.value === 'await') {
this.tolerateUnexpectedToken(token);
}
return this.finalize(node, new Node.Identifier(token.value));
};
Parser.prototype.parseVariableDeclaration = function (options) {
var node = this.createNode();
var params = [];
var id = this.parsePattern(params, 'var');
// ECMA-262 12.2.1
if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
if (this.scanner.isRestrictedWord((id).name)) {
this.tolerateError(messages_1.Messages.StrictVarName);
}
}
var init = null;
if (this.match('=')) {
this.nextToken();
init = this.isolateCoverGrammar(this.parseAssignmentExpression);
}
else if (id.type !== syntax_1.Syntax.Identifier && !options.inFor) {
this.expect('=');
}
return this.finalize(node, new Node.VariableDeclarator(id, init));
};
Parser.prototype.parseVariableDeclarationList = function (options) {
var opt = { inFor: options.inFor };
var list = [];
list.push(this.parseVariableDeclaration(opt));
while (this.match(',')) {
this.nextToken();
list.push(this.parseVariableDeclaration(opt));
}
return list;
};
Parser.prototype.parseVariableStatement = function () {
var node = this.createNode();
this.expectKeyword('var');
var declarations = this.parseVariableDeclarationList({ inFor: false });
this.consumeSemicolon();
return this.finalize(node, new Node.VariableDeclaration(declarations, 'var'));
};
// ECMA-262 13.4 Empty Statement
Parser.prototype.parseEmptyStatement = function () {
var node = this.createNode();
this.expect(';');
return this.finalize(node, new Node.EmptyStatement());
};
// ECMA-262 13.5 Expression Statement
Parser.prototype.parseExpressionStatement = function () {
var node = this.createNode();
var expr = this.parseExpression();
this.consumeSemicolon();
return this.finalize(node, new Node.ExpressionStatement(expr));
};
// ECMA-262 13.6 If statement
Parser.prototype.parseIfStatement = function () {
var node = this.createNode();
var consequent;
var alternate = null;
this.expectKeyword('if');
this.expect('(');
var test = this.parseExpression();
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
consequent = this.finalize(this.createNode(), new Node.EmptyStatement());
}
else {
this.expect(')');
consequent = this.parseStatement();
if (this.matchKeyword('else')) {
this.nextToken();
alternate = this.parseStatement();
}
}
return this.finalize(node, new Node.IfStatement(test, consequent, alternate));
};
// ECMA-262 13.7.2 The do-while Statement
Parser.prototype.parseDoWhileStatement = function () {
var node = this.createNode();
this.expectKeyword('do');
var previousInIteration = this.context.inIteration;
this.context.inIteration = true;
var body = this.parseStatement();
this.context.inIteration = previousInIteration;
this.expectKeyword('while');
this.expect('(');
var test = this.parseExpression();
this.expect(')');
if (this.match(';')) {
this.nextToken();
}
return this.finalize(node, new Node.DoWhileStatement(body, test));
};
// ECMA-262 13.7.3 The while Statement
Parser.prototype.parseWhileStatement = function () {
var node = this.createNode();
var body;
this.expectKeyword('while');
this.expect('(');
var test = this.parseExpression();
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
body = this.finalize(this.createNode(), new Node.EmptyStatement());
}
else {
this.expect(')');
var previousInIteration = this.context.inIteration;
this.context.inIteration = true;
body = this.parseStatement();
this.context.inIteration = previousInIteration;
}
return this.finalize(node, new Node.WhileStatement(test, body));
};
// ECMA-262 13.7.4 The for Statement
// ECMA-262 13.7.5 The for-in and for-of Statements
Parser.prototype.parseForStatement = function () {
var init = null;
var test = null;
var update = null;
var forIn = true;
var left, right;
var node = this.createNode();
this.expectKeyword('for');
this.expect('(');
if (this.match(';')) {
this.nextToken();
}
else {
if (this.matchKeyword('var')) {
init = this.createNode();
this.nextToken();
var previousAllowIn = this.context.allowIn;
this.context.allowIn = false;
var declarations = this.parseVariableDeclarationList({ inFor: true });
this.context.allowIn = previousAllowIn;
if (declarations.length === 1 && this.matchKeyword('in')) {
var decl = declarations[0];
if (decl.init && (decl.id.type === syntax_1.Syntax.ArrayPattern || decl.id.type === syntax_1.Syntax.ObjectPattern || this.context.strict)) {
this.tolerateError(messages_1.Messages.ForInOfLoopInitializer, 'for-in');
}
init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
this.nextToken();
left = init;
right = this.parseExpression();
init = null;
}
else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
this.nextToken();
left = init;
right = this.parseAssignmentExpression();
init = null;
forIn = false;
}
else {
init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
this.expect(';');
}
}
else if (this.matchKeyword('const') || this.matchKeyword('let')) {
init = this.createNode();
var kind = this.nextToken().value;
if (!this.context.strict && this.lookahead.value === 'in') {
init = this.finalize(init, new Node.Identifier(kind));
this.nextToken();
left = init;
right = this.parseExpression();
init = null;
}
else {
var previousAllowIn = this.context.allowIn;
this.context.allowIn = false;
var declarations = this.parseBindingList(kind, { inFor: true });
this.context.allowIn = previousAllowIn;
if (declarations.length === 1 && declarations[0].init === null && this.matchKeyword('in')) {
init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
this.nextToken();
left = init;
right = this.parseExpression();
init = null;
}
else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
this.nextToken();
left = init;
right = this.parseAssignmentExpression();
init = null;
forIn = false;
}
else {
this.consumeSemicolon();
init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
}
}
}
else {
var initStartToken = this.lookahead;
var previousAllowIn = this.context.allowIn;
this.context.allowIn = false;
init = this.inheritCoverGrammar(this.parseAssignmentExpression);
this.context.allowIn = previousAllowIn;
if (this.matchKeyword('in')) {
if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
this.tolerateError(messages_1.Messages.InvalidLHSInForIn);
}
this.nextToken();
this.reinterpretExpressionAsPattern(init);
left = init;
right = this.parseExpression();
init = null;
}
else if (this.matchContextualKeyword('of')) {
if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
this.tolerateError(messages_1.Messages.InvalidLHSInForLoop);
}
this.nextToken();
this.reinterpretExpressionAsPattern(init);
left = init;
right = this.parseAssignmentExpression();
init = null;
forIn = false;
}
else {
if (this.match(',')) {
var initSeq = [init];
while (this.match(',')) {
this.nextToken();
initSeq.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
}
init = this.finalize(this.startNode(initStartToken), new Node.SequenceExpression(initSeq));
}
this.expect(';');
}
}
}
if (typeof left === 'undefined') {
if (!this.match(';')) {
test = this.parseExpression();
}
this.expect(';');
if (!this.match(')')) {
update = this.parseExpression();
}
}
var body;
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
body = this.finalize(this.createNode(), new Node.EmptyStatement());
}
else {
this.expect(')');
var previousInIteration = this.context.inIteration;
this.context.inIteration = true;
body = this.isolateCoverGrammar(this.parseStatement);
this.context.inIteration = previousInIteration;
}
return (typeof left === 'undefined') ?
this.finalize(node, new Node.ForStatement(init, test, update, body)) :
forIn ? this.finalize(node, new Node.ForInStatement(left, right, body)) :
this.finalize(node, new Node.ForOfStatement(left, right, body));
};
// ECMA-262 13.8 The continue statement
Parser.prototype.parseContinueStatement = function () {
var node = this.createNode();
this.expectKeyword('continue');
var label = null;
if (this.lookahead.type === token_1.Token.Identifier && !this.hasLineTerminator) {
label = this.parseVariableIdentifier();
var key = '$' + label.name;
if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
this.throwError(messages_1.Messages.UnknownLabel, label.name);
}
}
this.consumeSemicolon();
if (label === null && !this.context.inIteration) {
this.throwError(messages_1.Messages.IllegalContinue);
}
return this.finalize(node, new Node.ContinueStatement(label));
};
// ECMA-262 13.9 The break statement
Parser.prototype.parseBreakStatement = function () {
var node = this.createNode();
this.expectKeyword('break');
var label = null;
if (this.lookahead.type === token_1.Token.Identifier && !this.hasLineTerminator) {
label = this.parseVariableIdentifier();
var key = '$' + label.name;
if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
this.throwError(messages_1.Messages.UnknownLabel, label.name);
}
}
this.consumeSemicolon();
if (label === null && !this.context.inIteration && !this.context.inSwitch) {
this.throwError(messages_1.Messages.IllegalBreak);
}
return this.finalize(node, new Node.BreakStatement(label));
};
// ECMA-262 13.10 The return statement
Parser.prototype.parseReturnStatement = function () {
if (!this.context.inFunctionBody) {
this.tolerateError(messages_1.Messages.IllegalReturn);
}
var node = this.createNode();
this.expectKeyword('return');
var hasArgument = !this.match(';') && !this.match('}') &&
!this.hasLineTerminator && this.lookahead.type !== token_1.Token.EOF;
var argument = hasArgument ? this.parseExpression() : null;
this.consumeSemicolon();
return this.finalize(node, new Node.ReturnStatement(argument));
};
// ECMA-262 13.11 The with statement
Parser.prototype.parseWithStatement = function () {
if (this.context.strict) {
this.tolerateError(messages_1.Messages.StrictModeWith);
}
var node = this.createNode();
this.expectKeyword('with');
this.expect('(');
var object = this.parseExpression();
this.expect(')');
var body = this.parseStatement();
return this.finalize(node, new Node.WithStatement(object, body));
};
// ECMA-262 13.12 The switch statement
Parser.prototype.parseSwitchCase = function () {
var node = this.createNode();
var test;
if (this.matchKeyword('default')) {
this.nextToken();
test = null;
}
else {
this.expectKeyword('case');
test = this.parseExpression();
}
this.expect(':');
var consequent = [];
while (true) {
if (this.match('}') || this.matchKeyword('default') || this.matchKeyword('case')) {
break;
}
consequent.push(this.parseStatementListItem());
}
return this.finalize(node, new Node.SwitchCase(test, consequent));
};
Parser.prototype.parseSwitchStatement = function () {
var node = this.createNode();
this.expectKeyword('switch');
this.expect('(');
var discriminant = this.parseExpression();
this.expect(')');
var previousInSwitch = this.context.inSwitch;
this.context.inSwitch = true;
var cases = [];
var defaultFound = false;
this.expect('{');
while (true) {
if (this.match('}')) {
break;
}
var clause = this.parseSwitchCase();
if (clause.test === null) {
if (defaultFound) {
this.throwError(messages_1.Messages.MultipleDefaultsInSwitch);
}
defaultFound = true;
}
cases.push(clause);
}
this.expect('}');
this.context.inSwitch = previousInSwitch;
return this.finalize(node, new Node.SwitchStatement(discriminant, cases));
};
// ECMA-262 13.13 Labelled Statements
Parser.prototype.parseLabelledStatement = function () {
var node = this.createNode();
var expr = this.parseExpression();
var statement;
if ((expr.type === syntax_1.Syntax.Identifier) && this.match(':')) {
this.nextToken();
var id = (expr);
var key = '$' + id.name;
if (Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
this.throwError(messages_1.Messages.Redeclaration, 'Label', id.name);
}
this.context.labelSet[key] = true;
var labeledBody = this.parseStatement();
delete this.context.labelSet[key];
statement = new Node.LabeledStatement(id, labeledBody);
}
else {
this.consumeSemicolon();
statement = new Node.ExpressionStatement(expr);
}
return this.finalize(node, statement);
};
// ECMA-262 13.14 The throw statement
Parser.prototype.parseThrowStatement = function () {
var node = this.createNode();
this.expectKeyword('throw');
if (this.hasLineTerminator) {
this.throwError(messages_1.Messages.NewlineAfterThrow);
}
var argument = this.parseExpression();
this.consumeSemicolon();
return this.finalize(node, new Node.ThrowStatement(argument));
};
// ECMA-262 13.15 The try statement
Parser.prototype.parseCatchClause = function () {
var node = this.createNode();
this.expectKeyword('catch');
this.expect('(');
if (this.match(')')) {
this.throwUnexpectedToken(this.lookahead);
}
var params = [];
var param = this.parsePattern(params);
var paramMap = {};
for (var i = 0; i < params.length; i++) {
var key = '$' + params[i].value;
if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
this.tolerateError(messages_1.Messages.DuplicateBinding, params[i].value);
}
paramMap[key] = true;
}
if (this.context.strict && param.type === syntax_1.Syntax.Identifier) {
if (this.scanner.isRestrictedWord((param).name)) {
this.tolerateError(messages_1.Messages.StrictCatchVariable);
}
}
this.expect(')');
var body = this.parseBlock();
return this.finalize(node, new Node.CatchClause(param, body));
};
Parser.prototype.parseFinallyClause = function () {
this.expectKeyword('finally');
return this.parseBlock();
};
Parser.prototype.parseTryStatement = function () {
var node = this.createNode();
this.expectKeyword('try');
var block = this.parseBlock();
var handler = this.matchKeyword('catch') ? this.parseCatchClause() : null;
var finalizer = this.matchKeyword('finally') ? this.parseFinallyClause() : null;
if (!handler && !finalizer) {
this.throwError(messages_1.Messages.NoCatchOrFinally);
}
return this.finalize(node, new Node.TryStatement(block, handler, finalizer));
};
// ECMA-262 13.16 The debugger statement
Parser.prototype.parseDebuggerStatement = function () {
var node = this.createNode();
this.expectKeyword('debugger');
this.consumeSemicolon();
return this.finalize(node, new Node.DebuggerStatement());
};
// ECMA-262 13 Statements
Parser.prototype.parseStatement = function () {
var statement = null;
switch (this.lookahead.type) {
case token_1.Token.BooleanLiteral:
case token_1.Token.NullLiteral:
case token_1.Token.NumericLiteral:
case token_1.Token.StringLiteral:
case token_1.Token.Template:
case token_1.Token.RegularExpression:
statement = this.parseExpressionStatement();
break;
case token_1.Token.Punctuator:
var value = this.lookahead.value;
if (value === '{') {
statement = this.parseBlock();
}
else if (value === '(') {
statement = this.parseExpressionStatement();
}
else if (value === ';') {
statement = this.parseEmptyStatement();
}
else {
statement = this.parseExpressionStatement();
}
break;
case token_1.Token.Identifier:
statement = this.parseLabelledStatement();
break;
case token_1.Token.Keyword:
switch (this.lookahead.value) {
case 'break':
statement = this.parseBreakStatement();
break;
case 'continue':
statement = this.parseContinueStatement();
break;
case 'debugger':
statement = this.parseDebuggerStatement();
break;
case 'do':
statement = this.parseDoWhileStatement();
break;
case 'for':
statement = this.parseForStatement();
break;
case 'function':
statement = this.parseFunctionDeclaration();
break;
case 'if':
statement = this.parseIfStatement();
break;
case 'return':
statement = this.parseReturnStatement();
break;
case 'switch':
statement = this.parseSwitchStatement();
break;
case 'throw':
statement = this.parseThrowStatement();
break;
case 'try':
statement = this.parseTryStatement();
break;
case 'var':
statement = this.parseVariableStatement();
break;
case 'while':
statement = this.parseWhileStatement();
break;
case 'with':
statement = this.parseWithStatement();
break;
default:
statement = this.parseExpressionStatement();
break;
}
break;
default:
this.throwUnexpectedToken(this.lookahead);
}
return statement;
};
// ECMA-262 14.1 Function Definition
Parser.prototype.parseFunctionSourceElements = function () {
var node = this.createNode();
this.expect('{');
var body = this.parseDirectivePrologues();
var previousLabelSet = this.context.labelSet;
var previousInIteration = this.context.inIteration;
var previousInSwitch = this.context.inSwitch;
var previousInFunctionBody = this.context.inFunctionBody;
this.context.labelSet = {};
this.context.inIteration = false;
this.context.inSwitch = false;
this.context.inFunctionBody = true;
while (this.startMarker.index < this.scanner.length) {
if (this.match('}')) {
break;
}
body.push(this.parseStatementListItem());
}
this.expect('}');
this.context.labelSet = previousLabelSet;
this.context.inIteration = previousInIteration;
this.context.inSwitch = previousInSwitch;
this.context.inFunctionBody = previousInFunctionBody;
return this.finalize(node, new Node.BlockStatement(body));
};
Parser.prototype.validateParam = function (options, param, name) {
var key = '$' + name;
if (this.context.strict) {
if (this.scanner.isRestrictedWord(name)) {
options.stricted = param;
options.message = messages_1.Messages.StrictParamName;
}
if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
options.stricted = param;
options.message = messages_1.Messages.StrictParamDupe;
}
}
else if (!options.firstRestricted) {
if (this.scanner.isRestrictedWord(name)) {
options.firstRestricted = param;
options.message = messages_1.Messages.StrictParamName;
}
else if (this.scanner.isStrictModeReservedWord(name)) {
options.firstRestricted = param;
options.message = messages_1.Messages.StrictReservedWord;
}
else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
options.stricted = param;
options.message = messages_1.Messages.StrictParamDupe;
}
}
/* istanbul ignore next */
if (typeof Object.defineProperty === 'function') {
Object.defineProperty(options.paramSet, key, { value: true, enumerable: true, writable: true, configurable: true });
}
else {
options.paramSet[key] = true;
}
};
Parser.prototype.parseRestElement = function (params) {
var node = this.createNode();
this.nextToken();
if (this.match('{')) {
this.throwError(messages_1.Messages.ObjectPatternAsRestParameter);
}
params.push(this.lookahead);
var param = this.parseVariableIdentifier();
if (this.match('=')) {
this.throwError(messages_1.Messages.DefaultRestParameter);
}
if (!this.match(')')) {
this.throwError(messages_1.Messages.ParameterAfterRestParameter);
}
return this.finalize(node, new Node.RestElement(param));
};
Parser.prototype.parseFormalParameter = function (options) {
var param;
var params = [];
var token = this.lookahead;
if (token.value === '...') {
param = this.parseRestElement(params);
this.validateParam(options, param.argument, param.argument.name);
options.params.push(param);
return false;
}
param = this.parsePatternWithDefault(params);
for (var i = 0; i < params.length; i++) {
this.validateParam(options, params[i], params[i].value);
}
options.params.push(param);
return !this.match(')');
};
Parser.prototype.parseFormalParameters = function (firstRestricted) {
var options;
options = {
params: [],
firstRestricted: firstRestricted
};
this.expect('(');
if (!this.match(')')) {
options.paramSet = {};
while (this.startMarker.index < this.scanner.length) {
if (!this.parseFormalParameter(options)) {
break;
}
this.expect(',');
}
}
this.expect(')');
return {
params: options.params,
stricted: options.stricted,
firstRestricted: options.firstRestricted,
message: options.message
};
};
Parser.prototype.parseFunctionDeclaration = function (identifierIsOptional) {
var node = this.createNode();
this.expectKeyword('function');
var isGenerator = this.match('*');
if (isGenerator) {
this.nextToken();
}
var message;
var id = null;
var firstRestricted = null;
if (!identifierIsOptional || !this.match('(')) {
var token = this.lookahead;
id = this.parseVariableIdentifier();
if (this.context.strict) {
if (this.scanner.isRestrictedWord(token.value)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
}
}
else {
if (this.scanner.isRestrictedWord(token.value)) {
firstRestricted = token;
message = messages_1.Messages.StrictFunctionName;
}
else if (this.scanner.isStrictModeReservedWord(token.value)) {
firstRestricted = token;
message = messages_1.Messages.StrictReservedWord;
}
}
}
var previousAllowYield = this.context.allowYield;
this.context.allowYield = !isGenerator;
var formalParameters = this.parseFormalParameters(firstRestricted);
var params = formalParameters.params;
var stricted = formalParameters.stricted;
firstRestricted = formalParameters.firstRestricted;
if (formalParameters.message) {
message = formalParameters.message;
}
var previousStrict = this.context.strict;
var body = this.parseFunctionSourceElements();
if (this.context.strict && firstRestricted) {
this.throwUnexpectedToken(firstRestricted, message);
}
if (this.context.strict && stricted) {
this.tolerateUnexpectedToken(stricted, message);
}
this.context.strict = previousStrict;
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionDeclaration(id, params, body, isGenerator));
};
Parser.prototype.parseFunctionExpression = function () {
var node = this.createNode();
this.expectKeyword('function');
var isGenerator = this.match('*');
if (isGenerator) {
this.nextToken();
}
var message;
var id = null;
var firstRestricted;
var previousAllowYield = this.context.allowYield;
this.context.allowYield = !isGenerator;
if (!this.match('(')) {
var token = this.lookahead;
id = (!this.context.strict && !isGenerator && this.matchKeyword('yield')) ? this.parseIdentifierName() : this.parseVariableIdentifier();
if (this.context.strict) {
if (this.scanner.isRestrictedWord(token.value)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
}
}
else {
if (this.scanner.isRestrictedWord(token.value)) {
firstRestricted = token;
message = messages_1.Messages.StrictFunctionName;
}
else if (this.scanner.isStrictModeReservedWord(token.value)) {
firstRestricted = token;
message = messages_1.Messages.StrictReservedWord;
}
}
}
var formalParameters = this.parseFormalParameters(firstRestricted);
var params = formalParameters.params;
var stricted = formalParameters.stricted;
firstRestricted = formalParameters.firstRestricted;
if (formalParameters.message) {
message = formalParameters.message;
}
var previousStrict = this.context.strict;
var body = this.parseFunctionSourceElements();
if (this.context.strict && firstRestricted) {
this.throwUnexpectedToken(firstRestricted, message);
}
if (this.context.strict && stricted) {
this.tolerateUnexpectedToken(stricted, message);
}
this.context.strict = previousStrict;
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(id, params, body, isGenerator));
};
// ECMA-262 14.1.1 Directive Prologues
Parser.prototype.parseDirective = function () {
var token = this.lookahead;
var directive = null;
var node = this.createNode();
var expr = this.parseExpression();
if (expr.type === syntax_1.Syntax.Literal) {
directive = this.getTokenRaw(token).slice(1, -1);
}
this.consumeSemicolon();
return this.finalize(node, directive ? new Node.Directive(expr, directive) :
new Node.ExpressionStatement(expr));
};
Parser.prototype.parseDirectivePrologues = function () {
var firstRestricted = null;
var body = [];
while (true) {
var token = this.lookahead;
if (token.type !== token_1.Token.StringLiteral) {
break;
}
var statement = this.parseDirective();
body.push(statement);
var directive = statement.directive;
if (typeof directive !== 'string') {
break;
}
if (directive === 'use strict') {
this.context.strict = true;
if (firstRestricted) {
this.tolerateUnexpectedToken(firstRestricted, messages_1.Messages.StrictOctalLiteral);
}
}
else {
if (!firstRestricted && token.octal) {
firstRestricted = token;
}
}
}
return body;
};
// ECMA-262 14.3 Method Definitions
Parser.prototype.qualifiedPropertyName = function (token) {
switch (token.type) {
case token_1.Token.Identifier:
case token_1.Token.StringLiteral:
case token_1.Token.BooleanLiteral:
case token_1.Token.NullLiteral:
case token_1.Token.NumericLiteral:
case token_1.Token.Keyword:
return true;
case token_1.Token.Punctuator:
return token.value === '[';
}
return false;
};
Parser.prototype.parseGetterMethod = function () {
var node = this.createNode();
this.expect('(');
this.expect(')');
var isGenerator = false;
var params = {
params: [],
stricted: null,
firstRestricted: null,
message: null
};
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
var method = this.parsePropertyMethod(params);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
};
Parser.prototype.parseSetterMethod = function () {
var node = this.createNode();
var options = {
params: [],
firstRestricted: null,
paramSet: {}
};
var isGenerator = false;
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
this.expect('(');
if (this.match(')')) {
this.tolerateUnexpectedToken(this.lookahead);
}
else {
this.parseFormalParameter(options);
}
this.expect(')');
var method = this.parsePropertyMethod(options);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, options.params, method, isGenerator));
};
Parser.prototype.parseGeneratorMethod = function () {
var node = this.createNode();
var isGenerator = true;
var previousAllowYield = this.context.allowYield;
this.context.allowYield = true;
var params = this.parseFormalParameters();
this.context.allowYield = false;
var method = this.parsePropertyMethod(params);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
};
// ECMA-262 14.4 Generator Function Definitions
Parser.prototype.parseYieldExpression = function () {
var node = this.createNode();
this.expectKeyword('yield');
var argument = null;
var delegate = false;
if (!this.hasLineTerminator) {
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
delegate = this.match('*');
if (delegate) {
this.nextToken();
argument = this.parseAssignmentExpression();
}
else {
if (!this.match(';') && !this.match('}') && !this.match(')') && this.lookahead.type !== token_1.Token.EOF) {
argument = this.parseAssignmentExpression();
}
}
this.context.allowYield = previousAllowYield;
}
return this.finalize(node, new Node.YieldExpression(argument, delegate));
};
// ECMA-262 14.5 Class Definitions
Parser.prototype.parseClassElement = function (hasConstructor) {
var token = this.lookahead;
var node = this.createNode();
var kind;
var key;
var value;
var computed = false;
var method = false;
var isStatic = false;
if (this.match('*')) {
this.nextToken();
}
else {
computed = this.match('[');
key = this.parseObjectPropertyKey();
var id = key;
if (id.name === 'static' && (this.qualifiedPropertyName(this.lookahead) || this.match('*'))) {
token = this.lookahead;
isStatic = true;
computed = this.match('[');
if (this.match('*')) {
this.nextToken();
}
else {
key = this.parseObjectPropertyKey();
}
}
}
var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
if (token.type === token_1.Token.Identifier) {
if (token.value === 'get' && lookaheadPropertyKey) {
kind = 'get';
computed = this.match('[');
key = this.parseObjectPropertyKey();
this.context.allowYield = false;
value = this.parseGetterMethod();
}
else if (token.value === 'set' && lookaheadPropertyKey) {
kind = 'set';
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseSetterMethod();
}
}
else if (token.type === token_1.Token.Punctuator && token.value === '*' && lookaheadPropertyKey) {
kind = 'init';
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseGeneratorMethod();
method = true;
}
if (!kind && key && this.match('(')) {
kind = 'init';
value = this.parsePropertyMethodFunction();
method = true;
}
if (!kind) {
this.throwUnexpectedToken(this.lookahead);
}
if (kind === 'init') {
kind = 'method';
}
if (!computed) {
if (isStatic && this.isPropertyKey(key, 'prototype')) {
this.throwUnexpectedToken(token, messages_1.Messages.StaticPrototype);
}
if (!isStatic && this.isPropertyKey(key, 'constructor')) {
if (kind !== 'method' || !method || value.generator) {
this.throwUnexpectedToken(token, messages_1.Messages.ConstructorSpecialMethod);
}
if (hasConstructor.value) {
this.throwUnexpectedToken(token, messages_1.Messages.DuplicateConstructor);
}
else {
hasConstructor.value = true;
}
kind = 'constructor';
}
}
return this.finalize(node, new Node.MethodDefinition(key, computed, value, kind, isStatic));
};
Parser.prototype.parseClassElementList = function () {
var body = [];
var hasConstructor = { value: false };
this.expect('{');
while (!this.match('}')) {
if (this.match(';')) {
this.nextToken();
}
else {
body.push(this.parseClassElement(hasConstructor));
}
}
this.expect('}');
return body;
};
Parser.prototype.parseClassBody = function () {
var node = this.createNode();
var elementList = this.parseClassElementList();
return this.finalize(node, new Node.ClassBody(elementList));
};
Parser.prototype.parseClassDeclaration = function (identifierIsOptional) {
var node = this.createNode();
var previousStrict = this.context.strict;
this.context.strict = true;
this.expectKeyword('class');
var id = (identifierIsOptional && (this.lookahead.type !== token_1.Token.Identifier)) ? null : this.parseVariableIdentifier();
var superClass = null;
if (this.matchKeyword('extends')) {
this.nextToken();
superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
}
var classBody = this.parseClassBody();
this.context.strict = previousStrict;
return this.finalize(node, new Node.ClassDeclaration(id, superClass, classBody));
};
Parser.prototype.parseClassExpression = function () {
var node = this.createNode();
var previousStrict = this.context.strict;
this.context.strict = true;
this.expectKeyword('class');
var id = (this.lookahead.type === token_1.Token.Identifier) ? this.parseVariableIdentifier() : null;
var superClass = null;
if (this.matchKeyword('extends')) {
this.nextToken();
superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
}
var classBody = this.parseClassBody();
this.context.strict = previousStrict;
return this.finalize(node, new Node.ClassExpression(id, superClass, classBody));
};
// ECMA-262 15.1 Scripts
// ECMA-262 15.2 Modules
Parser.prototype.parseProgram = function () {
var node = this.createNode();
var body = this.parseDirectivePrologues();
while (this.startMarker.index < this.scanner.length) {
body.push(this.parseStatementListItem());
}
return this.finalize(node, new Node.Program(body, this.sourceType));
};
// ECMA-262 15.2.2 Imports
Parser.prototype.parseModuleSpecifier = function () {
var node = this.createNode();
if (this.lookahead.type !== token_1.Token.StringLiteral) {
this.throwError(messages_1.Messages.InvalidModuleSpecifier);
}
var token = this.nextToken();
var raw = this.getTokenRaw(token);
return this.finalize(node, new Node.Literal(token.value, raw));
};
// import {<foo as bar>} ...;
Parser.prototype.parseImportSpecifier = function () {
var node = this.createNode();
var local;
var imported = this.parseIdentifierName();
if (this.matchContextualKeyword('as')) {
this.nextToken();
local = this.parseVariableIdentifier();
}
else {
local = imported;
}
return this.finalize(node, new Node.ImportSpecifier(local, imported));
};
// {foo, bar as bas}
Parser.prototype.parseNamedImports = function () {
this.expect('{');
var specifiers = [];
while (!this.match('}')) {
specifiers.push(this.parseImportSpecifier());
if (!this.match('}')) {
this.expect(',');
}
}
this.expect('}');
return specifiers;
};
// import <foo> ...;
Parser.prototype.parseImportDefaultSpecifier = function () {
var node = this.createNode();
var local = this.parseIdentifierName();
return this.finalize(node, new Node.ImportDefaultSpecifier(local));
};
// import <* as foo> ...;
Parser.prototype.parseImportNamespaceSpecifier = function () {
var node = this.createNode();
this.expect('*');
if (!this.matchContextualKeyword('as')) {
this.throwError(messages_1.Messages.NoAsAfterImportNamespace);
}
this.nextToken();
var local = this.parseIdentifierName();
return this.finalize(node, new Node.ImportNamespaceSpecifier(local));
};
Parser.prototype.parseImportDeclaration = function () {
if (this.context.inFunctionBody) {
this.throwError(messages_1.Messages.IllegalImportDeclaration);
}
var node = this.createNode();
this.expectKeyword('import');
var src;
var specifiers = [];
if (this.lookahead.type === token_1.Token.StringLiteral) {
// import 'foo';
src = this.parseModuleSpecifier();
}
else {
if (this.match('{')) {
// import {bar}
specifiers = specifiers.concat(this.parseNamedImports());
}
else if (this.match('*')) {
// import * as foo
specifiers.push(this.parseImportNamespaceSpecifier());
}
else if (this.isIdentifierName(this.lookahead) && !this.matchKeyword('default')) {
// import foo
specifiers.push(this.parseImportDefaultSpecifier());
if (this.match(',')) {
this.nextToken();
if (this.match('*')) {
// import foo, * as foo
specifiers.push(this.parseImportNamespaceSpecifier());
}
else if (this.match('{')) {
// import foo, {bar}
specifiers = specifiers.concat(this.parseNamedImports());
}
else {
this.throwUnexpectedToken(this.lookahead);
}
}
}
else {
this.throwUnexpectedToken(this.nextToken());
}
if (!this.matchContextualKeyword('from')) {
var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
this.throwError(message, this.lookahead.value);
}
this.nextToken();
src = this.parseModuleSpecifier();
}
this.consumeSemicolon();
return this.finalize(node, new Node.ImportDeclaration(specifiers, src));
};
// ECMA-262 15.2.3 Exports
Parser.prototype.parseExportSpecifier = function () {
var node = this.createNode();
var local = this.parseIdentifierName();
var exported = local;
if (this.matchContextualKeyword('as')) {
this.nextToken();
exported = this.parseIdentifierName();
}
return this.finalize(node, new Node.ExportSpecifier(local, exported));
};
Parser.prototype.parseExportDeclaration = function () {
if (this.context.inFunctionBody) {
this.throwError(messages_1.Messages.IllegalExportDeclaration);
}
var node = this.createNode();
this.expectKeyword('export');
var exportDeclaration;
if (this.matchKeyword('default')) {
// export default ...
this.nextToken();
if (this.matchKeyword('function')) {
// export default function foo () {}
// export default function () {}
var declaration = this.parseFunctionDeclaration(true);
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
}
else if (this.matchKeyword('class')) {
// export default class foo {}
var declaration = this.parseClassDeclaration(true);
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
}
else {
if (this.matchContextualKeyword('from')) {
this.throwError(messages_1.Messages.UnexpectedToken, this.lookahead.value);
}
// export default {};
// export default [];
// export default (1 + 2);
var declaration = this.match('{') ? this.parseObjectInitializer() :
this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression();
this.consumeSemicolon();
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
}
}
else if (this.match('*')) {
// export * from 'foo';
this.nextToken();
if (!this.matchContextualKeyword('from')) {
var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
this.throwError(message, this.lookahead.value);
}
this.nextToken();
var src = this.parseModuleSpecifier();
this.consumeSemicolon();
exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src));
}
else if (this.lookahead.type === token_1.Token.Keyword) {
// export var f = 1;
var declaration = void 0;
switch (this.lookahead.value) {
case 'let':
case 'const':
declaration = this.parseLexicalDeclaration({ inFor: false });
break;
case 'var':
case 'class':
case 'function':
declaration = this.parseStatementListItem();
break;
default:
this.throwUnexpectedToken(this.lookahead);
}
exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
}
else {
var specifiers = [];
var source = null;
var isExportFromIdentifier = false;
this.expect('{');
while (!this.match('}')) {
isExportFromIdentifier = isExportFromIdentifier || this.matchKeyword('default');
specifiers.push(this.parseExportSpecifier());
if (!this.match('}')) {
this.expect(',');
}
}
this.expect('}');
if (this.matchContextualKeyword('from')) {
// export {default} from 'foo';
// export {foo} from 'foo';
this.nextToken();
source = this.parseModuleSpecifier();
this.consumeSemicolon();
}
else if (isExportFromIdentifier) {
// export {default}; // missing fromClause
var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
this.throwError(message, this.lookahead.value);
}
else {
// export {foo};
this.consumeSemicolon();
}
exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(null, specifiers, source));
}
return exportDeclaration;
};
return Parser;
}());
exports.Parser = Parser;
/***/ },
/* 4 */
/***/ function(module, exports) {
// Ensure the condition is true, otherwise throw an error.
// This is only to have a better contract semantic, i.e. another safety net
// to catch a logic error. The condition shall be fulfilled in normal case.
// Do NOT use this to enforce a certain condition on any user input.
"use strict";
function assert(condition, message) {
/* istanbul ignore if */
if (!condition) {
throw new Error('ASSERT: ' + message);
}
}
exports.assert = assert;
/***/ },
/* 5 */
/***/ function(module, exports) {
"use strict";
// Error messages should be identical to V8.
exports.Messages = {
UnexpectedToken: 'Unexpected token %0',
UnexpectedTokenIllegal: 'Unexpected token ILLEGAL',
UnexpectedNumber: 'Unexpected number',
UnexpectedString: 'Unexpected string',
UnexpectedIdentifier: 'Unexpected identifier',
UnexpectedReserved: 'Unexpected reserved word',
UnexpectedTemplate: 'Unexpected quasi %0',
UnexpectedEOS: 'Unexpected end of input',
NewlineAfterThrow: 'Illegal newline after throw',
InvalidRegExp: 'Invalid regular expression',
UnterminatedRegExp: 'Invalid regular expression: missing /',
InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
InvalidLHSInForIn: 'Invalid left-hand side in for-in',
InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
NoCatchOrFinally: 'Missing catch or finally after try',
UnknownLabel: 'Undefined label \'%0\'',
Redeclaration: '%0 \'%1\' has already been declared',
IllegalContinue: 'Illegal continue statement',
IllegalBreak: 'Illegal break statement',
IllegalReturn: 'Illegal return statement',
StrictModeWith: 'Strict mode code may not include a with statement',
StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
StrictVarName: 'Variable name may not be eval or arguments in strict mode',
StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
StrictDelete: 'Delete of an unqualified identifier in strict mode.',
StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
StrictReservedWord: 'Use of future reserved word in strict mode',
TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
DefaultRestParameter: 'Unexpected token =',
ObjectPatternAsRestParameter: 'Unexpected token {',
DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
ConstructorSpecialMethod: 'Class constructor may not be an accessor',
DuplicateConstructor: 'A class may only have one constructor',
StaticPrototype: 'Classes may not have static property named prototype',
MissingFromClause: 'Unexpected token',
NoAsAfterImportNamespace: 'Unexpected token',
InvalidModuleSpecifier: 'Unexpected token',
IllegalImportDeclaration: 'Unexpected token',
IllegalExportDeclaration: 'Unexpected token',
DuplicateBinding: 'Duplicate binding %0',
ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer'
};
/***/ },
/* 6 */
/***/ function(module, exports) {
"use strict";
var ErrorHandler = (function () {
function ErrorHandler() {
this.errors = [];
this.tolerant = false;
}
;
ErrorHandler.prototype.recordError = function (error) {
this.errors.push(error);
};
;
ErrorHandler.prototype.tolerate = function (error) {
if (this.tolerant) {
this.recordError(error);
}
else {
throw error;
}
};
;
ErrorHandler.prototype.constructError = function (msg, column) {
var error = new Error(msg);
try {
throw error;
}
catch (base) {
/* istanbul ignore else */
if (Object.create && Object.defineProperty) {
error = Object.create(base);
Object.defineProperty(error, 'column', { value: column });
}
}
finally {
return error;
}
};
;
ErrorHandler.prototype.createError = function (index, line, col, description) {
var msg = 'Line ' + line + ': ' + description;
var error = this.constructError(msg, col);
error.index = index;
error.lineNumber = line;
error.description = description;
return error;
};
;
ErrorHandler.prototype.throwError = function (index, line, col, description) {
throw this.createError(index, line, col, description);
};
;
ErrorHandler.prototype.tolerateError = function (index, line, col, description) {
var error = this.createError(index, line, col, description);
if (this.tolerant) {
this.recordError(error);
}
else {
throw error;
}
};
;
return ErrorHandler;
}());
exports.ErrorHandler = ErrorHandler;
/***/ },
/* 7 */
/***/ function(module, exports) {
"use strict";
(function (Token) {
Token[Token["BooleanLiteral"] = 1] = "BooleanLiteral";
Token[Token["EOF"] = 2] = "EOF";
Token[Token["Identifier"] = 3] = "Identifier";
Token[Token["Keyword"] = 4] = "Keyword";
Token[Token["NullLiteral"] = 5] = "NullLiteral";
Token[Token["NumericLiteral"] = 6] = "NumericLiteral";
Token[Token["Punctuator"] = 7] = "Punctuator";
Token[Token["StringLiteral"] = 8] = "StringLiteral";
Token[Token["RegularExpression"] = 9] = "RegularExpression";
Token[Token["Template"] = 10] = "Template";
})(exports.Token || (exports.Token = {}));
var Token = exports.Token;
;
exports.TokenName = {};
exports.TokenName[Token.BooleanLiteral] = 'Boolean';
exports.TokenName[Token.EOF] = '<end>';
exports.TokenName[Token.Identifier] = 'Identifier';
exports.TokenName[Token.Keyword] = 'Keyword';
exports.TokenName[Token.NullLiteral] = 'Null';
exports.TokenName[Token.NumericLiteral] = 'Numeric';
exports.TokenName[Token.Punctuator] = 'Punctuator';
exports.TokenName[Token.StringLiteral] = 'String';
exports.TokenName[Token.RegularExpression] = 'RegularExpression';
exports.TokenName[Token.Template] = 'Template';
/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var assert_1 = __webpack_require__(4);
var messages_1 = __webpack_require__(5);
var character_1 = __webpack_require__(9);
var token_1 = __webpack_require__(7);
function hexValue(ch) {
return '0123456789abcdef'.indexOf(ch.toLowerCase());
}
function octalValue(ch) {
return '01234567'.indexOf(ch);
}
var Scanner = (function () {
function Scanner(code, handler) {
this.source = code;
this.errorHandler = handler;
this.trackComment = false;
this.length = code.length;
this.index = 0;
this.lineNumber = (code.length > 0) ? 1 : 0;
this.lineStart = 0;
this.curlyStack = [];
}
;
Scanner.prototype.eof = function () {
return this.index >= this.length;
};
;
Scanner.prototype.throwUnexpectedToken = function (message) {
if (message === void 0) { message = messages_1.Messages.UnexpectedTokenIllegal; }
this.errorHandler.throwError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
};
;
Scanner.prototype.tolerateUnexpectedToken = function () {
this.errorHandler.tolerateError(this.index, this.lineNumber, this.index - this.lineStart + 1, messages_1.Messages.UnexpectedTokenIllegal);
};
;
// ECMA-262 11.4 Comments
Scanner.prototype.skipSingleLineComment = function (offset) {
var comments;
var start, loc;
if (this.trackComment) {
comments = [];
start = this.index - offset;
loc = {
start: {
line: this.lineNumber,
column: this.index - this.lineStart - offset
},
end: {}
};
}
while (!this.eof()) {
var ch = this.source.charCodeAt(this.index);
++this.index;
if (character_1.Character.isLineTerminator(ch)) {
if (this.trackComment) {
loc.end = {
line: this.lineNumber,
column: this.index - this.lineStart - 1
};
var entry = {
multiLine: false,
slice: [start + offset, this.index - 1],
range: [start, this.index - 1],
loc: loc
};
comments.push(entry);
}
if (ch === 13 && this.source.charCodeAt(this.index) === 10) {
++this.index;
}
++this.lineNumber;
this.lineStart = this.index;
return comments;
}
}
if (this.trackComment) {
loc.end = {
line: this.lineNumber,
column: this.index - this.lineStart
};
var entry = {
multiLine: false,
slice: [start + offset, this.index],
range: [start, this.index],
loc: loc
};
comments.push(entry);
}
return comments;
};
;
Scanner.prototype.skipMultiLineComment = function () {
var comments;
var start, loc;
if (this.trackComment) {
comments = [];
start = this.index - 2;
loc = {
start: {
line: this.lineNumber,
column: this.index - this.lineStart - 2
},
end: {}
};
}
while (!this.eof()) {
var ch = this.source.charCodeAt(this.index);
if (character_1.Character.isLineTerminator(ch)) {
if (ch === 0x0D && this.source.charCodeAt(this.index + 1) === 0x0A) {
++this.index;
}
++this.lineNumber;
++this.index;
this.lineStart = this.index;
}
else if (ch === 0x2A) {
// Block comment ends with '*/'.
if (this.source.charCodeAt(this.index + 1) === 0x2F) {
this.index += 2;
if (this.trackComment) {
loc.end = {
line: this.lineNumber,
column: this.index - this.lineStart
};
var entry = {
multiLine: true,
slice: [start + 2, this.index - 2],
range: [start, this.index],
loc: loc
};
comments.push(entry);
}
return comments;
}
++this.index;
}
else {
++this.index;
}
}
// Ran off the end of the file - the whole thing is a comment
if (this.trackComment) {
loc.end = {
line: this.lineNumber,
column: this.index - this.lineStart
};
var entry = {
multiLine: true,
slice: [start + 2, this.index],
range: [start, this.index],
loc: loc
};
comments.push(entry);
}
this.tolerateUnexpectedToken();
return comments;
};
;
Scanner.prototype.scanComments = function () {
var comments;
if (this.trackComment) {
comments = [];
}
var start = (this.index === 0);
while (!this.eof()) {
var ch = this.source.charCodeAt(this.index);
if (character_1.Character.isWhiteSpace(ch)) {
++this.index;
}
else if (character_1.Character.isLineTerminator(ch)) {
++this.index;
if (ch === 0x0D && this.source.charCodeAt(this.index) === 0x0A) {
++this.index;
}
++this.lineNumber;
this.lineStart = this.index;
start = true;
}
else if (ch === 0x2F) {
ch = this.source.charCodeAt(this.index + 1);
if (ch === 0x2F) {
this.index += 2;
var comment = this.skipSingleLineComment(2);
if (this.trackComment) {
comments = comments.concat(comment);
}
start = true;
}
else if (ch === 0x2A) {
this.index += 2;
var comment = this.skipMultiLineComment();
if (this.trackComment) {
comments = comments.concat(comment);
}
}
else {
break;
}
}
else if (start && ch === 0x2D) {
// U+003E is '>'
if ((this.source.charCodeAt(this.index + 1) === 0x2D) && (this.source.charCodeAt(this.index + 2) === 0x3E)) {
// '-->' is a single-line comment
this.index += 3;
var comment = this.skipSingleLineComment(3);
if (this.trackComment) {
comments = comments.concat(comment);
}
}
else {
break;
}
}
else if (ch === 0x3C) {
if (this.source.slice(this.index + 1, this.index + 4) === '!--') {
this.index += 4; // `<!--`
var comment = this.skipSingleLineComment(4);
if (this.trackComment) {
comments = comments.concat(comment);
}
}
else {
break;
}
}
else {
break;
}
}
return comments;
};
;
// ECMA-262 11.6.2.2 Future Reserved Words
Scanner.prototype.isFutureReservedWord = function (id) {
switch (id) {
case 'enum':
case 'export':
case 'import':
case 'super':
return true;
default:
return false;
}
};
;
Scanner.prototype.isStrictModeReservedWord = function (id) {
switch (id) {
case 'implements':
case 'interface':
case 'package':
case 'private':
case 'protected':
case 'public':
case 'static':
case 'yield':
case 'let':
return true;
default:
return false;
}
};
;
Scanner.prototype.isRestrictedWord = function (id) {
return id === 'eval' || id === 'arguments';
};
;
// ECMA-262 11.6.2.1 Keywords
Scanner.prototype.isKeyword = function (id) {
switch (id.length) {
case 2:
return (id === 'if') || (id === 'in') || (id === 'do');
case 3:
return (id === 'var') || (id === 'for') || (id === 'new') ||
(id === 'try') || (id === 'let');
case 4:
return (id === 'this') || (id === 'else') || (id === 'case') ||
(id === 'void') || (id === 'with') || (id === 'enum');
case 5:
return (id === 'while') || (id === 'break') || (id === 'catch') ||
(id === 'throw') || (id === 'const') || (id === 'yield') ||
(id === 'class') || (id === 'super');
case 6:
return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
(id === 'switch') || (id === 'export') || (id === 'import');
case 7:
return (id === 'default') || (id === 'finally') || (id === 'extends');
case 8:
return (id === 'function') || (id === 'continue') || (id === 'debugger');
case 10:
return (id === 'instanceof');
default:
return false;
}
};
;
Scanner.prototype.codePointAt = function (i) {
var cp = this.source.charCodeAt(i);
if (cp >= 0xD800 && cp <= 0xDBFF) {
var second = this.source.charCodeAt(i + 1);
if (second >= 0xDC00 && second <= 0xDFFF) {
var first = cp;
cp = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
}
}
return cp;
};
;
Scanner.prototype.scanHexEscape = function (prefix) {
var len = (prefix === 'u') ? 4 : 2;
var code = 0;
for (var i = 0; i < len; ++i) {
if (!this.eof() && character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
code = code * 16 + hexValue(this.source[this.index++]);
}
else {
return '';
}
}
return String.fromCharCode(code);
};
;
Scanner.prototype.scanUnicodeCodePointEscape = function () {
var ch = this.source[this.index];
var code = 0;
// At least, one hex digit is required.
if (ch === '}') {
this.throwUnexpectedToken();
}
while (!this.eof()) {
ch = this.source[this.index++];
if (!character_1.Character.isHexDigit(ch.charCodeAt(0))) {
break;
}
code = code * 16 + hexValue(ch);
}
if (code > 0x10FFFF || ch !== '}') {
this.throwUnexpectedToken();
}
return character_1.Character.fromCodePoint(code);
};
;
Scanner.prototype.getIdentifier = function () {
var start = this.index++;
while (!this.eof()) {
var ch = this.source.charCodeAt(this.index);
if (ch === 0x5C) {
// Blackslash (U+005C) marks Unicode escape sequence.
this.index = start;
return this.getComplexIdentifier();
}
else if (ch >= 0xD800 && ch < 0xDFFF) {
// Need to handle surrogate pairs.
this.index = start;
return this.getComplexIdentifier();
}
if (character_1.Character.isIdentifierPart(ch)) {
++this.index;
}
else {
break;
}
}
return this.source.slice(start, this.index);
};
;
Scanner.prototype.getComplexIdentifier = function () {
var cp = this.codePointAt(this.index);
var id = character_1.Character.fromCodePoint(cp);
this.index += id.length;
// '\u' (U+005C, U+0075) denotes an escaped character.
var ch;
if (cp === 0x5C) {
if (this.source.charCodeAt(this.index) !== 0x75) {
this.throwUnexpectedToken();
}
++this.index;
if (this.source[this.index] === '{') {
++this.index;
ch = this.scanUnicodeCodePointEscape();
}
else {
ch = this.scanHexEscape('u');
cp = ch.charCodeAt(0);
if (!ch || ch === '\\' || !character_1.Character.isIdentifierStart(cp)) {
this.throwUnexpectedToken();
}
}
id = ch;
}
while (!this.eof()) {
cp = this.codePointAt(this.index);
if (!character_1.Character.isIdentifierPart(cp)) {
break;
}
ch = character_1.Character.fromCodePoint(cp);
id += ch;
this.index += ch.length;
// '\u' (U+005C, U+0075) denotes an escaped character.
if (cp === 0x5C) {
id = id.substr(0, id.length - 1);
if (this.source.charCodeAt(this.index) !== 0x75) {
this.throwUnexpectedToken();
}
++this.index;
if (this.source[this.index] === '{') {
++this.index;
ch = this.scanUnicodeCodePointEscape();
}
else {
ch = this.scanHexEscape('u');
cp = ch.charCodeAt(0);
if (!ch || ch === '\\' || !character_1.Character.isIdentifierPart(cp)) {
this.throwUnexpectedToken();
}
}
id += ch;
}
}
return id;
};
;
Scanner.prototype.octalToDecimal = function (ch) {
// \0 is not octal escape sequence
var octal = (ch !== '0');
var code = octalValue(ch);
if (!this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
octal = true;
code = code * 8 + octalValue(this.source[this.index++]);
// 3 digits are only allowed when string starts
// with 0, 1, 2, 3
if ('0123'.indexOf(ch) >= 0 && !this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
code = code * 8 + octalValue(this.source[this.index++]);
}
}
return {
code: code,
octal: octal
};
};
;
// ECMA-262 11.6 Names and Keywords
Scanner.prototype.scanIdentifier = function () {
var type;
var start = this.index;
// Backslash (U+005C) starts an escaped character.
var id = (this.source.charCodeAt(start) === 0x5C) ? this.getComplexIdentifier() : this.getIdentifier();
// There is no keyword or literal with only one character.
// Thus, it must be an identifier.
if (id.length === 1) {
type = token_1.Token.Identifier;
}
else if (this.isKeyword(id)) {
type = token_1.Token.Keyword;
}
else if (id === 'null') {
type = token_1.Token.NullLiteral;
}
else if (id === 'true' || id === 'false') {
type = token_1.Token.BooleanLiteral;
}
else {
type = token_1.Token.Identifier;
}
return {
type: type,
value: id,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
;
// ECMA-262 11.7 Punctuators
Scanner.prototype.scanPunctuator = function () {
var token = {
type: token_1.Token.Punctuator,
value: '',
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: this.index,
end: this.index
};
// Check for most common single-character punctuators.
var str = this.source[this.index];
switch (str) {
case '(':
case '{':
if (str === '{') {
this.curlyStack.push('{');
}
++this.index;
break;
case '.':
++this.index;
if (this.source[this.index] === '.' && this.source[this.index + 1] === '.') {
// Spread operator: ...
this.index += 2;
str = '...';
}
break;
case '}':
++this.index;
this.curlyStack.pop();
break;
case ')':
case ';':
case ',':
case '[':
case ']':
case ':':
case '?':
case '~':
++this.index;
break;
default:
// 4-character punctuator.
str = this.source.substr(this.index, 4);
if (str === '>>>=') {
this.index += 4;
}
else {
// 3-character punctuators.
str = str.substr(0, 3);
if (str === '===' || str === '!==' || str === '>>>' ||
str === '<<=' || str === '>>=' || str === '**=') {
this.index += 3;
}
else {
// 2-character punctuators.
str = str.substr(0, 2);
if (str === '&&' || str === '||' || str === '==' || str === '!=' ||
str === '+=' || str === '-=' || str === '*=' || str === '/=' ||
str === '++' || str === '--' || str === '<<' || str === '>>' ||
str === '&=' || str === '|=' || str === '^=' || str === '%=' ||
str === '<=' || str === '>=' || str === '=>' || str === '**') {
this.index += 2;
}
else {
// 1-character punctuators.
str = this.source[this.index];
if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {
++this.index;
}
}
}
}
}
if (this.index === token.start) {
this.throwUnexpectedToken();
}
token.end = this.index;
token.value = str;
return token;
};
;
// ECMA-262 11.8.3 Numeric Literals
Scanner.prototype.scanHexLiteral = function (start) {
var number = '';
while (!this.eof()) {
if (!character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
break;
}
number += this.source[this.index++];
}
if (number.length === 0) {
this.throwUnexpectedToken();
}
if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
this.throwUnexpectedToken();
}
return {
type: token_1.Token.NumericLiteral,
value: parseInt('0x' + number, 16),
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
;
Scanner.prototype.scanBinaryLiteral = function (start) {
var number = '';
var ch;
while (!this.eof()) {
ch = this.source[this.index];
if (ch !== '0' && ch !== '1') {
break;
}
number += this.source[this.index++];
}
if (number.length === 0) {
// only 0b or 0B
this.throwUnexpectedToken();
}
if (!this.eof()) {
ch = this.source.charCodeAt(this.index);
/* istanbul ignore else */
if (character_1.Character.isIdentifierStart(ch) || character_1.Character.isDecimalDigit(ch)) {
this.throwUnexpectedToken();
}
}
return {
type: token_1.Token.NumericLiteral,
value: parseInt(number, 2),
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
;
Scanner.prototype.scanOctalLiteral = function (prefix, start) {
var number = '';
var octal = false;
if (character_1.Character.isOctalDigit(prefix.charCodeAt(0))) {
octal = true;
number = '0' + this.source[this.index++];
}
else {
++this.index;
}
while (!this.eof()) {
if (!character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
break;
}
number += this.source[this.index++];
}
if (!octal && number.length === 0) {
// only 0o or 0O
this.throwUnexpectedToken();
}
if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index)) || character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
this.throwUnexpectedToken();
}
return {
type: token_1.Token.NumericLiteral,
value: parseInt(number, 8),
octal: octal,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
;
Scanner.prototype.isImplicitOctalLiteral = function () {
// Implicit octal, unless there is a non-octal digit.
// (Annex B.1.1 on Numeric Literals)
for (var i = this.index + 1; i < this.length; ++i) {
var ch = this.source[i];
if (ch === '8' || ch === '9') {
return false;
}
if (!character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
return true;
}
}
return true;
};
;
Scanner.prototype.scanNumericLiteral = function () {
var start = this.index;
var ch = this.source[start];
assert_1.assert(character_1.Character.isDecimalDigit(ch.charCodeAt(0)) || (ch === '.'), 'Numeric literal must start with a decimal digit or a decimal point');
var number = '';
if (ch !== '.') {
number = this.source[this.index++];
ch = this.source[this.index];
// Hex number starts with '0x'.
// Octal number starts with '0'.
// Octal number in ES6 starts with '0o'.
// Binary number in ES6 starts with '0b'.
if (number === '0') {
if (ch === 'x' || ch === 'X') {
++this.index;
return this.scanHexLiteral(start);
}
if (ch === 'b' || ch === 'B') {
++this.index;
return this.scanBinaryLiteral(start);
}
if (ch === 'o' || ch === 'O') {
return this.scanOctalLiteral(ch, start);
}
if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
if (this.isImplicitOctalLiteral()) {
return this.scanOctalLiteral(ch, start);
}
}
}
while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
number += this.source[this.index++];
}
ch = this.source[this.index];
}
if (ch === '.') {
number += this.source[this.index++];
while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
number += this.source[this.index++];
}
ch = this.source[this.index];
}
if (ch === 'e' || ch === 'E') {
number += this.source[this.index++];
ch = this.source[this.index];
if (ch === '+' || ch === '-') {
number += this.source[this.index++];
}
if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
number += this.source[this.index++];
}
}
else {
this.throwUnexpectedToken();
}
}
if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
this.throwUnexpectedToken();
}
return {
type: token_1.Token.NumericLiteral,
value: parseFloat(number),
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
;
// ECMA-262 11.8.4 String Literals
Scanner.prototype.scanStringLiteral = function () {
var start = this.index;
var quote = this.source[start];
assert_1.assert((quote === '\'' || quote === '"'), 'String literal must starts with a quote');
++this.index;
var octal = false;
var str = '';
while (!this.eof()) {
var ch = this.source[this.index++];
if (ch === quote) {
quote = '';
break;
}
else if (ch === '\\') {
ch = this.source[this.index++];
if (!ch || !character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
switch (ch) {
case 'u':
case 'x':
if (this.source[this.index] === '{') {
++this.index;
str += this.scanUnicodeCodePointEscape();
}
else {
var unescaped = this.scanHexEscape(ch);
if (!unescaped) {
this.throwUnexpectedToken();
}
str += unescaped;
}
break;
case 'n':
str += '\n';
break;
case 'r':
str += '\r';
break;
case 't':
str += '\t';
break;
case 'b':
str += '\b';
break;
case 'f':
str += '\f';
break;
case 'v':
str += '\x0B';
break;
case '8':
case '9':
str += ch;
this.tolerateUnexpectedToken();
break;
default:
if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
var octToDec = this.octalToDecimal(ch);
octal = octToDec.octal || octal;
str += String.fromCharCode(octToDec.code);
}
else {
str += ch;
}
break;
}
}
else {
++this.lineNumber;
if (ch === '\r' && this.source[this.index] === '\n') {
++this.index;
}
this.lineStart = this.index;
}
}
else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
break;
}
else {
str += ch;
}
}
if (quote !== '') {
this.index = start;
this.throwUnexpectedToken();
}
return {
type: token_1.Token.StringLiteral,
value: str,
octal: octal,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
;
// ECMA-262 11.8.6 Template Literal Lexical Components
Scanner.prototype.scanTemplate = function () {
var cooked = '';
var terminated = false;
var start = this.index;
var head = (this.source[start] === '`');
var tail = false;
var rawOffset = 2;
++this.index;
while (!this.eof()) {
var ch = this.source[this.index++];
if (ch === '`') {
rawOffset = 1;
tail = true;
terminated = true;
break;
}
else if (ch === '$') {
if (this.source[this.index] === '{') {
this.curlyStack.push('${');
++this.index;
terminated = true;
break;
}
cooked += ch;
}
else if (ch === '\\') {
ch = this.source[this.index++];
if (!character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
switch (ch) {
case 'n':
cooked += '\n';
break;
case 'r':
cooked += '\r';
break;
case 't':
cooked += '\t';
break;
case 'u':
case 'x':
if (this.source[this.index] === '{') {
++this.index;
cooked += this.scanUnicodeCodePointEscape();
}
else {
var restore = this.index;
var unescaped = this.scanHexEscape(ch);
if (unescaped) {
cooked += unescaped;
}
else {
this.index = restore;
cooked += ch;
}
}
break;
case 'b':
cooked += '\b';
break;
case 'f':
cooked += '\f';
break;
case 'v':
cooked += '\v';
break;
default:
if (ch === '0') {
if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
// Illegal: \01 \02 and so on
this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
}
cooked += '\0';
}
else if (character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
// Illegal: \1 \2
this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
}
else {
cooked += ch;
}
break;
}
}
else {
++this.lineNumber;
if (ch === '\r' && this.source[this.index] === '\n') {
++this.index;
}
this.lineStart = this.index;
}
}
else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
++this.lineNumber;
if (ch === '\r' && this.source[this.index] === '\n') {
++this.index;
}
this.lineStart = this.index;
cooked += '\n';
}
else {
cooked += ch;
}
}
if (!terminated) {
this.throwUnexpectedToken();
}
if (!head) {
this.curlyStack.pop();
}
return {
type: token_1.Token.Template,
value: {
cooked: cooked,
raw: this.source.slice(start + 1, this.index - rawOffset)
},
head: head,
tail: tail,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
;
// ECMA-262 11.8.5 Regular Expression Literals
Scanner.prototype.testRegExp = function (pattern, flags) {
// The BMP character to use as a replacement for astral symbols when
// translating an ES6 "u"-flagged pattern to an ES5-compatible
// approximation.
// Note: replacing with '\uFFFF' enables false positives in unlikely
// scenarios. For example, `[\u{1044f}-\u{10440}]` is an invalid
// pattern that would not be detected by this substitution.
var astralSubstitute = '\uFFFF';
var tmp = pattern;
var self = this;
if (flags.indexOf('u') >= 0) {
tmp = tmp
.replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, function ($0, $1, $2) {
var codePoint = parseInt($1 || $2, 16);
if (codePoint > 0x10FFFF) {
self.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
}
if (codePoint <= 0xFFFF) {
return String.fromCharCode(codePoint);
}
return astralSubstitute;
})
.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, astralSubstitute);
}
// First, detect invalid regular expressions.
try {
RegExp(tmp);
}
catch (e) {
this.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
}
// Return a regular expression object for this pattern-flag pair, or
// `null` in case the current environment doesn't support the flags it
// uses.
try {
return new RegExp(pattern, flags);
}
catch (exception) {
/* istanbul ignore next */
return null;
}
};
;
Scanner.prototype.scanRegExpBody = function () {
var ch = this.source[this.index];
assert_1.assert(ch === '/', 'Regular expression literal must start with a slash');
var str = this.source[this.index++];
var classMarker = false;
var terminated = false;
while (!this.eof()) {
ch = this.source[this.index++];
str += ch;
if (ch === '\\') {
ch = this.source[this.index++];
// ECMA-262 7.8.5
if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
}
str += ch;
}
else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
}
else if (classMarker) {
if (ch === ']') {
classMarker = false;
}
}
else {
if (ch === '/') {
terminated = true;
break;
}
else if (ch === '[') {
classMarker = true;
}
}
}
if (!terminated) {
this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
}
// Exclude leading and trailing slash.
var body = str.substr(1, str.length - 2);
return {
value: body,
literal: str
};
};
;
Scanner.prototype.scanRegExpFlags = function () {
var str = '';
var flags = '';
while (!this.eof()) {
var ch = this.source[this.index];
if (!character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
break;
}
++this.index;
if (ch === '\\' && !this.eof()) {
ch = this.source[this.index];
if (ch === 'u') {
++this.index;
var restore = this.index;
ch = this.scanHexEscape('u');
if (ch) {
flags += ch;
for (str += '\\u'; restore < this.index; ++restore) {
str += this.source[restore];
}
}
else {
this.index = restore;
flags += 'u';
str += '\\u';
}
this.tolerateUnexpectedToken();
}
else {
str += '\\';
this.tolerateUnexpectedToken();
}
}
else {
flags += ch;
str += ch;
}
}
return {
value: flags,
literal: str
};
};
;
Scanner.prototype.scanRegExp = function () {
var start = this.index;
var body = this.scanRegExpBody();
var flags = this.scanRegExpFlags();
var value = this.testRegExp(body.value, flags.value);
return {
type: token_1.Token.RegularExpression,
value: value,
literal: body.literal + flags.literal,
regex: {
pattern: body.value,
flags: flags.value
},
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
;
Scanner.prototype.lex = function () {
if (this.eof()) {
return {
type: token_1.Token.EOF,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: this.index,
end: this.index
};
}
var cp = this.source.charCodeAt(this.index);
if (character_1.Character.isIdentifierStart(cp)) {
return this.scanIdentifier();
}
// Very common: ( and ) and ;
if (cp === 0x28 || cp === 0x29 || cp === 0x3B) {
return this.scanPunctuator();
}
// String literal starts with single quote (U+0027) or double quote (U+0022).
if (cp === 0x27 || cp === 0x22) {
return this.scanStringLiteral();
}
// Dot (.) U+002E can also start a floating-point number, hence the need
// to check the next character.
if (cp === 0x2E) {
if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index + 1))) {
return this.scanNumericLiteral();
}
return this.scanPunctuator();
}
if (character_1.Character.isDecimalDigit(cp)) {
return this.scanNumericLiteral();
}
// Template literals start with ` (U+0060) for template head
// or } (U+007D) for template middle or template tail.
if (cp === 0x60 || (cp === 0x7D && this.curlyStack[this.curlyStack.length - 1] === '${')) {
return this.scanTemplate();
}
// Possible identifier start in a surrogate pair.
if (cp >= 0xD800 && cp < 0xDFFF) {
if (character_1.Character.isIdentifierStart(this.codePointAt(this.index))) {
return this.scanIdentifier();
}
}
return this.scanPunctuator();
};
;
return Scanner;
}());
exports.Scanner = Scanner;
/***/ },
/* 9 */
/***/ function(module, exports) {
"use strict";
// See also tools/generate-unicode-regex.js.
var Regex = {
// Unicode v8.0.0 NonAsciiIdentifierStart:
NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,
// Unicode v8.0.0 NonAsciiIdentifierPart:
NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
};
exports.Character = {
fromCodePoint: function (cp) {
return (cp < 0x10000) ? String.fromCharCode(cp) :
String.fromCharCode(0xD800 + ((cp - 0x10000) >> 10)) +
String.fromCharCode(0xDC00 + ((cp - 0x10000) & 1023));
},
// ECMA-262 11.2 White Space
isWhiteSpace: function (cp) {
return (cp === 0x20) || (cp === 0x09) || (cp === 0x0B) || (cp === 0x0C) || (cp === 0xA0) ||
(cp >= 0x1680 && [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(cp) >= 0);
},
// ECMA-262 11.3 Line Terminators
isLineTerminator: function (cp) {
return (cp === 0x0A) || (cp === 0x0D) || (cp === 0x2028) || (cp === 0x2029);
},
// ECMA-262 11.6 Identifier Names and Identifiers
isIdentifierStart: function (cp) {
return (cp === 0x24) || (cp === 0x5F) ||
(cp >= 0x41 && cp <= 0x5A) ||
(cp >= 0x61 && cp <= 0x7A) ||
(cp === 0x5C) ||
((cp >= 0x80) && Regex.NonAsciiIdentifierStart.test(exports.Character.fromCodePoint(cp)));
},
isIdentifierPart: function (cp) {
return (cp === 0x24) || (cp === 0x5F) ||
(cp >= 0x41 && cp <= 0x5A) ||
(cp >= 0x61 && cp <= 0x7A) ||
(cp >= 0x30 && cp <= 0x39) ||
(cp === 0x5C) ||
((cp >= 0x80) && Regex.NonAsciiIdentifierPart.test(exports.Character.fromCodePoint(cp)));
},
// ECMA-262 11.8.3 Numeric Literals
isDecimalDigit: function (cp) {
return (cp >= 0x30 && cp <= 0x39); // 0..9
},
isHexDigit: function (cp) {
return (cp >= 0x30 && cp <= 0x39) ||
(cp >= 0x41 && cp <= 0x46) ||
(cp >= 0x61 && cp <= 0x66); // a..f
},
isOctalDigit: function (cp) {
return (cp >= 0x30 && cp <= 0x37); // 0..7
}
};
/***/ },
/* 10 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var syntax_1 = __webpack_require__(2);
var ArrayExpression = (function () {
function ArrayExpression(elements) {
this.type = syntax_1.Syntax.ArrayExpression;
this.elements = elements;
}
return ArrayExpression;
}());
exports.ArrayExpression = ArrayExpression;
var ArrayPattern = (function () {
function ArrayPattern(elements) {
this.type = syntax_1.Syntax.ArrayPattern;
this.elements = elements;
}
return ArrayPattern;
}());
exports.ArrayPattern = ArrayPattern;
var ArrowFunctionExpression = (function () {
function ArrowFunctionExpression(params, body, expression) {
this.type = syntax_1.Syntax.ArrowFunctionExpression;
this.id = null;
this.params = params;
this.body = body;
this.generator = false;
this.expression = expression;
}
return ArrowFunctionExpression;
}());
exports.ArrowFunctionExpression = ArrowFunctionExpression;
var AssignmentExpression = (function () {
function AssignmentExpression(operator, left, right) {
this.type = syntax_1.Syntax.AssignmentExpression;
this.operator = operator;
this.left = left;
this.right = right;
}
return AssignmentExpression;
}());
exports.AssignmentExpression = AssignmentExpression;
var AssignmentPattern = (function () {
function AssignmentPattern(left, right) {
this.type = syntax_1.Syntax.AssignmentPattern;
this.left = left;
this.right = right;
}
return AssignmentPattern;
}());
exports.AssignmentPattern = AssignmentPattern;
var BinaryExpression = (function () {
function BinaryExpression(operator, left, right) {
var logical = (operator === '||' || operator === '&&');
this.type = logical ? syntax_1.Syntax.LogicalExpression : syntax_1.Syntax.BinaryExpression;
this.operator = operator;
this.left = left;
this.right = right;
}
return BinaryExpression;
}());
exports.BinaryExpression = BinaryExpression;
var BlockStatement = (function () {
function BlockStatement(body) {
this.type = syntax_1.Syntax.BlockStatement;
this.body = body;
}
return BlockStatement;
}());
exports.BlockStatement = BlockStatement;
var BreakStatement = (function () {
function BreakStatement(label) {
this.type = syntax_1.Syntax.BreakStatement;
this.label = label;
}
return BreakStatement;
}());
exports.BreakStatement = BreakStatement;
var CallExpression = (function () {
function CallExpression(callee, args) {
this.type = syntax_1.Syntax.CallExpression;
this.callee = callee;
this.arguments = args;
}
return CallExpression;
}());
exports.CallExpression = CallExpression;
var CatchClause = (function () {
function CatchClause(param, body) {
this.type = syntax_1.Syntax.CatchClause;
this.param = param;
this.body = body;
}
return CatchClause;
}());
exports.CatchClause = CatchClause;
var ClassBody = (function () {
function ClassBody(body) {
this.type = syntax_1.Syntax.ClassBody;
this.body = body;
}
return ClassBody;
}());
exports.ClassBody = ClassBody;
var ClassDeclaration = (function () {
function ClassDeclaration(id, superClass, body) {
this.type = syntax_1.Syntax.ClassDeclaration;
this.id = id;
this.superClass = superClass;
this.body = body;
}
return ClassDeclaration;
}());
exports.ClassDeclaration = ClassDeclaration;
var ClassExpression = (function () {
function ClassExpression(id, superClass, body) {
this.type = syntax_1.Syntax.ClassExpression;
this.id = id;
this.superClass = superClass;
this.body = body;
}
return ClassExpression;
}());
exports.ClassExpression = ClassExpression;
var ComputedMemberExpression = (function () {
function ComputedMemberExpression(object, property) {
this.type = syntax_1.Syntax.MemberExpression;
this.computed = true;
this.object = object;
this.property = property;
}
return ComputedMemberExpression;
}());
exports.ComputedMemberExpression = ComputedMemberExpression;
var ConditionalExpression = (function () {
function ConditionalExpression(test, consequent, alternate) {
this.type = syntax_1.Syntax.ConditionalExpression;
this.test = test;
this.consequent = consequent;
this.alternate = alternate;
}
return ConditionalExpression;
}());
exports.ConditionalExpression = ConditionalExpression;
var ContinueStatement = (function () {
function ContinueStatement(label) {
this.type = syntax_1.Syntax.ContinueStatement;
this.label = label;
}
return ContinueStatement;
}());
exports.ContinueStatement = ContinueStatement;
var DebuggerStatement = (function () {
function DebuggerStatement() {
this.type = syntax_1.Syntax.DebuggerStatement;
}
return DebuggerStatement;
}());
exports.DebuggerStatement = DebuggerStatement;
var Directive = (function () {
function Directive(expression, directive) {
this.type = syntax_1.Syntax.ExpressionStatement;
this.expression = expression;
this.directive = directive;
}
return Directive;
}());
exports.Directive = Directive;
var DoWhileStatement = (function () {
function DoWhileStatement(body, test) {
this.type = syntax_1.Syntax.DoWhileStatement;
this.body = body;
this.test = test;
}
return DoWhileStatement;
}());
exports.DoWhileStatement = DoWhileStatement;
var EmptyStatement = (function () {
function EmptyStatement() {
this.type = syntax_1.Syntax.EmptyStatement;
}
return EmptyStatement;
}());
exports.EmptyStatement = EmptyStatement;
var ExportAllDeclaration = (function () {
function ExportAllDeclaration(source) {
this.type = syntax_1.Syntax.ExportAllDeclaration;
this.source = source;
}
return ExportAllDeclaration;
}());
exports.ExportAllDeclaration = ExportAllDeclaration;
var ExportDefaultDeclaration = (function () {
function ExportDefaultDeclaration(declaration) {
this.type = syntax_1.Syntax.ExportDefaultDeclaration;
this.declaration = declaration;
}
return ExportDefaultDeclaration;
}());
exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
var ExportNamedDeclaration = (function () {
function ExportNamedDeclaration(declaration, specifiers, source) {
this.type = syntax_1.Syntax.ExportNamedDeclaration;
this.declaration = declaration;
this.specifiers = specifiers;
this.source = source;
}
return ExportNamedDeclaration;
}());
exports.ExportNamedDeclaration = ExportNamedDeclaration;
var ExportSpecifier = (function () {
function ExportSpecifier(local, exported) {
this.type = syntax_1.Syntax.ExportSpecifier;
this.exported = exported;
this.local = local;
}
return ExportSpecifier;
}());
exports.ExportSpecifier = ExportSpecifier;
var ExpressionStatement = (function () {
function ExpressionStatement(expression) {
this.type = syntax_1.Syntax.ExpressionStatement;
this.expression = expression;
}
return ExpressionStatement;
}());
exports.ExpressionStatement = ExpressionStatement;
var ForInStatement = (function () {
function ForInStatement(left, right, body) {
this.type = syntax_1.Syntax.ForInStatement;
this.left = left;
this.right = right;
this.body = body;
this.each = false;
}
return ForInStatement;
}());
exports.ForInStatement = ForInStatement;
var ForOfStatement = (function () {
function ForOfStatement(left, right, body) {
this.type = syntax_1.Syntax.ForOfStatement;
this.left = left;
this.right = right;
this.body = body;
}
return ForOfStatement;
}());
exports.ForOfStatement = ForOfStatement;
var ForStatement = (function () {
function ForStatement(init, test, update, body) {
this.type = syntax_1.Syntax.ForStatement;
this.init = init;
this.test = test;
this.update = update;
this.body = body;
}
return ForStatement;
}());
exports.ForStatement = ForStatement;
var FunctionDeclaration = (function () {
function FunctionDeclaration(id, params, body, generator) {
this.type = syntax_1.Syntax.FunctionDeclaration;
this.id = id;
this.params = params;
this.body = body;
this.generator = generator;
this.expression = false;
}
return FunctionDeclaration;
}());
exports.FunctionDeclaration = FunctionDeclaration;
var FunctionExpression = (function () {
function FunctionExpression(id, params, body, generator) {
this.type = syntax_1.Syntax.FunctionExpression;
this.id = id;
this.params = params;
this.body = body;
this.generator = generator;
this.expression = false;
}
return FunctionExpression;
}());
exports.FunctionExpression = FunctionExpression;
var Identifier = (function () {
function Identifier(name) {
this.type = syntax_1.Syntax.Identifier;
this.name = name;
}
return Identifier;
}());
exports.Identifier = Identifier;
var IfStatement = (function () {
function IfStatement(test, consequent, alternate) {
this.type = syntax_1.Syntax.IfStatement;
this.test = test;
this.consequent = consequent;
this.alternate = alternate;
}
return IfStatement;
}());
exports.IfStatement = IfStatement;
var ImportDeclaration = (function () {
function ImportDeclaration(specifiers, source) {
this.type = syntax_1.Syntax.ImportDeclaration;
this.specifiers = specifiers;
this.source = source;
}
return ImportDeclaration;
}());
exports.ImportDeclaration = ImportDeclaration;
var ImportDefaultSpecifier = (function () {
function ImportDefaultSpecifier(local) {
this.type = syntax_1.Syntax.ImportDefaultSpecifier;
this.local = local;
}
return ImportDefaultSpecifier;
}());
exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
var ImportNamespaceSpecifier = (function () {
function ImportNamespaceSpecifier(local) {
this.type = syntax_1.Syntax.ImportNamespaceSpecifier;
this.local = local;
}
return ImportNamespaceSpecifier;
}());
exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
var ImportSpecifier = (function () {
function ImportSpecifier(local, imported) {
this.type = syntax_1.Syntax.ImportSpecifier;
this.local = local;
this.imported = imported;
}
return ImportSpecifier;
}());
exports.ImportSpecifier = ImportSpecifier;
var LabeledStatement = (function () {
function LabeledStatement(label, body) {
this.type = syntax_1.Syntax.LabeledStatement;
this.label = label;
this.body = body;
}
return LabeledStatement;
}());
exports.LabeledStatement = LabeledStatement;
var Literal = (function () {
function Literal(value, raw) {
this.type = syntax_1.Syntax.Literal;
this.value = value;
this.raw = raw;
}
return Literal;
}());
exports.Literal = Literal;
var MetaProperty = (function () {
function MetaProperty(meta, property) {
this.type = syntax_1.Syntax.MetaProperty;
this.meta = meta;
this.property = property;
}
return MetaProperty;
}());
exports.MetaProperty = MetaProperty;
var MethodDefinition = (function () {
function MethodDefinition(key, computed, value, kind, isStatic) {
this.type = syntax_1.Syntax.MethodDefinition;
this.key = key;
this.computed = computed;
this.value = value;
this.kind = kind;
this.static = isStatic;
}
return MethodDefinition;
}());
exports.MethodDefinition = MethodDefinition;
var NewExpression = (function () {
function NewExpression(callee, args) {
this.type = syntax_1.Syntax.NewExpression;
this.callee = callee;
this.arguments = args;
}
return NewExpression;
}());
exports.NewExpression = NewExpression;
var ObjectExpression = (function () {
function ObjectExpression(properties) {
this.type = syntax_1.Syntax.ObjectExpression;
this.properties = properties;
}
return ObjectExpression;
}());
exports.ObjectExpression = ObjectExpression;
var ObjectPattern = (function () {
function ObjectPattern(properties) {
this.type = syntax_1.Syntax.ObjectPattern;
this.properties = properties;
}
return ObjectPattern;
}());
exports.ObjectPattern = ObjectPattern;
var Program = (function () {
function Program(body, sourceType) {
this.type = syntax_1.Syntax.Program;
this.body = body;
this.sourceType = sourceType;
}
return Program;
}());
exports.Program = Program;
var Property = (function () {
function Property(kind, key, computed, value, method, shorthand) {
this.type = syntax_1.Syntax.Property;
this.key = key;
this.computed = computed;
this.value = value;
this.kind = kind;
this.method = method;
this.shorthand = shorthand;
}
return Property;
}());
exports.Property = Property;
var RegexLiteral = (function () {
function RegexLiteral(value, raw, regex) {
this.type = syntax_1.Syntax.Literal;
this.value = value;
this.raw = raw;
this.regex = regex;
}
return RegexLiteral;
}());
exports.RegexLiteral = RegexLiteral;
var RestElement = (function () {
function RestElement(argument) {
this.type = syntax_1.Syntax.RestElement;
this.argument = argument;
}
return RestElement;
}());
exports.RestElement = RestElement;
var ReturnStatement = (function () {
function ReturnStatement(argument) {
this.type = syntax_1.Syntax.ReturnStatement;
this.argument = argument;
}
return ReturnStatement;
}());
exports.ReturnStatement = ReturnStatement;
var SequenceExpression = (function () {
function SequenceExpression(expressions) {
this.type = syntax_1.Syntax.SequenceExpression;
this.expressions = expressions;
}
return SequenceExpression;
}());
exports.SequenceExpression = SequenceExpression;
var SpreadElement = (function () {
function SpreadElement(argument) {
this.type = syntax_1.Syntax.SpreadElement;
this.argument = argument;
}
return SpreadElement;
}());
exports.SpreadElement = SpreadElement;
var StaticMemberExpression = (function () {
function StaticMemberExpression(object, property) {
this.type = syntax_1.Syntax.MemberExpression;
this.computed = false;
this.object = object;
this.property = property;
}
return StaticMemberExpression;
}());
exports.StaticMemberExpression = StaticMemberExpression;
var Super = (function () {
function Super() {
this.type = syntax_1.Syntax.Super;
}
return Super;
}());
exports.Super = Super;
var SwitchCase = (function () {
function SwitchCase(test, consequent) {
this.type = syntax_1.Syntax.SwitchCase;
this.test = test;
this.consequent = consequent;
}
return SwitchCase;
}());
exports.SwitchCase = SwitchCase;
var SwitchStatement = (function () {
function SwitchStatement(discriminant, cases) {
this.type = syntax_1.Syntax.SwitchStatement;
this.discriminant = discriminant;
this.cases = cases;
}
return SwitchStatement;
}());
exports.SwitchStatement = SwitchStatement;
var TaggedTemplateExpression = (function () {
function TaggedTemplateExpression(tag, quasi) {
this.type = syntax_1.Syntax.TaggedTemplateExpression;
this.tag = tag;
this.quasi = quasi;
}
return TaggedTemplateExpression;
}());
exports.TaggedTemplateExpression = TaggedTemplateExpression;
var TemplateElement = (function () {
function TemplateElement(value, tail) {
this.type = syntax_1.Syntax.TemplateElement;
this.value = value;
this.tail = tail;
}
return TemplateElement;
}());
exports.TemplateElement = TemplateElement;
var TemplateLiteral = (function () {
function TemplateLiteral(quasis, expressions) {
this.type = syntax_1.Syntax.TemplateLiteral;
this.quasis = quasis;
this.expressions = expressions;
}
return TemplateLiteral;
}());
exports.TemplateLiteral = TemplateLiteral;
var ThisExpression = (function () {
function ThisExpression() {
this.type = syntax_1.Syntax.ThisExpression;
}
return ThisExpression;
}());
exports.ThisExpression = ThisExpression;
var ThrowStatement = (function () {
function ThrowStatement(argument) {
this.type = syntax_1.Syntax.ThrowStatement;
this.argument = argument;
}
return ThrowStatement;
}());
exports.ThrowStatement = ThrowStatement;
var TryStatement = (function () {
function TryStatement(block, handler, finalizer) {
this.type = syntax_1.Syntax.TryStatement;
this.block = block;
this.handler = handler;
this.finalizer = finalizer;
}
return TryStatement;
}());
exports.TryStatement = TryStatement;
var UnaryExpression = (function () {
function UnaryExpression(operator, argument) {
this.type = syntax_1.Syntax.UnaryExpression;
this.operator = operator;
this.argument = argument;
this.prefix = true;
}
return UnaryExpression;
}());
exports.UnaryExpression = UnaryExpression;
var UpdateExpression = (function () {
function UpdateExpression(operator, argument, prefix) {
this.type = syntax_1.Syntax.UpdateExpression;
this.operator = operator;
this.argument = argument;
this.prefix = prefix;
}
return UpdateExpression;
}());
exports.UpdateExpression = UpdateExpression;
var VariableDeclaration = (function () {
function VariableDeclaration(declarations, kind) {
this.type = syntax_1.Syntax.VariableDeclaration;
this.declarations = declarations;
this.kind = kind;
}
return VariableDeclaration;
}());
exports.VariableDeclaration = VariableDeclaration;
var VariableDeclarator = (function () {
function VariableDeclarator(id, init) {
this.type = syntax_1.Syntax.VariableDeclarator;
this.id = id;
this.init = init;
}
return VariableDeclarator;
}());
exports.VariableDeclarator = VariableDeclarator;
var WhileStatement = (function () {
function WhileStatement(test, body) {
this.type = syntax_1.Syntax.WhileStatement;
this.test = test;
this.body = body;
}
return WhileStatement;
}());
exports.WhileStatement = WhileStatement;
var WithStatement = (function () {
function WithStatement(object, body) {
this.type = syntax_1.Syntax.WithStatement;
this.object = object;
this.body = body;
}
return WithStatement;
}());
exports.WithStatement = WithStatement;
var YieldExpression = (function () {
function YieldExpression(argument, delegate) {
this.type = syntax_1.Syntax.YieldExpression;
this.argument = argument;
this.delegate = delegate;
}
return YieldExpression;
}());
exports.YieldExpression = YieldExpression;
/***/ },
/* 11 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
/* istanbul ignore next */
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var character_1 = __webpack_require__(9);
var token_1 = __webpack_require__(7);
var parser_1 = __webpack_require__(3);
var xhtml_entities_1 = __webpack_require__(12);
var jsx_syntax_1 = __webpack_require__(13);
var Node = __webpack_require__(10);
var JSXNode = __webpack_require__(14);
var JSXToken;
(function (JSXToken) {
JSXToken[JSXToken["Identifier"] = 100] = "Identifier";
JSXToken[JSXToken["Text"] = 101] = "Text";
})(JSXToken || (JSXToken = {}));
token_1.TokenName[JSXToken.Identifier] = 'JSXIdentifier';
token_1.TokenName[JSXToken.Text] = 'JSXText';
// Fully qualified element name, e.g. <svg:path> returns "svg:path"
function getQualifiedElementName(elementName) {
var qualifiedName;
switch (elementName.type) {
case jsx_syntax_1.JSXSyntax.JSXIdentifier:
var id = (elementName);
qualifiedName = id.name;
break;
case jsx_syntax_1.JSXSyntax.JSXNamespacedName:
var ns = (elementName);
qualifiedName = getQualifiedElementName(ns.namespace) + ':' +
getQualifiedElementName(ns.name);
break;
case jsx_syntax_1.JSXSyntax.JSXMemberExpression:
var expr = (elementName);
qualifiedName = getQualifiedElementName(expr.object) + '.' +
getQualifiedElementName(expr.property);
break;
}
return qualifiedName;
}
var JSXParser = (function (_super) {
__extends(JSXParser, _super);
function JSXParser(code, options, delegate) {
_super.call(this, code, options, delegate);
}
JSXParser.prototype.parsePrimaryExpression = function () {
return this.match('<') ? this.parseJSXRoot() : _super.prototype.parsePrimaryExpression.call(this);
};
JSXParser.prototype.startJSX = function () {
// Unwind the scanner before the lookahead token.
this.scanner.index = this.startMarker.index;
this.scanner.lineNumber = this.startMarker.lineNumber;
this.scanner.lineStart = this.startMarker.lineStart;
};
JSXParser.prototype.finishJSX = function () {
// Prime the next lookahead.
this.nextToken();
};
JSXParser.prototype.createJSXNode = function () {
this.collectComments();
return {
index: this.scanner.index,
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
};
};
JSXParser.prototype.createJSXChildNode = function () {
return {
index: this.scanner.index,
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
};
};
JSXParser.prototype.scanXHTMLEntity = function () {
var result = '&';
var str = '';
while (!this.scanner.eof()) {
var ch = this.scanner.source[this.scanner.index++];
if (ch === ';') {
if (str[0] === '#') {
str = str.substr(1);
var hex = (str[0] === 'x');
var cp = hex ? parseInt('0' + str, 16) : parseInt(str, 10);
result = String.fromCharCode(cp);
}
else if (xhtml_entities_1.XHTMLEntities[str]) {
result = xhtml_entities_1.XHTMLEntities[str];
}
else {
result += ch;
}
break;
}
str += ch;
result += ch;
}
return result;
};
// Scan the next JSX token. This replaces Scanner#lex when in JSX mode.
JSXParser.prototype.lexJSX = function () {
var cp = this.scanner.source.charCodeAt(this.scanner.index);
// < > / : = { }
if (cp === 60 || cp === 62 || cp === 47 || cp === 58 || cp === 61 || cp === 123 || cp === 125) {
var value = this.scanner.source[this.scanner.index++];
return {
type: token_1.Token.Punctuator,
value: value,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: this.scanner.index - 1,
end: this.scanner.index
};
}
// " '
if (cp === 34 || cp === 39) {
var start = this.scanner.index;
var quote = this.scanner.source[this.scanner.index++];
var str = '';
while (!this.scanner.eof()) {
var ch = this.scanner.source[this.scanner.index++];
if (ch === quote) {
break;
}
else if (ch === '&') {
str += this.scanXHTMLEntity();
}
else {
str += ch;
}
}
return {
type: token_1.Token.StringLiteral,
value: str,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: start,
end: this.scanner.index
};
}
// ... or .
if (cp === 46) {
var n1 = this.scanner.source.charCodeAt(this.scanner.index + 1);
var n2 = this.scanner.source.charCodeAt(this.scanner.index + 2);
var value = (n1 === 46 && n2 === 46) ? '...' : '.';
var start = this.scanner.index;
this.scanner.index += value.length;
return {
type: token_1.Token.Punctuator,
value: value,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: start,
end: this.scanner.index
};
}
// Identifer can not contain backslash (char code 92).
if (character_1.Character.isIdentifierStart(cp) && (cp !== 92)) {
var start = this.scanner.index;
++this.scanner.index;
while (!this.scanner.eof()) {
var ch = this.scanner.source.charCodeAt(this.scanner.index);
if (character_1.Character.isIdentifierPart(ch) && (ch !== 92)) {
++this.scanner.index;
}
else if (ch === 45) {
// Hyphen (char code 45) can be part of an identifier.
++this.scanner.index;
}
else {
break;
}
}
var id = this.scanner.source.slice(start, this.scanner.index);
return {
type: JSXToken.Identifier,
value: id,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: start,
end: this.scanner.index
};
}
this.scanner.throwUnexpectedToken();
};
JSXParser.prototype.nextJSXToken = function () {
this.collectComments();
this.startMarker.index = this.scanner.index;
this.startMarker.lineNumber = this.scanner.lineNumber;
this.startMarker.lineStart = this.scanner.lineStart;
var token = this.lexJSX();
this.lastMarker.index = this.scanner.index;
this.lastMarker.lineNumber = this.scanner.lineNumber;
this.lastMarker.lineStart = this.scanner.lineStart;
if (this.config.tokens) {
this.tokens.push(this.convertToken(token));
}
return token;
};
JSXParser.prototype.nextJSXText = function () {
this.startMarker.index = this.scanner.index;
this.startMarker.lineNumber = this.scanner.lineNumber;
this.startMarker.lineStart = this.scanner.lineStart;
var start = this.scanner.index;
var text = '';
while (!this.scanner.eof()) {
var ch = this.scanner.source[this.scanner.index];
if (ch === '{' || ch === '<') {
break;
}
++this.scanner.index;
text += ch;
if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
++this.scanner.lineNumber;
if (ch === '\r' && this.scanner.source[this.scanner.index] === '\n') {
++this.scanner.index;
}
this.scanner.lineStart = this.scanner.index;
}
}
this.lastMarker.index = this.scanner.index;
this.lastMarker.lineNumber = this.scanner.lineNumber;
this.lastMarker.lineStart = this.scanner.lineStart;
var token = {
type: JSXToken.Text,
value: text,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: start,
end: this.scanner.index
};
if ((text.length > 0) && this.config.tokens) {
this.tokens.push(this.convertToken(token));
}
return token;
};
JSXParser.prototype.peekJSXToken = function () {
var previousIndex = this.scanner.index;
var previousLineNumber = this.scanner.lineNumber;
var previousLineStart = this.scanner.lineStart;
this.scanner.scanComments();
var next = this.lexJSX();
this.scanner.index = previousIndex;
this.scanner.lineNumber = previousLineNumber;
this.scanner.lineStart = previousLineStart;
return next;
};
// Expect the next JSX token to match the specified punctuator.
// If not, an exception will be thrown.
JSXParser.prototype.expectJSX = function (value) {
var token = this.nextJSXToken();
if (token.type !== token_1.Token.Punctuator || token.value !== value) {
this.throwUnexpectedToken(token);
}
};
// Return true if the next JSX token matches the specified punctuator.
JSXParser.prototype.matchJSX = function (value) {
var next = this.peekJSXToken();
return next.type === token_1.Token.Punctuator && next.value === value;
};
JSXParser.prototype.parseJSXIdentifier = function () {
var node = this.createJSXNode();
var token = this.nextJSXToken();
if (token.type !== JSXToken.Identifier) {
this.throwUnexpectedToken(token);
}
return this.finalize(node, new JSXNode.JSXIdentifier(token.value));
};
JSXParser.prototype.parseJSXElementName = function () {
var node = this.createJSXNode();
var elementName = this.parseJSXIdentifier();
if (this.matchJSX(':')) {
var namespace = elementName;
this.expectJSX(':');
var name_1 = this.parseJSXIdentifier();
elementName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_1));
}
else if (this.matchJSX('.')) {
while (this.matchJSX('.')) {
var object = elementName;
this.expectJSX('.');
var property = this.parseJSXIdentifier();
elementName = this.finalize(node, new JSXNode.JSXMemberExpression(object, property));
}
}
return elementName;
};
JSXParser.prototype.parseJSXAttributeName = function () {
var node = this.createJSXNode();
var attributeName;
var identifier = this.parseJSXIdentifier();
if (this.matchJSX(':')) {
var namespace = identifier;
this.expectJSX(':');
var name_2 = this.parseJSXIdentifier();
attributeName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_2));
}
else {
attributeName = identifier;
}
return attributeName;
};
JSXParser.prototype.parseJSXStringLiteralAttribute = function () {
var node = this.createJSXNode();
var token = this.nextJSXToken();
if (token.type !== token_1.Token.StringLiteral) {
this.throwUnexpectedToken(token);
}
var raw = this.getTokenRaw(token);
return this.finalize(node, new Node.Literal(token.value, raw));
};
JSXParser.prototype.parseJSXExpressionAttribute = function () {
var node = this.createJSXNode();
this.expectJSX('{');
var expression = null;
this.finishJSX();
if (this.match('}')) {
this.tolerateError('JSX attributes must only be assigned a non-empty expression');
}
expression = this.parseAssignmentExpression();
this.startJSX();
this.expectJSX('}');
return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
};
JSXParser.prototype.parseJSXAttributeValue = function () {
return this.matchJSX('{') ? this.parseJSXExpressionAttribute() :
this.matchJSX('<') ? this.parseJSXElement() : this.parseJSXStringLiteralAttribute();
};
JSXParser.prototype.parseJSXNameValueAttribute = function () {
var node = this.createJSXNode();
var name = this.parseJSXAttributeName();
var value = null;
if (this.matchJSX('=')) {
this.expectJSX('=');
value = this.parseJSXAttributeValue();
}
return this.finalize(node, new JSXNode.JSXAttribute(name, value));
};
JSXParser.prototype.parseJSXSpreadAttribute = function () {
var node = this.createJSXNode();
this.expectJSX('{');
this.expectJSX('...');
this.finishJSX();
var argument = this.parseAssignmentExpression();
this.startJSX();
this.expectJSX('}');
return this.finalize(node, new JSXNode.JSXSpreadAttribute(argument));
};
JSXParser.prototype.parseJSXAttributes = function () {
var attributes = [];
while (!this.matchJSX('/') && !this.matchJSX('>')) {
var attribute = this.matchJSX('{') ? this.parseJSXSpreadAttribute() :
this.parseJSXNameValueAttribute();
attributes.push(attribute);
}
return attributes;
};
JSXParser.prototype.parseJSXOpeningElement = function () {
var node = this.createJSXNode();
this.expectJSX('<');
var name = this.parseJSXElementName();
var attributes = this.parseJSXAttributes();
var selfClosing = this.matchJSX('/');
if (selfClosing) {
this.expectJSX('/');
}
this.expectJSX('>');
return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
};
JSXParser.prototype.parseJSXBoundaryElement = function () {
var node = this.createJSXNode();
this.expectJSX('<');
if (this.matchJSX('/')) {
this.expectJSX('/');
var name_3 = this.parseJSXElementName();
this.expectJSX('>');
return this.finalize(node, new JSXNode.JSXClosingElement(name_3));
}
var name = this.parseJSXElementName();
var attributes = this.parseJSXAttributes();
var selfClosing = this.matchJSX('/');
if (selfClosing) {
this.expectJSX('/');
}
this.expectJSX('>');
return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
};
JSXParser.prototype.parseJSXEmptyExpression = function () {
var node = this.createJSXChildNode();
this.collectComments();
this.lastMarker.index = this.scanner.index;
this.lastMarker.lineNumber = this.scanner.lineNumber;
this.lastMarker.lineStart = this.scanner.lineStart;
return this.finalize(node, new JSXNode.JSXEmptyExpression());
};
JSXParser.prototype.parseJSXExpression = function () {
var expression;
if (this.matchJSX('}')) {
expression = this.parseJSXEmptyExpression();
}
else {
this.finishJSX();
expression = this.parseAssignmentExpression();
this.startJSX();
}
return expression;
};
JSXParser.prototype.parseJSXExpressionContainer = function () {
var node = this.createJSXNode();
this.expectJSX('{');
var expression = this.parseJSXExpression();
this.expectJSX('}');
return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
};
JSXParser.prototype.parseJSXChildren = function () {
var children = [];
while (!this.scanner.eof()) {
var node = this.createJSXChildNode();
var token = this.nextJSXText();
if (token.start < token.end) {
var raw = this.getTokenRaw(token);
var child = this.finalize(node, new JSXNode.JSXText(token.value, raw));
children.push(child);
}
if (this.scanner.source[this.scanner.index] === '{') {
var container = this.parseJSXExpressionContainer();
children.push(container);
}
else {
break;
}
}
return children;
};
JSXParser.prototype.parseComplexJSXElement = function (el) {
var stack = [];
while (!this.scanner.eof()) {
el.children = el.children.concat(this.parseJSXChildren());
var node = this.createJSXChildNode();
var element = this.parseJSXBoundaryElement();
if (element.type === jsx_syntax_1.JSXSyntax.JSXOpeningElement) {
var opening = (element);
if (opening.selfClosing) {
var child = this.finalize(node, new JSXNode.JSXElement(opening, [], null));
el.children.push(child);
}
else {
stack.push(el);
el = { node: node, opening: opening, closing: null, children: [] };
}
}
if (element.type === jsx_syntax_1.JSXSyntax.JSXClosingElement) {
el.closing = (element);
var open_1 = getQualifiedElementName(el.opening.name);
var close_1 = getQualifiedElementName(el.closing.name);
if (open_1 !== close_1) {
this.tolerateError('Expected corresponding JSX closing tag for %0', open_1);
}
if (stack.length > 0) {
var child = this.finalize(el.node, new JSXNode.JSXElement(el.opening, el.children, el.closing));
el = stack.pop();
el.children.push(child);
}
else {
break;
}
}
}
return el;
};
JSXParser.prototype.parseJSXElement = function () {
var node = this.createJSXNode();
var opening = this.parseJSXOpeningElement();
var children = [];
var closing = null;
if (!opening.selfClosing) {
var el = this.parseComplexJSXElement({ node: node, opening: opening, closing: closing, children: children });
children = el.children;
closing = el.closing;
}
return this.finalize(node, new JSXNode.JSXElement(opening, children, closing));
};
JSXParser.prototype.parseJSXRoot = function () {
// Pop the opening '<' added from the lookahead.
if (this.config.tokens) {
this.tokens.pop();
}
this.startJSX();
var element = this.parseJSXElement();
this.finishJSX();
return element;
};
return JSXParser;
}(parser_1.Parser));
exports.JSXParser = JSXParser;
/***/ },
/* 12 */
/***/ function(module, exports) {
// Generated by generate-xhtml-entities.js. DO NOT MODIFY!
"use strict";
exports.XHTMLEntities = {
quot: '\u0022',
amp: '\u0026',
apos: '\u0027',
gt: '\u003E',
nbsp: '\u00A0',
iexcl: '\u00A1',
cent: '\u00A2',
pound: '\u00A3',
curren: '\u00A4',
yen: '\u00A5',
brvbar: '\u00A6',
sect: '\u00A7',
uml: '\u00A8',
copy: '\u00A9',
ordf: '\u00AA',
laquo: '\u00AB',
not: '\u00AC',
shy: '\u00AD',
reg: '\u00AE',
macr: '\u00AF',
deg: '\u00B0',
plusmn: '\u00B1',
sup2: '\u00B2',
sup3: '\u00B3',
acute: '\u00B4',
micro: '\u00B5',
para: '\u00B6',
middot: '\u00B7',
cedil: '\u00B8',
sup1: '\u00B9',
ordm: '\u00BA',
raquo: '\u00BB',
frac14: '\u00BC',
frac12: '\u00BD',
frac34: '\u00BE',
iquest: '\u00BF',
Agrave: '\u00C0',
Aacute: '\u00C1',
Acirc: '\u00C2',
Atilde: '\u00C3',
Auml: '\u00C4',
Aring: '\u00C5',
AElig: '\u00C6',
Ccedil: '\u00C7',
Egrave: '\u00C8',
Eacute: '\u00C9',
Ecirc: '\u00CA',
Euml: '\u00CB',
Igrave: '\u00CC',
Iacute: '\u00CD',
Icirc: '\u00CE',
Iuml: '\u00CF',
ETH: '\u00D0',
Ntilde: '\u00D1',
Ograve: '\u00D2',
Oacute: '\u00D3',
Ocirc: '\u00D4',
Otilde: '\u00D5',
Ouml: '\u00D6',
times: '\u00D7',
Oslash: '\u00D8',
Ugrave: '\u00D9',
Uacute: '\u00DA',
Ucirc: '\u00DB',
Uuml: '\u00DC',
Yacute: '\u00DD',
THORN: '\u00DE',
szlig: '\u00DF',
agrave: '\u00E0',
aacute: '\u00E1',
acirc: '\u00E2',
atilde: '\u00E3',
auml: '\u00E4',
aring: '\u00E5',
aelig: '\u00E6',
ccedil: '\u00E7',
egrave: '\u00E8',
eacute: '\u00E9',
ecirc: '\u00EA',
euml: '\u00EB',
igrave: '\u00EC',
iacute: '\u00ED',
icirc: '\u00EE',
iuml: '\u00EF',
eth: '\u00F0',
ntilde: '\u00F1',
ograve: '\u00F2',
oacute: '\u00F3',
ocirc: '\u00F4',
otilde: '\u00F5',
ouml: '\u00F6',
divide: '\u00F7',
oslash: '\u00F8',
ugrave: '\u00F9',
uacute: '\u00FA',
ucirc: '\u00FB',
uuml: '\u00FC',
yacute: '\u00FD',
thorn: '\u00FE',
yuml: '\u00FF',
OElig: '\u0152',
oelig: '\u0153',
Scaron: '\u0160',
scaron: '\u0161',
Yuml: '\u0178',
fnof: '\u0192',
circ: '\u02C6',
tilde: '\u02DC',
Alpha: '\u0391',
Beta: '\u0392',
Gamma: '\u0393',
Delta: '\u0394',
Epsilon: '\u0395',
Zeta: '\u0396',
Eta: '\u0397',
Theta: '\u0398',
Iota: '\u0399',
Kappa: '\u039A',
Lambda: '\u039B',
Mu: '\u039C',
Nu: '\u039D',
Xi: '\u039E',
Omicron: '\u039F',
Pi: '\u03A0',
Rho: '\u03A1',
Sigma: '\u03A3',
Tau: '\u03A4',
Upsilon: '\u03A5',
Phi: '\u03A6',
Chi: '\u03A7',
Psi: '\u03A8',
Omega: '\u03A9',
alpha: '\u03B1',
beta: '\u03B2',
gamma: '\u03B3',
delta: '\u03B4',
epsilon: '\u03B5',
zeta: '\u03B6',
eta: '\u03B7',
theta: '\u03B8',
iota: '\u03B9',
kappa: '\u03BA',
lambda: '\u03BB',
mu: '\u03BC',
nu: '\u03BD',
xi: '\u03BE',
omicron: '\u03BF',
pi: '\u03C0',
rho: '\u03C1',
sigmaf: '\u03C2',
sigma: '\u03C3',
tau: '\u03C4',
upsilon: '\u03C5',
phi: '\u03C6',
chi: '\u03C7',
psi: '\u03C8',
omega: '\u03C9',
thetasym: '\u03D1',
upsih: '\u03D2',
piv: '\u03D6',
ensp: '\u2002',
emsp: '\u2003',
thinsp: '\u2009',
zwnj: '\u200C',
zwj: '\u200D',
lrm: '\u200E',
rlm: '\u200F',
ndash: '\u2013',
mdash: '\u2014',
lsquo: '\u2018',
rsquo: '\u2019',
sbquo: '\u201A',
ldquo: '\u201C',
rdquo: '\u201D',
bdquo: '\u201E',
dagger: '\u2020',
Dagger: '\u2021',
bull: '\u2022',
hellip: '\u2026',
permil: '\u2030',
prime: '\u2032',
Prime: '\u2033',
lsaquo: '\u2039',
rsaquo: '\u203A',
oline: '\u203E',
frasl: '\u2044',
euro: '\u20AC',
image: '\u2111',
weierp: '\u2118',
real: '\u211C',
trade: '\u2122',
alefsym: '\u2135',
larr: '\u2190',
uarr: '\u2191',
rarr: '\u2192',
darr: '\u2193',
harr: '\u2194',
crarr: '\u21B5',
lArr: '\u21D0',
uArr: '\u21D1',
rArr: '\u21D2',
dArr: '\u21D3',
hArr: '\u21D4',
forall: '\u2200',
part: '\u2202',
exist: '\u2203',
empty: '\u2205',
nabla: '\u2207',
isin: '\u2208',
notin: '\u2209',
ni: '\u220B',
prod: '\u220F',
sum: '\u2211',
minus: '\u2212',
lowast: '\u2217',
radic: '\u221A',
prop: '\u221D',
infin: '\u221E',
ang: '\u2220',
and: '\u2227',
or: '\u2228',
cap: '\u2229',
cup: '\u222A',
int: '\u222B',
there4: '\u2234',
sim: '\u223C',
cong: '\u2245',
asymp: '\u2248',
ne: '\u2260',
equiv: '\u2261',
le: '\u2264',
ge: '\u2265',
sub: '\u2282',
sup: '\u2283',
nsub: '\u2284',
sube: '\u2286',
supe: '\u2287',
oplus: '\u2295',
otimes: '\u2297',
perp: '\u22A5',
sdot: '\u22C5',
lceil: '\u2308',
rceil: '\u2309',
lfloor: '\u230A',
rfloor: '\u230B',
loz: '\u25CA',
spades: '\u2660',
clubs: '\u2663',
hearts: '\u2665',
diams: '\u2666',
lang: '\u27E8',
rang: '\u27E9'
};
/***/ },
/* 13 */
/***/ function(module, exports) {
"use strict";
exports.JSXSyntax = {
JSXAttribute: 'JSXAttribute',
JSXClosingElement: 'JSXClosingElement',
JSXElement: 'JSXElement',
JSXEmptyExpression: 'JSXEmptyExpression',
JSXExpressionContainer: 'JSXExpressionContainer',
JSXIdentifier: 'JSXIdentifier',
JSXMemberExpression: 'JSXMemberExpression',
JSXNamespacedName: 'JSXNamespacedName',
JSXOpeningElement: 'JSXOpeningElement',
JSXSpreadAttribute: 'JSXSpreadAttribute',
JSXText: 'JSXText'
};
/***/ },
/* 14 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var jsx_syntax_1 = __webpack_require__(13);
var JSXClosingElement = (function () {
function JSXClosingElement(name) {
this.type = jsx_syntax_1.JSXSyntax.JSXClosingElement;
this.name = name;
}
return JSXClosingElement;
}());
exports.JSXClosingElement = JSXClosingElement;
var JSXElement = (function () {
function JSXElement(openingElement, children, closingElement) {
this.type = jsx_syntax_1.JSXSyntax.JSXElement;
this.openingElement = openingElement;
this.children = children;
this.closingElement = closingElement;
}
return JSXElement;
}());
exports.JSXElement = JSXElement;
var JSXEmptyExpression = (function () {
function JSXEmptyExpression() {
this.type = jsx_syntax_1.JSXSyntax.JSXEmptyExpression;
}
return JSXEmptyExpression;
}());
exports.JSXEmptyExpression = JSXEmptyExpression;
var JSXExpressionContainer = (function () {
function JSXExpressionContainer(expression) {
this.type = jsx_syntax_1.JSXSyntax.JSXExpressionContainer;
this.expression = expression;
}
return JSXExpressionContainer;
}());
exports.JSXExpressionContainer = JSXExpressionContainer;
var JSXIdentifier = (function () {
function JSXIdentifier(name) {
this.type = jsx_syntax_1.JSXSyntax.JSXIdentifier;
this.name = name;
}
return JSXIdentifier;
}());
exports.JSXIdentifier = JSXIdentifier;
var JSXMemberExpression = (function () {
function JSXMemberExpression(object, property) {
this.type = jsx_syntax_1.JSXSyntax.JSXMemberExpression;
this.object = object;
this.property = property;
}
return JSXMemberExpression;
}());
exports.JSXMemberExpression = JSXMemberExpression;
var JSXAttribute = (function () {
function JSXAttribute(name, value) {
this.type = jsx_syntax_1.JSXSyntax.JSXAttribute;
this.name = name;
this.value = value;
}
return JSXAttribute;
}());
exports.JSXAttribute = JSXAttribute;
var JSXNamespacedName = (function () {
function JSXNamespacedName(namespace, name) {
this.type = jsx_syntax_1.JSXSyntax.JSXNamespacedName;
this.namespace = namespace;
this.name = name;
}
return JSXNamespacedName;
}());
exports.JSXNamespacedName = JSXNamespacedName;
var JSXOpeningElement = (function () {
function JSXOpeningElement(name, selfClosing, attributes) {
this.type = jsx_syntax_1.JSXSyntax.JSXOpeningElement;
this.name = name;
this.selfClosing = selfClosing;
this.attributes = attributes;
}
return JSXOpeningElement;
}());
exports.JSXOpeningElement = JSXOpeningElement;
var JSXSpreadAttribute = (function () {
function JSXSpreadAttribute(argument) {
this.type = jsx_syntax_1.JSXSyntax.JSXSpreadAttribute;
this.argument = argument;
}
return JSXSpreadAttribute;
}());
exports.JSXSpreadAttribute = JSXSpreadAttribute;
var JSXText = (function () {
function JSXText(value, raw) {
this.type = jsx_syntax_1.JSXSyntax.JSXText;
this.value = value;
this.raw = raw;
}
return JSXText;
}());
exports.JSXText = JSXText;
/***/ },
/* 15 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var scanner_1 = __webpack_require__(8);
var error_handler_1 = __webpack_require__(6);
var token_1 = __webpack_require__(7);
var Reader = (function () {
function Reader() {
this.values = [];
this.curly = this.paren = -1;
}
;
// A function following one of those tokens is an expression.
Reader.prototype.beforeFunctionExpression = function (t) {
return ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new',
'return', 'case', 'delete', 'throw', 'void',
// assignment operators
'=', '+=', '-=', '*=', '**=', '/=', '%=', '<<=', '>>=', '>>>=',
'&=', '|=', '^=', ',',
// binary/unary operators
'+', '-', '*', '**', '/', '%', '++', '--', '<<', '>>', '>>>', '&',
'|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=',
'<=', '<', '>', '!=', '!=='].indexOf(t) >= 0;
};
;
// Determine if forward slash (/) is an operator or part of a regular expression
// https://github.com/mozilla/sweet.js/wiki/design
Reader.prototype.isRegexStart = function () {
var previous = this.values[this.values.length - 1];
var regex = (previous !== null);
switch (previous) {
case 'this':
case ']':
regex = false;
break;
case ')':
var check = this.values[this.paren - 1];
regex = (check === 'if' || check === 'while' || check === 'for' || check === 'with');
break;
case '}':
// Dividing a function by anything makes little sense,
// but we have to check for that.
regex = false;
if (this.values[this.curly - 3] === 'function') {
// Anonymous function, e.g. function(){} /42
var check_1 = this.values[this.curly - 4];
regex = check_1 ? !this.beforeFunctionExpression(check_1) : false;
}
else if (this.values[this.curly - 4] === 'function') {
// Named function, e.g. function f(){} /42/
var check_2 = this.values[this.curly - 5];
regex = check_2 ? !this.beforeFunctionExpression(check_2) : true;
}
}
return regex;
};
;
Reader.prototype.push = function (token) {
if (token.type === token_1.Token.Punctuator || token.type === token_1.Token.Keyword) {
if (token.value === '{') {
this.curly = this.values.length;
}
else if (token.value === '(') {
this.paren = this.values.length;
}
this.values.push(token.value);
}
else {
this.values.push(null);
}
};
;
return Reader;
}());
var Tokenizer = (function () {
function Tokenizer(code, config) {
this.errorHandler = new error_handler_1.ErrorHandler();
this.errorHandler.tolerant = config ? (typeof config.tolerant === 'boolean' && config.tolerant) : false;
this.scanner = new scanner_1.Scanner(code, this.errorHandler);
this.scanner.trackComment = config ? (typeof config.comment === 'boolean' && config.comment) : false;
this.trackRange = config ? (typeof config.range === 'boolean' && config.range) : false;
this.trackLoc = config ? (typeof config.loc === 'boolean' && config.loc) : false;
this.buffer = [];
this.reader = new Reader();
}
;
Tokenizer.prototype.errors = function () {
return this.errorHandler.errors;
};
;
Tokenizer.prototype.getNextToken = function () {
if (this.buffer.length === 0) {
var comments = this.scanner.scanComments();
if (this.scanner.trackComment) {
for (var i = 0; i < comments.length; ++i) {
var e = comments[i];
var comment = void 0;
var value = this.scanner.source.slice(e.slice[0], e.slice[1]);
comment = {
type: e.multiLine ? 'BlockComment' : 'LineComment',
value: value
};
if (this.trackRange) {
comment.range = e.range;
}
if (this.trackLoc) {
comment.loc = e.loc;
}
this.buffer.push(comment);
}
}
if (!this.scanner.eof()) {
var loc = void 0;
if (this.trackLoc) {
loc = {
start: {
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
},
end: {}
};
}
var token = void 0;
if (this.scanner.source[this.scanner.index] === '/') {
token = this.reader.isRegexStart() ? this.scanner.scanRegExp() : this.scanner.scanPunctuator();
}
else {
token = this.scanner.lex();
}
this.reader.push(token);
var entry = void 0;
entry = {
type: token_1.TokenName[token.type],
value: this.scanner.source.slice(token.start, token.end)
};
if (this.trackRange) {
entry.range = [token.start, token.end];
}
if (this.trackLoc) {
loc.end = {
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
};
entry.loc = loc;
}
if (token.regex) {
entry.regex = token.regex;
}
this.buffer.push(entry);
}
}
return this.buffer.shift();
};
;
return Tokenizer;
}());
exports.Tokenizer = Tokenizer;
/***/ }
/******/ ])
});
;