Comparing version 0.5.1 to 0.6.0
@@ -176,3 +176,6 @@ "use strict"; | ||
} else { | ||
if (token.color === char.color && token.morph === char.morph) { | ||
if (char.code === '\n') { | ||
result.push(token); | ||
token = null; | ||
} else if (token.color === char.color && token.morph === char.morph) { | ||
token.code += char.code; | ||
@@ -186,3 +189,3 @@ } else { | ||
result.push(token); | ||
if (token != null) result.push(token); | ||
return result; | ||
@@ -205,3 +208,5 @@ } | ||
while (index < startIndex + l.length && index < startParsed.length) { | ||
result.push({ ...startParsed[index], | ||
result.push({ | ||
code: startParsed[index].code, | ||
color: startParsed[index].color, | ||
morph: l === r ? 'retain' : 'delete' | ||
@@ -217,3 +222,5 @@ }); | ||
if (r !== l) { | ||
result.push({ ...endParsed[endex], | ||
result.push({ | ||
code: endParsed[endex].code, | ||
color: endParsed[endex].color, | ||
morph: 'create' | ||
@@ -279,3 +286,34 @@ }); | ||
recurse(start, end); | ||
return tokens(result); | ||
let [sat, sln, eat, eln] = [0, 0, 0, 0]; | ||
const positioned = result.map(({ | ||
code, | ||
color, | ||
morph | ||
}) => { | ||
const value = { | ||
code, | ||
color, | ||
morph, | ||
from: morph === 'create' ? null : [sat, sln], | ||
to: morph === 'delete' ? null : [eat, eln] | ||
}; | ||
if (code === '\n') { | ||
if (morph !== 'create') { | ||
sat = 0; | ||
sln++; | ||
} | ||
if (morph !== 'delete') { | ||
eat = 0; | ||
eln++; | ||
} | ||
} else { | ||
if (morph !== 'create') sat++; | ||
if (morph !== 'delete') eat++; | ||
} | ||
return value; | ||
}); | ||
return tokens(positioned); | ||
} |
@@ -153,3 +153,6 @@ import { createStarryNight, all } from '@wooorm/starry-night'; | ||
} else { | ||
if (token.color === char.color && token.morph === char.morph) { | ||
if (char.code === '\n') { | ||
result.push(token); | ||
token = null; | ||
} else if (token.color === char.color && token.morph === char.morph) { | ||
token.code += char.code; | ||
@@ -163,3 +166,3 @@ } else { | ||
result.push(token); | ||
if (token != null) result.push(token); | ||
return result; | ||
@@ -182,3 +185,5 @@ } | ||
while (index < startIndex + l.length && index < startParsed.length) { | ||
result.push({ ...startParsed[index], | ||
result.push({ | ||
code: startParsed[index].code, | ||
color: startParsed[index].color, | ||
morph: l === r ? 'retain' : 'delete' | ||
@@ -194,3 +199,5 @@ }); | ||
if (r !== l) { | ||
result.push({ ...endParsed[endex], | ||
result.push({ | ||
code: endParsed[endex].code, | ||
color: endParsed[endex].color, | ||
morph: 'create' | ||
@@ -256,3 +263,34 @@ }); | ||
recurse(start, end); | ||
return tokens(result); | ||
let [sat, sln, eat, eln] = [0, 0, 0, 0]; | ||
const positioned = result.map(({ | ||
code, | ||
color, | ||
morph | ||
}) => { | ||
const value = { | ||
code, | ||
color, | ||
morph, | ||
from: morph === 'create' ? null : [sat, sln], | ||
to: morph === 'delete' ? null : [eat, eln] | ||
}; | ||
if (code === '\n') { | ||
if (morph !== 'create') { | ||
sat = 0; | ||
sln++; | ||
} | ||
if (morph !== 'delete') { | ||
eat = 0; | ||
eln++; | ||
} | ||
} else { | ||
if (morph !== 'create') sat++; | ||
if (morph !== 'delete') eat++; | ||
} | ||
return value; | ||
}); | ||
return tokens(positioned); | ||
} |
@@ -16,10 +16,15 @@ import type { Root } from 'hast'; | ||
export declare const language: LanguageDictionary; | ||
export declare type Location = [number, number]; | ||
export interface Token { | ||
code: string; | ||
color: string; | ||
morph?: 'create' | 'delete' | 'retain'; | ||
} | ||
export interface MorphToken extends Token { | ||
morph: 'create' | 'delete' | 'retain'; | ||
from: Location | null; | ||
to: Location | null; | ||
} | ||
export declare function parse(code: CodeTree): Token[]; | ||
export declare function getColor(classList: string[]): string | undefined; | ||
export declare function diff(start: CodeTree, end: CodeTree): (Token | null)[]; | ||
export declare function diff(start: CodeTree, end: CodeTree): MorphToken[]; | ||
//# sourceMappingURL=tags.d.ts.map |
{ | ||
"name": "code-fns", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "A library for visualizing code.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
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
30367
952