|
|
|
@ -173,7 +173,7 @@ exports.kMaxLength = kMaxLength()
|
|
|
|
|
function typedArraySupport () {
|
|
|
|
|
try {
|
|
|
|
|
var arr = new Uint8Array(1)
|
|
|
|
|
arr.foo = function () { return 42 }
|
|
|
|
|
arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
|
|
|
|
|
return arr.foo() === 42 && // typed array instances can be augmented
|
|
|
|
|
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
|
|
|
|
|
arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
|
|
|
|
@ -286,6 +286,8 @@ if (Buffer.TYPED_ARRAY_SUPPORT) {
|
|
|
|
|
function assertSize (size) {
|
|
|
|
|
if (typeof size !== 'number') {
|
|
|
|
|
throw new TypeError('"size" argument must be a number')
|
|
|
|
|
} else if (size < 0) {
|
|
|
|
|
throw new RangeError('"size" argument must not be negative')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -317,7 +319,7 @@ function allocUnsafe (that, size) {
|
|
|
|
|
assertSize(size)
|
|
|
|
|
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
|
|
|
|
|
if (!Buffer.TYPED_ARRAY_SUPPORT) {
|
|
|
|
|
for (var i = 0; i < size; i++) {
|
|
|
|
|
for (var i = 0; i < size; ++i) {
|
|
|
|
|
that[i] = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -349,12 +351,20 @@ function fromString (that, string, encoding) {
|
|
|
|
|
var length = byteLength(string, encoding) | 0
|
|
|
|
|
that = createBuffer(that, length)
|
|
|
|
|
|
|
|
|
|
that.write(string, encoding)
|
|
|
|
|
var actual = that.write(string, encoding)
|
|
|
|
|
|
|
|
|
|
if (actual !== length) {
|
|
|
|
|
// Writing a hex string, for example, that contains invalid characters will
|
|
|
|
|
// cause everything after the first invalid character to be ignored. (e.g.
|
|
|
|
|
// 'abxxcd' will be treated as 'ab')
|
|
|
|
|
that = that.slice(0, actual)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return that
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fromArrayLike (that, array) {
|
|
|
|
|
var length = checked(array.length) | 0
|
|
|
|
|
var length = array.length < 0 ? 0 : checked(array.length) | 0
|
|
|
|
|
that = createBuffer(that, length)
|
|
|
|
|
for (var i = 0; i < length; i += 1) {
|
|
|
|
|
that[i] = array[i] & 255
|
|
|
|
@ -373,7 +383,9 @@ function fromArrayBuffer (that, array, byteOffset, length) {
|
|
|
|
|
throw new RangeError('\'length\' is out of bounds')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (length === undefined) {
|
|
|
|
|
if (byteOffset === undefined && length === undefined) {
|
|
|
|
|
array = new Uint8Array(array)
|
|
|
|
|
} else if (length === undefined) {
|
|
|
|
|
array = new Uint8Array(array, byteOffset)
|
|
|
|
|
} else {
|
|
|
|
|
array = new Uint8Array(array, byteOffset, length)
|
|
|
|
@ -421,7 +433,7 @@ function fromObject (that, obj) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checked (length) {
|
|
|
|
|
// Note: cannot use `length < kMaxLength` here because that fails when
|
|
|
|
|
// Note: cannot use `length < kMaxLength()` here because that fails when
|
|
|
|
|
// length is NaN (which is otherwise coerced to zero.)
|
|
|
|
|
if (length >= kMaxLength()) {
|
|
|
|
|
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
|
|
@ -470,9 +482,9 @@ Buffer.isEncoding = function isEncoding (encoding) {
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
|
case 'ascii':
|
|
|
|
|
case 'latin1':
|
|
|
|
|
case 'binary':
|
|
|
|
|
case 'base64':
|
|
|
|
|
case 'raw':
|
|
|
|
|
case 'ucs2':
|
|
|
|
|
case 'ucs-2':
|
|
|
|
|
case 'utf16le':
|
|
|
|
@ -495,14 +507,14 @@ Buffer.concat = function concat (list, length) {
|
|
|
|
|
var i
|
|
|
|
|
if (length === undefined) {
|
|
|
|
|
length = 0
|
|
|
|
|
for (i = 0; i < list.length; i++) {
|
|
|
|
|
for (i = 0; i < list.length; ++i) {
|
|
|
|
|
length += list[i].length
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var buffer = Buffer.allocUnsafe(length)
|
|
|
|
|
var pos = 0
|
|
|
|
|
for (i = 0; i < list.length; i++) {
|
|
|
|
|
for (i = 0; i < list.length; ++i) {
|
|
|
|
|
var buf = list[i]
|
|
|
|
|
if (!Buffer.isBuffer(buf)) {
|
|
|
|
|
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
|
|
@ -533,10 +545,8 @@ function byteLength (string, encoding) {
|
|
|
|
|
for (;;) {
|
|
|
|
|
switch (encoding) {
|
|
|
|
|
case 'ascii':
|
|
|
|
|
case 'latin1':
|
|
|
|
|
case 'binary':
|
|
|
|
|
// Deprecated
|
|
|
|
|
case 'raw':
|
|
|
|
|
case 'raws':
|
|
|
|
|
return len
|
|
|
|
|
case 'utf8':
|
|
|
|
|
case 'utf-8':
|
|
|
|
@ -609,8 +619,9 @@ function slowToString (encoding, start, end) {
|
|
|
|
|
case 'ascii':
|
|
|
|
|
return asciiSlice(this, start, end)
|
|
|
|
|
|
|
|
|
|
case 'latin1':
|
|
|
|
|
case 'binary':
|
|
|
|
|
return binarySlice(this, start, end)
|
|
|
|
|
return latin1Slice(this, start, end)
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
return base64Slice(this, start, end)
|
|
|
|
@ -662,6 +673,20 @@ Buffer.prototype.swap32 = function swap32 () {
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.swap64 = function swap64 () {
|
|
|
|
|
var len = this.length
|
|
|
|
|
if (len % 8 !== 0) {
|
|
|
|
|
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < len; i += 8) {
|
|
|
|
|
swap(this, i, i + 7)
|
|
|
|
|
swap(this, i + 1, i + 6)
|
|
|
|
|
swap(this, i + 2, i + 5)
|
|
|
|
|
swap(this, i + 3, i + 4)
|
|
|
|
|
}
|
|
|
|
|
return this
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.toString = function toString () {
|
|
|
|
|
var length = this.length | 0
|
|
|
|
|
if (length === 0) return ''
|
|
|
|
@ -744,7 +769,73 @@ Buffer.prototype.compare = function compare (target, start, end, thisStart, this
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function arrayIndexOf (arr, val, byteOffset, encoding) {
|
|
|
|
|
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
|
|
|
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
|
|
|
//
|
|
|
|
|
// Arguments:
|
|
|
|
|
// - buffer - a Buffer to search
|
|
|
|
|
// - val - a string, Buffer, or number
|
|
|
|
|
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
|
|
|
// - encoding - an optional encoding, relevant is val is a string
|
|
|
|
|
// - dir - true for indexOf, false for lastIndexOf
|
|
|
|
|
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
|
|
|
// Empty buffer means no match
|
|
|
|
|
if (buffer.length === 0) return -1
|
|
|
|
|
|
|
|
|
|
// Normalize byteOffset
|
|
|
|
|
if (typeof byteOffset === 'string') {
|
|
|
|
|
encoding = byteOffset
|
|
|
|
|
byteOffset = 0
|
|
|
|
|
} else if (byteOffset > 0x7fffffff) {
|
|
|
|
|
byteOffset = 0x7fffffff
|
|
|
|
|
} else if (byteOffset < -0x80000000) {
|
|
|
|
|
byteOffset = -0x80000000
|
|
|
|
|
}
|
|
|
|
|
byteOffset = +byteOffset // Coerce to Number.
|
|
|
|
|
if (isNaN(byteOffset)) {
|
|
|
|
|
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
|
|
|
byteOffset = dir ? 0 : (buffer.length - 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
|
|
|
if (byteOffset < 0) byteOffset = buffer.length + byteOffset
|
|
|
|
|
if (byteOffset >= buffer.length) {
|
|
|
|
|
if (dir) return -1
|
|
|
|
|
else byteOffset = buffer.length - 1
|
|
|
|
|
} else if (byteOffset < 0) {
|
|
|
|
|
if (dir) byteOffset = 0
|
|
|
|
|
else return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Normalize val
|
|
|
|
|
if (typeof val === 'string') {
|
|
|
|
|
val = Buffer.from(val, encoding)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
|
|
|
if (Buffer.isBuffer(val)) {
|
|
|
|
|
// Special case: looking for empty string/buffer always fails
|
|
|
|
|
if (val.length === 0) {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
|
|
|
} else if (typeof val === 'number') {
|
|
|
|
|
val = val & 0xFF // Search for a byte value [0-255]
|
|
|
|
|
if (Buffer.TYPED_ARRAY_SUPPORT &&
|
|
|
|
|
typeof Uint8Array.prototype.indexOf === 'function') {
|
|
|
|
|
if (dir) {
|
|
|
|
|
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
|
|
|
} else {
|
|
|
|
|
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new TypeError('val must be string, number or Buffer')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
|
|
|
var indexSize = 1
|
|
|
|
|
var arrLength = arr.length
|
|
|
|
|
var valLength = val.length
|
|
|
|
@ -771,61 +862,47 @@ function arrayIndexOf (arr, val, byteOffset, encoding) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var foundIndex = -1
|
|
|
|
|
for (var i = 0; byteOffset + i < arrLength; i++) {
|
|
|
|
|
if (read(arr, byteOffset + i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
|
|
|
if (foundIndex === -1) foundIndex = i
|
|
|
|
|
if (i - foundIndex + 1 === valLength) return (byteOffset + foundIndex) * indexSize
|
|
|
|
|
} else {
|
|
|
|
|
if (foundIndex !== -1) i -= i - foundIndex
|
|
|
|
|
foundIndex = -1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
|
|
|
if (typeof byteOffset === 'string') {
|
|
|
|
|
encoding = byteOffset
|
|
|
|
|
byteOffset = 0
|
|
|
|
|
} else if (byteOffset > 0x7fffffff) {
|
|
|
|
|
byteOffset = 0x7fffffff
|
|
|
|
|
} else if (byteOffset < -0x80000000) {
|
|
|
|
|
byteOffset = -0x80000000
|
|
|
|
|
}
|
|
|
|
|
byteOffset >>= 0
|
|
|
|
|
|
|
|
|
|
if (this.length === 0) return -1
|
|
|
|
|
if (byteOffset >= this.length) return -1
|
|
|
|
|
|
|
|
|
|
// Negative offsets start from the end of the buffer
|
|
|
|
|
if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
|
|
|
|
|
|
|
|
|
|
if (typeof val === 'string') {
|
|
|
|
|
val = Buffer.from(val, encoding)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Buffer.isBuffer(val)) {
|
|
|
|
|
// special case: looking for empty string/buffer always fails
|
|
|
|
|
if (val.length === 0) {
|
|
|
|
|
return -1
|
|
|
|
|
var i
|
|
|
|
|
if (dir) {
|
|
|
|
|
var foundIndex = -1
|
|
|
|
|
for (i = byteOffset; i < arrLength; i++) {
|
|
|
|
|
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
|
|
|
if (foundIndex === -1) foundIndex = i
|
|
|
|
|
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
|
|
|
} else {
|
|
|
|
|
if (foundIndex !== -1) i -= i - foundIndex
|
|
|
|
|
foundIndex = -1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return arrayIndexOf(this, val, byteOffset, encoding)
|
|
|
|
|
}
|
|
|
|
|
if (typeof val === 'number') {
|
|
|
|
|
if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
|
|
|
|
|
return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
|
|
|
|
|
} else {
|
|
|
|
|
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
|
|
|
|
|
for (i = byteOffset; i >= 0; i--) {
|
|
|
|
|
var found = true
|
|
|
|
|
for (var j = 0; j < valLength; j++) {
|
|
|
|
|
if (read(arr, i + j) !== read(val, j)) {
|
|
|
|
|
found = false
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (found) return i
|
|
|
|
|
}
|
|
|
|
|
return arrayIndexOf(this, [ val ], byteOffset, encoding)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new TypeError('val must be string, number or Buffer')
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
|
|
|
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
|
|
|
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
|
|
|
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hexWrite (buf, string, offset, length) {
|
|
|
|
|
offset = Number(offset) || 0
|
|
|
|
|
var remaining = buf.length - offset
|
|
|
|
@ -840,12 +917,12 @@ function hexWrite (buf, string, offset, length) {
|
|
|
|
|
|
|
|
|
|
// must be an even number of digits
|
|
|
|
|
var strLen = string.length
|
|
|
|
|
if (strLen % 2 !== 0) throw new Error('Invalid hex string')
|
|
|
|
|
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
|
|
|
|
|
|
|
|
|
|
if (length > strLen / 2) {
|
|
|
|
|
length = strLen / 2
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
for (var i = 0; i < length; ++i) {
|
|
|
|
|
var parsed = parseInt(string.substr(i * 2, 2), 16)
|
|
|
|
|
if (isNaN(parsed)) return i
|
|
|
|
|
buf[offset + i] = parsed
|
|
|
|
@ -861,7 +938,7 @@ function asciiWrite (buf, string, offset, length) {
|
|
|
|
|
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function binaryWrite (buf, string, offset, length) {
|
|
|
|
|
function latin1Write (buf, string, offset, length) {
|
|
|
|
|
return asciiWrite(buf, string, offset, length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -923,8 +1000,9 @@ Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
|
|
|
case 'ascii':
|
|
|
|
|
return asciiWrite(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'latin1':
|
|
|
|
|
case 'binary':
|
|
|
|
|
return binaryWrite(this, string, offset, length)
|
|
|
|
|
return latin1Write(this, string, offset, length)
|
|
|
|
|
|
|
|
|
|
case 'base64':
|
|
|
|
|
// Warning: maxLength not taken into account in base64Write
|
|
|
|
@ -1059,17 +1137,17 @@ function asciiSlice (buf, start, end) {
|
|
|
|
|
var ret = ''
|
|
|
|
|
end = Math.min(buf.length, end)
|
|
|
|
|
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
for (var i = start; i < end; ++i) {
|
|
|
|
|
ret += String.fromCharCode(buf[i] & 0x7F)
|
|
|
|
|
}
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function binarySlice (buf, start, end) {
|
|
|
|
|
function latin1Slice (buf, start, end) {
|
|
|
|
|
var ret = ''
|
|
|
|
|
end = Math.min(buf.length, end)
|
|
|
|
|
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
for (var i = start; i < end; ++i) {
|
|
|
|
|
ret += String.fromCharCode(buf[i])
|
|
|
|
|
}
|
|
|
|
|
return ret
|
|
|
|
@ -1082,7 +1160,7 @@ function hexSlice (buf, start, end) {
|
|
|
|
|
if (!end || end < 0 || end > len) end = len
|
|
|
|
|
|
|
|
|
|
var out = ''
|
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
|
for (var i = start; i < end; ++i) {
|
|
|
|
|
out += toHex(buf[i])
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
@ -1125,7 +1203,7 @@ Buffer.prototype.slice = function slice (start, end) {
|
|
|
|
|
} else {
|
|
|
|
|
var sliceLen = end - start
|
|
|
|
|
newBuf = new Buffer(sliceLen, undefined)
|
|
|
|
|
for (var i = 0; i < sliceLen; i++) {
|
|
|
|
|
for (var i = 0; i < sliceLen; ++i) {
|
|
|
|
|
newBuf[i] = this[i + start]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1352,7 +1430,7 @@ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
|
|
|
|
|
|
|
|
function objectWriteUInt16 (buf, value, offset, littleEndian) {
|
|
|
|
|
if (value < 0) value = 0xffff + value + 1
|
|
|
|
|
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
|
|
|
|
|
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
|
|
|
|
|
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
|
|
|
|
|
(littleEndian ? i : 1 - i) * 8
|
|
|
|
|
}
|
|
|
|
@ -1386,7 +1464,7 @@ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert
|
|
|
|
|
|
|
|
|
|
function objectWriteUInt32 (buf, value, offset, littleEndian) {
|
|
|
|
|
if (value < 0) value = 0xffffffff + value + 1
|
|
|
|
|
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
|
|
|
|
|
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
|
|
|
|
|
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1601,12 +1679,12 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
|
|
|
|
|
|
|
|
if (this === target && start < targetStart && targetStart < end) {
|
|
|
|
|
// descending copy from end
|
|
|
|
|
for (i = len - 1; i >= 0; i--) {
|
|
|
|
|
for (i = len - 1; i >= 0; --i) {
|
|
|
|
|
target[i + targetStart] = this[i + start]
|
|
|
|
|
}
|
|
|
|
|
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
|
|
|
|
|
// ascending copy from start
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
|
target[i + targetStart] = this[i + start]
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -1667,7 +1745,7 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
|
|
|
|
|
|
|
|
var i
|
|
|
|
|
if (typeof val === 'number') {
|
|
|
|
|
for (i = start; i < end; i++) {
|
|
|
|
|
for (i = start; i < end; ++i) {
|
|
|
|
|
this[i] = val
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -1675,7 +1753,7 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
|
|
|
? val
|
|
|
|
|
: utf8ToBytes(new Buffer(val, encoding).toString())
|
|
|
|
|
var len = bytes.length
|
|
|
|
|
for (i = 0; i < end - start; i++) {
|
|
|
|
|
for (i = 0; i < end - start; ++i) {
|
|
|
|
|
this[i + start] = bytes[i % len]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1717,7 +1795,7 @@ function utf8ToBytes (string, units) {
|
|
|
|
|
var leadSurrogate = null
|
|
|
|
|
var bytes = []
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
for (var i = 0; i < length; ++i) {
|
|
|
|
|
codePoint = string.charCodeAt(i)
|
|
|
|
|
|
|
|
|
|
// is surrogate component
|
|
|
|
@ -1792,7 +1870,7 @@ function utf8ToBytes (string, units) {
|
|
|
|
|
|
|
|
|
|
function asciiToBytes (str) {
|
|
|
|
|
var byteArray = []
|
|
|
|
|
for (var i = 0; i < str.length; i++) {
|
|
|
|
|
for (var i = 0; i < str.length; ++i) {
|
|
|
|
|
// Node's code seems to be doing this and not & 0x7F..
|
|
|
|
|
byteArray.push(str.charCodeAt(i) & 0xFF)
|
|
|
|
|
}
|
|
|
|
@ -1802,7 +1880,7 @@ function asciiToBytes (str) {
|
|
|
|
|
function utf16leToBytes (str, units) {
|
|
|
|
|
var c, hi, lo
|
|
|
|
|
var byteArray = []
|
|
|
|
|
for (var i = 0; i < str.length; i++) {
|
|
|
|
|
for (var i = 0; i < str.length; ++i) {
|
|
|
|
|
if ((units -= 2) < 0) break
|
|
|
|
|
|
|
|
|
|
c = str.charCodeAt(i)
|
|
|
|
@ -1820,7 +1898,7 @@ function base64ToBytes (str) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function blitBuffer (src, dst, offset, length) {
|
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
|
for (var i = 0; i < length; ++i) {
|
|
|
|
|
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
|
|
|
dst[i + offset] = src[i]
|
|
|
|
|
}
|
|
|
|
@ -2914,8 +2992,12 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
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;
|
|
|
|
|
if (cm.options.fixedGutter) {
|
|
|
|
|
if (view[i].gutter)
|
|
|
|
|
view[i].gutter.style.left = left;
|
|
|
|
|
if (view[i].gutterBackground)
|
|
|
|
|
view[i].gutterBackground.style.left = left;
|
|
|
|
|
}
|
|
|
|
|
var align = view[i].alignable;
|
|
|
|
|
if (align) for (var j = 0; j < align.length; j++)
|
|
|
|
|
align[j].style.left = left;
|
|
|
|
@ -3471,7 +3553,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handlePaste(e, cm) {
|
|
|
|
|
var pasted = e.clipboardData && e.clipboardData.getData("text/plain");
|
|
|
|
|
var pasted = e.clipboardData && e.clipboardData.getData("Text");
|
|
|
|
|
if (pasted) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (!cm.isReadOnly() && !cm.options.disableInput)
|
|
|
|
@ -3515,10 +3597,10 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
return {text: text, ranges: ranges};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function disableBrowserMagic(field) {
|
|
|
|
|
function disableBrowserMagic(field, spellcheck) {
|
|
|
|
|
field.setAttribute("autocorrect", "off");
|
|
|
|
|
field.setAttribute("autocapitalize", "off");
|
|
|
|
|
field.setAttribute("spellcheck", "false");
|
|
|
|
|
field.setAttribute("spellcheck", !!spellcheck);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TEXTAREA INPUT STYLE
|
|
|
|
@ -3543,7 +3625,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function hiddenTextarea() {
|
|
|
|
|
var te = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none");
|
|
|
|
|
var te = elt("textarea", null, null, "position: absolute; bottom: -1em; 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
|
|
|
|
@ -3896,10 +3978,14 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
init: function(display) {
|
|
|
|
|
var input = this, cm = input.cm;
|
|
|
|
|
var div = input.div = display.lineDiv;
|
|
|
|
|
disableBrowserMagic(div);
|
|
|
|
|
disableBrowserMagic(div, cm.options.spellcheck);
|
|
|
|
|
|
|
|
|
|
on(div, "paste", function(e) {
|
|
|
|
|
if (!signalDOMEvent(cm, e)) handlePaste(e, cm);
|
|
|
|
|
if (signalDOMEvent(cm, e) || handlePaste(e, cm)) return
|
|
|
|
|
// IE doesn't fire input events, so we schedule a read for the pasted content in this way
|
|
|
|
|
if (ie_version <= 11) setTimeout(operation(cm, function() {
|
|
|
|
|
if (!input.pollContent()) regChange(cm);
|
|
|
|
|
}), 20)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
on(div, "compositionstart", function(e) {
|
|
|
|
@ -3959,23 +4045,27 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// iOS exposes the clipboard API, but seems to discard content inserted into it
|
|
|
|
|
if (e.clipboardData && !ios) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (e.clipboardData) {
|
|
|
|
|
e.clipboardData.clearData();
|
|
|
|
|
e.clipboardData.setData("text/plain", lastCopied.text.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.text.join("\n");
|
|
|
|
|
var hadFocus = document.activeElement;
|
|
|
|
|
selectInput(te);
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
cm.display.lineSpace.removeChild(kludge);
|
|
|
|
|
hadFocus.focus();
|
|
|
|
|
}, 50);
|
|
|
|
|
var content = lastCopied.text.join("\n")
|
|
|
|
|
// iOS exposes the clipboard API, but seems to discard content inserted into it
|
|
|
|
|
e.clipboardData.setData("Text", content);
|
|
|
|
|
if (e.clipboardData.getData("Text") == content) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 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.text.join("\n");
|
|
|
|
|
var hadFocus = document.activeElement;
|
|
|
|
|
selectInput(te);
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
cm.display.lineSpace.removeChild(kludge);
|
|
|
|
|
hadFocus.focus();
|
|
|
|
|
if (hadFocus == div) input.showPrimarySelection()
|
|
|
|
|
}, 50);
|
|
|
|
|
}
|
|
|
|
|
on(div, "copy", onCopyCut);
|
|
|
|
|
on(div, "cut", onCopyCut);
|
|
|
|
@ -4283,7 +4373,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
if (found)
|
|
|
|
|
return badPos(Pos(found.line, found.ch + dist), bad);
|
|
|
|
|
else
|
|
|
|
|
dist += after.textContent.length;
|
|
|
|
|
dist += before.textContent.length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -5010,6 +5100,16 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getUsefulRect(rects, bias) {
|
|
|
|
|
var rect = nullRect
|
|
|
|
|
if (bias == "left") for (var i = 0; i < rects.length; i++) {
|
|
|
|
|
if ((rect = rects[i]).left != rect.right) break
|
|
|
|
|
} else for (var i = rects.length - 1; i >= 0; i--) {
|
|
|
|
|
if ((rect = rects[i]).left != rect.right) break
|
|
|
|
|
}
|
|
|
|
|
return rect
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
@ -5019,17 +5119,10 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
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) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
rect = getUsefulRect(range(node, start, end).getClientRects(), bias)
|
|
|
|
|
if (rect.left || rect.right || start == 0) break;
|
|
|
|
|
end = start;
|
|
|
|
|
start = start - 1;
|
|
|
|
@ -5255,10 +5348,23 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
for (;;) {
|
|
|
|
|
if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
|
|
|
|
|
var ch = x < fromX || x - fromX <= toX - x ? from : to;
|
|
|
|
|
var outside = ch == from ? fromOutside : toOutside
|
|
|
|
|
var xDiff = x - (ch == from ? fromX : toX);
|
|
|
|
|
// This is a kludge to handle the case where the coordinates
|
|
|
|
|
// are after a line-wrapped line. We should replace it with a
|
|
|
|
|
// more general handling of cursor positions around line
|
|
|
|
|
// breaks. (Issue #4078)
|
|
|
|
|
if (toOutside && !bidi && !/\s/.test(lineObj.text.charAt(ch)) && xDiff > 0 &&
|
|
|
|
|
ch < lineObj.text.length && preparedMeasure.view.measure.heights.length > 1) {
|
|
|
|
|
var charSize = measureCharPrepared(cm, preparedMeasure, ch, "right");
|
|
|
|
|
if (innerOff <= charSize.bottom && innerOff >= charSize.top && Math.abs(x - charSize.right) < xDiff) {
|
|
|
|
|
outside = false
|
|
|
|
|
ch++
|
|
|
|
|
xDiff = x - charSize.right
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
|
|
|
|
|
var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
|
|
|
|
|
xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
|
|
|
|
|
var pos = PosWithInfo(lineNo, ch, outside, xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
var step = Math.ceil(dist / 2), middle = from + step;
|
|
|
|
@ -5982,6 +6088,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
// Let the drag handler handle this.
|
|
|
|
|
if (webkit) display.scroller.draggable = true;
|
|
|
|
|
cm.state.draggingText = dragEnd;
|
|
|
|
|
dragEnd.copy = mac ? e.altKey : e.ctrlKey
|
|
|
|
|
// IE's approach to draggable
|
|
|
|
|
if (display.scroller.dragDrop) display.scroller.dragDrop();
|
|
|
|
|
on(document, "mouseup", dragEnd);
|
|
|
|
@ -6212,7 +6319,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
try {
|
|
|
|
|
var text = e.dataTransfer.getData("Text");
|
|
|
|
|
if (text) {
|
|
|
|
|
if (cm.state.draggingText && !(mac ? e.altKey : e.ctrlKey))
|
|
|
|
|
if (cm.state.draggingText && !cm.state.draggingText.copy)
|
|
|
|
|
var selected = cm.listSelections();
|
|
|
|
|
setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
|
|
|
|
|
if (selected) for (var i = 0; i < selected.length; ++i)
|
|
|
|
@ -6727,7 +6834,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
|
|
|
|
|
// Revert a change stored in a document's history.
|
|
|
|
|
function makeChangeFromHistory(doc, type, allowSelectionOnly) {
|
|
|
|
|
if (doc.cm && doc.cm.state.suppressEdits) return;
|
|
|
|
|
if (doc.cm && doc.cm.state.suppressEdits && !allowSelectionOnly) return;
|
|
|
|
|
|
|
|
|
|
var hist = doc.history, event, selAfter = doc.sel;
|
|
|
|
|
var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
|
|
|
|
@ -7253,7 +7360,10 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
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});
|
|
|
|
|
insertSorted(this.state.overlays,
|
|
|
|
|
{mode: mode, modeSpec: spec, opaque: options && options.opaque,
|
|
|
|
|
priority: (options && options.priority) || 0},
|
|
|
|
|
function(overlay) { return overlay.priority })
|
|
|
|
|
this.state.modeGen++;
|
|
|
|
|
regChange(this);
|
|
|
|
|
}),
|
|
|
|
@ -7725,6 +7835,9 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
option("inputStyle", mobile ? "contenteditable" : "textarea", function() {
|
|
|
|
|
throw new Error("inputStyle can not (yet) be changed in a running editor"); // FIXME
|
|
|
|
|
}, true);
|
|
|
|
|
option("spellcheck", false, function(cm, val) {
|
|
|
|
|
cm.getInputField().spellcheck = val
|
|
|
|
|
}, true);
|
|
|
|
|
option("rtlMoveVisually", !windows);
|
|
|
|
|
option("wholeLineUpdateBefore", true);
|
|
|
|
|
|
|
|
|
@ -7834,6 +7947,8 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
spec.name = found.name;
|
|
|
|
|
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
|
|
|
|
|
return CodeMirror.resolveMode("application/xml");
|
|
|
|
|
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
|
|
|
|
|
return CodeMirror.resolveMode("application/json");
|
|
|
|
|
}
|
|
|
|
|
if (typeof spec == "string") return {name: spec};
|
|
|
|
|
else return spec || {name: "null"};
|
|
|
|
@ -9252,6 +9367,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
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,
|
|
|
|
|
trailingSpace: false,
|
|
|
|
|
splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")};
|
|
|
|
|
lineView.measure = {};
|
|
|
|
|
|
|
|
|
@ -9313,7 +9429,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
// 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 displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text
|
|
|
|
|
var special = builder.cm.state.specialChars, mustWrap = false;
|
|
|
|
|
if (!special.test(text)) {
|
|
|
|
|
builder.col += text.length;
|
|
|
|
@ -9358,6 +9474,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
builder.pos++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32
|
|
|
|
|
if (style || startStyle || endStyle || mustWrap || css) {
|
|
|
|
|
var fullStyle = style || "";
|
|
|
|
|
if (startStyle) fullStyle += startStyle;
|
|
|
|
@ -9369,11 +9486,17 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
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;
|
|
|
|
|
function splitSpaces(text, trailingBefore) {
|
|
|
|
|
if (text.length > 1 && !/ /.test(text)) return text
|
|
|
|
|
var spaceBefore = trailingBefore, result = ""
|
|
|
|
|
for (var i = 0; i < text.length; i++) {
|
|
|
|
|
var ch = text.charAt(i)
|
|
|
|
|
if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
|
|
|
|
|
ch = "\u00a0"
|
|
|
|
|
result += ch
|
|
|
|
|
spaceBefore = ch == " "
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Work around nonsense dimensions being reported for stretches of
|
|
|
|
@ -9410,6 +9533,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
builder.content.appendChild(widget);
|
|
|
|
|
}
|
|
|
|
|
builder.pos += size;
|
|
|
|
|
builder.trailingSpace = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Outputs a number of spans to make up a line, taking highlighting
|
|
|
|
@ -10254,7 +10378,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Register a change in the history. Merges changes that are within
|
|
|
|
|
// a single operation, ore are close together with an origin that
|
|
|
|
|
// a single operation, or 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;
|
|
|
|
@ -10657,6 +10781,12 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function insertSorted(array, value, score) {
|
|
|
|
|
var pos = 0, priority = score(value)
|
|
|
|
|
while (pos < array.length && score(array[pos]) <= priority) pos++
|
|
|
|
|
array.splice(pos, 0, value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function nothing() {}
|
|
|
|
|
|
|
|
|
|
function createObj(base, props) {
|
|
|
|
@ -10857,8 +10987,9 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
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();
|
|
|
|
|
removeChildren(measure);
|
|
|
|
|
if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780)
|
|
|
|
|
return badBidiRects = (r1.right - r0.right < 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -11224,7 +11355,7 @@ CodeMirror.overlayMode = function(base, overlay, combine) {
|
|
|
|
|
|
|
|
|
|
// THE END
|
|
|
|
|
|
|
|
|
|
CodeMirror.version = "5.15.2";
|
|
|
|
|
CodeMirror.version = "5.18.2";
|
|
|
|
|
|
|
|
|
|
return CodeMirror;
|
|
|
|
|
});
|
|
|
|
@ -11427,7 +11558,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
list2: "variable-3",
|
|
|
|
|
list3: "keyword",
|
|
|
|
|
hr: "hr",
|
|
|
|
|
image: "tag",
|
|
|
|
|
image: "image",
|
|
|
|
|
imageAltText: "image-alt-text",
|
|
|
|
|
imageMarker: "image-marker",
|
|
|
|
|
formatting: "formatting",
|
|
|
|
|
linkInline: "link",
|
|
|
|
|
linkEmail: "link",
|
|
|
|
@ -11677,6 +11810,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
if (state.strikethrough) { styles.push(tokenTypes.strikethrough); }
|
|
|
|
|
if (state.linkText) { styles.push(tokenTypes.linkText); }
|
|
|
|
|
if (state.code) { styles.push(tokenTypes.code); }
|
|
|
|
|
if (state.image) { styles.push(tokenTypes.image); }
|
|
|
|
|
if (state.imageAltText) { styles.push(tokenTypes.imageAltText, "link"); }
|
|
|
|
|
if (state.imageMarker) { styles.push(tokenTypes.imageMarker); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state.header) { styles.push(tokenTypes.header, tokenTypes.header + "-" + state.header); }
|
|
|
|
@ -11796,12 +11932,29 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
|
|
|
|
|
stream.match(/\[[^\]]*\]/);
|
|
|
|
|
state.imageMarker = true;
|
|
|
|
|
state.image = true;
|
|
|
|
|
if (modeCfg.highlightFormatting) state.formatting = "image";
|
|
|
|
|
return getType(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ch === '[' && state.imageMarker) {
|
|
|
|
|
state.imageMarker = false;
|
|
|
|
|
state.imageAltText = true
|
|
|
|
|
if (modeCfg.highlightFormatting) state.formatting = "image";
|
|
|
|
|
return getType(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ch === ']' && state.imageAltText) {
|
|
|
|
|
if (modeCfg.highlightFormatting) state.formatting = "image";
|
|
|
|
|
var type = getType(state);
|
|
|
|
|
state.imageAltText = false;
|
|
|
|
|
state.image = false;
|
|
|
|
|
state.inline = state.f = linkHref;
|
|
|
|
|
return tokenTypes.image;
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ch === '[' && stream.match(/[^\]]*\](\(.*\)| ?\[.*?\])/, false)) {
|
|
|
|
|
if (ch === '[' && stream.match(/[^\]]*\](\(.*\)| ?\[.*?\])/, false) && !state.image) {
|
|
|
|
|
state.linkText = true;
|
|
|
|
|
if (modeCfg.highlightFormatting) state.formatting = "link";
|
|
|
|
|
return getType(state);
|
|
|
|
@ -12229,7 +12382,7 @@ CodeMirror.defineMIME("text/x-markdown", "markdown");
|
|
|
|
|
{name: "HTML", mime: "text/html", mode: "htmlmixed", ext: ["html", "htm"], alias: ["xhtml"]},
|
|
|
|
|
{name: "HTTP", mime: "message/http", mode: "http"},
|
|
|
|
|
{name: "IDL", mime: "text/x-idl", mode: "idl", ext: ["pro"]},
|
|
|
|
|
{name: "Jade", mime: "text/x-jade", mode: "jade", ext: ["jade"]},
|
|
|
|
|
{name: "Pug", mime: "text/x-pug", mode: "pug", ext: ["jade", "pug"], alias: ["jade"]},
|
|
|
|
|
{name: "Java", mime: "text/x-java", mode: "clike", ext: ["java"]},
|
|
|
|
|
{name: "Java Server Pages", mime: "application/x-jsp", mode: "htmlembedded", ext: ["jsp"], alias: ["jsp"]},
|
|
|
|
|
{name: "JavaScript", mimes: ["text/javascript", "text/ecmascript", "application/javascript", "application/x-javascript", "application/ecmascript"],
|
|
|
|
@ -13957,7 +14110,8 @@ function escape(html, encode) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unescape(html) {
|
|
|
|
|
return html.replace(/&([#\w]+);/g, function(_, n) {
|
|
|
|
|
// explicitly match decimal, hex, and named HTML entities
|
|
|
|
|
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
|
|
|
|
|
n = n.toLowerCase();
|
|
|
|
|
if (n === 'colon') return ':';
|
|
|
|
|
if (n.charAt(0) === '#') {
|
|
|
|
@ -16490,6 +16644,9 @@ SimpleMDE.prototype.render = function(el) {
|
|
|
|
|
cm.save();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if(options.onChange) {
|
|
|
|
|
this.codemirror.on("change", options.onChange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.gui = {};
|
|
|
|
|
|
|
|
|
|