@pkistudio/asn1defsifter 0.1.0

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/app.js ADDED
@@ -0,0 +1,821 @@
1
+ import De from "@pkistudio/pkistudiojs/viewer";
2
+ import ze from "@pkistudio/pkistudiojs/oid-resolver";
3
+ import { f as Pe, a as D, c as Te } from "./pki-report-CX5tXXqU.js";
4
+ const se = 80, We = "clipboard.hex", me = 640, qe = `
5
+ :host {
6
+ --window: transparent !important;
7
+ --panel: rgb(255 255 255 / 58%) !important;
8
+ --panel-border: rgb(185 196 208 / 0%) !important;
9
+ --chrome-start: rgb(255 255 255 / 60%) !important;
10
+ --chrome: rgb(238 243 248 / 42%) !important;
11
+ --subtle-border: rgb(214 222 230 / 54%) !important;
12
+ }
13
+
14
+ @media (prefers-color-scheme: dark) {
15
+ :host {
16
+ --window: transparent !important;
17
+ --panel: rgb(37 43 52 / 46%) !important;
18
+ --panel-border: rgb(79 90 104 / 0%) !important;
19
+ --chrome-start: rgb(48 55 67 / 50%) !important;
20
+ --chrome: rgb(37 44 54 / 34%) !important;
21
+ --subtle-border: rgb(119 132 150 / 34%) !important;
22
+ }
23
+ }
24
+
25
+ :host([data-pkistudio-theme="dark"]) {
26
+ --window: transparent !important;
27
+ --panel: rgb(37 43 52 / 46%) !important;
28
+ --panel-border: rgb(79 90 104 / 0%) !important;
29
+ --chrome-start: rgb(48 55 67 / 50%) !important;
30
+ --chrome: rgb(37 44 54 / 34%) !important;
31
+ --subtle-border: rgb(119 132 150 / 34%) !important;
32
+ }
33
+
34
+ .menu,
35
+ .card {
36
+ box-shadow: none !important;
37
+ }
38
+
39
+ .menu {
40
+ border: 1px solid var(--subtle-border) !important;
41
+ border-radius: 3px !important;
42
+ background: linear-gradient(var(--chrome-start), var(--chrome)) !important;
43
+ }
44
+
45
+ .card {
46
+ border: 0 !important;
47
+ }
48
+
49
+ .card,
50
+ .viewer {
51
+ background: transparent !important;
52
+ }
53
+
54
+ .node-context-menu,
55
+ .node-context-submenu {
56
+ border: 1px solid var(--panel-border) !important;
57
+ background: rgb(255 255 255 / 98%) !important;
58
+ box-shadow: 0 10px 28px rgb(15 23 42 / 28%) !important;
59
+ }
60
+
61
+ @media (prefers-color-scheme: dark) {
62
+ .node-context-menu,
63
+ .node-context-submenu {
64
+ background: rgb(37 43 52 / 98%) !important;
65
+ }
66
+ }
67
+
68
+ :host([data-pkistudio-theme="dark"]) .node-context-menu,
69
+ :host([data-pkistudio-theme="dark"]) .node-context-submenu {
70
+ background: rgb(37 43 52 / 98%) !important;
71
+ }
72
+ `;
73
+ function Ie(e = {}) {
74
+ var ie, oe;
75
+ const t = Mt(e.mount ?? "#app"), n = {
76
+ report: null,
77
+ sourceName: null,
78
+ bytes: null,
79
+ logs: [],
80
+ selectedRootCandidates: /* @__PURE__ */ new Map(),
81
+ selectedSubtreeCandidates: /* @__PURE__ */ new Map()
82
+ };
83
+ t.innerHTML = `
84
+ <main class="ads-shell" data-theme="${e.theme ?? "light"}">
85
+ <nav class="ads-toolbar" aria-label="Application toolbar">
86
+ <strong>ASN.1 Definition Sifter</strong>
87
+ <button id="adsAboutButton" type="button">About</button>
88
+ </nav>
89
+ <section class="ads-workspace" aria-label="ASN.1 Definition Sifter workspace">
90
+ <section class="ads-viewer-pane" aria-label="PkiStudioJS viewer">
91
+ <div id="adsInputViewer" class="ads-input-viewer"></div>
92
+ </section>
93
+ <div id="adsWorkspaceResizer" class="ads-workspace-resizer" role="separator" aria-label="Resize viewer and candidates" aria-orientation="vertical" tabindex="0"></div>
94
+ <section class="ads-pane ads-candidate-pane" aria-label="Candidate results">
95
+ <header class="ads-pane-menu">
96
+ <strong>Candidates</strong>
97
+ </header>
98
+ <div class="ads-candidate-split">
99
+ <div id="adsCandidateTree" class="ads-pane-content ads-tree" aria-label="Candidate tree">No candidate report yet.</div>
100
+ </div>
101
+ <div id="adsCandidateNotice" class="ads-notice" role="status">Candidate results will appear after input is loaded.</div>
102
+ </section>
103
+ </section>
104
+ <div id="adsSelectedPaneResizer" class="ads-selected-pane-resizer" role="separator" aria-label="Resize selected candidate" aria-orientation="horizontal" tabindex="0"></div>
105
+ <section class="ads-selected-pane" aria-label="Selected candidate details">
106
+ <header class="ads-selected-header">
107
+ <strong>Selected Candidate</strong>
108
+ <span id="adsSelectedCandidateSummary">None</span>
109
+ <button id="adsCopySelectedCandidateButton" type="button" disabled>Copy</button>
110
+ </header>
111
+ <div id="adsCandidateDetail" class="ads-selected-detail">Select a candidate to inspect evidence, diagnostics, ambiguities, matched paths, and bytes.</div>
112
+ </section>
113
+ <div id="adsApiLogResizer" class="ads-api-log-resizer" role="separator" aria-label="Resize API log" aria-orientation="horizontal" tabindex="0"></div>
114
+ <section class="ads-log-pane" aria-label="API log">
115
+ <header class="ads-log-menu">
116
+ <button id="adsClearLogButton" type="button">Clear</button>
117
+ </header>
118
+ <ol id="adsApiLog" class="ads-api-log" aria-live="polite"></ol>
119
+ </section>
120
+ <dialog id="adsAboutDialog" class="ads-about-dialog">
121
+ <section class="ads-about-panel">
122
+ <div>
123
+ <div class="ads-about-name">ASN.1 Definition Sifter</div>
124
+ <div class="ads-about-module">@pkistudio/asn1defsifter</div>
125
+ </div>
126
+ <p>Rank ASN.1 definition candidates for DER and TLV fragments with explainable evidence.</p>
127
+ <form method="dialog">
128
+ <button id="adsCloseAboutButton" type="button">Close</button>
129
+ </form>
130
+ </section>
131
+ </dialog>
132
+ </main>
133
+ `;
134
+ const i = h(t, "#adsAboutButton"), o = h(t, "#adsAboutDialog"), r = h(t, "#adsCloseAboutButton"), s = h(t, "#adsClearLogButton"), a = h(t, "#adsInputViewer");
135
+ e.theme && a.setAttribute("data-pkistudio-theme", e.theme);
136
+ const d = h(t, "#adsCandidateTree"), c = h(t, "#adsSelectedCandidateSummary"), m = h(t, "#adsCopySelectedCandidateButton"), p = h(t, "#adsCandidateDetail"), y = h(t, "#adsCandidateNotice"), g = h(t, "#adsApiLog"), u = h(t, "#adsApiLogResizer"), b = h(t, ".ads-selected-pane"), z = h(t, "#adsSelectedPaneResizer"), Le = h(t, ".ads-workspace"), $e = h(t, "#adsWorkspaceResizer"), v = De.init({
137
+ mount: a,
138
+ oidResolver: ((ie = e.viewer) == null ? void 0 : ie.oidResolver) ?? ze,
139
+ newWindowUrl: ((oe = e.viewer) == null ? void 0 : oe.newWindowUrl) ?? "viewer.html",
140
+ editable: !0
141
+ });
142
+ Ct(v);
143
+ const R = h(t, ".ads-shell");
144
+ Dt(R, b, z), zt(R, Le, $e), Ht(R, u);
145
+ const w = (l, S, $) => {
146
+ n.logs.push({ level: l, label: S, detail: $, timestamp: /* @__PURE__ */ new Date() }), n.logs.length > se && n.logs.splice(0, n.logs.length - se), ue(g, n.logs);
147
+ };
148
+ let L;
149
+ St(v, (l, S) => {
150
+ L = `${S} (${l})`, w("info", "PkiStudioJS.viewer.edit", L);
151
+ });
152
+ const P = (l) => {
153
+ y.textContent = l;
154
+ }, T = (l) => {
155
+ n.selectedSelection = l, m.disabled = !l, nt(p, c, l), Et(R, p);
156
+ };
157
+ m.addEventListener("click", () => {
158
+ if (!n.selectedSelection) return;
159
+ const l = it(n.selectedSelection, n.sourceName);
160
+ ot(JSON.stringify(l, null, 2)).then(() => {
161
+ w("success", "selectedCandidate.copy", `${l.context}: copied selected analysis JSON to clipboard.`);
162
+ }).catch((S) => {
163
+ w("error", "selectedCandidate.copy failed", pe(S));
164
+ });
165
+ });
166
+ const W = async (l, S = "input.der", $ = !0) => {
167
+ const Me = performance.now();
168
+ n.bytes = l, n.sourceName = S, $ && v.loadBytes(l, `Opened ${S} in the ASN.1 viewer.`), w("info", "loadBytes", `${S}: ${l.byteLength} bytes`);
169
+ try {
170
+ const C = await Pe(l, {
171
+ includeSubtrees: !0,
172
+ includeEmptySubtrees: !0,
173
+ includeNodes: !0,
174
+ maxSubtreeDepth: 4,
175
+ maxSubtreeReports: 50,
176
+ maxResults: 8
177
+ });
178
+ n.report = C, n.selectedRootCandidates = /* @__PURE__ */ new Map(), n.selectedSubtreeCandidates = /* @__PURE__ */ new Map(), q(d, C, l, n.selectedRootCandidates, n.selectedSubtreeCandidates, (A, k) => {
179
+ T(A), st(d, k);
180
+ });
181
+ const M = C.roots.length, re = C.roots.reduce((A, k) => A + k.candidates.length, 0), He = C.roots.reduce((A, k) => {
182
+ var ae;
183
+ return A + (((ae = k.subtrees) == null ? void 0 : ae.length) ?? 0);
184
+ }, 0);
185
+ P(`Resolved ${re} root candidate(s) across ${M} root node(s); ${He} subtree report(s).`), w("success", "createPkiCandidateReport", `Completed in ${Rt(Me)} with ${re} root candidate(s).`), ct(C, w);
186
+ } catch (C) {
187
+ n.report = null, d.textContent = "No candidate report available.", T();
188
+ const M = pe(C);
189
+ P(M), w("error", "createPkiCandidateReport failed", M);
190
+ }
191
+ }, Ae = async (l, S = We) => {
192
+ const $ = At(l);
193
+ await W($, S);
194
+ }, ke = (l) => {
195
+ n.report = null, n.sourceName = null, n.bytes = null, n.selectedRootCandidates = /* @__PURE__ */ new Map(), n.selectedSubtreeCandidates = /* @__PURE__ */ new Map(), n.selectedSelection = void 0, d.textContent = "No candidate report yet.", T(), P("Candidate results will appear after input is loaded."), w("success", "PkiStudioJS.viewer.close", l);
196
+ }, Be = () => {
197
+ var l;
198
+ document.removeEventListener("click", te), ne.disconnect(), (l = v.close) == null || l.call(v), document.documentElement.style.removeProperty("--ads-app-min-width"), t.innerHTML = "";
199
+ };
200
+ i.addEventListener("click", () => {
201
+ typeof o.showModal == "function" ? o.showModal() : o.setAttribute("open", "");
202
+ }), r.addEventListener("click", () => o.close()), s.addEventListener("click", () => {
203
+ n.logs = [], ue(g, n.logs);
204
+ });
205
+ const te = (l) => {
206
+ t.contains(l.target) && (l.target.closest(".ads-tree-alternatives") || j());
207
+ };
208
+ document.addEventListener("click", te);
209
+ const Re = () => {
210
+ if (!v.getNodeBytes) return;
211
+ let l;
212
+ try {
213
+ l = bt(v);
214
+ } catch {
215
+ n.bytes && vt(v) && ke("Cleared candidate report after the viewer was closed.");
216
+ return;
217
+ }
218
+ n.bytes && kt(n.bytes, l) || (w("info", "PkiStudioJS.viewer.change", `Viewer document changed${L ? ` after ${L}` : ""}; refreshing candidates.`), L = void 0, W(l, n.sourceName ?? "PkiStudioJS viewer", !1));
219
+ }, ne = new MutationObserver(() => window.setTimeout(Re));
220
+ return v.root && ne.observe(v.root, { childList: !0, subtree: !0, characterData: !0 }), w("info", "initAsn1DefinitionSifter", "Viewer initialized."), {
221
+ get report() {
222
+ return n.report;
223
+ },
224
+ get sourceName() {
225
+ return n.sourceName;
226
+ },
227
+ loadBytes: W,
228
+ loadHex: Ae,
229
+ close: Be
230
+ };
231
+ }
232
+ typeof window < "u" && (window.Asn1DefinitionSifter = { init: Ie });
233
+ function q(e, t, n, i, o, r) {
234
+ const s = Ze(e);
235
+ if (e.innerHTML = "", t.roots.length === 0) {
236
+ e.textContent = "No root TLV nodes were parsed.";
237
+ return;
238
+ }
239
+ let a;
240
+ for (const d of t.roots) {
241
+ const c = Fe(d.subtrees ?? []);
242
+ for (const m of he(d, i)) {
243
+ const p = Ve(m, d, n, c, i, o, () => q(e, t, n, i, o, r), r);
244
+ a ?? (a = { selection: O(m, d, n, V(m, c, o)), selectedElement: dt(p) }), e.append(p);
245
+ }
246
+ d.candidates.length === 0 && e.append(Ke(d, c, o, () => q(e, t, n, i, o, r), r));
247
+ }
248
+ et(e, s), a && r(a.selection, a.selectedElement);
249
+ }
250
+ function Ve(e, t, n, i, o, r, s, a) {
251
+ const d = document.createElement("details");
252
+ d.className = "ads-tree-node ads-candidate-node";
253
+ const c = V(e, i, r), m = D(c), p = H(x(e), `Root ${t.index} · ${N(c)} · ${m}`, {
254
+ hasChildren: i.length > 0
255
+ });
256
+ p.dataset.treeKind = "root", p.dataset.rootIndex = String(t.index), p.dataset.candidateKey = f(e), U(p, () => a(O(e, t, n, c), p));
257
+ const y = p.querySelector(".ads-tree-icon"), g = Ue(t, o, (u) => {
258
+ o.set(t.index, f(u)), s();
259
+ const b = be("root", String(t.index), f(u));
260
+ a(O(u, t, n, V(u, i, r)), b ?? p);
261
+ });
262
+ if (g.childElementCount > 0 && (y == null || y.addEventListener("click", (u) => {
263
+ u.preventDefault(), u.stopPropagation(), j(g);
264
+ const b = g.hidden;
265
+ g.hidden = !b;
266
+ }), p.append(g)), d.append(p), i.length > 0) {
267
+ const u = document.createElement("div");
268
+ u.className = "ads-tree-children";
269
+ for (const b of i) u.append(_(b, r, s, a));
270
+ d.append(u);
271
+ }
272
+ return d;
273
+ }
274
+ function he(e, t) {
275
+ var s;
276
+ const n = t.get(e.index), i = e.candidates.find((a) => f(a) === n);
277
+ if (i) return [i];
278
+ const o = B(e.candidates), r = (s = o[0]) == null ? void 0 : s.score;
279
+ return r === void 0 ? [] : o.filter((a) => Bt(a.score, r));
280
+ }
281
+ function Ke(e, t, n, i, o) {
282
+ const r = document.createElement("details");
283
+ if (r.className = "ads-tree-node", r.open = !0, r.append(H(`Root ${e.index}`, "No candidates", { hasChildren: t.length > 0 })), t.length > 0) {
284
+ const s = document.createElement("div");
285
+ s.className = "ads-tree-children";
286
+ for (const a of t) s.append(_(a, n, i, o));
287
+ r.append(s);
288
+ }
289
+ return r;
290
+ }
291
+ function _(e, t, n, i) {
292
+ var p;
293
+ const { subtree: o } = e, r = F(o, t), s = document.createElement("details");
294
+ s.className = "ads-tree-node ads-subtree-node";
295
+ const a = r ? K(e, t, r) : void 0, d = a === void 0 ? void 0 : D(a), c = r ? H(x(r), `${o.path} · ${N(a ?? r.score)} · ${d ?? r.confidence}`, {
296
+ hasChildren: e.children.length > 0
297
+ }) : H(xe(o), `${o.path} · ${o.features.tagName} · ${ht(((p = G(o.node)) == null ? void 0 : p.byteLength) ?? 0)}`, {
298
+ hasChildren: e.children.length > 0
299
+ });
300
+ if (r) {
301
+ c.dataset.treeKind = "subtree", c.dataset.path = o.path, c.dataset.candidateKey = f(r), U(c, () => i(ce(r, o, a), c));
302
+ const y = c.querySelector(".ads-tree-icon"), g = Oe(o, t, (u, b) => {
303
+ t.set(o.path, f(u)), n();
304
+ const z = be("subtree", o.path, f(u));
305
+ i(ce(u, o, K(e, t, u)), z ?? b);
306
+ });
307
+ y == null || y.addEventListener("click", (u) => {
308
+ u.preventDefault(), u.stopPropagation(), j(g);
309
+ const b = g.hidden;
310
+ g.hidden = !b;
311
+ }), c.append(g);
312
+ } else
313
+ U(c, () => i(tt(o), c));
314
+ s.append(c);
315
+ const m = document.createElement("div");
316
+ m.className = "ads-tree-children";
317
+ for (const y of e.children) m.append(_(y, t, n, i));
318
+ return s.append(m), s;
319
+ }
320
+ function Oe(e, t, n) {
321
+ const i = document.createElement("div");
322
+ i.className = "ads-tree-alternatives", i.setAttribute("role", "menu"), i.hidden = !0;
323
+ for (const o of B(e.candidates)) i.append(je(o, e, t, n));
324
+ return i;
325
+ }
326
+ function Ue(e, t, n) {
327
+ const i = document.createElement("div");
328
+ i.className = "ads-tree-alternatives", i.setAttribute("role", "menu"), i.hidden = !0;
329
+ const o = new Set(he(e, t).map(f));
330
+ for (const r of B(e.candidates).filter((s) => !o.has(f(s))))
331
+ i.append(_e(r, n));
332
+ return i;
333
+ }
334
+ function _e(e, t) {
335
+ const n = document.createElement("button");
336
+ return n.className = "ads-tree-item ads-candidate-item", n.type = "button", n.setAttribute("role", "menuitem"), n.dataset.candidateKey = f(e), n.append(Y(x(e)), X(N(e.score))), n.prepend(Se(!1)), n.addEventListener("click", (i) => {
337
+ i.preventDefault(), i.stopPropagation(), t(e);
338
+ }), n;
339
+ }
340
+ function je(e, t, n, i) {
341
+ const o = document.createElement("button");
342
+ o.className = "ads-tree-item ads-candidate-item", o.type = "button", o.setAttribute("role", "menuitemradio"), o.dataset.candidateKey = f(e);
343
+ const r = F(t, n);
344
+ return o.setAttribute("aria-checked", r && f(e) === f(r) ? "true" : "false"), o.append(Y(x(e)), X(N(e.score))), o.prepend(Se(!!(r && f(e) === f(r)))), o.addEventListener("click", (s) => {
345
+ s.preventDefault(), s.stopPropagation(), i(e, o);
346
+ }), o;
347
+ }
348
+ function j(e) {
349
+ for (const t of document.querySelectorAll(".ads-tree-alternatives"))
350
+ t !== e && (t.hidden = !0);
351
+ }
352
+ function Fe(e) {
353
+ const t = new Map(e.map((i) => [i.path, { subtree: i, children: [] }])), n = [];
354
+ for (const i of [...t.values()].sort((o, r) => o.subtree.path.localeCompare(r.subtree.path))) {
355
+ const o = t.get(Qe(i.subtree.path));
356
+ o ? o.children.push(i) : n.push(i);
357
+ }
358
+ for (const i of t.values()) i.children = I(i.children);
359
+ return I(n.flatMap(fe));
360
+ }
361
+ function fe(e) {
362
+ const t = I(e.children.flatMap(fe)), n = { ...e, children: t };
363
+ return Je(e.subtree) || Ye(e.subtree, t) ? [n] : t;
364
+ }
365
+ function Je(e) {
366
+ return e.candidates.length > 0;
367
+ }
368
+ function Ye(e, t) {
369
+ return e.candidates.length === 0 && t.length === 0 && Xe(e.node);
370
+ }
371
+ function Xe(e) {
372
+ return !!(e && !e.constructed && e.tagClass === "universal" && (e.tagNumber === 3 || e.tagNumber === 4));
373
+ }
374
+ function I(e) {
375
+ return [...e].sort((t, n) => Ge(t.subtree.path, n.subtree.path));
376
+ }
377
+ function Ge(e, t) {
378
+ const n = de(e), i = de(t), o = Math.max(n.length, i.length);
379
+ for (let r = 0; r < o; r += 1) {
380
+ const s = n[r], a = i[r];
381
+ if (s === void 0) return -1;
382
+ if (a === void 0) return 1;
383
+ if (s !== a) return s - a;
384
+ }
385
+ return e.localeCompare(t);
386
+ }
387
+ function de(e) {
388
+ return e.split(".").slice(1).map((t) => Number.parseInt(t, 10));
389
+ }
390
+ function Qe(e) {
391
+ const t = e.lastIndexOf(".");
392
+ return t > 0 ? e.slice(0, t) : "";
393
+ }
394
+ function F(e, t) {
395
+ const n = t.get(e.path);
396
+ return e.candidates.find((i) => f(i) === n) ?? B(e.candidates)[0];
397
+ }
398
+ function V(e, t, n) {
399
+ return J(t, n) ? ye(e.score, ge(t, n)) : e.score;
400
+ }
401
+ function K(e, t, n = F(e.subtree, t)) {
402
+ if (n)
403
+ return J(e.children, t) ? ye(n.score, ge(e.children, t)) : n.score;
404
+ }
405
+ function ge(e, t) {
406
+ return e.flatMap((n) => {
407
+ const i = K(n, t);
408
+ return i === void 0 ? [] : [i];
409
+ });
410
+ }
411
+ function ye(e, t) {
412
+ if (t.length === 0) return e;
413
+ const n = t.reduce((i, o) => i + o, e);
414
+ return Te(n / (t.length + 1));
415
+ }
416
+ function J(e, t) {
417
+ return e.some((n) => t.has(n.subtree.path) || J(n.children, t));
418
+ }
419
+ function be(e, t, n) {
420
+ for (const i of document.querySelectorAll(`summary[data-tree-kind="${e}"]`))
421
+ if ((e === "root" ? i.dataset.rootIndex === t : i.dataset.path === t) && i.dataset.candidateKey === n) return i;
422
+ }
423
+ function Ze(e) {
424
+ const t = /* @__PURE__ */ new Set();
425
+ for (const n of e.querySelectorAll("details[open]")) {
426
+ const i = n.querySelector(":scope > summary[data-tree-kind]"), o = i ? ve(i) : void 0;
427
+ o && t.add(o);
428
+ }
429
+ return t;
430
+ }
431
+ function et(e, t) {
432
+ for (const n of e.querySelectorAll("summary[data-tree-kind]")) {
433
+ const i = n.parentElement instanceof HTMLDetailsElement ? n.parentElement : void 0;
434
+ i && t.has(ve(n) ?? "") && (i.open = !0);
435
+ }
436
+ }
437
+ function ve(e) {
438
+ if (e.dataset.treeKind === "root" && e.dataset.rootIndex !== void 0) return `root:${e.dataset.rootIndex}`;
439
+ if (e.dataset.treeKind === "subtree" && e.dataset.path) return `subtree:${e.dataset.path}`;
440
+ }
441
+ function f(e) {
442
+ return `${e.moduleName ?? ""}\0${e.typeName}`;
443
+ }
444
+ function Se(e) {
445
+ const t = document.createElement("span");
446
+ return t.className = "ads-tree-checkmark", t.textContent = e ? "✓" : "", t.setAttribute("aria-hidden", "true"), t;
447
+ }
448
+ function O(e, t, n, i) {
449
+ return {
450
+ candidate: e,
451
+ context: `Root ${t.index}`,
452
+ bytes: t.index === 0 ? n : Q(t.node),
453
+ displayScore: i,
454
+ displayConfidence: i === void 0 ? void 0 : D(i)
455
+ };
456
+ }
457
+ function ce(e, t, n) {
458
+ return {
459
+ candidate: e,
460
+ context: `Subtree ${t.path}`,
461
+ bytes: Q(t.node),
462
+ displayScore: n,
463
+ displayConfidence: n === void 0 ? void 0 : D(n)
464
+ };
465
+ }
466
+ function tt(e) {
467
+ const t = G(e.node) ?? Q(e.node);
468
+ return {
469
+ context: `Subtree ${e.path}`,
470
+ bytes: t,
471
+ hexOnly: !0,
472
+ hexSummary: xe(e)
473
+ };
474
+ }
475
+ function nt(e, t, n) {
476
+ if (e.innerHTML = "", !n) {
477
+ t.textContent = "None", e.textContent = "Select a candidate to inspect evidence, diagnostics, ambiguities, matched paths, and bytes.";
478
+ return;
479
+ }
480
+ const { candidate: i, context: o } = n;
481
+ if (!i) {
482
+ t.textContent = `${o} · ${n.hexSummary ?? "HEX data"}`, e.append(E("Binary data", "No ASN.1 type candidate matched this value. The item is shown as raw hexadecimal bytes.")), e.append(E("Selected bytes", le(n)));
483
+ return;
484
+ }
485
+ const r = n.displayScore ?? i.score, s = n.displayConfidence ?? i.confidence;
486
+ t.textContent = `${o} · ${x(i)} · ${N(r)} · ${s}`, e.append(E("Evidence", i.evidence.slice(0, 8).join(`
487
+ `) || "No evidence.")), e.append(E("Diagnostics", i.diagnostics.slice(0, 8).map((a) => `${a.severity}: ${a.message}`).join(`
488
+ `) || "No diagnostics.")), e.append(E("Ambiguities", i.ambiguities.slice(0, 8).join(`
489
+ `) || "No ambiguities.")), e.append(E("Matched paths", i.matchedPaths.slice(0, 12).map((a) => `${a.nodePath} -> ${a.schemaPath}`).join(`
490
+ `) || "No matched paths.")), e.append(E("Selected bytes", le(n)));
491
+ }
492
+ function le(e) {
493
+ return !e.bytes || e.bytes.length === 0 ? `${e.context}: encoded bytes are not available from the parser output.` : we(e.bytes);
494
+ }
495
+ function it(e, t) {
496
+ const n = e.candidate;
497
+ return {
498
+ sourceName: t,
499
+ context: e.context,
500
+ hexOnly: !!e.hexOnly,
501
+ hexSummary: e.hexSummary,
502
+ displayScore: e.displayScore ?? (n == null ? void 0 : n.score),
503
+ displayConfidence: e.displayConfidence ?? (n == null ? void 0 : n.confidence),
504
+ candidate: n ? {
505
+ typeName: n.typeName,
506
+ moduleName: n.moduleName,
507
+ qualifiedName: x(n),
508
+ score: n.score,
509
+ confidence: n.confidence,
510
+ evidence: n.evidence,
511
+ diagnostics: n.diagnostics,
512
+ ambiguities: n.ambiguities,
513
+ matchedPaths: n.matchedPaths
514
+ } : void 0,
515
+ selectedBytesHex: e.bytes ? we(e.bytes) : void 0
516
+ };
517
+ }
518
+ async function ot(e) {
519
+ var i;
520
+ if ((i = navigator.clipboard) != null && i.writeText) {
521
+ await navigator.clipboard.writeText(e);
522
+ return;
523
+ }
524
+ const t = document.createElement("textarea");
525
+ t.value = e, t.style.position = "fixed", t.style.left = "-9999px", document.body.append(t), t.select();
526
+ const n = document.execCommand("copy");
527
+ if (t.remove(), !n) throw new Error("Clipboard write was not available.");
528
+ }
529
+ function we(e) {
530
+ return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
531
+ }
532
+ function H(e, t, n) {
533
+ const i = document.createElement("summary");
534
+ return n.hasChildren || i.classList.add("ads-tree-leaf"), i.append(rt(n.hasChildren), at(n.hasChildren ? "branch" : "leaf"), Y(e), X(t)), i;
535
+ }
536
+ function U(e, t) {
537
+ e.addEventListener("click", (n) => {
538
+ n.target.closest(".ads-disclosure") || (n.preventDefault(), t());
539
+ });
540
+ }
541
+ function rt(e) {
542
+ const t = document.createElement("span");
543
+ return t.className = "ads-disclosure", e || t.classList.add("ads-disclosure-hidden"), t.setAttribute("aria-hidden", "true"), t;
544
+ }
545
+ function at(e) {
546
+ const t = document.createElement("span");
547
+ return t.className = `ads-tree-icon ads-tree-icon-${e}`, t.setAttribute("aria-hidden", "true"), t;
548
+ }
549
+ function Y(e) {
550
+ const t = document.createElement("span");
551
+ return t.className = "ads-tree-label", t.textContent = e, t;
552
+ }
553
+ function X(e) {
554
+ const t = document.createElement("span");
555
+ return t.className = "ads-tree-note", t.textContent = e, t;
556
+ }
557
+ function st(e, t) {
558
+ for (const n of e.querySelectorAll(".ads-tree-selected")) n.classList.remove("ads-tree-selected");
559
+ t.classList.add("ads-tree-selected");
560
+ }
561
+ function dt(e) {
562
+ const t = e.querySelector("summary");
563
+ if (!t) throw new Error("Candidate tree node is missing a summary.");
564
+ return t;
565
+ }
566
+ function E(e, t) {
567
+ const n = document.createElement("section");
568
+ n.className = "ads-key-value", e === "Selected bytes" && n.classList.add("ads-key-value-bytes");
569
+ const i = document.createElement("h3");
570
+ i.textContent = e;
571
+ const o = document.createElement("pre");
572
+ return o.textContent = t, n.append(i, o), n;
573
+ }
574
+ function ue(e, t) {
575
+ e.innerHTML = "";
576
+ for (const n of t) {
577
+ const i = document.createElement("li");
578
+ i.className = `ads-api-log-entry ${n.level}`;
579
+ const o = document.createElement("time");
580
+ o.dateTime = n.timestamp.toISOString(), o.textContent = pt(n.timestamp);
581
+ const r = document.createElement("span");
582
+ r.className = "ads-api-log-operation", r.textContent = n.label;
583
+ const s = document.createElement("span");
584
+ s.className = "ads-api-log-detail", s.textContent = n.detail ?? "", i.append(o, r, s), e.append(i);
585
+ }
586
+ e.scrollTop = e.scrollHeight;
587
+ }
588
+ function ct(e, t) {
589
+ for (const n of e.roots)
590
+ for (const [i, o] of B(n.candidates).entries())
591
+ t(lt(o), `candidate root ${n.index}.${i + 1}`, ut(o));
592
+ }
593
+ function lt(e) {
594
+ return e.diagnostics.some((t) => t.severity === "error") ? "error" : e.diagnostics.some((t) => t.severity === "warning") || e.confidence === "low" ? "warning" : e.confidence === "high" ? "success" : "info";
595
+ }
596
+ function ut(e) {
597
+ const t = e.diagnostics.slice(0, 2).map((o) => `${o.severity}: ${o.message}`), n = [
598
+ `type=${x(e)}`,
599
+ `score=${N(e.score)}`,
600
+ `confidence=${e.confidence}`,
601
+ `evidence=${e.evidence.length}`,
602
+ `diagnostics=${e.diagnostics.length}`,
603
+ `ambiguities=${e.ambiguities.length}`,
604
+ `matchedPaths=${e.matchedPaths.length}`
605
+ ], i = e.evidence.slice(0, 2);
606
+ return i.length > 0 && n.push(`evidence: ${i.join(" / ")}`), t.length > 0 && n.push(`diagnostics: ${t.join(" / ")}`), e.ambiguities.length > 0 && n.push(`ambiguity: ${e.ambiguities[0]}`), n.join(" | ");
607
+ }
608
+ function pt(e) {
609
+ const t = (n, i = 2) => String(n).padStart(i, "0");
610
+ return `${e.getFullYear()}/${t(e.getMonth() + 1)}/${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}.${t(e.getMilliseconds(), 3)}`;
611
+ }
612
+ function xe(e) {
613
+ const t = G(e.node) ?? new Uint8Array();
614
+ return `HEX ${mt(t)}`;
615
+ }
616
+ function mt(e) {
617
+ const t = Array.from(e.slice(0, 12), (n) => n.toString(16).padStart(2, "0")).join(" ").toUpperCase();
618
+ return e.byteLength > 12 ? `${t} ...` : t || "(empty)";
619
+ }
620
+ function ht(e) {
621
+ return `${e} byte${e === 1 ? "" : "s"}`;
622
+ }
623
+ function G(e) {
624
+ if (e != null && e.valueBytes)
625
+ return e.tagClass === "universal" && e.tagNumber === 3 ? e.valueBytes.slice(1) : e.valueBytes;
626
+ }
627
+ function Q(e) {
628
+ if (e)
629
+ return Ce(e) ?? e.encodedBytes ?? e.valueBytes;
630
+ }
631
+ function Ce(e) {
632
+ if (e.tagNumber >= 31) return e.encodedBytes;
633
+ const t = ft(e);
634
+ if (!t) return e.encodedBytes;
635
+ const n = gt(e.tagClass) | (e.constructed ? 32 : 0) | e.tagNumber;
636
+ return Z(new Uint8Array([n]), yt(t.byteLength), t);
637
+ }
638
+ function ft(e) {
639
+ if (e.children && e.children.length > 0) {
640
+ const t = e.children.map(Ce);
641
+ return t.some((n) => !n) ? e.valueBytes ?? e.encodedBytes : Z(...t);
642
+ }
643
+ return e.valueBytes;
644
+ }
645
+ function gt(e) {
646
+ return e === "application" ? 64 : e === "context" ? 128 : e === "private" ? 192 : 0;
647
+ }
648
+ function yt(e) {
649
+ if (e < 128) return new Uint8Array([e]);
650
+ const t = [];
651
+ let n = e;
652
+ for (; n > 0; )
653
+ t.unshift(n & 255), n >>= 8;
654
+ return new Uint8Array([128 | t.length, ...t]);
655
+ }
656
+ function Z(...e) {
657
+ const t = new Uint8Array(e.reduce((i, o) => i + o.byteLength, 0));
658
+ let n = 0;
659
+ for (const i of e)
660
+ t.set(i, n), n += i.byteLength;
661
+ return t;
662
+ }
663
+ function bt(e) {
664
+ if (!e.getNodeBytes || !e.root) throw new Error("PkiStudioJS viewer bytes are not available.");
665
+ const t = Array.from(e.root.querySelectorAll(".tree > details.node > summary .icon[data-node-id]"), (n) => n.dataset.nodeId).filter((n) => !!n);
666
+ return t.length === 0 ? e.getNodeBytes("1") : Z(...t.map((n) => {
667
+ var i;
668
+ return ((i = e.getNodeBytes) == null ? void 0 : i.call(e, n)) ?? new Uint8Array();
669
+ }));
670
+ }
671
+ function vt(e) {
672
+ return e.root ? !!e.root.querySelector(".viewer.empty") : !0;
673
+ }
674
+ function St(e, t) {
675
+ var n;
676
+ (n = e.root) == null || n.addEventListener("click", (i) => {
677
+ const o = i.target.closest("button[data-node-action]"), r = o == null ? void 0 : o.dataset.nodeAction;
678
+ !r || !wt(r) || t(r, xt(o.textContent ?? r));
679
+ }, !0);
680
+ }
681
+ function wt(e) {
682
+ return e === "edit" || e === "delete" || e.startsWith("insert-") || e.startsWith("add-child");
683
+ }
684
+ function xt(e) {
685
+ return e.replace(/\s+/g, " ").trim() || "Edit action";
686
+ }
687
+ function Ct(e) {
688
+ if (!e.root) return;
689
+ const t = document.createElement("style");
690
+ t.textContent = qe, e.root.prepend(t);
691
+ }
692
+ function Et(e, t) {
693
+ window.requestAnimationFrame(() => Nt(e, t));
694
+ }
695
+ function Nt(e, t) {
696
+ const n = Lt(t), i = Math.max(me, n);
697
+ e.style.setProperty("--ads-app-min-width", `${Math.ceil(i)}px`), document.documentElement.style.setProperty("--ads-app-min-width", `${Math.ceil(i)}px`);
698
+ }
699
+ function Lt(e) {
700
+ const t = Array.from(e.querySelectorAll(".ads-key-value:not(.ads-key-value-bytes)"));
701
+ if (t.length === 0) return me;
702
+ const n = getComputedStyle(e), i = Ee(
703
+ n.marginLeft,
704
+ n.marginRight,
705
+ n.paddingLeft,
706
+ n.paddingRight,
707
+ n.borderLeftWidth,
708
+ n.borderRightWidth
709
+ );
710
+ return Math.max(...t.map($t)) + i + 2;
711
+ }
712
+ function $t(e) {
713
+ const t = e.querySelector("h3"), n = e.querySelector("pre"), i = getComputedStyle(e), o = Ee(i.borderLeftWidth, i.borderRightWidth);
714
+ return Math.max((t == null ? void 0 : t.scrollWidth) ?? 0, (n == null ? void 0 : n.scrollWidth) ?? 0) + o;
715
+ }
716
+ function Ee(...e) {
717
+ return e.reduce((t, n) => t + (Number.parseFloat(n) || 0), 0);
718
+ }
719
+ function At(e) {
720
+ const t = e.replace(/(?:0x|[^0-9a-fA-F])/g, "");
721
+ if (t.length === 0) throw new Error("Clipboard does not contain hexadecimal input.");
722
+ if (t.length % 2 !== 0) throw new Error("Hexadecimal input must contain an even number of digits.");
723
+ const n = new Uint8Array(t.length / 2);
724
+ for (let i = 0; i < n.length; i += 1)
725
+ n[i] = Number.parseInt(t.slice(i * 2, i * 2 + 2), 16);
726
+ return n;
727
+ }
728
+ function kt(e, t) {
729
+ if (e.byteLength !== t.byteLength) return !1;
730
+ for (let n = 0; n < e.byteLength; n += 1)
731
+ if (e[n] !== t[n]) return !1;
732
+ return !0;
733
+ }
734
+ function x(e) {
735
+ return e.moduleName ? `${e.moduleName}.${e.typeName}` : e.typeName;
736
+ }
737
+ function N(e) {
738
+ return `${Math.round(e * 100)}%`;
739
+ }
740
+ function B(e) {
741
+ return [...e].sort((t, n) => n.score - t.score || x(t).localeCompare(x(n)));
742
+ }
743
+ function Bt(e, t) {
744
+ return Math.abs(e - t) < 1e-9;
745
+ }
746
+ function Rt(e) {
747
+ return `${Math.round(performance.now() - e)} ms`;
748
+ }
749
+ function h(e, t) {
750
+ const n = e.querySelector(t);
751
+ if (!n) throw new Error(`Missing app element: ${t}`);
752
+ return n;
753
+ }
754
+ function Mt(e) {
755
+ if (typeof e != "string") return e;
756
+ const t = document.querySelector(e);
757
+ if (!t) throw new Error(`Mount element not found: ${e}`);
758
+ return t;
759
+ }
760
+ function Ht(e, t) {
761
+ let o = 0, r = 0;
762
+ const s = (d) => {
763
+ const c = ee(r - (d.clientY - o), 86, Pt(e, 220, 86));
764
+ e.style.setProperty("--ads-api-log-height", `${c}px`);
765
+ }, a = () => {
766
+ e.classList.remove("ads-resizing-rows"), document.removeEventListener("pointermove", s), document.removeEventListener("pointerup", a);
767
+ };
768
+ t.addEventListener("pointerdown", (d) => {
769
+ var c;
770
+ d.preventDefault(), o = d.clientY, r = ((c = e.querySelector(".ads-log-pane")) == null ? void 0 : c.getBoundingClientRect().height) ?? 156, e.classList.add("ads-resizing-rows"), document.addEventListener("pointermove", s), document.addEventListener("pointerup", a);
771
+ });
772
+ }
773
+ function Dt(e, t, n) {
774
+ let r = 0, s = 0;
775
+ const a = (c) => {
776
+ const m = ee(s - (c.clientY - r), 150, Tt(e, 220, 150));
777
+ e.style.setProperty("--ads-selected-height", `${m}px`);
778
+ }, d = () => {
779
+ e.classList.remove("ads-resizing-rows"), document.removeEventListener("pointermove", a), document.removeEventListener("pointerup", d);
780
+ };
781
+ n.addEventListener("pointerdown", (c) => {
782
+ c.preventDefault(), r = c.clientY, s = t.getBoundingClientRect().height || 180, e.classList.add("ads-resizing-rows"), document.addEventListener("pointermove", a), document.addEventListener("pointerup", d);
783
+ });
784
+ }
785
+ function zt(e, t, n) {
786
+ let r = 0, s = 0;
787
+ const a = (c) => {
788
+ const m = n.getBoundingClientRect().width || 6, p = t.getBoundingClientRect().width - m, y = Math.max(280, p - 320), g = ee(s + c.clientX - r, 280, y);
789
+ t.style.setProperty("--ads-viewer-width", `${g}px`);
790
+ }, d = () => {
791
+ e.classList.remove("ads-resizing-columns"), document.removeEventListener("pointermove", a), document.removeEventListener("pointerup", d);
792
+ };
793
+ n.addEventListener("pointerdown", (c) => {
794
+ var m;
795
+ c.preventDefault(), r = c.clientX, s = ((m = t.querySelector(".ads-viewer-pane")) == null ? void 0 : m.getBoundingClientRect().width) ?? 420, e.classList.add("ads-resizing-columns"), document.addEventListener("pointermove", a), document.addEventListener("pointerup", d);
796
+ });
797
+ }
798
+ function Pt(e, t, n) {
799
+ var a, d;
800
+ const i = ((a = e.querySelector(".ads-toolbar")) == null ? void 0 : a.getBoundingClientRect().height) ?? 0, o = ((d = e.querySelector(".ads-selected-pane")) == null ? void 0 : d.getBoundingClientRect().height) ?? 150, r = Ne(e), s = e.getBoundingClientRect().height || window.innerHeight;
801
+ return Math.max(n, Math.floor(s - i - r - o - t));
802
+ }
803
+ function Tt(e, t, n) {
804
+ var a, d;
805
+ const i = ((a = e.querySelector(".ads-toolbar")) == null ? void 0 : a.getBoundingClientRect().height) ?? 0, o = ((d = e.querySelector(".ads-log-pane")) == null ? void 0 : d.getBoundingClientRect().height) ?? 86, r = Ne(e), s = e.getBoundingClientRect().height || window.innerHeight;
806
+ return Math.max(n, Math.floor(s - i - r - o - t));
807
+ }
808
+ function Ne(e) {
809
+ var i, o;
810
+ const t = ((i = e.querySelector(".ads-selected-pane-resizer")) == null ? void 0 : i.getBoundingClientRect().height) ?? 6, n = ((o = e.querySelector(".ads-api-log-resizer")) == null ? void 0 : o.getBoundingClientRect().height) ?? 6;
811
+ return t + n;
812
+ }
813
+ function ee(e, t, n) {
814
+ return Math.min(Math.max(e, t), n);
815
+ }
816
+ function pe(e) {
817
+ return e instanceof Error ? e.message : String(e);
818
+ }
819
+ export {
820
+ Ie as initAsn1DefinitionSifter
821
+ };