vuehex 0.5.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.
package/dist/index.js ADDED
@@ -0,0 +1,1419 @@
1
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, guardReactiveProps, mergeModels, nextTick, normalizeClass, normalizeProps, normalizeStyle, onBeforeUnmount, onMounted, openBlock, ref, renderList, renderSlot, shallowRef, toDisplayString, toRef, unref, useModel, useSlots, vShow, watch, withCtx, withDirectives } from "vue";
2
+ var HTML_ESCAPE_LOOKUP = {
3
+ "&": "&",
4
+ "<": "&lt;",
5
+ ">": "&gt;",
6
+ "\"": "&quot;",
7
+ "'": "&#39;"
8
+ };
9
+ function normalizeSource(e) {
10
+ if (e instanceof Uint8Array) return e;
11
+ throw TypeError("VueHex expects virtual window data as Uint8Array instances.");
12
+ }
13
+ function clampBytesPerRow(e) {
14
+ return typeof e != "number" || !Number.isFinite(e) ? 16 : Math.max(1, Math.trunc(e));
15
+ }
16
+ function resolveFallbackChar(e) {
17
+ return typeof e == "string" && e.length > 0 ? escapeHtml(e.slice(0, 1)) : ".";
18
+ }
19
+ function escapeHtml(e) {
20
+ let t = "";
21
+ for (let n = 0; n < e.length; n += 1) {
22
+ let r = e[n] ?? "";
23
+ t += HTML_ESCAPE_LOOKUP[r] ?? r;
24
+ }
25
+ return t;
26
+ }
27
+ function formatOffsetPlain(e, t) {
28
+ let n = e.toString(16).padStart(8, "0");
29
+ return t ? n.toUpperCase() : n;
30
+ }
31
+ function clamp(e, t, n) {
32
+ return e < t ? t : e > n ? n : e;
33
+ }
34
+ function parseIndexAttribute(e, t) {
35
+ let n = e.getAttribute(t);
36
+ if (!n) return null;
37
+ let r = Number.parseInt(n, 10);
38
+ return Number.isFinite(r) ? r : null;
39
+ }
40
+ function readByteIndexFromElement(e) {
41
+ if (!(e instanceof HTMLElement)) return null;
42
+ let t = e.closest("[data-hex-index], [data-ascii-index]");
43
+ if (!t || t.getAttribute("aria-hidden") === "true") return null;
44
+ let n = t.hasAttribute("data-hex-index") ? t.getAttribute("data-hex-index") : t.getAttribute("data-ascii-index");
45
+ if (!n) return null;
46
+ let r = Number.parseInt(n, 10);
47
+ return Number.isFinite(r) ? r : null;
48
+ }
49
+ function normalizeThemeKey(e) {
50
+ if (typeof e != "string") return null;
51
+ let t = e.trim();
52
+ return t && t.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "") || null;
53
+ }
54
+ function useChunking(e) {
55
+ let n = ref(0), r = computed(() => {
56
+ let t = e.totalBytes.value;
57
+ return t <= 0 ? 0 : Math.ceil(t / Math.max(e.bytesPerRow.value, 1));
58
+ }), i = computed(() => {
59
+ let t = e.maxVirtualHeight.value;
60
+ if (!Number.isFinite(t) || t <= 0) return Infinity;
61
+ let n = e.rowHeightValue.value;
62
+ if (!Number.isFinite(n) || n <= 0) return Infinity;
63
+ let r = Math.floor(t / n);
64
+ return r > 0 ? r : Infinity;
65
+ }), a = computed(() => {
66
+ let e = i.value;
67
+ return Number.isFinite(e) && e > 0 && r.value > e;
68
+ }), o = computed(() => a.value ? Math.max(1, Math.ceil(r.value / i.value)) : 1), s = computed(() => {
69
+ if (!a.value) return 0;
70
+ let e = i.value;
71
+ return !Number.isFinite(e) || e <= 0 ? 0 : clamp(Math.floor(Math.max(0, n.value) / e), 0, Math.max(o.value - 1, 0));
72
+ }), c = computed(() => {
73
+ let e = r.value;
74
+ if (e <= 0) return 0;
75
+ if (!a.value) return e;
76
+ let t = i.value;
77
+ if (!Number.isFinite(t) || t <= 0) return e;
78
+ let o = Math.max(e - Math.max(0, n.value), 0);
79
+ return Math.min(o, t);
80
+ }), l = computed(() => {
81
+ let t = c.value;
82
+ return t <= 0 ? 0 : t * e.rowHeightValue.value;
83
+ }), u = computed(() => {
84
+ if (!e.showNavigator.value || !a.value) return [];
85
+ let t = r.value, n = i.value;
86
+ if (t <= 0 || !Number.isFinite(n) || n <= 0) return [];
87
+ let s = Math.max(e.bytesPerRow.value, 1), c = e.totalBytes.value, l = !!e.uppercase.value, u = [];
88
+ for (let e = 0; e < o.value; e += 1) {
89
+ let r = e * n;
90
+ if (r >= t) break;
91
+ let i = Math.min(n, t - r), a = r * s, o = Math.min(i * s, Math.max(c - a, 0)), d = o > 0 ? a + o - 1 : a;
92
+ u.push({
93
+ index: e,
94
+ label: `Chunk ${e + 1}`,
95
+ range: `${formatOffsetPlain(a, l)} - ${formatOffsetPlain(d, l)}`
96
+ });
97
+ }
98
+ return u;
99
+ });
100
+ function d() {
101
+ let e = r.value;
102
+ if (e <= 0) {
103
+ n.value = 0;
104
+ return;
105
+ }
106
+ if (!a.value) {
107
+ n.value = 0;
108
+ return;
109
+ }
110
+ let t = i.value, o = Math.max(e - 1, 0), s = clamp(Math.max(0, Math.trunc(n.value)), 0, o);
111
+ if (!Number.isFinite(t) || t <= 0) {
112
+ n.value = s;
113
+ return;
114
+ }
115
+ n.value = clamp(Math.floor(s / t) * t, 0, o);
116
+ }
117
+ function f(e) {
118
+ if (Number.isFinite(e) || (e = 0), d(), !a.value) return !1;
119
+ let t = i.value;
120
+ if (!Number.isFinite(t) || t <= 0) return !1;
121
+ let o = r.value;
122
+ if (o <= 0) return !1;
123
+ let s = Math.max(o - 1, 0), c = clamp(Math.floor(e), 0, s), l = clamp(Math.floor(c / t) * t, 0, s);
124
+ return l === n.value ? !1 : (n.value = l, !0);
125
+ }
126
+ function p(e) {
127
+ if (!Number.isFinite(e) || !a.value) return !1;
128
+ let t = i.value;
129
+ if (!Number.isFinite(t) || t <= 0) return !1;
130
+ let s = r.value;
131
+ if (s <= 0) return !1;
132
+ let c = Math.max(s - 1, 0), l = Math.max(o.value - 1, 0), u = clamp(clamp(Math.floor(e), 0, l) * t, 0, c);
133
+ return u === n.value ? !1 : (n.value = u, !0);
134
+ }
135
+ return {
136
+ chunkStartRow: n,
137
+ totalRows: r,
138
+ chunkRowCapacity: i,
139
+ isChunking: a,
140
+ chunkCount: o,
141
+ activeChunkIndex: s,
142
+ chunkRowCount: c,
143
+ chunkHeight: l,
144
+ chunkItems: u,
145
+ clampChunkStartToBounds: d,
146
+ ensureChunkForRow: f,
147
+ selectChunk: p
148
+ };
149
+ }
150
+ var CURSOR_CLASS = "vuehex-cursor";
151
+ function useCursor(e) {
152
+ let n = computed(() => {
153
+ if (!e.enabled.value) return null;
154
+ let t = e.totalBytes.value, n = e.cursorLocation.value;
155
+ if (n === null) return null;
156
+ let r = Number(n);
157
+ return !Number.isFinite(r) || t <= 0 ? null : t > 0 ? clamp(Math.trunc(r), 0, t - 1) : 0;
158
+ });
159
+ function r(t) {
160
+ if (!e.enabled.value || e.isExpandToContent.value || e.totalBytes.value <= 0) return;
161
+ let n = e.containerEl.value;
162
+ if (!n) {
163
+ e.scrollToByte(t);
164
+ return;
165
+ }
166
+ let r = Math.max(1, Math.trunc(e.bytesPerRow.value)), i = e.rowHeightValue.value, a = e.viewportRows.value;
167
+ if (i <= 0 || a <= 0) {
168
+ e.scrollToByte(t);
169
+ return;
170
+ }
171
+ let o = Math.floor(t / r), s = e.ensureChunkForRow(o), c = e.chunkStartRow.value;
172
+ if (s) {
173
+ n.scrollTop = Math.max(0, (o - c) * i), e.scheduleWindowEvaluation();
174
+ return;
175
+ }
176
+ let l = n.scrollTop, u = c + Math.floor(l / i), d = u + a - 1;
177
+ if (o < u) {
178
+ n.scrollTop = Math.max(0, (o - c) * i), e.scheduleWindowEvaluation();
179
+ return;
180
+ }
181
+ if (o > d) {
182
+ let t = o - (a - 1);
183
+ n.scrollTop = Math.max(0, (t - c) * i), e.scheduleWindowEvaluation();
184
+ }
185
+ }
186
+ function i(t) {
187
+ if (!e.enabled.value) return;
188
+ let n = e.totalBytes.value;
189
+ if (n <= 0) {
190
+ e.cursorLocation.value = null;
191
+ return;
192
+ }
193
+ let r = null;
194
+ if (t !== null) {
195
+ let e = Number(t);
196
+ Number.isFinite(e) && (r = n > 0 ? clamp(Math.trunc(e), 0, n - 1) : 0);
197
+ }
198
+ e.cursorLocation.value = r;
199
+ }
200
+ let a = ref(null);
201
+ function o(e, t) {
202
+ let n = e.querySelector(`[data-hex-index="${t}"]`), r = e.querySelector(`[data-ascii-index="${t}"]`);
203
+ n?.classList.remove(CURSOR_CLASS), r?.classList.remove(CURSOR_CLASS);
204
+ }
205
+ function s(e, t) {
206
+ let n = e.querySelector(`[data-hex-index="${t}"]`), r = e.querySelector(`[data-ascii-index="${t}"]`), i = !1;
207
+ return n && n.getAttribute("aria-hidden") !== "true" && (n.classList.add(CURSOR_CLASS), i = !0), r && r.getAttribute("aria-hidden") !== "true" && (r.classList.add(CURSOR_CLASS), i = !0), i;
208
+ }
209
+ function c() {
210
+ let t = e.tbodyEl.value;
211
+ if (!t) return;
212
+ let r = n.value, i = a.value;
213
+ if (i !== null && i !== r && o(t, i), r === null) {
214
+ a.value = null;
215
+ return;
216
+ }
217
+ a.value = s(t, r) ? r : null;
218
+ }
219
+ function u(t) {
220
+ if (!e.enabled.value || t.button !== 0) return;
221
+ let n = readByteIndexFromElement(t.target);
222
+ n !== null && (e.containerEl.value?.focus(), i(n));
223
+ }
224
+ function d(t) {
225
+ if (!e.enabled.value || e.totalBytes.value <= 0) return;
226
+ let r = Math.max(1, Math.trunc(e.bytesPerRow.value || 1)), a = null;
227
+ switch (t.key) {
228
+ case "ArrowLeft":
229
+ a = -1;
230
+ break;
231
+ case "ArrowRight":
232
+ a = 1;
233
+ break;
234
+ case "ArrowUp":
235
+ a = -r;
236
+ break;
237
+ case "ArrowDown":
238
+ a = r;
239
+ break;
240
+ default: return;
241
+ }
242
+ t.preventDefault(), i((n.value ?? 0) + (a ?? 0));
243
+ }
244
+ return watch(e.markup, async () => {
245
+ a.value = null, await nextTick(), c();
246
+ }, { flush: "post" }), watch([n, e.enabled], async () => {
247
+ await nextTick(), c();
248
+ }, { flush: "post" }), watch(n, (t, n) => {
249
+ e.enabled.value && (t === null || t === n || r(t));
250
+ }), onMounted(() => {
251
+ let t = e.containerEl.value;
252
+ t && (t.addEventListener("keydown", d), t.addEventListener("pointerdown", u));
253
+ }), onBeforeUnmount(() => {
254
+ let t = e.containerEl.value;
255
+ t && (t.removeEventListener("keydown", d), t.removeEventListener("pointerdown", u));
256
+ let n = e.tbodyEl.value, r = a.value;
257
+ n && r !== null && o(n, r), a.value = null;
258
+ }), {
259
+ cursorLocation: n,
260
+ setCursorLocation: i
261
+ };
262
+ }
263
+ function useDataMode(e) {
264
+ let n = computed(() => {
265
+ let t = e.dataMode.value ?? "auto";
266
+ return t === "buffer" || t === "window" || t === "auto" ? t : "auto";
267
+ }), r = computed(() => {
268
+ if (e.isExpandToContent.value || n.value === "buffer") return !1;
269
+ if (n.value === "window") return !0;
270
+ let t = e.totalSize.value;
271
+ return typeof t == "number" && Number.isFinite(t) && t > e.dataLength.value;
272
+ });
273
+ return {
274
+ normalizedMode: n,
275
+ isWindowed: r,
276
+ isSelfManaged: computed(() => !r.value)
277
+ };
278
+ }
279
+ var HEX_LOWER = Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0")), HEX_UPPER = HEX_LOWER.map((e) => e.toUpperCase()), PLACEHOLDER_HEX = "--", PLACEHOLDER_ASCII = "--";
280
+ function escapeAsciiChar(e) {
281
+ return escapeHtml(e);
282
+ }
283
+ function formatOffset(e, t) {
284
+ let n = e.toString(16).padStart(8, "0"), r = t ? n.toUpperCase() : n, i = r.replace(/^0+/, ""), a = r.length - i.length;
285
+ return a <= 0 ? r : `<span class="vuehex-offset-leading">${r.slice(0, a)}</span>${r.slice(a)}`;
286
+ }
287
+ function normalizeClassTokens(e) {
288
+ if (e == null) return [];
289
+ if (Array.isArray(e)) {
290
+ let t = [];
291
+ for (let n of e) t.push(...normalizeClassTokens(n));
292
+ return t;
293
+ }
294
+ return typeof e == "string" ? e.split(/\s+/g).map((e) => e.trim()).filter(Boolean) : [];
295
+ }
296
+ function escapeClassAttribute(e) {
297
+ let t = /* @__PURE__ */ new Set(), n = [];
298
+ for (let r of e) {
299
+ let e = r.trim();
300
+ !e || t.has(e) || (t.add(e), n.push(escapeHtml(e)));
301
+ }
302
+ return n.join(" ");
303
+ }
304
+ function useHexWindow(e) {
305
+ let n = shallowRef(""), r = shallowRef(new Uint8Array()), i = shallowRef("."), a = ref(0), o = ref(null), s = ref(!1), c = shallowRef(null), u = computed(() => {
306
+ let t = e.getWindowState();
307
+ return Math.floor(t.offset / Math.max(e.bytesPerRow.value, 1));
308
+ }), d = computed(() => {
309
+ let t = r.value.length;
310
+ return t === 0 ? 0 : Math.max(1, Math.ceil(t / Math.max(e.bytesPerRow.value, 1)));
311
+ });
312
+ function f() {
313
+ e.clampChunkStartToBounds();
314
+ let t = e.getWindowState(), n = normalizeSource(t.data);
315
+ r.value = n, i.value = resolveFallbackChar(e.getNonPrintableChar()), c.value = {
316
+ offset: t.offset,
317
+ length: n.length
318
+ }, S(), nextTick(() => {
319
+ x(), m();
320
+ });
321
+ }
322
+ function p(t) {
323
+ let n = e.containerEl.value;
324
+ if (!n) return !1;
325
+ let r = Math.max(e.bytesPerRow.value, 1), i = Math.floor(t / r);
326
+ e.ensureChunkForRow(i);
327
+ let a = i - e.chunkStartRow.value, o = e.rowHeightValue.value;
328
+ return o > 0 && (n.scrollTop = Math.max(a * o, 0)), !0;
329
+ }
330
+ function m() {
331
+ if (s.value) return;
332
+ s.value = !0;
333
+ let e = typeof window < "u" && typeof window.requestAnimationFrame == "function", t = () => {
334
+ s.value = !1, b(), S(), w();
335
+ };
336
+ e ? window.requestAnimationFrame(t) : nextTick(t);
337
+ }
338
+ function h() {
339
+ m();
340
+ }
341
+ function _(e) {
342
+ o.value = Math.max(0, Math.trunc(e)), m();
343
+ }
344
+ function v(e) {
345
+ if (!Number.isFinite(e)) return;
346
+ let t = Math.max(0, Math.trunc(e));
347
+ if (!p(t)) {
348
+ _(t);
349
+ return;
350
+ }
351
+ o.value = null, m();
352
+ }
353
+ function b() {
354
+ if (o.value == null) return;
355
+ let e = o.value;
356
+ p(e) && (o.value = null);
357
+ }
358
+ function x() {
359
+ let t = e.tbodyEl.value;
360
+ if (!t) return;
361
+ let n = t.querySelector("tr");
362
+ if (!n) return;
363
+ let r = n.getBoundingClientRect().height;
364
+ r > 0 && r !== e.rowHeight.value && (e.rowHeight.value = r);
365
+ }
366
+ function S() {
367
+ let t = r.value, o = Math.max(e.bytesPerRow.value, 1), s = e.getWindowState().offset;
368
+ if (t.length === 0) {
369
+ n.value = "", a.value = Math.floor(s / o), e.clearHoverState();
370
+ return;
371
+ }
372
+ let c = s + t.length, l = s, u = c, d = e.containerEl.value, f = e.viewportRows.value, p = e.overscanRows.value;
373
+ if (d && f > 0 && e.rowHeightValue.value > 0 && o > 0) {
374
+ let t = d.scrollTop, n = Math.floor(t / e.rowHeightValue.value), r = (e.chunkStartRow.value + n) * o, i = p * o, a = e.chunkStartRow.value * o;
375
+ l = clamp(r - i, Math.max(s, a), c), l >= c && (l = Math.max(c - o, s));
376
+ let m = l - s;
377
+ l = clamp(s + Math.floor(m / o) * o, s, Math.max(c - 1, s));
378
+ let h = Math.max(f + p * 2, 1) * o;
379
+ u = Math.min(c, l + h);
380
+ }
381
+ if (u <= l) {
382
+ n.value = "", a.value = Math.floor(l / o), e.clearHoverState();
383
+ return;
384
+ }
385
+ let m = l - s, h = Math.min(t.length, m + (u - l)), g = t.subarray(m, h);
386
+ a.value = Math.floor(l / o);
387
+ let _ = e.getPrintableChecker(), v = e.getAsciiRenderer(), y = e.getSelectionRange(), b = C(g, o, e.getUppercase(), i.value, l, _, v, y, e.getCellClassResolver());
388
+ n.value !== b && (e.clearHoverState(), n.value = b);
389
+ }
390
+ function C(e, t, n, r, i, a, o, s, c) {
391
+ if (e.length === 0) return "";
392
+ let l = n ? HEX_UPPER : HEX_LOWER, u = t % 2 == 0, d = u ? t / 2 : -1, f = Array(t);
393
+ for (let e = 0; e < t; e++) {
394
+ let t = u && e >= d, n = u && e === d, r = "vuehex-byte", i = "vuehex-ascii-char";
395
+ t && (r += ` vuehex-byte--second-column${n ? " vuehex-byte--column-start" : ""}`, i += ` vuehex-ascii-char--second-column${n ? " vuehex-ascii-char--column-start" : ""}`);
396
+ let a = `${r} vuehex-byte--placeholder`, o = `${i} vuehex-ascii-char--placeholder`, s = `${i} vuehex-ascii-char--printable`, c = `${i} vuehex-ascii-char--non-printable`;
397
+ f[e] = {
398
+ hexStatic: r,
399
+ asciiPrintable: s,
400
+ asciiNonPrintable: c,
401
+ hexPlaceholder: `<span class="${a}" aria-hidden="true">${PLACEHOLDER_HEX}</span>`,
402
+ asciiPlaceholder: `<span class="${o}" aria-hidden="true">${PLACEHOLDER_ASCII}</span>`
403
+ };
404
+ }
405
+ let p = "<span class=\"", m = "\" data-byte-value=\"", h = "</span>", g = Math.ceil(e.length / t) * (2 * t + 20), _ = Array(g), v = 0;
406
+ for (let u = 0; u < e.length; u += t) {
407
+ let d = Math.min(t, e.length - u), g = i + u;
408
+ _[v++] = "<tr role=\"row\" data-row-offset=\"" + g + "\"><th scope=\"row\" class=\"vuehex-offset\" role=\"rowheader\">" + formatOffset(g, n) + "</th><td class=\"vuehex-bytes\" role=\"cell\">";
409
+ for (let t = 0; t < d; t += 1) {
410
+ let n = e[u + t], r = g + t, i = `${f[t].hexStatic} vuehex-byte--value-${n}`;
411
+ if (s && r >= s.start && r <= s.end && (i += " vuehex-selected"), c) {
412
+ let e = c({
413
+ kind: "hex",
414
+ index: r,
415
+ byte: n
416
+ });
417
+ if (e != null) {
418
+ let t = normalizeClassTokens(e);
419
+ t.length > 0 && (i += ` ${escapeClassAttribute(t)}`);
420
+ }
421
+ }
422
+ _[v++] = p + i + "\" data-hex-index=\"" + r + m + n + "\">" + l[n] + h;
423
+ }
424
+ for (let e = d; e < t; e += 1) _[v++] = f[e].hexPlaceholder;
425
+ _[v++] = "</td><td class=\"vuehex-ascii\" role=\"cell\">";
426
+ for (let t = 0; t < d; t += 1) {
427
+ let n = e[u + t], i = g + t, l = f[t], d = r, y;
428
+ if (a(n)) {
429
+ let e = o(n);
430
+ if (e != null) {
431
+ let t = String(e);
432
+ t.length > 0 ? (d = escapeAsciiChar(t), y = `${l.asciiPrintable} vuehex-ascii-char--value-${n}`) : y = `${l.asciiNonPrintable} vuehex-ascii-char--value-${n}`;
433
+ } else y = `${l.asciiNonPrintable} vuehex-ascii-char--value-${n}`;
434
+ } else y = `${l.asciiNonPrintable} vuehex-ascii-char--value-${n}`;
435
+ if (s && i >= s.start && i <= s.end && (y += " vuehex-selected vuehex-selected--ascii"), c) {
436
+ let e = c({
437
+ kind: "ascii",
438
+ index: i,
439
+ byte: n
440
+ });
441
+ if (e != null) {
442
+ let t = normalizeClassTokens(e);
443
+ t.length > 0 && (y += ` ${escapeClassAttribute(t)}`);
444
+ }
445
+ }
446
+ _[v++] = p + y + "\" data-ascii-index=\"" + i + m + n + "\">" + d + h;
447
+ }
448
+ for (let e = d; e < t; e += 1) _[v++] = f[e].asciiPlaceholder;
449
+ _[v++] = "</td></tr>";
450
+ }
451
+ return _.length = v, _.join("");
452
+ }
453
+ function w() {
454
+ if (e.viewportRows.value === 0) return;
455
+ let t = e.containerEl.value;
456
+ if (!t) return;
457
+ let n = e.rowHeightValue.value, r = e.bytesPerRow.value;
458
+ if (n <= 0 || r <= 0) return;
459
+ let i = e.chunkRowCount.value;
460
+ if (i <= 0) return;
461
+ let a = e.chunkStartRow.value, o = a + i, s = e.overscanRows.value, l = t.scrollTop, f = clamp(clamp(a + Math.floor(l / n), a, Math.max(o - 1, a)) - s, a, Math.max(o - 1, a)), p = Math.max(e.viewportRows.value + s * 2, 1), m = Math.max(o - f, 0), h = Math.min(m, p);
462
+ if (h <= 0) return;
463
+ let g = f * r, _ = Math.max(e.totalBytes.value - g, 0), v = Math.min(_, h * r);
464
+ if (v <= 0) return;
465
+ let y = f + Math.ceil(v / r), b = u.value, x = b + d.value;
466
+ b <= f && x >= y || c.value && c.value.offset === g && c.value.length === v || (c.value = {
467
+ offset: g,
468
+ length: v
469
+ }, e.requestWindow(c.value));
470
+ }
471
+ return {
472
+ markup: n,
473
+ normalizedBytes: r,
474
+ fallbackAsciiChar: i,
475
+ renderStartRow: a,
476
+ renderedRows: d,
477
+ startRow: u,
478
+ scheduleWindowEvaluation: m,
479
+ handleScroll: h,
480
+ scrollToByte: v,
481
+ queueScrollToOffset: _,
482
+ updateFromWindowState: f,
483
+ updateRenderedSlice: S,
484
+ measureRowHeight: x
485
+ };
486
+ }
487
+ function useHoverLinking(e) {
488
+ let t = ref(null), n = ref(null), r = ref(null), i = ref(null), a = null;
489
+ function o(e) {
490
+ let t = e.target;
491
+ t instanceof HTMLElement && (c(t), u(t), f(t));
492
+ }
493
+ function s(e) {
494
+ let t = e.target;
495
+ if (!(t instanceof HTMLElement)) return;
496
+ let n = e.relatedTarget;
497
+ l(t, n), d(t, n), p(t, n);
498
+ let r = e.currentTarget;
499
+ r instanceof HTMLElement && (!(n instanceof HTMLElement) || !r.contains(n)) && _();
500
+ }
501
+ function c(n) {
502
+ let r = n.closest("tr[data-row-offset]");
503
+ if (!r?.dataset.rowOffset) return;
504
+ let i = parseIndexAttribute(r, "data-row-offset");
505
+ i !== null && (t.value != null && t.value !== i && (e.emit("row-hover-off", { offset: t.value }), t.value = null), t.value !== i && (t.value = i, e.emit("row-hover-on", { offset: i })));
506
+ }
507
+ function l(n, r) {
508
+ if (t.value == null) return;
509
+ let i = n.closest("tr[data-row-offset]");
510
+ if (!i?.dataset.rowOffset) return;
511
+ let a = parseIndexAttribute(i, "data-row-offset");
512
+ a === null || a !== t.value || r instanceof HTMLElement && i.contains(r) || (e.emit("row-hover-off", { offset: a }), t.value = null);
513
+ }
514
+ function u(t) {
515
+ let r = t.closest("span[data-hex-index]");
516
+ if (!r?.dataset.hexIndex || !r.dataset.byteValue) return;
517
+ let i = parseIndexAttribute(r, "data-hex-index"), a = parseIndexAttribute(r, "data-byte-value");
518
+ if (!(i === null || a === null)) {
519
+ if (n.value) {
520
+ if (n.value.index === i && n.value.byte === a) return;
521
+ e.emit("hex-hover-off", n.value), n.value = null;
522
+ }
523
+ n.value = {
524
+ index: i,
525
+ byte: a
526
+ }, e.emit("hex-hover-on", n.value), m(i);
527
+ }
528
+ }
529
+ function d(t, i) {
530
+ if (!n.value) return;
531
+ let a = t.closest("span[data-hex-index]");
532
+ if (!a?.dataset.hexIndex) return;
533
+ let o = parseIndexAttribute(a, "data-hex-index");
534
+ o === null || o !== n.value.index || i instanceof HTMLElement && a.contains(i) || i instanceof HTMLElement && (i.dataset.hexIndex === a.dataset.hexIndex || i.dataset.asciiIndex === a.dataset.hexIndex) || (e.emit("hex-hover-off", n.value), n.value = null, (!r.value || r.value.index !== o) && h());
535
+ }
536
+ function f(t) {
537
+ let n = t.closest("span[data-ascii-index]");
538
+ if (!n?.dataset.asciiIndex || !n.dataset.byteValue) return;
539
+ let i = parseIndexAttribute(n, "data-ascii-index"), a = parseIndexAttribute(n, "data-byte-value");
540
+ if (!(i === null || a === null)) {
541
+ if (r.value) {
542
+ if (r.value.index === i && r.value.byte === a) return;
543
+ e.emit("ascii-hover-off", r.value), r.value = null;
544
+ }
545
+ r.value = {
546
+ index: i,
547
+ byte: a
548
+ }, e.emit("ascii-hover-on", r.value), m(i);
549
+ }
550
+ }
551
+ function p(t, i) {
552
+ if (!r.value) return;
553
+ let a = t.closest("span[data-ascii-index]");
554
+ if (!a?.dataset.asciiIndex) return;
555
+ let o = parseIndexAttribute(a, "data-ascii-index");
556
+ o === null || o !== r.value.index || i instanceof HTMLElement && a.contains(i) || i instanceof HTMLElement && (i.dataset.asciiIndex === a.dataset.asciiIndex || i.dataset.hexIndex === a.dataset.asciiIndex) || (e.emit("ascii-hover-off", r.value), r.value = null, (!n.value || n.value.index !== o) && h());
557
+ }
558
+ function m(t) {
559
+ if (!Number.isFinite(t) || t < 0 || i.value === t) return;
560
+ a !== null && (typeof window < "u" && window.cancelAnimationFrame && window.cancelAnimationFrame(a), a = null);
561
+ let n = () => {
562
+ a = null, h();
563
+ let n = e.tbodyEl.value;
564
+ if (!n) {
565
+ i.value = t;
566
+ return;
567
+ }
568
+ let r = `[data-hex-index="${t}"], [data-ascii-index="${t}"]`;
569
+ n.querySelectorAll(r).forEach((e) => {
570
+ e.classList.add("vuehex-linked-hover");
571
+ }), i.value = t;
572
+ };
573
+ typeof window < "u" && window.requestAnimationFrame ? a = window.requestAnimationFrame(n) : n();
574
+ }
575
+ function h() {
576
+ if (i.value == null) return;
577
+ let t = e.tbodyEl.value;
578
+ if (t) {
579
+ let e = `[data-hex-index="${i.value}"], [data-ascii-index="${i.value}"]`;
580
+ t.querySelectorAll(e).forEach((e) => {
581
+ e.classList.remove("vuehex-linked-hover");
582
+ });
583
+ }
584
+ i.value = null;
585
+ }
586
+ function _() {
587
+ a !== null && (typeof window < "u" && window.cancelAnimationFrame && window.cancelAnimationFrame(a), a = null), n.value &&= (e.emit("hex-hover-off", n.value), null), r.value &&= (e.emit("ascii-hover-off", r.value), null), t.value != null && (e.emit("row-hover-off", { offset: t.value }), t.value = null), h();
588
+ }
589
+ return {
590
+ handlePointerOver: o,
591
+ handlePointerOut: s,
592
+ clearHoverState: _
593
+ };
594
+ }
595
+ function useSelection(e) {
596
+ function n(e, t) {
597
+ return {
598
+ start: Math.min(e, t),
599
+ end: Math.max(e, t)
600
+ };
601
+ }
602
+ let r = computed(() => e.getSelectionDataProp() || (e.isSelfManagedData.value ? (t, r) => {
603
+ let i = e.totalBytes.value;
604
+ if (i <= 0) return new Uint8Array();
605
+ let { start: a, end: o } = n(clamp(Math.trunc(t), 0, i - 1), clamp(Math.trunc(r), 0, i - 1));
606
+ return e.getSelfManagedBytes().slice(a, o + 1);
607
+ } : null)), i = computed(() => r.value !== null), a = computed(() => {
608
+ if (!i.value) return null;
609
+ let e = s.value;
610
+ return e ? n(e.anchor, e.focus) : null;
611
+ }), o = computed(() => {
612
+ let e = a.value;
613
+ return e ? Math.max(0, e.end - e.start + 1) : 0;
614
+ }), s = ref(null), c = ref(!1), l = ref(null), u = null;
615
+ watch(a, (t) => {
616
+ e.emitSelectionChange && e.emitSelectionChange({
617
+ start: t?.start ?? null,
618
+ end: t?.end ?? null,
619
+ length: o.value
620
+ });
621
+ });
622
+ function d() {
623
+ typeof window > "u" || (u !== null && cancelAnimationFrame(u), u = requestAnimationFrame(() => {
624
+ u = null, e.updateRenderedSlice();
625
+ }));
626
+ }
627
+ function f(e) {
628
+ if (!(e instanceof HTMLElement)) return null;
629
+ let t = e.closest("[data-hex-index], [data-ascii-index]");
630
+ if (!t || t.getAttribute("aria-hidden") === "true") return null;
631
+ if (t.hasAttribute("data-hex-index")) {
632
+ let e = parseIndexAttribute(t, "data-hex-index");
633
+ return e === null ? null : {
634
+ mode: "hex",
635
+ index: e
636
+ };
637
+ }
638
+ if (t.hasAttribute("data-ascii-index")) {
639
+ let e = parseIndexAttribute(t, "data-ascii-index");
640
+ return e === null ? null : {
641
+ mode: "ascii",
642
+ index: e
643
+ };
644
+ }
645
+ return null;
646
+ }
647
+ function h(e, t, n) {
648
+ s.value = {
649
+ mode: e,
650
+ anchor: t,
651
+ focus: t
652
+ }, c.value = !0, l.value = n, d();
653
+ }
654
+ function _(e) {
655
+ s.value && s.value.focus !== e && (s.value = {
656
+ ...s.value,
657
+ focus: e
658
+ }, d());
659
+ }
660
+ function v() {
661
+ c.value = !1, l.value = null;
662
+ }
663
+ function y() {
664
+ s.value && (s.value = null, d());
665
+ }
666
+ function b(t) {
667
+ if (!i.value || t.button !== 0) return;
668
+ let n = f(t.target);
669
+ if (n && e.emitByteClick) {
670
+ let t = e.getSelfManagedBytes();
671
+ if (n.index < t.length) {
672
+ let r = t[n.index];
673
+ r !== void 0 && e.emitByteClick({
674
+ index: n.index,
675
+ byte: r,
676
+ kind: n.mode
677
+ });
678
+ }
679
+ }
680
+ let r = s.value;
681
+ if (!n) {
682
+ t.shiftKey || y(), v();
683
+ return;
684
+ }
685
+ if (t.preventDefault(), e.containerEl.value?.focus(), t.shiftKey && r && r.mode === n.mode) {
686
+ s.value = {
687
+ mode: r.mode,
688
+ anchor: r.anchor,
689
+ focus: n.index
690
+ }, c.value = !1, l.value = null, d();
691
+ return;
692
+ }
693
+ h(n.mode, n.index, t.pointerId);
694
+ }
695
+ function x(e) {
696
+ return f(e.target) || f(document.elementFromPoint(e.clientX, e.clientY));
697
+ }
698
+ function S(e) {
699
+ if (!i.value || !c.value || l.value !== null && l.value !== e.pointerId) return;
700
+ let t = x(e);
701
+ if (!t) return;
702
+ let n = s.value;
703
+ !n || t.mode !== n.mode || _(t.index);
704
+ }
705
+ function C(e) {
706
+ i.value && (l.value !== null && l.value !== e.pointerId || v());
707
+ }
708
+ function w(t) {
709
+ let i = r.value;
710
+ if (!i) return null;
711
+ let { start: a, end: o } = n(t.anchor, t.focus), s = i(a, o);
712
+ if (!s.length) return null;
713
+ if (t.mode === "ascii") {
714
+ let t = e.getPrintableChecker(), n = e.getAsciiRenderer(), r = e.getNonPrintableChar();
715
+ return Array.from(s, (e) => t(e) ? n(e) : r).join("");
716
+ }
717
+ let c = e.getUppercase();
718
+ return Array.from(s, (e) => {
719
+ let t = e.toString(16).padStart(2, "0");
720
+ return c ? t.toUpperCase() : t;
721
+ }).join(" ");
722
+ }
723
+ function T(e) {
724
+ typeof navigator < "u" && navigator.clipboard?.writeText && navigator.clipboard.writeText(e).catch(() => {
725
+ console.error("Failed to write text to clipboard.");
726
+ });
727
+ }
728
+ function D(e) {
729
+ if (!i.value) return;
730
+ let t = e.key.toLowerCase();
731
+ if ((e.ctrlKey || e.metaKey) && t === "c") {
732
+ let t = s.value;
733
+ if (!t) return;
734
+ let n = w(t);
735
+ if (!n) return;
736
+ e.preventDefault(), T(n);
737
+ return;
738
+ }
739
+ e.key === "Escape" && (e.preventDefault(), y());
740
+ }
741
+ return watch(e.markup, () => {
742
+ d();
743
+ }), watch(i, () => {
744
+ d();
745
+ }), onMounted(() => {
746
+ let t = e.containerEl.value;
747
+ t && (t.addEventListener("keydown", D), t.addEventListener("pointerdown", b)), typeof window < "u" && (window.addEventListener("pointermove", S), window.addEventListener("pointerup", C), window.addEventListener("pointercancel", C));
748
+ }), onBeforeUnmount(() => {
749
+ let t = e.containerEl.value;
750
+ t && (t.removeEventListener("keydown", D), t.removeEventListener("pointerdown", b)), typeof window < "u" && (window.removeEventListener("pointermove", S), window.removeEventListener("pointerup", C), window.removeEventListener("pointercancel", C)), u !== null && (cancelAnimationFrame(u), u = null);
751
+ }), {
752
+ selectionDataProvider: r,
753
+ selectionEnabled: i,
754
+ selectionRange: a,
755
+ selectionCount: o
756
+ };
757
+ }
758
+ var _hoisted_1$2 = { class: "vuehex-chunk-nav__header" }, _hoisted_2$2 = { class: "vuehex-chunk-nav__summary" }, _hoisted_3$1 = {
759
+ class: "vuehex-chunk-list",
760
+ role: "listbox"
761
+ }, _hoisted_4$1 = ["aria-selected", "onClick"], _hoisted_5$1 = { class: "vuehex-chunk-item__label" }, _hoisted_6$1 = { class: "vuehex-chunk-item__range" }, VueHexChunkNavigator_default = /* @__PURE__ */ defineComponent({
762
+ __name: "VueHexChunkNavigator",
763
+ props: {
764
+ show: {
765
+ type: Boolean,
766
+ default: !1
767
+ },
768
+ placement: { default: "right" },
769
+ chunks: {},
770
+ activeIndex: {},
771
+ rootClassExtra: { default: () => [] },
772
+ viewerClassExtra: { default: () => [] },
773
+ expandToContent: {
774
+ type: Boolean,
775
+ default: !1
776
+ }
777
+ },
778
+ emits: ["select"],
779
+ setup(n, { emit: o }) {
780
+ let s = n, c = o, l = computed(() => Math.max(0, Math.trunc(s.activeIndex))), d = computed(() => {
781
+ let e = s.placement ?? "right";
782
+ switch (e) {
783
+ case "left":
784
+ case "right":
785
+ case "top":
786
+ case "bottom": return e;
787
+ default: return "right";
788
+ }
789
+ }), f = computed(() => d.value === "top" || d.value === "bottom"), p = computed(() => !!s.show && Array.isArray(s.chunks) && s.chunks.length > 1), m = computed(() => {
790
+ let e = ["vuehex-root", ...s.rootClassExtra ?? []];
791
+ return s.expandToContent && e.push("vuehex-root--expand-to-content"), p.value && (e.push(f.value ? "vuehex-root--vertical" : "vuehex-root--horizontal"), e.push(`vuehex-root--nav-${d.value}`)), e;
792
+ }), g = computed(() => {
793
+ let e = ["vuehex-chunk-nav"];
794
+ return p.value && e.push(`vuehex-chunk-nav--${d.value}`), e;
795
+ }), y = computed(() => {
796
+ let e = ["vuehex-viewer", ...s.viewerClassExtra ?? []];
797
+ return p.value && (e.push("vuehex-viewer--with-nav"), e.push(`vuehex-viewer--nav-${d.value}`)), e;
798
+ });
799
+ function x(e) {
800
+ let t = ["vuehex-chunk-item"];
801
+ return e === l.value && t.push("vuehex-chunk-item--active"), t;
802
+ }
803
+ function S(e) {
804
+ Number.isFinite(e) && c("select", Math.trunc(e));
805
+ }
806
+ return (t, n) => (openBlock(), createElementBlock("div", { class: normalizeClass(m.value) }, [p.value ? (openBlock(), createElementBlock("nav", {
807
+ key: 0,
808
+ class: normalizeClass(g.value),
809
+ role: "navigation",
810
+ "aria-label": "Chunk navigator"
811
+ }, [createElementVNode("header", _hoisted_1$2, [renderSlot(t.$slots, "chunk-navigator-header", {
812
+ chunks: s.chunks,
813
+ activeIndex: l.value
814
+ }, () => [n[0] ||= createElementVNode("span", { class: "vuehex-chunk-nav__title" }, "Chunks", -1), createElementVNode("span", _hoisted_2$2, toDisplayString(s.chunks.length) + " chunks", 1)])]), createElementVNode("div", _hoisted_3$1, [(openBlock(!0), createElementBlock(Fragment, null, renderList(s.chunks, (e) => (openBlock(), createElementBlock("button", {
815
+ key: e.index,
816
+ type: "button",
817
+ role: "option",
818
+ "aria-selected": e.index === l.value,
819
+ class: normalizeClass(x(e.index)),
820
+ onClick: (t) => S(e.index)
821
+ }, [renderSlot(t.$slots, "chunk-navigator-item", {
822
+ chunk: e,
823
+ active: e.index === l.value,
824
+ select: () => S(e.index)
825
+ }, () => [createElementVNode("span", _hoisted_5$1, toDisplayString(e.label), 1), createElementVNode("span", _hoisted_6$1, toDisplayString(e.range), 1)])], 10, _hoisted_4$1))), 128))])], 2)) : createCommentVNode("", !0), createElementVNode("div", { class: normalizeClass(y.value) }, [renderSlot(t.$slots, "default")], 2)], 2));
826
+ }
827
+ }), VUEHEX_CATEGORY_DIGIT_CLASS = "vuehex-category-digit", VUEHEX_CATEGORY_UPPERCASE_CLASS = "vuehex-category-uppercase", VUEHEX_CATEGORY_LOWERCASE_CLASS = "vuehex-category-lowercase", VUEHEX_CATEGORY_NULL_CLASS = "vuehex-category-null", VUEHEX_CATEGORY_ERASED_CLASS = "vuehex-category-erased", VUEHEX_CATEGORY_CONTROL_CLASS = "vuehex-category-control", VUEHEX_CATEGORY_HIGHBIT_CLASS = "vuehex-category-highbit";
828
+ const DEFAULT_ASCII_CATEGORY_CELL_CLASS_RESOLVER = ({ byte: e }) => {
829
+ if (e >= 48 && e <= 57) return VUEHEX_CATEGORY_DIGIT_CLASS;
830
+ if (e >= 65 && e <= 90) return VUEHEX_CATEGORY_UPPERCASE_CLASS;
831
+ if (e >= 97 && e <= 122) return VUEHEX_CATEGORY_LOWERCASE_CLASS;
832
+ if (e === 0) return VUEHEX_CATEGORY_NULL_CLASS;
833
+ if (e === 255) return VUEHEX_CATEGORY_ERASED_CLASS;
834
+ if (e >= 1 && e <= 31 || e === 127) return VUEHEX_CATEGORY_CONTROL_CLASS;
835
+ if (e >= 128 && e <= 254) return VUEHEX_CATEGORY_HIGHBIT_CLASS;
836
+ }, DEFAULT_PRINTABLE_CHECK = (e) => e >= 32 && e <= 126, DEFAULT_ASCII_RENDERER = (e) => String.fromCharCode(e), VUE_HEX_ASCII_PRESETS = Object.freeze({
837
+ standard: {
838
+ label: "Standard ASCII (0x20-0x7E)",
839
+ isPrintable: DEFAULT_PRINTABLE_CHECK,
840
+ renderAscii: DEFAULT_ASCII_RENDERER
841
+ },
842
+ latin1: {
843
+ label: "Latin-1 Supplement (0x20-0x7E, 0xA0-0xFF)",
844
+ isPrintable: (e) => DEFAULT_PRINTABLE_CHECK(e) || e >= 160 && e <= 255,
845
+ renderAscii: DEFAULT_ASCII_RENDERER
846
+ },
847
+ visibleWhitespace: {
848
+ label: "Visible ASCII + whitespace glyphs",
849
+ isPrintable: (e) => DEFAULT_PRINTABLE_CHECK(e) || e === 9 || e === 10 || e === 13,
850
+ renderAscii: (e) => {
851
+ switch (e) {
852
+ case 9: return "⇥";
853
+ case 10: return "␊";
854
+ case 13: return "␍";
855
+ case 32: return "␠";
856
+ default: return String.fromCharCode(e);
857
+ }
858
+ }
859
+ }
860
+ });
861
+ var _hoisted_1$1 = { class: "vuehex-statusbar__section vuehex-statusbar__section--left" }, _hoisted_2$1 = { class: "vuehex-statusbar__label" }, _hoisted_3 = { class: "vuehex-statusbar__section vuehex-statusbar__section--middle" }, _hoisted_4 = { class: "vuehex-statusbar__label" }, _hoisted_5 = { class: "vuehex-statusbar__section vuehex-statusbar__section--right" }, _hoisted_6 = { class: "vuehex-statusbar__label" }, VueHexStatusBar_default = /* @__PURE__ */ defineComponent({
862
+ __name: "VueHexStatusBar",
863
+ props: {
864
+ placement: {},
865
+ layout: { default: null },
866
+ uppercase: {
867
+ type: Boolean,
868
+ default: !1
869
+ },
870
+ isPrintable: {
871
+ type: Function,
872
+ default: void 0
873
+ },
874
+ renderAscii: {
875
+ type: Function,
876
+ default: void 0
877
+ },
878
+ nonPrintableChar: { default: "." },
879
+ selectionRange: { default: null },
880
+ selectionCount: { default: 0 }
881
+ },
882
+ setup(n, { expose: r }) {
883
+ let o = n, s = useSlots();
884
+ function c(e, t) {
885
+ let n = Math.max(0, Math.min(255, Math.trunc(e))).toString(16).padStart(2, "0");
886
+ return t ? n.toUpperCase() : n;
887
+ }
888
+ let l = ref(null), d = computed(() => l.value?.index ?? null), p = computed(() => l.value ? c(l.value.byte, !!o.uppercase) : ""), m = computed(() => {
889
+ if (!l.value) return "";
890
+ let e = l.value.byte, t = o.isPrintable ?? DEFAULT_PRINTABLE_CHECK, n = o.renderAscii ?? DEFAULT_ASCII_RENDERER, r = o.nonPrintableChar;
891
+ return t(e) ? n(e) : r;
892
+ }), y = computed(() => {
893
+ let e = o.selectionRange, t = o.selectionCount;
894
+ return !e || t <= 0 ? "" : `${t} bytes (${e.start}–${e.end})`;
895
+ });
896
+ r({ handleHoverEvent: (e, t) => {
897
+ if (e === "hex-hover-on" || e === "ascii-hover-on") {
898
+ let e = t, n = Number(e?.index), r = Number(e?.byte);
899
+ Number.isFinite(n) && Number.isFinite(r) && (l.value = {
900
+ index: Math.trunc(n),
901
+ byte: Math.trunc(r)
902
+ });
903
+ return;
904
+ }
905
+ if (e === "hex-hover-off" || e === "ascii-hover-off") {
906
+ let e = l.value;
907
+ if (!e) return;
908
+ let n = t, r = Number(n?.index);
909
+ (!Number.isFinite(r) || Math.trunc(r) === e.index) && (l.value = null);
910
+ }
911
+ } });
912
+ let x = computed(() => {
913
+ let e = ["vuehex-statusbar"];
914
+ return e.push(o.placement === "top" ? "vuehex-statusbar--top" : "vuehex-statusbar--bottom"), e;
915
+ }), S = computed(() => ({ order: o.placement === "top" ? 0 : 2 }));
916
+ function C(e) {
917
+ if (typeof e == "string") {
918
+ let t = e.trim();
919
+ return t ? { name: t } : null;
920
+ }
921
+ if (!e || typeof e != "object") return null;
922
+ let t = e, n = typeof t.name == "string" ? t.name.trim() : "";
923
+ return n ? {
924
+ name: n,
925
+ config: t.config
926
+ } : null;
927
+ }
928
+ function E(e, t) {
929
+ let n = e?.[t];
930
+ return Array.isArray(n) ? n : [];
931
+ }
932
+ let D = computed(() => {
933
+ let e = o.layout;
934
+ return e ? {
935
+ left: E(e, "left"),
936
+ middle: E(e, "middle"),
937
+ right: E(e, "right")
938
+ } : {
939
+ left: [
940
+ "offset",
941
+ "hex",
942
+ "ascii"
943
+ ],
944
+ middle: [],
945
+ right: ["selection"]
946
+ };
947
+ }), O = computed(() => {
948
+ let e = (e) => (D.value[e] ?? []).map(C).filter((e) => e !== null);
949
+ return {
950
+ left: e("left"),
951
+ middle: e("middle"),
952
+ right: e("right")
953
+ };
954
+ });
955
+ function k(e) {
956
+ return e === "offset" || e === "hex" || e === "ascii" || e === "selection" || e === "slot";
957
+ }
958
+ function A(e, t) {
959
+ if (!e || typeof e != "object") return null;
960
+ let n = e[t];
961
+ return typeof n == "string" ? n : null;
962
+ }
963
+ function j(e, t) {
964
+ if (!e || typeof e != "object") return null;
965
+ let n = e[t];
966
+ return typeof n == "boolean" ? n : null;
967
+ }
968
+ function M(e, t) {
969
+ if (!e || typeof e != "object") return null;
970
+ let n = e[t];
971
+ return typeof n == "number" && Number.isFinite(n) ? n : null;
972
+ }
973
+ function pe(e, t) {
974
+ if (e === null) return "";
975
+ if (A(t, "format") === "decimal") return String(Math.max(0, Math.trunc(e)));
976
+ let n = !!o.uppercase, r = Math.max(0, Math.trunc(M(t, "pad") ?? 0)), i = Math.max(0, Math.trunc(e)).toString(16), a = (n ? i.toUpperCase() : i).padStart(r, "0");
977
+ return j(t, "prefix") ?? !0 ? `0x${a}` : a;
978
+ }
979
+ function N(e, t) {
980
+ return e ? j(t, "prefix") ? `0x${e}` : e : "";
981
+ }
982
+ function P(e, t) {
983
+ return e ? j(t, "quote") ? `'${e}'` : e : "";
984
+ }
985
+ function F(e) {
986
+ return e === "left" ? "statusbar-left" : e === "middle" ? "statusbar-middle" : "statusbar-right";
987
+ }
988
+ function me(e) {
989
+ return e === "slot" ? null : e === "offset" ? "10ch" : e === "hex" ? "4ch" : e === "ascii" ? "3ch" : null;
990
+ }
991
+ function I(e, t) {
992
+ if (e === "slot") return;
993
+ let n = A(t, "valueWidth"), r = A(t, "valueMinWidth"), i = me(e), a = {};
994
+ return n && (a.width = n), r ? a.minWidth = r : !n && i && (a.minWidth = i), (a.width || a.minWidth) && (a.whiteSpace = "nowrap", a.overflow = "hidden", a.textOverflow = "ellipsis"), Object.keys(a).length ? a : void 0;
995
+ }
996
+ function L(e, t, n) {
997
+ let r = e.name.trim();
998
+ if (!k(r)) return null;
999
+ if (r === "slot") {
1000
+ let e = F(t);
1001
+ return {
1002
+ kind: "slot",
1003
+ key: n,
1004
+ slotName: e,
1005
+ visible: !!s[e]
1006
+ };
1007
+ }
1008
+ let i = A(e.config, "label") ?? (r === "offset" ? "Offset" : r === "hex" ? "Hex" : r === "ascii" ? "ASCII" : "Selection");
1009
+ if (r === "offset") return {
1010
+ kind: "builtin",
1011
+ key: n,
1012
+ name: r,
1013
+ label: i,
1014
+ value: pe(d.value, e.config),
1015
+ visible: !0,
1016
+ valueStyle: I(r, e.config)
1017
+ };
1018
+ if (r === "hex") return {
1019
+ kind: "builtin",
1020
+ key: n,
1021
+ name: r,
1022
+ label: i,
1023
+ value: N(p.value, e.config),
1024
+ visible: !0,
1025
+ valueStyle: I(r, e.config)
1026
+ };
1027
+ if (r === "ascii") return {
1028
+ kind: "builtin",
1029
+ key: n,
1030
+ name: r,
1031
+ label: i,
1032
+ value: P(m.value, e.config),
1033
+ visible: !0,
1034
+ valueStyle: I(r, e.config)
1035
+ };
1036
+ let a = y.value;
1037
+ return {
1038
+ kind: "builtin",
1039
+ key: n,
1040
+ name: r,
1041
+ label: i,
1042
+ value: a,
1043
+ visible: j(e.config, "showWhenEmpty") ? !0 : !!a,
1044
+ valueStyle: I(r, e.config)
1045
+ };
1046
+ }
1047
+ function R(e) {
1048
+ return O.value[e].map((t, n) => L(t, e, `${e}-${n}`)).filter((e) => e !== null);
1049
+ }
1050
+ let z = computed(() => ({
1051
+ left: R("left"),
1052
+ middle: R("middle"),
1053
+ right: R("right")
1054
+ }));
1055
+ return (t, n) => (openBlock(), createElementBlock("div", {
1056
+ class: normalizeClass(x.value),
1057
+ style: normalizeStyle(S.value),
1058
+ role: "status",
1059
+ "aria-live": "polite"
1060
+ }, [
1061
+ createElementVNode("div", _hoisted_1$1, [(openBlock(!0), createElementBlock(Fragment, null, renderList(z.value.left, (n) => withDirectives((openBlock(), createElementBlock("span", {
1062
+ key: n.key,
1063
+ class: "vuehex-statusbar__item"
1064
+ }, [n.kind === "slot" ? renderSlot(t.$slots, n.slotName, { key: 0 }) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createElementVNode("span", _hoisted_2$1, toDisplayString(n.label), 1), createElementVNode("span", {
1065
+ class: "vuehex-statusbar__value",
1066
+ style: normalizeStyle(n.valueStyle)
1067
+ }, toDisplayString(n.value), 5)], 64))])), [[vShow, n.visible]])), 128))]),
1068
+ createElementVNode("div", _hoisted_3, [(openBlock(!0), createElementBlock(Fragment, null, renderList(z.value.middle, (n) => withDirectives((openBlock(), createElementBlock("span", {
1069
+ key: n.key,
1070
+ class: "vuehex-statusbar__item"
1071
+ }, [n.kind === "slot" ? renderSlot(t.$slots, n.slotName, { key: 0 }) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createElementVNode("span", _hoisted_4, toDisplayString(n.label), 1), createElementVNode("span", {
1072
+ class: "vuehex-statusbar__value",
1073
+ style: normalizeStyle(n.valueStyle)
1074
+ }, toDisplayString(n.value), 5)], 64))])), [[vShow, n.visible]])), 128))]),
1075
+ createElementVNode("div", _hoisted_5, [(openBlock(!0), createElementBlock(Fragment, null, renderList(z.value.right, (n) => withDirectives((openBlock(), createElementBlock("span", {
1076
+ key: n.key,
1077
+ class: "vuehex-statusbar__item"
1078
+ }, [n.kind === "slot" ? renderSlot(t.$slots, n.slotName, { key: 0 }) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createElementVNode("span", _hoisted_6, toDisplayString(n.label), 1), createElementVNode("span", {
1079
+ class: "vuehex-statusbar__value",
1080
+ style: normalizeStyle(n.valueStyle)
1081
+ }, toDisplayString(n.value), 5)], 64))])), [[vShow, n.visible]])), 128))])
1082
+ ], 6));
1083
+ }
1084
+ }), _hoisted_1 = ["aria-disabled", "tabindex"], _hoisted_2 = ["innerHTML"], DEFAULT_ROW_HEIGHT = 24, MAX_VIRTUAL_HEIGHT = 8e6, VueHex_default = /* @__PURE__ */ defineComponent({
1085
+ __name: "VueHex",
1086
+ props: /* @__PURE__ */ mergeModels({
1087
+ dataMode: { default: "auto" },
1088
+ expandToContent: {
1089
+ type: Boolean,
1090
+ default: !1
1091
+ },
1092
+ totalSize: {},
1093
+ bytesPerRow: { default: 16 },
1094
+ uppercase: {
1095
+ type: Boolean,
1096
+ default: !1
1097
+ },
1098
+ nonPrintableChar: { default: "." },
1099
+ overscan: { default: 2 },
1100
+ isPrintable: {
1101
+ type: Function,
1102
+ default: DEFAULT_PRINTABLE_CHECK
1103
+ },
1104
+ renderAscii: {
1105
+ type: Function,
1106
+ default: DEFAULT_ASCII_RENDERER
1107
+ },
1108
+ theme: {},
1109
+ cellClassForByte: {},
1110
+ getSelectionData: {},
1111
+ showChunkNavigator: {
1112
+ type: Boolean,
1113
+ default: !1
1114
+ },
1115
+ chunkNavigatorPlacement: { default: "right" },
1116
+ statusbar: { default: null },
1117
+ cursor: {
1118
+ type: Boolean,
1119
+ default: !1
1120
+ },
1121
+ statusbarLayout: { default: null }
1122
+ }, {
1123
+ windowOffset: { default: 0 },
1124
+ windowOffsetModifiers: {},
1125
+ modelValue: { default: new Uint8Array() },
1126
+ modelModifiers: {},
1127
+ cursorLocation: { default: null },
1128
+ cursorLocationModifiers: {}
1129
+ }),
1130
+ emits: /* @__PURE__ */ mergeModels([
1131
+ "updateVirtualData",
1132
+ "byte-click",
1133
+ "selection-change",
1134
+ "row-hover-on",
1135
+ "row-hover-off",
1136
+ "hex-hover-on",
1137
+ "hex-hover-off",
1138
+ "ascii-hover-on",
1139
+ "ascii-hover-off"
1140
+ ], [
1141
+ "update:windowOffset",
1142
+ "update:modelValue",
1143
+ "update:cursorLocation"
1144
+ ]),
1145
+ setup(e, { expose: i, emit: o }) {
1146
+ let c = useModel(e, "windowOffset"), l = useModel(e, "modelValue"), _ = useModel(e, "cursorLocation"), y = e, b = o, w = computed(() => !!y.expandToContent), T = computed(() => w.value ? 0 : Math.max(0, Math.trunc(c.value ?? 0))), fe = computed(() => l.value?.length ?? 0), { isWindowed: O, isSelfManaged: k } = useDataMode({
1147
+ dataMode: toRef(y, "dataMode"),
1148
+ isExpandToContent: w,
1149
+ windowOffset: T,
1150
+ totalSize: toRef(y, "totalSize"),
1151
+ dataLength: fe
1152
+ }), j = computed(() => ({
1153
+ offset: k.value ? 0 : T.value,
1154
+ data: l.value
1155
+ })), M = computed(() => {
1156
+ if (w.value) return j.value.data.length;
1157
+ let e = y.totalSize;
1158
+ return typeof e == "number" && Number.isFinite(e) ? Math.max(0, Math.trunc(e)) : j.value.data.length;
1159
+ }), pe = computed(() => O.value), N = computed(() => !!y.uppercase), P = computed(() => y.isPrintable ?? DEFAULT_PRINTABLE_CHECK), F = computed(() => y.renderAscii ?? DEFAULT_ASCII_RENDERER), L = computed(() => y.nonPrintableChar ?? "."), B = computed(() => w.value ? Infinity : MAX_VIRTUAL_HEIGHT), V = ref(), H = ref(), he = ref(null), U = ref(0), W = computed(() => clampBytesPerRow(y.bytesPerRow)), G = computed(() => he.value ?? DEFAULT_ROW_HEIGHT), K = computed(() => w.value || U.value <= 0 ? 0 : Math.max(1, Math.ceil(U.value / G.value))), q = computed(() => Math.max(0, Math.trunc(y.overscan))), ge = computed(() => {
1160
+ let e = normalizeThemeKey(y.theme);
1161
+ return e ? [
1162
+ "default",
1163
+ "deep-space",
1164
+ "deep_space",
1165
+ "deepspace",
1166
+ "dark-mode",
1167
+ "darkmode"
1168
+ ].includes(e) ? "dark" : [
1169
+ "light",
1170
+ "daylight",
1171
+ "light-mode",
1172
+ "lightmode"
1173
+ ].includes(e) ? "light" : e : null;
1174
+ }), J = computed(() => {
1175
+ let e = ge.value;
1176
+ return !e || e === "auto" ? ["vuehex-theme-auto"] : [`vuehex-theme-${e}`];
1177
+ }), _e = computed(() => {
1178
+ let e = ["vuehex"];
1179
+ return e.push(...J.value), w.value && e.push("vuehex--expand-to-content"), He.value || e.push("vuehex-selection-disabled"), e;
1180
+ }), ve = computed(() => ["vuehex-table"]), { chunkStartRow: Y, activeChunkIndex: ye, chunkRowCount: be, chunkHeight: xe, chunkItems: Se, clampChunkStartToBounds: Ce, ensureChunkForRow: we, selectChunk: Te } = useChunking({
1181
+ showNavigator: computed(() => !!y.showChunkNavigator),
1182
+ totalBytes: M,
1183
+ bytesPerRow: W,
1184
+ rowHeightValue: G,
1185
+ maxVirtualHeight: B,
1186
+ uppercase: N
1187
+ }), Ee = computed(() => [...J.value]), De = computed(() => y.statusbar === "top" || y.statusbar === "bottom"), Oe = computed(() => y.statusbar === "top" ? "top" : "bottom"), ke = computed(() => {
1188
+ let e = [];
1189
+ return De.value && (e.push("vuehex-viewer--with-statusbar"), e.push(Oe.value === "top" ? "vuehex-viewer--statusbar-top" : "vuehex-viewer--statusbar-bottom")), e;
1190
+ }), Ae = ref(null), { handlePointerOver: je, handlePointerOut: Me, clearHoverState: Ne } = useHoverLinking({
1191
+ emit: (e, t) => {
1192
+ Ae.value?.handleHoverEvent(e, t), b(e, t);
1193
+ },
1194
+ tbodyEl: H
1195
+ }), Pe = computed(() => {
1196
+ let e = y.cellClassForByte;
1197
+ if (e === void 0) return DEFAULT_ASCII_CATEGORY_CELL_CLASS_RESOLVER;
1198
+ if (e !== null) {
1199
+ if (typeof e == "function") return e;
1200
+ if (Array.isArray(e)) {
1201
+ let t = e.filter((e) => typeof e == "function");
1202
+ return t.length === 0 ? void 0 : (e) => {
1203
+ let n = [];
1204
+ for (let r of t) {
1205
+ let t = r(e);
1206
+ t != null && n.push(t);
1207
+ }
1208
+ if (n.length !== 0) return n.flat();
1209
+ };
1210
+ }
1211
+ }
1212
+ }), { markup: X, renderStartRow: Fe, scheduleWindowEvaluation: Z, handleScroll: Ie, scrollToByte: Le, queueScrollToOffset: Re, updateFromWindowState: ze, updateRenderedSlice: Be, measureRowHeight: Ve } = useHexWindow({
1213
+ containerEl: V,
1214
+ tbodyEl: H,
1215
+ bytesPerRow: W,
1216
+ rowHeight: he,
1217
+ rowHeightValue: G,
1218
+ viewportRows: K,
1219
+ overscanRows: q,
1220
+ chunkStartRow: Y,
1221
+ chunkRowCount: be,
1222
+ totalBytes: M,
1223
+ ensureChunkForRow: we,
1224
+ clampChunkStartToBounds: Ce,
1225
+ getWindowState: () => j.value,
1226
+ getUppercase: () => N.value,
1227
+ getPrintableChecker: () => P.value,
1228
+ getAsciiRenderer: () => F.value,
1229
+ getCellClassResolver: () => Pe.value,
1230
+ getNonPrintableChar: () => L.value,
1231
+ getSelectionRange: () => Q.value,
1232
+ requestWindow: (e) => {
1233
+ pe.value && (c.value = e.offset, b("updateVirtualData", e));
1234
+ },
1235
+ clearHoverState: Ne
1236
+ }), { selectionEnabled: He, selectionRange: Q, selectionCount: Ue } = useSelection({
1237
+ containerEl: V,
1238
+ tbodyEl: H,
1239
+ markup: X,
1240
+ getSelectionDataProp: () => y.getSelectionData,
1241
+ isSelfManagedData: k,
1242
+ totalBytes: M,
1243
+ getSelfManagedBytes: () => j.value.data,
1244
+ getUppercase: () => N.value,
1245
+ getPrintableChecker: () => P.value,
1246
+ getAsciiRenderer: () => F.value,
1247
+ getNonPrintableChar: () => L.value,
1248
+ updateRenderedSlice: Be,
1249
+ emitByteClick: (e) => b("byte-click", e),
1250
+ emitSelectionChange: (e) => b("selection-change", e)
1251
+ }), We = computed(() => !!y.cursor);
1252
+ useCursor({
1253
+ enabled: We,
1254
+ isExpandToContent: w,
1255
+ containerEl: V,
1256
+ tbodyEl: H,
1257
+ markup: X,
1258
+ totalBytes: M,
1259
+ bytesPerRow: W,
1260
+ rowHeightValue: G,
1261
+ viewportRows: K,
1262
+ chunkStartRow: Y,
1263
+ ensureChunkForRow: we,
1264
+ scheduleWindowEvaluation: Z,
1265
+ cursorLocation: _,
1266
+ scrollToByte: Le
1267
+ });
1268
+ let Ge = computed(() => He.value || We.value);
1269
+ function Ke() {
1270
+ if (!w.value && (Ie(), k.value)) {
1271
+ let e = V.value;
1272
+ if (e) {
1273
+ let t = e.scrollTop, n = Math.floor(t / G.value), r = (Y.value + n) * W.value;
1274
+ r !== c.value && (c.value = r);
1275
+ }
1276
+ }
1277
+ }
1278
+ let qe = computed(() => w.value ? 0 : (Fe.value - Y.value) * G.value), Je = computed(() => ({
1279
+ position: "relative",
1280
+ width: "100%",
1281
+ ...w.value ? {} : { height: `${Math.max(xe.value, 0)}px` }
1282
+ })), Ye = computed(() => {
1283
+ if (w.value) return {
1284
+ position: "static",
1285
+ width: "100%",
1286
+ transform: "none"
1287
+ };
1288
+ let e = qe.value;
1289
+ return {
1290
+ position: "absolute",
1291
+ top: "0px",
1292
+ left: "0px",
1293
+ right: "0px",
1294
+ width: "100%",
1295
+ transform: Number.isFinite(e) ? `translateY(${e}px)` : "translateY(0px)"
1296
+ };
1297
+ });
1298
+ function Xe(e) {
1299
+ if (!Te(e)) return;
1300
+ let t = V.value;
1301
+ t && (t.scrollTop = 0), k.value && (c.value = Y.value * W.value), Z();
1302
+ }
1303
+ watch(() => ({
1304
+ data: j.value.data,
1305
+ offset: j.value.offset,
1306
+ bytesPerRow: W.value,
1307
+ uppercase: y.uppercase,
1308
+ nonPrintableChar: y.nonPrintableChar,
1309
+ isPrintable: y.isPrintable,
1310
+ renderAscii: y.renderAscii,
1311
+ cellClassForByte: Pe.value
1312
+ }), () => {
1313
+ ze();
1314
+ }, { immediate: !0 }), watch(() => c.value, (e, t) => {
1315
+ e !== t && e != null && Number.isFinite(e) && e >= 0 && Re(e);
1316
+ }), watch([
1317
+ M,
1318
+ W,
1319
+ K,
1320
+ q,
1321
+ B,
1322
+ Y
1323
+ ], () => {
1324
+ Ce(), Z();
1325
+ });
1326
+ let $ = null;
1327
+ return onMounted(() => {
1328
+ let e = V.value;
1329
+ e && (U.value = e.clientHeight, $ = new ResizeObserver((e) => {
1330
+ let t = e[0];
1331
+ t && (U.value = t.contentRect.height, Z(), Ve());
1332
+ }), $.observe(e));
1333
+ let t = H.value;
1334
+ t && (t.addEventListener("pointerover", je), t.addEventListener("pointerout", Me)), Re(j.value.offset);
1335
+ }), onBeforeUnmount(() => {
1336
+ $?.disconnect(), $ = null;
1337
+ let e = H.value;
1338
+ e && (e.removeEventListener("pointerover", je), e.removeEventListener("pointerout", Me)), Ne();
1339
+ }), i({
1340
+ scrollToByte: Le,
1341
+ selectChunk: Te
1342
+ }), (e, t) => (openBlock(), createBlock(VueHexChunkNavigator_default, {
1343
+ show: y.showChunkNavigator,
1344
+ placement: y.chunkNavigatorPlacement,
1345
+ chunks: unref(Se),
1346
+ "active-index": unref(ye),
1347
+ "root-class-extra": Ee.value,
1348
+ "viewer-class-extra": ke.value,
1349
+ "expand-to-content": w.value,
1350
+ onSelect: Xe
1351
+ }, {
1352
+ "chunk-navigator-header": withCtx((t) => [renderSlot(e.$slots, "chunk-navigator-header", normalizeProps(guardReactiveProps(t)))]),
1353
+ "chunk-navigator-item": withCtx((t) => [renderSlot(e.$slots, "chunk-navigator-item", normalizeProps(guardReactiveProps(t)))]),
1354
+ default: withCtx(() => [De.value ? (openBlock(), createBlock(VueHexStatusBar_default, {
1355
+ key: 0,
1356
+ ref_key: "statusBarRef",
1357
+ ref: Ae,
1358
+ placement: Oe.value,
1359
+ layout: y.statusbarLayout,
1360
+ uppercase: y.uppercase,
1361
+ "is-printable": y.isPrintable,
1362
+ "render-ascii": y.renderAscii,
1363
+ "non-printable-char": y.nonPrintableChar,
1364
+ "selection-range": unref(Q),
1365
+ "selection-count": unref(Ue)
1366
+ }, {
1367
+ "statusbar-left": withCtx(() => [renderSlot(e.$slots, "statusbar-left")]),
1368
+ "statusbar-middle": withCtx(() => [renderSlot(e.$slots, "statusbar-middle")]),
1369
+ "statusbar-right": withCtx(() => [renderSlot(e.$slots, "statusbar-right")]),
1370
+ _: 3
1371
+ }, 8, [
1372
+ "placement",
1373
+ "layout",
1374
+ "uppercase",
1375
+ "is-printable",
1376
+ "render-ascii",
1377
+ "non-printable-char",
1378
+ "selection-range",
1379
+ "selection-count"
1380
+ ])) : createCommentVNode("", !0), createElementVNode("div", {
1381
+ ref_key: "containerEl",
1382
+ ref: V,
1383
+ class: normalizeClass(_e.value),
1384
+ role: "table",
1385
+ "aria-label": "Hex viewer",
1386
+ "aria-disabled": Ge.value ? void 0 : "true",
1387
+ tabindex: Ge.value ? 0 : void 0,
1388
+ onScroll: Ke
1389
+ }, [createElementVNode("div", {
1390
+ class: "vuehex-inner",
1391
+ style: normalizeStyle(Je.value),
1392
+ role: "presentation"
1393
+ }, [createElementVNode("table", {
1394
+ class: normalizeClass(ve.value),
1395
+ style: normalizeStyle(Ye.value),
1396
+ role: "presentation"
1397
+ }, [createElementVNode("tbody", {
1398
+ ref_key: "tbodyEl",
1399
+ ref: H,
1400
+ innerHTML: unref(X)
1401
+ }, null, 8, _hoisted_2)], 6)], 4)], 42, _hoisted_1)]),
1402
+ _: 3
1403
+ }, 8, [
1404
+ "show",
1405
+ "placement",
1406
+ "chunks",
1407
+ "active-index",
1408
+ "root-class-extra",
1409
+ "viewer-class-extra",
1410
+ "expand-to-content"
1411
+ ]));
1412
+ }
1413
+ });
1414
+ function install(e, t = {}) {
1415
+ let n = t.componentName ?? "VueHex";
1416
+ e.component(n, VueHex_default);
1417
+ }
1418
+ var src_default = { install };
1419
+ export { DEFAULT_ASCII_CATEGORY_CELL_CLASS_RESOLVER, DEFAULT_ASCII_RENDERER, DEFAULT_PRINTABLE_CHECK, VUE_HEX_ASCII_PRESETS, VueHex_default as VueHex, src_default as default, install };