@dou-ui/code 0.1.0-alpha.1 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"code-diff.js","names":["_sfc_main"],"sources":["../src/code-diff.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n DiffSplitIcon,\n DiffUnifiedIcon,\n FoldVerticalIcon,\n UnfoldVerticalIcon,\n} from '@dou-ui/icons'\nimport { DouButton, DouTooltip, createScrollLink, useNamespace } from 'dou-ui'\nimport { computed, h, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'\nimport CodeEditor from './code-editor.vue'\nimport { type CodeDiffHunk, diffText, lineStarts } from './core/diff'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeTransactionResult } from './core/transaction'\nimport { splitLines } from './core/text'\nimport {\n type CodeDecoration,\n type CodeExtension,\n type CodeGutterMarker,\n type CodeWidget,\n defineCodeExtension,\n} from './extension'\nimport { format, useCodeMessages } from './locale'\nimport type { CodeDiffEmits, CodeDiffProps, CodeEditorExpose } from './types'\n\n/**\n * Two texts compared: side by side, or the changes in one column. Changed\n * lines are tinted, the words that changed inside them marked, and long\n * runs of unchanged lines hidden behind a bar that shows them.\n */\ndefineOptions({ name: 'DouCodeDiff' })\n\nconst props = withDefaults(defineProps<CodeDiffProps>(), {\n original: '',\n modelValue: '',\n language: undefined,\n mode: 'auto',\n editable: false,\n collapseUnchanged: true,\n ignoreWhitespace: false,\n words: true,\n wrap: false,\n extensions: undefined,\n tabSize: 2,\n toolbar: true,\n messages: undefined,\n})\nconst emit = defineEmits<CodeDiffEmits>()\n\nconst ns = useNamespace('code-diff')\nconst messages = useCodeMessages(() => props.messages)\n\n// ---------------------------------------------------------------- view\n\nconst root = ref<HTMLElement>()\n/** Whether the box is wide enough for two columns. */\nconst roomy = ref(true)\n/** The view picked with the toggle, when `mode` isn't bound. */\nconst picked = ref<'split' | 'inline' | null>(null)\nwatch(\n () => props.mode,\n () => (picked.value = null),\n)\nconst view = computed<'split' | 'inline'>(() => {\n if (picked.value) return picked.value\n if (props.mode !== 'auto') return props.mode\n return roomy.value ? 'split' : 'inline'\n})\nfunction toggleView() {\n const other = view.value === 'split' ? 'inline' : 'split'\n picked.value = other\n emit('update:mode', other)\n}\n\n/** Below this, each side would show fewer than about 30 columns: one column reads better. */\nconst SPLIT_WIDTH = 560\n\nlet resize: ResizeObserver | undefined\nonMounted(() => {\n if (typeof ResizeObserver === 'undefined' || !root.value) return\n resize = new ResizeObserver(([entry]) => {\n if (entry) roomy.value = entry.contentRect.width >= SPLIT_WIDTH\n })\n resize.observe(root.value)\n})\nonBeforeUnmount(() => resize?.disconnect())\n\n// ---------------------------------------------------------------- texts and changes\n\n/** The modified text as edited here, ahead of the parent's copy. */\nconst modified = ref(props.modelValue)\nwatch(\n () => props.modelValue,\n (value) => (modified.value = value),\n)\nfunction onModifiedInput(value: string) {\n modified.value = value\n emit('update:modelValue', value)\n}\n\nconst hunks = computed<CodeDiffHunk[]>(() =>\n diffText(props.original, modified.value, {\n ignoreWhitespace: props.ignoreWhitespace,\n words: props.words,\n }),\n)\nconst originalLines = computed(() => splitLines(props.original))\nconst modifiedLines = computed(() => splitLines(modified.value))\n\nconst stats = computed(() => {\n let added = 0\n let removed = 0\n for (const hunk of hunks.value) {\n added += hunk.modifiedCount\n removed += hunk.originalCount\n }\n return { added, removed }\n})\n\n// ---------------------------------------------------------------- unchanged lines\n\ninterface Unchanged {\n /** First line on each side, from 1. */\n a: number\n b: number\n count: number\n /** Where its hidden part starts, from its first line, and how long it is (0 when nothing is hidden). */\n hideFrom: number\n hideCount: number\n /** Stays the same while the modified text is edited. */\n key: number\n}\n\nconst collapse = computed(() => {\n const option = props.collapseUnchanged\n if (!option) return null\n const own = option === true ? {} : option\n return {\n context: Math.max(1, Math.floor(own.context ?? 3)),\n minLines: Math.max(1, Math.floor(own.minLines ?? 4)),\n }\n})\n/** The runs of unchanged lines opened with their bar, by key; `true` for all of them. */\nconst opened = reactive(new Set<number>())\nconst allOpen = ref(false)\n\nconst unchanged = computed<Unchanged[]>(() => {\n const list = hunks.value\n const total = originalLines.value.length\n const out: Unchanged[] = []\n const rule = collapse.value\n const push = (a: number, b: number, count: number, before: boolean, after: boolean) => {\n if (count <= 0) return\n let hideFrom = 0\n let hideCount = 0\n if (rule && list.length && !allOpen.value && !opened.has(a)) {\n const from = before ? rule.context : 0\n const to = count - (after ? rule.context : 0)\n if (to - from >= rule.minLines) {\n hideFrom = from\n hideCount = to - from\n }\n }\n out.push({ a, b, count, hideFrom, hideCount, key: a })\n }\n let a = 1\n let b = 1\n for (let i = 0; i < list.length; i++) {\n const hunk = list[i]!\n push(a, b, hunk.originalStart - a, i > 0, true)\n a = hunk.originalStart + hunk.originalCount\n b = hunk.modifiedStart + hunk.modifiedCount\n }\n push(a, b, total - a + 1, list.length > 0, false)\n return out\n})\nconst hiddenCount = computed(() => unchanged.value.reduce((sum, run) => sum + run.hideCount, 0))\nconst anyHideable = computed(() => !!collapse.value && hunks.value.length > 0)\n\nfunction open(key: number) {\n opened.add(key)\n}\nfunction toggleAll() {\n if (hiddenCount.value) allOpen.value = true\n else {\n allOpen.value = false\n opened.clear()\n }\n}\n// A new pair of texts starts collapsed again.\nwatch(\n () => props.original,\n () => {\n allOpen.value = false\n opened.clear()\n },\n)\n\n/**\n * The bar over a run of hidden lines. Side by side, the original's bar\n * mirrors the modified one's: pressed with a pointer, but left out of the\n * keyboard order and of what is read out, so the run is one stop, not two.\n */\nfunction bar(run: Unchanged, mirror = false) {\n const label = format(messages.value.diffUnchanged, { count: run.hideCount })\n return h(\n 'button',\n {\n type: 'button',\n class: ns.e('bar'),\n 'aria-label': `${messages.value.unfold}:${label}`,\n 'aria-hidden': mirror ? 'true' : undefined,\n tabindex: mirror ? -1 : undefined,\n onClick: () => open(run.key),\n },\n [h(UnfoldVerticalIcon, { class: ns.e('bar-icon') }), h('span', label)],\n )\n}\nconst BAR_HEIGHT = 28\n\n// ---------------------------------------------------------------- side by side\n\ntype Side = 'a' | 'b'\n\n/** What one side of the split view draws: tints, marks, fillers, hidden lines and bars. */\nfunction sideExtension(side: Side): CodeExtension {\n const startOf = (hunk: CodeDiffHunk) => (side === 'a' ? hunk.originalStart : hunk.modifiedStart)\n const countOf = (hunk: CodeDiffHunk) => (side === 'a' ? hunk.originalCount : hunk.modifiedCount)\n const otherCountOf = (hunk: CodeDiffHunk) =>\n side === 'a' ? hunk.modifiedCount : hunk.originalCount\n const tone = side === 'a' ? 'removed' : 'added'\n\n return defineCodeExtension({\n name: 'diff',\n decorations({ visible }) {\n const out: CodeDecoration[] = []\n for (const hunk of hunks.value) {\n const start = startOf(hunk)\n const count = countOf(hunk)\n if (start > visible.to) break\n if (!count || start + count - 1 < visible.from) continue\n const from = Math.max(start, visible.from)\n const to = Math.min(start + count - 1, visible.to)\n for (let n = from; n <= to; n++)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-${tone}` })\n for (const part of hunk.parts) {\n const range = side === 'a' ? part.original : part.modified\n if (range.to > range.from)\n out.push({\n type: 'mark',\n from: range.from,\n to: range.to,\n class: `${ns.e('word')} is-${tone}`,\n })\n }\n }\n return out\n },\n gutters: [\n {\n name: 'diff',\n width: 16,\n markers({ visible }) {\n const out: CodeGutterMarker[] = []\n const title = side === 'a' ? messages.value.diffRemoved : messages.value.diffAdded\n for (const hunk of hunks.value) {\n const start = startOf(hunk)\n const count = countOf(hunk)\n if (start > visible.to) break\n for (let n = Math.max(start, visible.from); n < start + count && n <= visible.to; n++)\n out.push({\n line: n,\n text: side === 'a' ? '−' : '+',\n class: `${ns.e('sign')} is-${tone}`,\n title,\n })\n }\n return out\n },\n },\n ],\n widgets() {\n const out: CodeWidget[] = []\n hunks.value.forEach((hunk, i) => {\n const missing = otherCountOf(hunk) - countOf(hunk)\n if (missing <= 0) return\n const last = startOf(hunk) - 1 + countOf(hunk)\n out.push({\n id: `fill-${i}`,\n ...(last >= 1 ? { line: last } : { line: 1, position: 'above' as const }),\n height: missing * 20,\n render: () =>\n h('div', {\n class: ns.e('filler'),\n style: { height: `calc(${missing} * var(--dou-code-editor-line-height))` },\n }),\n })\n })\n const total = side === 'a' ? originalLines.value.length : modifiedLines.value.length\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = (side === 'a' ? run.a : run.b) + run.hideFrom\n const last = first + run.hideCount - 1\n out.push({\n id: `bar-${run.key}`,\n ...(last < total ? { line: last + 1, position: 'above' as const } : { line: first - 1 }),\n height: BAR_HEIGHT,\n render: () => bar(run, side === 'a'),\n })\n }\n return out\n },\n hide() {\n const out: Array<{ from: number; to: number }> = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = (side === 'a' ? run.a : run.b) + run.hideFrom\n out.push({ from: first, to: first + run.hideCount - 1 })\n }\n return out\n },\n })\n}\n\nconst modifiedOwn = sideExtension('b')\nconst modifiedExtensions = computed(() => [modifiedOwn, ...(props.extensions ?? [])])\n\nconst editorA = ref<CodeEditorExpose>()\nconst editorB = ref<CodeEditorExpose>()\nconst sideA = ref<HTMLElement>()\nconst sideB = ref<HTMLElement>()\nconst extensionsA = [sideExtension('a')]\n\n// Both sides scroll together; they are the same height, line for line.\nconst link = createScrollLink()\nfunction onScroll(event: Event) {\n if (view.value !== 'split') return\n const from = (event.target as HTMLElement).closest(`.${ns.e('side')}`)\n const source = from?.querySelector<HTMLElement>('.dou-code-editor__scroller')\n if (!source || source !== event.target) return\n const other = (from === sideA.value ? sideB.value : sideA.value)?.querySelector<HTMLElement>(\n '.dou-code-editor__scroller',\n )\n if (other) link.follow(source, other)\n}\n\n// ---------------------------------------------------------------- inline\n\nconst enum Kind {\n Same,\n Removed,\n Added,\n}\n\ninterface Unified {\n text: string\n kinds: Uint8Array\n /** Line numbers on each side, 0 where the line isn't there. */\n aNums: Int32Array\n bNums: Int32Array\n /** Where each change starts, from 1. */\n hunkLines: number[]\n /** Where each unchanged run starts, from 1, by key. */\n runLines: Map<number, number>\n marks: Array<{ from: number; to: number; kind: Kind }>\n}\n\nconst unified = computed<Unified | null>(() => {\n if (view.value !== 'inline') return null\n const a = originalLines.value\n const b = modifiedLines.value\n const lines: string[] = []\n const kinds: number[] = []\n const aNums: number[] = []\n const bNums: number[] = []\n const hunkLines: number[] = []\n const runLines = new Map<number, number>()\n const marks: Unified['marks'] = []\n let pos = 0\n const push = (text: string, kind: Kind, an: number, bn: number) => {\n lines.push(text)\n kinds.push(kind)\n aNums.push(an)\n bNums.push(bn)\n pos += text.length + 1\n }\n const runs = unchanged.value\n let r = 0\n const sameUpTo = (aEnd: number) => {\n while (r < runs.length && runs[r]!.a < aEnd) {\n const run = runs[r++]!\n runLines.set(run.key, lines.length + 1)\n for (let i = 0; i < run.count; i++) push(b[run.b - 1 + i]!, Kind.Same, run.a + i, run.b + i)\n }\n }\n // Where each original and modified line starts, for moving the word marks.\n const aStarts = lineStarts(a)\n const bStarts = lineStarts(b)\n for (const hunk of hunks.value) {\n sameUpTo(hunk.originalStart)\n hunkLines.push(lines.length + 1)\n const removedAt = pos\n for (let i = 0; i < hunk.originalCount; i++)\n push(a[hunk.originalStart - 1 + i]!, Kind.Removed, hunk.originalStart + i, 0)\n const addedAt = pos\n for (let i = 0; i < hunk.modifiedCount; i++)\n push(b[hunk.modifiedStart - 1 + i]!, Kind.Added, 0, hunk.modifiedStart + i)\n const aBase = aStarts[hunk.originalStart - 1]!\n const bBase = bStarts[hunk.modifiedStart - 1]!\n for (const part of hunk.parts) {\n if (part.original.to > part.original.from)\n marks.push({\n from: removedAt + part.original.from - aBase,\n to: removedAt + part.original.to - aBase,\n kind: Kind.Removed,\n })\n if (part.modified.to > part.modified.from)\n marks.push({\n from: addedAt + part.modified.from - bBase,\n to: addedAt + part.modified.to - bBase,\n kind: Kind.Added,\n })\n }\n }\n sameUpTo(Infinity)\n return {\n text: lines.join('\\n'),\n kinds: Uint8Array.from(kinds),\n aNums: Int32Array.from(aNums),\n bNums: Int32Array.from(bNums),\n hunkLines,\n runLines,\n marks,\n }\n})\n\nconst digits = (n: number) => String(Math.max(1, n)).length\nconst numberWidth = (n: number) => digits(n) * 8 + 16\n\n/** The line numbers of one side, in the inline view's gutter. */\nconst numbersOf =\n (pick: 'aNums' | 'bNums') =>\n ({ visible }: { visible: { from: number; to: number } }) => {\n const u = unified.value\n if (!u) return []\n const out: CodeGutterMarker[] = []\n const list = u[pick]\n for (let n = visible.from; n <= visible.to && n <= list.length; n++) {\n const value = list[n - 1]!\n const kind = u.kinds[n - 1]\n const tone = kind === Kind.Removed ? ' is-removed' : kind === Kind.Added ? ' is-added' : ''\n out.push({ line: n, text: value ? String(value) : '', class: `${ns.e('number')}${tone}` })\n }\n return out\n }\n\nconst inlineExtension = defineCodeExtension({\n name: 'diff',\n decorations({ visible }) {\n const u = unified.value\n if (!u) return []\n const out: CodeDecoration[] = []\n for (let n = visible.from; n <= visible.to && n <= u.kinds.length; n++) {\n const kind = u.kinds[n - 1]\n if (kind === Kind.Removed)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-removed` })\n else if (kind === Kind.Added)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-added` })\n }\n for (const mark of u.marks)\n out.push({\n type: 'mark',\n from: mark.from,\n to: mark.to,\n class: `${ns.e('word')} ${mark.kind === Kind.Removed ? 'is-removed' : 'is-added'}`,\n })\n return out\n },\n get gutters() {\n return [\n {\n name: 'diff-original',\n width: numberWidth(originalLines.value.length),\n markers: numbersOf('aNums'),\n },\n {\n name: 'diff-modified',\n width: numberWidth(modifiedLines.value.length),\n markers: numbersOf('bNums'),\n },\n {\n name: 'diff',\n width: 16,\n markers: ({ visible }: { visible: { from: number; to: number } }) => {\n const u = unified.value\n if (!u) return []\n const out: CodeGutterMarker[] = []\n for (let n = visible.from; n <= visible.to && n <= u.kinds.length; n++) {\n const kind = u.kinds[n - 1]\n if (kind === Kind.Removed)\n out.push({\n line: n,\n text: '−',\n class: `${ns.e('sign')} is-removed`,\n title: messages.value.diffRemoved,\n })\n else if (kind === Kind.Added)\n out.push({\n line: n,\n text: '+',\n class: `${ns.e('sign')} is-added`,\n title: messages.value.diffAdded,\n })\n }\n return out\n },\n },\n ]\n },\n widgets() {\n const u = unified.value\n if (!u) return []\n const total = u.kinds.length\n const out: CodeWidget[] = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = u.runLines.get(run.key)! + run.hideFrom\n const last = first + run.hideCount - 1\n out.push({\n id: `bar-${run.key}`,\n ...(last < total ? { line: last + 1, position: 'above' as const } : { line: first - 1 }),\n height: BAR_HEIGHT,\n render: () => bar(run),\n })\n }\n return out\n },\n hide() {\n const u = unified.value\n if (!u) return []\n const out: Array<{ from: number; to: number }> = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = u.runLines.get(run.key)! + run.hideFrom\n out.push({ from: first, to: first + run.hideCount - 1 })\n }\n return out\n },\n})\nconst inlineExtensions = [inlineExtension]\nconst editorInline = ref<CodeEditorExpose>()\nconst inlineBox = ref<HTMLElement>()\n\n// ---------------------------------------------------------------- hidden lines a cursor reaches\n\n/** Shows the run of hidden lines a cursor moved into, e.g. with search. */\nfunction revealAt(side: Side | 'inline', result: CodeTransactionResult) {\n if (!hiddenCount.value) return\n const { doc, selection } = result.state\n const u = unified.value\n for (const range of selection.ranges) {\n const line = doc.lineAt(range.head).number\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const start =\n side === 'inline' ? (u?.runLines.get(run.key) ?? 0) : side === 'a' ? run.a : run.b\n const first = start + run.hideFrom\n if (line >= first && line < first + run.hideCount) open(run.key)\n }\n }\n}\n\n// ---------------------------------------------------------------- going from change to change\n\nconst live = ref('')\nconst current = ref(-1)\n\nfunction target(): { editor: CodeEditorExpose; box: HTMLElement; side: Side | 'inline' } | null {\n if (view.value === 'inline')\n return editorInline.value && inlineBox.value\n ? { editor: editorInline.value, box: inlineBox.value, side: 'inline' }\n : null\n const inA = !!sideA.value?.contains(document.activeElement)\n const editor = inA ? editorA.value : editorB.value\n const box = inA ? sideA.value : sideB.value\n return editor && box ? { editor, box, side: inA ? 'a' : 'b' } : null\n}\n\nfunction lineOf(index: number, side: Side | 'inline') {\n const hunk = hunks.value[index]!\n if (side === 'inline') return unified.value?.hunkLines[index] ?? 1\n return side === 'a' ? hunk.originalStart : hunk.modifiedStart\n}\n\nfunction go(step: 1 | -1) {\n const list = hunks.value\n const t = target()\n if (!list.length || !t) return false\n const doc = t.editor.doc\n const at = doc.lineAt(t.editor.selection.ranges[t.editor.selection.main]!.head).number\n let index = -1\n if (step > 0) {\n index = list.findIndex((_, i) => lineOf(i, t.side) > at)\n if (index < 0) index = 0\n } else {\n for (let i = list.length - 1; i >= 0; i--)\n if (lineOf(i, t.side) < at) {\n index = i\n break\n }\n if (index < 0) index = list.length - 1\n }\n const line = Math.min(doc.lines, Math.max(1, lineOf(index, t.side)))\n t.editor.select(doc.line(line).from)\n current.value = index\n const hunk = list[index]!\n live.value = format(messages.value.diffChangeAt, {\n index: index + 1,\n count: list.length,\n line: hunk.modifiedStart,\n removed: hunk.originalCount,\n added: hunk.modifiedCount,\n })\n // The editor may grow with the page instead of scrolling: bring the cursor into the window too.\n nextTick(() => t.box.querySelector('textarea')?.scrollIntoView({ block: 'nearest' }))\n return true\n}\n\nconst keymap: CodeKeymap = {\n f7: () => go(1),\n 'shift+f7': () => go(-1),\n}\n\nfunction next() {\n return go(1)\n}\nfunction previous() {\n return go(-1)\n}\n\nconst summary = computed(() =>\n hunks.value.length ? format(messages.value.diffStats, stats.value) : messages.value.diffNoChanges,\n)\n\ndefineExpose({\n /** The changes found now. */\n get hunks() {\n return hunks.value\n },\n /** Moves to the next change; `false` when there is none. */\n next,\n /** Moves to the previous change. */\n previous,\n /** Shows every unchanged line. */\n expandAll: () => (allOpen.value = true),\n /** Hides the runs of unchanged lines again. */\n collapseAll: () => {\n allOpen.value = false\n opened.clear()\n },\n /** The editors drawn now: both sides, or the inline one as `modified`. */\n get original() {\n return view.value === 'split' ? editorA.value : undefined\n },\n get modified() {\n return view.value === 'split' ? editorB.value : editorInline.value\n },\n})\n</script>\n\n<template>\n <div ref=\"root\" :class=\"[ns.b(), ns.m(view)]\" role=\"group\" :aria-label=\"messages.diff\">\n <div v-if=\"toolbar\" :class=\"ns.e('toolbar')\">\n <span :class=\"ns.e('stats')\">\n <template v-if=\"hunks.length\">\n <span :class=\"[ns.e('count'), 'is-added']\" aria-hidden=\"true\">+{{ stats.added }}</span>\n <span :class=\"[ns.e('count'), 'is-removed']\" aria-hidden=\"true\"\n >−{{ stats.removed }}</span\n >\n <span :class=\"ns.e('hidden-text')\">{{ summary }}</span>\n </template>\n <span v-else :class=\"ns.e('summary')\">{{ summary }}</span>\n </span>\n <DouTooltip :content=\"messages.diffPrevious\" shortcut=\"shift+f7\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"!hunks.length\"\n :aria-label=\"messages.diffPrevious\"\n @click=\"previous\"\n >\n <ArrowUpIcon />\n </DouButton>\n </DouTooltip>\n <DouTooltip :content=\"messages.diffNext\" shortcut=\"f7\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"!hunks.length\"\n :aria-label=\"messages.diffNext\"\n @click=\"next\"\n >\n <ArrowDownIcon />\n </DouButton>\n </DouTooltip>\n <DouTooltip\n v-if=\"anyHideable\"\n :content=\"hiddenCount ? messages.diffExpandAll : messages.diffCollapse\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"hiddenCount ? messages.diffExpandAll : messages.diffCollapse\"\n @click=\"toggleAll\"\n >\n <UnfoldVerticalIcon v-if=\"hiddenCount\" />\n <FoldVerticalIcon v-else />\n </DouButton>\n </DouTooltip>\n <DouTooltip :content=\"view === 'split' ? messages.diffInline : messages.diffSplit\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"view === 'split' ? messages.diffInline : messages.diffSplit\"\n @click=\"toggleView\"\n >\n <DiffUnifiedIcon v-if=\"view === 'split'\" />\n <DiffSplitIcon v-else />\n </DouButton>\n </DouTooltip>\n </div>\n <div v-if=\"view === 'split'\" :class=\"ns.e('body')\" @scroll.capture=\"onScroll\">\n <div :class=\"ns.e('label')\">{{ messages.diffOriginal }}</div>\n <div :class=\"ns.e('label')\">{{ messages.diffModified }}</div>\n <div ref=\"sideA\" :class=\"[ns.e('side'), 'is-original']\">\n <CodeEditor\n ref=\"editorA\"\n :model-value=\"original\"\n :language=\"language\"\n :extensions=\"extensionsA\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diffOriginal\"\n :foldable=\"false\"\n :active-line=\"false\"\n readonly\n @transaction=\"revealAt('a', $event)\"\n />\n </div>\n <div ref=\"sideB\" :class=\"[ns.e('side'), 'is-modified']\">\n <CodeEditor\n ref=\"editorB\"\n :model-value=\"modified\"\n :language=\"language\"\n :extensions=\"modifiedExtensions\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diffModified\"\n :foldable=\"false\"\n :active-line=\"false\"\n :readonly=\"!editable\"\n @update:model-value=\"onModifiedInput\"\n @transaction=\"revealAt('b', $event)\"\n />\n </div>\n </div>\n <div v-else ref=\"inlineBox\" :class=\"ns.e('body')\">\n <CodeEditor\n ref=\"editorInline\"\n :model-value=\"unified?.text ?? ''\"\n :language=\"language\"\n :extensions=\"inlineExtensions\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diff\"\n :line-numbers=\"false\"\n :foldable=\"false\"\n :active-line=\"false\"\n :wrap=\"wrap\"\n readonly\n @transaction=\"revealAt('inline', $event)\"\n />\n </div>\n <div :class=\"ns.e('live')\" aria-live=\"polite\">{{ live }}</div>\n </div>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"code-diff.js","names":["_sfc_main"],"sources":["../src/code-diff.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n DiffSplitIcon,\n DiffUnifiedIcon,\n FoldVerticalIcon,\n UnfoldVerticalIcon,\n} from '@dou-ui/icons'\nimport { DouButton, DouTooltip, createScrollLink, useNamespace } from 'dou-ui'\nimport { computed, h, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'\nimport CodeEditor from './code-editor.vue'\nimport { type CodeDiffHunk, diffText, lineStarts } from './core/diff'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeTransactionResult } from './core/transaction'\nimport { splitLines } from './core/text'\nimport {\n type CodeDecoration,\n type CodeExtension,\n type CodeGutterMarker,\n type CodeWidget,\n defineCodeExtension,\n} from './extension'\nimport { format, useCodeMessages } from './locale'\nimport type { CodeDiffEmits, CodeDiffProps, CodeEditorExpose } from './types'\n\n/**\n * Two texts compared: side by side, or the changes in one column. Changed\n * lines are tinted, the words that changed inside them marked, and long\n * runs of unchanged lines hidden behind a bar that shows them.\n */\ndefineOptions({ name: 'DouCodeDiff' })\n\nconst props = withDefaults(defineProps<CodeDiffProps>(), {\n original: '',\n modelValue: '',\n language: undefined,\n mode: 'auto',\n editable: false,\n collapseUnchanged: true,\n ignoreWhitespace: false,\n words: true,\n wrap: false,\n extensions: undefined,\n tabSize: 2,\n toolbar: true,\n bordered: true,\n messages: undefined,\n})\nconst emit = defineEmits<CodeDiffEmits>()\n\nconst ns = useNamespace('code-diff')\nconst messages = useCodeMessages(() => props.messages)\n\n// ---------------------------------------------------------------- view\n\nconst root = ref<HTMLElement>()\n/** Whether the box is wide enough for two columns. */\nconst roomy = ref(true)\n/** The view picked with the toggle, when `mode` isn't bound. */\nconst picked = ref<'split' | 'inline' | null>(null)\nwatch(\n () => props.mode,\n () => (picked.value = null),\n)\nconst view = computed<'split' | 'inline'>(() => {\n if (picked.value) return picked.value\n if (props.mode !== 'auto') return props.mode\n return roomy.value ? 'split' : 'inline'\n})\nfunction toggleView() {\n const other = view.value === 'split' ? 'inline' : 'split'\n picked.value = other\n emit('update:mode', other)\n}\n\n/** Below this, each side would show fewer than about 30 columns: one column reads better. */\nconst SPLIT_WIDTH = 560\n\nlet resize: ResizeObserver | undefined\nonMounted(() => {\n if (typeof ResizeObserver === 'undefined' || !root.value) return\n resize = new ResizeObserver(([entry]) => {\n if (entry) roomy.value = entry.contentRect.width >= SPLIT_WIDTH\n })\n resize.observe(root.value)\n})\nonBeforeUnmount(() => resize?.disconnect())\n\n// ---------------------------------------------------------------- texts and changes\n\n/** The modified text as edited here, ahead of the parent's copy. */\nconst modified = ref(props.modelValue)\nwatch(\n () => props.modelValue,\n (value) => (modified.value = value),\n)\nfunction onModifiedInput(value: string) {\n modified.value = value\n emit('update:modelValue', value)\n}\n\nconst hunks = computed<CodeDiffHunk[]>(() =>\n diffText(props.original, modified.value, {\n ignoreWhitespace: props.ignoreWhitespace,\n words: props.words,\n }),\n)\nconst originalLines = computed(() => splitLines(props.original))\nconst modifiedLines = computed(() => splitLines(modified.value))\n\nconst stats = computed(() => {\n let added = 0\n let removed = 0\n for (const hunk of hunks.value) {\n added += hunk.modifiedCount\n removed += hunk.originalCount\n }\n return { added, removed }\n})\n\n// ---------------------------------------------------------------- unchanged lines\n\ninterface Unchanged {\n /** First line on each side, from 1. */\n a: number\n b: number\n count: number\n /** Where its hidden part starts, from its first line, and how long it is (0 when nothing is hidden). */\n hideFrom: number\n hideCount: number\n /** Stays the same while the modified text is edited. */\n key: number\n}\n\nconst collapse = computed(() => {\n const option = props.collapseUnchanged\n if (!option) return null\n const own = option === true ? {} : option\n return {\n context: Math.max(1, Math.floor(own.context ?? 3)),\n minLines: Math.max(1, Math.floor(own.minLines ?? 4)),\n }\n})\n/** The runs of unchanged lines opened with their bar, by key; `true` for all of them. */\nconst opened = reactive(new Set<number>())\nconst allOpen = ref(false)\n\nconst unchanged = computed<Unchanged[]>(() => {\n const list = hunks.value\n const total = originalLines.value.length\n const out: Unchanged[] = []\n const rule = collapse.value\n const push = (a: number, b: number, count: number, before: boolean, after: boolean) => {\n if (count <= 0) return\n let hideFrom = 0\n let hideCount = 0\n if (rule && list.length && !allOpen.value && !opened.has(a)) {\n const from = before ? rule.context : 0\n const to = count - (after ? rule.context : 0)\n if (to - from >= rule.minLines) {\n hideFrom = from\n hideCount = to - from\n }\n }\n out.push({ a, b, count, hideFrom, hideCount, key: a })\n }\n let a = 1\n let b = 1\n for (let i = 0; i < list.length; i++) {\n const hunk = list[i]!\n push(a, b, hunk.originalStart - a, i > 0, true)\n a = hunk.originalStart + hunk.originalCount\n b = hunk.modifiedStart + hunk.modifiedCount\n }\n push(a, b, total - a + 1, list.length > 0, false)\n return out\n})\nconst hiddenCount = computed(() => unchanged.value.reduce((sum, run) => sum + run.hideCount, 0))\nconst anyHideable = computed(() => !!collapse.value && hunks.value.length > 0)\n\nfunction open(key: number) {\n opened.add(key)\n}\nfunction toggleAll() {\n if (hiddenCount.value) allOpen.value = true\n else {\n allOpen.value = false\n opened.clear()\n }\n}\n// A new pair of texts starts collapsed again.\nwatch(\n () => props.original,\n () => {\n allOpen.value = false\n opened.clear()\n },\n)\n\n/**\n * The bar over a run of hidden lines. Side by side, the original's bar\n * mirrors the modified one's: pressed with a pointer, but left out of the\n * keyboard order and of what is read out, so the run is one stop, not two.\n */\nfunction bar(run: Unchanged, mirror = false) {\n const label = format(messages.value.diffUnchanged, { count: run.hideCount })\n return h(\n 'button',\n {\n type: 'button',\n class: ns.e('bar'),\n 'aria-label': `${messages.value.unfold}:${label}`,\n 'aria-hidden': mirror ? 'true' : undefined,\n tabindex: mirror ? -1 : undefined,\n onClick: () => open(run.key),\n },\n [h(UnfoldVerticalIcon, { class: ns.e('bar-icon') }), h('span', label)],\n )\n}\nconst BAR_HEIGHT = 28\n\n// ---------------------------------------------------------------- side by side\n\ntype Side = 'a' | 'b'\n\n/** What one side of the split view draws: tints, marks, fillers, hidden lines and bars. */\nfunction sideExtension(side: Side): CodeExtension {\n const startOf = (hunk: CodeDiffHunk) => (side === 'a' ? hunk.originalStart : hunk.modifiedStart)\n const countOf = (hunk: CodeDiffHunk) => (side === 'a' ? hunk.originalCount : hunk.modifiedCount)\n const otherCountOf = (hunk: CodeDiffHunk) =>\n side === 'a' ? hunk.modifiedCount : hunk.originalCount\n const tone = side === 'a' ? 'removed' : 'added'\n\n return defineCodeExtension({\n name: 'diff',\n decorations({ visible }) {\n const out: CodeDecoration[] = []\n for (const hunk of hunks.value) {\n const start = startOf(hunk)\n const count = countOf(hunk)\n if (start > visible.to) break\n if (!count || start + count - 1 < visible.from) continue\n const from = Math.max(start, visible.from)\n const to = Math.min(start + count - 1, visible.to)\n for (let n = from; n <= to; n++)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-${tone}` })\n for (const part of hunk.parts) {\n const range = side === 'a' ? part.original : part.modified\n if (range.to > range.from)\n out.push({\n type: 'mark',\n from: range.from,\n to: range.to,\n class: `${ns.e('word')} is-${tone}`,\n })\n }\n }\n return out\n },\n gutters: [\n {\n name: 'diff',\n width: 16,\n markers({ visible }) {\n const out: CodeGutterMarker[] = []\n const title = side === 'a' ? messages.value.diffRemoved : messages.value.diffAdded\n for (const hunk of hunks.value) {\n const start = startOf(hunk)\n const count = countOf(hunk)\n if (start > visible.to) break\n for (let n = Math.max(start, visible.from); n < start + count && n <= visible.to; n++)\n out.push({\n line: n,\n text: side === 'a' ? '−' : '+',\n class: `${ns.e('sign')} is-${tone}`,\n title,\n })\n }\n return out\n },\n },\n ],\n widgets() {\n const out: CodeWidget[] = []\n hunks.value.forEach((hunk, i) => {\n const missing = otherCountOf(hunk) - countOf(hunk)\n if (missing <= 0) return\n const last = startOf(hunk) - 1 + countOf(hunk)\n out.push({\n id: `fill-${i}`,\n ...(last >= 1 ? { line: last } : { line: 1, position: 'above' as const }),\n height: missing * 20,\n render: () =>\n h('div', {\n class: ns.e('filler'),\n style: { height: `calc(${missing} * var(--dou-code-editor-line-height))` },\n }),\n })\n })\n const total = side === 'a' ? originalLines.value.length : modifiedLines.value.length\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = (side === 'a' ? run.a : run.b) + run.hideFrom\n const last = first + run.hideCount - 1\n out.push({\n id: `bar-${run.key}`,\n ...(last < total ? { line: last + 1, position: 'above' as const } : { line: first - 1 }),\n height: BAR_HEIGHT,\n render: () => bar(run, side === 'a'),\n })\n }\n return out\n },\n hide() {\n const out: Array<{ from: number; to: number }> = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = (side === 'a' ? run.a : run.b) + run.hideFrom\n out.push({ from: first, to: first + run.hideCount - 1 })\n }\n return out\n },\n })\n}\n\nconst modifiedOwn = sideExtension('b')\nconst modifiedExtensions = computed(() => [modifiedOwn, ...(props.extensions ?? [])])\n\nconst editorA = ref<CodeEditorExpose>()\nconst editorB = ref<CodeEditorExpose>()\nconst sideA = ref<HTMLElement>()\nconst sideB = ref<HTMLElement>()\nconst extensionsA = [sideExtension('a')]\n\n// Both sides scroll together; they are the same height, line for line.\nconst link = createScrollLink()\nfunction onScroll(event: Event) {\n if (view.value !== 'split') return\n const from = (event.target as HTMLElement).closest(`.${ns.e('side')}`)\n const source = from?.querySelector<HTMLElement>('.dou-code-editor__scroller')\n if (!source || source !== event.target) return\n const other = (from === sideA.value ? sideB.value : sideA.value)?.querySelector<HTMLElement>(\n '.dou-code-editor__scroller',\n )\n if (other) link.follow(source, other)\n}\n\n// ---------------------------------------------------------------- inline\n\nconst enum Kind {\n Same,\n Removed,\n Added,\n}\n\ninterface Unified {\n text: string\n kinds: Uint8Array\n /** Line numbers on each side, 0 where the line isn't there. */\n aNums: Int32Array\n bNums: Int32Array\n /** Where each change starts, from 1. */\n hunkLines: number[]\n /** Where each unchanged run starts, from 1, by key. */\n runLines: Map<number, number>\n marks: Array<{ from: number; to: number; kind: Kind }>\n}\n\nconst unified = computed<Unified | null>(() => {\n if (view.value !== 'inline') return null\n const a = originalLines.value\n const b = modifiedLines.value\n const lines: string[] = []\n const kinds: number[] = []\n const aNums: number[] = []\n const bNums: number[] = []\n const hunkLines: number[] = []\n const runLines = new Map<number, number>()\n const marks: Unified['marks'] = []\n let pos = 0\n const push = (text: string, kind: Kind, an: number, bn: number) => {\n lines.push(text)\n kinds.push(kind)\n aNums.push(an)\n bNums.push(bn)\n pos += text.length + 1\n }\n const runs = unchanged.value\n let r = 0\n const sameUpTo = (aEnd: number) => {\n while (r < runs.length && runs[r]!.a < aEnd) {\n const run = runs[r++]!\n runLines.set(run.key, lines.length + 1)\n for (let i = 0; i < run.count; i++) push(b[run.b - 1 + i]!, Kind.Same, run.a + i, run.b + i)\n }\n }\n // Where each original and modified line starts, for moving the word marks.\n const aStarts = lineStarts(a)\n const bStarts = lineStarts(b)\n for (const hunk of hunks.value) {\n sameUpTo(hunk.originalStart)\n hunkLines.push(lines.length + 1)\n const removedAt = pos\n for (let i = 0; i < hunk.originalCount; i++)\n push(a[hunk.originalStart - 1 + i]!, Kind.Removed, hunk.originalStart + i, 0)\n const addedAt = pos\n for (let i = 0; i < hunk.modifiedCount; i++)\n push(b[hunk.modifiedStart - 1 + i]!, Kind.Added, 0, hunk.modifiedStart + i)\n const aBase = aStarts[hunk.originalStart - 1]!\n const bBase = bStarts[hunk.modifiedStart - 1]!\n for (const part of hunk.parts) {\n if (part.original.to > part.original.from)\n marks.push({\n from: removedAt + part.original.from - aBase,\n to: removedAt + part.original.to - aBase,\n kind: Kind.Removed,\n })\n if (part.modified.to > part.modified.from)\n marks.push({\n from: addedAt + part.modified.from - bBase,\n to: addedAt + part.modified.to - bBase,\n kind: Kind.Added,\n })\n }\n }\n sameUpTo(Infinity)\n return {\n text: lines.join('\\n'),\n kinds: Uint8Array.from(kinds),\n aNums: Int32Array.from(aNums),\n bNums: Int32Array.from(bNums),\n hunkLines,\n runLines,\n marks,\n }\n})\n\nconst digits = (n: number) => String(Math.max(1, n)).length\nconst numberWidth = (n: number) => digits(n) * 8 + 16\n\n/** The line numbers of one side, in the inline view's gutter. */\nconst numbersOf =\n (pick: 'aNums' | 'bNums') =>\n ({ visible }: { visible: { from: number; to: number } }) => {\n const u = unified.value\n if (!u) return []\n const out: CodeGutterMarker[] = []\n const list = u[pick]\n for (let n = visible.from; n <= visible.to && n <= list.length; n++) {\n const value = list[n - 1]!\n const kind = u.kinds[n - 1]\n const tone = kind === Kind.Removed ? ' is-removed' : kind === Kind.Added ? ' is-added' : ''\n out.push({ line: n, text: value ? String(value) : '', class: `${ns.e('number')}${tone}` })\n }\n return out\n }\n\nconst inlineExtension = defineCodeExtension({\n name: 'diff',\n decorations({ visible }) {\n const u = unified.value\n if (!u) return []\n const out: CodeDecoration[] = []\n for (let n = visible.from; n <= visible.to && n <= u.kinds.length; n++) {\n const kind = u.kinds[n - 1]\n if (kind === Kind.Removed)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-removed` })\n else if (kind === Kind.Added)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-added` })\n }\n for (const mark of u.marks)\n out.push({\n type: 'mark',\n from: mark.from,\n to: mark.to,\n class: `${ns.e('word')} ${mark.kind === Kind.Removed ? 'is-removed' : 'is-added'}`,\n })\n return out\n },\n get gutters() {\n return [\n {\n name: 'diff-original',\n width: numberWidth(originalLines.value.length),\n markers: numbersOf('aNums'),\n },\n {\n name: 'diff-modified',\n width: numberWidth(modifiedLines.value.length),\n markers: numbersOf('bNums'),\n },\n {\n name: 'diff',\n width: 16,\n markers: ({ visible }: { visible: { from: number; to: number } }) => {\n const u = unified.value\n if (!u) return []\n const out: CodeGutterMarker[] = []\n for (let n = visible.from; n <= visible.to && n <= u.kinds.length; n++) {\n const kind = u.kinds[n - 1]\n if (kind === Kind.Removed)\n out.push({\n line: n,\n text: '−',\n class: `${ns.e('sign')} is-removed`,\n title: messages.value.diffRemoved,\n })\n else if (kind === Kind.Added)\n out.push({\n line: n,\n text: '+',\n class: `${ns.e('sign')} is-added`,\n title: messages.value.diffAdded,\n })\n }\n return out\n },\n },\n ]\n },\n widgets() {\n const u = unified.value\n if (!u) return []\n const total = u.kinds.length\n const out: CodeWidget[] = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = u.runLines.get(run.key)! + run.hideFrom\n const last = first + run.hideCount - 1\n out.push({\n id: `bar-${run.key}`,\n ...(last < total ? { line: last + 1, position: 'above' as const } : { line: first - 1 }),\n height: BAR_HEIGHT,\n render: () => bar(run),\n })\n }\n return out\n },\n hide() {\n const u = unified.value\n if (!u) return []\n const out: Array<{ from: number; to: number }> = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = u.runLines.get(run.key)! + run.hideFrom\n out.push({ from: first, to: first + run.hideCount - 1 })\n }\n return out\n },\n})\nconst inlineExtensions = [inlineExtension]\nconst editorInline = ref<CodeEditorExpose>()\nconst inlineBox = ref<HTMLElement>()\n\n// ---------------------------------------------------------------- hidden lines a cursor reaches\n\n/** Shows the run of hidden lines a cursor moved into, e.g. with search. */\nfunction revealAt(side: Side | 'inline', result: CodeTransactionResult) {\n if (!hiddenCount.value) return\n const { doc, selection } = result.state\n const u = unified.value\n for (const range of selection.ranges) {\n const line = doc.lineAt(range.head).number\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const start =\n side === 'inline' ? (u?.runLines.get(run.key) ?? 0) : side === 'a' ? run.a : run.b\n const first = start + run.hideFrom\n if (line >= first && line < first + run.hideCount) open(run.key)\n }\n }\n}\n\n// ---------------------------------------------------------------- going from change to change\n\nconst live = ref('')\nconst current = ref(-1)\n\nfunction target(): { editor: CodeEditorExpose; box: HTMLElement; side: Side | 'inline' } | null {\n if (view.value === 'inline')\n return editorInline.value && inlineBox.value\n ? { editor: editorInline.value, box: inlineBox.value, side: 'inline' }\n : null\n const inA = !!sideA.value?.contains(document.activeElement)\n const editor = inA ? editorA.value : editorB.value\n const box = inA ? sideA.value : sideB.value\n return editor && box ? { editor, box, side: inA ? 'a' : 'b' } : null\n}\n\nfunction lineOf(index: number, side: Side | 'inline') {\n const hunk = hunks.value[index]!\n if (side === 'inline') return unified.value?.hunkLines[index] ?? 1\n return side === 'a' ? hunk.originalStart : hunk.modifiedStart\n}\n\nfunction go(step: 1 | -1) {\n const list = hunks.value\n const t = target()\n if (!list.length || !t) return false\n const doc = t.editor.doc\n const at = doc.lineAt(t.editor.selection.ranges[t.editor.selection.main]!.head).number\n let index = -1\n if (step > 0) {\n index = list.findIndex((_, i) => lineOf(i, t.side) > at)\n if (index < 0) index = 0\n } else {\n for (let i = list.length - 1; i >= 0; i--)\n if (lineOf(i, t.side) < at) {\n index = i\n break\n }\n if (index < 0) index = list.length - 1\n }\n const line = Math.min(doc.lines, Math.max(1, lineOf(index, t.side)))\n t.editor.select(doc.line(line).from)\n current.value = index\n const hunk = list[index]!\n live.value = format(messages.value.diffChangeAt, {\n index: index + 1,\n count: list.length,\n line: hunk.modifiedStart,\n removed: hunk.originalCount,\n added: hunk.modifiedCount,\n })\n // The editor may grow with the page instead of scrolling: bring the cursor into the window too.\n nextTick(() => t.box.querySelector('textarea')?.scrollIntoView({ block: 'nearest' }))\n return true\n}\n\nconst keymap: CodeKeymap = {\n f7: () => go(1),\n 'shift+f7': () => go(-1),\n}\n\nfunction next() {\n return go(1)\n}\nfunction previous() {\n return go(-1)\n}\n\nconst summary = computed(() =>\n hunks.value.length ? format(messages.value.diffStats, stats.value) : messages.value.diffNoChanges,\n)\n\ndefineExpose({\n /** The changes found now. */\n get hunks() {\n return hunks.value\n },\n /** Moves to the next change; `false` when there is none. */\n next,\n /** Moves to the previous change. */\n previous,\n /** Shows every unchanged line. */\n expandAll: () => (allOpen.value = true),\n /** Hides the runs of unchanged lines again. */\n collapseAll: () => {\n allOpen.value = false\n opened.clear()\n },\n /** The editors drawn now: both sides, or the inline one as `modified`. */\n get original() {\n return view.value === 'split' ? editorA.value : undefined\n },\n get modified() {\n return view.value === 'split' ? editorB.value : editorInline.value\n },\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[ns.b(), ns.m(view), ns.is('bordered', bordered)]\"\n role=\"group\"\n :aria-label=\"messages.diff\"\n >\n <div v-if=\"toolbar\" :class=\"ns.e('toolbar')\">\n <span :class=\"ns.e('stats')\">\n <template v-if=\"hunks.length\">\n <span :class=\"[ns.e('count'), 'is-added']\" aria-hidden=\"true\">+{{ stats.added }}</span>\n <span :class=\"[ns.e('count'), 'is-removed']\" aria-hidden=\"true\"\n >−{{ stats.removed }}</span\n >\n <span :class=\"ns.e('hidden-text')\">{{ summary }}</span>\n </template>\n <span v-else :class=\"ns.e('summary')\">{{ summary }}</span>\n </span>\n <DouTooltip :content=\"messages.diffPrevious\" shortcut=\"shift+f7\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"!hunks.length\"\n :aria-label=\"messages.diffPrevious\"\n @click=\"previous\"\n >\n <ArrowUpIcon />\n </DouButton>\n </DouTooltip>\n <DouTooltip :content=\"messages.diffNext\" shortcut=\"f7\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"!hunks.length\"\n :aria-label=\"messages.diffNext\"\n @click=\"next\"\n >\n <ArrowDownIcon />\n </DouButton>\n </DouTooltip>\n <DouTooltip\n v-if=\"anyHideable\"\n :content=\"hiddenCount ? messages.diffExpandAll : messages.diffCollapse\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"hiddenCount ? messages.diffExpandAll : messages.diffCollapse\"\n @click=\"toggleAll\"\n >\n <UnfoldVerticalIcon v-if=\"hiddenCount\" />\n <FoldVerticalIcon v-else />\n </DouButton>\n </DouTooltip>\n <DouTooltip :content=\"view === 'split' ? messages.diffInline : messages.diffSplit\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"view === 'split' ? messages.diffInline : messages.diffSplit\"\n @click=\"toggleView\"\n >\n <DiffUnifiedIcon v-if=\"view === 'split'\" />\n <DiffSplitIcon v-else />\n </DouButton>\n </DouTooltip>\n </div>\n <div v-if=\"view === 'split'\" :class=\"ns.e('body')\" @scroll.capture=\"onScroll\">\n <div :class=\"ns.e('label')\">{{ messages.diffOriginal }}</div>\n <div :class=\"ns.e('label')\">{{ messages.diffModified }}</div>\n <div ref=\"sideA\" :class=\"[ns.e('side'), 'is-original']\">\n <CodeEditor\n ref=\"editorA\"\n :model-value=\"original\"\n :language=\"language\"\n :extensions=\"extensionsA\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diffOriginal\"\n :foldable=\"false\"\n :active-line=\"false\"\n :bordered=\"false\"\n readonly\n @transaction=\"revealAt('a', $event)\"\n />\n </div>\n <div ref=\"sideB\" :class=\"[ns.e('side'), 'is-modified']\">\n <CodeEditor\n ref=\"editorB\"\n :model-value=\"modified\"\n :language=\"language\"\n :extensions=\"modifiedExtensions\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diffModified\"\n :foldable=\"false\"\n :active-line=\"false\"\n :bordered=\"false\"\n :readonly=\"!editable\"\n @update:model-value=\"onModifiedInput\"\n @transaction=\"revealAt('b', $event)\"\n />\n </div>\n </div>\n <div v-else ref=\"inlineBox\" :class=\"ns.e('body')\">\n <CodeEditor\n ref=\"editorInline\"\n :model-value=\"unified?.text ?? ''\"\n :language=\"language\"\n :extensions=\"inlineExtensions\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diff\"\n :line-numbers=\"false\"\n :foldable=\"false\"\n :active-line=\"false\"\n :bordered=\"false\"\n :wrap=\"wrap\"\n readonly\n @transaction=\"revealAt('inline', $event)\"\n />\n </div>\n <div :class=\"ns.e('live')\" aria-live=\"polite\">{{ live }}</div>\n </div>\n</template>\n"],"mappings":""}
@@ -56,6 +56,10 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
56
56
  type: Boolean,
57
57
  default: true
58
58
  },
59
+ bordered: {
60
+ type: Boolean,
61
+ default: true
62
+ },
59
63
  messages: { default: void 0 }
60
64
  },
61
65
  emits: ["update:modelValue", "update:mode"],
@@ -608,7 +612,11 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
608
612
  return openBlock(), createElementBlock("div", {
609
613
  ref_key: "root",
610
614
  ref: root,
611
- class: normalizeClass([unref(ns).b(), unref(ns).m(view.value)]),
615
+ class: normalizeClass([
616
+ unref(ns).b(),
617
+ unref(ns).m(view.value),
618
+ unref(ns).is("bordered", __props.bordered)
619
+ ]),
612
620
  role: "group",
613
621
  "aria-label": unref(messages).diff
614
622
  }, [
@@ -713,6 +721,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
713
721
  "aria-label": unref(messages).diffOriginal,
714
722
  foldable: false,
715
723
  "active-line": false,
724
+ bordered: false,
716
725
  readonly: "",
717
726
  onTransaction: _cache[0] || (_cache[0] = ($event) => revealAt("a", $event))
718
727
  }, null, 8, [
@@ -738,6 +747,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
738
747
  "aria-label": unref(messages).diffModified,
739
748
  foldable: false,
740
749
  "active-line": false,
750
+ bordered: false,
741
751
  readonly: !__props.editable,
742
752
  "onUpdate:modelValue": onModifiedInput,
743
753
  onTransaction: _cache[1] || (_cache[1] = ($event) => revealAt("b", $event))
@@ -768,6 +778,7 @@ var code_diff_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
768
778
  "line-numbers": false,
769
779
  foldable: false,
770
780
  "active-line": false,
781
+ bordered: false,
771
782
  wrap: __props.wrap,
772
783
  readonly: "",
773
784
  onTransaction: _cache[2] || (_cache[2] = ($event) => revealAt("inline", $event))
@@ -1 +1 @@
1
- {"version":3,"file":"code-diff.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_createElementVNode","_Fragment","_toDisplayString","_createVNode","_withCtx","_createBlock","_createCommentVNode","CodeEditor"],"sources":["../src/code-diff.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n DiffSplitIcon,\n DiffUnifiedIcon,\n FoldVerticalIcon,\n UnfoldVerticalIcon,\n} from '@dou-ui/icons'\nimport { DouButton, DouTooltip, createScrollLink, useNamespace } from 'dou-ui'\nimport { computed, h, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'\nimport CodeEditor from './code-editor.vue'\nimport { type CodeDiffHunk, diffText, lineStarts } from './core/diff'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeTransactionResult } from './core/transaction'\nimport { splitLines } from './core/text'\nimport {\n type CodeDecoration,\n type CodeExtension,\n type CodeGutterMarker,\n type CodeWidget,\n defineCodeExtension,\n} from './extension'\nimport { format, useCodeMessages } from './locale'\nimport type { CodeDiffEmits, CodeDiffProps, CodeEditorExpose } from './types'\n\n/**\n * Two texts compared: side by side, or the changes in one column. Changed\n * lines are tinted, the words that changed inside them marked, and long\n * runs of unchanged lines hidden behind a bar that shows them.\n */\ndefineOptions({ name: 'DouCodeDiff' })\n\nconst props = withDefaults(defineProps<CodeDiffProps>(), {\n original: '',\n modelValue: '',\n language: undefined,\n mode: 'auto',\n editable: false,\n collapseUnchanged: true,\n ignoreWhitespace: false,\n words: true,\n wrap: false,\n extensions: undefined,\n tabSize: 2,\n toolbar: true,\n messages: undefined,\n})\nconst emit = defineEmits<CodeDiffEmits>()\n\nconst ns = useNamespace('code-diff')\nconst messages = useCodeMessages(() => props.messages)\n\n// ---------------------------------------------------------------- view\n\nconst root = ref<HTMLElement>()\n/** Whether the box is wide enough for two columns. */\nconst roomy = ref(true)\n/** The view picked with the toggle, when `mode` isn't bound. */\nconst picked = ref<'split' | 'inline' | null>(null)\nwatch(\n () => props.mode,\n () => (picked.value = null),\n)\nconst view = computed<'split' | 'inline'>(() => {\n if (picked.value) return picked.value\n if (props.mode !== 'auto') return props.mode\n return roomy.value ? 'split' : 'inline'\n})\nfunction toggleView() {\n const other = view.value === 'split' ? 'inline' : 'split'\n picked.value = other\n emit('update:mode', other)\n}\n\n/** Below this, each side would show fewer than about 30 columns: one column reads better. */\nconst SPLIT_WIDTH = 560\n\nlet resize: ResizeObserver | undefined\nonMounted(() => {\n if (typeof ResizeObserver === 'undefined' || !root.value) return\n resize = new ResizeObserver(([entry]) => {\n if (entry) roomy.value = entry.contentRect.width >= SPLIT_WIDTH\n })\n resize.observe(root.value)\n})\nonBeforeUnmount(() => resize?.disconnect())\n\n// ---------------------------------------------------------------- texts and changes\n\n/** The modified text as edited here, ahead of the parent's copy. */\nconst modified = ref(props.modelValue)\nwatch(\n () => props.modelValue,\n (value) => (modified.value = value),\n)\nfunction onModifiedInput(value: string) {\n modified.value = value\n emit('update:modelValue', value)\n}\n\nconst hunks = computed<CodeDiffHunk[]>(() =>\n diffText(props.original, modified.value, {\n ignoreWhitespace: props.ignoreWhitespace,\n words: props.words,\n }),\n)\nconst originalLines = computed(() => splitLines(props.original))\nconst modifiedLines = computed(() => splitLines(modified.value))\n\nconst stats = computed(() => {\n let added = 0\n let removed = 0\n for (const hunk of hunks.value) {\n added += hunk.modifiedCount\n removed += hunk.originalCount\n }\n return { added, removed }\n})\n\n// ---------------------------------------------------------------- unchanged lines\n\ninterface Unchanged {\n /** First line on each side, from 1. */\n a: number\n b: number\n count: number\n /** Where its hidden part starts, from its first line, and how long it is (0 when nothing is hidden). */\n hideFrom: number\n hideCount: number\n /** Stays the same while the modified text is edited. */\n key: number\n}\n\nconst collapse = computed(() => {\n const option = props.collapseUnchanged\n if (!option) return null\n const own = option === true ? {} : option\n return {\n context: Math.max(1, Math.floor(own.context ?? 3)),\n minLines: Math.max(1, Math.floor(own.minLines ?? 4)),\n }\n})\n/** The runs of unchanged lines opened with their bar, by key; `true` for all of them. */\nconst opened = reactive(new Set<number>())\nconst allOpen = ref(false)\n\nconst unchanged = computed<Unchanged[]>(() => {\n const list = hunks.value\n const total = originalLines.value.length\n const out: Unchanged[] = []\n const rule = collapse.value\n const push = (a: number, b: number, count: number, before: boolean, after: boolean) => {\n if (count <= 0) return\n let hideFrom = 0\n let hideCount = 0\n if (rule && list.length && !allOpen.value && !opened.has(a)) {\n const from = before ? rule.context : 0\n const to = count - (after ? rule.context : 0)\n if (to - from >= rule.minLines) {\n hideFrom = from\n hideCount = to - from\n }\n }\n out.push({ a, b, count, hideFrom, hideCount, key: a })\n }\n let a = 1\n let b = 1\n for (let i = 0; i < list.length; i++) {\n const hunk = list[i]!\n push(a, b, hunk.originalStart - a, i > 0, true)\n a = hunk.originalStart + hunk.originalCount\n b = hunk.modifiedStart + hunk.modifiedCount\n }\n push(a, b, total - a + 1, list.length > 0, false)\n return out\n})\nconst hiddenCount = computed(() => unchanged.value.reduce((sum, run) => sum + run.hideCount, 0))\nconst anyHideable = computed(() => !!collapse.value && hunks.value.length > 0)\n\nfunction open(key: number) {\n opened.add(key)\n}\nfunction toggleAll() {\n if (hiddenCount.value) allOpen.value = true\n else {\n allOpen.value = false\n opened.clear()\n }\n}\n// A new pair of texts starts collapsed again.\nwatch(\n () => props.original,\n () => {\n allOpen.value = false\n opened.clear()\n },\n)\n\n/**\n * The bar over a run of hidden lines. Side by side, the original's bar\n * mirrors the modified one's: pressed with a pointer, but left out of the\n * keyboard order and of what is read out, so the run is one stop, not two.\n */\nfunction bar(run: Unchanged, mirror = false) {\n const label = format(messages.value.diffUnchanged, { count: run.hideCount })\n return h(\n 'button',\n {\n type: 'button',\n class: ns.e('bar'),\n 'aria-label': `${messages.value.unfold}:${label}`,\n 'aria-hidden': mirror ? 'true' : undefined,\n tabindex: mirror ? -1 : undefined,\n onClick: () => open(run.key),\n },\n [h(UnfoldVerticalIcon, { class: ns.e('bar-icon') }), h('span', label)],\n )\n}\nconst BAR_HEIGHT = 28\n\n// ---------------------------------------------------------------- side by side\n\ntype Side = 'a' | 'b'\n\n/** What one side of the split view draws: tints, marks, fillers, hidden lines and bars. */\nfunction sideExtension(side: Side): CodeExtension {\n const startOf = (hunk: CodeDiffHunk) => (side === 'a' ? hunk.originalStart : hunk.modifiedStart)\n const countOf = (hunk: CodeDiffHunk) => (side === 'a' ? hunk.originalCount : hunk.modifiedCount)\n const otherCountOf = (hunk: CodeDiffHunk) =>\n side === 'a' ? hunk.modifiedCount : hunk.originalCount\n const tone = side === 'a' ? 'removed' : 'added'\n\n return defineCodeExtension({\n name: 'diff',\n decorations({ visible }) {\n const out: CodeDecoration[] = []\n for (const hunk of hunks.value) {\n const start = startOf(hunk)\n const count = countOf(hunk)\n if (start > visible.to) break\n if (!count || start + count - 1 < visible.from) continue\n const from = Math.max(start, visible.from)\n const to = Math.min(start + count - 1, visible.to)\n for (let n = from; n <= to; n++)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-${tone}` })\n for (const part of hunk.parts) {\n const range = side === 'a' ? part.original : part.modified\n if (range.to > range.from)\n out.push({\n type: 'mark',\n from: range.from,\n to: range.to,\n class: `${ns.e('word')} is-${tone}`,\n })\n }\n }\n return out\n },\n gutters: [\n {\n name: 'diff',\n width: 16,\n markers({ visible }) {\n const out: CodeGutterMarker[] = []\n const title = side === 'a' ? messages.value.diffRemoved : messages.value.diffAdded\n for (const hunk of hunks.value) {\n const start = startOf(hunk)\n const count = countOf(hunk)\n if (start > visible.to) break\n for (let n = Math.max(start, visible.from); n < start + count && n <= visible.to; n++)\n out.push({\n line: n,\n text: side === 'a' ? '−' : '+',\n class: `${ns.e('sign')} is-${tone}`,\n title,\n })\n }\n return out\n },\n },\n ],\n widgets() {\n const out: CodeWidget[] = []\n hunks.value.forEach((hunk, i) => {\n const missing = otherCountOf(hunk) - countOf(hunk)\n if (missing <= 0) return\n const last = startOf(hunk) - 1 + countOf(hunk)\n out.push({\n id: `fill-${i}`,\n ...(last >= 1 ? { line: last } : { line: 1, position: 'above' as const }),\n height: missing * 20,\n render: () =>\n h('div', {\n class: ns.e('filler'),\n style: { height: `calc(${missing} * var(--dou-code-editor-line-height))` },\n }),\n })\n })\n const total = side === 'a' ? originalLines.value.length : modifiedLines.value.length\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = (side === 'a' ? run.a : run.b) + run.hideFrom\n const last = first + run.hideCount - 1\n out.push({\n id: `bar-${run.key}`,\n ...(last < total ? { line: last + 1, position: 'above' as const } : { line: first - 1 }),\n height: BAR_HEIGHT,\n render: () => bar(run, side === 'a'),\n })\n }\n return out\n },\n hide() {\n const out: Array<{ from: number; to: number }> = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = (side === 'a' ? run.a : run.b) + run.hideFrom\n out.push({ from: first, to: first + run.hideCount - 1 })\n }\n return out\n },\n })\n}\n\nconst modifiedOwn = sideExtension('b')\nconst modifiedExtensions = computed(() => [modifiedOwn, ...(props.extensions ?? [])])\n\nconst editorA = ref<CodeEditorExpose>()\nconst editorB = ref<CodeEditorExpose>()\nconst sideA = ref<HTMLElement>()\nconst sideB = ref<HTMLElement>()\nconst extensionsA = [sideExtension('a')]\n\n// Both sides scroll together; they are the same height, line for line.\nconst link = createScrollLink()\nfunction onScroll(event: Event) {\n if (view.value !== 'split') return\n const from = (event.target as HTMLElement).closest(`.${ns.e('side')}`)\n const source = from?.querySelector<HTMLElement>('.dou-code-editor__scroller')\n if (!source || source !== event.target) return\n const other = (from === sideA.value ? sideB.value : sideA.value)?.querySelector<HTMLElement>(\n '.dou-code-editor__scroller',\n )\n if (other) link.follow(source, other)\n}\n\n// ---------------------------------------------------------------- inline\n\nconst enum Kind {\n Same,\n Removed,\n Added,\n}\n\ninterface Unified {\n text: string\n kinds: Uint8Array\n /** Line numbers on each side, 0 where the line isn't there. */\n aNums: Int32Array\n bNums: Int32Array\n /** Where each change starts, from 1. */\n hunkLines: number[]\n /** Where each unchanged run starts, from 1, by key. */\n runLines: Map<number, number>\n marks: Array<{ from: number; to: number; kind: Kind }>\n}\n\nconst unified = computed<Unified | null>(() => {\n if (view.value !== 'inline') return null\n const a = originalLines.value\n const b = modifiedLines.value\n const lines: string[] = []\n const kinds: number[] = []\n const aNums: number[] = []\n const bNums: number[] = []\n const hunkLines: number[] = []\n const runLines = new Map<number, number>()\n const marks: Unified['marks'] = []\n let pos = 0\n const push = (text: string, kind: Kind, an: number, bn: number) => {\n lines.push(text)\n kinds.push(kind)\n aNums.push(an)\n bNums.push(bn)\n pos += text.length + 1\n }\n const runs = unchanged.value\n let r = 0\n const sameUpTo = (aEnd: number) => {\n while (r < runs.length && runs[r]!.a < aEnd) {\n const run = runs[r++]!\n runLines.set(run.key, lines.length + 1)\n for (let i = 0; i < run.count; i++) push(b[run.b - 1 + i]!, Kind.Same, run.a + i, run.b + i)\n }\n }\n // Where each original and modified line starts, for moving the word marks.\n const aStarts = lineStarts(a)\n const bStarts = lineStarts(b)\n for (const hunk of hunks.value) {\n sameUpTo(hunk.originalStart)\n hunkLines.push(lines.length + 1)\n const removedAt = pos\n for (let i = 0; i < hunk.originalCount; i++)\n push(a[hunk.originalStart - 1 + i]!, Kind.Removed, hunk.originalStart + i, 0)\n const addedAt = pos\n for (let i = 0; i < hunk.modifiedCount; i++)\n push(b[hunk.modifiedStart - 1 + i]!, Kind.Added, 0, hunk.modifiedStart + i)\n const aBase = aStarts[hunk.originalStart - 1]!\n const bBase = bStarts[hunk.modifiedStart - 1]!\n for (const part of hunk.parts) {\n if (part.original.to > part.original.from)\n marks.push({\n from: removedAt + part.original.from - aBase,\n to: removedAt + part.original.to - aBase,\n kind: Kind.Removed,\n })\n if (part.modified.to > part.modified.from)\n marks.push({\n from: addedAt + part.modified.from - bBase,\n to: addedAt + part.modified.to - bBase,\n kind: Kind.Added,\n })\n }\n }\n sameUpTo(Infinity)\n return {\n text: lines.join('\\n'),\n kinds: Uint8Array.from(kinds),\n aNums: Int32Array.from(aNums),\n bNums: Int32Array.from(bNums),\n hunkLines,\n runLines,\n marks,\n }\n})\n\nconst digits = (n: number) => String(Math.max(1, n)).length\nconst numberWidth = (n: number) => digits(n) * 8 + 16\n\n/** The line numbers of one side, in the inline view's gutter. */\nconst numbersOf =\n (pick: 'aNums' | 'bNums') =>\n ({ visible }: { visible: { from: number; to: number } }) => {\n const u = unified.value\n if (!u) return []\n const out: CodeGutterMarker[] = []\n const list = u[pick]\n for (let n = visible.from; n <= visible.to && n <= list.length; n++) {\n const value = list[n - 1]!\n const kind = u.kinds[n - 1]\n const tone = kind === Kind.Removed ? ' is-removed' : kind === Kind.Added ? ' is-added' : ''\n out.push({ line: n, text: value ? String(value) : '', class: `${ns.e('number')}${tone}` })\n }\n return out\n }\n\nconst inlineExtension = defineCodeExtension({\n name: 'diff',\n decorations({ visible }) {\n const u = unified.value\n if (!u) return []\n const out: CodeDecoration[] = []\n for (let n = visible.from; n <= visible.to && n <= u.kinds.length; n++) {\n const kind = u.kinds[n - 1]\n if (kind === Kind.Removed)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-removed` })\n else if (kind === Kind.Added)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-added` })\n }\n for (const mark of u.marks)\n out.push({\n type: 'mark',\n from: mark.from,\n to: mark.to,\n class: `${ns.e('word')} ${mark.kind === Kind.Removed ? 'is-removed' : 'is-added'}`,\n })\n return out\n },\n get gutters() {\n return [\n {\n name: 'diff-original',\n width: numberWidth(originalLines.value.length),\n markers: numbersOf('aNums'),\n },\n {\n name: 'diff-modified',\n width: numberWidth(modifiedLines.value.length),\n markers: numbersOf('bNums'),\n },\n {\n name: 'diff',\n width: 16,\n markers: ({ visible }: { visible: { from: number; to: number } }) => {\n const u = unified.value\n if (!u) return []\n const out: CodeGutterMarker[] = []\n for (let n = visible.from; n <= visible.to && n <= u.kinds.length; n++) {\n const kind = u.kinds[n - 1]\n if (kind === Kind.Removed)\n out.push({\n line: n,\n text: '−',\n class: `${ns.e('sign')} is-removed`,\n title: messages.value.diffRemoved,\n })\n else if (kind === Kind.Added)\n out.push({\n line: n,\n text: '+',\n class: `${ns.e('sign')} is-added`,\n title: messages.value.diffAdded,\n })\n }\n return out\n },\n },\n ]\n },\n widgets() {\n const u = unified.value\n if (!u) return []\n const total = u.kinds.length\n const out: CodeWidget[] = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = u.runLines.get(run.key)! + run.hideFrom\n const last = first + run.hideCount - 1\n out.push({\n id: `bar-${run.key}`,\n ...(last < total ? { line: last + 1, position: 'above' as const } : { line: first - 1 }),\n height: BAR_HEIGHT,\n render: () => bar(run),\n })\n }\n return out\n },\n hide() {\n const u = unified.value\n if (!u) return []\n const out: Array<{ from: number; to: number }> = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = u.runLines.get(run.key)! + run.hideFrom\n out.push({ from: first, to: first + run.hideCount - 1 })\n }\n return out\n },\n})\nconst inlineExtensions = [inlineExtension]\nconst editorInline = ref<CodeEditorExpose>()\nconst inlineBox = ref<HTMLElement>()\n\n// ---------------------------------------------------------------- hidden lines a cursor reaches\n\n/** Shows the run of hidden lines a cursor moved into, e.g. with search. */\nfunction revealAt(side: Side | 'inline', result: CodeTransactionResult) {\n if (!hiddenCount.value) return\n const { doc, selection } = result.state\n const u = unified.value\n for (const range of selection.ranges) {\n const line = doc.lineAt(range.head).number\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const start =\n side === 'inline' ? (u?.runLines.get(run.key) ?? 0) : side === 'a' ? run.a : run.b\n const first = start + run.hideFrom\n if (line >= first && line < first + run.hideCount) open(run.key)\n }\n }\n}\n\n// ---------------------------------------------------------------- going from change to change\n\nconst live = ref('')\nconst current = ref(-1)\n\nfunction target(): { editor: CodeEditorExpose; box: HTMLElement; side: Side | 'inline' } | null {\n if (view.value === 'inline')\n return editorInline.value && inlineBox.value\n ? { editor: editorInline.value, box: inlineBox.value, side: 'inline' }\n : null\n const inA = !!sideA.value?.contains(document.activeElement)\n const editor = inA ? editorA.value : editorB.value\n const box = inA ? sideA.value : sideB.value\n return editor && box ? { editor, box, side: inA ? 'a' : 'b' } : null\n}\n\nfunction lineOf(index: number, side: Side | 'inline') {\n const hunk = hunks.value[index]!\n if (side === 'inline') return unified.value?.hunkLines[index] ?? 1\n return side === 'a' ? hunk.originalStart : hunk.modifiedStart\n}\n\nfunction go(step: 1 | -1) {\n const list = hunks.value\n const t = target()\n if (!list.length || !t) return false\n const doc = t.editor.doc\n const at = doc.lineAt(t.editor.selection.ranges[t.editor.selection.main]!.head).number\n let index = -1\n if (step > 0) {\n index = list.findIndex((_, i) => lineOf(i, t.side) > at)\n if (index < 0) index = 0\n } else {\n for (let i = list.length - 1; i >= 0; i--)\n if (lineOf(i, t.side) < at) {\n index = i\n break\n }\n if (index < 0) index = list.length - 1\n }\n const line = Math.min(doc.lines, Math.max(1, lineOf(index, t.side)))\n t.editor.select(doc.line(line).from)\n current.value = index\n const hunk = list[index]!\n live.value = format(messages.value.diffChangeAt, {\n index: index + 1,\n count: list.length,\n line: hunk.modifiedStart,\n removed: hunk.originalCount,\n added: hunk.modifiedCount,\n })\n // The editor may grow with the page instead of scrolling: bring the cursor into the window too.\n nextTick(() => t.box.querySelector('textarea')?.scrollIntoView({ block: 'nearest' }))\n return true\n}\n\nconst keymap: CodeKeymap = {\n f7: () => go(1),\n 'shift+f7': () => go(-1),\n}\n\nfunction next() {\n return go(1)\n}\nfunction previous() {\n return go(-1)\n}\n\nconst summary = computed(() =>\n hunks.value.length ? format(messages.value.diffStats, stats.value) : messages.value.diffNoChanges,\n)\n\ndefineExpose({\n /** The changes found now. */\n get hunks() {\n return hunks.value\n },\n /** Moves to the next change; `false` when there is none. */\n next,\n /** Moves to the previous change. */\n previous,\n /** Shows every unchanged line. */\n expandAll: () => (allOpen.value = true),\n /** Hides the runs of unchanged lines again. */\n collapseAll: () => {\n allOpen.value = false\n opened.clear()\n },\n /** The editors drawn now: both sides, or the inline one as `modified`. */\n get original() {\n return view.value === 'split' ? editorA.value : undefined\n },\n get modified() {\n return view.value === 'split' ? editorB.value : editorInline.value\n },\n})\n</script>\n\n<template>\n <div ref=\"root\" :class=\"[ns.b(), ns.m(view)]\" role=\"group\" :aria-label=\"messages.diff\">\n <div v-if=\"toolbar\" :class=\"ns.e('toolbar')\">\n <span :class=\"ns.e('stats')\">\n <template v-if=\"hunks.length\">\n <span :class=\"[ns.e('count'), 'is-added']\" aria-hidden=\"true\">+{{ stats.added }}</span>\n <span :class=\"[ns.e('count'), 'is-removed']\" aria-hidden=\"true\"\n >−{{ stats.removed }}</span\n >\n <span :class=\"ns.e('hidden-text')\">{{ summary }}</span>\n </template>\n <span v-else :class=\"ns.e('summary')\">{{ summary }}</span>\n </span>\n <DouTooltip :content=\"messages.diffPrevious\" shortcut=\"shift+f7\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"!hunks.length\"\n :aria-label=\"messages.diffPrevious\"\n @click=\"previous\"\n >\n <ArrowUpIcon />\n </DouButton>\n </DouTooltip>\n <DouTooltip :content=\"messages.diffNext\" shortcut=\"f7\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"!hunks.length\"\n :aria-label=\"messages.diffNext\"\n @click=\"next\"\n >\n <ArrowDownIcon />\n </DouButton>\n </DouTooltip>\n <DouTooltip\n v-if=\"anyHideable\"\n :content=\"hiddenCount ? messages.diffExpandAll : messages.diffCollapse\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"hiddenCount ? messages.diffExpandAll : messages.diffCollapse\"\n @click=\"toggleAll\"\n >\n <UnfoldVerticalIcon v-if=\"hiddenCount\" />\n <FoldVerticalIcon v-else />\n </DouButton>\n </DouTooltip>\n <DouTooltip :content=\"view === 'split' ? messages.diffInline : messages.diffSplit\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"view === 'split' ? messages.diffInline : messages.diffSplit\"\n @click=\"toggleView\"\n >\n <DiffUnifiedIcon v-if=\"view === 'split'\" />\n <DiffSplitIcon v-else />\n </DouButton>\n </DouTooltip>\n </div>\n <div v-if=\"view === 'split'\" :class=\"ns.e('body')\" @scroll.capture=\"onScroll\">\n <div :class=\"ns.e('label')\">{{ messages.diffOriginal }}</div>\n <div :class=\"ns.e('label')\">{{ messages.diffModified }}</div>\n <div ref=\"sideA\" :class=\"[ns.e('side'), 'is-original']\">\n <CodeEditor\n ref=\"editorA\"\n :model-value=\"original\"\n :language=\"language\"\n :extensions=\"extensionsA\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diffOriginal\"\n :foldable=\"false\"\n :active-line=\"false\"\n readonly\n @transaction=\"revealAt('a', $event)\"\n />\n </div>\n <div ref=\"sideB\" :class=\"[ns.e('side'), 'is-modified']\">\n <CodeEditor\n ref=\"editorB\"\n :model-value=\"modified\"\n :language=\"language\"\n :extensions=\"modifiedExtensions\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diffModified\"\n :foldable=\"false\"\n :active-line=\"false\"\n :readonly=\"!editable\"\n @update:model-value=\"onModifiedInput\"\n @transaction=\"revealAt('b', $event)\"\n />\n </div>\n </div>\n <div v-else ref=\"inlineBox\" :class=\"ns.e('body')\">\n <CodeEditor\n ref=\"editorInline\"\n :model-value=\"unified?.text ?? ''\"\n :language=\"language\"\n :extensions=\"inlineExtensions\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diff\"\n :line-numbers=\"false\"\n :foldable=\"false\"\n :active-line=\"false\"\n :wrap=\"wrap\"\n readonly\n @transaction=\"revealAt('inline', $event)\"\n />\n </div>\n <div :class=\"ns.e('live')\" aria-live=\"polite\">{{ live }}</div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;AA4EA,IAAM,cAAc;AA+IpB,IAAM,aAAa;;AAkInB,IAAW,OAAX,yBAAA,MAAA;CACE,KAAA,KAAA,UAAA,KAAA;CACA,KAAA,KAAA,aAAA,KAAA;CACA,KAAA,KAAA,WAAA,KAAA;;AACF,EAJW,QAAA,CAAA,CAIX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAhUA,MAAM,QAAQ;EAed,MAAM,OAAO;EAEb,MAAM,KAAK,aAAa,WAAW;EACnC,MAAM,WAAW,sBAAsB,MAAM,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CAAE,CAAC,EAAC,MAAA,CAAA;I,IACtCI,YAeEI,qBAAA;KAdI,SAAA;KAAJ,KAAI;KACH,eAAa,QAAA,OAAS,QAAI;KAC1B,UAAU,QAAA;KACV,YAAY;KACZ,YAAU,QAAA;KACV,UAAUR,MAAA,QAAA;KACF;KACR,cAAYA,MAAA,QAAA,CAAQ,CAAC;KACrB,gBAAc;KACd,UAAU;KACV,eAAa;KACb,MAAM,QAAA;KACP,UAAA;KACC,eAAW,OAAA,OAAA,OAAA,MAAA,WAAE,SAAQ,UAAW,MAAM;;;;;;;;;IAG3CC,mBAA8D,OAAA;KAAxD,OAAKF,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,MAAA,CAAA;KAAU,aAAU;IAAY,GAAAG,gBAAA,KAAA,KAAI,GAAA,CAAA"}
1
+ {"version":3,"file":"code-diff.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_createElementVNode","_Fragment","_toDisplayString","_createVNode","_withCtx","_createBlock","_createCommentVNode","CodeEditor"],"sources":["../src/code-diff.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ArrowDownIcon,\n ArrowUpIcon,\n DiffSplitIcon,\n DiffUnifiedIcon,\n FoldVerticalIcon,\n UnfoldVerticalIcon,\n} from '@dou-ui/icons'\nimport { DouButton, DouTooltip, createScrollLink, useNamespace } from 'dou-ui'\nimport { computed, h, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'\nimport CodeEditor from './code-editor.vue'\nimport { type CodeDiffHunk, diffText, lineStarts } from './core/diff'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeTransactionResult } from './core/transaction'\nimport { splitLines } from './core/text'\nimport {\n type CodeDecoration,\n type CodeExtension,\n type CodeGutterMarker,\n type CodeWidget,\n defineCodeExtension,\n} from './extension'\nimport { format, useCodeMessages } from './locale'\nimport type { CodeDiffEmits, CodeDiffProps, CodeEditorExpose } from './types'\n\n/**\n * Two texts compared: side by side, or the changes in one column. Changed\n * lines are tinted, the words that changed inside them marked, and long\n * runs of unchanged lines hidden behind a bar that shows them.\n */\ndefineOptions({ name: 'DouCodeDiff' })\n\nconst props = withDefaults(defineProps<CodeDiffProps>(), {\n original: '',\n modelValue: '',\n language: undefined,\n mode: 'auto',\n editable: false,\n collapseUnchanged: true,\n ignoreWhitespace: false,\n words: true,\n wrap: false,\n extensions: undefined,\n tabSize: 2,\n toolbar: true,\n bordered: true,\n messages: undefined,\n})\nconst emit = defineEmits<CodeDiffEmits>()\n\nconst ns = useNamespace('code-diff')\nconst messages = useCodeMessages(() => props.messages)\n\n// ---------------------------------------------------------------- view\n\nconst root = ref<HTMLElement>()\n/** Whether the box is wide enough for two columns. */\nconst roomy = ref(true)\n/** The view picked with the toggle, when `mode` isn't bound. */\nconst picked = ref<'split' | 'inline' | null>(null)\nwatch(\n () => props.mode,\n () => (picked.value = null),\n)\nconst view = computed<'split' | 'inline'>(() => {\n if (picked.value) return picked.value\n if (props.mode !== 'auto') return props.mode\n return roomy.value ? 'split' : 'inline'\n})\nfunction toggleView() {\n const other = view.value === 'split' ? 'inline' : 'split'\n picked.value = other\n emit('update:mode', other)\n}\n\n/** Below this, each side would show fewer than about 30 columns: one column reads better. */\nconst SPLIT_WIDTH = 560\n\nlet resize: ResizeObserver | undefined\nonMounted(() => {\n if (typeof ResizeObserver === 'undefined' || !root.value) return\n resize = new ResizeObserver(([entry]) => {\n if (entry) roomy.value = entry.contentRect.width >= SPLIT_WIDTH\n })\n resize.observe(root.value)\n})\nonBeforeUnmount(() => resize?.disconnect())\n\n// ---------------------------------------------------------------- texts and changes\n\n/** The modified text as edited here, ahead of the parent's copy. */\nconst modified = ref(props.modelValue)\nwatch(\n () => props.modelValue,\n (value) => (modified.value = value),\n)\nfunction onModifiedInput(value: string) {\n modified.value = value\n emit('update:modelValue', value)\n}\n\nconst hunks = computed<CodeDiffHunk[]>(() =>\n diffText(props.original, modified.value, {\n ignoreWhitespace: props.ignoreWhitespace,\n words: props.words,\n }),\n)\nconst originalLines = computed(() => splitLines(props.original))\nconst modifiedLines = computed(() => splitLines(modified.value))\n\nconst stats = computed(() => {\n let added = 0\n let removed = 0\n for (const hunk of hunks.value) {\n added += hunk.modifiedCount\n removed += hunk.originalCount\n }\n return { added, removed }\n})\n\n// ---------------------------------------------------------------- unchanged lines\n\ninterface Unchanged {\n /** First line on each side, from 1. */\n a: number\n b: number\n count: number\n /** Where its hidden part starts, from its first line, and how long it is (0 when nothing is hidden). */\n hideFrom: number\n hideCount: number\n /** Stays the same while the modified text is edited. */\n key: number\n}\n\nconst collapse = computed(() => {\n const option = props.collapseUnchanged\n if (!option) return null\n const own = option === true ? {} : option\n return {\n context: Math.max(1, Math.floor(own.context ?? 3)),\n minLines: Math.max(1, Math.floor(own.minLines ?? 4)),\n }\n})\n/** The runs of unchanged lines opened with their bar, by key; `true` for all of them. */\nconst opened = reactive(new Set<number>())\nconst allOpen = ref(false)\n\nconst unchanged = computed<Unchanged[]>(() => {\n const list = hunks.value\n const total = originalLines.value.length\n const out: Unchanged[] = []\n const rule = collapse.value\n const push = (a: number, b: number, count: number, before: boolean, after: boolean) => {\n if (count <= 0) return\n let hideFrom = 0\n let hideCount = 0\n if (rule && list.length && !allOpen.value && !opened.has(a)) {\n const from = before ? rule.context : 0\n const to = count - (after ? rule.context : 0)\n if (to - from >= rule.minLines) {\n hideFrom = from\n hideCount = to - from\n }\n }\n out.push({ a, b, count, hideFrom, hideCount, key: a })\n }\n let a = 1\n let b = 1\n for (let i = 0; i < list.length; i++) {\n const hunk = list[i]!\n push(a, b, hunk.originalStart - a, i > 0, true)\n a = hunk.originalStart + hunk.originalCount\n b = hunk.modifiedStart + hunk.modifiedCount\n }\n push(a, b, total - a + 1, list.length > 0, false)\n return out\n})\nconst hiddenCount = computed(() => unchanged.value.reduce((sum, run) => sum + run.hideCount, 0))\nconst anyHideable = computed(() => !!collapse.value && hunks.value.length > 0)\n\nfunction open(key: number) {\n opened.add(key)\n}\nfunction toggleAll() {\n if (hiddenCount.value) allOpen.value = true\n else {\n allOpen.value = false\n opened.clear()\n }\n}\n// A new pair of texts starts collapsed again.\nwatch(\n () => props.original,\n () => {\n allOpen.value = false\n opened.clear()\n },\n)\n\n/**\n * The bar over a run of hidden lines. Side by side, the original's bar\n * mirrors the modified one's: pressed with a pointer, but left out of the\n * keyboard order and of what is read out, so the run is one stop, not two.\n */\nfunction bar(run: Unchanged, mirror = false) {\n const label = format(messages.value.diffUnchanged, { count: run.hideCount })\n return h(\n 'button',\n {\n type: 'button',\n class: ns.e('bar'),\n 'aria-label': `${messages.value.unfold}:${label}`,\n 'aria-hidden': mirror ? 'true' : undefined,\n tabindex: mirror ? -1 : undefined,\n onClick: () => open(run.key),\n },\n [h(UnfoldVerticalIcon, { class: ns.e('bar-icon') }), h('span', label)],\n )\n}\nconst BAR_HEIGHT = 28\n\n// ---------------------------------------------------------------- side by side\n\ntype Side = 'a' | 'b'\n\n/** What one side of the split view draws: tints, marks, fillers, hidden lines and bars. */\nfunction sideExtension(side: Side): CodeExtension {\n const startOf = (hunk: CodeDiffHunk) => (side === 'a' ? hunk.originalStart : hunk.modifiedStart)\n const countOf = (hunk: CodeDiffHunk) => (side === 'a' ? hunk.originalCount : hunk.modifiedCount)\n const otherCountOf = (hunk: CodeDiffHunk) =>\n side === 'a' ? hunk.modifiedCount : hunk.originalCount\n const tone = side === 'a' ? 'removed' : 'added'\n\n return defineCodeExtension({\n name: 'diff',\n decorations({ visible }) {\n const out: CodeDecoration[] = []\n for (const hunk of hunks.value) {\n const start = startOf(hunk)\n const count = countOf(hunk)\n if (start > visible.to) break\n if (!count || start + count - 1 < visible.from) continue\n const from = Math.max(start, visible.from)\n const to = Math.min(start + count - 1, visible.to)\n for (let n = from; n <= to; n++)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-${tone}` })\n for (const part of hunk.parts) {\n const range = side === 'a' ? part.original : part.modified\n if (range.to > range.from)\n out.push({\n type: 'mark',\n from: range.from,\n to: range.to,\n class: `${ns.e('word')} is-${tone}`,\n })\n }\n }\n return out\n },\n gutters: [\n {\n name: 'diff',\n width: 16,\n markers({ visible }) {\n const out: CodeGutterMarker[] = []\n const title = side === 'a' ? messages.value.diffRemoved : messages.value.diffAdded\n for (const hunk of hunks.value) {\n const start = startOf(hunk)\n const count = countOf(hunk)\n if (start > visible.to) break\n for (let n = Math.max(start, visible.from); n < start + count && n <= visible.to; n++)\n out.push({\n line: n,\n text: side === 'a' ? '−' : '+',\n class: `${ns.e('sign')} is-${tone}`,\n title,\n })\n }\n return out\n },\n },\n ],\n widgets() {\n const out: CodeWidget[] = []\n hunks.value.forEach((hunk, i) => {\n const missing = otherCountOf(hunk) - countOf(hunk)\n if (missing <= 0) return\n const last = startOf(hunk) - 1 + countOf(hunk)\n out.push({\n id: `fill-${i}`,\n ...(last >= 1 ? { line: last } : { line: 1, position: 'above' as const }),\n height: missing * 20,\n render: () =>\n h('div', {\n class: ns.e('filler'),\n style: { height: `calc(${missing} * var(--dou-code-editor-line-height))` },\n }),\n })\n })\n const total = side === 'a' ? originalLines.value.length : modifiedLines.value.length\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = (side === 'a' ? run.a : run.b) + run.hideFrom\n const last = first + run.hideCount - 1\n out.push({\n id: `bar-${run.key}`,\n ...(last < total ? { line: last + 1, position: 'above' as const } : { line: first - 1 }),\n height: BAR_HEIGHT,\n render: () => bar(run, side === 'a'),\n })\n }\n return out\n },\n hide() {\n const out: Array<{ from: number; to: number }> = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = (side === 'a' ? run.a : run.b) + run.hideFrom\n out.push({ from: first, to: first + run.hideCount - 1 })\n }\n return out\n },\n })\n}\n\nconst modifiedOwn = sideExtension('b')\nconst modifiedExtensions = computed(() => [modifiedOwn, ...(props.extensions ?? [])])\n\nconst editorA = ref<CodeEditorExpose>()\nconst editorB = ref<CodeEditorExpose>()\nconst sideA = ref<HTMLElement>()\nconst sideB = ref<HTMLElement>()\nconst extensionsA = [sideExtension('a')]\n\n// Both sides scroll together; they are the same height, line for line.\nconst link = createScrollLink()\nfunction onScroll(event: Event) {\n if (view.value !== 'split') return\n const from = (event.target as HTMLElement).closest(`.${ns.e('side')}`)\n const source = from?.querySelector<HTMLElement>('.dou-code-editor__scroller')\n if (!source || source !== event.target) return\n const other = (from === sideA.value ? sideB.value : sideA.value)?.querySelector<HTMLElement>(\n '.dou-code-editor__scroller',\n )\n if (other) link.follow(source, other)\n}\n\n// ---------------------------------------------------------------- inline\n\nconst enum Kind {\n Same,\n Removed,\n Added,\n}\n\ninterface Unified {\n text: string\n kinds: Uint8Array\n /** Line numbers on each side, 0 where the line isn't there. */\n aNums: Int32Array\n bNums: Int32Array\n /** Where each change starts, from 1. */\n hunkLines: number[]\n /** Where each unchanged run starts, from 1, by key. */\n runLines: Map<number, number>\n marks: Array<{ from: number; to: number; kind: Kind }>\n}\n\nconst unified = computed<Unified | null>(() => {\n if (view.value !== 'inline') return null\n const a = originalLines.value\n const b = modifiedLines.value\n const lines: string[] = []\n const kinds: number[] = []\n const aNums: number[] = []\n const bNums: number[] = []\n const hunkLines: number[] = []\n const runLines = new Map<number, number>()\n const marks: Unified['marks'] = []\n let pos = 0\n const push = (text: string, kind: Kind, an: number, bn: number) => {\n lines.push(text)\n kinds.push(kind)\n aNums.push(an)\n bNums.push(bn)\n pos += text.length + 1\n }\n const runs = unchanged.value\n let r = 0\n const sameUpTo = (aEnd: number) => {\n while (r < runs.length && runs[r]!.a < aEnd) {\n const run = runs[r++]!\n runLines.set(run.key, lines.length + 1)\n for (let i = 0; i < run.count; i++) push(b[run.b - 1 + i]!, Kind.Same, run.a + i, run.b + i)\n }\n }\n // Where each original and modified line starts, for moving the word marks.\n const aStarts = lineStarts(a)\n const bStarts = lineStarts(b)\n for (const hunk of hunks.value) {\n sameUpTo(hunk.originalStart)\n hunkLines.push(lines.length + 1)\n const removedAt = pos\n for (let i = 0; i < hunk.originalCount; i++)\n push(a[hunk.originalStart - 1 + i]!, Kind.Removed, hunk.originalStart + i, 0)\n const addedAt = pos\n for (let i = 0; i < hunk.modifiedCount; i++)\n push(b[hunk.modifiedStart - 1 + i]!, Kind.Added, 0, hunk.modifiedStart + i)\n const aBase = aStarts[hunk.originalStart - 1]!\n const bBase = bStarts[hunk.modifiedStart - 1]!\n for (const part of hunk.parts) {\n if (part.original.to > part.original.from)\n marks.push({\n from: removedAt + part.original.from - aBase,\n to: removedAt + part.original.to - aBase,\n kind: Kind.Removed,\n })\n if (part.modified.to > part.modified.from)\n marks.push({\n from: addedAt + part.modified.from - bBase,\n to: addedAt + part.modified.to - bBase,\n kind: Kind.Added,\n })\n }\n }\n sameUpTo(Infinity)\n return {\n text: lines.join('\\n'),\n kinds: Uint8Array.from(kinds),\n aNums: Int32Array.from(aNums),\n bNums: Int32Array.from(bNums),\n hunkLines,\n runLines,\n marks,\n }\n})\n\nconst digits = (n: number) => String(Math.max(1, n)).length\nconst numberWidth = (n: number) => digits(n) * 8 + 16\n\n/** The line numbers of one side, in the inline view's gutter. */\nconst numbersOf =\n (pick: 'aNums' | 'bNums') =>\n ({ visible }: { visible: { from: number; to: number } }) => {\n const u = unified.value\n if (!u) return []\n const out: CodeGutterMarker[] = []\n const list = u[pick]\n for (let n = visible.from; n <= visible.to && n <= list.length; n++) {\n const value = list[n - 1]!\n const kind = u.kinds[n - 1]\n const tone = kind === Kind.Removed ? ' is-removed' : kind === Kind.Added ? ' is-added' : ''\n out.push({ line: n, text: value ? String(value) : '', class: `${ns.e('number')}${tone}` })\n }\n return out\n }\n\nconst inlineExtension = defineCodeExtension({\n name: 'diff',\n decorations({ visible }) {\n const u = unified.value\n if (!u) return []\n const out: CodeDecoration[] = []\n for (let n = visible.from; n <= visible.to && n <= u.kinds.length; n++) {\n const kind = u.kinds[n - 1]\n if (kind === Kind.Removed)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-removed` })\n else if (kind === Kind.Added)\n out.push({ type: 'line', line: n, class: `${ns.e('line')} is-added` })\n }\n for (const mark of u.marks)\n out.push({\n type: 'mark',\n from: mark.from,\n to: mark.to,\n class: `${ns.e('word')} ${mark.kind === Kind.Removed ? 'is-removed' : 'is-added'}`,\n })\n return out\n },\n get gutters() {\n return [\n {\n name: 'diff-original',\n width: numberWidth(originalLines.value.length),\n markers: numbersOf('aNums'),\n },\n {\n name: 'diff-modified',\n width: numberWidth(modifiedLines.value.length),\n markers: numbersOf('bNums'),\n },\n {\n name: 'diff',\n width: 16,\n markers: ({ visible }: { visible: { from: number; to: number } }) => {\n const u = unified.value\n if (!u) return []\n const out: CodeGutterMarker[] = []\n for (let n = visible.from; n <= visible.to && n <= u.kinds.length; n++) {\n const kind = u.kinds[n - 1]\n if (kind === Kind.Removed)\n out.push({\n line: n,\n text: '−',\n class: `${ns.e('sign')} is-removed`,\n title: messages.value.diffRemoved,\n })\n else if (kind === Kind.Added)\n out.push({\n line: n,\n text: '+',\n class: `${ns.e('sign')} is-added`,\n title: messages.value.diffAdded,\n })\n }\n return out\n },\n },\n ]\n },\n widgets() {\n const u = unified.value\n if (!u) return []\n const total = u.kinds.length\n const out: CodeWidget[] = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = u.runLines.get(run.key)! + run.hideFrom\n const last = first + run.hideCount - 1\n out.push({\n id: `bar-${run.key}`,\n ...(last < total ? { line: last + 1, position: 'above' as const } : { line: first - 1 }),\n height: BAR_HEIGHT,\n render: () => bar(run),\n })\n }\n return out\n },\n hide() {\n const u = unified.value\n if (!u) return []\n const out: Array<{ from: number; to: number }> = []\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const first = u.runLines.get(run.key)! + run.hideFrom\n out.push({ from: first, to: first + run.hideCount - 1 })\n }\n return out\n },\n})\nconst inlineExtensions = [inlineExtension]\nconst editorInline = ref<CodeEditorExpose>()\nconst inlineBox = ref<HTMLElement>()\n\n// ---------------------------------------------------------------- hidden lines a cursor reaches\n\n/** Shows the run of hidden lines a cursor moved into, e.g. with search. */\nfunction revealAt(side: Side | 'inline', result: CodeTransactionResult) {\n if (!hiddenCount.value) return\n const { doc, selection } = result.state\n const u = unified.value\n for (const range of selection.ranges) {\n const line = doc.lineAt(range.head).number\n for (const run of unchanged.value) {\n if (!run.hideCount) continue\n const start =\n side === 'inline' ? (u?.runLines.get(run.key) ?? 0) : side === 'a' ? run.a : run.b\n const first = start + run.hideFrom\n if (line >= first && line < first + run.hideCount) open(run.key)\n }\n }\n}\n\n// ---------------------------------------------------------------- going from change to change\n\nconst live = ref('')\nconst current = ref(-1)\n\nfunction target(): { editor: CodeEditorExpose; box: HTMLElement; side: Side | 'inline' } | null {\n if (view.value === 'inline')\n return editorInline.value && inlineBox.value\n ? { editor: editorInline.value, box: inlineBox.value, side: 'inline' }\n : null\n const inA = !!sideA.value?.contains(document.activeElement)\n const editor = inA ? editorA.value : editorB.value\n const box = inA ? sideA.value : sideB.value\n return editor && box ? { editor, box, side: inA ? 'a' : 'b' } : null\n}\n\nfunction lineOf(index: number, side: Side | 'inline') {\n const hunk = hunks.value[index]!\n if (side === 'inline') return unified.value?.hunkLines[index] ?? 1\n return side === 'a' ? hunk.originalStart : hunk.modifiedStart\n}\n\nfunction go(step: 1 | -1) {\n const list = hunks.value\n const t = target()\n if (!list.length || !t) return false\n const doc = t.editor.doc\n const at = doc.lineAt(t.editor.selection.ranges[t.editor.selection.main]!.head).number\n let index = -1\n if (step > 0) {\n index = list.findIndex((_, i) => lineOf(i, t.side) > at)\n if (index < 0) index = 0\n } else {\n for (let i = list.length - 1; i >= 0; i--)\n if (lineOf(i, t.side) < at) {\n index = i\n break\n }\n if (index < 0) index = list.length - 1\n }\n const line = Math.min(doc.lines, Math.max(1, lineOf(index, t.side)))\n t.editor.select(doc.line(line).from)\n current.value = index\n const hunk = list[index]!\n live.value = format(messages.value.diffChangeAt, {\n index: index + 1,\n count: list.length,\n line: hunk.modifiedStart,\n removed: hunk.originalCount,\n added: hunk.modifiedCount,\n })\n // The editor may grow with the page instead of scrolling: bring the cursor into the window too.\n nextTick(() => t.box.querySelector('textarea')?.scrollIntoView({ block: 'nearest' }))\n return true\n}\n\nconst keymap: CodeKeymap = {\n f7: () => go(1),\n 'shift+f7': () => go(-1),\n}\n\nfunction next() {\n return go(1)\n}\nfunction previous() {\n return go(-1)\n}\n\nconst summary = computed(() =>\n hunks.value.length ? format(messages.value.diffStats, stats.value) : messages.value.diffNoChanges,\n)\n\ndefineExpose({\n /** The changes found now. */\n get hunks() {\n return hunks.value\n },\n /** Moves to the next change; `false` when there is none. */\n next,\n /** Moves to the previous change. */\n previous,\n /** Shows every unchanged line. */\n expandAll: () => (allOpen.value = true),\n /** Hides the runs of unchanged lines again. */\n collapseAll: () => {\n allOpen.value = false\n opened.clear()\n },\n /** The editors drawn now: both sides, or the inline one as `modified`. */\n get original() {\n return view.value === 'split' ? editorA.value : undefined\n },\n get modified() {\n return view.value === 'split' ? editorB.value : editorInline.value\n },\n})\n</script>\n\n<template>\n <div\n ref=\"root\"\n :class=\"[ns.b(), ns.m(view), ns.is('bordered', bordered)]\"\n role=\"group\"\n :aria-label=\"messages.diff\"\n >\n <div v-if=\"toolbar\" :class=\"ns.e('toolbar')\">\n <span :class=\"ns.e('stats')\">\n <template v-if=\"hunks.length\">\n <span :class=\"[ns.e('count'), 'is-added']\" aria-hidden=\"true\">+{{ stats.added }}</span>\n <span :class=\"[ns.e('count'), 'is-removed']\" aria-hidden=\"true\"\n >−{{ stats.removed }}</span\n >\n <span :class=\"ns.e('hidden-text')\">{{ summary }}</span>\n </template>\n <span v-else :class=\"ns.e('summary')\">{{ summary }}</span>\n </span>\n <DouTooltip :content=\"messages.diffPrevious\" shortcut=\"shift+f7\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"!hunks.length\"\n :aria-label=\"messages.diffPrevious\"\n @click=\"previous\"\n >\n <ArrowUpIcon />\n </DouButton>\n </DouTooltip>\n <DouTooltip :content=\"messages.diffNext\" shortcut=\"f7\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :disabled=\"!hunks.length\"\n :aria-label=\"messages.diffNext\"\n @click=\"next\"\n >\n <ArrowDownIcon />\n </DouButton>\n </DouTooltip>\n <DouTooltip\n v-if=\"anyHideable\"\n :content=\"hiddenCount ? messages.diffExpandAll : messages.diffCollapse\"\n >\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"hiddenCount ? messages.diffExpandAll : messages.diffCollapse\"\n @click=\"toggleAll\"\n >\n <UnfoldVerticalIcon v-if=\"hiddenCount\" />\n <FoldVerticalIcon v-else />\n </DouButton>\n </DouTooltip>\n <DouTooltip :content=\"view === 'split' ? messages.diffInline : messages.diffSplit\">\n <DouButton\n variant=\"ghost\"\n size=\"sm\"\n :aria-label=\"view === 'split' ? messages.diffInline : messages.diffSplit\"\n @click=\"toggleView\"\n >\n <DiffUnifiedIcon v-if=\"view === 'split'\" />\n <DiffSplitIcon v-else />\n </DouButton>\n </DouTooltip>\n </div>\n <div v-if=\"view === 'split'\" :class=\"ns.e('body')\" @scroll.capture=\"onScroll\">\n <div :class=\"ns.e('label')\">{{ messages.diffOriginal }}</div>\n <div :class=\"ns.e('label')\">{{ messages.diffModified }}</div>\n <div ref=\"sideA\" :class=\"[ns.e('side'), 'is-original']\">\n <CodeEditor\n ref=\"editorA\"\n :model-value=\"original\"\n :language=\"language\"\n :extensions=\"extensionsA\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diffOriginal\"\n :foldable=\"false\"\n :active-line=\"false\"\n :bordered=\"false\"\n readonly\n @transaction=\"revealAt('a', $event)\"\n />\n </div>\n <div ref=\"sideB\" :class=\"[ns.e('side'), 'is-modified']\">\n <CodeEditor\n ref=\"editorB\"\n :model-value=\"modified\"\n :language=\"language\"\n :extensions=\"modifiedExtensions\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diffModified\"\n :foldable=\"false\"\n :active-line=\"false\"\n :bordered=\"false\"\n :readonly=\"!editable\"\n @update:model-value=\"onModifiedInput\"\n @transaction=\"revealAt('b', $event)\"\n />\n </div>\n </div>\n <div v-else ref=\"inlineBox\" :class=\"ns.e('body')\">\n <CodeEditor\n ref=\"editorInline\"\n :model-value=\"unified?.text ?? ''\"\n :language=\"language\"\n :extensions=\"inlineExtensions\"\n :tab-size=\"tabSize\"\n :messages=\"messages\"\n :keymap=\"keymap\"\n :aria-label=\"messages.diff\"\n :line-numbers=\"false\"\n :foldable=\"false\"\n :active-line=\"false\"\n :bordered=\"false\"\n :wrap=\"wrap\"\n readonly\n @transaction=\"revealAt('inline', $event)\"\n />\n </div>\n <div :class=\"ns.e('live')\" aria-live=\"polite\">{{ live }}</div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;AA6EA,IAAM,cAAc;AA+IpB,IAAM,aAAa;;AAkInB,IAAW,OAAX,yBAAA,MAAA;CACE,KAAA,KAAA,UAAA,KAAA;CACA,KAAA,KAAA,aAAA,KAAA;CACA,KAAA,KAAA,WAAA,KAAA;;AACF,EAJW,QAAA,CAAA,CAIX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAjUA,MAAM,QAAQ;EAgBd,MAAM,OAAO;EAEb,MAAM,KAAK,aAAa,WAAW;EACnC,MAAM,WAAW,sBAAsB,MAAM,QAAQ;EAIrD,MAAM,OAAO,IAAiB;;EAE9B,MAAM,QAAQ,IAAI,IAAI;;EAEtB,MAAM,SAAS,IAA+B,IAAI;EAClD,YACQ,MAAM,YACL,OAAO,QAAQ,IACxB;EACA,MAAM,OAAO,eAAmC;GAC9C,IAAI,OAAO,OAAO,OAAO,OAAO;GAChC,IAAI,MAAM,SAAS,QAAQ,OAAO,MAAM;GACxC,OAAO,MAAM,QAAQ,UAAU;EACjC,CAAC;EACD,SAAS,aAAa;GACpB,MAAM,QAAQ,KAAK,UAAU,UAAU,WAAW;GAClD,OAAO,QAAQ;GACf,KAAK,eAAe,KAAK;EAC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