diff2html
Advanced tools
Comparing version 3.4.37 to 3.4.38
@@ -1,28 +0,19 @@ | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
import { LineType } from './types'; | ||
import { escapeForRegExp } from './utils'; | ||
function getExtension(filename, language) { | ||
var filenameParts = filename.split('.'); | ||
const filenameParts = filename.split('.'); | ||
return filenameParts.length > 1 ? filenameParts[filenameParts.length - 1] : language; | ||
} | ||
function startsWithAny(str, prefixes) { | ||
return prefixes.reduce(function (startsWith, prefix) { return startsWith || str.startsWith(prefix); }, false); | ||
return prefixes.reduce((startsWith, prefix) => startsWith || str.startsWith(prefix), false); | ||
} | ||
var baseDiffFilenamePrefixes = ['a/', 'b/', 'i/', 'w/', 'c/', 'o/']; | ||
const baseDiffFilenamePrefixes = ['a/', 'b/', 'i/', 'w/', 'c/', 'o/']; | ||
function getFilename(line, linePrefix, extraPrefix) { | ||
var prefixes = extraPrefix !== undefined ? __spreadArray(__spreadArray([], baseDiffFilenamePrefixes, true), [extraPrefix], false) : baseDiffFilenamePrefixes; | ||
var FilenameRegExp = linePrefix | ||
? new RegExp("^".concat(escapeForRegExp(linePrefix), " \"?(.+?)\"?$")) | ||
const prefixes = extraPrefix !== undefined ? [...baseDiffFilenamePrefixes, extraPrefix] : baseDiffFilenamePrefixes; | ||
const FilenameRegExp = linePrefix | ||
? new RegExp(`^${escapeForRegExp(linePrefix)} "?(.+?)"?$`) | ||
: new RegExp('^"?(.+?)"?$'); | ||
var _a = FilenameRegExp.exec(line) || [], _b = _a[1], filename = _b === void 0 ? '' : _b; | ||
var matchingPrefix = prefixes.find(function (p) { return filename.indexOf(p) === 0; }); | ||
var fnameWithoutPrefix = matchingPrefix ? filename.slice(matchingPrefix.length) : filename; | ||
const [, filename = ''] = FilenameRegExp.exec(line) || []; | ||
const matchingPrefix = prefixes.find(p => filename.indexOf(p) === 0); | ||
const fnameWithoutPrefix = matchingPrefix ? filename.slice(matchingPrefix.length) : filename; | ||
return fnameWithoutPrefix.replace(/\s+\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)? [+-]\d{4}.*$/, ''); | ||
@@ -36,33 +27,32 @@ } | ||
} | ||
export function parse(diffInput, config) { | ||
if (config === void 0) { config = {}; } | ||
var files = []; | ||
var currentFile = null; | ||
var currentBlock = null; | ||
var oldLine = null; | ||
var oldLine2 = null; | ||
var newLine = null; | ||
var possibleOldName = null; | ||
var possibleNewName = null; | ||
var oldFileNameHeader = '--- '; | ||
var newFileNameHeader = '+++ '; | ||
var hunkHeaderPrefix = '@@'; | ||
var oldMode = /^old mode (\d{6})/; | ||
var newMode = /^new mode (\d{6})/; | ||
var deletedFileMode = /^deleted file mode (\d{6})/; | ||
var newFileMode = /^new file mode (\d{6})/; | ||
var copyFrom = /^copy from "?(.+)"?/; | ||
var copyTo = /^copy to "?(.+)"?/; | ||
var renameFrom = /^rename from "?(.+)"?/; | ||
var renameTo = /^rename to "?(.+)"?/; | ||
var similarityIndex = /^similarity index (\d+)%/; | ||
var dissimilarityIndex = /^dissimilarity index (\d+)%/; | ||
var index = /^index ([\da-z]+)\.\.([\da-z]+)\s*(\d{6})?/; | ||
var binaryFiles = /^Binary files (.*) and (.*) differ/; | ||
var binaryDiff = /^GIT binary patch/; | ||
var combinedIndex = /^index ([\da-z]+),([\da-z]+)\.\.([\da-z]+)/; | ||
var combinedMode = /^mode (\d{6}),(\d{6})\.\.(\d{6})/; | ||
var combinedNewFile = /^new file mode (\d{6})/; | ||
var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/; | ||
var diffLines = diffInput | ||
export function parse(diffInput, config = {}) { | ||
const files = []; | ||
let currentFile = null; | ||
let currentBlock = null; | ||
let oldLine = null; | ||
let oldLine2 = null; | ||
let newLine = null; | ||
let possibleOldName = null; | ||
let possibleNewName = null; | ||
const oldFileNameHeader = '--- '; | ||
const newFileNameHeader = '+++ '; | ||
const hunkHeaderPrefix = '@@'; | ||
const oldMode = /^old mode (\d{6})/; | ||
const newMode = /^new mode (\d{6})/; | ||
const deletedFileMode = /^deleted file mode (\d{6})/; | ||
const newFileMode = /^new file mode (\d{6})/; | ||
const copyFrom = /^copy from "?(.+)"?/; | ||
const copyTo = /^copy to "?(.+)"?/; | ||
const renameFrom = /^rename from "?(.+)"?/; | ||
const renameTo = /^rename to "?(.+)"?/; | ||
const similarityIndex = /^similarity index (\d+)%/; | ||
const dissimilarityIndex = /^dissimilarity index (\d+)%/; | ||
const index = /^index ([\da-z]+)\.\.([\da-z]+)\s*(\d{6})?/; | ||
const binaryFiles = /^Binary files (.*) and (.*) differ/; | ||
const binaryDiff = /^GIT binary patch/; | ||
const combinedIndex = /^index ([\da-z]+),([\da-z]+)\.\.([\da-z]+)/; | ||
const combinedMode = /^mode (\d{6}),(\d{6})\.\.(\d{6})/; | ||
const combinedNewFile = /^new file mode (\d{6})/; | ||
const combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/; | ||
const diffLines = diffInput | ||
.replace(/\\ No newline at end of file/g, '') | ||
@@ -104,3 +94,3 @@ .replace(/\r\n?/g, '\n') | ||
saveBlock(); | ||
var values; | ||
let values; | ||
if (currentFile !== null) { | ||
@@ -138,7 +128,7 @@ if ((values = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@.*/.exec(line))) { | ||
return; | ||
var currentLine = { | ||
const currentLine = { | ||
content: line, | ||
}; | ||
var addedPrefixes = currentFile.isCombined ? ['+ ', ' +', '++'] : ['+']; | ||
var deletedPrefixes = currentFile.isCombined ? ['- ', ' -', '--'] : ['-']; | ||
const addedPrefixes = currentFile.isCombined ? ['+ ', ' +', '++'] : ['+']; | ||
const deletedPrefixes = currentFile.isCombined ? ['- ', ' -', '--'] : ['-']; | ||
if (startsWithAny(line, addedPrefixes)) { | ||
@@ -164,3 +154,3 @@ currentFile.addedLines++; | ||
function existHunkHeader(line, lineIdx) { | ||
var idx = lineIdx; | ||
let idx = lineIdx; | ||
while (idx < diffLines.length - 3) { | ||
@@ -179,13 +169,13 @@ if (line.startsWith('diff')) { | ||
} | ||
diffLines.forEach(function (line, lineIndex) { | ||
diffLines.forEach((line, lineIndex) => { | ||
if (!line || line.startsWith('*')) { | ||
return; | ||
} | ||
var values; | ||
var prevLine = diffLines[lineIndex - 1]; | ||
var nxtLine = diffLines[lineIndex + 1]; | ||
var afterNxtLine = diffLines[lineIndex + 2]; | ||
let values; | ||
const prevLine = diffLines[lineIndex - 1]; | ||
const nxtLine = diffLines[lineIndex + 1]; | ||
const afterNxtLine = diffLines[lineIndex + 2]; | ||
if (line.startsWith('diff --git') || line.startsWith('diff --combined')) { | ||
startFile(); | ||
var gitDiffStart = /^diff --git "?([a-ciow]\/.+)"? "?([a-ciow]\/.+)"?/; | ||
const gitDiffStart = /^diff --git "?([a-ciow]\/.+)"? "?([a-ciow]\/.+)"?/; | ||
if ((values = gitDiffStart.exec(line))) { | ||
@@ -203,3 +193,3 @@ possibleOldName = getFilename(values[1], undefined, config.dstPrefix); | ||
startFile(); | ||
var unixDiffBinaryStart = /^Binary files "?([a-ciow]\/.+)"? and "?([a-ciow]\/.+)"? differ/; | ||
const unixDiffBinaryStart = /^Binary files "?([a-ciow]\/.+)"? and "?([a-ciow]\/.+)"? differ/; | ||
if ((values = unixDiffBinaryStart.exec(line))) { | ||
@@ -235,3 +225,3 @@ possibleOldName = getFilename(values[1], undefined, config.dstPrefix); | ||
currentBlock = null; | ||
var message = typeof config.diffTooBigMessage === 'function' | ||
const message = typeof config.diffTooBigMessage === 'function' | ||
? config.diffTooBigMessage(files.length) | ||
@@ -271,3 +261,3 @@ : 'Diff too big to be displayed'; | ||
} | ||
var doesNotExistHunkHeader = !existHunkHeader(line, lineIndex); | ||
const doesNotExistHunkHeader = !existHunkHeader(line, lineIndex); | ||
if (currentFile === null) { | ||
@@ -274,0 +264,0 @@ throw new Error('Where is my file !!!'); |
import * as Hogan from "hogan.js"; | ||
declare type CompiledTemplates = { | ||
type CompiledTemplates = { | ||
[name: string]: Hogan.Template; | ||
@@ -4,0 +4,0 @@ }; |
import * as Hogan from "hogan.js"; | ||
export var defaultTemplates = {}; | ||
export const defaultTemplates = {}; | ||
defaultTemplates["file-summary-line"] = new Hogan.Template({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<li class=\"d2h-file-list-line\">"); t.b("\n" + i); t.b(" <span class=\"d2h-file-name-wrapper\">"); t.b("\n" + i); t.b(t.rp("<fileIcon0", c, p, " ")); t.b(" <a href=\"#"); t.b(t.v(t.f("fileHtmlId", c, p, 0))); t.b("\" class=\"d2h-file-name\">"); t.b(t.v(t.f("fileName", c, p, 0))); t.b("</a>"); t.b("\n" + i); t.b(" <span class=\"d2h-file-stats\">"); t.b("\n" + i); t.b(" <span class=\"d2h-lines-added\">"); t.b(t.v(t.f("addedLines", c, p, 0))); t.b("</span>"); t.b("\n" + i); t.b(" <span class=\"d2h-lines-deleted\">"); t.b(t.v(t.f("deletedLines", c, p, 0))); t.b("</span>"); t.b("\n" + i); t.b(" </span>"); t.b("\n" + i); t.b(" </span>"); t.b("\n" + i); t.b("</li>"); return t.fl(); }, partials: { "<fileIcon0": { name: "fileIcon", partials: {}, subs: {} } }, subs: {} }); | ||
@@ -4,0 +4,0 @@ defaultTemplates["file-summary-wrapper"] = new Hogan.Template({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<div class=\"d2h-file-list-wrapper\">"); t.b("\n" + i); t.b(" <div class=\"d2h-file-list-header\">"); t.b("\n" + i); t.b(" <span class=\"d2h-file-list-title\">Files changed ("); t.b(t.v(t.f("filesNumber", c, p, 0))); t.b(")</span>"); t.b("\n" + i); t.b(" <a class=\"d2h-file-switch d2h-hide\">hide</a>"); t.b("\n" + i); t.b(" <a class=\"d2h-file-switch d2h-show\">show</a>"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" <ol class=\"d2h-file-list\">"); t.b("\n" + i); t.b(" "); t.b(t.t(t.f("files", c, p, 0))); t.b("\n" + i); t.b(" </ol>"); t.b("\n" + i); t.b("</div>"); return t.fl(); }, partials: {}, subs: {} }); |
@@ -1,12 +0,1 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as DiffParser from './diff-parser'; | ||
@@ -18,14 +7,12 @@ import * as fileListPrinter from './file-list-renderer'; | ||
import HoganJsUtils from './hoganjs-utils'; | ||
export var defaultDiff2HtmlConfig = __assign(__assign(__assign({}, defaultLineByLineRendererConfig), defaultSideBySideRendererConfig), { outputFormat: OutputFormatType.LINE_BY_LINE, drawFileList: true }); | ||
export function parse(diffInput, configuration) { | ||
if (configuration === void 0) { configuration = {}; } | ||
return DiffParser.parse(diffInput, __assign(__assign({}, defaultDiff2HtmlConfig), configuration)); | ||
export const defaultDiff2HtmlConfig = Object.assign(Object.assign(Object.assign({}, defaultLineByLineRendererConfig), defaultSideBySideRendererConfig), { outputFormat: OutputFormatType.LINE_BY_LINE, drawFileList: true }); | ||
export function parse(diffInput, configuration = {}) { | ||
return DiffParser.parse(diffInput, Object.assign(Object.assign({}, defaultDiff2HtmlConfig), configuration)); | ||
} | ||
export function html(diffInput, configuration) { | ||
if (configuration === void 0) { configuration = {}; } | ||
var config = __assign(__assign({}, defaultDiff2HtmlConfig), configuration); | ||
var diffJson = typeof diffInput === 'string' ? DiffParser.parse(diffInput, config) : diffInput; | ||
var hoganUtils = new HoganJsUtils(config); | ||
var fileList = config.drawFileList ? fileListPrinter.render(diffJson, hoganUtils) : ''; | ||
var diffOutput = config.outputFormat === 'side-by-side' | ||
export function html(diffInput, configuration = {}) { | ||
const config = Object.assign(Object.assign({}, defaultDiff2HtmlConfig), configuration); | ||
const diffJson = typeof diffInput === 'string' ? DiffParser.parse(diffInput, config) : diffInput; | ||
const hoganUtils = new HoganJsUtils(config); | ||
const fileList = config.drawFileList ? fileListPrinter.render(diffJson, hoganUtils) : ''; | ||
const diffOutput = config.outputFormat === 'side-by-side' | ||
? new SideBySideRenderer(hoganUtils, config).render(diffJson) | ||
@@ -32,0 +19,0 @@ : new LineByLineRenderer(hoganUtils, config).render(diffJson); |
import * as renderUtils from './render-utils'; | ||
var baseTemplatesPath = 'file-summary'; | ||
var iconsBaseTemplatesPath = 'icon'; | ||
const baseTemplatesPath = 'file-summary'; | ||
const iconsBaseTemplatesPath = 'icon'; | ||
export function render(diffFiles, hoganUtils) { | ||
var files = diffFiles | ||
.map(function (file) { | ||
return hoganUtils.render(baseTemplatesPath, 'line', { | ||
fileHtmlId: renderUtils.getHtmlId(file), | ||
oldName: file.oldName, | ||
newName: file.newName, | ||
fileName: renderUtils.filenameDiff(file), | ||
deletedLines: '-' + file.deletedLines, | ||
addedLines: '+' + file.addedLines, | ||
}, { | ||
fileIcon: hoganUtils.template(iconsBaseTemplatesPath, renderUtils.getFileIcon(file)), | ||
}); | ||
}) | ||
const files = diffFiles | ||
.map(file => hoganUtils.render(baseTemplatesPath, 'line', { | ||
fileHtmlId: renderUtils.getHtmlId(file), | ||
oldName: file.oldName, | ||
newName: file.newName, | ||
fileName: renderUtils.filenameDiff(file), | ||
deletedLines: '-' + file.deletedLines, | ||
addedLines: '+' + file.addedLines, | ||
}, { | ||
fileIcon: hoganUtils.template(iconsBaseTemplatesPath, renderUtils.getFileIcon(file)), | ||
})) | ||
.join('\n'); | ||
@@ -19,0 +17,0 @@ return hoganUtils.render(baseTemplatesPath, 'wrapper', { |
@@ -1,47 +0,31 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as Hogan from 'hogan.js'; | ||
import { defaultTemplates } from './diff2html-templates'; | ||
var HoganJsUtils = (function () { | ||
function HoganJsUtils(_a) { | ||
var _b = _a.compiledTemplates, compiledTemplates = _b === void 0 ? {} : _b, _c = _a.rawTemplates, rawTemplates = _c === void 0 ? {} : _c; | ||
var compiledRawTemplates = Object.entries(rawTemplates).reduce(function (previousTemplates, _a) { | ||
var _b; | ||
var name = _a[0], templateString = _a[1]; | ||
var compiledTemplate = Hogan.compile(templateString, { asString: false }); | ||
return __assign(__assign({}, previousTemplates), (_b = {}, _b[name] = compiledTemplate, _b)); | ||
export default class HoganJsUtils { | ||
constructor({ compiledTemplates = {}, rawTemplates = {} }) { | ||
const compiledRawTemplates = Object.entries(rawTemplates).reduce((previousTemplates, [name, templateString]) => { | ||
const compiledTemplate = Hogan.compile(templateString, { asString: false }); | ||
return Object.assign(Object.assign({}, previousTemplates), { [name]: compiledTemplate }); | ||
}, {}); | ||
this.preCompiledTemplates = __assign(__assign(__assign({}, defaultTemplates), compiledTemplates), compiledRawTemplates); | ||
this.preCompiledTemplates = Object.assign(Object.assign(Object.assign({}, defaultTemplates), compiledTemplates), compiledRawTemplates); | ||
} | ||
HoganJsUtils.compile = function (templateString) { | ||
static compile(templateString) { | ||
return Hogan.compile(templateString, { asString: false }); | ||
}; | ||
HoganJsUtils.prototype.render = function (namespace, view, params, partials, indent) { | ||
var templateKey = this.templateKey(namespace, view); | ||
} | ||
render(namespace, view, params, partials, indent) { | ||
const templateKey = this.templateKey(namespace, view); | ||
try { | ||
var template = this.preCompiledTemplates[templateKey]; | ||
const template = this.preCompiledTemplates[templateKey]; | ||
return template.render(params, partials, indent); | ||
} | ||
catch (e) { | ||
throw new Error("Could not find template to render '".concat(templateKey, "'")); | ||
throw new Error(`Could not find template to render '${templateKey}'`); | ||
} | ||
}; | ||
HoganJsUtils.prototype.template = function (namespace, view) { | ||
} | ||
template(namespace, view) { | ||
return this.preCompiledTemplates[this.templateKey(namespace, view)]; | ||
}; | ||
HoganJsUtils.prototype.templateKey = function (namespace, view) { | ||
return "".concat(namespace, "-").concat(view); | ||
}; | ||
return HoganJsUtils; | ||
}()); | ||
export default HoganJsUtils; | ||
} | ||
templateKey(namespace, view) { | ||
return `${namespace}-${view}`; | ||
} | ||
} | ||
//# sourceMappingURL=hoganjs-utils.js.map |
@@ -33,3 +33,3 @@ import HoganJsUtils from './hoganjs-utils'; | ||
} | ||
declare type DiffLineGroups = [ | ||
type DiffLineGroups = [ | ||
(DiffLineContext & DiffLineContent)[], | ||
@@ -39,3 +39,3 @@ (DiffLineDeleted & DiffLineContent)[], | ||
][]; | ||
declare type DiffPreparedLine = { | ||
type DiffPreparedLine = { | ||
type: renderUtils.CSSLineClass; | ||
@@ -47,3 +47,3 @@ prefix: string; | ||
}; | ||
declare type FileHtml = { | ||
type FileHtml = { | ||
left: string; | ||
@@ -50,0 +50,0 @@ right: string; |
@@ -1,49 +0,36 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as Rematch from './rematch'; | ||
import * as renderUtils from './render-utils'; | ||
import { LineType, } from './types'; | ||
export var defaultLineByLineRendererConfig = __assign(__assign({}, renderUtils.defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 }); | ||
var genericTemplatesPath = 'generic'; | ||
var baseTemplatesPath = 'line-by-line'; | ||
var iconsBaseTemplatesPath = 'icon'; | ||
var tagsBaseTemplatesPath = 'tag'; | ||
var LineByLineRenderer = (function () { | ||
function LineByLineRenderer(hoganUtils, config) { | ||
if (config === void 0) { config = {}; } | ||
export const defaultLineByLineRendererConfig = Object.assign(Object.assign({}, renderUtils.defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 }); | ||
const genericTemplatesPath = 'generic'; | ||
const baseTemplatesPath = 'line-by-line'; | ||
const iconsBaseTemplatesPath = 'icon'; | ||
const tagsBaseTemplatesPath = 'tag'; | ||
export default class LineByLineRenderer { | ||
constructor(hoganUtils, config = {}) { | ||
this.hoganUtils = hoganUtils; | ||
this.config = __assign(__assign({}, defaultLineByLineRendererConfig), config); | ||
this.config = Object.assign(Object.assign({}, defaultLineByLineRendererConfig), config); | ||
} | ||
LineByLineRenderer.prototype.render = function (diffFiles) { | ||
var _this = this; | ||
var diffsHtml = diffFiles | ||
.map(function (file) { | ||
var diffs; | ||
render(diffFiles) { | ||
const diffsHtml = diffFiles | ||
.map(file => { | ||
let diffs; | ||
if (file.blocks.length) { | ||
diffs = _this.generateFileHtml(file); | ||
diffs = this.generateFileHtml(file); | ||
} | ||
else { | ||
diffs = _this.generateEmptyDiff(); | ||
diffs = this.generateEmptyDiff(); | ||
} | ||
return _this.makeFileDiffHtml(file, diffs); | ||
return this.makeFileDiffHtml(file, diffs); | ||
}) | ||
.join('\n'); | ||
return this.hoganUtils.render(genericTemplatesPath, 'wrapper', { content: diffsHtml }); | ||
}; | ||
LineByLineRenderer.prototype.makeFileDiffHtml = function (file, diffs) { | ||
} | ||
makeFileDiffHtml(file, diffs) { | ||
if (this.config.renderNothingWhenEmpty && Array.isArray(file.blocks) && file.blocks.length === 0) | ||
return ''; | ||
var fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, 'file-diff'); | ||
var filePathTemplate = this.hoganUtils.template(genericTemplatesPath, 'file-path'); | ||
var fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, 'file'); | ||
var fileTagTemplate = this.hoganUtils.template(tagsBaseTemplatesPath, renderUtils.getFileIcon(file)); | ||
const fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, 'file-diff'); | ||
const filePathTemplate = this.hoganUtils.template(genericTemplatesPath, 'file-path'); | ||
const fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, 'file'); | ||
const fileTagTemplate = this.hoganUtils.template(tagsBaseTemplatesPath, renderUtils.getFileIcon(file)); | ||
return fileDiffTemplate.render({ | ||
@@ -60,4 +47,4 @@ file: file, | ||
}); | ||
}; | ||
LineByLineRenderer.prototype.generateEmptyDiff = function () { | ||
} | ||
generateEmptyDiff() { | ||
return this.hoganUtils.render(genericTemplatesPath, 'empty-diff', { | ||
@@ -67,9 +54,8 @@ contentClass: 'd2h-code-line', | ||
}); | ||
}; | ||
LineByLineRenderer.prototype.generateFileHtml = function (file) { | ||
var _this = this; | ||
var matcher = Rematch.newMatcherFn(Rematch.newDistanceFn(function (e) { return renderUtils.deconstructLine(e.content, file.isCombined).content; })); | ||
} | ||
generateFileHtml(file) { | ||
const matcher = Rematch.newMatcherFn(Rematch.newDistanceFn((e) => renderUtils.deconstructLine(e.content, file.isCombined).content)); | ||
return file.blocks | ||
.map(function (block) { | ||
var lines = _this.hoganUtils.render(genericTemplatesPath, 'block-header', { | ||
.map(block => { | ||
let lines = this.hoganUtils.render(genericTemplatesPath, 'block-header', { | ||
CSSLineClass: renderUtils.CSSLineClass, | ||
@@ -80,8 +66,6 @@ blockHeader: file.isTooBig ? block.header : renderUtils.escapeForHtml(block.header), | ||
}); | ||
_this.applyLineGroupping(block).forEach(function (_a) { | ||
var contextLines = _a[0], oldLines = _a[1], newLines = _a[2]; | ||
this.applyLineGroupping(block).forEach(([contextLines, oldLines, newLines]) => { | ||
if (oldLines.length && newLines.length && !contextLines.length) { | ||
_this.applyRematchMatching(oldLines, newLines, matcher).map(function (_a) { | ||
var oldLines = _a[0], newLines = _a[1]; | ||
var _b = _this.processChangedLines(file, file.isCombined, oldLines, newLines), left = _b.left, right = _b.right; | ||
this.applyRematchMatching(oldLines, newLines, matcher).map(([oldLines, newLines]) => { | ||
const { left, right } = this.processChangedLines(file, file.isCombined, oldLines, newLines); | ||
lines += left; | ||
@@ -92,5 +76,5 @@ lines += right; | ||
else if (contextLines.length) { | ||
contextLines.forEach(function (line) { | ||
var _a = renderUtils.deconstructLine(line.content, file.isCombined), prefix = _a.prefix, content = _a.content; | ||
lines += _this.generateSingleLineHtml(file, { | ||
contextLines.forEach(line => { | ||
const { prefix, content } = renderUtils.deconstructLine(line.content, file.isCombined); | ||
lines += this.generateSingleLineHtml(file, { | ||
type: renderUtils.CSSLineClass.CONTEXT, | ||
@@ -105,3 +89,3 @@ prefix: prefix, | ||
else if (oldLines.length || newLines.length) { | ||
var _b = _this.processChangedLines(file, file.isCombined, oldLines, newLines), left = _b.left, right = _b.right; | ||
const { left, right } = this.processChangedLines(file, file.isCombined, oldLines, newLines); | ||
lines += left; | ||
@@ -117,9 +101,9 @@ lines += right; | ||
.join('\n'); | ||
}; | ||
LineByLineRenderer.prototype.applyLineGroupping = function (block) { | ||
var blockLinesGroups = []; | ||
var oldLines = []; | ||
var newLines = []; | ||
for (var i = 0; i < block.lines.length; i++) { | ||
var diffLine = block.lines[i]; | ||
} | ||
applyLineGroupping(block) { | ||
const blockLinesGroups = []; | ||
let oldLines = []; | ||
let newLines = []; | ||
for (let i = 0; i < block.lines.length; i++) { | ||
const diffLine = block.lines[i]; | ||
if ((diffLine.type !== LineType.INSERT && newLines.length) || | ||
@@ -150,25 +134,25 @@ (diffLine.type === LineType.CONTEXT && oldLines.length > 0)) { | ||
return blockLinesGroups; | ||
}; | ||
LineByLineRenderer.prototype.applyRematchMatching = function (oldLines, newLines, matcher) { | ||
var comparisons = oldLines.length * newLines.length; | ||
var maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(function (elem) { return elem.content.length; }))); | ||
var doMatching = comparisons < this.config.matchingMaxComparisons && | ||
} | ||
applyRematchMatching(oldLines, newLines, matcher) { | ||
const comparisons = oldLines.length * newLines.length; | ||
const maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(elem => elem.content.length))); | ||
const doMatching = comparisons < this.config.matchingMaxComparisons && | ||
maxLineSizeInBlock < this.config.maxLineSizeInBlockForComparison && | ||
(this.config.matching === 'lines' || this.config.matching === 'words'); | ||
return doMatching ? matcher(oldLines, newLines) : [[oldLines, newLines]]; | ||
}; | ||
LineByLineRenderer.prototype.processChangedLines = function (file, isCombined, oldLines, newLines) { | ||
var fileHtml = { | ||
} | ||
processChangedLines(file, isCombined, oldLines, newLines) { | ||
const fileHtml = { | ||
right: '', | ||
left: '', | ||
}; | ||
var maxLinesNumber = Math.max(oldLines.length, newLines.length); | ||
for (var i = 0; i < maxLinesNumber; i++) { | ||
var oldLine = oldLines[i]; | ||
var newLine = newLines[i]; | ||
var diff = oldLine !== undefined && newLine !== undefined | ||
const maxLinesNumber = Math.max(oldLines.length, newLines.length); | ||
for (let i = 0; i < maxLinesNumber; i++) { | ||
const oldLine = oldLines[i]; | ||
const newLine = newLines[i]; | ||
const diff = oldLine !== undefined && newLine !== undefined | ||
? renderUtils.diffHighlight(oldLine.content, newLine.content, isCombined, this.config) | ||
: undefined; | ||
var preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined | ||
? __assign(__assign({}, (diff !== undefined | ||
const preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined | ||
? Object.assign(Object.assign({}, (diff !== undefined | ||
? { | ||
@@ -179,5 +163,5 @@ prefix: diff.oldLine.prefix, | ||
} | ||
: __assign(__assign({}, renderUtils.deconstructLine(oldLine.content, isCombined)), { type: renderUtils.toCSSClass(oldLine.type) }))), { oldNumber: oldLine.oldNumber, newNumber: oldLine.newNumber }) : undefined; | ||
var preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined | ||
? __assign(__assign({}, (diff !== undefined | ||
: Object.assign(Object.assign({}, renderUtils.deconstructLine(oldLine.content, isCombined)), { type: renderUtils.toCSSClass(oldLine.type) }))), { oldNumber: oldLine.oldNumber, newNumber: oldLine.newNumber }) : undefined; | ||
const preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined | ||
? Object.assign(Object.assign({}, (diff !== undefined | ||
? { | ||
@@ -188,4 +172,4 @@ prefix: diff.newLine.prefix, | ||
} | ||
: __assign(__assign({}, renderUtils.deconstructLine(newLine.content, isCombined)), { type: renderUtils.toCSSClass(newLine.type) }))), { oldNumber: newLine.oldNumber, newNumber: newLine.newNumber }) : undefined; | ||
var _a = this.generateLineHtml(file, preparedOldLine, preparedNewLine), left = _a.left, right = _a.right; | ||
: Object.assign(Object.assign({}, renderUtils.deconstructLine(newLine.content, isCombined)), { type: renderUtils.toCSSClass(newLine.type) }))), { oldNumber: newLine.oldNumber, newNumber: newLine.newNumber }) : undefined; | ||
const { left, right } = this.generateLineHtml(file, preparedOldLine, preparedNewLine); | ||
fileHtml.left += left; | ||
@@ -195,4 +179,4 @@ fileHtml.right += right; | ||
return fileHtml; | ||
}; | ||
LineByLineRenderer.prototype.generateLineHtml = function (file, oldLine, newLine) { | ||
} | ||
generateLineHtml(file, oldLine, newLine) { | ||
return { | ||
@@ -202,7 +186,7 @@ left: this.generateSingleLineHtml(file, oldLine), | ||
}; | ||
}; | ||
LineByLineRenderer.prototype.generateSingleLineHtml = function (file, line) { | ||
} | ||
generateSingleLineHtml(file, line) { | ||
if (line === undefined) | ||
return ''; | ||
var lineNumberHtml = this.hoganUtils.render(baseTemplatesPath, 'numbers', { | ||
const lineNumberHtml = this.hoganUtils.render(baseTemplatesPath, 'numbers', { | ||
oldNumber: line.oldNumber || '', | ||
@@ -218,9 +202,7 @@ newNumber: line.newNumber || '', | ||
lineNumber: lineNumberHtml, | ||
line: line, | ||
file: file, | ||
line, | ||
file, | ||
}); | ||
}; | ||
return LineByLineRenderer; | ||
}()); | ||
export default LineByLineRenderer; | ||
} | ||
} | ||
//# sourceMappingURL=line-by-line-renderer.js.map |
@@ -1,2 +0,2 @@ | ||
export declare type BestMatch = { | ||
export type BestMatch = { | ||
indexA: number; | ||
@@ -7,6 +7,6 @@ indexB: number; | ||
export declare function levenshtein(a: string, b: string): number; | ||
export declare type DistanceFn<T> = (x: T, y: T) => number; | ||
export type DistanceFn<T> = (x: T, y: T) => number; | ||
export declare function newDistanceFn<T>(str: (value: T) => string): DistanceFn<T>; | ||
export declare type MatcherFn<T> = (a: T[], b: T[], level?: number, cache?: Map<string, number>) => T[][][]; | ||
export type MatcherFn<T> = (a: T[], b: T[], level?: number, cache?: Map<string, number>) => T[][][]; | ||
export declare function newMatcherFn<T>(distance: (x: T, y: T) => number): MatcherFn<T>; | ||
//# sourceMappingURL=rematch.d.ts.map |
@@ -8,8 +8,8 @@ export function levenshtein(a, b) { | ||
} | ||
var matrix = []; | ||
var i; | ||
const matrix = []; | ||
let i; | ||
for (i = 0; i <= b.length; i++) { | ||
matrix[i] = [i]; | ||
} | ||
var j; | ||
let j; | ||
for (j = 0; j <= a.length; j++) { | ||
@@ -31,6 +31,6 @@ matrix[0][j] = j; | ||
export function newDistanceFn(str) { | ||
return function (x, y) { | ||
var xValue = str(x).trim(); | ||
var yValue = str(y).trim(); | ||
var lev = levenshtein(xValue, yValue); | ||
return (x, y) => { | ||
const xValue = str(x).trim(); | ||
const yValue = str(y).trim(); | ||
const lev = levenshtein(xValue, yValue); | ||
return lev / (xValue.length + yValue.length); | ||
@@ -40,10 +40,9 @@ }; | ||
export function newMatcherFn(distance) { | ||
function findBestMatch(a, b, cache) { | ||
if (cache === void 0) { cache = new Map(); } | ||
var bestMatchDist = Infinity; | ||
var bestMatch; | ||
for (var i = 0; i < a.length; ++i) { | ||
for (var j = 0; j < b.length; ++j) { | ||
var cacheKey = JSON.stringify([a[i], b[j]]); | ||
var md = void 0; | ||
function findBestMatch(a, b, cache = new Map()) { | ||
let bestMatchDist = Infinity; | ||
let bestMatch; | ||
for (let i = 0; i < a.length; ++i) { | ||
for (let j = 0; j < b.length; ++j) { | ||
const cacheKey = JSON.stringify([a[i], b[j]]); | ||
let md; | ||
if (!(cache.has(cacheKey) && (md = cache.get(cacheKey)))) { | ||
@@ -61,21 +60,19 @@ md = distance(a[i], b[j]); | ||
} | ||
function group(a, b, level, cache) { | ||
if (level === void 0) { level = 0; } | ||
if (cache === void 0) { cache = new Map(); } | ||
var bm = findBestMatch(a, b, cache); | ||
function group(a, b, level = 0, cache = new Map()) { | ||
const bm = findBestMatch(a, b, cache); | ||
if (!bm || a.length + b.length < 3) { | ||
return [[a, b]]; | ||
} | ||
var a1 = a.slice(0, bm.indexA); | ||
var b1 = b.slice(0, bm.indexB); | ||
var aMatch = [a[bm.indexA]]; | ||
var bMatch = [b[bm.indexB]]; | ||
var tailA = bm.indexA + 1; | ||
var tailB = bm.indexB + 1; | ||
var a2 = a.slice(tailA); | ||
var b2 = b.slice(tailB); | ||
var group1 = group(a1, b1, level + 1, cache); | ||
var groupMatch = group(aMatch, bMatch, level + 1, cache); | ||
var group2 = group(a2, b2, level + 1, cache); | ||
var result = groupMatch; | ||
const a1 = a.slice(0, bm.indexA); | ||
const b1 = b.slice(0, bm.indexB); | ||
const aMatch = [a[bm.indexA]]; | ||
const bMatch = [b[bm.indexB]]; | ||
const tailA = bm.indexA + 1; | ||
const tailB = bm.indexB + 1; | ||
const a2 = a.slice(tailA); | ||
const b2 = b.slice(tailB); | ||
const group1 = group(a1, b1, level + 1, cache); | ||
const groupMatch = group(aMatch, bMatch, level + 1, cache); | ||
const group2 = group(a2, b2, level + 1, cache); | ||
let result = groupMatch; | ||
if (bm.indexA > 0 || bm.indexB > 0) { | ||
@@ -82,0 +79,0 @@ result = group1.concat(result); |
import { LineMatchingType, DiffStyleType, LineType, DiffLineParts, DiffFile, DiffFileName } from './types'; | ||
export declare type CSSLineClass = 'd2h-ins' | 'd2h-del' | 'd2h-cntx' | 'd2h-info' | 'd2h-ins d2h-change' | 'd2h-del d2h-change'; | ||
export type CSSLineClass = 'd2h-ins' | 'd2h-del' | 'd2h-cntx' | 'd2h-info' | 'd2h-ins d2h-change' | 'd2h-del d2h-change'; | ||
export declare const CSSLineClass: { | ||
[_: string]: CSSLineClass; | ||
}; | ||
export declare type HighlightedLines = { | ||
export type HighlightedLines = { | ||
oldLine: { | ||
@@ -8,0 +8,0 @@ prefix: string; |
@@ -1,12 +0,1 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as jsDiff from 'diff'; | ||
@@ -16,3 +5,3 @@ import { unifyPath, hashCode } from './utils'; | ||
import { LineMatchingType, DiffStyleType, LineType } from './types'; | ||
export var CSSLineClass = { | ||
export const CSSLineClass = { | ||
INSERTS: 'd2h-ins', | ||
@@ -25,3 +14,3 @@ DELETES: 'd2h-del', | ||
}; | ||
export var defaultRenderConfig = { | ||
export const defaultRenderConfig = { | ||
matching: LineMatchingType.NONE, | ||
@@ -32,5 +21,5 @@ matchWordsThreshold: 0.25, | ||
}; | ||
var separator = '/'; | ||
var distance = rematch.newDistanceFn(function (change) { return change.value; }); | ||
var matcher = rematch.newMatcherFn(distance); | ||
const separator = '/'; | ||
const distance = rematch.newDistanceFn((change) => change.value); | ||
const matcher = rematch.newMatcherFn(distance); | ||
function isDevNullName(name) { | ||
@@ -68,5 +57,4 @@ return name.indexOf('dev/null') !== -1; | ||
} | ||
export function deconstructLine(line, isCombined, escape) { | ||
if (escape === void 0) { escape = true; } | ||
var indexToSplit = prefixLength(isCombined); | ||
export function deconstructLine(line, isCombined, escape = true) { | ||
const indexToSplit = prefixLength(isCombined); | ||
return { | ||
@@ -78,14 +66,14 @@ prefix: line.substring(0, indexToSplit), | ||
export function filenameDiff(file) { | ||
var oldFilename = unifyPath(file.oldName); | ||
var newFilename = unifyPath(file.newName); | ||
const oldFilename = unifyPath(file.oldName); | ||
const newFilename = unifyPath(file.newName); | ||
if (oldFilename !== newFilename && !isDevNullName(oldFilename) && !isDevNullName(newFilename)) { | ||
var prefixPaths = []; | ||
var suffixPaths = []; | ||
var oldFilenameParts = oldFilename.split(separator); | ||
var newFilenameParts = newFilename.split(separator); | ||
var oldFilenamePartsSize = oldFilenameParts.length; | ||
var newFilenamePartsSize = newFilenameParts.length; | ||
var i = 0; | ||
var j = oldFilenamePartsSize - 1; | ||
var k = newFilenamePartsSize - 1; | ||
const prefixPaths = []; | ||
const suffixPaths = []; | ||
const oldFilenameParts = oldFilename.split(separator); | ||
const newFilenameParts = newFilename.split(separator); | ||
const oldFilenamePartsSize = oldFilenameParts.length; | ||
const newFilenamePartsSize = newFilenameParts.length; | ||
let i = 0; | ||
let j = oldFilenamePartsSize - 1; | ||
let k = newFilenamePartsSize - 1; | ||
while (i < j && i < k) { | ||
@@ -110,6 +98,6 @@ if (oldFilenameParts[i] === newFilenameParts[i]) { | ||
} | ||
var finalPrefix = prefixPaths.join(separator); | ||
var finalSuffix = suffixPaths.join(separator); | ||
var oldRemainingPath = oldFilenameParts.slice(i, j + 1).join(separator); | ||
var newRemainingPath = newFilenameParts.slice(i, k + 1).join(separator); | ||
const finalPrefix = prefixPaths.join(separator); | ||
const finalSuffix = suffixPaths.join(separator); | ||
const oldRemainingPath = oldFilenameParts.slice(i, j + 1).join(separator); | ||
const newRemainingPath = newFilenameParts.slice(i, k + 1).join(separator); | ||
if (finalPrefix.length && finalSuffix.length) { | ||
@@ -134,6 +122,6 @@ return (finalPrefix + separator + '{' + oldRemainingPath + ' โ ' + newRemainingPath + '}' + separator + finalSuffix); | ||
export function getHtmlId(file) { | ||
return "d2h-".concat(hashCode(filenameDiff(file)).toString().slice(-6)); | ||
return `d2h-${hashCode(filenameDiff(file)).toString().slice(-6)}`; | ||
} | ||
export function getFileIcon(file) { | ||
var templateName = 'file-changed'; | ||
let templateName = 'file-changed'; | ||
if (file.isRename) { | ||
@@ -156,7 +144,6 @@ templateName = 'file-renamed'; | ||
} | ||
export function diffHighlight(diffLine1, diffLine2, isCombined, config) { | ||
if (config === void 0) { config = {}; } | ||
var _a = __assign(__assign({}, defaultRenderConfig), config), matching = _a.matching, maxLineLengthHighlight = _a.maxLineLengthHighlight, matchWordsThreshold = _a.matchWordsThreshold, diffStyle = _a.diffStyle; | ||
var line1 = deconstructLine(diffLine1, isCombined, false); | ||
var line2 = deconstructLine(diffLine2, isCombined, false); | ||
export function diffHighlight(diffLine1, diffLine2, isCombined, config = {}) { | ||
const { matching, maxLineLengthHighlight, matchWordsThreshold, diffStyle } = Object.assign(Object.assign({}, defaultRenderConfig), config); | ||
const line1 = deconstructLine(diffLine1, isCombined, false); | ||
const line2 = deconstructLine(diffLine2, isCombined, false); | ||
if (line1.content.length > maxLineLengthHighlight || line2.content.length > maxLineLengthHighlight) { | ||
@@ -174,13 +161,13 @@ return { | ||
} | ||
var diff = diffStyle === 'char' | ||
const diff = diffStyle === 'char' | ||
? jsDiff.diffChars(line1.content, line2.content) | ||
: jsDiff.diffWordsWithSpace(line1.content, line2.content); | ||
var changedWords = []; | ||
const changedWords = []; | ||
if (diffStyle === 'word' && matching === 'words') { | ||
var removed = diff.filter(function (element) { return element.removed; }); | ||
var added = diff.filter(function (element) { return element.added; }); | ||
var chunks = matcher(added, removed); | ||
chunks.forEach(function (chunk) { | ||
const removed = diff.filter(element => element.removed); | ||
const added = diff.filter(element => element.added); | ||
const chunks = matcher(added, removed); | ||
chunks.forEach(chunk => { | ||
if (chunk[0].length === 1 && chunk[1].length === 1) { | ||
var dist = distance(chunk[0][0], chunk[1][0]); | ||
const dist = distance(chunk[0][0], chunk[1][0]); | ||
if (dist < matchWordsThreshold) { | ||
@@ -193,9 +180,9 @@ changedWords.push(chunk[0][0]); | ||
} | ||
var highlightedLine = diff.reduce(function (highlightedLine, part) { | ||
var elemType = part.added ? 'ins' : part.removed ? 'del' : null; | ||
var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : ''; | ||
var escapedValue = escapeForHtml(part.value); | ||
const highlightedLine = diff.reduce((highlightedLine, part) => { | ||
const elemType = part.added ? 'ins' : part.removed ? 'del' : null; | ||
const addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : ''; | ||
const escapedValue = escapeForHtml(part.value); | ||
return elemType !== null | ||
? "".concat(highlightedLine, "<").concat(elemType).concat(addClass, ">").concat(escapedValue, "</").concat(elemType, ">") | ||
: "".concat(highlightedLine).concat(escapedValue); | ||
? `${highlightedLine}<${elemType}${addClass}>${escapedValue}</${elemType}>` | ||
: `${highlightedLine}${escapedValue}`; | ||
}, ''); | ||
@@ -202,0 +189,0 @@ return { |
@@ -34,3 +34,3 @@ import HoganJsUtils from './hoganjs-utils'; | ||
} | ||
declare type DiffLineGroups = [ | ||
type DiffLineGroups = [ | ||
(DiffLineContext & DiffLineContent)[], | ||
@@ -40,3 +40,3 @@ (DiffLineDeleted & DiffLineContent)[], | ||
][]; | ||
declare type DiffPreparedLine = { | ||
type DiffPreparedLine = { | ||
type: renderUtils.CSSLineClass; | ||
@@ -47,3 +47,3 @@ prefix: string; | ||
}; | ||
declare type FileHtml = { | ||
type FileHtml = { | ||
left: string; | ||
@@ -50,0 +50,0 @@ right: string; |
@@ -1,49 +0,36 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import * as Rematch from './rematch'; | ||
import * as renderUtils from './render-utils'; | ||
import { LineType, } from './types'; | ||
export var defaultSideBySideRendererConfig = __assign(__assign({}, renderUtils.defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 }); | ||
var genericTemplatesPath = 'generic'; | ||
var baseTemplatesPath = 'side-by-side'; | ||
var iconsBaseTemplatesPath = 'icon'; | ||
var tagsBaseTemplatesPath = 'tag'; | ||
var SideBySideRenderer = (function () { | ||
function SideBySideRenderer(hoganUtils, config) { | ||
if (config === void 0) { config = {}; } | ||
export const defaultSideBySideRendererConfig = Object.assign(Object.assign({}, renderUtils.defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 }); | ||
const genericTemplatesPath = 'generic'; | ||
const baseTemplatesPath = 'side-by-side'; | ||
const iconsBaseTemplatesPath = 'icon'; | ||
const tagsBaseTemplatesPath = 'tag'; | ||
export default class SideBySideRenderer { | ||
constructor(hoganUtils, config = {}) { | ||
this.hoganUtils = hoganUtils; | ||
this.config = __assign(__assign({}, defaultSideBySideRendererConfig), config); | ||
this.config = Object.assign(Object.assign({}, defaultSideBySideRendererConfig), config); | ||
} | ||
SideBySideRenderer.prototype.render = function (diffFiles) { | ||
var _this = this; | ||
var diffsHtml = diffFiles | ||
.map(function (file) { | ||
var diffs; | ||
render(diffFiles) { | ||
const diffsHtml = diffFiles | ||
.map(file => { | ||
let diffs; | ||
if (file.blocks.length) { | ||
diffs = _this.generateFileHtml(file); | ||
diffs = this.generateFileHtml(file); | ||
} | ||
else { | ||
diffs = _this.generateEmptyDiff(); | ||
diffs = this.generateEmptyDiff(); | ||
} | ||
return _this.makeFileDiffHtml(file, diffs); | ||
return this.makeFileDiffHtml(file, diffs); | ||
}) | ||
.join('\n'); | ||
return this.hoganUtils.render(genericTemplatesPath, 'wrapper', { content: diffsHtml }); | ||
}; | ||
SideBySideRenderer.prototype.makeFileDiffHtml = function (file, diffs) { | ||
} | ||
makeFileDiffHtml(file, diffs) { | ||
if (this.config.renderNothingWhenEmpty && Array.isArray(file.blocks) && file.blocks.length === 0) | ||
return ''; | ||
var fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, 'file-diff'); | ||
var filePathTemplate = this.hoganUtils.template(genericTemplatesPath, 'file-path'); | ||
var fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, 'file'); | ||
var fileTagTemplate = this.hoganUtils.template(tagsBaseTemplatesPath, renderUtils.getFileIcon(file)); | ||
const fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, 'file-diff'); | ||
const filePathTemplate = this.hoganUtils.template(genericTemplatesPath, 'file-path'); | ||
const fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, 'file'); | ||
const fileTagTemplate = this.hoganUtils.template(tagsBaseTemplatesPath, renderUtils.getFileIcon(file)); | ||
return fileDiffTemplate.render({ | ||
@@ -60,4 +47,4 @@ file: file, | ||
}); | ||
}; | ||
SideBySideRenderer.prototype.generateEmptyDiff = function () { | ||
} | ||
generateEmptyDiff() { | ||
return { | ||
@@ -70,18 +57,15 @@ right: '', | ||
}; | ||
}; | ||
SideBySideRenderer.prototype.generateFileHtml = function (file) { | ||
var _this = this; | ||
var matcher = Rematch.newMatcherFn(Rematch.newDistanceFn(function (e) { return renderUtils.deconstructLine(e.content, file.isCombined).content; })); | ||
} | ||
generateFileHtml(file) { | ||
const matcher = Rematch.newMatcherFn(Rematch.newDistanceFn((e) => renderUtils.deconstructLine(e.content, file.isCombined).content)); | ||
return file.blocks | ||
.map(function (block) { | ||
var fileHtml = { | ||
left: _this.makeHeaderHtml(block.header, file), | ||
right: _this.makeHeaderHtml(''), | ||
.map(block => { | ||
const fileHtml = { | ||
left: this.makeHeaderHtml(block.header, file), | ||
right: this.makeHeaderHtml(''), | ||
}; | ||
_this.applyLineGroupping(block).forEach(function (_a) { | ||
var contextLines = _a[0], oldLines = _a[1], newLines = _a[2]; | ||
this.applyLineGroupping(block).forEach(([contextLines, oldLines, newLines]) => { | ||
if (oldLines.length && newLines.length && !contextLines.length) { | ||
_this.applyRematchMatching(oldLines, newLines, matcher).map(function (_a) { | ||
var oldLines = _a[0], newLines = _a[1]; | ||
var _b = _this.processChangedLines(file.isCombined, oldLines, newLines), left = _b.left, right = _b.right; | ||
this.applyRematchMatching(oldLines, newLines, matcher).map(([oldLines, newLines]) => { | ||
const { left, right } = this.processChangedLines(file.isCombined, oldLines, newLines); | ||
fileHtml.left += left; | ||
@@ -92,5 +76,5 @@ fileHtml.right += right; | ||
else if (contextLines.length) { | ||
contextLines.forEach(function (line) { | ||
var _a = renderUtils.deconstructLine(line.content, file.isCombined), prefix = _a.prefix, content = _a.content; | ||
var _b = _this.generateLineHtml({ | ||
contextLines.forEach(line => { | ||
const { prefix, content } = renderUtils.deconstructLine(line.content, file.isCombined); | ||
const { left, right } = this.generateLineHtml({ | ||
type: renderUtils.CSSLineClass.CONTEXT, | ||
@@ -105,3 +89,3 @@ prefix: prefix, | ||
number: line.newNumber, | ||
}), left = _b.left, right = _b.right; | ||
}); | ||
fileHtml.left += left; | ||
@@ -112,3 +96,3 @@ fileHtml.right += right; | ||
else if (oldLines.length || newLines.length) { | ||
var _b = _this.processChangedLines(file.isCombined, oldLines, newLines), left = _b.left, right = _b.right; | ||
const { left, right } = this.processChangedLines(file.isCombined, oldLines, newLines); | ||
fileHtml.left += left; | ||
@@ -123,12 +107,12 @@ fileHtml.right += right; | ||
}) | ||
.reduce(function (accomulated, html) { | ||
.reduce((accomulated, html) => { | ||
return { left: accomulated.left + html.left, right: accomulated.right + html.right }; | ||
}, { left: '', right: '' }); | ||
}; | ||
SideBySideRenderer.prototype.applyLineGroupping = function (block) { | ||
var blockLinesGroups = []; | ||
var oldLines = []; | ||
var newLines = []; | ||
for (var i = 0; i < block.lines.length; i++) { | ||
var diffLine = block.lines[i]; | ||
} | ||
applyLineGroupping(block) { | ||
const blockLinesGroups = []; | ||
let oldLines = []; | ||
let newLines = []; | ||
for (let i = 0; i < block.lines.length; i++) { | ||
const diffLine = block.lines[i]; | ||
if ((diffLine.type !== LineType.INSERT && newLines.length) || | ||
@@ -159,12 +143,12 @@ (diffLine.type === LineType.CONTEXT && oldLines.length > 0)) { | ||
return blockLinesGroups; | ||
}; | ||
SideBySideRenderer.prototype.applyRematchMatching = function (oldLines, newLines, matcher) { | ||
var comparisons = oldLines.length * newLines.length; | ||
var maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(function (elem) { return elem.content.length; }))); | ||
var doMatching = comparisons < this.config.matchingMaxComparisons && | ||
} | ||
applyRematchMatching(oldLines, newLines, matcher) { | ||
const comparisons = oldLines.length * newLines.length; | ||
const maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(elem => elem.content.length))); | ||
const doMatching = comparisons < this.config.matchingMaxComparisons && | ||
maxLineSizeInBlock < this.config.maxLineSizeInBlockForComparison && | ||
(this.config.matching === 'lines' || this.config.matching === 'words'); | ||
return doMatching ? matcher(oldLines, newLines) : [[oldLines, newLines]]; | ||
}; | ||
SideBySideRenderer.prototype.makeHeaderHtml = function (blockHeader, file) { | ||
} | ||
makeHeaderHtml(blockHeader, file) { | ||
return this.hoganUtils.render(genericTemplatesPath, 'block-header', { | ||
@@ -176,17 +160,17 @@ CSSLineClass: renderUtils.CSSLineClass, | ||
}); | ||
}; | ||
SideBySideRenderer.prototype.processChangedLines = function (isCombined, oldLines, newLines) { | ||
var fileHtml = { | ||
} | ||
processChangedLines(isCombined, oldLines, newLines) { | ||
const fileHtml = { | ||
right: '', | ||
left: '', | ||
}; | ||
var maxLinesNumber = Math.max(oldLines.length, newLines.length); | ||
for (var i = 0; i < maxLinesNumber; i++) { | ||
var oldLine = oldLines[i]; | ||
var newLine = newLines[i]; | ||
var diff = oldLine !== undefined && newLine !== undefined | ||
const maxLinesNumber = Math.max(oldLines.length, newLines.length); | ||
for (let i = 0; i < maxLinesNumber; i++) { | ||
const oldLine = oldLines[i]; | ||
const newLine = newLines[i]; | ||
const diff = oldLine !== undefined && newLine !== undefined | ||
? renderUtils.diffHighlight(oldLine.content, newLine.content, isCombined, this.config) | ||
: undefined; | ||
var preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined | ||
? __assign(__assign({}, (diff !== undefined | ||
const preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined | ||
? Object.assign(Object.assign({}, (diff !== undefined | ||
? { | ||
@@ -197,5 +181,5 @@ prefix: diff.oldLine.prefix, | ||
} | ||
: __assign(__assign({}, renderUtils.deconstructLine(oldLine.content, isCombined)), { type: renderUtils.toCSSClass(oldLine.type) }))), { number: oldLine.oldNumber }) : undefined; | ||
var preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined | ||
? __assign(__assign({}, (diff !== undefined | ||
: Object.assign(Object.assign({}, renderUtils.deconstructLine(oldLine.content, isCombined)), { type: renderUtils.toCSSClass(oldLine.type) }))), { number: oldLine.oldNumber }) : undefined; | ||
const preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined | ||
? Object.assign(Object.assign({}, (diff !== undefined | ||
? { | ||
@@ -206,4 +190,4 @@ prefix: diff.newLine.prefix, | ||
} | ||
: __assign(__assign({}, renderUtils.deconstructLine(newLine.content, isCombined)), { type: renderUtils.toCSSClass(newLine.type) }))), { number: newLine.newNumber }) : undefined; | ||
var _a = this.generateLineHtml(preparedOldLine, preparedNewLine), left = _a.left, right = _a.right; | ||
: Object.assign(Object.assign({}, renderUtils.deconstructLine(newLine.content, isCombined)), { type: renderUtils.toCSSClass(newLine.type) }))), { number: newLine.newNumber }) : undefined; | ||
const { left, right } = this.generateLineHtml(preparedOldLine, preparedNewLine); | ||
fileHtml.left += left; | ||
@@ -213,4 +197,4 @@ fileHtml.right += right; | ||
return fileHtml; | ||
}; | ||
SideBySideRenderer.prototype.generateLineHtml = function (oldLine, newLine) { | ||
} | ||
generateLineHtml(oldLine, newLine) { | ||
return { | ||
@@ -220,10 +204,10 @@ left: this.generateSingleHtml(oldLine), | ||
}; | ||
}; | ||
SideBySideRenderer.prototype.generateSingleHtml = function (line) { | ||
var lineClass = 'd2h-code-side-linenumber'; | ||
var contentClass = 'd2h-code-side-line'; | ||
} | ||
generateSingleHtml(line) { | ||
const lineClass = 'd2h-code-side-linenumber'; | ||
const contentClass = 'd2h-code-side-line'; | ||
return this.hoganUtils.render(genericTemplatesPath, 'line', { | ||
type: (line === null || line === void 0 ? void 0 : line.type) || "".concat(renderUtils.CSSLineClass.CONTEXT, " d2h-emptyplaceholder"), | ||
lineClass: line !== undefined ? lineClass : "".concat(lineClass, " d2h-code-side-emptyplaceholder"), | ||
contentClass: line !== undefined ? contentClass : "".concat(contentClass, " d2h-code-side-emptyplaceholder"), | ||
type: (line === null || line === void 0 ? void 0 : line.type) || `${renderUtils.CSSLineClass.CONTEXT} d2h-emptyplaceholder`, | ||
lineClass: line !== undefined ? lineClass : `${lineClass} d2h-code-side-emptyplaceholder`, | ||
contentClass: line !== undefined ? contentClass : `${contentClass} d2h-code-side-emptyplaceholder`, | ||
prefix: (line === null || line === void 0 ? void 0 : line.prefix) === ' ' ? ' ' : line === null || line === void 0 ? void 0 : line.prefix, | ||
@@ -233,6 +217,4 @@ content: line === null || line === void 0 ? void 0 : line.content, | ||
}); | ||
}; | ||
return SideBySideRenderer; | ||
}()); | ||
export default SideBySideRenderer; | ||
} | ||
} | ||
//# sourceMappingURL=side-by-side-renderer.js.map |
@@ -1,2 +0,2 @@ | ||
export declare type DiffLineParts = { | ||
export type DiffLineParts = { | ||
prefix: string; | ||
@@ -25,6 +25,6 @@ content: string; | ||
} | ||
export declare type DiffLineContent = { | ||
export type DiffLineContent = { | ||
content: string; | ||
}; | ||
export declare type DiffLine = (DiffLineDeleted | DiffLineInserted | DiffLineContext) & DiffLineContent; | ||
export type DiffLine = (DiffLineDeleted | DiffLineInserted | DiffLineContext) & DiffLineContent; | ||
export interface DiffBlock { | ||
@@ -64,11 +64,11 @@ oldStartLine: number; | ||
} | ||
export declare type OutputFormatType = 'line-by-line' | 'side-by-side'; | ||
export type OutputFormatType = 'line-by-line' | 'side-by-side'; | ||
export declare const OutputFormatType: { | ||
[_: string]: OutputFormatType; | ||
}; | ||
export declare type LineMatchingType = 'lines' | 'words' | 'none'; | ||
export type LineMatchingType = 'lines' | 'words' | 'none'; | ||
export declare const LineMatchingType: { | ||
[_: string]: LineMatchingType; | ||
}; | ||
export declare type DiffStyleType = 'word' | 'char'; | ||
export type DiffStyleType = 'word' | 'char'; | ||
export declare const DiffStyleType: { | ||
@@ -75,0 +75,0 @@ [_: string]: DiffStyleType; |
@@ -7,7 +7,7 @@ export var LineType; | ||
})(LineType || (LineType = {})); | ||
export var OutputFormatType = { | ||
export const OutputFormatType = { | ||
LINE_BY_LINE: 'line-by-line', | ||
SIDE_BY_SIDE: 'side-by-side', | ||
}; | ||
export var LineMatchingType = { | ||
export const LineMatchingType = { | ||
LINES: 'lines', | ||
@@ -17,3 +17,3 @@ WORDS: 'words', | ||
}; | ||
export var DiffStyleType = { | ||
export const DiffStyleType = { | ||
WORD: 'word', | ||
@@ -20,0 +20,0 @@ CHAR: 'char', |
@@ -1,21 +0,9 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import { closeTags, nodeStream, mergeStreams, getLanguage } from './highlight.js-helpers'; | ||
import { html, defaultDiff2HtmlConfig } from '../../diff2html'; | ||
export var defaultDiff2HtmlUIConfig = __assign(__assign({}, defaultDiff2HtmlConfig), { synchronisedScroll: true, highlight: true, fileListToggle: true, fileListStartVisible: false, highlightLanguages: new Map(), smartSelection: true, fileContentToggle: true, stickyFileHeaders: true }); | ||
var Diff2HtmlUI = (function () { | ||
function Diff2HtmlUI(target, diffInput, config, hljs) { | ||
if (config === void 0) { config = {}; } | ||
export const defaultDiff2HtmlUIConfig = Object.assign(Object.assign({}, defaultDiff2HtmlConfig), { synchronisedScroll: true, highlight: true, fileListToggle: true, fileListStartVisible: false, highlightLanguages: new Map(), smartSelection: true, fileContentToggle: true, stickyFileHeaders: true }); | ||
export class Diff2HtmlUI { | ||
constructor(target, diffInput, config = {}, hljs) { | ||
this.hljs = null; | ||
this.currentSelectionColumnId = -1; | ||
this.config = __assign(__assign({}, defaultDiff2HtmlUIConfig), config); | ||
this.config = Object.assign(Object.assign({}, defaultDiff2HtmlUIConfig), config); | ||
this.diffHtml = diffInput !== undefined ? html(diffInput, this.config) : target.innerHTML; | ||
@@ -26,3 +14,3 @@ this.targetElement = target; | ||
} | ||
Diff2HtmlUI.prototype.draw = function () { | ||
draw() { | ||
this.targetElement.innerHTML = this.diffHtml; | ||
@@ -39,9 +27,9 @@ if (this.config.synchronisedScroll) | ||
this.stickyFileHeaders(); | ||
}; | ||
Diff2HtmlUI.prototype.synchronisedScroll = function () { | ||
this.targetElement.querySelectorAll('.d2h-file-wrapper').forEach(function (wrapper) { | ||
var _a = Array().slice.call(wrapper.querySelectorAll('.d2h-file-side-diff')), left = _a[0], right = _a[1]; | ||
} | ||
synchronisedScroll() { | ||
this.targetElement.querySelectorAll('.d2h-file-wrapper').forEach(wrapper => { | ||
const [left, right] = Array().slice.call(wrapper.querySelectorAll('.d2h-file-side-diff')); | ||
if (left === undefined || right === undefined) | ||
return; | ||
var onScroll = function (event) { | ||
const onScroll = (event) => { | ||
if (event === null || event.target === null) | ||
@@ -61,10 +49,10 @@ return; | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype.fileListToggle = function (startVisible) { | ||
var showBtn = this.targetElement.querySelector('.d2h-show'); | ||
var hideBtn = this.targetElement.querySelector('.d2h-hide'); | ||
var fileList = this.targetElement.querySelector('.d2h-file-list'); | ||
} | ||
fileListToggle(startVisible) { | ||
const showBtn = this.targetElement.querySelector('.d2h-show'); | ||
const hideBtn = this.targetElement.querySelector('.d2h-hide'); | ||
const fileList = this.targetElement.querySelector('.d2h-file-list'); | ||
if (showBtn === null || hideBtn === null || fileList === null) | ||
return; | ||
var show = function () { | ||
const show = () => { | ||
showBtn.style.display = 'none'; | ||
@@ -74,3 +62,3 @@ hideBtn.style.display = 'inline'; | ||
}; | ||
var hide = function () { | ||
const hide = () => { | ||
showBtn.style.display = 'inline'; | ||
@@ -80,5 +68,5 @@ hideBtn.style.display = 'none'; | ||
}; | ||
showBtn.addEventListener('click', function () { return show(); }); | ||
hideBtn.addEventListener('click', function () { return hide(); }); | ||
var hashTag = this.getHashTag(); | ||
showBtn.addEventListener('click', () => show()); | ||
hideBtn.addEventListener('click', () => hide()); | ||
const hashTag = this.getHashTag(); | ||
if (hashTag === 'files-summary-show') | ||
@@ -92,9 +80,9 @@ show(); | ||
hide(); | ||
}; | ||
Diff2HtmlUI.prototype.fileContentToggle = function () { | ||
this.targetElement.querySelectorAll('.d2h-file-collapse').forEach(function (fileContentToggleBtn) { | ||
} | ||
fileContentToggle() { | ||
this.targetElement.querySelectorAll('.d2h-file-collapse').forEach(fileContentToggleBtn => { | ||
fileContentToggleBtn.style.display = 'flex'; | ||
var toggleFileContents = function (selector) { | ||
const toggleFileContents = selector => { | ||
var _a; | ||
var fileContents = (_a = fileContentToggleBtn | ||
const fileContents = (_a = fileContentToggleBtn | ||
.closest('.d2h-file-wrapper')) === null || _a === void 0 ? void 0 : _a.querySelector(selector); | ||
@@ -106,3 +94,3 @@ if (fileContents !== null && fileContents !== undefined) { | ||
}; | ||
var toggleHandler = function (e) { | ||
const toggleHandler = e => { | ||
if (fileContentToggleBtn === e.target) | ||
@@ -113,36 +101,35 @@ return; | ||
}; | ||
fileContentToggleBtn.addEventListener('click', function (e) { return toggleHandler(e); }); | ||
fileContentToggleBtn.addEventListener('click', e => toggleHandler(e)); | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype.highlightCode = function () { | ||
var _this = this; | ||
var hljs = this.hljs; | ||
} | ||
highlightCode() { | ||
const hljs = this.hljs; | ||
if (hljs === null) { | ||
throw new Error('Missing a `highlight.js` implementation. Please provide one when instantiating Diff2HtmlUI.'); | ||
} | ||
var files = this.targetElement.querySelectorAll('.d2h-file-wrapper'); | ||
files.forEach(function (file) { | ||
var language = file.getAttribute('data-lang'); | ||
if (!(_this.config.highlightLanguages instanceof Map)) { | ||
_this.config.highlightLanguages = new Map(Object.entries(_this.config.highlightLanguages)); | ||
const files = this.targetElement.querySelectorAll('.d2h-file-wrapper'); | ||
files.forEach(file => { | ||
const language = file.getAttribute('data-lang'); | ||
if (!(this.config.highlightLanguages instanceof Map)) { | ||
this.config.highlightLanguages = new Map(Object.entries(this.config.highlightLanguages)); | ||
} | ||
var hljsLanguage = language && _this.config.highlightLanguages.has(language) | ||
const hljsLanguage = language && this.config.highlightLanguages.has(language) | ||
? | ||
_this.config.highlightLanguages.get(language) | ||
this.config.highlightLanguages.get(language) | ||
: language | ||
? getLanguage(language) | ||
: 'plaintext'; | ||
var codeLines = file.querySelectorAll('.d2h-code-line-ctn'); | ||
codeLines.forEach(function (line) { | ||
var text = line.textContent; | ||
var lineParent = line.parentNode; | ||
if (text === null || lineParent === null || !_this.isElement(lineParent)) | ||
const codeLines = file.querySelectorAll('.d2h-code-line-ctn'); | ||
codeLines.forEach(line => { | ||
const text = line.textContent; | ||
const lineParent = line.parentNode; | ||
if (text === null || lineParent === null || !this.isElement(lineParent)) | ||
return; | ||
var result = closeTags(hljs.highlight(text, { | ||
const result = closeTags(hljs.highlight(text, { | ||
language: hljsLanguage, | ||
ignoreIllegals: true, | ||
})); | ||
var originalStream = nodeStream(line); | ||
const originalStream = nodeStream(line); | ||
if (originalStream.length) { | ||
var resultNode = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); | ||
const resultNode = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); | ||
resultNode.innerHTML = result.value; | ||
@@ -158,15 +145,15 @@ result.value = mergeStreams(originalStream, nodeStream(resultNode), text); | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype.stickyFileHeaders = function () { | ||
this.targetElement.querySelectorAll('.d2h-file-header').forEach(function (header) { | ||
} | ||
stickyFileHeaders() { | ||
this.targetElement.querySelectorAll('.d2h-file-header').forEach(header => { | ||
header.classList.add('d2h-sticky-header'); | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype.smartSelection = function () { | ||
} | ||
smartSelection() { | ||
console.warn('Smart selection is now enabled by default with CSS. No need to call this method anymore.'); | ||
}; | ||
Diff2HtmlUI.prototype.getHashTag = function () { | ||
var docUrl = document.URL; | ||
var hashTagIndex = docUrl.indexOf('#'); | ||
var hashTag = null; | ||
} | ||
getHashTag() { | ||
const docUrl = document.URL; | ||
const hashTagIndex = docUrl.indexOf('#'); | ||
let hashTag = null; | ||
if (hashTagIndex !== -1) { | ||
@@ -176,9 +163,7 @@ hashTag = docUrl.substr(hashTagIndex + 1); | ||
return hashTag; | ||
}; | ||
Diff2HtmlUI.prototype.isElement = function (arg) { | ||
} | ||
isElement(arg) { | ||
return arg !== null && (arg === null || arg === void 0 ? void 0 : arg.classList) !== undefined; | ||
}; | ||
return Diff2HtmlUI; | ||
}()); | ||
export { Diff2HtmlUI }; | ||
} | ||
} | ||
//# sourceMappingURL=diff2html-ui-base.js.map |
@@ -6,3 +6,4 @@ import { DiffFile } from '../../types'; | ||
} | ||
export { Diff2HtmlUIConfig, defaultDiff2HtmlUIConfig }; | ||
export { defaultDiff2HtmlUIConfig }; | ||
export type { Diff2HtmlUIConfig }; | ||
//# sourceMappingURL=diff2html-ui-slim.d.ts.map |
@@ -1,28 +0,9 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
import { hljs } from './highlight.js-slim'; | ||
import { Diff2HtmlUI as Diff2HtmlUIBase, defaultDiff2HtmlUIConfig } from './diff2html-ui-base'; | ||
var Diff2HtmlUI = (function (_super) { | ||
__extends(Diff2HtmlUI, _super); | ||
function Diff2HtmlUI(target, diffInput, config) { | ||
if (config === void 0) { config = {}; } | ||
return _super.call(this, target, diffInput, config, hljs) || this; | ||
export class Diff2HtmlUI extends Diff2HtmlUIBase { | ||
constructor(target, diffInput, config = {}) { | ||
super(target, diffInput, config, hljs); | ||
} | ||
return Diff2HtmlUI; | ||
}(Diff2HtmlUIBase)); | ||
export { Diff2HtmlUI }; | ||
} | ||
export { defaultDiff2HtmlUIConfig }; | ||
//# sourceMappingURL=diff2html-ui-slim.js.map |
@@ -6,3 +6,4 @@ import { DiffFile } from '../../types'; | ||
} | ||
export { Diff2HtmlUIConfig, defaultDiff2HtmlUIConfig }; | ||
export { defaultDiff2HtmlUIConfig }; | ||
export type { Diff2HtmlUIConfig }; | ||
//# sourceMappingURL=diff2html-ui.d.ts.map |
@@ -1,28 +0,9 @@ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
import hljs from 'highlight.js'; | ||
import { Diff2HtmlUI as Diff2HtmlUIBase, defaultDiff2HtmlUIConfig } from './diff2html-ui-base'; | ||
var Diff2HtmlUI = (function (_super) { | ||
__extends(Diff2HtmlUI, _super); | ||
function Diff2HtmlUI(target, diffInput, config) { | ||
if (config === void 0) { config = {}; } | ||
return _super.call(this, target, diffInput, config, hljs) || this; | ||
export class Diff2HtmlUI extends Diff2HtmlUIBase { | ||
constructor(target, diffInput, config = {}) { | ||
super(target, diffInput, config, hljs); | ||
} | ||
return Diff2HtmlUI; | ||
}(Diff2HtmlUIBase)); | ||
export { Diff2HtmlUI }; | ||
} | ||
export { defaultDiff2HtmlUIConfig }; | ||
//# sourceMappingURL=diff2html-ui.js.map |
import { HighlightResult } from 'highlight.js'; | ||
declare type NodeEvent = { | ||
type NodeEvent = { | ||
event: 'start' | 'stop'; | ||
@@ -4,0 +4,0 @@ offset: number; |
@@ -8,5 +8,5 @@ function escapeHTML(value) { | ||
export function nodeStream(node) { | ||
var result = []; | ||
var nodeStream = function (node, offset) { | ||
for (var child = node.firstChild; child; child = child.nextSibling) { | ||
const result = []; | ||
const nodeStream = (node, offset) => { | ||
for (let child = node.firstChild; child; child = child.nextSibling) { | ||
if (child.nodeType === 3 && child.nodeValue !== null) { | ||
@@ -37,5 +37,5 @@ offset += child.nodeValue.length; | ||
export function mergeStreams(original, highlighted, value) { | ||
var processed = 0; | ||
var result = ''; | ||
var nodeStack = []; | ||
let processed = 0; | ||
let result = ''; | ||
const nodeStack = []; | ||
function isElement(arg) { | ||
@@ -57,5 +57,5 @@ return arg !== null && (arg === null || arg === void 0 ? void 0 : arg.attributes) !== undefined; | ||
} | ||
result += "<".concat(tag(node), " ").concat(Array() | ||
.map.call(node.attributes, function (attr) { return "".concat(attr.nodeName, "=\"").concat(escapeHTML(attr.value).replace(/"/g, '"'), "\""); }) | ||
.join(' '), ">"); | ||
result += `<${tag(node)} ${Array() | ||
.map.call(node.attributes, attr => `${attr.nodeName}="${escapeHTML(attr.value).replace(/"/g, '"')}"`) | ||
.join(' ')}>`; | ||
} | ||
@@ -69,3 +69,3 @@ function close(node) { | ||
while (original.length || highlighted.length) { | ||
var stream = selectStream(); | ||
let stream = selectStream(); | ||
result += escapeHTML(value.substring(processed, stream[0].offset)); | ||
@@ -94,9 +94,9 @@ processed = stream[0].offset; | ||
export function closeTags(res) { | ||
var tokenStack = new Array(); | ||
const tokenStack = new Array(); | ||
res.value = res.value | ||
.split('\n') | ||
.map(function (line) { | ||
var prepend = tokenStack.map(function (token) { return "<span class=\"".concat(token, "\">"); }).join(''); | ||
var matches = line.matchAll(/(<span class="(.*?)">|<\/span>)/g); | ||
Array.from(matches).forEach(function (match) { | ||
.map(line => { | ||
const prepend = tokenStack.map(token => `<span class="${token}">`).join(''); | ||
const matches = line.matchAll(/(<span class="(.*?)">|<\/span>)/g); | ||
Array.from(matches).forEach(match => { | ||
if (match[0] === '</span>') | ||
@@ -107,3 +107,3 @@ tokenStack.shift(); | ||
}); | ||
var append = '</span>'.repeat(tokenStack.length); | ||
const append = '</span>'.repeat(tokenStack.length); | ||
return prepend + line + append; | ||
@@ -114,3 +114,3 @@ }) | ||
} | ||
var languagesToExt = { | ||
const languagesToExt = { | ||
'1c': '1c', | ||
@@ -117,0 +117,0 @@ abnf: 'abnf', |
@@ -104,3 +104,3 @@ import highlightJS from 'highlight.js/lib/core'; | ||
highlightJS.registerLanguage('typescript', typescript); | ||
export var hljs = highlightJS; | ||
export const hljs = highlightJS; | ||
//# sourceMappingURL=highlight.js-slim.js.map |
@@ -1,2 +0,2 @@ | ||
var specials = [ | ||
const specials = [ | ||
'-', | ||
@@ -19,3 +19,3 @@ '[', | ||
]; | ||
var regex = RegExp('[' + specials.join('\\') + ']', 'g'); | ||
const regex = RegExp('[' + specials.join('\\') + ']', 'g'); | ||
export function escapeForRegExp(str) { | ||
@@ -28,4 +28,4 @@ return str.replace(regex, '\\$&'); | ||
export function hashCode(text) { | ||
var i, chr, len; | ||
var hash = 0; | ||
let i, chr, len; | ||
let hash = 0; | ||
for (i = 0, len = text.length; i < len; i++) { | ||
@@ -32,0 +32,0 @@ chr = text.charCodeAt(i); |
"use strict"; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parse = void 0; | ||
var types_1 = require("./types"); | ||
var utils_1 = require("./utils"); | ||
const types_1 = require("./types"); | ||
const utils_1 = require("./utils"); | ||
function getExtension(filename, language) { | ||
var filenameParts = filename.split('.'); | ||
const filenameParts = filename.split('.'); | ||
return filenameParts.length > 1 ? filenameParts[filenameParts.length - 1] : language; | ||
} | ||
function startsWithAny(str, prefixes) { | ||
return prefixes.reduce(function (startsWith, prefix) { return startsWith || str.startsWith(prefix); }, false); | ||
return prefixes.reduce((startsWith, prefix) => startsWith || str.startsWith(prefix), false); | ||
} | ||
var baseDiffFilenamePrefixes = ['a/', 'b/', 'i/', 'w/', 'c/', 'o/']; | ||
const baseDiffFilenamePrefixes = ['a/', 'b/', 'i/', 'w/', 'c/', 'o/']; | ||
function getFilename(line, linePrefix, extraPrefix) { | ||
var prefixes = extraPrefix !== undefined ? __spreadArray(__spreadArray([], baseDiffFilenamePrefixes, true), [extraPrefix], false) : baseDiffFilenamePrefixes; | ||
var FilenameRegExp = linePrefix | ||
? new RegExp("^".concat((0, utils_1.escapeForRegExp)(linePrefix), " \"?(.+?)\"?$")) | ||
const prefixes = extraPrefix !== undefined ? [...baseDiffFilenamePrefixes, extraPrefix] : baseDiffFilenamePrefixes; | ||
const FilenameRegExp = linePrefix | ||
? new RegExp(`^${(0, utils_1.escapeForRegExp)(linePrefix)} "?(.+?)"?$`) | ||
: new RegExp('^"?(.+?)"?$'); | ||
var _a = FilenameRegExp.exec(line) || [], _b = _a[1], filename = _b === void 0 ? '' : _b; | ||
var matchingPrefix = prefixes.find(function (p) { return filename.indexOf(p) === 0; }); | ||
var fnameWithoutPrefix = matchingPrefix ? filename.slice(matchingPrefix.length) : filename; | ||
const [, filename = ''] = FilenameRegExp.exec(line) || []; | ||
const matchingPrefix = prefixes.find(p => filename.indexOf(p) === 0); | ||
const fnameWithoutPrefix = matchingPrefix ? filename.slice(matchingPrefix.length) : filename; | ||
return fnameWithoutPrefix.replace(/\s+\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)? [+-]\d{4}.*$/, ''); | ||
@@ -39,33 +30,32 @@ } | ||
} | ||
function parse(diffInput, config) { | ||
if (config === void 0) { config = {}; } | ||
var files = []; | ||
var currentFile = null; | ||
var currentBlock = null; | ||
var oldLine = null; | ||
var oldLine2 = null; | ||
var newLine = null; | ||
var possibleOldName = null; | ||
var possibleNewName = null; | ||
var oldFileNameHeader = '--- '; | ||
var newFileNameHeader = '+++ '; | ||
var hunkHeaderPrefix = '@@'; | ||
var oldMode = /^old mode (\d{6})/; | ||
var newMode = /^new mode (\d{6})/; | ||
var deletedFileMode = /^deleted file mode (\d{6})/; | ||
var newFileMode = /^new file mode (\d{6})/; | ||
var copyFrom = /^copy from "?(.+)"?/; | ||
var copyTo = /^copy to "?(.+)"?/; | ||
var renameFrom = /^rename from "?(.+)"?/; | ||
var renameTo = /^rename to "?(.+)"?/; | ||
var similarityIndex = /^similarity index (\d+)%/; | ||
var dissimilarityIndex = /^dissimilarity index (\d+)%/; | ||
var index = /^index ([\da-z]+)\.\.([\da-z]+)\s*(\d{6})?/; | ||
var binaryFiles = /^Binary files (.*) and (.*) differ/; | ||
var binaryDiff = /^GIT binary patch/; | ||
var combinedIndex = /^index ([\da-z]+),([\da-z]+)\.\.([\da-z]+)/; | ||
var combinedMode = /^mode (\d{6}),(\d{6})\.\.(\d{6})/; | ||
var combinedNewFile = /^new file mode (\d{6})/; | ||
var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/; | ||
var diffLines = diffInput | ||
function parse(diffInput, config = {}) { | ||
const files = []; | ||
let currentFile = null; | ||
let currentBlock = null; | ||
let oldLine = null; | ||
let oldLine2 = null; | ||
let newLine = null; | ||
let possibleOldName = null; | ||
let possibleNewName = null; | ||
const oldFileNameHeader = '--- '; | ||
const newFileNameHeader = '+++ '; | ||
const hunkHeaderPrefix = '@@'; | ||
const oldMode = /^old mode (\d{6})/; | ||
const newMode = /^new mode (\d{6})/; | ||
const deletedFileMode = /^deleted file mode (\d{6})/; | ||
const newFileMode = /^new file mode (\d{6})/; | ||
const copyFrom = /^copy from "?(.+)"?/; | ||
const copyTo = /^copy to "?(.+)"?/; | ||
const renameFrom = /^rename from "?(.+)"?/; | ||
const renameTo = /^rename to "?(.+)"?/; | ||
const similarityIndex = /^similarity index (\d+)%/; | ||
const dissimilarityIndex = /^dissimilarity index (\d+)%/; | ||
const index = /^index ([\da-z]+)\.\.([\da-z]+)\s*(\d{6})?/; | ||
const binaryFiles = /^Binary files (.*) and (.*) differ/; | ||
const binaryDiff = /^GIT binary patch/; | ||
const combinedIndex = /^index ([\da-z]+),([\da-z]+)\.\.([\da-z]+)/; | ||
const combinedMode = /^mode (\d{6}),(\d{6})\.\.(\d{6})/; | ||
const combinedNewFile = /^new file mode (\d{6})/; | ||
const combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/; | ||
const diffLines = diffInput | ||
.replace(/\\ No newline at end of file/g, '') | ||
@@ -107,3 +97,3 @@ .replace(/\r\n?/g, '\n') | ||
saveBlock(); | ||
var values; | ||
let values; | ||
if (currentFile !== null) { | ||
@@ -141,7 +131,7 @@ if ((values = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@.*/.exec(line))) { | ||
return; | ||
var currentLine = { | ||
const currentLine = { | ||
content: line, | ||
}; | ||
var addedPrefixes = currentFile.isCombined ? ['+ ', ' +', '++'] : ['+']; | ||
var deletedPrefixes = currentFile.isCombined ? ['- ', ' -', '--'] : ['-']; | ||
const addedPrefixes = currentFile.isCombined ? ['+ ', ' +', '++'] : ['+']; | ||
const deletedPrefixes = currentFile.isCombined ? ['- ', ' -', '--'] : ['-']; | ||
if (startsWithAny(line, addedPrefixes)) { | ||
@@ -167,3 +157,3 @@ currentFile.addedLines++; | ||
function existHunkHeader(line, lineIdx) { | ||
var idx = lineIdx; | ||
let idx = lineIdx; | ||
while (idx < diffLines.length - 3) { | ||
@@ -182,13 +172,13 @@ if (line.startsWith('diff')) { | ||
} | ||
diffLines.forEach(function (line, lineIndex) { | ||
diffLines.forEach((line, lineIndex) => { | ||
if (!line || line.startsWith('*')) { | ||
return; | ||
} | ||
var values; | ||
var prevLine = diffLines[lineIndex - 1]; | ||
var nxtLine = diffLines[lineIndex + 1]; | ||
var afterNxtLine = diffLines[lineIndex + 2]; | ||
let values; | ||
const prevLine = diffLines[lineIndex - 1]; | ||
const nxtLine = diffLines[lineIndex + 1]; | ||
const afterNxtLine = diffLines[lineIndex + 2]; | ||
if (line.startsWith('diff --git') || line.startsWith('diff --combined')) { | ||
startFile(); | ||
var gitDiffStart = /^diff --git "?([a-ciow]\/.+)"? "?([a-ciow]\/.+)"?/; | ||
const gitDiffStart = /^diff --git "?([a-ciow]\/.+)"? "?([a-ciow]\/.+)"?/; | ||
if ((values = gitDiffStart.exec(line))) { | ||
@@ -206,3 +196,3 @@ possibleOldName = getFilename(values[1], undefined, config.dstPrefix); | ||
startFile(); | ||
var unixDiffBinaryStart = /^Binary files "?([a-ciow]\/.+)"? and "?([a-ciow]\/.+)"? differ/; | ||
const unixDiffBinaryStart = /^Binary files "?([a-ciow]\/.+)"? and "?([a-ciow]\/.+)"? differ/; | ||
if ((values = unixDiffBinaryStart.exec(line))) { | ||
@@ -238,3 +228,3 @@ possibleOldName = getFilename(values[1], undefined, config.dstPrefix); | ||
currentBlock = null; | ||
var message = typeof config.diffTooBigMessage === 'function' | ||
const message = typeof config.diffTooBigMessage === 'function' | ||
? config.diffTooBigMessage(files.length) | ||
@@ -274,3 +264,3 @@ : 'Diff too big to be displayed'; | ||
} | ||
var doesNotExistHunkHeader = !existHunkHeader(line, lineIndex); | ||
const doesNotExistHunkHeader = !existHunkHeader(line, lineIndex); | ||
if (currentFile === null) { | ||
@@ -277,0 +267,0 @@ throw new Error('Where is my file !!!'); |
import * as Hogan from "hogan.js"; | ||
declare type CompiledTemplates = { | ||
type CompiledTemplates = { | ||
[name: string]: Hogan.Template; | ||
@@ -4,0 +4,0 @@ }; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultTemplates = void 0; | ||
var Hogan = __importStar(require("hogan.js")); | ||
const tslib_1 = require("tslib"); | ||
const Hogan = tslib_1.__importStar(require("hogan.js")); | ||
exports.defaultTemplates = {}; | ||
@@ -29,0 +7,0 @@ exports.defaultTemplates["file-summary-line"] = new Hogan.Template({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<li class=\"d2h-file-list-line\">"); t.b("\n" + i); t.b(" <span class=\"d2h-file-name-wrapper\">"); t.b("\n" + i); t.b(t.rp("<fileIcon0", c, p, " ")); t.b(" <a href=\"#"); t.b(t.v(t.f("fileHtmlId", c, p, 0))); t.b("\" class=\"d2h-file-name\">"); t.b(t.v(t.f("fileName", c, p, 0))); t.b("</a>"); t.b("\n" + i); t.b(" <span class=\"d2h-file-stats\">"); t.b("\n" + i); t.b(" <span class=\"d2h-lines-added\">"); t.b(t.v(t.f("addedLines", c, p, 0))); t.b("</span>"); t.b("\n" + i); t.b(" <span class=\"d2h-lines-deleted\">"); t.b(t.v(t.f("deletedLines", c, p, 0))); t.b("</span>"); t.b("\n" + i); t.b(" </span>"); t.b("\n" + i); t.b(" </span>"); t.b("\n" + i); t.b("</li>"); return t.fl(); }, partials: { "<fileIcon0": { name: "fileIcon", partials: {}, subs: {} } }, subs: {} }); |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.html = exports.parse = exports.defaultDiff2HtmlConfig = void 0; | ||
var DiffParser = __importStar(require("./diff-parser")); | ||
var fileListPrinter = __importStar(require("./file-list-renderer")); | ||
var line_by_line_renderer_1 = __importStar(require("./line-by-line-renderer")); | ||
var side_by_side_renderer_1 = __importStar(require("./side-by-side-renderer")); | ||
var types_1 = require("./types"); | ||
var hoganjs_utils_1 = __importDefault(require("./hoganjs-utils")); | ||
exports.defaultDiff2HtmlConfig = __assign(__assign(__assign({}, line_by_line_renderer_1.defaultLineByLineRendererConfig), side_by_side_renderer_1.defaultSideBySideRendererConfig), { outputFormat: types_1.OutputFormatType.LINE_BY_LINE, drawFileList: true }); | ||
function parse(diffInput, configuration) { | ||
if (configuration === void 0) { configuration = {}; } | ||
return DiffParser.parse(diffInput, __assign(__assign({}, exports.defaultDiff2HtmlConfig), configuration)); | ||
const tslib_1 = require("tslib"); | ||
const DiffParser = tslib_1.__importStar(require("./diff-parser")); | ||
const fileListPrinter = tslib_1.__importStar(require("./file-list-renderer")); | ||
const line_by_line_renderer_1 = tslib_1.__importStar(require("./line-by-line-renderer")); | ||
const side_by_side_renderer_1 = tslib_1.__importStar(require("./side-by-side-renderer")); | ||
const types_1 = require("./types"); | ||
const hoganjs_utils_1 = tslib_1.__importDefault(require("./hoganjs-utils")); | ||
exports.defaultDiff2HtmlConfig = Object.assign(Object.assign(Object.assign({}, line_by_line_renderer_1.defaultLineByLineRendererConfig), side_by_side_renderer_1.defaultSideBySideRendererConfig), { outputFormat: types_1.OutputFormatType.LINE_BY_LINE, drawFileList: true }); | ||
function parse(diffInput, configuration = {}) { | ||
return DiffParser.parse(diffInput, Object.assign(Object.assign({}, exports.defaultDiff2HtmlConfig), configuration)); | ||
} | ||
exports.parse = parse; | ||
function html(diffInput, configuration) { | ||
if (configuration === void 0) { configuration = {}; } | ||
var config = __assign(__assign({}, exports.defaultDiff2HtmlConfig), configuration); | ||
var diffJson = typeof diffInput === 'string' ? DiffParser.parse(diffInput, config) : diffInput; | ||
var hoganUtils = new hoganjs_utils_1.default(config); | ||
var fileList = config.drawFileList ? fileListPrinter.render(diffJson, hoganUtils) : ''; | ||
var diffOutput = config.outputFormat === 'side-by-side' | ||
function html(diffInput, configuration = {}) { | ||
const config = Object.assign(Object.assign({}, exports.defaultDiff2HtmlConfig), configuration); | ||
const diffJson = typeof diffInput === 'string' ? DiffParser.parse(diffInput, config) : diffInput; | ||
const hoganUtils = new hoganjs_utils_1.default(config); | ||
const fileList = config.drawFileList ? fileListPrinter.render(diffJson, hoganUtils) : ''; | ||
const diffOutput = config.outputFormat === 'side-by-side' | ||
? new side_by_side_renderer_1.default(hoganUtils, config).render(diffJson) | ||
@@ -61,0 +23,0 @@ : new line_by_line_renderer_1.default(hoganUtils, config).render(diffJson); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.render = void 0; | ||
var renderUtils = __importStar(require("./render-utils")); | ||
var baseTemplatesPath = 'file-summary'; | ||
var iconsBaseTemplatesPath = 'icon'; | ||
const tslib_1 = require("tslib"); | ||
const renderUtils = tslib_1.__importStar(require("./render-utils")); | ||
const baseTemplatesPath = 'file-summary'; | ||
const iconsBaseTemplatesPath = 'icon'; | ||
function render(diffFiles, hoganUtils) { | ||
var files = diffFiles | ||
.map(function (file) { | ||
return hoganUtils.render(baseTemplatesPath, 'line', { | ||
fileHtmlId: renderUtils.getHtmlId(file), | ||
oldName: file.oldName, | ||
newName: file.newName, | ||
fileName: renderUtils.filenameDiff(file), | ||
deletedLines: '-' + file.deletedLines, | ||
addedLines: '+' + file.addedLines, | ||
}, { | ||
fileIcon: hoganUtils.template(iconsBaseTemplatesPath, renderUtils.getFileIcon(file)), | ||
}); | ||
}) | ||
const files = diffFiles | ||
.map(file => hoganUtils.render(baseTemplatesPath, 'line', { | ||
fileHtmlId: renderUtils.getHtmlId(file), | ||
oldName: file.oldName, | ||
newName: file.newName, | ||
fileName: renderUtils.filenameDiff(file), | ||
deletedLines: '-' + file.deletedLines, | ||
addedLines: '+' + file.addedLines, | ||
}, { | ||
fileIcon: hoganUtils.template(iconsBaseTemplatesPath, renderUtils.getFileIcon(file)), | ||
})) | ||
.join('\n'); | ||
@@ -45,0 +21,0 @@ return hoganUtils.render(baseTemplatesPath, 'wrapper', { |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Hogan = __importStar(require("hogan.js")); | ||
var diff2html_templates_1 = require("./diff2html-templates"); | ||
var HoganJsUtils = (function () { | ||
function HoganJsUtils(_a) { | ||
var _b = _a.compiledTemplates, compiledTemplates = _b === void 0 ? {} : _b, _c = _a.rawTemplates, rawTemplates = _c === void 0 ? {} : _c; | ||
var compiledRawTemplates = Object.entries(rawTemplates).reduce(function (previousTemplates, _a) { | ||
var _b; | ||
var name = _a[0], templateString = _a[1]; | ||
var compiledTemplate = Hogan.compile(templateString, { asString: false }); | ||
return __assign(__assign({}, previousTemplates), (_b = {}, _b[name] = compiledTemplate, _b)); | ||
const tslib_1 = require("tslib"); | ||
const Hogan = tslib_1.__importStar(require("hogan.js")); | ||
const diff2html_templates_1 = require("./diff2html-templates"); | ||
class HoganJsUtils { | ||
constructor({ compiledTemplates = {}, rawTemplates = {} }) { | ||
const compiledRawTemplates = Object.entries(rawTemplates).reduce((previousTemplates, [name, templateString]) => { | ||
const compiledTemplate = Hogan.compile(templateString, { asString: false }); | ||
return Object.assign(Object.assign({}, previousTemplates), { [name]: compiledTemplate }); | ||
}, {}); | ||
this.preCompiledTemplates = __assign(__assign(__assign({}, diff2html_templates_1.defaultTemplates), compiledTemplates), compiledRawTemplates); | ||
this.preCompiledTemplates = Object.assign(Object.assign(Object.assign({}, diff2html_templates_1.defaultTemplates), compiledTemplates), compiledRawTemplates); | ||
} | ||
HoganJsUtils.compile = function (templateString) { | ||
static compile(templateString) { | ||
return Hogan.compile(templateString, { asString: false }); | ||
}; | ||
HoganJsUtils.prototype.render = function (namespace, view, params, partials, indent) { | ||
var templateKey = this.templateKey(namespace, view); | ||
} | ||
render(namespace, view, params, partials, indent) { | ||
const templateKey = this.templateKey(namespace, view); | ||
try { | ||
var template = this.preCompiledTemplates[templateKey]; | ||
const template = this.preCompiledTemplates[templateKey]; | ||
return template.render(params, partials, indent); | ||
} | ||
catch (e) { | ||
throw new Error("Could not find template to render '".concat(templateKey, "'")); | ||
throw new Error(`Could not find template to render '${templateKey}'`); | ||
} | ||
}; | ||
HoganJsUtils.prototype.template = function (namespace, view) { | ||
} | ||
template(namespace, view) { | ||
return this.preCompiledTemplates[this.templateKey(namespace, view)]; | ||
}; | ||
HoganJsUtils.prototype.templateKey = function (namespace, view) { | ||
return "".concat(namespace, "-").concat(view); | ||
}; | ||
return HoganJsUtils; | ||
}()); | ||
} | ||
templateKey(namespace, view) { | ||
return `${namespace}-${view}`; | ||
} | ||
} | ||
exports.default = HoganJsUtils; | ||
//# sourceMappingURL=hoganjs-utils.js.map |
@@ -33,3 +33,3 @@ import HoganJsUtils from './hoganjs-utils'; | ||
} | ||
declare type DiffLineGroups = [ | ||
type DiffLineGroups = [ | ||
(DiffLineContext & DiffLineContent)[], | ||
@@ -39,3 +39,3 @@ (DiffLineDeleted & DiffLineContent)[], | ||
][]; | ||
declare type DiffPreparedLine = { | ||
type DiffPreparedLine = { | ||
type: renderUtils.CSSLineClass; | ||
@@ -47,3 +47,3 @@ prefix: string; | ||
}; | ||
declare type FileHtml = { | ||
type FileHtml = { | ||
left: string; | ||
@@ -50,0 +50,0 @@ right: string; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultLineByLineRendererConfig = void 0; | ||
var Rematch = __importStar(require("./rematch")); | ||
var renderUtils = __importStar(require("./render-utils")); | ||
var types_1 = require("./types"); | ||
exports.defaultLineByLineRendererConfig = __assign(__assign({}, renderUtils.defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 }); | ||
var genericTemplatesPath = 'generic'; | ||
var baseTemplatesPath = 'line-by-line'; | ||
var iconsBaseTemplatesPath = 'icon'; | ||
var tagsBaseTemplatesPath = 'tag'; | ||
var LineByLineRenderer = (function () { | ||
function LineByLineRenderer(hoganUtils, config) { | ||
if (config === void 0) { config = {}; } | ||
const tslib_1 = require("tslib"); | ||
const Rematch = tslib_1.__importStar(require("./rematch")); | ||
const renderUtils = tslib_1.__importStar(require("./render-utils")); | ||
const types_1 = require("./types"); | ||
exports.defaultLineByLineRendererConfig = Object.assign(Object.assign({}, renderUtils.defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 }); | ||
const genericTemplatesPath = 'generic'; | ||
const baseTemplatesPath = 'line-by-line'; | ||
const iconsBaseTemplatesPath = 'icon'; | ||
const tagsBaseTemplatesPath = 'tag'; | ||
class LineByLineRenderer { | ||
constructor(hoganUtils, config = {}) { | ||
this.hoganUtils = hoganUtils; | ||
this.config = __assign(__assign({}, exports.defaultLineByLineRendererConfig), config); | ||
this.config = Object.assign(Object.assign({}, exports.defaultLineByLineRendererConfig), config); | ||
} | ||
LineByLineRenderer.prototype.render = function (diffFiles) { | ||
var _this = this; | ||
var diffsHtml = diffFiles | ||
.map(function (file) { | ||
var diffs; | ||
render(diffFiles) { | ||
const diffsHtml = diffFiles | ||
.map(file => { | ||
let diffs; | ||
if (file.blocks.length) { | ||
diffs = _this.generateFileHtml(file); | ||
diffs = this.generateFileHtml(file); | ||
} | ||
else { | ||
diffs = _this.generateEmptyDiff(); | ||
diffs = this.generateEmptyDiff(); | ||
} | ||
return _this.makeFileDiffHtml(file, diffs); | ||
return this.makeFileDiffHtml(file, diffs); | ||
}) | ||
.join('\n'); | ||
return this.hoganUtils.render(genericTemplatesPath, 'wrapper', { content: diffsHtml }); | ||
}; | ||
LineByLineRenderer.prototype.makeFileDiffHtml = function (file, diffs) { | ||
} | ||
makeFileDiffHtml(file, diffs) { | ||
if (this.config.renderNothingWhenEmpty && Array.isArray(file.blocks) && file.blocks.length === 0) | ||
return ''; | ||
var fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, 'file-diff'); | ||
var filePathTemplate = this.hoganUtils.template(genericTemplatesPath, 'file-path'); | ||
var fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, 'file'); | ||
var fileTagTemplate = this.hoganUtils.template(tagsBaseTemplatesPath, renderUtils.getFileIcon(file)); | ||
const fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, 'file-diff'); | ||
const filePathTemplate = this.hoganUtils.template(genericTemplatesPath, 'file-path'); | ||
const fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, 'file'); | ||
const fileTagTemplate = this.hoganUtils.template(tagsBaseTemplatesPath, renderUtils.getFileIcon(file)); | ||
return fileDiffTemplate.render({ | ||
@@ -86,4 +51,4 @@ file: file, | ||
}); | ||
}; | ||
LineByLineRenderer.prototype.generateEmptyDiff = function () { | ||
} | ||
generateEmptyDiff() { | ||
return this.hoganUtils.render(genericTemplatesPath, 'empty-diff', { | ||
@@ -93,9 +58,8 @@ contentClass: 'd2h-code-line', | ||
}); | ||
}; | ||
LineByLineRenderer.prototype.generateFileHtml = function (file) { | ||
var _this = this; | ||
var matcher = Rematch.newMatcherFn(Rematch.newDistanceFn(function (e) { return renderUtils.deconstructLine(e.content, file.isCombined).content; })); | ||
} | ||
generateFileHtml(file) { | ||
const matcher = Rematch.newMatcherFn(Rematch.newDistanceFn((e) => renderUtils.deconstructLine(e.content, file.isCombined).content)); | ||
return file.blocks | ||
.map(function (block) { | ||
var lines = _this.hoganUtils.render(genericTemplatesPath, 'block-header', { | ||
.map(block => { | ||
let lines = this.hoganUtils.render(genericTemplatesPath, 'block-header', { | ||
CSSLineClass: renderUtils.CSSLineClass, | ||
@@ -106,8 +70,6 @@ blockHeader: file.isTooBig ? block.header : renderUtils.escapeForHtml(block.header), | ||
}); | ||
_this.applyLineGroupping(block).forEach(function (_a) { | ||
var contextLines = _a[0], oldLines = _a[1], newLines = _a[2]; | ||
this.applyLineGroupping(block).forEach(([contextLines, oldLines, newLines]) => { | ||
if (oldLines.length && newLines.length && !contextLines.length) { | ||
_this.applyRematchMatching(oldLines, newLines, matcher).map(function (_a) { | ||
var oldLines = _a[0], newLines = _a[1]; | ||
var _b = _this.processChangedLines(file, file.isCombined, oldLines, newLines), left = _b.left, right = _b.right; | ||
this.applyRematchMatching(oldLines, newLines, matcher).map(([oldLines, newLines]) => { | ||
const { left, right } = this.processChangedLines(file, file.isCombined, oldLines, newLines); | ||
lines += left; | ||
@@ -118,5 +80,5 @@ lines += right; | ||
else if (contextLines.length) { | ||
contextLines.forEach(function (line) { | ||
var _a = renderUtils.deconstructLine(line.content, file.isCombined), prefix = _a.prefix, content = _a.content; | ||
lines += _this.generateSingleLineHtml(file, { | ||
contextLines.forEach(line => { | ||
const { prefix, content } = renderUtils.deconstructLine(line.content, file.isCombined); | ||
lines += this.generateSingleLineHtml(file, { | ||
type: renderUtils.CSSLineClass.CONTEXT, | ||
@@ -131,3 +93,3 @@ prefix: prefix, | ||
else if (oldLines.length || newLines.length) { | ||
var _b = _this.processChangedLines(file, file.isCombined, oldLines, newLines), left = _b.left, right = _b.right; | ||
const { left, right } = this.processChangedLines(file, file.isCombined, oldLines, newLines); | ||
lines += left; | ||
@@ -143,9 +105,9 @@ lines += right; | ||
.join('\n'); | ||
}; | ||
LineByLineRenderer.prototype.applyLineGroupping = function (block) { | ||
var blockLinesGroups = []; | ||
var oldLines = []; | ||
var newLines = []; | ||
for (var i = 0; i < block.lines.length; i++) { | ||
var diffLine = block.lines[i]; | ||
} | ||
applyLineGroupping(block) { | ||
const blockLinesGroups = []; | ||
let oldLines = []; | ||
let newLines = []; | ||
for (let i = 0; i < block.lines.length; i++) { | ||
const diffLine = block.lines[i]; | ||
if ((diffLine.type !== types_1.LineType.INSERT && newLines.length) || | ||
@@ -176,25 +138,25 @@ (diffLine.type === types_1.LineType.CONTEXT && oldLines.length > 0)) { | ||
return blockLinesGroups; | ||
}; | ||
LineByLineRenderer.prototype.applyRematchMatching = function (oldLines, newLines, matcher) { | ||
var comparisons = oldLines.length * newLines.length; | ||
var maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(function (elem) { return elem.content.length; }))); | ||
var doMatching = comparisons < this.config.matchingMaxComparisons && | ||
} | ||
applyRematchMatching(oldLines, newLines, matcher) { | ||
const comparisons = oldLines.length * newLines.length; | ||
const maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(elem => elem.content.length))); | ||
const doMatching = comparisons < this.config.matchingMaxComparisons && | ||
maxLineSizeInBlock < this.config.maxLineSizeInBlockForComparison && | ||
(this.config.matching === 'lines' || this.config.matching === 'words'); | ||
return doMatching ? matcher(oldLines, newLines) : [[oldLines, newLines]]; | ||
}; | ||
LineByLineRenderer.prototype.processChangedLines = function (file, isCombined, oldLines, newLines) { | ||
var fileHtml = { | ||
} | ||
processChangedLines(file, isCombined, oldLines, newLines) { | ||
const fileHtml = { | ||
right: '', | ||
left: '', | ||
}; | ||
var maxLinesNumber = Math.max(oldLines.length, newLines.length); | ||
for (var i = 0; i < maxLinesNumber; i++) { | ||
var oldLine = oldLines[i]; | ||
var newLine = newLines[i]; | ||
var diff = oldLine !== undefined && newLine !== undefined | ||
const maxLinesNumber = Math.max(oldLines.length, newLines.length); | ||
for (let i = 0; i < maxLinesNumber; i++) { | ||
const oldLine = oldLines[i]; | ||
const newLine = newLines[i]; | ||
const diff = oldLine !== undefined && newLine !== undefined | ||
? renderUtils.diffHighlight(oldLine.content, newLine.content, isCombined, this.config) | ||
: undefined; | ||
var preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined | ||
? __assign(__assign({}, (diff !== undefined | ||
const preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined | ||
? Object.assign(Object.assign({}, (diff !== undefined | ||
? { | ||
@@ -205,5 +167,5 @@ prefix: diff.oldLine.prefix, | ||
} | ||
: __assign(__assign({}, renderUtils.deconstructLine(oldLine.content, isCombined)), { type: renderUtils.toCSSClass(oldLine.type) }))), { oldNumber: oldLine.oldNumber, newNumber: oldLine.newNumber }) : undefined; | ||
var preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined | ||
? __assign(__assign({}, (diff !== undefined | ||
: Object.assign(Object.assign({}, renderUtils.deconstructLine(oldLine.content, isCombined)), { type: renderUtils.toCSSClass(oldLine.type) }))), { oldNumber: oldLine.oldNumber, newNumber: oldLine.newNumber }) : undefined; | ||
const preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined | ||
? Object.assign(Object.assign({}, (diff !== undefined | ||
? { | ||
@@ -214,4 +176,4 @@ prefix: diff.newLine.prefix, | ||
} | ||
: __assign(__assign({}, renderUtils.deconstructLine(newLine.content, isCombined)), { type: renderUtils.toCSSClass(newLine.type) }))), { oldNumber: newLine.oldNumber, newNumber: newLine.newNumber }) : undefined; | ||
var _a = this.generateLineHtml(file, preparedOldLine, preparedNewLine), left = _a.left, right = _a.right; | ||
: Object.assign(Object.assign({}, renderUtils.deconstructLine(newLine.content, isCombined)), { type: renderUtils.toCSSClass(newLine.type) }))), { oldNumber: newLine.oldNumber, newNumber: newLine.newNumber }) : undefined; | ||
const { left, right } = this.generateLineHtml(file, preparedOldLine, preparedNewLine); | ||
fileHtml.left += left; | ||
@@ -221,4 +183,4 @@ fileHtml.right += right; | ||
return fileHtml; | ||
}; | ||
LineByLineRenderer.prototype.generateLineHtml = function (file, oldLine, newLine) { | ||
} | ||
generateLineHtml(file, oldLine, newLine) { | ||
return { | ||
@@ -228,7 +190,7 @@ left: this.generateSingleLineHtml(file, oldLine), | ||
}; | ||
}; | ||
LineByLineRenderer.prototype.generateSingleLineHtml = function (file, line) { | ||
} | ||
generateSingleLineHtml(file, line) { | ||
if (line === undefined) | ||
return ''; | ||
var lineNumberHtml = this.hoganUtils.render(baseTemplatesPath, 'numbers', { | ||
const lineNumberHtml = this.hoganUtils.render(baseTemplatesPath, 'numbers', { | ||
oldNumber: line.oldNumber || '', | ||
@@ -244,9 +206,8 @@ newNumber: line.newNumber || '', | ||
lineNumber: lineNumberHtml, | ||
line: line, | ||
file: file, | ||
line, | ||
file, | ||
}); | ||
}; | ||
return LineByLineRenderer; | ||
}()); | ||
} | ||
} | ||
exports.default = LineByLineRenderer; | ||
//# sourceMappingURL=line-by-line-renderer.js.map |
@@ -1,2 +0,2 @@ | ||
export declare type BestMatch = { | ||
export type BestMatch = { | ||
indexA: number; | ||
@@ -7,6 +7,6 @@ indexB: number; | ||
export declare function levenshtein(a: string, b: string): number; | ||
export declare type DistanceFn<T> = (x: T, y: T) => number; | ||
export type DistanceFn<T> = (x: T, y: T) => number; | ||
export declare function newDistanceFn<T>(str: (value: T) => string): DistanceFn<T>; | ||
export declare type MatcherFn<T> = (a: T[], b: T[], level?: number, cache?: Map<string, number>) => T[][][]; | ||
export type MatcherFn<T> = (a: T[], b: T[], level?: number, cache?: Map<string, number>) => T[][][]; | ||
export declare function newMatcherFn<T>(distance: (x: T, y: T) => number): MatcherFn<T>; | ||
//# sourceMappingURL=rematch.d.ts.map |
@@ -11,8 +11,8 @@ "use strict"; | ||
} | ||
var matrix = []; | ||
var i; | ||
const matrix = []; | ||
let i; | ||
for (i = 0; i <= b.length; i++) { | ||
matrix[i] = [i]; | ||
} | ||
var j; | ||
let j; | ||
for (j = 0; j <= a.length; j++) { | ||
@@ -35,6 +35,6 @@ matrix[0][j] = j; | ||
function newDistanceFn(str) { | ||
return function (x, y) { | ||
var xValue = str(x).trim(); | ||
var yValue = str(y).trim(); | ||
var lev = levenshtein(xValue, yValue); | ||
return (x, y) => { | ||
const xValue = str(x).trim(); | ||
const yValue = str(y).trim(); | ||
const lev = levenshtein(xValue, yValue); | ||
return lev / (xValue.length + yValue.length); | ||
@@ -45,10 +45,9 @@ }; | ||
function newMatcherFn(distance) { | ||
function findBestMatch(a, b, cache) { | ||
if (cache === void 0) { cache = new Map(); } | ||
var bestMatchDist = Infinity; | ||
var bestMatch; | ||
for (var i = 0; i < a.length; ++i) { | ||
for (var j = 0; j < b.length; ++j) { | ||
var cacheKey = JSON.stringify([a[i], b[j]]); | ||
var md = void 0; | ||
function findBestMatch(a, b, cache = new Map()) { | ||
let bestMatchDist = Infinity; | ||
let bestMatch; | ||
for (let i = 0; i < a.length; ++i) { | ||
for (let j = 0; j < b.length; ++j) { | ||
const cacheKey = JSON.stringify([a[i], b[j]]); | ||
let md; | ||
if (!(cache.has(cacheKey) && (md = cache.get(cacheKey)))) { | ||
@@ -66,21 +65,19 @@ md = distance(a[i], b[j]); | ||
} | ||
function group(a, b, level, cache) { | ||
if (level === void 0) { level = 0; } | ||
if (cache === void 0) { cache = new Map(); } | ||
var bm = findBestMatch(a, b, cache); | ||
function group(a, b, level = 0, cache = new Map()) { | ||
const bm = findBestMatch(a, b, cache); | ||
if (!bm || a.length + b.length < 3) { | ||
return [[a, b]]; | ||
} | ||
var a1 = a.slice(0, bm.indexA); | ||
var b1 = b.slice(0, bm.indexB); | ||
var aMatch = [a[bm.indexA]]; | ||
var bMatch = [b[bm.indexB]]; | ||
var tailA = bm.indexA + 1; | ||
var tailB = bm.indexB + 1; | ||
var a2 = a.slice(tailA); | ||
var b2 = b.slice(tailB); | ||
var group1 = group(a1, b1, level + 1, cache); | ||
var groupMatch = group(aMatch, bMatch, level + 1, cache); | ||
var group2 = group(a2, b2, level + 1, cache); | ||
var result = groupMatch; | ||
const a1 = a.slice(0, bm.indexA); | ||
const b1 = b.slice(0, bm.indexB); | ||
const aMatch = [a[bm.indexA]]; | ||
const bMatch = [b[bm.indexB]]; | ||
const tailA = bm.indexA + 1; | ||
const tailB = bm.indexB + 1; | ||
const a2 = a.slice(tailA); | ||
const b2 = b.slice(tailB); | ||
const group1 = group(a1, b1, level + 1, cache); | ||
const groupMatch = group(aMatch, bMatch, level + 1, cache); | ||
const group2 = group(a2, b2, level + 1, cache); | ||
let result = groupMatch; | ||
if (bm.indexA > 0 || bm.indexB > 0) { | ||
@@ -87,0 +84,0 @@ result = group1.concat(result); |
import { LineMatchingType, DiffStyleType, LineType, DiffLineParts, DiffFile, DiffFileName } from './types'; | ||
export declare type CSSLineClass = 'd2h-ins' | 'd2h-del' | 'd2h-cntx' | 'd2h-info' | 'd2h-ins d2h-change' | 'd2h-del d2h-change'; | ||
export type CSSLineClass = 'd2h-ins' | 'd2h-del' | 'd2h-cntx' | 'd2h-info' | 'd2h-ins d2h-change' | 'd2h-del d2h-change'; | ||
export declare const CSSLineClass: { | ||
[_: string]: CSSLineClass; | ||
}; | ||
export declare type HighlightedLines = { | ||
export type HighlightedLines = { | ||
oldLine: { | ||
@@ -8,0 +8,0 @@ prefix: string; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.diffHighlight = exports.getFileIcon = exports.getHtmlId = exports.filenameDiff = exports.deconstructLine = exports.escapeForHtml = exports.toCSSClass = exports.defaultRenderConfig = exports.CSSLineClass = void 0; | ||
var jsDiff = __importStar(require("diff")); | ||
var utils_1 = require("./utils"); | ||
var rematch = __importStar(require("./rematch")); | ||
var types_1 = require("./types"); | ||
const tslib_1 = require("tslib"); | ||
const jsDiff = tslib_1.__importStar(require("diff")); | ||
const utils_1 = require("./utils"); | ||
const rematch = tslib_1.__importStar(require("./rematch")); | ||
const types_1 = require("./types"); | ||
exports.CSSLineClass = { | ||
@@ -56,5 +23,5 @@ INSERTS: 'd2h-ins', | ||
}; | ||
var separator = '/'; | ||
var distance = rematch.newDistanceFn(function (change) { return change.value; }); | ||
var matcher = rematch.newMatcherFn(distance); | ||
const separator = '/'; | ||
const distance = rematch.newDistanceFn((change) => change.value); | ||
const matcher = rematch.newMatcherFn(distance); | ||
function isDevNullName(name) { | ||
@@ -94,5 +61,4 @@ return name.indexOf('dev/null') !== -1; | ||
exports.escapeForHtml = escapeForHtml; | ||
function deconstructLine(line, isCombined, escape) { | ||
if (escape === void 0) { escape = true; } | ||
var indexToSplit = prefixLength(isCombined); | ||
function deconstructLine(line, isCombined, escape = true) { | ||
const indexToSplit = prefixLength(isCombined); | ||
return { | ||
@@ -105,14 +71,14 @@ prefix: line.substring(0, indexToSplit), | ||
function filenameDiff(file) { | ||
var oldFilename = (0, utils_1.unifyPath)(file.oldName); | ||
var newFilename = (0, utils_1.unifyPath)(file.newName); | ||
const oldFilename = (0, utils_1.unifyPath)(file.oldName); | ||
const newFilename = (0, utils_1.unifyPath)(file.newName); | ||
if (oldFilename !== newFilename && !isDevNullName(oldFilename) && !isDevNullName(newFilename)) { | ||
var prefixPaths = []; | ||
var suffixPaths = []; | ||
var oldFilenameParts = oldFilename.split(separator); | ||
var newFilenameParts = newFilename.split(separator); | ||
var oldFilenamePartsSize = oldFilenameParts.length; | ||
var newFilenamePartsSize = newFilenameParts.length; | ||
var i = 0; | ||
var j = oldFilenamePartsSize - 1; | ||
var k = newFilenamePartsSize - 1; | ||
const prefixPaths = []; | ||
const suffixPaths = []; | ||
const oldFilenameParts = oldFilename.split(separator); | ||
const newFilenameParts = newFilename.split(separator); | ||
const oldFilenamePartsSize = oldFilenameParts.length; | ||
const newFilenamePartsSize = newFilenameParts.length; | ||
let i = 0; | ||
let j = oldFilenamePartsSize - 1; | ||
let k = newFilenamePartsSize - 1; | ||
while (i < j && i < k) { | ||
@@ -137,6 +103,6 @@ if (oldFilenameParts[i] === newFilenameParts[i]) { | ||
} | ||
var finalPrefix = prefixPaths.join(separator); | ||
var finalSuffix = suffixPaths.join(separator); | ||
var oldRemainingPath = oldFilenameParts.slice(i, j + 1).join(separator); | ||
var newRemainingPath = newFilenameParts.slice(i, k + 1).join(separator); | ||
const finalPrefix = prefixPaths.join(separator); | ||
const finalSuffix = suffixPaths.join(separator); | ||
const oldRemainingPath = oldFilenameParts.slice(i, j + 1).join(separator); | ||
const newRemainingPath = newFilenameParts.slice(i, k + 1).join(separator); | ||
if (finalPrefix.length && finalSuffix.length) { | ||
@@ -162,7 +128,7 @@ return (finalPrefix + separator + '{' + oldRemainingPath + ' โ ' + newRemainingPath + '}' + separator + finalSuffix); | ||
function getHtmlId(file) { | ||
return "d2h-".concat((0, utils_1.hashCode)(filenameDiff(file)).toString().slice(-6)); | ||
return `d2h-${(0, utils_1.hashCode)(filenameDiff(file)).toString().slice(-6)}`; | ||
} | ||
exports.getHtmlId = getHtmlId; | ||
function getFileIcon(file) { | ||
var templateName = 'file-changed'; | ||
let templateName = 'file-changed'; | ||
if (file.isRename) { | ||
@@ -186,7 +152,6 @@ templateName = 'file-renamed'; | ||
exports.getFileIcon = getFileIcon; | ||
function diffHighlight(diffLine1, diffLine2, isCombined, config) { | ||
if (config === void 0) { config = {}; } | ||
var _a = __assign(__assign({}, exports.defaultRenderConfig), config), matching = _a.matching, maxLineLengthHighlight = _a.maxLineLengthHighlight, matchWordsThreshold = _a.matchWordsThreshold, diffStyle = _a.diffStyle; | ||
var line1 = deconstructLine(diffLine1, isCombined, false); | ||
var line2 = deconstructLine(diffLine2, isCombined, false); | ||
function diffHighlight(diffLine1, diffLine2, isCombined, config = {}) { | ||
const { matching, maxLineLengthHighlight, matchWordsThreshold, diffStyle } = Object.assign(Object.assign({}, exports.defaultRenderConfig), config); | ||
const line1 = deconstructLine(diffLine1, isCombined, false); | ||
const line2 = deconstructLine(diffLine2, isCombined, false); | ||
if (line1.content.length > maxLineLengthHighlight || line2.content.length > maxLineLengthHighlight) { | ||
@@ -204,13 +169,13 @@ return { | ||
} | ||
var diff = diffStyle === 'char' | ||
const diff = diffStyle === 'char' | ||
? jsDiff.diffChars(line1.content, line2.content) | ||
: jsDiff.diffWordsWithSpace(line1.content, line2.content); | ||
var changedWords = []; | ||
const changedWords = []; | ||
if (diffStyle === 'word' && matching === 'words') { | ||
var removed = diff.filter(function (element) { return element.removed; }); | ||
var added = diff.filter(function (element) { return element.added; }); | ||
var chunks = matcher(added, removed); | ||
chunks.forEach(function (chunk) { | ||
const removed = diff.filter(element => element.removed); | ||
const added = diff.filter(element => element.added); | ||
const chunks = matcher(added, removed); | ||
chunks.forEach(chunk => { | ||
if (chunk[0].length === 1 && chunk[1].length === 1) { | ||
var dist = distance(chunk[0][0], chunk[1][0]); | ||
const dist = distance(chunk[0][0], chunk[1][0]); | ||
if (dist < matchWordsThreshold) { | ||
@@ -223,9 +188,9 @@ changedWords.push(chunk[0][0]); | ||
} | ||
var highlightedLine = diff.reduce(function (highlightedLine, part) { | ||
var elemType = part.added ? 'ins' : part.removed ? 'del' : null; | ||
var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : ''; | ||
var escapedValue = escapeForHtml(part.value); | ||
const highlightedLine = diff.reduce((highlightedLine, part) => { | ||
const elemType = part.added ? 'ins' : part.removed ? 'del' : null; | ||
const addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : ''; | ||
const escapedValue = escapeForHtml(part.value); | ||
return elemType !== null | ||
? "".concat(highlightedLine, "<").concat(elemType).concat(addClass, ">").concat(escapedValue, "</").concat(elemType, ">") | ||
: "".concat(highlightedLine).concat(escapedValue); | ||
? `${highlightedLine}<${elemType}${addClass}>${escapedValue}</${elemType}>` | ||
: `${highlightedLine}${escapedValue}`; | ||
}, ''); | ||
@@ -232,0 +197,0 @@ return { |
@@ -34,3 +34,3 @@ import HoganJsUtils from './hoganjs-utils'; | ||
} | ||
declare type DiffLineGroups = [ | ||
type DiffLineGroups = [ | ||
(DiffLineContext & DiffLineContent)[], | ||
@@ -40,3 +40,3 @@ (DiffLineDeleted & DiffLineContent)[], | ||
][]; | ||
declare type DiffPreparedLine = { | ||
type DiffPreparedLine = { | ||
type: renderUtils.CSSLineClass; | ||
@@ -47,3 +47,3 @@ prefix: string; | ||
}; | ||
declare type FileHtml = { | ||
type FileHtml = { | ||
left: string; | ||
@@ -50,0 +50,0 @@ right: string; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultSideBySideRendererConfig = void 0; | ||
var Rematch = __importStar(require("./rematch")); | ||
var renderUtils = __importStar(require("./render-utils")); | ||
var types_1 = require("./types"); | ||
exports.defaultSideBySideRendererConfig = __assign(__assign({}, renderUtils.defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 }); | ||
var genericTemplatesPath = 'generic'; | ||
var baseTemplatesPath = 'side-by-side'; | ||
var iconsBaseTemplatesPath = 'icon'; | ||
var tagsBaseTemplatesPath = 'tag'; | ||
var SideBySideRenderer = (function () { | ||
function SideBySideRenderer(hoganUtils, config) { | ||
if (config === void 0) { config = {}; } | ||
const tslib_1 = require("tslib"); | ||
const Rematch = tslib_1.__importStar(require("./rematch")); | ||
const renderUtils = tslib_1.__importStar(require("./render-utils")); | ||
const types_1 = require("./types"); | ||
exports.defaultSideBySideRendererConfig = Object.assign(Object.assign({}, renderUtils.defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 }); | ||
const genericTemplatesPath = 'generic'; | ||
const baseTemplatesPath = 'side-by-side'; | ||
const iconsBaseTemplatesPath = 'icon'; | ||
const tagsBaseTemplatesPath = 'tag'; | ||
class SideBySideRenderer { | ||
constructor(hoganUtils, config = {}) { | ||
this.hoganUtils = hoganUtils; | ||
this.config = __assign(__assign({}, exports.defaultSideBySideRendererConfig), config); | ||
this.config = Object.assign(Object.assign({}, exports.defaultSideBySideRendererConfig), config); | ||
} | ||
SideBySideRenderer.prototype.render = function (diffFiles) { | ||
var _this = this; | ||
var diffsHtml = diffFiles | ||
.map(function (file) { | ||
var diffs; | ||
render(diffFiles) { | ||
const diffsHtml = diffFiles | ||
.map(file => { | ||
let diffs; | ||
if (file.blocks.length) { | ||
diffs = _this.generateFileHtml(file); | ||
diffs = this.generateFileHtml(file); | ||
} | ||
else { | ||
diffs = _this.generateEmptyDiff(); | ||
diffs = this.generateEmptyDiff(); | ||
} | ||
return _this.makeFileDiffHtml(file, diffs); | ||
return this.makeFileDiffHtml(file, diffs); | ||
}) | ||
.join('\n'); | ||
return this.hoganUtils.render(genericTemplatesPath, 'wrapper', { content: diffsHtml }); | ||
}; | ||
SideBySideRenderer.prototype.makeFileDiffHtml = function (file, diffs) { | ||
} | ||
makeFileDiffHtml(file, diffs) { | ||
if (this.config.renderNothingWhenEmpty && Array.isArray(file.blocks) && file.blocks.length === 0) | ||
return ''; | ||
var fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, 'file-diff'); | ||
var filePathTemplate = this.hoganUtils.template(genericTemplatesPath, 'file-path'); | ||
var fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, 'file'); | ||
var fileTagTemplate = this.hoganUtils.template(tagsBaseTemplatesPath, renderUtils.getFileIcon(file)); | ||
const fileDiffTemplate = this.hoganUtils.template(baseTemplatesPath, 'file-diff'); | ||
const filePathTemplate = this.hoganUtils.template(genericTemplatesPath, 'file-path'); | ||
const fileIconTemplate = this.hoganUtils.template(iconsBaseTemplatesPath, 'file'); | ||
const fileTagTemplate = this.hoganUtils.template(tagsBaseTemplatesPath, renderUtils.getFileIcon(file)); | ||
return fileDiffTemplate.render({ | ||
@@ -86,4 +51,4 @@ file: file, | ||
}); | ||
}; | ||
SideBySideRenderer.prototype.generateEmptyDiff = function () { | ||
} | ||
generateEmptyDiff() { | ||
return { | ||
@@ -96,18 +61,15 @@ right: '', | ||
}; | ||
}; | ||
SideBySideRenderer.prototype.generateFileHtml = function (file) { | ||
var _this = this; | ||
var matcher = Rematch.newMatcherFn(Rematch.newDistanceFn(function (e) { return renderUtils.deconstructLine(e.content, file.isCombined).content; })); | ||
} | ||
generateFileHtml(file) { | ||
const matcher = Rematch.newMatcherFn(Rematch.newDistanceFn((e) => renderUtils.deconstructLine(e.content, file.isCombined).content)); | ||
return file.blocks | ||
.map(function (block) { | ||
var fileHtml = { | ||
left: _this.makeHeaderHtml(block.header, file), | ||
right: _this.makeHeaderHtml(''), | ||
.map(block => { | ||
const fileHtml = { | ||
left: this.makeHeaderHtml(block.header, file), | ||
right: this.makeHeaderHtml(''), | ||
}; | ||
_this.applyLineGroupping(block).forEach(function (_a) { | ||
var contextLines = _a[0], oldLines = _a[1], newLines = _a[2]; | ||
this.applyLineGroupping(block).forEach(([contextLines, oldLines, newLines]) => { | ||
if (oldLines.length && newLines.length && !contextLines.length) { | ||
_this.applyRematchMatching(oldLines, newLines, matcher).map(function (_a) { | ||
var oldLines = _a[0], newLines = _a[1]; | ||
var _b = _this.processChangedLines(file.isCombined, oldLines, newLines), left = _b.left, right = _b.right; | ||
this.applyRematchMatching(oldLines, newLines, matcher).map(([oldLines, newLines]) => { | ||
const { left, right } = this.processChangedLines(file.isCombined, oldLines, newLines); | ||
fileHtml.left += left; | ||
@@ -118,5 +80,5 @@ fileHtml.right += right; | ||
else if (contextLines.length) { | ||
contextLines.forEach(function (line) { | ||
var _a = renderUtils.deconstructLine(line.content, file.isCombined), prefix = _a.prefix, content = _a.content; | ||
var _b = _this.generateLineHtml({ | ||
contextLines.forEach(line => { | ||
const { prefix, content } = renderUtils.deconstructLine(line.content, file.isCombined); | ||
const { left, right } = this.generateLineHtml({ | ||
type: renderUtils.CSSLineClass.CONTEXT, | ||
@@ -131,3 +93,3 @@ prefix: prefix, | ||
number: line.newNumber, | ||
}), left = _b.left, right = _b.right; | ||
}); | ||
fileHtml.left += left; | ||
@@ -138,3 +100,3 @@ fileHtml.right += right; | ||
else if (oldLines.length || newLines.length) { | ||
var _b = _this.processChangedLines(file.isCombined, oldLines, newLines), left = _b.left, right = _b.right; | ||
const { left, right } = this.processChangedLines(file.isCombined, oldLines, newLines); | ||
fileHtml.left += left; | ||
@@ -149,12 +111,12 @@ fileHtml.right += right; | ||
}) | ||
.reduce(function (accomulated, html) { | ||
.reduce((accomulated, html) => { | ||
return { left: accomulated.left + html.left, right: accomulated.right + html.right }; | ||
}, { left: '', right: '' }); | ||
}; | ||
SideBySideRenderer.prototype.applyLineGroupping = function (block) { | ||
var blockLinesGroups = []; | ||
var oldLines = []; | ||
var newLines = []; | ||
for (var i = 0; i < block.lines.length; i++) { | ||
var diffLine = block.lines[i]; | ||
} | ||
applyLineGroupping(block) { | ||
const blockLinesGroups = []; | ||
let oldLines = []; | ||
let newLines = []; | ||
for (let i = 0; i < block.lines.length; i++) { | ||
const diffLine = block.lines[i]; | ||
if ((diffLine.type !== types_1.LineType.INSERT && newLines.length) || | ||
@@ -185,12 +147,12 @@ (diffLine.type === types_1.LineType.CONTEXT && oldLines.length > 0)) { | ||
return blockLinesGroups; | ||
}; | ||
SideBySideRenderer.prototype.applyRematchMatching = function (oldLines, newLines, matcher) { | ||
var comparisons = oldLines.length * newLines.length; | ||
var maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(function (elem) { return elem.content.length; }))); | ||
var doMatching = comparisons < this.config.matchingMaxComparisons && | ||
} | ||
applyRematchMatching(oldLines, newLines, matcher) { | ||
const comparisons = oldLines.length * newLines.length; | ||
const maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(elem => elem.content.length))); | ||
const doMatching = comparisons < this.config.matchingMaxComparisons && | ||
maxLineSizeInBlock < this.config.maxLineSizeInBlockForComparison && | ||
(this.config.matching === 'lines' || this.config.matching === 'words'); | ||
return doMatching ? matcher(oldLines, newLines) : [[oldLines, newLines]]; | ||
}; | ||
SideBySideRenderer.prototype.makeHeaderHtml = function (blockHeader, file) { | ||
} | ||
makeHeaderHtml(blockHeader, file) { | ||
return this.hoganUtils.render(genericTemplatesPath, 'block-header', { | ||
@@ -202,17 +164,17 @@ CSSLineClass: renderUtils.CSSLineClass, | ||
}); | ||
}; | ||
SideBySideRenderer.prototype.processChangedLines = function (isCombined, oldLines, newLines) { | ||
var fileHtml = { | ||
} | ||
processChangedLines(isCombined, oldLines, newLines) { | ||
const fileHtml = { | ||
right: '', | ||
left: '', | ||
}; | ||
var maxLinesNumber = Math.max(oldLines.length, newLines.length); | ||
for (var i = 0; i < maxLinesNumber; i++) { | ||
var oldLine = oldLines[i]; | ||
var newLine = newLines[i]; | ||
var diff = oldLine !== undefined && newLine !== undefined | ||
const maxLinesNumber = Math.max(oldLines.length, newLines.length); | ||
for (let i = 0; i < maxLinesNumber; i++) { | ||
const oldLine = oldLines[i]; | ||
const newLine = newLines[i]; | ||
const diff = oldLine !== undefined && newLine !== undefined | ||
? renderUtils.diffHighlight(oldLine.content, newLine.content, isCombined, this.config) | ||
: undefined; | ||
var preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined | ||
? __assign(__assign({}, (diff !== undefined | ||
const preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined | ||
? Object.assign(Object.assign({}, (diff !== undefined | ||
? { | ||
@@ -223,5 +185,5 @@ prefix: diff.oldLine.prefix, | ||
} | ||
: __assign(__assign({}, renderUtils.deconstructLine(oldLine.content, isCombined)), { type: renderUtils.toCSSClass(oldLine.type) }))), { number: oldLine.oldNumber }) : undefined; | ||
var preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined | ||
? __assign(__assign({}, (diff !== undefined | ||
: Object.assign(Object.assign({}, renderUtils.deconstructLine(oldLine.content, isCombined)), { type: renderUtils.toCSSClass(oldLine.type) }))), { number: oldLine.oldNumber }) : undefined; | ||
const preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined | ||
? Object.assign(Object.assign({}, (diff !== undefined | ||
? { | ||
@@ -232,4 +194,4 @@ prefix: diff.newLine.prefix, | ||
} | ||
: __assign(__assign({}, renderUtils.deconstructLine(newLine.content, isCombined)), { type: renderUtils.toCSSClass(newLine.type) }))), { number: newLine.newNumber }) : undefined; | ||
var _a = this.generateLineHtml(preparedOldLine, preparedNewLine), left = _a.left, right = _a.right; | ||
: Object.assign(Object.assign({}, renderUtils.deconstructLine(newLine.content, isCombined)), { type: renderUtils.toCSSClass(newLine.type) }))), { number: newLine.newNumber }) : undefined; | ||
const { left, right } = this.generateLineHtml(preparedOldLine, preparedNewLine); | ||
fileHtml.left += left; | ||
@@ -239,4 +201,4 @@ fileHtml.right += right; | ||
return fileHtml; | ||
}; | ||
SideBySideRenderer.prototype.generateLineHtml = function (oldLine, newLine) { | ||
} | ||
generateLineHtml(oldLine, newLine) { | ||
return { | ||
@@ -246,10 +208,10 @@ left: this.generateSingleHtml(oldLine), | ||
}; | ||
}; | ||
SideBySideRenderer.prototype.generateSingleHtml = function (line) { | ||
var lineClass = 'd2h-code-side-linenumber'; | ||
var contentClass = 'd2h-code-side-line'; | ||
} | ||
generateSingleHtml(line) { | ||
const lineClass = 'd2h-code-side-linenumber'; | ||
const contentClass = 'd2h-code-side-line'; | ||
return this.hoganUtils.render(genericTemplatesPath, 'line', { | ||
type: (line === null || line === void 0 ? void 0 : line.type) || "".concat(renderUtils.CSSLineClass.CONTEXT, " d2h-emptyplaceholder"), | ||
lineClass: line !== undefined ? lineClass : "".concat(lineClass, " d2h-code-side-emptyplaceholder"), | ||
contentClass: line !== undefined ? contentClass : "".concat(contentClass, " d2h-code-side-emptyplaceholder"), | ||
type: (line === null || line === void 0 ? void 0 : line.type) || `${renderUtils.CSSLineClass.CONTEXT} d2h-emptyplaceholder`, | ||
lineClass: line !== undefined ? lineClass : `${lineClass} d2h-code-side-emptyplaceholder`, | ||
contentClass: line !== undefined ? contentClass : `${contentClass} d2h-code-side-emptyplaceholder`, | ||
prefix: (line === null || line === void 0 ? void 0 : line.prefix) === ' ' ? ' ' : line === null || line === void 0 ? void 0 : line.prefix, | ||
@@ -259,6 +221,5 @@ content: line === null || line === void 0 ? void 0 : line.content, | ||
}); | ||
}; | ||
return SideBySideRenderer; | ||
}()); | ||
} | ||
} | ||
exports.default = SideBySideRenderer; | ||
//# sourceMappingURL=side-by-side-renderer.js.map |
@@ -1,2 +0,2 @@ | ||
export declare type DiffLineParts = { | ||
export type DiffLineParts = { | ||
prefix: string; | ||
@@ -25,6 +25,6 @@ content: string; | ||
} | ||
export declare type DiffLineContent = { | ||
export type DiffLineContent = { | ||
content: string; | ||
}; | ||
export declare type DiffLine = (DiffLineDeleted | DiffLineInserted | DiffLineContext) & DiffLineContent; | ||
export type DiffLine = (DiffLineDeleted | DiffLineInserted | DiffLineContext) & DiffLineContent; | ||
export interface DiffBlock { | ||
@@ -64,11 +64,11 @@ oldStartLine: number; | ||
} | ||
export declare type OutputFormatType = 'line-by-line' | 'side-by-side'; | ||
export type OutputFormatType = 'line-by-line' | 'side-by-side'; | ||
export declare const OutputFormatType: { | ||
[_: string]: OutputFormatType; | ||
}; | ||
export declare type LineMatchingType = 'lines' | 'words' | 'none'; | ||
export type LineMatchingType = 'lines' | 'words' | 'none'; | ||
export declare const LineMatchingType: { | ||
[_: string]: LineMatchingType; | ||
}; | ||
export declare type DiffStyleType = 'word' | 'char'; | ||
export type DiffStyleType = 'word' | 'char'; | ||
export declare const DiffStyleType: { | ||
@@ -75,0 +75,0 @@ [_: string]: DiffStyleType; |
@@ -9,3 +9,3 @@ "use strict"; | ||
LineType["CONTEXT"] = "context"; | ||
})(LineType = exports.LineType || (exports.LineType = {})); | ||
})(LineType || (exports.LineType = LineType = {})); | ||
exports.OutputFormatType = { | ||
@@ -12,0 +12,0 @@ LINE_BY_LINE: 'line-by-line', |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Diff2HtmlUI = exports.defaultDiff2HtmlUIConfig = void 0; | ||
var highlight_js_helpers_1 = require("./highlight.js-helpers"); | ||
var diff2html_1 = require("../../diff2html"); | ||
exports.defaultDiff2HtmlUIConfig = __assign(__assign({}, diff2html_1.defaultDiff2HtmlConfig), { synchronisedScroll: true, highlight: true, fileListToggle: true, fileListStartVisible: false, highlightLanguages: new Map(), smartSelection: true, fileContentToggle: true, stickyFileHeaders: true }); | ||
var Diff2HtmlUI = (function () { | ||
function Diff2HtmlUI(target, diffInput, config, hljs) { | ||
if (config === void 0) { config = {}; } | ||
const highlight_js_helpers_1 = require("./highlight.js-helpers"); | ||
const diff2html_1 = require("../../diff2html"); | ||
exports.defaultDiff2HtmlUIConfig = Object.assign(Object.assign({}, diff2html_1.defaultDiff2HtmlConfig), { synchronisedScroll: true, highlight: true, fileListToggle: true, fileListStartVisible: false, highlightLanguages: new Map(), smartSelection: true, fileContentToggle: true, stickyFileHeaders: true }); | ||
class Diff2HtmlUI { | ||
constructor(target, diffInput, config = {}, hljs) { | ||
this.hljs = null; | ||
this.currentSelectionColumnId = -1; | ||
this.config = __assign(__assign({}, exports.defaultDiff2HtmlUIConfig), config); | ||
this.config = Object.assign(Object.assign({}, exports.defaultDiff2HtmlUIConfig), config); | ||
this.diffHtml = diffInput !== undefined ? (0, diff2html_1.html)(diffInput, this.config) : target.innerHTML; | ||
@@ -29,3 +17,3 @@ this.targetElement = target; | ||
} | ||
Diff2HtmlUI.prototype.draw = function () { | ||
draw() { | ||
this.targetElement.innerHTML = this.diffHtml; | ||
@@ -42,9 +30,9 @@ if (this.config.synchronisedScroll) | ||
this.stickyFileHeaders(); | ||
}; | ||
Diff2HtmlUI.prototype.synchronisedScroll = function () { | ||
this.targetElement.querySelectorAll('.d2h-file-wrapper').forEach(function (wrapper) { | ||
var _a = Array().slice.call(wrapper.querySelectorAll('.d2h-file-side-diff')), left = _a[0], right = _a[1]; | ||
} | ||
synchronisedScroll() { | ||
this.targetElement.querySelectorAll('.d2h-file-wrapper').forEach(wrapper => { | ||
const [left, right] = Array().slice.call(wrapper.querySelectorAll('.d2h-file-side-diff')); | ||
if (left === undefined || right === undefined) | ||
return; | ||
var onScroll = function (event) { | ||
const onScroll = (event) => { | ||
if (event === null || event.target === null) | ||
@@ -64,10 +52,10 @@ return; | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype.fileListToggle = function (startVisible) { | ||
var showBtn = this.targetElement.querySelector('.d2h-show'); | ||
var hideBtn = this.targetElement.querySelector('.d2h-hide'); | ||
var fileList = this.targetElement.querySelector('.d2h-file-list'); | ||
} | ||
fileListToggle(startVisible) { | ||
const showBtn = this.targetElement.querySelector('.d2h-show'); | ||
const hideBtn = this.targetElement.querySelector('.d2h-hide'); | ||
const fileList = this.targetElement.querySelector('.d2h-file-list'); | ||
if (showBtn === null || hideBtn === null || fileList === null) | ||
return; | ||
var show = function () { | ||
const show = () => { | ||
showBtn.style.display = 'none'; | ||
@@ -77,3 +65,3 @@ hideBtn.style.display = 'inline'; | ||
}; | ||
var hide = function () { | ||
const hide = () => { | ||
showBtn.style.display = 'inline'; | ||
@@ -83,5 +71,5 @@ hideBtn.style.display = 'none'; | ||
}; | ||
showBtn.addEventListener('click', function () { return show(); }); | ||
hideBtn.addEventListener('click', function () { return hide(); }); | ||
var hashTag = this.getHashTag(); | ||
showBtn.addEventListener('click', () => show()); | ||
hideBtn.addEventListener('click', () => hide()); | ||
const hashTag = this.getHashTag(); | ||
if (hashTag === 'files-summary-show') | ||
@@ -95,9 +83,9 @@ show(); | ||
hide(); | ||
}; | ||
Diff2HtmlUI.prototype.fileContentToggle = function () { | ||
this.targetElement.querySelectorAll('.d2h-file-collapse').forEach(function (fileContentToggleBtn) { | ||
} | ||
fileContentToggle() { | ||
this.targetElement.querySelectorAll('.d2h-file-collapse').forEach(fileContentToggleBtn => { | ||
fileContentToggleBtn.style.display = 'flex'; | ||
var toggleFileContents = function (selector) { | ||
const toggleFileContents = selector => { | ||
var _a; | ||
var fileContents = (_a = fileContentToggleBtn | ||
const fileContents = (_a = fileContentToggleBtn | ||
.closest('.d2h-file-wrapper')) === null || _a === void 0 ? void 0 : _a.querySelector(selector); | ||
@@ -109,3 +97,3 @@ if (fileContents !== null && fileContents !== undefined) { | ||
}; | ||
var toggleHandler = function (e) { | ||
const toggleHandler = e => { | ||
if (fileContentToggleBtn === e.target) | ||
@@ -116,36 +104,35 @@ return; | ||
}; | ||
fileContentToggleBtn.addEventListener('click', function (e) { return toggleHandler(e); }); | ||
fileContentToggleBtn.addEventListener('click', e => toggleHandler(e)); | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype.highlightCode = function () { | ||
var _this = this; | ||
var hljs = this.hljs; | ||
} | ||
highlightCode() { | ||
const hljs = this.hljs; | ||
if (hljs === null) { | ||
throw new Error('Missing a `highlight.js` implementation. Please provide one when instantiating Diff2HtmlUI.'); | ||
} | ||
var files = this.targetElement.querySelectorAll('.d2h-file-wrapper'); | ||
files.forEach(function (file) { | ||
var language = file.getAttribute('data-lang'); | ||
if (!(_this.config.highlightLanguages instanceof Map)) { | ||
_this.config.highlightLanguages = new Map(Object.entries(_this.config.highlightLanguages)); | ||
const files = this.targetElement.querySelectorAll('.d2h-file-wrapper'); | ||
files.forEach(file => { | ||
const language = file.getAttribute('data-lang'); | ||
if (!(this.config.highlightLanguages instanceof Map)) { | ||
this.config.highlightLanguages = new Map(Object.entries(this.config.highlightLanguages)); | ||
} | ||
var hljsLanguage = language && _this.config.highlightLanguages.has(language) | ||
const hljsLanguage = language && this.config.highlightLanguages.has(language) | ||
? | ||
_this.config.highlightLanguages.get(language) | ||
this.config.highlightLanguages.get(language) | ||
: language | ||
? (0, highlight_js_helpers_1.getLanguage)(language) | ||
: 'plaintext'; | ||
var codeLines = file.querySelectorAll('.d2h-code-line-ctn'); | ||
codeLines.forEach(function (line) { | ||
var text = line.textContent; | ||
var lineParent = line.parentNode; | ||
if (text === null || lineParent === null || !_this.isElement(lineParent)) | ||
const codeLines = file.querySelectorAll('.d2h-code-line-ctn'); | ||
codeLines.forEach(line => { | ||
const text = line.textContent; | ||
const lineParent = line.parentNode; | ||
if (text === null || lineParent === null || !this.isElement(lineParent)) | ||
return; | ||
var result = (0, highlight_js_helpers_1.closeTags)(hljs.highlight(text, { | ||
const result = (0, highlight_js_helpers_1.closeTags)(hljs.highlight(text, { | ||
language: hljsLanguage, | ||
ignoreIllegals: true, | ||
})); | ||
var originalStream = (0, highlight_js_helpers_1.nodeStream)(line); | ||
const originalStream = (0, highlight_js_helpers_1.nodeStream)(line); | ||
if (originalStream.length) { | ||
var resultNode = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); | ||
const resultNode = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); | ||
resultNode.innerHTML = result.value; | ||
@@ -161,15 +148,15 @@ result.value = (0, highlight_js_helpers_1.mergeStreams)(originalStream, (0, highlight_js_helpers_1.nodeStream)(resultNode), text); | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype.stickyFileHeaders = function () { | ||
this.targetElement.querySelectorAll('.d2h-file-header').forEach(function (header) { | ||
} | ||
stickyFileHeaders() { | ||
this.targetElement.querySelectorAll('.d2h-file-header').forEach(header => { | ||
header.classList.add('d2h-sticky-header'); | ||
}); | ||
}; | ||
Diff2HtmlUI.prototype.smartSelection = function () { | ||
} | ||
smartSelection() { | ||
console.warn('Smart selection is now enabled by default with CSS. No need to call this method anymore.'); | ||
}; | ||
Diff2HtmlUI.prototype.getHashTag = function () { | ||
var docUrl = document.URL; | ||
var hashTagIndex = docUrl.indexOf('#'); | ||
var hashTag = null; | ||
} | ||
getHashTag() { | ||
const docUrl = document.URL; | ||
const hashTagIndex = docUrl.indexOf('#'); | ||
let hashTag = null; | ||
if (hashTagIndex !== -1) { | ||
@@ -179,9 +166,8 @@ hashTag = docUrl.substr(hashTagIndex + 1); | ||
return hashTag; | ||
}; | ||
Diff2HtmlUI.prototype.isElement = function (arg) { | ||
} | ||
isElement(arg) { | ||
return arg !== null && (arg === null || arg === void 0 ? void 0 : arg.classList) !== undefined; | ||
}; | ||
return Diff2HtmlUI; | ||
}()); | ||
} | ||
} | ||
exports.Diff2HtmlUI = Diff2HtmlUI; | ||
//# sourceMappingURL=diff2html-ui-base.js.map |
@@ -6,3 +6,4 @@ import { DiffFile } from '../../types'; | ||
} | ||
export { Diff2HtmlUIConfig, defaultDiff2HtmlUIConfig }; | ||
export { defaultDiff2HtmlUIConfig }; | ||
export type { Diff2HtmlUIConfig }; | ||
//# sourceMappingURL=diff2html-ui-slim.d.ts.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultDiff2HtmlUIConfig = exports.Diff2HtmlUI = void 0; | ||
var highlight_js_slim_1 = require("./highlight.js-slim"); | ||
var diff2html_ui_base_1 = require("./diff2html-ui-base"); | ||
const highlight_js_slim_1 = require("./highlight.js-slim"); | ||
const diff2html_ui_base_1 = require("./diff2html-ui-base"); | ||
Object.defineProperty(exports, "defaultDiff2HtmlUIConfig", { enumerable: true, get: function () { return diff2html_ui_base_1.defaultDiff2HtmlUIConfig; } }); | ||
var Diff2HtmlUI = (function (_super) { | ||
__extends(Diff2HtmlUI, _super); | ||
function Diff2HtmlUI(target, diffInput, config) { | ||
if (config === void 0) { config = {}; } | ||
return _super.call(this, target, diffInput, config, highlight_js_slim_1.hljs) || this; | ||
class Diff2HtmlUI extends diff2html_ui_base_1.Diff2HtmlUI { | ||
constructor(target, diffInput, config = {}) { | ||
super(target, diffInput, config, highlight_js_slim_1.hljs); | ||
} | ||
return Diff2HtmlUI; | ||
}(diff2html_ui_base_1.Diff2HtmlUI)); | ||
} | ||
exports.Diff2HtmlUI = Diff2HtmlUI; | ||
//# sourceMappingURL=diff2html-ui-slim.js.map |
@@ -6,3 +6,4 @@ import { DiffFile } from '../../types'; | ||
} | ||
export { Diff2HtmlUIConfig, defaultDiff2HtmlUIConfig }; | ||
export { defaultDiff2HtmlUIConfig }; | ||
export type { Diff2HtmlUIConfig }; | ||
//# sourceMappingURL=diff2html-ui.d.ts.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultDiff2HtmlUIConfig = exports.Diff2HtmlUI = void 0; | ||
var highlight_js_1 = __importDefault(require("highlight.js")); | ||
var diff2html_ui_base_1 = require("./diff2html-ui-base"); | ||
const tslib_1 = require("tslib"); | ||
const highlight_js_1 = tslib_1.__importDefault(require("highlight.js")); | ||
const diff2html_ui_base_1 = require("./diff2html-ui-base"); | ||
Object.defineProperty(exports, "defaultDiff2HtmlUIConfig", { enumerable: true, get: function () { return diff2html_ui_base_1.defaultDiff2HtmlUIConfig; } }); | ||
var Diff2HtmlUI = (function (_super) { | ||
__extends(Diff2HtmlUI, _super); | ||
function Diff2HtmlUI(target, diffInput, config) { | ||
if (config === void 0) { config = {}; } | ||
return _super.call(this, target, diffInput, config, highlight_js_1.default) || this; | ||
class Diff2HtmlUI extends diff2html_ui_base_1.Diff2HtmlUI { | ||
constructor(target, diffInput, config = {}) { | ||
super(target, diffInput, config, highlight_js_1.default); | ||
} | ||
return Diff2HtmlUI; | ||
}(diff2html_ui_base_1.Diff2HtmlUI)); | ||
} | ||
exports.Diff2HtmlUI = Diff2HtmlUI; | ||
//# sourceMappingURL=diff2html-ui.js.map |
import { HighlightResult } from 'highlight.js'; | ||
declare type NodeEvent = { | ||
type NodeEvent = { | ||
event: 'start' | 'stop'; | ||
@@ -4,0 +4,0 @@ offset: number; |
@@ -11,5 +11,5 @@ "use strict"; | ||
function nodeStream(node) { | ||
var result = []; | ||
var nodeStream = function (node, offset) { | ||
for (var child = node.firstChild; child; child = child.nextSibling) { | ||
const result = []; | ||
const nodeStream = (node, offset) => { | ||
for (let child = node.firstChild; child; child = child.nextSibling) { | ||
if (child.nodeType === 3 && child.nodeValue !== null) { | ||
@@ -41,5 +41,5 @@ offset += child.nodeValue.length; | ||
function mergeStreams(original, highlighted, value) { | ||
var processed = 0; | ||
var result = ''; | ||
var nodeStack = []; | ||
let processed = 0; | ||
let result = ''; | ||
const nodeStack = []; | ||
function isElement(arg) { | ||
@@ -61,5 +61,5 @@ return arg !== null && (arg === null || arg === void 0 ? void 0 : arg.attributes) !== undefined; | ||
} | ||
result += "<".concat(tag(node), " ").concat(Array() | ||
.map.call(node.attributes, function (attr) { return "".concat(attr.nodeName, "=\"").concat(escapeHTML(attr.value).replace(/"/g, '"'), "\""); }) | ||
.join(' '), ">"); | ||
result += `<${tag(node)} ${Array() | ||
.map.call(node.attributes, attr => `${attr.nodeName}="${escapeHTML(attr.value).replace(/"/g, '"')}"`) | ||
.join(' ')}>`; | ||
} | ||
@@ -73,3 +73,3 @@ function close(node) { | ||
while (original.length || highlighted.length) { | ||
var stream = selectStream(); | ||
let stream = selectStream(); | ||
result += escapeHTML(value.substring(processed, stream[0].offset)); | ||
@@ -99,9 +99,9 @@ processed = stream[0].offset; | ||
function closeTags(res) { | ||
var tokenStack = new Array(); | ||
const tokenStack = new Array(); | ||
res.value = res.value | ||
.split('\n') | ||
.map(function (line) { | ||
var prepend = tokenStack.map(function (token) { return "<span class=\"".concat(token, "\">"); }).join(''); | ||
var matches = line.matchAll(/(<span class="(.*?)">|<\/span>)/g); | ||
Array.from(matches).forEach(function (match) { | ||
.map(line => { | ||
const prepend = tokenStack.map(token => `<span class="${token}">`).join(''); | ||
const matches = line.matchAll(/(<span class="(.*?)">|<\/span>)/g); | ||
Array.from(matches).forEach(match => { | ||
if (match[0] === '</span>') | ||
@@ -112,3 +112,3 @@ tokenStack.shift(); | ||
}); | ||
var append = '</span>'.repeat(tokenStack.length); | ||
const append = '</span>'.repeat(tokenStack.length); | ||
return prepend + line + append; | ||
@@ -120,3 +120,3 @@ }) | ||
exports.closeTags = closeTags; | ||
var languagesToExt = { | ||
const languagesToExt = { | ||
'1c': '1c', | ||
@@ -123,0 +123,0 @@ abnf: 'abnf', |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hljs = void 0; | ||
var core_1 = __importDefault(require("highlight.js/lib/core")); | ||
var cpp_1 = __importDefault(require("highlight.js/lib/languages/cpp")); | ||
var xml_1 = __importDefault(require("highlight.js/lib/languages/xml")); | ||
var awk_1 = __importDefault(require("highlight.js/lib/languages/awk")); | ||
var bash_1 = __importDefault(require("highlight.js/lib/languages/bash")); | ||
var c_1 = __importDefault(require("highlight.js/lib/languages/c")); | ||
var clojure_1 = __importDefault(require("highlight.js/lib/languages/clojure")); | ||
var crystal_1 = __importDefault(require("highlight.js/lib/languages/crystal")); | ||
var csharp_1 = __importDefault(require("highlight.js/lib/languages/csharp")); | ||
var csp_1 = __importDefault(require("highlight.js/lib/languages/csp")); | ||
var css_1 = __importDefault(require("highlight.js/lib/languages/css")); | ||
var markdown_1 = __importDefault(require("highlight.js/lib/languages/markdown")); | ||
var dart_1 = __importDefault(require("highlight.js/lib/languages/dart")); | ||
var diff_1 = __importDefault(require("highlight.js/lib/languages/diff")); | ||
var dockerfile_1 = __importDefault(require("highlight.js/lib/languages/dockerfile")); | ||
var elixir_1 = __importDefault(require("highlight.js/lib/languages/elixir")); | ||
var elm_1 = __importDefault(require("highlight.js/lib/languages/elm")); | ||
var ruby_1 = __importDefault(require("highlight.js/lib/languages/ruby")); | ||
var erlang_1 = __importDefault(require("highlight.js/lib/languages/erlang")); | ||
var fsharp_1 = __importDefault(require("highlight.js/lib/languages/fsharp")); | ||
var go_1 = __importDefault(require("highlight.js/lib/languages/go")); | ||
var gradle_1 = __importDefault(require("highlight.js/lib/languages/gradle")); | ||
var groovy_1 = __importDefault(require("highlight.js/lib/languages/groovy")); | ||
var handlebars_1 = __importDefault(require("highlight.js/lib/languages/handlebars")); | ||
var haskell_1 = __importDefault(require("highlight.js/lib/languages/haskell")); | ||
var ini_1 = __importDefault(require("highlight.js/lib/languages/ini")); | ||
var java_1 = __importDefault(require("highlight.js/lib/languages/java")); | ||
var javascript_1 = __importDefault(require("highlight.js/lib/languages/javascript")); | ||
var json_1 = __importDefault(require("highlight.js/lib/languages/json")); | ||
var kotlin_1 = __importDefault(require("highlight.js/lib/languages/kotlin")); | ||
var less_1 = __importDefault(require("highlight.js/lib/languages/less")); | ||
var lisp_1 = __importDefault(require("highlight.js/lib/languages/lisp")); | ||
var lua_1 = __importDefault(require("highlight.js/lib/languages/lua")); | ||
var makefile_1 = __importDefault(require("highlight.js/lib/languages/makefile")); | ||
var perl_1 = __importDefault(require("highlight.js/lib/languages/perl")); | ||
var nginx_1 = __importDefault(require("highlight.js/lib/languages/nginx")); | ||
var objectivec_1 = __importDefault(require("highlight.js/lib/languages/objectivec")); | ||
var pgsql_1 = __importDefault(require("highlight.js/lib/languages/pgsql")); | ||
var php_1 = __importDefault(require("highlight.js/lib/languages/php")); | ||
var plaintext_1 = __importDefault(require("highlight.js/lib/languages/plaintext")); | ||
var powershell_1 = __importDefault(require("highlight.js/lib/languages/powershell")); | ||
var properties_1 = __importDefault(require("highlight.js/lib/languages/properties")); | ||
var protobuf_1 = __importDefault(require("highlight.js/lib/languages/protobuf")); | ||
var python_1 = __importDefault(require("highlight.js/lib/languages/python")); | ||
var rust_1 = __importDefault(require("highlight.js/lib/languages/rust")); | ||
var scala_1 = __importDefault(require("highlight.js/lib/languages/scala")); | ||
var scss_1 = __importDefault(require("highlight.js/lib/languages/scss")); | ||
var shell_1 = __importDefault(require("highlight.js/lib/languages/shell")); | ||
var sql_1 = __importDefault(require("highlight.js/lib/languages/sql")); | ||
var swift_1 = __importDefault(require("highlight.js/lib/languages/swift")); | ||
var yaml_1 = __importDefault(require("highlight.js/lib/languages/yaml")); | ||
var typescript_1 = __importDefault(require("highlight.js/lib/languages/typescript")); | ||
const tslib_1 = require("tslib"); | ||
const core_1 = tslib_1.__importDefault(require("highlight.js/lib/core")); | ||
const cpp_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/cpp")); | ||
const xml_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/xml")); | ||
const awk_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/awk")); | ||
const bash_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/bash")); | ||
const c_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/c")); | ||
const clojure_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/clojure")); | ||
const crystal_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/crystal")); | ||
const csharp_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/csharp")); | ||
const csp_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/csp")); | ||
const css_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/css")); | ||
const markdown_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/markdown")); | ||
const dart_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/dart")); | ||
const diff_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/diff")); | ||
const dockerfile_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/dockerfile")); | ||
const elixir_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/elixir")); | ||
const elm_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/elm")); | ||
const ruby_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/ruby")); | ||
const erlang_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/erlang")); | ||
const fsharp_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/fsharp")); | ||
const go_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/go")); | ||
const gradle_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/gradle")); | ||
const groovy_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/groovy")); | ||
const handlebars_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/handlebars")); | ||
const haskell_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/haskell")); | ||
const ini_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/ini")); | ||
const java_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/java")); | ||
const javascript_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/javascript")); | ||
const json_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/json")); | ||
const kotlin_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/kotlin")); | ||
const less_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/less")); | ||
const lisp_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/lisp")); | ||
const lua_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/lua")); | ||
const makefile_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/makefile")); | ||
const perl_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/perl")); | ||
const nginx_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/nginx")); | ||
const objectivec_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/objectivec")); | ||
const pgsql_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/pgsql")); | ||
const php_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/php")); | ||
const plaintext_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/plaintext")); | ||
const powershell_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/powershell")); | ||
const properties_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/properties")); | ||
const protobuf_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/protobuf")); | ||
const python_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/python")); | ||
const rust_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/rust")); | ||
const scala_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/scala")); | ||
const scss_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/scss")); | ||
const shell_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/shell")); | ||
const sql_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/sql")); | ||
const swift_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/swift")); | ||
const yaml_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/yaml")); | ||
const typescript_1 = tslib_1.__importDefault(require("highlight.js/lib/languages/typescript")); | ||
core_1.default.registerLanguage('cpp', cpp_1.default); | ||
@@ -60,0 +58,0 @@ core_1.default.registerLanguage('xml', xml_1.default); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hashCode = exports.unifyPath = exports.escapeForRegExp = void 0; | ||
var specials = [ | ||
const specials = [ | ||
'-', | ||
@@ -22,3 +22,3 @@ '[', | ||
]; | ||
var regex = RegExp('[' + specials.join('\\') + ']', 'g'); | ||
const regex = RegExp('[' + specials.join('\\') + ']', 'g'); | ||
function escapeForRegExp(str) { | ||
@@ -33,4 +33,4 @@ return str.replace(regex, '\\$&'); | ||
function hashCode(text) { | ||
var i, chr, len; | ||
var hash = 0; | ||
let i, chr, len; | ||
let hash = 0; | ||
for (i = 0, len = text.length; i < len; i++) { | ||
@@ -37,0 +37,0 @@ chr = text.charCodeAt(i); |
{ | ||
"name": "diff2html", | ||
"version": "3.4.37", | ||
"version": "3.4.38", | ||
"homepage": "https://diff2html.xyz", | ||
@@ -88,24 +88,23 @@ "description": "Fast Diff to colorized HTML", | ||
"optionalDependencies": { | ||
"highlight.js": "11.6.0" | ||
"highlight.js": "11.8.0" | ||
}, | ||
"devDependencies": { | ||
"@types/diff": "5.0.2", | ||
"@types/diff": "5.0.3", | ||
"@types/hogan.js": "3.0.1", | ||
"@types/jest": "29.2.0", | ||
"@types/mkdirp": "1.0.2", | ||
"@types/node": "18.11.3", | ||
"@types/jest": "29.5.3", | ||
"@types/node": "20.4.8", | ||
"@types/nopt": "3.0.29", | ||
"@typescript-eslint/eslint-plugin": "5.40.1", | ||
"@typescript-eslint/parser": "5.40.1", | ||
"@typescript-eslint/eslint-plugin": "6.2.1", | ||
"@typescript-eslint/parser": "6.2.1", | ||
"all-contributors-cli": "^6.24.0", | ||
"autoprefixer": "10.4.12", | ||
"autoprefixer": "10.4.14", | ||
"bulma": "^0.9.4", | ||
"clipboard": "2.0.11", | ||
"copy-webpack-plugin": "11.0.0", | ||
"css-loader": "6.7.1", | ||
"cssnano": "5.1.13", | ||
"eslint": "8.26.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-jest": "27.1.3", | ||
"css-loader": "6.8.1", | ||
"cssnano": "6.0.1", | ||
"eslint": "8.46.0", | ||
"eslint-config-prettier": "9.0.0", | ||
"eslint-plugin-import": "2.28.0", | ||
"eslint-plugin-jest": "27.2.3", | ||
"eslint-plugin-json": "3.1.0", | ||
@@ -115,30 +114,30 @@ "eslint-plugin-node": "11.1.0", | ||
"eslint-plugin-promise": "6.1.1", | ||
"eslint-plugin-sonarjs": "0.16.0", | ||
"eslint-plugin-sonarjs": "0.20.0", | ||
"file-loader": "6.2.0", | ||
"handlebars": "4.7.7", | ||
"handlebars-loader": "1.7.2", | ||
"html-webpack-plugin": "5.5.0", | ||
"handlebars": "4.7.8", | ||
"handlebars-loader": "1.7.3", | ||
"html-webpack-plugin": "5.5.3", | ||
"husky": "^8.0.1", | ||
"image-webpack-loader": "8.1.0", | ||
"is-ci-cli": "2.2.0", | ||
"jest": "29.2.1", | ||
"lint-staged": "13.0.3", | ||
"jest": "29.6.2", | ||
"lint-staged": "13.2.3", | ||
"markdown-toc": "^1.2.0", | ||
"mini-css-extract-plugin": "2.6.1", | ||
"mkdirp": "1.0.4", | ||
"nopt": "6.0.0", | ||
"postcss": "8.4.18", | ||
"postcss-cli": "10.0.0", | ||
"postcss-import": "15.0.0", | ||
"postcss-loader": "7.0.1", | ||
"postcss-preset-env": "7.8.2", | ||
"prettier": "2.7.1", | ||
"ts-jest": "29.0.3", | ||
"ts-loader": "9.4.1", | ||
"mini-css-extract-plugin": "2.7.6", | ||
"mkdirp": "3.0.1", | ||
"nopt": "7.2.0", | ||
"postcss": "8.4.27", | ||
"postcss-cli": "10.1.0", | ||
"postcss-import": "15.1.0", | ||
"postcss-loader": "7.3.3", | ||
"postcss-preset-env": "9.1.1", | ||
"prettier": "3.0.1", | ||
"ts-jest": "29.1.1", | ||
"ts-loader": "9.4.4", | ||
"ts-node": "10.9.1", | ||
"typescript": "4.8.4", | ||
"typescript": "5.1.6", | ||
"url-loader": "4.1.1", | ||
"webpack": "5.76.0", | ||
"webpack-cli": "4.10.0", | ||
"whatwg-fetch": "3.6.2" | ||
"webpack": "5.88.2", | ||
"webpack-cli": "5.1.4", | ||
"whatwg-fetch": "3.6.17" | ||
}, | ||
@@ -145,0 +144,0 @@ "resolutions": { |
@@ -256,3 +256,3 @@ # diff2html | ||
```html | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en-us"> | ||
@@ -457,3 +457,3 @@ <head> | ||
```html | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html> | ||
@@ -460,0 +460,0 @@ <head> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1928115
50
4931
1