LaravelTest
334 строки · 11.8 Кб
1(function () {2'use strict';3
4function copyObj(obj, target, overwrite) {5if (!target) { target = {}; }6for (var prop in obj)7{ if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))8{ target[prop] = obj[prop]; } }9return target10}11
12// Counts the column offset in a string, taking tabs into account.13// Used mostly to find indentation.14function countColumn(string, end, tabSize, startIndex, startValue) {15if (end == null) {16end = string.search(/[^\s\u00a0]/);17if (end == -1) { end = string.length; }18}19for (var i = startIndex || 0, n = startValue || 0;;) {20var nextTab = string.indexOf("\t", i);21if (nextTab < 0 || nextTab >= end)22{ return n + (end - i) }23n += nextTab - i;24n += tabSize - (n % tabSize);25i = nextTab + 1;26}27}28
29function nothing() {}30
31function createObj(base, props) {32var inst;33if (Object.create) {34inst = Object.create(base);35} else {36nothing.prototype = base;37inst = new nothing();38}39if (props) { copyObj(props, inst); }40return inst41}42
43// STRING STREAM44
45// Fed to the mode parsers, provides helper functions to make46// parsers more succinct.47
48var StringStream = function(string, tabSize, lineOracle) {49this.pos = this.start = 0;50this.string = string;51this.tabSize = tabSize || 8;52this.lastColumnPos = this.lastColumnValue = 0;53this.lineStart = 0;54this.lineOracle = lineOracle;55};56
57StringStream.prototype.eol = function () {return this.pos >= this.string.length};58StringStream.prototype.sol = function () {return this.pos == this.lineStart};59StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};60StringStream.prototype.next = function () {61if (this.pos < this.string.length)62{ return this.string.charAt(this.pos++) }63};64StringStream.prototype.eat = function (match) {65var ch = this.string.charAt(this.pos);66var ok;67if (typeof match == "string") { ok = ch == match; }68else { ok = ch && (match.test ? match.test(ch) : match(ch)); }69if (ok) {++this.pos; return ch}70};71StringStream.prototype.eatWhile = function (match) {72var start = this.pos;73while (this.eat(match)){}74return this.pos > start75};76StringStream.prototype.eatSpace = function () {77var start = this.pos;78while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this.pos; }79return this.pos > start80};81StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;};82StringStream.prototype.skipTo = function (ch) {83var found = this.string.indexOf(ch, this.pos);84if (found > -1) {this.pos = found; return true}85};86StringStream.prototype.backUp = function (n) {this.pos -= n;};87StringStream.prototype.column = function () {88if (this.lastColumnPos < this.start) {89this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);90this.lastColumnPos = this.start;91}92return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)93};94StringStream.prototype.indentation = function () {95return countColumn(this.string, null, this.tabSize) -96(this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)97};98StringStream.prototype.match = function (pattern, consume, caseInsensitive) {99if (typeof pattern == "string") {100var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; };101var substr = this.string.substr(this.pos, pattern.length);102if (cased(substr) == cased(pattern)) {103if (consume !== false) { this.pos += pattern.length; }104return true105}106} else {107var match = this.string.slice(this.pos).match(pattern);108if (match && match.index > 0) { return null }109if (match && consume !== false) { this.pos += match[0].length; }110return match111}112};113StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};114StringStream.prototype.hideFirstChars = function (n, inner) {115this.lineStart += n;116try { return inner() }117finally { this.lineStart -= n; }118};119StringStream.prototype.lookAhead = function (n) {120var oracle = this.lineOracle;121return oracle && oracle.lookAhead(n)122};123StringStream.prototype.baseToken = function () {124var oracle = this.lineOracle;125return oracle && oracle.baseToken(this.pos)126};127
128// Known modes, by name and by MIME129var modes = {}, mimeModes = {};130
131// Extra arguments are stored as the mode's dependencies, which is132// used by (legacy) mechanisms like loadmode.js to automatically133// load a mode. (Preferred mechanism is the require/define calls.)134function defineMode(name, mode) {135if (arguments.length > 2)136{ mode.dependencies = Array.prototype.slice.call(arguments, 2); }137modes[name] = mode;138}139
140function defineMIME(mime, spec) {141mimeModes[mime] = spec;142}143
144// Given a MIME type, a {name, ...options} config object, or a name145// string, return a mode config object.146function resolveMode(spec) {147if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {148spec = mimeModes[spec];149} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {150var found = mimeModes[spec.name];151if (typeof found == "string") { found = {name: found}; }152spec = createObj(found, spec);153spec.name = found.name;154} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {155return resolveMode("application/xml")156} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {157return resolveMode("application/json")158}159if (typeof spec == "string") { return {name: spec} }160else { return spec || {name: "null"} }161}162
163// Given a mode spec (anything that resolveMode accepts), find and164// initialize an actual mode object.165function getMode(options, spec) {166spec = resolveMode(spec);167var mfactory = modes[spec.name];168if (!mfactory) { return getMode(options, "text/plain") }169var modeObj = mfactory(options, spec);170if (modeExtensions.hasOwnProperty(spec.name)) {171var exts = modeExtensions[spec.name];172for (var prop in exts) {173if (!exts.hasOwnProperty(prop)) { continue }174if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; }175modeObj[prop] = exts[prop];176}177}178modeObj.name = spec.name;179if (spec.helperType) { modeObj.helperType = spec.helperType; }180if (spec.modeProps) { for (var prop$1 in spec.modeProps)181{ modeObj[prop$1] = spec.modeProps[prop$1]; } }182
183return modeObj184}185
186// This can be used to attach properties to mode objects from187// outside the actual mode definition.188var modeExtensions = {};189function extendMode(mode, properties) {190var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});191copyObj(properties, exts);192}193
194function copyState(mode, state) {195if (state === true) { return state }196if (mode.copyState) { return mode.copyState(state) }197var nstate = {};198for (var n in state) {199var val = state[n];200if (val instanceof Array) { val = val.concat([]); }201nstate[n] = val;202}203return nstate204}205
206// Given a mode and a state (for that mode), find the inner mode and207// state at the position that the state refers to.208function innerMode(mode, state) {209var info;210while (mode.innerMode) {211info = mode.innerMode(state);212if (!info || info.mode == mode) { break }213state = info.state;214mode = info.mode;215}216return info || {mode: mode, state: state}217}218
219function startState(mode, a1, a2) {220return mode.startState ? mode.startState(a1, a2) : true221}222
223var modeMethods = {224__proto__: null,225modes: modes,226mimeModes: mimeModes,227defineMode: defineMode,228defineMIME: defineMIME,229resolveMode: resolveMode,230getMode: getMode,231modeExtensions: modeExtensions,232extendMode: extendMode,233copyState: copyState,234innerMode: innerMode,235startState: startState236};237
238// declare global: globalThis, CodeMirror239
240// Create a minimal CodeMirror needed to use runMode, and assign to root.241var root = typeof globalThis !== 'undefined' ? globalThis : window;242root.CodeMirror = {};243
244// Copy StringStream and mode methods into CodeMirror object.245CodeMirror.StringStream = StringStream;246for (var exported in modeMethods) { CodeMirror[exported] = modeMethods[exported]; }247
248// Minimal default mode.249CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); });250CodeMirror.defineMIME("text/plain", "null");251
252CodeMirror.registerHelper = CodeMirror.registerGlobalHelper = Math.min;253CodeMirror.splitLines = function(string) { return string.split(/\r?\n|\r/) };254CodeMirror.countColumn = countColumn;255
256CodeMirror.defaults = { indentUnit: 2 };257
258// CodeMirror, copyright (c) by Marijn Haverbeke and others259// Distributed under an MIT license: https://codemirror.net/LICENSE260
261(function(mod) {262if (typeof exports == "object" && typeof module == "object") // CommonJS263{ mod(require("../../lib/codemirror")); }264else if (typeof define == "function" && define.amd) // AMD265{ define(["../../lib/codemirror"], mod); }266else // Plain browser env267{ mod(CodeMirror); }268})(function(CodeMirror) {269
270CodeMirror.runMode = function(string, modespec, callback, options) {271var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);272var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;273
274// Create a tokenizing callback function if passed-in callback is a DOM element.275if (callback.appendChild) {276var ie = /MSIE \d/.test(navigator.userAgent);277var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);278var node = callback, col = 0;279node.innerHTML = "";280callback = function(text, style) {281if (text == "\n") {282// Emitting LF or CRLF on IE8 or earlier results in an incorrect display.283// Emitting a carriage return makes everything ok.284node.appendChild(document.createTextNode(ie_lt9 ? '\r' : text));285col = 0;286return;287}288var content = "";289// replace tabs290for (var pos = 0;;) {291var idx = text.indexOf("\t", pos);292if (idx == -1) {293content += text.slice(pos);294col += text.length - pos;295break;296} else {297col += idx - pos;298content += text.slice(pos, idx);299var size = tabSize - col % tabSize;300col += size;301for (var i = 0; i < size; ++i) { content += " "; }302pos = idx + 1;303}304}305// Create a node with token style and append it to the callback DOM element.306if (style) {307var sp = node.appendChild(document.createElement("span"));308sp.className = "cm-" + style.replace(/ +/g, " cm-");309sp.appendChild(document.createTextNode(content));310} else {311node.appendChild(document.createTextNode(content));312}313};314}315
316var lines = CodeMirror.splitLines(string), state = (options && options.state) || CodeMirror.startState(mode);317for (var i = 0, e = lines.length; i < e; ++i) {318if (i) { callback("\n"); }319var stream = new CodeMirror.StringStream(lines[i], null, {320lookAhead: function(n) { return lines[i + n] },321baseToken: function() {}322});323if (!stream.string && mode.blankLine) { mode.blankLine(state); }324while (!stream.eol()) {325var style = mode.token(stream, state);326callback(stream.current(), style, i, stream.start, state, mode);327stream.start = stream.pos;328}329}330};331
332});333
334}());335