@emeryld/rrroutes-export 1.0.1

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.
@@ -0,0 +1,1550 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Finalized Leaves Viewer</title>
7
+ <style>
8
+ :root {
9
+ --bg: #212121;
10
+ --surface: #2a2a2a;
11
+ --surface-2: #353535;
12
+ --border: #4a4a4a;
13
+ --text: #fffafa;
14
+ --muted: #c8c2c2;
15
+ --accent: #a764d3;
16
+ --schema-accent: #fbbd23;
17
+ --ok: #1f8f4e;
18
+ --danger: #d12b2b;
19
+ }
20
+
21
+ * {
22
+ box-sizing: border-box;
23
+ }
24
+
25
+ body {
26
+ margin: 0;
27
+ font-family: 'Iosevka Web', 'SFMono-Regular', Menlo, Consolas, monospace;
28
+ color: var(--text);
29
+ background: var(--bg);
30
+ }
31
+
32
+ a {
33
+ color: var(--schema-accent);
34
+ }
35
+
36
+ mark {
37
+ background: #00e5ff;
38
+ color: #0f1416;
39
+ border-radius: 2px;
40
+ padding: 0 1px;
41
+ }
42
+
43
+ .wrap {
44
+ max-width: 1200px;
45
+ margin: 0 auto;
46
+ padding: 20px;
47
+ }
48
+
49
+ .card {
50
+ background: var(--surface);
51
+ border: 1px solid var(--border);
52
+ border-radius: 6px;
53
+ padding: 12px;
54
+ }
55
+
56
+ .controls {
57
+ display: grid;
58
+ gap: 14px;
59
+ }
60
+
61
+ .primary-row {
62
+ display: grid;
63
+ gap: 10px;
64
+ grid-template-columns: minmax(220px, 0.9fr) minmax(300px, 1.4fr) minmax(220px, 1fr);
65
+ align-items: end;
66
+ }
67
+
68
+ .control-block {
69
+ display: grid;
70
+ gap: 6px;
71
+ }
72
+
73
+ .control-label {
74
+ font-size: 12px;
75
+ color: var(--muted);
76
+ }
77
+
78
+ .quick-toggles {
79
+ display: flex;
80
+ flex-wrap: wrap;
81
+ gap: 8px;
82
+ align-items: center;
83
+ }
84
+
85
+ .scope-row {
86
+ border-top: 1px solid var(--border);
87
+ padding-top: 12px;
88
+ display: grid;
89
+ gap: 10px;
90
+ }
91
+
92
+ .scope-actions {
93
+ display: flex;
94
+ flex-wrap: wrap;
95
+ gap: 8px;
96
+ }
97
+
98
+ .scope-groups {
99
+ display: grid;
100
+ gap: 10px;
101
+ }
102
+
103
+ .scope-group {
104
+ display: grid;
105
+ gap: 6px;
106
+ }
107
+
108
+ .scope-group-title {
109
+ font-size: 12px;
110
+ color: var(--muted);
111
+ }
112
+
113
+ .scope-group-chips {
114
+ display: flex;
115
+ flex-wrap: wrap;
116
+ gap: 6px;
117
+ }
118
+
119
+ .field-item {
120
+ display: inline-flex;
121
+ align-items: center;
122
+ gap: 6px;
123
+ padding: 3px 0;
124
+ }
125
+
126
+ input[type='text'],
127
+ select {
128
+ width: 100%;
129
+ border: 1px solid var(--border);
130
+ border-radius: 4px;
131
+ padding: 8px 10px;
132
+ font: inherit;
133
+ background: var(--surface-2);
134
+ color: var(--text);
135
+ }
136
+
137
+ button {
138
+ border: 1px solid var(--border);
139
+ border-radius: 6px;
140
+ padding: 7px 10px;
141
+ font: inherit;
142
+ background: var(--surface-2);
143
+ color: var(--text);
144
+ cursor: pointer;
145
+ }
146
+
147
+ button:hover {
148
+ background: var(--surface-2);
149
+ }
150
+
151
+ .meta {
152
+ color: var(--muted);
153
+ font-size: 12px;
154
+ }
155
+
156
+ #results {
157
+ margin-top: 14px;
158
+ display: grid;
159
+ gap: 0;
160
+ }
161
+
162
+ details.leaf {
163
+ border-top: 1px solid var(--border);
164
+ padding: 10px 2px;
165
+ }
166
+
167
+ summary {
168
+ cursor: pointer;
169
+ font-weight: 700;
170
+ color: var(--accent);
171
+ }
172
+
173
+ .leaf-content {
174
+ display: grid;
175
+ gap: 4px;
176
+ margin-top: 10px;
177
+ margin-left: 16px;
178
+ padding-left: 12px;
179
+ border-left: 2px solid var(--border);
180
+ }
181
+
182
+ .section {
183
+ border-top: 1px solid var(--border);
184
+ padding: 10px 0 2px;
185
+ }
186
+
187
+ .section h3 {
188
+ margin: 0 0 8px;
189
+ font-size: 13px;
190
+ }
191
+
192
+ .grid-2 {
193
+ display: grid;
194
+ gap: 6px;
195
+ grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
196
+ }
197
+
198
+ .grid-3 {
199
+ display: grid;
200
+ gap: 6px;
201
+ grid-template-columns: repeat(3, minmax(0, 1fr));
202
+ }
203
+
204
+ .kv {
205
+ border-bottom: 1px dashed var(--border);
206
+ padding: 4px 0 6px;
207
+ }
208
+
209
+ .kv .k {
210
+ font-size: 11px;
211
+ color: var(--muted);
212
+ }
213
+
214
+ .kv .k a {
215
+ color: var(--schema-accent);
216
+ text-decoration: underline;
217
+ text-underline-offset: 2px;
218
+ }
219
+
220
+ .kv .v {
221
+ margin-top: 2px;
222
+ word-break: break-word;
223
+ }
224
+
225
+ .chips {
226
+ display: flex;
227
+ gap: 6px;
228
+ flex-wrap: wrap;
229
+ }
230
+
231
+ .chips.filters {
232
+ margin-top: 2px;
233
+ }
234
+
235
+ .chip {
236
+ border: 1px solid var(--border);
237
+ border-radius: 4px;
238
+ padding: 2px 6px;
239
+ font-size: 12px;
240
+ background: var(--surface-2);
241
+ }
242
+
243
+ .chip-btn {
244
+ cursor: pointer;
245
+ }
246
+
247
+ .chip.ok {
248
+ border-color: #b5e4c8;
249
+ color: var(--ok);
250
+ background: #effbf4;
251
+ }
252
+
253
+ .pill-toggle {
254
+ border: 1px solid var(--border);
255
+ border-radius: 999px;
256
+ padding: 6px 12px;
257
+ font-size: 12px;
258
+ background: var(--surface-2);
259
+ color: var(--text);
260
+ }
261
+
262
+ .pill-toggle[aria-pressed='true'] {
263
+ border-color: var(--accent);
264
+ background: rgba(167, 100, 211, 0.25);
265
+ color: #f0d8ff;
266
+ }
267
+
268
+ .scope-action {
269
+ font-size: 12px;
270
+ padding: 5px 10px;
271
+ }
272
+
273
+ .field-chip {
274
+ font-size: 12px;
275
+ padding: 5px 10px;
276
+ border-radius: 999px;
277
+ }
278
+
279
+ .field-chip[aria-pressed='true'] {
280
+ border-color: var(--schema-accent);
281
+ background: rgba(251, 189, 35, 0.22);
282
+ color: #ffe7aa;
283
+ }
284
+
285
+ .advanced-panel {
286
+ border-top: 1px solid var(--border);
287
+ padding-top: 10px;
288
+ }
289
+
290
+ .advanced-panel > summary {
291
+ color: var(--text);
292
+ font-size: 13px;
293
+ }
294
+
295
+ .advanced-content {
296
+ margin-top: 10px;
297
+ display: flex;
298
+ flex-wrap: wrap;
299
+ gap: 12px;
300
+ align-items: center;
301
+ }
302
+
303
+ .advanced-content .field-item {
304
+ padding: 0;
305
+ }
306
+
307
+ .active-filters-row {
308
+ border-top: 1px solid var(--border);
309
+ padding-top: 10px;
310
+ display: grid;
311
+ gap: 6px;
312
+ }
313
+
314
+ .active-filters-title {
315
+ color: var(--muted);
316
+ font-size: 12px;
317
+ }
318
+
319
+ .icon-row {
320
+ display: flex;
321
+ gap: 6px;
322
+ margin-top: 2px;
323
+ }
324
+
325
+ .icon-badge {
326
+ display: inline-flex;
327
+ align-items: center;
328
+ justify-content: center;
329
+ width: 18px;
330
+ height: 18px;
331
+ border: 1px solid var(--border);
332
+ border-radius: 4px;
333
+ font-size: 11px;
334
+ background: var(--surface-2);
335
+ }
336
+
337
+ .icon-badge.feed {
338
+ width: auto;
339
+ min-width: 46px;
340
+ padding: 2px 8px;
341
+ font-weight: 700;
342
+ border-color: var(--schema-accent);
343
+ color: var(--schema-accent);
344
+ background: rgba(251, 189, 35, 0.15);
345
+ }
346
+
347
+ .icon-badge.warn {
348
+ border-color: #f2d5d5;
349
+ color: #a02424;
350
+ background: #fff4f4;
351
+ }
352
+
353
+ .empty {
354
+ color: var(--muted);
355
+ }
356
+
357
+ .mono {
358
+ font-family: inherit;
359
+ }
360
+
361
+ .schema-block {
362
+ border-top: 1px solid var(--border);
363
+ padding: 8px 0 2px;
364
+ margin-bottom: 6px;
365
+ }
366
+
367
+ .schema-block:last-child {
368
+ margin-bottom: 0;
369
+ }
370
+
371
+ .schema-header {
372
+ font-weight: 700;
373
+ margin-bottom: 6px;
374
+ }
375
+
376
+ .schema-tree details {
377
+ margin-left: 12px;
378
+ border-left: 1px solid var(--border);
379
+ padding-left: 8px;
380
+ }
381
+
382
+ .tree-row {
383
+ display: grid;
384
+ grid-template-columns: 1fr auto;
385
+ gap: 8px;
386
+ padding: 3px 0;
387
+ align-items: center;
388
+ }
389
+
390
+ .schema-tree summary .tree-row {
391
+ display: grid;
392
+ vertical-align: middle;
393
+ }
394
+
395
+ .schema-tree > .tree-row {
396
+ margin-left: 18px;
397
+ }
398
+
399
+ .tree-name {
400
+ display: inline-flex;
401
+ align-items: baseline;
402
+ gap: 2px;
403
+ }
404
+
405
+ .tree-col-muted {
406
+ color: var(--muted);
407
+ font-size: 12px;
408
+ }
409
+
410
+ .required-star {
411
+ color: var(--danger);
412
+ font-weight: 700;
413
+ }
414
+
415
+ .tree-pill {
416
+ border: 1px solid var(--schema-accent);
417
+ border-radius: 4px;
418
+ padding: 1px 6px;
419
+ font-size: 11px;
420
+ background: rgba(251, 189, 35, 0.15);
421
+ color: var(--schema-accent);
422
+ }
423
+
424
+ .schema-tree details > summary {
425
+ color: var(--schema-accent);
426
+ list-style: none;
427
+ display: grid;
428
+ grid-template-columns: 12px 1fr;
429
+ align-items: center;
430
+ column-gap: 6px;
431
+ }
432
+
433
+ .schema-tree details > summary::-webkit-details-marker {
434
+ display: none;
435
+ }
436
+
437
+ .schema-tree details > summary::marker {
438
+ content: '';
439
+ }
440
+
441
+ .schema-tree details > summary::before {
442
+ content: '▸';
443
+ display: inline-block;
444
+ grid-column: 1;
445
+ width: 12px;
446
+ text-align: center;
447
+ }
448
+
449
+ .schema-tree details > summary > .tree-row {
450
+ grid-column: 2;
451
+ }
452
+
453
+ .schema-tree details[open] > summary::before {
454
+ content: '▾';
455
+ }
456
+
457
+ input[type='checkbox'] {
458
+ accent-color: var(--accent);
459
+ }
460
+
461
+ @media (max-width: 720px) {
462
+ .primary-row {
463
+ grid-template-columns: 1fr;
464
+ align-items: stretch;
465
+ }
466
+
467
+ .grid-3 {
468
+ grid-template-columns: 1fr;
469
+ }
470
+ }
471
+ </style>
472
+ </head>
473
+ <body>
474
+ <div class="wrap">
475
+ <h1>Finalized Leaves Viewer</h1>
476
+ <div class="card controls">
477
+ <div class="primary-row">
478
+ <label class="control-block">
479
+ <span class="control-label">Load export JSON file</span>
480
+ <input id="fileInput" type="file" accept="application/json,.json" />
481
+ </label>
482
+ <label class="control-block">
483
+ <span class="control-label">Search text</span>
484
+ <input id="searchInput" type="text" placeholder="Type to search..." />
485
+ </label>
486
+ <div class="control-block">
487
+ <span class="control-label">Quick filters</span>
488
+ <div class="quick-toggles">
489
+ <button id="caseSensitive" class="pill-toggle" type="button" aria-pressed="false">
490
+ Case sensitive
491
+ </button>
492
+ <button id="regexSearch" class="pill-toggle" type="button" aria-pressed="false">
493
+ Regex
494
+ </button>
495
+ </div>
496
+ </div>
497
+ </div>
498
+
499
+ <div class="scope-row">
500
+ <div class="scope-actions">
501
+ <button id="selectAllFields" class="scope-action" type="button">All</button>
502
+ <button id="clearAllFields" class="scope-action" type="button">None</button>
503
+ <button id="coreFields" class="scope-action" type="button">Core</button>
504
+ <button id="schemasOnlyFields" class="scope-action" type="button">Schema</button>
505
+ <button id="sourceOnlyFields" class="scope-action" type="button">Source</button>
506
+ </div>
507
+ <div id="fieldChipGroups" class="scope-groups"></div>
508
+ </div>
509
+
510
+ <details class="advanced-panel">
511
+ <summary>Advanced filters</summary>
512
+ <div class="advanced-content">
513
+ <label class="field-item">
514
+ <span>type match</span>
515
+ <select id="typeMatchMode">
516
+ <option value="contains" selected>contains</option>
517
+ <option value="exact">exact</option>
518
+ </select>
519
+ </label>
520
+ <button
521
+ id="schemaRowsMatchOnly"
522
+ class="pill-toggle"
523
+ type="button"
524
+ aria-pressed="false"
525
+ >
526
+ Schema rows match only
527
+ </button>
528
+ <button id="resetFilters" type="button">Reset filters</button>
529
+ </div>
530
+ </details>
531
+
532
+ <div class="active-filters-row">
533
+ <div class="active-filters-title">Active filters</div>
534
+ <div id="activeFilterChips" class="chips filters"></div>
535
+ </div>
536
+
537
+ <div id="status" class="meta">Load a JSON export to begin.</div>
538
+ </div>
539
+
540
+ <div id="results"></div>
541
+ </div>
542
+
543
+ <!--__FINALIZED_LEAVES_BAKED_PAYLOAD__-->
544
+ <script>
545
+ const SEARCH_FIELDS = [
546
+ { id: 'method', label: 'method', get: (leaf) => [leaf.method] },
547
+ { id: 'path', label: 'path', get: (leaf) => [leaf.path] },
548
+ { id: 'key', label: 'key', get: (leaf) => [leaf.key] },
549
+ { id: 'summary', label: 'summary', get: (leaf) => [leaf.cfg?.summary] },
550
+ {
551
+ id: 'description',
552
+ label: 'description',
553
+ get: (leaf) => [leaf.cfg?.description],
554
+ },
555
+ { id: 'docsGroup', label: 'docsGroup', get: (leaf) => [leaf.cfg?.docsGroup] },
556
+ { id: 'tags', label: 'tags', get: (leaf) => leaf.cfg?.tags || [] },
557
+ { id: 'stability', label: 'stability', get: (leaf) => [leaf.cfg?.stability] },
558
+ { id: 'docsMeta', label: 'docsMeta', get: (leaf) => [leaf.cfg?.docsMeta] },
559
+ {
560
+ id: 'sourceDefinition',
561
+ label: 'source definition',
562
+ get: (leaf, schemaFlatByLeaf, payload) => {
563
+ const source = payload?.sourceByLeaf?.[leaf.key]?.definition
564
+ if (!source) return []
565
+ return [`${source.file}:${source.line}:${source.column}`]
566
+ },
567
+ },
568
+ {
569
+ id: 'sourceSchemas',
570
+ label: 'source schemas',
571
+ get: (leaf, schemaFlatByLeaf, payload) => {
572
+ const schemas = payload?.sourceByLeaf?.[leaf.key]?.schemas
573
+ if (!schemas || typeof schemas !== 'object') return []
574
+ return Object.values(schemas).flatMap((schema) => {
575
+ if (!schema || typeof schema !== 'object') return []
576
+ const tokens = []
577
+ if (schema.sourceName) tokens.push(schema.sourceName)
578
+ if (schema.tag) tokens.push(schema.tag)
579
+ tokens.push(`${schema.file}:${schema.line}:${schema.column}`)
580
+ return tokens
581
+ })
582
+ },
583
+ },
584
+ {
585
+ id: 'types',
586
+ label: 'types',
587
+ get: (leaf, schemaFlatByLeaf) => schemaTypeTokens(schemaFlatByLeaf?.[leaf.key]),
588
+ },
589
+ {
590
+ id: 'params',
591
+ label: 'params',
592
+ get: (leaf, schemaFlatByLeaf) =>
593
+ schemaSectionToSearchTokens(schemaFlatByLeaf?.[leaf.key], 'params'),
594
+ },
595
+ {
596
+ id: 'query',
597
+ label: 'query',
598
+ get: (leaf, schemaFlatByLeaf) =>
599
+ schemaSectionToSearchTokens(schemaFlatByLeaf?.[leaf.key], 'query'),
600
+ },
601
+ {
602
+ id: 'body',
603
+ label: 'body',
604
+ get: (leaf, schemaFlatByLeaf) =>
605
+ schemaSectionToSearchTokens(schemaFlatByLeaf?.[leaf.key], 'body'),
606
+ },
607
+ {
608
+ id: 'output',
609
+ label: 'output',
610
+ get: (leaf, schemaFlatByLeaf) =>
611
+ schemaSectionToSearchTokens(schemaFlatByLeaf?.[leaf.key], 'output'),
612
+ },
613
+ ]
614
+
615
+ const SCHEMA_SECTIONS = ['params', 'query', 'body', 'output']
616
+ const SCHEMA_FIELD_IDS = new Set(SCHEMA_SECTIONS)
617
+ const SOURCE_FIELD_IDS = new Set(['sourceDefinition', 'sourceSchemas'])
618
+ const SCHEMA_SCOPE_FIELD_IDS = new Set([...SCHEMA_SECTIONS, 'types'])
619
+ const CORE_FIELD_IDS = new Set(
620
+ SEARCH_FIELDS.map((field) => field.id).filter(
621
+ (id) => !SCHEMA_SCOPE_FIELD_IDS.has(id) && !SOURCE_FIELD_IDS.has(id),
622
+ ),
623
+ )
624
+ const FIELD_GROUPS = [
625
+ {
626
+ id: 'core',
627
+ label: 'Core fields',
628
+ fieldIds: SEARCH_FIELDS.filter((field) => CORE_FIELD_IDS.has(field.id)).map(
629
+ (field) => field.id,
630
+ ),
631
+ },
632
+ {
633
+ id: 'schema',
634
+ label: 'Schema fields',
635
+ fieldIds: SEARCH_FIELDS.filter((field) => SCHEMA_SCOPE_FIELD_IDS.has(field.id)).map(
636
+ (field) => field.id,
637
+ ),
638
+ },
639
+ {
640
+ id: 'source',
641
+ label: 'Source fields',
642
+ fieldIds: SEARCH_FIELDS.filter((field) => SOURCE_FIELD_IDS.has(field.id)).map(
643
+ (field) => field.id,
644
+ ),
645
+ },
646
+ ]
647
+
648
+ const state = {
649
+ payload: null,
650
+ leaves: [],
651
+ selectedFieldIds: new Set(SEARCH_FIELDS.map((field) => field.id)),
652
+ }
653
+
654
+ const fileInput = document.getElementById('fileInput')
655
+ const searchInput = document.getElementById('searchInput')
656
+ const caseSensitiveToggle = document.getElementById('caseSensitive')
657
+ const regexSearchToggle = document.getElementById('regexSearch')
658
+ const typeMatchModeInput = document.getElementById('typeMatchMode')
659
+ const schemaRowsMatchOnlyToggle = document.getElementById('schemaRowsMatchOnly')
660
+ const fieldChipGroups = document.getElementById('fieldChipGroups')
661
+ const activeFilterChips = document.getElementById('activeFilterChips')
662
+ const selectAllFieldsBtn = document.getElementById('selectAllFields')
663
+ const clearAllFieldsBtn = document.getElementById('clearAllFields')
664
+ const coreFieldsBtn = document.getElementById('coreFields')
665
+ const schemasOnlyFieldsBtn = document.getElementById('schemasOnlyFields')
666
+ const sourceOnlyFieldsBtn = document.getElementById('sourceOnlyFields')
667
+ const resetFiltersBtn = document.getElementById('resetFilters')
668
+ const statusEl = document.getElementById('status')
669
+ const resultsEl = document.getElementById('results')
670
+
671
+ const URL_PARAM_KEY = 'filters'
672
+ let isHydratingFromUrl = false
673
+
674
+ function escapeHtml(value) {
675
+ return String(value)
676
+ .replace(/&/g, '&amp;')
677
+ .replace(/</g, '&lt;')
678
+ .replace(/>/g, '&gt;')
679
+ .replace(/"/g, '&quot;')
680
+ .replace(/'/g, '&#39;')
681
+ }
682
+
683
+ function escapeRegExp(value) {
684
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
685
+ }
686
+
687
+ function isPressed(button) {
688
+ return button?.getAttribute('aria-pressed') === 'true'
689
+ }
690
+
691
+ function setPressed(button, pressed) {
692
+ if (!button) return
693
+ button.setAttribute('aria-pressed', pressed ? 'true' : 'false')
694
+ }
695
+
696
+ function togglePressed(button) {
697
+ const next = !isPressed(button)
698
+ setPressed(button, next)
699
+ return next
700
+ }
701
+
702
+ function createSearchEngine(queryRaw, options) {
703
+ const query = queryRaw || ''
704
+ const caseSensitive = Boolean(options.caseSensitive)
705
+ const regex = Boolean(options.regex)
706
+
707
+ if (!query) {
708
+ return {
709
+ active: false,
710
+ query,
711
+ caseSensitive,
712
+ regex,
713
+ error: null,
714
+ test: () => true,
715
+ highlight: (text) => escapeHtml(text ?? ''),
716
+ }
717
+ }
718
+
719
+ if (regex) {
720
+ try {
721
+ const flags = caseSensitive ? 'g' : 'gi'
722
+ const rx = new RegExp(query, flags)
723
+ return {
724
+ active: true,
725
+ query,
726
+ caseSensitive,
727
+ regex,
728
+ error: null,
729
+ test: (text) => {
730
+ const source = String(text ?? '')
731
+ const probe = new RegExp(rx.source, rx.flags)
732
+ return probe.test(source)
733
+ },
734
+ highlight: (text) => {
735
+ const source = String(text ?? '')
736
+ return escapeHtml(source).replace(
737
+ new RegExp(rx.source, rx.flags),
738
+ (m) => `<mark>${m}</mark>`,
739
+ )
740
+ },
741
+ }
742
+ } catch (error) {
743
+ return {
744
+ active: true,
745
+ query,
746
+ caseSensitive,
747
+ regex,
748
+ error: error instanceof Error ? error.message : 'Invalid regex',
749
+ test: () => false,
750
+ highlight: (text) => escapeHtml(text ?? ''),
751
+ }
752
+ }
753
+ }
754
+
755
+ const needle = caseSensitive ? query : query.toLowerCase()
756
+ const flags = caseSensitive ? 'g' : 'gi'
757
+ const safe = escapeRegExp(query)
758
+
759
+ return {
760
+ active: true,
761
+ query,
762
+ caseSensitive,
763
+ regex,
764
+ error: null,
765
+ test: (text) => {
766
+ const source = String(text ?? '')
767
+ const hay = caseSensitive ? source : source.toLowerCase()
768
+ return hay.includes(needle)
769
+ },
770
+ highlight: (text) =>
771
+ escapeHtml(String(text ?? '')).replace(
772
+ new RegExp(safe, flags),
773
+ (m) => `<mark>${m}</mark>`,
774
+ ),
775
+ }
776
+ }
777
+
778
+ function toTokens(value) {
779
+ if (value === null || value === undefined) return []
780
+ if (typeof value === 'string') return [value]
781
+ if (typeof value === 'number' || typeof value === 'boolean') return [String(value)]
782
+ if (Array.isArray(value)) return value.flatMap((item) => toTokens(item))
783
+ if (typeof value === 'object') return [JSON.stringify(value)]
784
+ return []
785
+ }
786
+
787
+ function flatSchemaToSearchTokens(flatSchema) {
788
+ if (!flatSchema || typeof flatSchema !== 'object') return []
789
+
790
+ const tokens = new Set()
791
+
792
+ Object.entries(flatSchema).forEach(([path, info]) => {
793
+ if (path) {
794
+ tokens.add(path)
795
+ path.split('.').forEach((segment) => {
796
+ if (segment) tokens.add(segment)
797
+ })
798
+ }
799
+
800
+ if (info && typeof info === 'object') {
801
+ tokens.add(JSON.stringify(info))
802
+ if (info.type) tokens.add(String(info.type))
803
+ if (info.kind) tokens.add(String(info.kind))
804
+ if (info.description) tokens.add(String(info.description))
805
+ if (Array.isArray(info.enumValues)) {
806
+ info.enumValues.forEach((value) => tokens.add(String(value)))
807
+ }
808
+ } else if (info !== null && info !== undefined) {
809
+ tokens.add(String(info))
810
+ }
811
+ })
812
+
813
+ tokens.add(JSON.stringify(flatSchema))
814
+ return Array.from(tokens)
815
+ }
816
+
817
+ function schemaSectionToSearchTokens(flatSchema, sectionName) {
818
+ if (!flatSchema || typeof flatSchema !== 'object') return []
819
+ const sectionEntries = Object.entries(flatSchema).filter(
820
+ ([path]) => path === sectionName || path.startsWith(`${sectionName}.`),
821
+ )
822
+
823
+ if (sectionEntries.length === 0) return []
824
+ return flatSchemaToSearchTokens(Object.fromEntries(sectionEntries))
825
+ }
826
+
827
+ function schemaTypeTokens(flatSchema) {
828
+ if (!flatSchema || typeof flatSchema !== 'object') return []
829
+
830
+ const tokens = new Set()
831
+ Object.values(flatSchema).forEach((info) => {
832
+ if (!info || typeof info !== 'object') return
833
+ if (info.type) tokens.add(String(info.type))
834
+ if (info.kind) tokens.add(String(info.kind))
835
+ if (Array.isArray(info.enumValues)) {
836
+ info.enumValues.forEach((value) => tokens.add(String(value)))
837
+ }
838
+ })
839
+
840
+ return Array.from(tokens)
841
+ }
842
+
843
+ function schemaEntryTokens(path, info) {
844
+ const tokens = new Set()
845
+
846
+ if (path) {
847
+ tokens.add(path)
848
+ path.split('.').forEach((segment) => {
849
+ if (segment) tokens.add(segment)
850
+ })
851
+ }
852
+
853
+ if (info && typeof info === 'object') {
854
+ tokens.add(JSON.stringify(info))
855
+ if (info.type) tokens.add(String(info.type))
856
+ if (info.kind) tokens.add(String(info.kind))
857
+ if (info.description) tokens.add(String(info.description))
858
+ if (Array.isArray(info.enumValues)) {
859
+ info.enumValues.forEach((value) => tokens.add(String(value)))
860
+ }
861
+ } else if (info !== null && info !== undefined) {
862
+ tokens.add(String(info))
863
+ }
864
+
865
+ return Array.from(tokens)
866
+ }
867
+
868
+ function schemaEntryMatchesActiveFilter(sectionName, fullPath, info, engine, selectedIds) {
869
+ if (!engine.active) return true
870
+
871
+ let matched = false
872
+ if (selectedIds.includes(sectionName)) {
873
+ matched = schemaEntryTokens(fullPath, info).some((token) => engine.test(token))
874
+ }
875
+
876
+ if (!matched && selectedIds.includes('types')) {
877
+ const typeTokens = []
878
+ if (info && typeof info === 'object') {
879
+ if (info.type) typeTokens.push(String(info.type))
880
+ if (info.kind) typeTokens.push(String(info.kind))
881
+ if (Array.isArray(info.enumValues)) {
882
+ info.enumValues.forEach((value) => typeTokens.push(String(value)))
883
+ }
884
+ }
885
+
886
+ if (typeMatchModeInput.value === 'exact' && !engine.regex) {
887
+ const needle = engine.caseSensitive ? engine.query : engine.query.toLowerCase()
888
+ const normalized = engine.caseSensitive
889
+ ? typeTokens
890
+ : typeTokens.map((token) => token.toLowerCase())
891
+ matched = normalized.includes(needle)
892
+ } else {
893
+ matched = typeTokens.some((token) => engine.test(token))
894
+ }
895
+ }
896
+
897
+ return matched
898
+ }
899
+
900
+ function matchesLeaf(leaf, engine, selectedIds) {
901
+ if (!engine.active) return true
902
+ if (selectedIds.length === 0) return false
903
+ const schemaFlatByLeaf = state.payload?.schemaFlatByLeaf || {}
904
+ const payload = state.payload || {}
905
+
906
+ return SEARCH_FIELDS.some((field) => {
907
+ if (!selectedIds.includes(field.id)) return false
908
+ const tokens = toTokens(field.get(leaf, schemaFlatByLeaf, payload))
909
+ if (field.id === 'types' && typeMatchModeInput.value === 'exact' && !engine.regex) {
910
+ const needle = engine.caseSensitive ? engine.query : engine.query.toLowerCase()
911
+ const normalized = engine.caseSensitive
912
+ ? tokens
913
+ : tokens.map((token) => String(token).toLowerCase())
914
+ return normalized.includes(needle)
915
+ }
916
+ return tokens.some((token) => engine.test(token))
917
+ })
918
+ }
919
+
920
+ function el(tag, className, text) {
921
+ const node = document.createElement(tag)
922
+ if (className) node.className = className
923
+ if (text !== undefined) node.textContent = text
924
+ return node
925
+ }
926
+
927
+ function setHighlighted(node, text, engine) {
928
+ node.innerHTML = engine.highlight(text ?? '')
929
+ }
930
+
931
+ function kv(key, value, engine) {
932
+ const box = el('div', 'kv')
933
+ box.appendChild(el('div', 'k', key))
934
+ const valueNode = el('div', 'v mono')
935
+ setHighlighted(valueNode, value === undefined ? '—' : String(value), engine)
936
+ box.appendChild(valueNode)
937
+ return box
938
+ }
939
+
940
+ function renderSchemaSummary(name, schema, engine) {
941
+ const row = el('div', 'kv')
942
+ row.appendChild(el('div', 'k', name))
943
+
944
+ const valueNode = el('div', 'v mono')
945
+ if (!schema) {
946
+ setHighlighted(valueNode, 'not defined', engine)
947
+ row.appendChild(valueNode)
948
+ return row
949
+ }
950
+
951
+ const parts = [schema.kind]
952
+ if (schema.optional) parts.push('optional')
953
+ if (schema.nullable) parts.push('nullable')
954
+ if (Array.isArray(schema.enumValues) && schema.enumValues.length > 0) {
955
+ parts.push(`enum: ${schema.enumValues.join('|')}`)
956
+ }
957
+ if (schema.properties) {
958
+ parts.push(`properties: ${Object.keys(schema.properties).length}`)
959
+ }
960
+
961
+ setHighlighted(valueNode, parts.join(' | '), engine)
962
+ row.appendChild(valueNode)
963
+ return row
964
+ }
965
+
966
+ function sourceHref(source) {
967
+ if (!source || !source.file) return undefined
968
+ const normalizedPath = String(source.file).replace(/\\/g, '/')
969
+ const platform =
970
+ (navigator.userAgentData && navigator.userAgentData.platform) ||
971
+ navigator.platform ||
972
+ ''
973
+ const isWindows = /win/i.test(platform)
974
+ const vscodePath = isWindows
975
+ ? normalizedPath.replace(/^\/+/, '')
976
+ : normalizedPath.startsWith('/')
977
+ ? normalizedPath
978
+ : `/${normalizedPath}`
979
+ const line = Number.isFinite(source.line) ? source.line : 1
980
+ const column = Number.isFinite(source.column) ? source.column : 1
981
+
982
+ return `vscode://file/${encodeURI(vscodePath)}:${line}:${column}`
983
+ }
984
+
985
+ function createSourceRow(label, source, engine) {
986
+ const box = el('div', 'kv')
987
+ const labelNode = el('div', 'v mono')
988
+
989
+ if (!source || !source.file) {
990
+ setHighlighted(labelNode, label, engine)
991
+ box.appendChild(labelNode)
992
+ return box
993
+ }
994
+
995
+ const href = sourceHref(source)
996
+ const link = document.createElement('a')
997
+ link.href = href
998
+ link.target = '_blank'
999
+ link.rel = 'noopener noreferrer'
1000
+ link.innerHTML = engine.highlight(label)
1001
+ labelNode.appendChild(link)
1002
+ box.appendChild(labelNode)
1003
+ return box
1004
+ }
1005
+
1006
+ function splitFlatSchemaBySection(flatSchema) {
1007
+ const result = {
1008
+ params: {},
1009
+ query: {},
1010
+ body: {},
1011
+ output: {},
1012
+ }
1013
+
1014
+ if (!flatSchema) return result
1015
+
1016
+ Object.entries(flatSchema).forEach(([path, info]) => {
1017
+ const section = SCHEMA_SECTIONS.find(
1018
+ (name) => path === name || path.startsWith(`${name}.`),
1019
+ )
1020
+ if (!section) return
1021
+ result[section][path] = info
1022
+ })
1023
+
1024
+ return result
1025
+ }
1026
+
1027
+ const SCHEMA_SOURCE_KEYS_BY_SECTION = {
1028
+ params: 'paramsSchema',
1029
+ query: 'querySchema',
1030
+ body: 'bodySchema',
1031
+ output: 'outputSchema',
1032
+ }
1033
+
1034
+ function getSchemaSource(source, sectionName) {
1035
+ const schemaKey = SCHEMA_SOURCE_KEYS_BY_SECTION[sectionName]
1036
+ if (!schemaKey || !source?.schemas || typeof source.schemas !== 'object') {
1037
+ return {
1038
+ schemaKey,
1039
+ sourceValue: undefined,
1040
+ }
1041
+ }
1042
+
1043
+ return {
1044
+ schemaKey,
1045
+ sourceValue: source.schemas[schemaKey],
1046
+ }
1047
+ }
1048
+
1049
+ function resolveSchemaSourceLabel(schemaKey, sourceValue) {
1050
+ if (!sourceValue || typeof sourceValue !== 'object') return schemaKey || 'schema'
1051
+ return sourceValue.sourceName || sourceValue.tag || schemaKey || 'schema'
1052
+ }
1053
+
1054
+ function createTreeNode(name = '') {
1055
+ return {
1056
+ name,
1057
+ info: null,
1058
+ fullPath: null,
1059
+ children: {},
1060
+ }
1061
+ }
1062
+
1063
+ function buildSchemaTree(entries, sectionName) {
1064
+ const root = createTreeNode(sectionName)
1065
+ Object.entries(entries)
1066
+ .sort(([a], [b]) => a.localeCompare(b))
1067
+ .forEach(([fullPath, info]) => {
1068
+ const trimmed = fullPath === sectionName ? '' : fullPath.slice(sectionName.length + 1)
1069
+ const segments = trimmed ? trimmed.split('.') : []
1070
+
1071
+ let current = root
1072
+ segments.forEach((segment) => {
1073
+ if (!current.children[segment]) {
1074
+ current.children[segment] = createTreeNode(segment)
1075
+ }
1076
+ current = current.children[segment]
1077
+ })
1078
+
1079
+ current.info = info
1080
+ current.fullPath = fullPath
1081
+ })
1082
+
1083
+ return root
1084
+ }
1085
+
1086
+ function renderTreeNode(node, engine, isRoot) {
1087
+ const childKeys = Object.keys(node.children)
1088
+ const hasChildren = childKeys.length > 0
1089
+ const hasInfo = Boolean(node.info)
1090
+ const appendNameCell = (row) => {
1091
+ const nameWrap = el('span', 'mono tree-name')
1092
+ const nameNode = el('span')
1093
+ setHighlighted(nameNode, node.name, engine)
1094
+ nameWrap.appendChild(nameNode)
1095
+
1096
+ if (node.info && !node.info.optional) {
1097
+ const star = el('span', 'required-star', '*')
1098
+ nameWrap.appendChild(star)
1099
+ }
1100
+
1101
+ if (node.info?.nullable) {
1102
+ nameWrap.appendChild(el('span', 'tree-col-muted', '-'))
1103
+ }
1104
+
1105
+ row.appendChild(nameWrap)
1106
+ }
1107
+
1108
+ const appendTypeCell = (row, info) => {
1109
+ const type = el('span', 'tree-pill')
1110
+ setHighlighted(type, info?.type || info?.kind || '—', engine)
1111
+ row.appendChild(type)
1112
+ }
1113
+
1114
+ if (isRoot || hasChildren) {
1115
+ const details = el('details')
1116
+ details.open = true
1117
+ const summary = el('summary')
1118
+ const row = el('div', 'tree-row')
1119
+
1120
+ appendNameCell(row)
1121
+ appendTypeCell(row, hasInfo ? node.info : null)
1122
+
1123
+ summary.appendChild(row)
1124
+ details.appendChild(summary)
1125
+
1126
+ const container = el('div', 'schema-tree')
1127
+ childKeys
1128
+ .sort((a, b) => a.localeCompare(b))
1129
+ .forEach((key) => container.appendChild(renderTreeNode(node.children[key], engine, false)))
1130
+ details.appendChild(container)
1131
+ return details
1132
+ }
1133
+
1134
+ const row = el('div', 'tree-row')
1135
+ appendNameCell(row)
1136
+ appendTypeCell(row, node.info)
1137
+
1138
+ return row
1139
+ }
1140
+
1141
+ function renderSeparatedSchemas(flatSchema, engine, selectedIds, source) {
1142
+ if (!flatSchema || typeof flatSchema !== 'object') return null
1143
+ const section = el('div', 'section')
1144
+ section.appendChild(el('h3', '', 'Schemas (separated by section)'))
1145
+
1146
+ const grouped = splitFlatSchemaBySection(flatSchema)
1147
+ let hasAnySchemaEntries = false
1148
+ const limitToMatchedRows = isPressed(schemaRowsMatchOnlyToggle) && engine.active
1149
+
1150
+ SCHEMA_SECTIONS.forEach((sectionName) => {
1151
+ const rawEntries = grouped[sectionName]
1152
+ if (!rawEntries || Object.keys(rawEntries).length === 0) return
1153
+
1154
+ const entries = limitToMatchedRows
1155
+ ? Object.fromEntries(
1156
+ Object.entries(rawEntries).filter(([fullPath, info]) =>
1157
+ schemaEntryMatchesActiveFilter(sectionName, fullPath, info, engine, selectedIds),
1158
+ ),
1159
+ )
1160
+ : rawEntries
1161
+ if (Object.keys(entries).length === 0) return
1162
+
1163
+ hasAnySchemaEntries = true
1164
+ const block = el('div', 'schema-block')
1165
+ const header = el('div', 'schema-header mono')
1166
+ setHighlighted(header, sectionName, engine)
1167
+ block.appendChild(header)
1168
+
1169
+ const schemaSource = getSchemaSource(source, sectionName)
1170
+ if (schemaSource.sourceValue) {
1171
+ block.appendChild(
1172
+ createSourceRow(
1173
+ resolveSchemaSourceLabel(
1174
+ schemaSource.schemaKey || `${sectionName}Schema`,
1175
+ schemaSource.sourceValue,
1176
+ ),
1177
+ schemaSource.sourceValue,
1178
+ engine,
1179
+ ),
1180
+ )
1181
+ }
1182
+
1183
+ const tree = buildSchemaTree(entries, sectionName)
1184
+ block.appendChild(renderTreeNode(tree, engine, true))
1185
+
1186
+ section.appendChild(block)
1187
+ })
1188
+
1189
+ return hasAnySchemaEntries ? section : null
1190
+ }
1191
+
1192
+ function renderLeaf(leaf, engine, selectedIds) {
1193
+ const details = el('details', 'leaf')
1194
+ const summary = el('summary')
1195
+ setHighlighted(summary, `${String(leaf.method || '').toUpperCase()} ${leaf.path || ''}`, engine)
1196
+ details.appendChild(summary)
1197
+
1198
+ const content = el('div', 'leaf-content')
1199
+ const cfg = leaf.cfg || {}
1200
+ const flatSchema = state.payload?.schemaFlatByLeaf?.[leaf.key]
1201
+
1202
+ const overview = el('div', 'section')
1203
+ overview.appendChild(el('h3', '', 'Overview'))
1204
+ const topGrid = el('div', 'grid-3')
1205
+ topGrid.appendChild(kv('group', cfg.docsGroup, engine))
1206
+ topGrid.appendChild(
1207
+ kv('tags', cfg.tags && cfg.tags.length > 0 ? cfg.tags.join(', ') : undefined, engine),
1208
+ )
1209
+ topGrid.appendChild(kv('stability', cfg.stability, engine))
1210
+ overview.appendChild(topGrid)
1211
+ overview.appendChild(kv('summary', cfg.summary, engine))
1212
+ overview.appendChild(kv('description', cfg.description, engine))
1213
+
1214
+ const iconRow = el('div', 'icon-row')
1215
+ if (cfg.feed) {
1216
+ const feed = el('span', 'icon-badge feed')
1217
+ feed.title = 'Feed endpoint'
1218
+ setHighlighted(feed, 'Feed', engine)
1219
+ iconRow.appendChild(feed)
1220
+ }
1221
+ if (cfg.deprecated) {
1222
+ const deprecated = el('span', 'icon-badge warn')
1223
+ deprecated.title = 'Deprecated'
1224
+ setHighlighted(deprecated, 'D', engine)
1225
+ iconRow.appendChild(deprecated)
1226
+ }
1227
+ if (cfg.docsHidden) {
1228
+ const hidden = el('span', 'icon-badge warn')
1229
+ hidden.title = 'Hidden'
1230
+ setHighlighted(hidden, 'H', engine)
1231
+ iconRow.appendChild(hidden)
1232
+ }
1233
+ if (iconRow.childNodes.length > 0) {
1234
+ overview.appendChild(iconRow)
1235
+ }
1236
+ content.appendChild(overview)
1237
+
1238
+ const files = el('div', 'section')
1239
+ if (Array.isArray(cfg.bodyFiles) && cfg.bodyFiles.length > 0) {
1240
+ files.appendChild(el('h3', '', 'Body Files'))
1241
+ const chips = el('div', 'chips')
1242
+ cfg.bodyFiles.forEach((file) => {
1243
+ const chip = el('span', 'chip ok')
1244
+ setHighlighted(chip, `${file.name} (max ${file.maxCount})`, engine)
1245
+ chips.appendChild(chip)
1246
+ })
1247
+ files.appendChild(chips)
1248
+ content.appendChild(files)
1249
+ }
1250
+
1251
+ const sourceByLeaf = state.payload?.sourceByLeaf || {}
1252
+ const source = sourceByLeaf[leaf.key]
1253
+ if (source?.definition) {
1254
+ overview.appendChild(createSourceRow('definition', source.definition, engine))
1255
+ }
1256
+
1257
+ const separatedSchemas = renderSeparatedSchemas(flatSchema, engine, selectedIds, source)
1258
+ if (separatedSchemas) {
1259
+ content.appendChild(separatedSchemas)
1260
+ }
1261
+
1262
+ details.appendChild(content)
1263
+ return details
1264
+ }
1265
+
1266
+ function renderResults() {
1267
+ const engine = createSearchEngine(searchInput.value.trim(), {
1268
+ caseSensitive: isPressed(caseSensitiveToggle),
1269
+ regex: isPressed(regexSearchToggle),
1270
+ })
1271
+
1272
+ if (engine.error) {
1273
+ statusEl.textContent = `Invalid regex: ${engine.error}`
1274
+ resultsEl.innerHTML = ''
1275
+ resultsEl.appendChild(el('div', 'empty', 'Fix the regex to continue.'))
1276
+ renderActiveFilterChips({
1277
+ selectedIds: selectedFieldIds(),
1278
+ hasRegexError: true,
1279
+ })
1280
+ return
1281
+ }
1282
+
1283
+ const selectedIds = selectedFieldIds()
1284
+ const filtered = state.leaves.filter((leaf) => matchesLeaf(leaf, engine, selectedIds))
1285
+
1286
+ statusEl.textContent = `${filtered.length} / ${state.leaves.length} routes matched.`
1287
+ resultsEl.innerHTML = ''
1288
+ renderActiveFilterChips({ selectedIds, hasRegexError: false })
1289
+
1290
+ if (filtered.length === 0) {
1291
+ resultsEl.appendChild(el('div', 'empty', 'No matches.'))
1292
+ syncFilterStateToUrl()
1293
+ return
1294
+ }
1295
+
1296
+ filtered.forEach((leaf) => {
1297
+ resultsEl.appendChild(renderLeaf(leaf, engine, selectedIds))
1298
+ })
1299
+ syncFilterStateToUrl()
1300
+ }
1301
+
1302
+ function selectedFieldIds() {
1303
+ return SEARCH_FIELDS.filter((field) => state.selectedFieldIds.has(field.id)).map(
1304
+ (field) => field.id,
1305
+ )
1306
+ }
1307
+
1308
+ function renderFieldChips() {
1309
+ fieldChipGroups.innerHTML = ''
1310
+ FIELD_GROUPS.forEach((group) => {
1311
+ const groupWrap = el('div', 'scope-group')
1312
+ groupWrap.appendChild(el('div', 'scope-group-title', group.label))
1313
+ const chipsWrap = el('div', 'scope-group-chips')
1314
+
1315
+ group.fieldIds.forEach((fieldId) => {
1316
+ const field = SEARCH_FIELDS.find((item) => item.id === fieldId)
1317
+ if (!field) return
1318
+ const chip = document.createElement('button')
1319
+ chip.type = 'button'
1320
+ chip.className = 'field-chip'
1321
+ chip.textContent = field.label
1322
+ setPressed(chip, state.selectedFieldIds.has(field.id))
1323
+ chip.addEventListener('click', () => {
1324
+ if (state.selectedFieldIds.has(field.id)) {
1325
+ state.selectedFieldIds.delete(field.id)
1326
+ } else {
1327
+ state.selectedFieldIds.add(field.id)
1328
+ }
1329
+ renderFieldChips()
1330
+ renderResults()
1331
+ })
1332
+ chipsWrap.appendChild(chip)
1333
+ })
1334
+
1335
+ groupWrap.appendChild(chipsWrap)
1336
+ fieldChipGroups.appendChild(groupWrap)
1337
+ })
1338
+ }
1339
+
1340
+ function setFieldSelection(allowedIds, options = {}) {
1341
+ const { rerender = true } = options
1342
+ state.selectedFieldIds = new Set(
1343
+ SEARCH_FIELDS.map((field) => field.id).filter((id) => allowedIds.has(id)),
1344
+ )
1345
+ renderFieldChips()
1346
+ if (rerender) renderResults()
1347
+ }
1348
+
1349
+ function resetFiltersToDefault() {
1350
+ searchInput.value = ''
1351
+ setPressed(caseSensitiveToggle, false)
1352
+ setPressed(regexSearchToggle, false)
1353
+ typeMatchModeInput.value = 'contains'
1354
+ setPressed(schemaRowsMatchOnlyToggle, false)
1355
+ setFieldSelection(new Set(SEARCH_FIELDS.map((field) => field.id)), { rerender: false })
1356
+ renderResults()
1357
+ }
1358
+
1359
+ function renderActiveFilterChips({ selectedIds, hasRegexError }) {
1360
+ activeFilterChips.innerHTML = ''
1361
+ const searchValue = searchInput.value.trim()
1362
+ const chipModels = []
1363
+
1364
+ if (searchValue) {
1365
+ chipModels.push({
1366
+ text: `search: ${searchValue}`,
1367
+ onClick: () => {
1368
+ searchInput.value = ''
1369
+ renderResults()
1370
+ },
1371
+ })
1372
+ }
1373
+ if (typeMatchModeInput.value === 'exact') {
1374
+ chipModels.push({
1375
+ text: 'type mode: exact',
1376
+ onClick: () => {
1377
+ typeMatchModeInput.value = 'contains'
1378
+ renderResults()
1379
+ },
1380
+ })
1381
+ }
1382
+ if (isPressed(schemaRowsMatchOnlyToggle)) {
1383
+ chipModels.push({
1384
+ text: 'schema rows: matched only',
1385
+ onClick: () => {
1386
+ setPressed(schemaRowsMatchOnlyToggle, false)
1387
+ renderResults()
1388
+ },
1389
+ })
1390
+ }
1391
+ if (isPressed(caseSensitiveToggle)) {
1392
+ chipModels.push({
1393
+ text: 'case sensitive',
1394
+ onClick: () => {
1395
+ setPressed(caseSensitiveToggle, false)
1396
+ renderResults()
1397
+ },
1398
+ })
1399
+ }
1400
+ if (isPressed(regexSearchToggle)) {
1401
+ chipModels.push({
1402
+ text: 'regex',
1403
+ onClick: () => {
1404
+ setPressed(regexSearchToggle, false)
1405
+ renderResults()
1406
+ },
1407
+ })
1408
+ }
1409
+ if (hasRegexError) chipModels.push({ text: 'regex error' })
1410
+
1411
+ const allIds = SEARCH_FIELDS.map((field) => field.id)
1412
+ if (selectedIds.length !== allIds.length) {
1413
+ chipModels.push({
1414
+ text: `fields: ${selectedIds.join(', ') || 'none'}`,
1415
+ onClick: () => setFieldSelection(new Set(allIds)),
1416
+ })
1417
+ }
1418
+
1419
+ if (chipModels.length === 0) {
1420
+ activeFilterChips.appendChild(el('span', 'empty', 'No active filters'))
1421
+ return
1422
+ }
1423
+
1424
+ chipModels.forEach((chipModel) => {
1425
+ const chip = document.createElement(chipModel.onClick ? 'button' : 'span')
1426
+ chip.className = chipModel.onClick ? 'chip chip-btn' : 'chip'
1427
+ chip.textContent = chipModel.text
1428
+ if (chipModel.onClick) {
1429
+ chip.type = 'button'
1430
+ chip.addEventListener('click', chipModel.onClick)
1431
+ }
1432
+ activeFilterChips.appendChild(chip)
1433
+ })
1434
+ }
1435
+
1436
+ function collectFilterState() {
1437
+ return {
1438
+ search: searchInput.value,
1439
+ caseSensitive: isPressed(caseSensitiveToggle),
1440
+ regex: isPressed(regexSearchToggle),
1441
+ typeMatchMode: typeMatchModeInput.value === 'exact' ? 'exact' : 'contains',
1442
+ schemaRowsMatchOnly: isPressed(schemaRowsMatchOnlyToggle),
1443
+ selectedFields: selectedFieldIds(),
1444
+ }
1445
+ }
1446
+
1447
+ function syncFilterStateToUrl() {
1448
+ if (isHydratingFromUrl) return
1449
+
1450
+ const data = collectFilterState()
1451
+ const params = new URLSearchParams(window.location.hash.replace(/^#/, ''))
1452
+ const serialized = encodeURIComponent(JSON.stringify(data))
1453
+ params.set(URL_PARAM_KEY, serialized)
1454
+ const nextHash = params.toString()
1455
+ if (window.location.hash !== `#${nextHash}`) {
1456
+ window.location.hash = nextHash
1457
+ }
1458
+ }
1459
+
1460
+ function hydrateFilterStateFromUrl() {
1461
+ const params = new URLSearchParams(window.location.hash.replace(/^#/, ''))
1462
+ const raw = params.get(URL_PARAM_KEY)
1463
+ if (!raw) return
1464
+
1465
+ try {
1466
+ const parsed = JSON.parse(decodeURIComponent(raw))
1467
+ isHydratingFromUrl = true
1468
+ if (typeof parsed.search === 'string') searchInput.value = parsed.search
1469
+ setPressed(caseSensitiveToggle, Boolean(parsed.caseSensitive))
1470
+ setPressed(regexSearchToggle, Boolean(parsed.regex))
1471
+ if (parsed.typeMatchMode === 'exact' || parsed.typeMatchMode === 'contains') {
1472
+ typeMatchModeInput.value = parsed.typeMatchMode
1473
+ }
1474
+ setPressed(schemaRowsMatchOnlyToggle, Boolean(parsed.schemaRowsMatchOnly))
1475
+
1476
+ if (Array.isArray(parsed.selectedFields)) {
1477
+ setFieldSelection(new Set(parsed.selectedFields), { rerender: false })
1478
+ }
1479
+ } catch (error) {
1480
+ // Ignore malformed hash state.
1481
+ } finally {
1482
+ isHydratingFromUrl = false
1483
+ }
1484
+ }
1485
+
1486
+ async function handleFile(file) {
1487
+ const text = await file.text()
1488
+ const parsed = JSON.parse(text)
1489
+ if (!parsed || !Array.isArray(parsed.leaves)) {
1490
+ throw new Error('Invalid export file: expected top-level "leaves" array.')
1491
+ }
1492
+
1493
+ state.payload = parsed
1494
+ state.leaves = parsed.leaves
1495
+ renderResults()
1496
+ }
1497
+
1498
+ function initializeFromBakedPayload() {
1499
+ const baked = window.__FINALIZED_LEAVES_PAYLOAD
1500
+ if (!baked || !Array.isArray(baked.leaves)) return
1501
+
1502
+ state.payload = baked
1503
+ state.leaves = baked.leaves
1504
+ statusEl.textContent = `Loaded baked payload with ${state.leaves.length} routes.`
1505
+ renderResults()
1506
+ }
1507
+
1508
+ fileInput.addEventListener('change', async (event) => {
1509
+ const file = event.target.files?.[0]
1510
+ if (!file) return
1511
+
1512
+ try {
1513
+ await handleFile(file)
1514
+ } catch (error) {
1515
+ statusEl.textContent = error instanceof Error ? error.message : String(error)
1516
+ resultsEl.innerHTML = ''
1517
+ }
1518
+ })
1519
+
1520
+ searchInput.addEventListener('input', renderResults)
1521
+ caseSensitiveToggle.addEventListener('click', () => {
1522
+ togglePressed(caseSensitiveToggle)
1523
+ renderResults()
1524
+ })
1525
+ regexSearchToggle.addEventListener('click', () => {
1526
+ togglePressed(regexSearchToggle)
1527
+ renderResults()
1528
+ })
1529
+ typeMatchModeInput.addEventListener('change', renderResults)
1530
+ schemaRowsMatchOnlyToggle.addEventListener('click', () => {
1531
+ togglePressed(schemaRowsMatchOnlyToggle)
1532
+ renderResults()
1533
+ })
1534
+
1535
+ selectAllFieldsBtn.addEventListener('click', () =>
1536
+ setFieldSelection(new Set(SEARCH_FIELDS.map((field) => field.id))),
1537
+ )
1538
+ clearAllFieldsBtn.addEventListener('click', () => setFieldSelection(new Set()))
1539
+ coreFieldsBtn.addEventListener('click', () => setFieldSelection(CORE_FIELD_IDS))
1540
+ schemasOnlyFieldsBtn.addEventListener('click', () => setFieldSelection(SCHEMA_SCOPE_FIELD_IDS))
1541
+ sourceOnlyFieldsBtn.addEventListener('click', () => setFieldSelection(SOURCE_FIELD_IDS))
1542
+ resetFiltersBtn.addEventListener('click', resetFiltersToDefault)
1543
+
1544
+ renderFieldChips()
1545
+ hydrateFilterStateFromUrl()
1546
+ initializeFromBakedPayload()
1547
+ renderResults()
1548
+ </script>
1549
+ </body>
1550
+ </html>