mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 07:37:10 +00:00
Add version mcmeta diff page (#428)
* Add version mcmeta diff page * Add toggle for word wrapping * Fix diff view on mobile * Use full layout width on version details * Show image and audio diffs * Add word_wrap locale
This commit is contained in:
@@ -545,3 +545,39 @@ export function composeMatrix(translation: Vector, leftRotation: quat, scale: Ve
|
||||
.scale(scale)
|
||||
.mul(Matrix4.fromQuat(rightRotation))
|
||||
}
|
||||
|
||||
export interface PatchLine {
|
||||
line: string
|
||||
before?: number
|
||||
after?: number
|
||||
}
|
||||
|
||||
export function parseGitPatch(patch: string) {
|
||||
const source = patch.split('\n')
|
||||
const result: PatchLine[] = []
|
||||
let before = 1
|
||||
let after = 1
|
||||
for (let i = 0; i < source.length; i += 1) {
|
||||
const line = source[i]
|
||||
if (line.startsWith('@')) {
|
||||
const match = line.match(/^@@ -(\d+)(?:,(?:\d+))? \+(\d+)(?:,(?:\d+))? @@/)
|
||||
if (!match) throw new Error(`Invalid patch pattern at line ${i+1}: ${line}`)
|
||||
result.push({ line })
|
||||
before = Number(match[1])
|
||||
after = Number(match[2])
|
||||
} else if (line.startsWith(' ')) {
|
||||
result.push({ line, before, after })
|
||||
before += 1
|
||||
after += 1
|
||||
} else if (line.startsWith('+')) {
|
||||
result.push({ line, after })
|
||||
after += 1
|
||||
} else if (line.startsWith('-')) {
|
||||
result.push({ line, before })
|
||||
before += 1
|
||||
} else if (!line.startsWith('\\')) {
|
||||
throw new Error(`Invalid patch, got ${line.charAt(0)} at line ${i+1}`)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user