Repository navigation
Expand file tree
/
Copy pathSTR.html
More file actions
3974 lines (3726 loc) · 172 KB
/
Copy pathSTR.html
File metadata and controls
3974 lines (3726 loc) · 172 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Search Term Validator — v12</title>
<!--
APP_VERSION is defined once in the <script> block below and drives:
(a) the version badge in the header
(b) the <title> suffix
(c) the CSV export filename suffix
When producing a new iteration, update the single APP_VERSION constant
(and this <title>) and everything else follows.
-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* =====================================================================
DESIGN LAYER — v11
Purely presentational. No selector names, IDs or DOM hooks were added,
removed or renamed relative to v10, and the geometry the virtual
scroller depends on is preserved exactly:
.lines padding-top .......... 12px (matches ROW_HEIGHT offset +12)
.line line-height/min-height 20px (matches ROW_HEIGHT = 20)
.line left gutter ........... 46px (.ln absolute, 38px wide)
.pane-body has no padding (it is the scroll host)
Changing any of the four above will desynchronise row positioning.
===================================================================== */
*, *::before, *::after { box-sizing: border-box; }
:root {
/* Surfaces */
--bg: #eef0f4;
--panel: #ffffff;
--surface-alt: #f7f8fa;
--surface-sunken: #f1f3f7;
--border: #e4e7ee;
--border-strong: #cdd2dd;
/* Ink */
--text: #14161b;
--text-muted: #626b7b;
--text-faint: #98a0af;
/* Accent */
--accent: #2b54c9;
--accent-hover: #1f3fa3;
--accent-soft: #edf2ff;
/* Severity — row tints, solid marks, and ink */
--red-bg: #fdf0ef; --red-border: #c8453f; --red-text: #8a2320;
--yellow-bg: #fdf6e4; --yellow-border: #d9a326; --yellow-text: #6a4a09;
--blue-bg: #ecf2fd; --blue-border: #3f74c9; --blue-text: #1b4585;
--mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
--sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
--shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
--shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .07);
--shadow-lg: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 8px rgba(16, 24, 40, .08);
--radius: 10px;
--radius-lg: 14px;
}
html, body { height: 100%; margin: 0; }
body {
font-family: var(--sans);
color: var(--text);
background: var(--bg);
font-size: 14px;
line-height: 1.45;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
}
::selection { background: #cfdcfa; color: var(--text); }
/* Thin, unobtrusive scrollbars */
* { scrollbar-width: thin; scrollbar-color: #c8cddb transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
background: #ccd2df; border-radius: 999px;
border: 3px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: #b3bbcc; background-clip: content-box; }
button {
font-family: inherit; font-size: 13px; font-weight: 500;
letter-spacing: .005em;
border: 1px solid var(--border-strong);
background: #fff; color: var(--text);
padding: 6px 12px; border-radius: 8px; cursor: pointer;
box-shadow: var(--shadow-sm);
transition: background .14s ease, border-color .14s ease, box-shadow .14s ease, color .14s ease, transform .14s ease;
}
button:hover { background: var(--surface-alt); border-color: #b9c0ce; }
button:active { transform: translateY(.5px); }
button.primary {
background: var(--accent); color: #fff; border-color: var(--accent);
box-shadow: 0 1px 2px rgba(28, 55, 130, .28), 0 1px 3px rgba(28, 55, 130, .18);
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
/* Ghost buttons stay clearly readable — they are real actions
("Load sample", "Report (.md)", "Copy all"), not disabled controls. */
button.ghost { background: transparent; border-color: transparent; box-shadow: none; color: #414b5c; }
button.ghost:hover { background: var(--surface-sunken); color: var(--text); }
button:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
/* --- Layout ----------------------------------------------------------- */
.app { display: flex; flex-direction: column; height: 100vh; }
header.topbar {
display: flex; align-items: center; flex-wrap: wrap;
gap: 8px; row-gap: 8px;
padding: 12px 18px;
background: rgba(255, 255, 255, .88);
backdrop-filter: saturate(180%) blur(8px);
-webkit-backdrop-filter: saturate(180%) blur(8px);
border-bottom: 1px solid var(--border);
box-shadow: 0 1px 0 rgba(16, 24, 40, .02);
z-index: 20;
}
header .brand {
display: flex; align-items: center; gap: 10px;
font-weight: 600; font-size: 15px; letter-spacing: -.01em;
margin-right: 6px; white-space: nowrap;
}
/* Toolbar controls keep their labels on one line; when the bar runs out of
room the row wraps instead of squashing labels into two lines. */
header.topbar button { white-space: nowrap; flex: 0 0 auto; }
header .brand svg {
display: block;
color: var(--accent);
background: var(--accent-soft);
border-radius: 7px;
padding: 3px;
width: 26px; height: 26px;
box-shadow: inset 0 0 0 1px rgba(43, 84, 201, .12);
}
.spacer { flex: 1; }
.summary {
display: flex; align-items: center; gap: 6px;
flex-wrap: wrap; min-width: 0;
font-size: 12px; color: var(--text-muted);
padding: 4px 6px;
background: var(--surface-sunken);
border: 1px solid var(--border); border-radius: 999px;
}
.summary .pill {
display: inline-flex; align-items: center; gap: 4px;
padding: 3px 10px; border-radius: 999px;
font-weight: 600; font-variant-numeric: tabular-nums;
border: 1px solid transparent;
transition: box-shadow .14s ease, transform .14s ease, filter .14s ease;
}
.summary .pill:hover { filter: brightness(.97); box-shadow: 0 1px 3px rgba(16, 24, 40, .10); }
.pill.err { background: var(--red-bg); color: var(--red-text); border-color: rgba(200, 69, 63, .22); }
.pill.warn { background: var(--yellow-bg); color: var(--yellow-text); border-color: rgba(217, 163, 38, .28); }
.pill.fix { background: var(--blue-bg); color: var(--blue-text); border-color: rgba(63, 116, 201, .22); }
.pill.total { background: #fff; color: var(--text-muted); border-color: var(--border); }
/* v8: perf badge and jump-to-line input */
.perf-badge {
font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums;
padding: 2px 8px; border-radius: 999px; background: transparent;
display: none;
}
.perf-badge.visible {
display: inline-flex; align-items: center; gap: 4px;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
max-width: 300px;
}
.perf-badge.slow { color: var(--yellow-text); background: var(--yellow-bg); }
.jump-wrap { display: inline-flex; align-items: center; gap: 6px; margin-left: 2px; white-space: nowrap; }
.jump-wrap input {
font-family: var(--mono); font-size: 11px;
width: 64px; padding: 3px 8px;
border: 1px solid var(--border-strong); border-radius: 999px;
background: #fff; color: var(--text);
transition: border-color .14s ease, box-shadow .14s ease;
}
.jump-wrap input:hover { border-color: #b9c0ce; }
.jump-wrap input:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 3px rgba(43, 84, 201, .16);
}
/* v8: brief highlight on Go-To-Line jump target. */
@keyframes stv-flash {
0% { background: rgba(43, 84, 201, .28); }
100% { background: transparent; }
}
.line.flash { animation: stv-flash 900ms ease-out; }
main {
flex: 1;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 14px;
padding: 14px 16px 16px;
overflow: hidden;
background: var(--bg);
}
.pane {
display: flex; flex-direction: column;
background: var(--panel);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-sm);
overflow: hidden;
min-width: 0;
}
.pane-header {
display: flex; align-items: center; gap: 8px;
padding: 10px 14px;
border-bottom: 1px solid var(--border);
font-size: 11px; font-weight: 700;
color: var(--text-muted);
text-transform: uppercase; letter-spacing: .07em;
background: linear-gradient(180deg, #fbfcfd 0%, var(--surface-alt) 100%);
min-height: 40px;
}
/* The scroll host for the virtual scroller — must stay padding-free. */
.pane-body { flex: 1; overflow: auto; position: relative; }
/* Input textarea */
#inputArea {
width: 100%; height: 100%;
border: 0; padding: 12px 14px;
resize: none; outline: none;
font-family: var(--mono); font-size: 13px;
line-height: 20px;
background: transparent; color: var(--text);
tab-size: 4;
}
#inputArea::placeholder { color: var(--text-faint); }
/* Highlighted overlay (post-validation view) */
.lines {
font-family: var(--mono); font-size: 13px; line-height: 20px;
padding: 12px 0;
}
.line {
display: flex; align-items: flex-start;
padding: 0 14px 0 46px;
position: relative;
min-height: 20px;
white-space: pre;
transition: background .1s ease;
}
.line:hover { background: var(--surface-alt); }
.line .ln {
position: absolute; left: 0; top: 0;
width: 38px; text-align: right;
color: var(--text-faint); font-size: 11px;
font-variant-numeric: tabular-nums;
user-select: none;
padding-top: 1px;
}
/* Severity rows: soft tint + a hairline severity rail on the left edge.
Both are paint-only (inset shadow), so the 20px row box is unchanged. */
.line.err { background: var(--red-bg); box-shadow: inset 3px 0 0 var(--red-border); }
.line.warn { background: var(--yellow-bg); box-shadow: inset 3px 0 0 var(--yellow-border); }
.line.fix { background: var(--blue-bg); box-shadow: inset 3px 0 0 var(--blue-border); }
.line.err:hover { background: #fce7e5; }
.line.warn:hover { background: #fbf1d6; }
.line.fix:hover { background: #e4edfc; }
.line .content { flex: 1; word-break: break-all; white-space: pre-wrap; }
.line .content.needs-review { color: var(--red-text); font-style: italic; }
.line .content.placeholder { color: var(--text-faint); font-style: italic; }
.line .copy {
opacity: 0; margin-left: 8px;
font-size: 10px; font-weight: 600;
text-transform: uppercase; letter-spacing: .06em;
line-height: 16px; padding: 0 8px;
border-radius: 999px;
background: #fff; border: 1px solid var(--border-strong);
color: var(--text-muted);
box-shadow: none;
transition: opacity .12s ease, color .12s ease, border-color .12s ease;
}
.line:hover .copy { opacity: 1; }
.line .copy:hover { background: #fff; color: var(--accent); border-color: var(--accent); }
/* Issues sidebar (below output) — inline chips.
v9: force single-line clipping so multi-chip rows can't overflow the
fixed 20 px slot used by the virtual scroller. Excess chips are moved
into a "+N" pill (see buildRow). */
.chips {
display: inline-flex; flex-wrap: nowrap; gap: 4px;
margin-left: 8px; vertical-align: middle;
max-width: 55%;
overflow: hidden; white-space: nowrap;
align-items: center;
}
.chip {
display: inline-block;
/* v9 (retained): 11px with wider tracking reads sharply on 4K displays.
line-height is pinned at 16px so a chip can never exceed the fixed
20 px row slot the virtual scroller allocates. */
font-size: 11px; font-weight: 700; text-transform: uppercase;
line-height: 16px; padding: 0 7px; border-radius: 999px;
letter-spacing: .05em;
cursor: pointer;
border: 1px solid transparent;
transition: transform .1s ease, box-shadow .1s ease, filter .1s ease;
flex: 0 0 auto;
}
.chip:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(16, 24, 40, .18); filter: saturate(1.05); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Contrast (WCAG AA, 11px bold ⇒ 4.5:1 required):
.err #fff on #c8453f ≈ 4.8:1
.warn #362000 on #d9a326 ≈ 5.1:1 (v9 fix, preserved)
.fix #fff on #3f74c9 ≈ 4.6:1 */
.chip.err { background: var(--red-border); color: #fff; border-color: #ab3833; }
.chip.warn { background: var(--yellow-border); color: #362000; border-color: #b8871f; }
.chip.fix { background: var(--blue-border); color: #fff; border-color: #315fa8; }
.chip.filter-active { outline: 2px solid var(--text); outline-offset: 1px; }
/* v9: overflow pill "+N" — quieter than a real chip so it doesn't compete. */
.chip.more {
background: #fff; color: var(--text-muted);
border-color: var(--border-strong);
font-weight: 600;
}
.chip.more:hover { color: var(--text); border-color: #b9c0ce; }
/* Tooltip */
#tooltip {
position: fixed; z-index: 1000;
max-width: 380px;
background: #14161b; color: #eef0f4;
padding: 11px 13px; border-radius: 10px;
font-size: 12px; line-height: 1.55;
box-shadow: 0 16px 40px rgba(10, 14, 22, .32), 0 2px 8px rgba(10, 14, 22, .22);
border: 1px solid rgba(255, 255, 255, .08);
pointer-events: none;
opacity: 0; transition: opacity .12s ease;
font-family: var(--sans);
}
#tooltip.visible { opacity: 1; }
#tooltip .tt-title {
font-weight: 700; margin-bottom: 5px;
letter-spacing: .02em;
}
#tooltip .tt-rule {
font-family: var(--mono); font-size: 11px; color: #a3adbe;
margin-top: 8px; padding-top: 8px;
border-top: 1px solid rgba(255, 255, 255, .12);
}
#tooltip ul { margin: 4px 0 0; padding-left: 18px; }
/* v9: arrow shown only in keyboard-anchored mode. */
#tooltip.anchored::before {
content: ''; position: absolute; width: 8px; height: 8px;
background: #14161b; transform: rotate(45deg);
left: -4px; top: 14px;
}
#tooltip.anchored.arrow-right::before { left: auto; right: -4px; }
#tooltip.anchored.arrow-below::before { left: 14px; top: -4px; }
#tooltip.anchored.arrow-above::before { left: 14px; top: auto; bottom: -4px; right: auto; }
/* v9: screen-reader-only visually-hidden helper for the live region. */
.sr-only {
position: absolute; width: 1px; height: 1px;
padding: 0; margin: -1px; overflow: hidden;
clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
/* Settings modal */
.modal-backdrop {
position: fixed; inset: 0;
background: rgba(17, 22, 33, .45);
backdrop-filter: blur(3px);
-webkit-backdrop-filter: blur(3px);
display: none; align-items: center; justify-content: center;
z-index: 500;
padding: 24px;
}
.modal-backdrop.visible { display: flex; animation: stv-fade .14s ease-out; }
@keyframes stv-fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
background: #fff; border-radius: 16px;
border: 1px solid var(--border);
box-shadow: var(--shadow-lg);
width: 560px; max-width: 92vw;
max-height: 88vh; overflow: auto;
}
.modal header {
padding: 16px 20px; border-bottom: 1px solid var(--border);
display: flex; align-items: center;
position: sticky; top: 0;
background: rgba(255, 255, 255, .94);
backdrop-filter: blur(6px);
-webkit-backdrop-filter: blur(6px);
z-index: 1;
}
.modal header h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.modal .content { padding: 18px 20px; }
.modal .content h3 { color: var(--text-muted); }
.modal .content a { color: var(--accent); text-decoration-color: rgba(43, 84, 201, .3); text-underline-offset: 2px; }
.modal .content a:hover { text-decoration-color: var(--accent); }
.modal .content code {
font-family: var(--mono); font-size: 11.5px;
background: var(--surface-sunken); border: 1px solid var(--border);
padding: 1px 5px; border-radius: 5px;
}
.modal footer {
padding: 14px 20px; border-top: 1px solid var(--border);
display: flex; gap: 8px; justify-content: flex-end;
background: var(--surface-alt);
position: sticky; bottom: 0;
}
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }
.field input[type="number"], .field textarea {
width: 100%; padding: 8px 10px;
border: 1px solid var(--border-strong); border-radius: 8px;
font-family: var(--mono); font-size: 12px;
background: #fff; color: var(--text);
transition: border-color .14s ease, box-shadow .14s ease;
}
.field input[type="number"]:focus, .field textarea:focus {
outline: none; border-color: var(--accent);
box-shadow: 0 0 0 3px rgba(43, 84, 201, .16);
}
.field textarea { height: 96px; resize: vertical; line-height: 1.6; }
.field .hint { font-size: 11px; color: var(--text-muted); margin-top: 5px; line-height: 1.5; }
.toggle {
display: flex; align-items: center; gap: 9px;
font-size: 13px; font-weight: 500; color: var(--text);
cursor: pointer;
}
.toggle input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
/* Focus + a11y */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
/* Toast */
.toast {
position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
background: #14161b; color: #fff;
padding: 9px 16px; border-radius: 999px;
font-size: 12px; font-weight: 500; z-index: 2000;
box-shadow: var(--shadow-lg);
opacity: 0; transition: opacity .18s ease;
pointer-events: none;
}
.toast.visible { opacity: 1; }
/* v12: "Download to run privately offline" — an anchor styled as a
toolbar control. Accent-tinted so it reads as the one link on the bar
without competing with the primary Validate button. */
.dl-link {
display: inline-flex; align-items: center; gap: 7px;
flex: 0 0 auto; white-space: nowrap;
font-size: 13px; font-weight: 600; line-height: 1;
padding: 7px 13px; border-radius: 8px;
color: var(--accent); text-decoration: none;
background: var(--accent-soft);
border: 1px solid rgba(43, 84, 201, .22);
box-shadow: var(--shadow-sm);
transition: background .14s ease, border-color .14s ease, color .14s ease, box-shadow .14s ease, transform .14s ease;
}
.dl-link:hover {
background: var(--accent); color: #fff;
border-color: var(--accent);
box-shadow: 0 1px 2px rgba(28, 55, 130, .28), 0 2px 6px rgba(28, 55, 130, .18);
}
.dl-link:active { transform: translateY(.5px); }
.dl-link svg { display: block; flex: 0 0 auto; }
/* Export split button group */
.export-group {
display: inline-flex; align-items: stretch;
border-radius: 8px; overflow: hidden;
background: #fff;
box-shadow: 0 0 0 1px var(--border-strong), var(--shadow-sm);
}
.export-group > button { border-radius: 0; border: 0; box-shadow: none; }
.export-group > button + button { border-left: 1px solid var(--border); }
.export-group > button:hover { background: var(--surface-alt); }
/* Filter bar in output pane */
#filterBar {
display: none;
align-items: center; gap: 6px;
padding: 8px 12px; border-bottom: 1px solid var(--border);
background: var(--surface-alt); font-size: 12px; color: var(--text-muted);
flex-wrap: wrap;
}
#filterBar.visible { display: flex; }
#filterBar .fchip {
display: inline-flex; align-items: center; gap: 4px;
padding: 3px 10px; border-radius: 999px;
background: #fff; border: 1px solid var(--border-strong);
font-family: var(--mono); font-size: 11px; color: var(--text);
cursor: pointer;
transition: background .14s ease, color .14s ease, border-color .14s ease, box-shadow .14s ease;
}
#filterBar .fchip:hover { background: var(--surface-sunken); border-color: #b9c0ce; }
#filterBar .fchip.active {
background: var(--accent); color: #fff; border-color: var(--accent);
box-shadow: 0 1px 3px rgba(28, 55, 130, .3);
}
#filterBar .fclear {
background: transparent; border: 0; color: var(--accent);
cursor: pointer; font-size: 12px; font-weight: 600; padding: 2px 6px;
box-shadow: none;
}
#filterBar .fclear:hover { text-decoration: underline; background: transparent; }
.line.filtered-out { display: none; }
/* Keyboard-shortcuts modal specific */
#shortcutsModal kbd {
display: inline-block;
font-family: var(--mono); font-size: 11px; font-weight: 600;
padding: 2px 7px; border-radius: 6px;
background: linear-gradient(180deg, #fff 0%, var(--surface-sunken) 100%);
border: 1px solid var(--border-strong);
box-shadow: 0 1px 0 rgba(16, 24, 40, .06);
color: var(--text);
min-width: 22px; text-align: center;
}
#shortcutsModal table { width: 100%; border-collapse: collapse; font-size: 13px; }
#shortcutsModal td { padding: 9px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
#shortcutsModal tr:last-child td { border-bottom: 0; }
#shortcutsModal td:first-child { width: 34%; white-space: nowrap; }
#shortcutsModal td:last-child { color: var(--text-muted); }
/* Reference modal readability */
#referenceContent ul { color: var(--text); }
#referenceContent li { margin-bottom: 6px; }
/* Small viewport: stack the topbar, hide button text where possible */
@media (max-width: 900px) {
header.topbar {
flex-wrap: wrap;
padding: 10px 12px;
gap: 6px;
}
header .brand { font-size: 14px; }
.summary { order: 10; width: 100%; padding: 4px 6px; gap: 5px; font-size: 11px; flex-wrap: wrap; border-radius: 12px; }
.summary .pill { padding: 2px 8px; }
main { grid-template-columns: 1fr; gap: 10px; padding: 10px; }
.pane { border-radius: 12px; }
header.topbar button { padding: 5px 9px; font-size: 12px; }
.dl-link { padding: 6px 10px; font-size: 12px; gap: 6px; }
/* v9: perf badge collapses to just the total on small viewports. */
.perf-badge.visible .perf-detail { display: none; }
/* v9: chips get tighter on small viewports so they don't crowd the row. */
.chips { max-width: 40%; }
}
@media (max-width: 600px) {
#btnSample { display: none; }
header .brand { flex: 1 0 100%; }
/* v9: hide the "GO TO LINE" label on tiny viewports; the input's
placeholder "#" is enough context and the pane column is precious. */
.jump-wrap label { display: none; }
.jump-wrap input { width: 48px; }
/* v9: chip max-width drops further on tiny viewports. */
.chips { max-width: 35%; }
/* v12: the download control collapses to its icon; the accessible name
is carried by aria-label/title. */
.dl-link .dl-text { display: none; }
.dl-link { padding: 6px 9px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: .01ms !important;
animation-iteration-count: 1 !important;
transition-duration: .01ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<rect x="2.5" y="2.5" width="19" height="19" rx="4" stroke="currentColor" stroke-width="1.6"/>
<path d="M7 12l3.2 3.2L17 8.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Search Term Validator
<span id="versionBadge" style="font-weight:400;color:var(--text-muted);font-size:12px;margin-left:6px"></span>
</div>
<button id="btnValidate" class="primary">Validate</button>
<button id="btnClear">Clear</button>
<button id="btnSample" class="ghost">Load sample</button>
<div class="spacer"></div>
<div class="summary" id="summary">
<span class="pill total"><span id="s_total">0</span> terms</span>
<span class="pill err"><span id="s_err">0</span> errors</span>
<span class="pill warn"><span id="s_warn">0</span> warnings</span>
<span class="pill fix"><span id="s_fix">0</span> auto-fixes</span>
<span id="s_perf" class="perf-badge" title="Validation time"></span>
<span id="jumpWrap" class="jump-wrap" style="display:none" title="Jump to a specific line number">
<label for="jumpTo" style="font-size:11px;color:var(--text-muted);letter-spacing:.03em">GO TO LINE</label>
<input id="jumpTo" type="number" min="1" step="1" placeholder="#" aria-label="Jump to line number">
</span>
</div>
<button id="btnDedupe" title="Remove exact duplicates and logical subsets">Dedupe</button>
<div class="export-group" role="group" aria-label="Export">
<button id="btnExport" title="Export CSV report">Export CSV</button>
<button id="btnExportReport" class="ghost" title="Export human-readable Markdown report grouped by rule">Report (.md)</button>
</div>
<button id="btnReference" title="Reference: dtSearch/Relativity rules the validator can't fully check" aria-label="Reference">Reference</button>
<button id="btnShortcuts" title="Keyboard shortcuts (press ?)" aria-label="Keyboard shortcuts">?</button>
<button id="btnSettings" title="Settings" aria-label="Settings">⚙︎</button>
<!-- v12: offline copy. Plain anchor — no script is bound to it, so it
cannot affect validation. Relative href: keep STRvalidator.zip in
the same directory as this page when you publish it. -->
<a id="btnDownload" class="dl-link" href="STRvalidator.zip" download
aria-label="Download to run privately offline"
title="Download a self-contained copy to run offline — nothing you paste ever leaves your machine">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M12 3.5v11m0 0l-4-4m4 4l4-4" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4.5 16.5v2a2 2 0 002 2h11a2 2 0 002-2v-2" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>
</svg>
<span class="dl-text">Download to run privately offline</span>
</a>
</header>
<main>
<section class="pane">
<div class="pane-header">
<span>Input</span>
<span style="font-weight:400;text-transform:none;letter-spacing:0;color:var(--text-muted)">— one term per line</span>
<div class="spacer" style="flex:1"></div>
<span id="inputMode" style="font-weight:400;text-transform:none;letter-spacing:0;color:var(--text-muted)">edit mode</span>
</div>
<div class="pane-body" id="inputBody">
<textarea id="inputArea" spellcheck="false" placeholder="Paste search terms here, one per line…"></textarea>
<div id="inputHighlight" class="lines" style="display:none"></div>
</div>
</section>
<section class="pane">
<div class="pane-header">
<span>Corrected output</span>
<div class="spacer" style="flex:1"></div>
<button id="btnCopyAll" class="ghost">Copy all</button>
</div>
<div id="filterBar" role="toolbar" aria-label="Filter by rule">
<span style="font-weight:600;text-transform:uppercase;letter-spacing:.04em;font-size:11px">Filter</span>
<div id="filterChips" style="display:inline-flex;gap:4px;flex-wrap:wrap"></div>
<button class="fclear" id="btnClearFilter">Clear</button>
</div>
<div class="pane-body" id="outputBody">
<div id="outputArea" class="lines"></div>
</div>
</section>
</main>
</div>
<div id="tooltip" role="tooltip"></div>
<div id="toast" class="toast" role="status" aria-live="polite"></div>
<!-- v9: polite live region so screen readers announce validation completion. -->
<div id="srAnnounce" class="sr-only" role="status" aria-live="polite" aria-atomic="true"></div>
<!-- Shortcuts modal -->
<div class="modal-backdrop" id="shortcutsModal">
<div class="modal" role="dialog" aria-labelledby="shortcutsTitle" style="max-width:520px">
<header><h2 id="shortcutsTitle">Keyboard shortcuts</h2><div class="spacer" style="flex:1"></div><button class="ghost" id="btnCloseShortcuts">✕</button></header>
<div class="content">
<table>
<tr><td><kbd>Ctrl</kbd> / <kbd>⌘</kbd> + <kbd>Enter</kbd></td><td>Validate the current input.</td></tr>
<tr><td><kbd>Esc</kbd></td><td>Close any open modal, or clear the active rule filter.</td></tr>
<tr><td><kbd>?</kbd> or <kbd>Shift</kbd>+<kbd>/</kbd></td><td>Open this shortcuts panel.</td></tr>
<tr><td><kbd>Ctrl</kbd> / <kbd>⌘</kbd> + <kbd>K</kbd></td><td>Focus the input area.</td></tr>
<tr><td><kbd>Ctrl</kbd> / <kbd>⌘</kbd> + <kbd>D</kbd></td><td>Open Dedupe.</td></tr>
<tr><td><kbd>Ctrl</kbd> / <kbd>⌘</kbd> + <kbd>E</kbd></td><td>Export CSV. Add <kbd>Shift</kbd> for the Markdown report.</td></tr>
<tr><td>Click a rule chip on a line</td><td>Filter output to that rule only. Click again or press <kbd>Esc</kbd> to clear.</td></tr>
<tr><td>Click a summary pill</td><td>Filter output by severity (errors, warnings, auto-fixes).</td></tr>
</table>
<p style="margin:12px 0 0;color:var(--text-muted);font-size:12px">Shortcuts are disabled while an input or textarea is focused, except for <kbd>Ctrl</kbd>+<kbd>Enter</kbd>.</p>
</div>
<footer>
<div class="spacer" style="flex:1"></div>
<button id="btnCloseShortcuts2" class="primary">Close</button>
</footer>
</div>
</div>
<!-- Reference modal -->
<div class="modal-backdrop" id="referenceModal">
<div class="modal" role="dialog" aria-labelledby="referenceTitle" style="max-width:720px">
<header><h2 id="referenceTitle">Reference — advisory rules</h2><div class="spacer" style="flex:1"></div><button class="ghost" id="btnCloseReference">✕</button></header>
<div class="content" id="referenceContent">
<p style="margin-top:0;color:var(--text-muted);font-size:13px">These rules from the Relativity/dtSearch documentation can't be fully verified from term text alone. Use them as a checklist while drafting. Every item below cites the source page in the official Relativity documentation.</p>
<div style="margin:10px 0 14px;padding:10px 12px;border:1px solid var(--border);border-radius:6px;background:var(--surface-alt,#f8f9fb);font-size:12px;line-height:1.5">
<div style="font-weight:600;margin-bottom:4px">Primary sources</div>
<ul style="margin:4px 0 0;padding-left:16px">
<li><a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Using_dtSearch_syntax_options.htm" target="_blank" rel="noopener">Using dtSearch syntax options</a> — connectors, proximity, wildcards, stemming, fuzzy, phonic</li>
<li><a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Making_the_stop_word_and_alphabet_list_searchable.htm" target="_blank" rel="noopener">dtSearch noise words and alphabet</a> — noise list, letters, reserved symbols</li>
<li><a href="https://help.relativity.com/RelativityOne/Content/Relativity/Regular_expressions/Using_regular_expressions_with_dtSearch.htm" target="_blank" rel="noopener">Regular expression caveats with dtSearch</a> — <code>##"..."</code> syntax, case sensitivity in regex</li>
<li><a href="https://help.relativity.com/RelativityOne/Content/Relativity/Regular_expressions/Searching_with_regular_expressions.htm" target="_blank" rel="noopener">Searching with regular expressions</a> — regex examples and patterns</li>
<li><a href="https://help.relativity.com/RelativityOne/Content/Relativity/Search_term_reports/STR.htm" target="_blank" rel="noopener">Search terms reports (STR) overview</a> — STR-specific constraints (Fuzziness, Dictionary)</li>
<li><a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Running_a_Dictionary_search.htm" target="_blank" rel="noopener">Running a Dictionary search</a> — token validation workflow</li>
<li><a href="https://help.relativity.com/RelativityOne/Content/System_Guides/User_quick_reference/Searching_Quick_Reference/Search.htm" target="_blank" rel="noopener">Searching quick reference</a> — operator summary table</li>
<li><a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Searching_for_symbols.htm" target="_blank" rel="noopener">Searching for symbols and emojis</a> — making reserved characters searchable</li>
</ul>
</div>
<h3 style="margin:14px 0 6px;font-size:13px;letter-spacing:.05em;text-transform:uppercase;color:var(--text-muted)">Query design</h3>
<ul style="margin:0;padding-left:18px;line-height:1.55">
<li>Use several specific STRs instead of one broad query with many OR’d concepts. Broad queries are hard to review, hard to validate against a Dictionary, and often over-inclusive. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/Search_term_reports/STR.htm" target="_blank" rel="noopener">[STR overview]</a></li>
<li>Minimize the number of saved-search field conditions layered on top of the STR. Every condition adds a place where the STR’s intent can be quietly narrowed. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/Search_term_reports/Create.htm" target="_blank" rel="noopener">[Create STR]</a></li>
<li>Consider smaller, targeted indexes (by custodian, date range, or file type) rather than one large index. Smaller indexes validate faster and behave more predictably. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/dtSearch.htm" target="_blank" rel="noopener">[dtSearch overview]</a></li>
<li>Missing highlights in a hit document do not mean the search failed. Highlighting is a display artifact and can lag or be omitted for complex proximity results. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Running_a_dtSearch.htm" target="_blank" rel="noopener">[Running a dtSearch]</a></li>
<li>Ignore isolated highlights inside proximity-hit documents — the proximity operator groups matches internally, but the highlighter shows every individual token. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Using_dtSearch_syntax_options.htm" target="_blank" rel="noopener">[Syntax options]</a></li>
</ul>
<h3 style="margin:14px 0 6px;font-size:13px;letter-spacing:.05em;text-transform:uppercase;color:var(--text-muted)">Validation workflow</h3>
<ul style="margin:0;padding-left:18px;line-height:1.55">
<li>Use the Dictionary to validate a term against actual indexed tokens. Dictionary is capped at ~2,000 unique expansions per query — broad wildcards and stemming can silently exceed this. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Running_a_Dictionary_search.htm" target="_blank" rel="noopener">[Dictionary search]</a></li>
<li>Prefer Dictionary validation over broad wildcards. If a wildcard expands to more than the Dictionary can show, you don’t truly know what it will match. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Running_a_Dictionary_search.htm" target="_blank" rel="noopener">[Dictionary search]</a></li>
<li>Validate wildcard, stemming, fuzzy, and phonic expansions in the Dictionary before running the STR against production data. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Using_dtSearch_syntax_options.htm" target="_blank" rel="noopener">[Syntax options]</a></li>
<li>Enable auto-recognition for <code>date()</code>, <code>mail()</code>, and <code>creditcard()</code> pattern types before you rely on them, but only when necessary — auto-recognition slows indexing and increases index size. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Using_dtSearch_syntax_options.htm" target="_blank" rel="noopener">[Syntax options]</a></li>
<li>Record: which index/searchable set was used, the alphabet file version, the noise word list, the STR terms as run, and the run timestamp — for defensibility. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/Search_term_reports/Create.htm" target="_blank" rel="noopener">[Create STR]</a></li>
</ul>
<h3 style="margin:14px 0 6px;font-size:13px;letter-spacing:.05em;text-transform:uppercase;color:var(--text-muted)">Index-dependent behavior</h3>
<ul style="margin:0;padding-left:18px;line-height:1.55">
<li>The Fuzziness Level control is not supported in STR searches. Use <code>word%</code> notation instead if you need approximate matching. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Using_dtSearch_syntax_options.htm" target="_blank" rel="noopener">[Syntax options: fuzzy]</a></li>
<li>Accent sensitivity depends on how the index was built. This validator cannot verify accent handling from term text alone. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Making_the_stop_word_and_alphabet_list_searchable.htm" target="_blank" rel="noopener">[Alphabet file]</a></li>
<li>Underscore does <strong>not</strong> create a word break by default. <code>foo_bar</code> is indexed as one token, not two. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Making_the_stop_word_and_alphabet_list_searchable.htm" target="_blank" rel="noopener">[Alphabet file]</a></li>
<li>Reserved symbols — <code>? * % ~ # = : & ( )</code> — are stripped by default. To search them as literals, add them to the alphabet file and fully rebuild the index. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/dtSearch/Searching_for_symbols.htm" target="_blank" rel="noopener">[Searching for symbols]</a></li>
<li>Searches are case-insensitive. dtSearch normalizes indexed text to lowercase; uppercase in the query has no effect except inside <code>##"..."</code> regex, where uppercase will fail to match. <a href="https://help.relativity.com/RelativityOne/Content/Relativity/Regular_expressions/Using_regular_expressions_with_dtSearch.htm" target="_blank" rel="noopener">[Regex caveats]</a></li>
</ul>
<p style="margin:14px 0 0;color:var(--text-muted);font-size:12px">Documentation URLs point to the current RelativityOne pages. If you’re on Server, replace <code>/RelativityOne/</code> with <code>/Server2026/</code> (or your version) in the URL.</p>
</div>
<footer>
<div class="spacer" style="flex:1"></div>
<button id="btnCloseReference2" class="primary">Close</button>
</footer>
</div>
</div>
<!-- Settings modal -->
<div class="modal-backdrop" id="settingsModal">
<div class="modal" role="dialog" aria-labelledby="settingsTitle">
<header><h2 id="settingsTitle">Settings</h2><div class="spacer" style="flex:1"></div><button class="ghost" id="btnCloseSettings">✕</button></header>
<div class="content">
<div class="field">
<label for="sSameSentence">Westlaw /s (same sentence) → w/N</label>
<input type="number" id="sSameSentence" min="1" max="200" value="15">
<div class="hint">Approximation. dtSearch has no "sentence" operator; a word-window is used instead.</div>
</div>
<div class="field">
<label for="sSameParagraph">Westlaw /p (same paragraph) → w/N</label>
<input type="number" id="sSameParagraph" min="1" max="500" value="50">
<div class="hint">Approximation. dtSearch has no "paragraph" operator.</div>
</div>
<div class="field">
<label class="toggle">
<input type="checkbox" id="sFlagSPPromotion" checked>
Flag /s and /p conversions for review (recommended)
</label>
</div>
<div class="field">
<label class="toggle">
<input type="checkbox" id="sDedupeOn">
Auto-dedupe (exact duplicates + logical subsets)
</label>
<div class="hint">Off by default. When on, dedupe runs automatically at validation time.</div>
</div>
<div class="field">
<label for="sNoise">dtSearch noise words (comma or whitespace separated)</label>
<textarea id="sNoise"></textarea>
<div class="hint">Default is the dtSearch standard English noise word list. Noise words inside quoted phrases produce warnings because they are not indexed.</div>
</div>
<div class="field">
<label class="toggle">
<input type="checkbox" id="sStrictReserved" checked>
Wrap reserved operator words used as literal terms in quotes
</label>
</div>
</div>
<footer>
<button id="btnResetSettings">Reset defaults</button>
<button id="btnSaveSettings" class="primary">Save</button>
</footer>
</div>
</div>
<script>
/* =====================================================================
VALIDATION ENGINE (Phase 2 will lift this module verbatim into the
Relativity custom application. Keep it UI-free.)
===================================================================== */
const Validator = (function () {
'use strict';
// Standard dtSearch English noise words (built-in default list).
// Source: dtSearch Corp — noise.dat default English list.
const DEFAULT_NOISE = [
"a","about","after","all","also","an","and","another","any","are","as","at",
"be","because","been","before","being","between","both","but","by",
"came","can","come","could",
"did","do","does",
"each","else",
"for","from",
"get","got",
"had","has","have","he","her","here","him","himself","his","how",
"i","if","in","into","is","it","its",
"just",
"like",
"make","many","me","might","more","most","much","must","my",
"never","no","now",
"of","on","only","or","other","our","out","over",
"re",
"said","same","see","should","since","she","so","some","still","such",
"take","than","that","the","their","them","then","there","these","they","this","those","through","to","too",
"under","up","use",
"very",
"want","was","way","we","well","were","what","when","where","which","while","who","will","with","would",
"you","your"
];
// Reserved dtSearch operator words — when a bare (unquoted) token equals one
// of these, it is not searched literally.
const RESERVED_OPS = new Set([
"and","or","not","w","pre","to","contains","xfirstword","xlastword"
]);
// Westlaw field-restriction commands attorneys sometimes carry over.
// Westlaw-only field commands that dtSearch/Relativity STR does not support.
// NOTE: 'date' is intentionally NOT in this list — dtSearch supports date()
// when the index has auto-recognition enabled. See checkDateFunction for
// the finer-grained date() checks.
const WESTLAW_FIELDS = ["atleast", "da", "ad", "co", "ti", "sy", "di", "pr", "he"];
const MAX_TERM_LENGTH = 450; // RelativityOne STR effective limit
const DEFAULT_SETTINGS = {
sameSentence: 15,
sameParagraph: 50,
flagSPPromotion: true,
dedupeOn: false,
noiseWords: DEFAULT_NOISE.slice(),
strictReserved: true,
};
/* ---------- helpers ---------- */
function normalizeArtifacts(s) {
// Smart quotes / curly apostrophes / dashes / non-breaking spaces
return s
.replace(/[\u201C\u201D\u201E\u201F\u2033\u2036]/g, '"') // curly double quotes
.replace(/[\u2018\u2019\u201A\u201B\u2032\u2035]/g, "'") // curly single quotes
.replace(/[\u2013\u2014\u2015]/g, '-') // en/em/horiz dashes
.replace(/\u2026/g, '...') // ellipsis
.replace(/\u00A0/g, ' ') // NBSP
.replace(/\t/g, ' '); // tabs -> space
}
function stripQuotedRegions(s) {
// Replace anything inside double quotes with same-length filler so we can
// scan operators outside quoted phrases only.
let out = '', inQ = false;
for (let i = 0; i < s.length; i++) {
const c = s[i];
if (c === '"') { inQ = !inQ; out += c; }
else out += inQ ? '\0' : c;
}
return out;
}
function findQuotedPhrases(s) {
const phrases = [];
const re = /"([^"]*)"/g;
let m;
while ((m = re.exec(s)) !== null) {
phrases.push({ text: m[1], start: m.index + 1, end: m.index + 1 + m[1].length });
}
return phrases;
}
/* ---------- individual rules ---------- */
function checkSilentClean(original) {
// Trim + collapse internal whitespace + normalize artifacts. Runs of two
// or more whitespace characters are now surfaced as a NO_DOUBLE_SPACES
// fix rather than silently collapsed, per Relativity documentation.
const trimmed = original.replace(/^\s+|\s+$/g, '');
// Detect BEFORE the collapse whether the interior had double whitespace.
const hadDoubleSpace = /\S\s{2,}\S/.test(trimmed);
const normalized = normalizeArtifacts(trimmed).replace(/\s+/g, ' ');
const issues = [];
if (normalized !== original) {
const artifactChanged = normalizeArtifacts(original.replace(/^\s+|\s+$/g, '').replace(/\s+/g,' ')) !== original.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' ');
if (artifactChanged) {
issues.push({
severity: 'fix',
code: 'ARTIFACT_NORMALIZED',
message: 'Word-copy artifacts normalized to ASCII (smart quotes, curly apostrophes, em-dashes, non-breaking spaces).',
rule: 'dtSearch requires straight ASCII quotes; smart quotes are treated as different characters and may not match anything.',
});
}
}
if (hadDoubleSpace) {
issues.push({
severity: 'fix',
code: 'NO_DOUBLE_SPACES',
message: 'Runs of two or more whitespace characters were collapsed to a single space.',
rule: 'Relativity: do not allow two or more spaces anywhere in the search string. Consecutive whitespace can be misinterpreted by the parser and hides intent.',
});
}
return { text: normalized, issues };
}
function checkAmpersand(text) {
// & outside quoted phrases -> AND
const issues = [];
const stripped = stripQuotedRegions(text);
if (/&/.test(stripped)) {
// Rebuild text substituting & with AND outside quotes
let out = '', inQ = false;
for (let i = 0; i < text.length; i++) {
const c = text[i];
if (c === '"') { inQ = !inQ; out += c; continue; }
if (!inQ && c === '&') {
// Ensure surrounding whitespace
const prev = out.slice(-1);
if (prev && prev !== ' ') out += ' ';
out += 'AND';
if (text[i+1] && text[i+1] !== ' ') out += ' ';
} else out += c;
}
issues.push({
severity: 'fix',
code: 'AMP_TO_AND',
message: 'Converted "&" to "AND".',
rule: 'dtSearch/Relativity require the literal word AND for boolean conjunction. "&" is not a supported operator.',
});
return { text: out.replace(/ {2,}/g,' '), issues };
}
return { text, issues };
}
function checkWestlawBang(text) {
// ! root expander (word ending with !) -> * outside quotes
const issues = [];
let changed = false;
const stripped = stripQuotedRegions(text);
// Find tokens ending in !
const re = /([A-Za-z][A-Za-z0-9_-]*)!/g;
let m;
const matches = [];
while ((m = re.exec(stripped)) !== null) matches.push({ start: m.index, end: m.index + m[0].length, token: m[1] });
if (matches.length) {
// rebuild
let out = '', cur = 0;
matches.forEach(mt => {
out += text.slice(cur, mt.end - 1); // up to before the !
out += '*';
cur = mt.end;
});
out += text.slice(cur);
issues.push({
severity: 'fix',
code: 'WL_BANG_TO_STAR',
message: 'Converted Westlaw root expander "!" to dtSearch wildcard "*".',
rule: 'Westlaw uses "term!" for stemming; dtSearch uses "term*". They are close but not identical — dtSearch matches any trailing characters including none if minimum stem length is met.',
});
return { text: out, issues };
}
return { text, issues };
}
function checkProximity(text, settings) {
// Handle:
// token /N token (unordered) -> token w/N token
// token +N token (ordered) -> token pre/N token
// token /s token -> token w/{sameSentence} token (flagged)
// token /p token -> token w/{sameParagraph} token (flagged)
// Only outside quotes. And be careful NOT to mangle already-correct
// "w/N" or "pre/N".
const issues = [];
let out = '';
let i = 0;
let inQ = false;
let modified = false;
while (i < text.length) {
const c = text[i];
if (c === '"') { inQ = !inQ; out += c; i++; continue; }
if (inQ) { out += c; i++; continue; }
// Skip already-correct dtSearch operators like " w/5 ", " pre/5 "
// Detect them and pass through unchanged.
const passthroughRe = /^(w\/\d+|pre\/\d+|not\s+w\/\d+)/i;
const rest = text.slice(i);
const pass = rest.match(passthroughRe);
if (pass && (i === 0 || /\s/.test(text[i-1]))) {
// must be at token boundary
out += pass[0]; i += pass[0].length; continue;
}