|
| 1 | +<script setup> |
| 2 | +/** Vendor */ |
| 3 | +import { DateTime } from "luxon" |
| 4 | +
|
| 5 | +const props = defineProps({ |
| 6 | + bytes: { |
| 7 | + type: Array, |
| 8 | + }, |
| 9 | + range: { |
| 10 | + type: Object, |
| 11 | + }, |
| 12 | +}) |
| 13 | +
|
| 14 | +const hexToUint8Array = (hex) => { |
| 15 | + const arr = [] |
| 16 | + for (let i = 0; i < hex.length; i += 2) { |
| 17 | + arr.push(parseInt(hex.substr(i, 2), 16)) |
| 18 | + } |
| 19 | + return new Uint8Array(arr) |
| 20 | +} |
| 21 | +
|
| 22 | +const isASCII = (str) => { |
| 23 | + return /^[\x00-\x7F]*$/.test(str) |
| 24 | +} |
| 25 | +</script> |
| 26 | + |
| 27 | +<template> |
| 28 | + <Flex direction="column" gap="16" :class="$style.wrapper"> |
| 29 | + <Flex align="center" justify="between" :class="$style.header"> |
| 30 | + <Text size="13" weight="600" color="primary">Data Inspector</Text> |
| 31 | + </Flex> |
| 32 | + |
| 33 | + <Flex direction="column" gap="8" :class="$style.content"> |
| 34 | + <Flex direction="column" gap="8" :class="$style.field"> |
| 35 | + <Flex align="center" justify="between"> |
| 36 | + <Text size="12" weight="600" color="secondary">Binary</Text> |
| 37 | + <CopyButton v-if="range.start" :text="bytes[range.start - 1].toString(2).padStart(8, '0')" size="12" /> |
| 38 | + </Flex> |
| 39 | + |
| 40 | + <Text v-if="range.start" size="13" weight="600" color="primary" mono> |
| 41 | + {{ bytes[range.start - 1].toString(2).padStart(8, "0") }} |
| 42 | + </Text> |
| 43 | + <Text v-else size="13" weight="600" color="tertiary" mono>No bytes selected</Text> |
| 44 | + </Flex> |
| 45 | + |
| 46 | + <Flex direction="column" gap="8" :class="$style.field"> |
| 47 | + <Flex align="center" justify="between"> |
| 48 | + <Text size="12" weight="600" color="secondary">uint8</Text> |
| 49 | + <CopyButton v-if="range.start" :text="hexToUint8Array(bytes[range.start - 1])" size="12" /> |
| 50 | + </Flex> |
| 51 | + |
| 52 | + <Text v-if="range.start" size="13" weight="600" color="primary" mono> |
| 53 | + {{ hexToUint8Array(bytes[range.start - 1]) }} |
| 54 | + </Text> |
| 55 | + <Text v-else size="13" weight="600" color="tertiary" mono>No bytes selected</Text> |
| 56 | + </Flex> |
| 57 | + |
| 58 | + <Flex direction="column" gap="8" :class="$style.field"> |
| 59 | + <Flex align="center" justify="between"> |
| 60 | + <Text size="12" weight="600" color="secondary">Time</Text> |
| 61 | + <CopyButton v-if="range.start" :text="hexToUint8Array(bytes[range.start - 1])" size="12" /> |
| 62 | + </Flex> |
| 63 | + |
| 64 | + <Text v-if="range.start" size="13" weight="600" color="primary" mono> |
| 65 | + {{ DateTime.fromISO(parseInt(bytes[range.start - 1], 16)) }} |
| 66 | + </Text> |
| 67 | + <Text v-else size="13" weight="600" color="tertiary" mono>No bytes selected</Text> |
| 68 | + </Flex> |
| 69 | + |
| 70 | + <Flex direction="column" gap="8" :class="$style.field"> |
| 71 | + <Flex align="center" justify="between"> |
| 72 | + <Text size="12" weight="600" color="secondary">ASCII Character</Text> |
| 73 | + <CopyButton |
| 74 | + v-if="range.start" |
| 75 | + :text=" |
| 76 | + range.start < range.end |
| 77 | + ? bytes |
| 78 | + .slice(range.start - 1, range.end) |
| 79 | + .map((byte) => String.fromCharCode(parseInt(byte, 16))) |
| 80 | + .join('') |
| 81 | + : bytes |
| 82 | + .slice(range.end - 1, range.start) |
| 83 | + .map((byte) => String.fromCharCode(parseInt(byte, 16))) |
| 84 | + .join('') |
| 85 | + " |
| 86 | + size="12" |
| 87 | + /> |
| 88 | + </Flex> |
| 89 | + |
| 90 | + <Text v-if="range.start < range.end" size="13" weight="600" height="140" color="primary" mono :class="$style.ascii"> |
| 91 | + {{ |
| 92 | + bytes |
| 93 | + .slice(range.start - 1, range.end) |
| 94 | + .map((byte) => String.fromCharCode(parseInt(byte, 16))) |
| 95 | + .join("") |
| 96 | + }} |
| 97 | + </Text> |
| 98 | + <Text v-if="range.start > range.end" size="13" weight="600" height="140" color="primary" mono :class="$style.ascii"> |
| 99 | + {{ |
| 100 | + bytes |
| 101 | + .slice(range.end - 1, range.start) |
| 102 | + .map((byte) => String.fromCharCode(parseInt(byte, 16))) |
| 103 | + .join("") |
| 104 | + }} |
| 105 | + </Text> |
| 106 | + </Flex> |
| 107 | + </Flex> |
| 108 | + </Flex> |
| 109 | +</template> |
| 110 | + |
| 111 | +<style module> |
| 112 | +.wrapper { |
| 113 | + border-radius: 8px; |
| 114 | + background: var(--card-background); |
| 115 | + overflow: hidden; |
| 116 | +
|
| 117 | + padding: 16px; |
| 118 | +} |
| 119 | +
|
| 120 | +.header { |
| 121 | + cursor: pointer; |
| 122 | + border-radius: 6px; |
| 123 | +
|
| 124 | + padding: 8px; |
| 125 | + margin: -8px; |
| 126 | +
|
| 127 | + transition: all 0.2s ease; |
| 128 | +
|
| 129 | + &:hover { |
| 130 | + background: var(--op-5); |
| 131 | + } |
| 132 | +} |
| 133 | +
|
| 134 | +.field { |
| 135 | + border-radius: 6px; |
| 136 | + background: var(--op-5); |
| 137 | +
|
| 138 | + padding: 8px; |
| 139 | +} |
| 140 | +
|
| 141 | +.value { |
| 142 | + cursor: pointer; |
| 143 | +
|
| 144 | + transition: all 0.2s ease; |
| 145 | +
|
| 146 | + &:hover { |
| 147 | + color: var(--txt-primary); |
| 148 | + background: var(--op-10); |
| 149 | + } |
| 150 | +
|
| 151 | + &:nth-child(9) { |
| 152 | + margin-right: 10px; |
| 153 | + } |
| 154 | +} |
| 155 | +
|
| 156 | +.ascii { |
| 157 | + overflow: hidden; |
| 158 | + text-overflow: ellipsis; |
| 159 | +} |
| 160 | +</style> |
0 commit comments