@unofficialbox/box-open-elements 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -73
- package/dist/components/collections/table.d.ts +113 -3
- package/dist/components/collections/table.js +540 -37
- package/dist/components/feedback/due-badge.d.ts +38 -0
- package/dist/components/feedback/due-badge.js +168 -0
- package/dist/components/feedback/due-types.d.ts +32 -0
- package/dist/components/feedback/due-types.js +91 -0
- package/dist/components/feedback/progress-steps.d.ts +51 -5
- package/dist/components/feedback/progress-steps.js +200 -22
- package/dist/components/feedback/stage-path.d.ts +44 -0
- package/dist/components/feedback/stage-path.js +235 -0
- package/dist/components/forms/select.d.ts +21 -0
- package/dist/components/forms/select.js +100 -3
- package/dist/components/forms/text-field.d.ts +21 -0
- package/dist/components/forms/text-field.js +100 -1
- package/dist/components/layout/nav-sidebar.d.ts +14 -0
- package/dist/components/layout/nav-sidebar.js +49 -0
- package/dist/components/layout/split-view.d.ts +14 -0
- package/dist/components/layout/split-view.js +80 -1
- package/dist/components/overlays/command-palette.d.ts +62 -0
- package/dist/components/overlays/command-palette.js +537 -0
- package/dist/components/overlays/command-types.d.ts +90 -0
- package/dist/components/overlays/command-types.js +259 -0
- package/dist/components/overlays/drawer.d.ts +18 -0
- package/dist/components/overlays/drawer.js +135 -9
- package/dist/components/overlays/shortcuts-overlay.d.ts +48 -0
- package/dist/components/overlays/shortcuts-overlay.js +385 -0
- package/dist/components/overlays/tooltip.js +1 -1
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +2 -0
- package/dist/core/offset-window.d.ts +70 -0
- package/dist/core/offset-window.js +134 -0
- package/dist/core/virtualize.d.ts +71 -0
- package/dist/core/virtualize.js +67 -0
- package/dist/element-maps.d.ts +292 -0
- package/dist/element-maps.js +1 -0
- package/dist/entries/activity-density.d.ts +1 -0
- package/dist/entries/activity-density.js +1 -0
- package/dist/entries/agent-chat.d.ts +1 -0
- package/dist/entries/agent-chat.js +1 -0
- package/dist/entries/audit-log.d.ts +1 -0
- package/dist/entries/audit-log.js +1 -0
- package/dist/entries/command-palette.d.ts +1 -0
- package/dist/entries/command-palette.js +1 -0
- package/dist/entries/compare-view.d.ts +1 -0
- package/dist/entries/compare-view.js +1 -0
- package/dist/entries/diff-viewer.d.ts +1 -0
- package/dist/entries/diff-viewer.js +1 -0
- package/dist/entries/due-badge.d.ts +1 -0
- package/dist/entries/due-badge.js +1 -0
- package/dist/entries/form-wizard.d.ts +1 -0
- package/dist/entries/form-wizard.js +1 -0
- package/dist/entries/lineage-graph.d.ts +1 -0
- package/dist/entries/lineage-graph.js +1 -0
- package/dist/entries/notification-bell.d.ts +1 -0
- package/dist/entries/notification-bell.js +1 -0
- package/dist/entries/notification-inbox.d.ts +1 -0
- package/dist/entries/notification-inbox.js +1 -0
- package/dist/entries/provenance-strip.d.ts +1 -0
- package/dist/entries/provenance-strip.js +1 -0
- package/dist/entries/run-trace.d.ts +1 -0
- package/dist/entries/run-trace.js +1 -0
- package/dist/entries/shortcuts-overlay.d.ts +1 -0
- package/dist/entries/shortcuts-overlay.js +1 -0
- package/dist/entries/signature-ceremony.d.ts +1 -0
- package/dist/entries/signature-ceremony.js +1 -0
- package/dist/entries/stage-path.d.ts +1 -0
- package/dist/entries/stage-path.js +1 -0
- package/dist/entries/timeline.d.ts +1 -0
- package/dist/entries/timeline.js +1 -0
- package/dist/entries/version-graph.d.ts +1 -0
- package/dist/entries/version-graph.js +1 -0
- package/dist/entries/version-list.d.ts +1 -0
- package/dist/entries/version-list.js +1 -0
- package/dist/entries/wizard-summary.d.ts +1 -0
- package/dist/entries/wizard-summary.js +1 -0
- package/dist/entries/work-queue.d.ts +1 -0
- package/dist/entries/work-queue.js +1 -0
- package/dist/entries/workload-board.d.ts +1 -0
- package/dist/entries/workload-board.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/patterns/agent-chat/agent-chat.d.ts +75 -0
- package/dist/patterns/agent-chat/agent-chat.js +820 -0
- package/dist/patterns/agent-chat/controller.d.ts +27 -0
- package/dist/patterns/agent-chat/controller.js +182 -0
- package/dist/patterns/agent-chat/index.d.ts +3 -0
- package/dist/patterns/agent-chat/index.js +6 -0
- package/dist/patterns/agent-chat/types.d.ts +109 -0
- package/dist/patterns/agent-chat/types.js +1 -0
- package/dist/patterns/audit/activity-density.d.ts +68 -0
- package/dist/patterns/audit/activity-density.js +428 -0
- package/dist/patterns/audit/audit-log.d.ts +182 -0
- package/dist/patterns/audit/audit-log.js +1082 -0
- package/dist/patterns/audit/index.d.ts +3 -0
- package/dist/patterns/audit/index.js +7 -0
- package/dist/patterns/audit/shared.d.ts +10 -0
- package/dist/patterns/audit/shared.js +50 -0
- package/dist/patterns/audit/types.d.ts +143 -0
- package/dist/patterns/audit/types.js +327 -0
- package/dist/patterns/audit/window.d.ts +116 -0
- package/dist/patterns/audit/window.js +132 -0
- package/dist/patterns/content-explorer/actions/controller.js +12 -2
- package/dist/patterns/content-explorer/box-transport.js +117 -25
- package/dist/patterns/content-explorer/content-explorer.d.ts +13 -1
- package/dist/patterns/content-explorer/content-explorer.js +36 -3
- package/dist/patterns/content-explorer/contracts.d.ts +24 -1
- package/dist/patterns/content-explorer/contracts.js +68 -11
- package/dist/patterns/content-explorer/controller.d.ts +16 -1
- package/dist/patterns/content-explorer/controller.js +130 -4
- package/dist/patterns/content-explorer/navigation/controller.js +11 -9
- package/dist/patterns/content-explorer/types.d.ts +58 -1
- package/dist/patterns/content-picker/content-picker.d.ts +71 -0
- package/dist/patterns/content-picker/content-picker.js +747 -0
- package/dist/patterns/content-picker/controller.d.ts +38 -0
- package/dist/patterns/content-picker/controller.js +141 -0
- package/dist/patterns/content-picker/index.d.ts +3 -0
- package/dist/patterns/content-picker/index.js +6 -0
- package/dist/patterns/content-picker/types.d.ts +52 -0
- package/dist/patterns/content-picker/types.js +26 -0
- package/dist/patterns/content-sidebar/content-sidebar.d.ts +43 -0
- package/dist/patterns/content-sidebar/content-sidebar.js +293 -0
- package/dist/patterns/content-sidebar/index.d.ts +2 -0
- package/dist/patterns/content-sidebar/index.js +4 -0
- package/dist/patterns/content-sidebar/types.d.ts +18 -0
- package/dist/patterns/content-sidebar/types.js +20 -0
- package/dist/patterns/content-uploader/box-transport.d.ts +14 -0
- package/dist/patterns/content-uploader/box-transport.js +54 -0
- package/dist/patterns/content-uploader/content-uploader.d.ts +62 -0
- package/dist/patterns/content-uploader/content-uploader.js +559 -0
- package/dist/patterns/content-uploader/controller.d.ts +39 -0
- package/dist/patterns/content-uploader/controller.js +227 -0
- package/dist/patterns/content-uploader/index.d.ts +4 -0
- package/dist/patterns/content-uploader/index.js +8 -0
- package/dist/patterns/content-uploader/types.d.ts +120 -0
- package/dist/patterns/content-uploader/types.js +38 -0
- package/dist/patterns/diff/compare-view.d.ts +47 -0
- package/dist/patterns/diff/compare-view.js +276 -0
- package/dist/patterns/diff/diff-viewer.d.ts +42 -0
- package/dist/patterns/diff/diff-viewer.js +434 -0
- package/dist/patterns/diff/engine.d.ts +22 -0
- package/dist/patterns/diff/engine.js +276 -0
- package/dist/patterns/diff/index.d.ts +4 -0
- package/dist/patterns/diff/index.js +8 -0
- package/dist/patterns/diff/types.d.ts +69 -0
- package/dist/patterns/diff/types.js +24 -0
- package/dist/patterns/form-wizard/controller.d.ts +39 -0
- package/dist/patterns/form-wizard/controller.js +157 -0
- package/dist/patterns/form-wizard/form-wizard.d.ts +63 -0
- package/dist/patterns/form-wizard/form-wizard.js +468 -0
- package/dist/patterns/form-wizard/index.d.ts +4 -0
- package/dist/patterns/form-wizard/index.js +8 -0
- package/dist/patterns/form-wizard/types.d.ts +109 -0
- package/dist/patterns/form-wizard/types.js +83 -0
- package/dist/patterns/form-wizard/wizard-summary.d.ts +62 -0
- package/dist/patterns/form-wizard/wizard-summary.js +324 -0
- package/dist/patterns/internal/safe-href.d.ts +17 -0
- package/dist/patterns/internal/safe-href.js +17 -0
- package/dist/patterns/lineage/index.d.ts +3 -0
- package/dist/patterns/lineage/index.js +6 -0
- package/dist/patterns/lineage/lineage-graph.d.ts +30 -0
- package/dist/patterns/lineage/lineage-graph.js +434 -0
- package/dist/patterns/lineage/provenance-strip.d.ts +22 -0
- package/dist/patterns/lineage/provenance-strip.js +194 -0
- package/dist/patterns/lineage/types.d.ts +53 -0
- package/dist/patterns/lineage/types.js +49 -0
- package/dist/patterns/notifications/index.d.ts +3 -0
- package/dist/patterns/notifications/index.js +6 -0
- package/dist/patterns/notifications/notification-bell.d.ts +38 -0
- package/dist/patterns/notifications/notification-bell.js +198 -0
- package/dist/patterns/notifications/notification-inbox.d.ts +46 -0
- package/dist/patterns/notifications/notification-inbox.js +537 -0
- package/dist/patterns/notifications/types.d.ts +61 -0
- package/dist/patterns/notifications/types.js +108 -0
- package/dist/patterns/preview/annotation-inspector.d.ts +25 -6
- package/dist/patterns/preview/annotation-inspector.js +239 -94
- package/dist/patterns/preview/annotation-thread.d.ts +25 -5
- package/dist/patterns/preview/annotation-thread.js +233 -82
- package/dist/patterns/preview/annotation-toolbar.d.ts +20 -6
- package/dist/patterns/preview/annotation-toolbar.js +162 -96
- package/dist/patterns/preview/content-preview-adapter.d.ts +10 -1
- package/dist/patterns/preview/content-preview-adapter.js +26 -1
- package/dist/patterns/preview/preview-element.d.ts +15 -2
- package/dist/patterns/preview/preview-element.js +223 -52
- package/dist/patterns/preview/provider-adapter.d.ts +47 -0
- package/dist/patterns/preview/provider-adapter.js +17 -0
- package/dist/patterns/run/index.d.ts +2 -0
- package/dist/patterns/run/index.js +4 -0
- package/dist/patterns/run/run-trace.d.ts +40 -0
- package/dist/patterns/run/run-trace.js +441 -0
- package/dist/patterns/run/types.d.ts +66 -0
- package/dist/patterns/run/types.js +152 -0
- package/dist/patterns/signature/index.d.ts +2 -0
- package/dist/patterns/signature/index.js +4 -0
- package/dist/patterns/signature/signature-ceremony.d.ts +33 -0
- package/dist/patterns/signature/signature-ceremony.js +317 -0
- package/dist/patterns/signature/types.d.ts +68 -0
- package/dist/patterns/signature/types.js +89 -0
- package/dist/patterns/timeline/index.d.ts +2 -0
- package/dist/patterns/timeline/index.js +4 -0
- package/dist/patterns/timeline/timeline.d.ts +27 -0
- package/dist/patterns/timeline/timeline.js +430 -0
- package/dist/patterns/timeline/types.d.ts +36 -0
- package/dist/patterns/timeline/types.js +27 -0
- package/dist/patterns/versions/graph-layout.d.ts +43 -0
- package/dist/patterns/versions/graph-layout.js +159 -0
- package/dist/patterns/versions/index.d.ts +4 -0
- package/dist/patterns/versions/index.js +8 -0
- package/dist/patterns/versions/shared.d.ts +4 -0
- package/dist/patterns/versions/shared.js +13 -0
- package/dist/patterns/versions/types.d.ts +37 -0
- package/dist/patterns/versions/types.js +39 -0
- package/dist/patterns/versions/version-graph.d.ts +36 -0
- package/dist/patterns/versions/version-graph.js +438 -0
- package/dist/patterns/versions/version-list.d.ts +39 -0
- package/dist/patterns/versions/version-list.js +407 -0
- package/dist/patterns/work-queue/controller.d.ts +26 -0
- package/dist/patterns/work-queue/controller.js +150 -0
- package/dist/patterns/work-queue/index.d.ts +4 -0
- package/dist/patterns/work-queue/index.js +7 -0
- package/dist/patterns/work-queue/types.d.ts +128 -0
- package/dist/patterns/work-queue/types.js +45 -0
- package/dist/patterns/work-queue/work-queue.d.ts +48 -0
- package/dist/patterns/work-queue/work-queue.js +534 -0
- package/dist/patterns/work-queue/workload-board.d.ts +53 -0
- package/dist/patterns/work-queue/workload-board.js +608 -0
- package/package.json +89 -5
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { computeTextDiff, formatDiffStats } from "./engine.js";
|
|
2
|
+
import { BaseElement } from "../../core/index.js";
|
|
3
|
+
import { boeMotionDuration, boeMotionEasing } from "../../foundations/motion/index.js";
|
|
4
|
+
import { boePanel, boeRadius } from "../../foundations/geometry/index.js";
|
|
5
|
+
const DEFAULT_TAG_NAME = "box-diff-viewer";
|
|
6
|
+
const escapeHtml = (value) => value
|
|
7
|
+
.replaceAll("&", "&")
|
|
8
|
+
.replaceAll("<", "<")
|
|
9
|
+
.replaceAll(">", ">")
|
|
10
|
+
.replaceAll('"', """)
|
|
11
|
+
.replaceAll("'", "'");
|
|
12
|
+
const elementStyles = `
|
|
13
|
+
[hidden] {
|
|
14
|
+
display: none !important;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
:host {
|
|
18
|
+
display: block;
|
|
19
|
+
color: inherit;
|
|
20
|
+
font: inherit;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
[part="panel"] {
|
|
24
|
+
display: grid;
|
|
25
|
+
gap: ${boePanel.gap};
|
|
26
|
+
padding: ${boePanel.padding};
|
|
27
|
+
border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 82%, transparent);
|
|
28
|
+
border-radius: ${boePanel.radius};
|
|
29
|
+
background: ${boePanel.background};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
[part="header"] {
|
|
33
|
+
display: flex;
|
|
34
|
+
flex-wrap: wrap;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: ${boePanel.gap};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
[part="title"] {
|
|
40
|
+
margin: 0;
|
|
41
|
+
font: inherit;
|
|
42
|
+
font-size: 1.05rem;
|
|
43
|
+
font-weight: 700;
|
|
44
|
+
color: var(--boe-token-text-text, #1f1e1b);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
[part="stats"] {
|
|
48
|
+
display: inline-flex;
|
|
49
|
+
padding: 0.2rem 0.55rem;
|
|
50
|
+
border-radius: 999px;
|
|
51
|
+
background: var(--boe-token-surface-item-surface-selected, #f2f7fd);
|
|
52
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
53
|
+
font-size: 0.78rem;
|
|
54
|
+
font-weight: 700;
|
|
55
|
+
font-variant-numeric: tabular-nums;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
[part="nav"] {
|
|
59
|
+
display: inline-flex;
|
|
60
|
+
align-items: center;
|
|
61
|
+
gap: 0.4rem;
|
|
62
|
+
margin-left: auto;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
[part="nav-position"] {
|
|
66
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
67
|
+
font-size: 0.8rem;
|
|
68
|
+
font-variant-numeric: tabular-nums;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[part="nav-previous"],
|
|
72
|
+
[part="nav-next"] {
|
|
73
|
+
appearance: none;
|
|
74
|
+
font: inherit;
|
|
75
|
+
font-size: 0.8rem;
|
|
76
|
+
font-weight: 600;
|
|
77
|
+
padding: 0.3rem 0.6rem;
|
|
78
|
+
border-radius: ${boeRadius.control};
|
|
79
|
+
border: 1px solid var(--boe-token-stroke-stroke, #e8e8e8);
|
|
80
|
+
background: var(--boe-token-surface-surface, #ffffff);
|
|
81
|
+
color: var(--boe-token-text-text, #222222);
|
|
82
|
+
cursor: pointer;
|
|
83
|
+
transition: background ${boeMotionDuration.interactive} ${boeMotionEasing.standard};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
[part="nav-previous"]:hover:not(:disabled),
|
|
87
|
+
[part="nav-next"]:hover:not(:disabled) {
|
|
88
|
+
background: var(--boe-token-surface-surface-hover, #f4f4f4);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
[part="nav-previous"]:disabled,
|
|
92
|
+
[part="nav-next"]:disabled {
|
|
93
|
+
cursor: not-allowed;
|
|
94
|
+
opacity: 0.5;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
[part="nav-previous"]:focus-visible,
|
|
98
|
+
[part="nav-next"]:focus-visible {
|
|
99
|
+
outline: none;
|
|
100
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--boe-token-surface-surface-brand, #0061d5) 18%, transparent);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
[part="scroller"] {
|
|
104
|
+
overflow-x: auto;
|
|
105
|
+
border: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 62%, transparent);
|
|
106
|
+
border-radius: ${boeRadius.large};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
[part="table"] {
|
|
110
|
+
width: 100%;
|
|
111
|
+
border-collapse: collapse;
|
|
112
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
113
|
+
font-size: 0.82rem;
|
|
114
|
+
line-height: 1.55;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
[part="column-label"] {
|
|
118
|
+
padding: 0.45rem 0.6rem;
|
|
119
|
+
text-align: left;
|
|
120
|
+
font-family: inherit;
|
|
121
|
+
font-size: 0.74rem;
|
|
122
|
+
font-weight: 700;
|
|
123
|
+
letter-spacing: 0.08em;
|
|
124
|
+
text-transform: uppercase;
|
|
125
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
126
|
+
border-bottom: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 62%, transparent);
|
|
127
|
+
background: var(--boe-token-surface-surface-secondary, #fbfbfb);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
[part="line-number"] {
|
|
131
|
+
width: 1%;
|
|
132
|
+
min-width: 2.4rem;
|
|
133
|
+
padding: 0 0.55rem;
|
|
134
|
+
text-align: right;
|
|
135
|
+
vertical-align: top;
|
|
136
|
+
color: color-mix(in srgb, var(--boe-token-text-text-secondary, #6f6f6f) 72%, transparent);
|
|
137
|
+
user-select: none;
|
|
138
|
+
border-right: 1px solid color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 46%, transparent);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
[part="cell"] {
|
|
142
|
+
padding: 0 0.6rem;
|
|
143
|
+
vertical-align: top;
|
|
144
|
+
white-space: pre-wrap;
|
|
145
|
+
word-break: break-word;
|
|
146
|
+
color: var(--boe-token-text-text, #1f1e1b);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
[part="row"][data-kind="removed"] [part="cell"][data-side="before"],
|
|
150
|
+
[part="row"][data-kind="changed"] [part="cell"][data-side="before"] {
|
|
151
|
+
background: color-mix(in srgb, var(--boe-token-surface-status-surface-error, #ed3757) 8%, transparent);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
[part="row"][data-kind="added"] [part="cell"][data-side="after"],
|
|
155
|
+
[part="row"][data-kind="changed"] [part="cell"][data-side="after"] {
|
|
156
|
+
background: color-mix(in srgb, var(--boe-token-surface-status-surface-success, #26a27b) 10%, transparent);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
[part="row"][data-active="true"] [part="cell"] {
|
|
160
|
+
box-shadow: inset 3px 0 0 var(--boe-token-surface-surface-brand, #0061d5);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
del {
|
|
164
|
+
text-decoration: line-through;
|
|
165
|
+
text-decoration-thickness: 1px;
|
|
166
|
+
background: color-mix(in srgb, var(--boe-token-surface-status-surface-error, #ed3757) 22%, transparent);
|
|
167
|
+
color: inherit;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
ins {
|
|
171
|
+
text-decoration: none;
|
|
172
|
+
background: color-mix(in srgb, var(--boe-token-surface-status-surface-success, #26a27b) 26%, transparent);
|
|
173
|
+
color: inherit;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
[part="empty"] {
|
|
177
|
+
padding: ${boePanel.padding};
|
|
178
|
+
border-radius: ${boeRadius.large};
|
|
179
|
+
border: 1px dashed color-mix(in srgb, var(--boe-token-stroke-stroke, #e8e8e8) 70%, transparent);
|
|
180
|
+
color: var(--boe-token-text-text-secondary, #6f6f6f);
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
183
|
+
export class DiffViewer extends BaseElement {
|
|
184
|
+
static tagName = DEFAULT_TAG_NAME;
|
|
185
|
+
static get observedAttributes() {
|
|
186
|
+
return ["after-label", "after-text", "before-label", "before-text", "heading", "mode"];
|
|
187
|
+
}
|
|
188
|
+
titleEl;
|
|
189
|
+
statsEl;
|
|
190
|
+
navEl;
|
|
191
|
+
navPositionEl;
|
|
192
|
+
navPreviousEl;
|
|
193
|
+
navNextEl;
|
|
194
|
+
scrollerEl;
|
|
195
|
+
emptyEl;
|
|
196
|
+
result = null;
|
|
197
|
+
resultSignature = "";
|
|
198
|
+
activeChangeIndex = -1;
|
|
199
|
+
get heading() {
|
|
200
|
+
return this.getAttribute("heading") ?? "Comparison";
|
|
201
|
+
}
|
|
202
|
+
set heading(value) {
|
|
203
|
+
this.setAttribute("heading", value);
|
|
204
|
+
}
|
|
205
|
+
/** The original document text. (`before`/`after` collide with ChildNode methods.) */
|
|
206
|
+
get beforeText() {
|
|
207
|
+
return this.getAttribute("before-text") ?? "";
|
|
208
|
+
}
|
|
209
|
+
set beforeText(value) {
|
|
210
|
+
this.setAttribute("before-text", value);
|
|
211
|
+
}
|
|
212
|
+
/** The revised document text. */
|
|
213
|
+
get afterText() {
|
|
214
|
+
return this.getAttribute("after-text") ?? "";
|
|
215
|
+
}
|
|
216
|
+
set afterText(value) {
|
|
217
|
+
this.setAttribute("after-text", value);
|
|
218
|
+
}
|
|
219
|
+
get beforeLabel() {
|
|
220
|
+
return this.getAttribute("before-label") ?? "Original";
|
|
221
|
+
}
|
|
222
|
+
set beforeLabel(value) {
|
|
223
|
+
this.setAttribute("before-label", value);
|
|
224
|
+
}
|
|
225
|
+
get afterLabel() {
|
|
226
|
+
return this.getAttribute("after-label") ?? "Revised";
|
|
227
|
+
}
|
|
228
|
+
set afterLabel(value) {
|
|
229
|
+
this.setAttribute("after-label", value);
|
|
230
|
+
}
|
|
231
|
+
/** `split` (side-by-side, default) or `inline` (unified). */
|
|
232
|
+
get mode() {
|
|
233
|
+
return this.getAttribute("mode") === "inline" ? "inline" : "split";
|
|
234
|
+
}
|
|
235
|
+
set mode(value) {
|
|
236
|
+
this.setAttribute("mode", value);
|
|
237
|
+
}
|
|
238
|
+
/** The computed diff for the current inputs. */
|
|
239
|
+
get diff() {
|
|
240
|
+
return this.result;
|
|
241
|
+
}
|
|
242
|
+
/** Step change navigation programmatically; used by the header buttons. */
|
|
243
|
+
goToChange(index) {
|
|
244
|
+
const ranges = this.result?.changeRanges ?? [];
|
|
245
|
+
if (!ranges.length) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const clamped = Math.max(0, Math.min(ranges.length - 1, index));
|
|
249
|
+
this.activeChangeIndex = clamped;
|
|
250
|
+
if (this.isRendered) {
|
|
251
|
+
this.update();
|
|
252
|
+
}
|
|
253
|
+
const range = ranges[clamped];
|
|
254
|
+
const target = this.scrollerEl.querySelector(`[part="row"][data-row-index="${String(range?.start ?? 0)}"]`);
|
|
255
|
+
target?.scrollIntoView?.({ block: "center" });
|
|
256
|
+
this.dispatchEvent(new CustomEvent("change-focused", {
|
|
257
|
+
bubbles: true,
|
|
258
|
+
composed: true,
|
|
259
|
+
detail: { index: clamped, total: ranges.length },
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
lineHtml(line) {
|
|
263
|
+
if (!line) {
|
|
264
|
+
return "";
|
|
265
|
+
}
|
|
266
|
+
if (!line.segments) {
|
|
267
|
+
return escapeHtml(line.text);
|
|
268
|
+
}
|
|
269
|
+
return line.segments
|
|
270
|
+
.map(segment => {
|
|
271
|
+
const text = escapeHtml(segment.text);
|
|
272
|
+
if (segment.kind === "removed") {
|
|
273
|
+
return `<del>${text}</del>`;
|
|
274
|
+
}
|
|
275
|
+
if (segment.kind === "added") {
|
|
276
|
+
return `<ins>${text}</ins>`;
|
|
277
|
+
}
|
|
278
|
+
return text;
|
|
279
|
+
})
|
|
280
|
+
.join("");
|
|
281
|
+
}
|
|
282
|
+
rowHtml(rowIndex, active) {
|
|
283
|
+
const row = this.result?.rows[rowIndex];
|
|
284
|
+
if (!row) {
|
|
285
|
+
return "";
|
|
286
|
+
}
|
|
287
|
+
const attrs = `part="row" data-kind="${row.kind}" data-row-index="${String(rowIndex)}" data-active="${active ? "true" : "false"}"`;
|
|
288
|
+
if (this.mode === "inline") {
|
|
289
|
+
const lines = [];
|
|
290
|
+
if (row.before && row.kind !== "equal") {
|
|
291
|
+
lines.push(`
|
|
292
|
+
<tr ${attrs}>
|
|
293
|
+
<td part="line-number">${String(row.before.number)}</td>
|
|
294
|
+
<td part="line-number"></td>
|
|
295
|
+
<td part="cell" data-side="before">${this.lineHtml(row.before)}</td>
|
|
296
|
+
</tr>
|
|
297
|
+
`);
|
|
298
|
+
}
|
|
299
|
+
if (row.after) {
|
|
300
|
+
lines.push(`
|
|
301
|
+
<tr ${attrs}>
|
|
302
|
+
<td part="line-number">${row.kind === "equal" && row.before ? String(row.before.number) : ""}</td>
|
|
303
|
+
<td part="line-number">${String(row.after.number)}</td>
|
|
304
|
+
<td part="cell" data-side="${row.kind === "equal" ? "context" : "after"}">${this.lineHtml(row.after)}</td>
|
|
305
|
+
</tr>
|
|
306
|
+
`);
|
|
307
|
+
}
|
|
308
|
+
return lines.join("");
|
|
309
|
+
}
|
|
310
|
+
return `
|
|
311
|
+
<tr ${attrs}>
|
|
312
|
+
<td part="line-number">${row.before ? String(row.before.number) : ""}</td>
|
|
313
|
+
<td part="cell" data-side="before">${this.lineHtml(row.before)}</td>
|
|
314
|
+
<td part="line-number">${row.after ? String(row.after.number) : ""}</td>
|
|
315
|
+
<td part="cell" data-side="after">${this.lineHtml(row.after)}</td>
|
|
316
|
+
</tr>
|
|
317
|
+
`;
|
|
318
|
+
}
|
|
319
|
+
rebuildTable() {
|
|
320
|
+
const rows = this.result?.rows ?? [];
|
|
321
|
+
const activeRange = this.activeChangeIndex >= 0 ? this.result?.changeRanges[this.activeChangeIndex] : undefined;
|
|
322
|
+
const isActive = (index) => !!activeRange && index >= activeRange.start && index <= activeRange.end;
|
|
323
|
+
const header = this.mode === "inline"
|
|
324
|
+
? `<tr>
|
|
325
|
+
<th part="column-label" scope="col" colspan="2">Line</th>
|
|
326
|
+
<th part="column-label" scope="col">${escapeHtml(`${this.beforeLabel} → ${this.afterLabel}`)}</th>
|
|
327
|
+
</tr>`
|
|
328
|
+
: `<tr>
|
|
329
|
+
<th part="column-label" scope="col" colspan="2">${escapeHtml(this.beforeLabel)}</th>
|
|
330
|
+
<th part="column-label" scope="col" colspan="2">${escapeHtml(this.afterLabel)}</th>
|
|
331
|
+
</tr>`;
|
|
332
|
+
this.scrollerEl.innerHTML = `
|
|
333
|
+
<table part="table" aria-label="${escapeHtml(`${this.heading}: ${this.beforeLabel} vs ${this.afterLabel}`)}">
|
|
334
|
+
<thead>${header}</thead>
|
|
335
|
+
<tbody>${rows.map((_, index) => this.rowHtml(index, isActive(index))).join("")}</tbody>
|
|
336
|
+
</table>
|
|
337
|
+
`;
|
|
338
|
+
}
|
|
339
|
+
renderTemplate() {
|
|
340
|
+
if (!this.shadowRoot) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
this.shadowRoot.innerHTML = `
|
|
344
|
+
<style>${elementStyles}</style>
|
|
345
|
+
<section part="panel">
|
|
346
|
+
<header part="header">
|
|
347
|
+
<h2 part="title"></h2>
|
|
348
|
+
<span part="stats"></span>
|
|
349
|
+
<span part="nav" hidden>
|
|
350
|
+
<button type="button" part="nav-previous" aria-label="Previous change">‹ Prev</button>
|
|
351
|
+
<span part="nav-position" aria-live="polite"></span>
|
|
352
|
+
<button type="button" part="nav-next" aria-label="Next change">Next ›</button>
|
|
353
|
+
</span>
|
|
354
|
+
</header>
|
|
355
|
+
<div part="scroller" tabindex="0"></div>
|
|
356
|
+
<div part="empty" hidden>Nothing to compare.</div>
|
|
357
|
+
</section>
|
|
358
|
+
`;
|
|
359
|
+
this.titleEl = this.shadowRoot.querySelector('[part="title"]');
|
|
360
|
+
this.statsEl = this.shadowRoot.querySelector('[part="stats"]');
|
|
361
|
+
this.navEl = this.shadowRoot.querySelector('[part="nav"]');
|
|
362
|
+
this.navPositionEl = this.shadowRoot.querySelector('[part="nav-position"]');
|
|
363
|
+
this.navPreviousEl = this.shadowRoot.querySelector('[part="nav-previous"]');
|
|
364
|
+
this.navNextEl = this.shadowRoot.querySelector('[part="nav-next"]');
|
|
365
|
+
this.scrollerEl = this.shadowRoot.querySelector('[part="scroller"]');
|
|
366
|
+
this.emptyEl = this.shadowRoot.querySelector('[part="empty"]');
|
|
367
|
+
}
|
|
368
|
+
setupListeners() {
|
|
369
|
+
this.navPreviousEl.addEventListener("click", () => {
|
|
370
|
+
this.goToChange(this.activeChangeIndex <= 0 ? 0 : this.activeChangeIndex - 1);
|
|
371
|
+
});
|
|
372
|
+
this.navNextEl.addEventListener("click", () => {
|
|
373
|
+
this.goToChange(this.activeChangeIndex + 1);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
update() {
|
|
377
|
+
if (!this.scrollerEl) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
this.titleEl.textContent = this.heading;
|
|
381
|
+
const before = this.beforeText;
|
|
382
|
+
const after = this.afterText;
|
|
383
|
+
const hasContent = before.length > 0 || after.length > 0;
|
|
384
|
+
this.emptyEl.hidden = hasContent;
|
|
385
|
+
this.scrollerEl.hidden = !hasContent;
|
|
386
|
+
// The diff and the table rebuild only when the inputs (or mode) change;
|
|
387
|
+
// navigation re-marks the active rows and label/heading changes patch the
|
|
388
|
+
// header cells + aria-label in place (see below), preserving the table.
|
|
389
|
+
const signature = [this.mode, String(before.length), String(after.length), before, after].join("");
|
|
390
|
+
if (signature !== this.resultSignature) {
|
|
391
|
+
this.resultSignature = signature;
|
|
392
|
+
this.result = hasContent ? computeTextDiff(before, after) : null;
|
|
393
|
+
this.activeChangeIndex = -1;
|
|
394
|
+
if (hasContent) {
|
|
395
|
+
this.rebuildTable();
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
this.scrollerEl.innerHTML = "";
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
else if (this.result) {
|
|
402
|
+
// Re-mark active rows in place.
|
|
403
|
+
const activeRange = this.activeChangeIndex >= 0 ? this.result.changeRanges[this.activeChangeIndex] : undefined;
|
|
404
|
+
this.scrollerEl.querySelectorAll('[part="row"]').forEach(row => {
|
|
405
|
+
const index = Number(row.dataset.rowIndex);
|
|
406
|
+
row.dataset.active =
|
|
407
|
+
activeRange && index >= activeRange.start && index <= activeRange.end ? "true" : "false";
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
// Labels and heading are patched into the existing table so renaming a
|
|
411
|
+
// column (or the heading) never resets scroll position or row identity.
|
|
412
|
+
const table = this.scrollerEl.querySelector('[part="table"]');
|
|
413
|
+
if (table) {
|
|
414
|
+
table.setAttribute("aria-label", `${this.heading}: ${this.beforeLabel} vs ${this.afterLabel}`);
|
|
415
|
+
const labels = table.querySelectorAll('[part="column-label"]');
|
|
416
|
+
if (this.mode === "inline") {
|
|
417
|
+
labels[1].textContent = `${this.beforeLabel} → ${this.afterLabel}`;
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
labels[0].textContent = this.beforeLabel;
|
|
421
|
+
labels[1].textContent = this.afterLabel;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const stats = this.result?.stats ?? { added: 0, removed: 0, changed: 0 };
|
|
425
|
+
this.statsEl.textContent = formatDiffStats(stats);
|
|
426
|
+
const total = this.result?.changeRanges.length ?? 0;
|
|
427
|
+
this.navEl.hidden = total === 0;
|
|
428
|
+
this.navPositionEl.textContent =
|
|
429
|
+
this.activeChangeIndex >= 0 ? `Change ${String(this.activeChangeIndex + 1)} of ${String(total)}` : `${String(total)} changes`;
|
|
430
|
+
this.navPreviousEl.disabled = this.activeChangeIndex <= 0;
|
|
431
|
+
this.navNextEl.disabled = total === 0 || this.activeChangeIndex >= total - 1;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
DiffViewer.register();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure text-diff engine: line-level alignment with word-level refinement of
|
|
3
|
+
* changed lines. DOM-free and deterministic so the whole pipeline is
|
|
4
|
+
* unit-testable; the viewer element is a thin renderer over `computeTextDiff`.
|
|
5
|
+
*/
|
|
6
|
+
import type { DiffResult, DiffSegment, DiffStats } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Word-level runs for one changed line pair: the before side carries
|
|
9
|
+
* equal/removed segments, the after side equal/added.
|
|
10
|
+
*/
|
|
11
|
+
export declare const computeInlineSegments: (before: string, after: string) => {
|
|
12
|
+
before: DiffSegment[];
|
|
13
|
+
after: DiffSegment[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Line-level diff of two documents. Adjacent removed/added runs are paired
|
|
17
|
+
* into `changed` rows (with word-level segments) when the lines are similar
|
|
18
|
+
* enough; otherwise they stay as distinct removals and additions.
|
|
19
|
+
*/
|
|
20
|
+
export declare const computeTextDiff: (before: string, after: string) => DiffResult;
|
|
21
|
+
/** Compact "+A −R ~C" summary for headers and chips. */
|
|
22
|
+
export declare const formatDiffStats: (stats: DiffStats) => string;
|