|
1 | 1 | <script lang="ts"> |
2 | | - import { getI18nContext } from '@svelteness/kit-docs'; |
| 2 | + import { getI18nContext } from '@svelteness/kit-docs' |
3 | 3 | // import MCFunctionTML from '../mcfunction.tmLanguage.json'; |
4 | 4 |
|
5 | | - import clsx from 'clsx'; |
| 5 | + import clsx from 'clsx' |
6 | 6 |
|
7 | | - import CopyFileIcon from '~icons/ri/file-copy-line'; |
| 7 | + import CopyFileIcon from '~icons/ri/file-copy-line' |
8 | 8 |
|
9 | | - export let lang: string | null = null; |
10 | | - export let ext: string | null = null; |
11 | | - export let code: string | null = null; |
12 | | - export let rawCode: string | null = null; |
13 | | - export let title: string | null = null; |
14 | | - export let linesCount: number = (code?.match(/"line"/g) || []).length; |
15 | | - export let showLineNumbers = false; |
16 | | - export let highlightLines: [number, number][] = []; |
17 | | - export let copyHighlightOnly = false; |
18 | | - export let copySteps = false; |
19 | | - export let showCopyCode = copySteps || copyHighlightOnly; |
| 9 | + export let lang: string | null = null |
| 10 | + export let ext: string | null = null |
| 11 | + export let code: string | null = null |
| 12 | + export let rawCode: string | null = null |
| 13 | + export let title: string | null = null |
| 14 | + export let linesCount: number = (code?.match(/"line"/g) || []).length |
| 15 | + export let showLineNumbers = false |
| 16 | + export let highlightLines: [number, number][] = [] |
| 17 | + export let copyHighlightOnly = false |
| 18 | + export let copySteps = false |
| 19 | + export let showCopyCode = copySteps || copyHighlightOnly |
20 | 20 |
|
21 | | - const i18n = getI18nContext(); |
| 21 | + const i18n = getI18nContext() |
22 | 22 |
|
23 | | - let currentStep = 1; |
24 | | - let stepHighlightLines: [number, number][] = []; |
| 23 | + let currentStep = 1 |
| 24 | + let stepHighlightLines: [number, number][] = [] |
25 | 25 |
|
26 | 26 | $: if (copySteps) { |
27 | | - stepHighlightLines = [highlightLines[currentStep - 1] ?? [currentStep, currentStep]]; |
| 27 | + stepHighlightLines = [highlightLines[currentStep - 1] ?? [currentStep, currentStep]] |
28 | 28 | } |
29 | 29 |
|
30 | | - $: currentHighlightedLines = copySteps ? stepHighlightLines : highlightLines; |
| 30 | + $: currentHighlightedLines = copySteps ? stepHighlightLines : highlightLines |
31 | 31 |
|
32 | 32 | const isHighlightLine = (lineNumber: number, _?: any): boolean => |
33 | | - currentHighlightedLines.some(([start, end]) => lineNumber >= start && lineNumber <= end); |
| 33 | + currentHighlightedLines.some(([start, end]) => lineNumber >= start && lineNumber <= end) |
34 | 34 |
|
35 | 35 | // `linesCount-1` since last line is always empty (prettier) |
36 | | - $: lines = [...Array(linesCount - 1).keys()].map((n) => n + 1); |
| 36 | + $: lines = [...Array(linesCount - 1).keys()].map((n) => n + 1) |
37 | 37 |
|
38 | | - $: unescapedRawCode = rawCode?.replace(/​/g, ''); |
| 38 | + $: unescapedRawCode = rawCode?.replace(/​/g, '') |
39 | 39 |
|
40 | | - let showCopiedCodePrompt = false; |
| 40 | + let showCopiedCodePrompt = false |
41 | 41 | async function copyCodeToClipboard() { |
42 | 42 | try { |
43 | 43 | const copiedCode = |
|
46 | 46 | ?.split('\n') |
47 | 47 | .filter((_, i) => isHighlightLine(i + 1)) |
48 | 48 | .join('\n') |
49 | | - : unescapedRawCode; |
| 49 | + : unescapedRawCode |
50 | 50 |
|
51 | | - await navigator.clipboard.writeText(copiedCode || ''); |
| 51 | + await navigator.clipboard.writeText(copiedCode || '') |
52 | 52 | } catch (e) { |
53 | 53 | // no-op |
54 | 54 | } |
55 | 55 |
|
56 | | - showCopiedCodePrompt = true; |
| 56 | + showCopiedCodePrompt = true |
57 | 57 | if (copySteps) { |
58 | | - const nextStep = currentStep + 1; |
59 | | - const maxSteps = highlightLines.length > 0 ? highlightLines.length : lines.length; |
60 | | - currentStep = nextStep > maxSteps ? 1 : nextStep; |
| 58 | + const nextStep = currentStep + 1 |
| 59 | + const maxSteps = highlightLines.length > 0 ? highlightLines.length : lines.length |
| 60 | + currentStep = nextStep > maxSteps ? 1 : nextStep |
61 | 61 | } |
62 | 62 | } |
63 | 63 |
|
64 | 64 | $: if (showCopiedCodePrompt) { |
65 | 65 | setTimeout(() => { |
66 | | - showCopiedCodePrompt = false; |
67 | | - }, 400); |
| 66 | + showCopiedCodePrompt = false |
| 67 | + }, 400) |
68 | 68 | } |
69 | 69 |
|
70 | | - $: showTopBar = title || showCopyCode; |
71 | | - $: hasTopbarTitle = title || ext; |
72 | | - $: topbarTitle = title ?? (ext === 'sh' ? 'terminal' : ext); |
| 70 | + $: showTopBar = title || showCopyCode |
| 71 | + $: hasTopbarTitle = title || ext |
| 72 | + $: topbarTitle = title ?? (ext === 'sh' ? 'terminal' : ext) |
73 | 73 | </script> |
74 | 74 |
|
75 | 75 | <div |
|
0 commit comments