@uibit/diff-viewer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 UIBit Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Diff Viewer
2
+
3
+ [Interactive Demonstration](https://rawlings.github.io/uibit/components/diff-viewer)
4
+
5
+ Diff Viewer provides a comparison block for reviewing differences between two sets of text or code. It computes a line-level diff internally using the Longest Common Subsequence (LCS) algorithm, displaying additions and removals in a side-by-side (split) or inline format.
6
+
7
+ ## Value Delivery
8
+
9
+ - **Clear Comparison** – Helps users quickly identify text insertions and deletions with standardized semantic color highlights.
10
+ - **Flexible Layouts** – Supports split-pane side-by-side or inline unified layouts to accommodate different screen sizes and user preferences.
11
+ - **Self-Contained Computation** – Performs diff calculations entirely client-side without relying on external libraries or server roundtrips.
12
+
13
+ ## Ideal Applications
14
+
15
+ - **Version History** – Reviewing edits in collaborative documents or content management systems.
16
+ - **Code Reviews** – Inline or split presentation of source code edits and patches.
17
+ - **Configuration Audits** – Comparing system settings, configuration files, or data payloads.
18
+
19
+ ## Further Information
20
+
21
+ Detailed design guidelines, customizable attributes, and integration examples are available on our documentation site.
22
+
23
+ ## Changelog
24
+
25
+ Please see the [Changelog](CHANGELOG.md) for version history.
@@ -0,0 +1,374 @@
1
+ {
2
+ "schemaVersion": "1.0.0",
3
+ "readme": "",
4
+ "modules": [
5
+ {
6
+ "kind": "javascript-module",
7
+ "path": "src/diff-viewer.ts",
8
+ "declarations": [
9
+ {
10
+ "kind": "class",
11
+ "description": "Side-by-side or inline comparison block for two blocks of text or code.\nComputes a line-level diff internally using LCS — no external libraries needed.\nDeleted lines are highlighted red, inserted lines green, in the familiar\ncode-review style.\n\nSupply the two texts via the `old` and `new` properties (or `old-text` /\n`new-text` attributes for HTML usage). Switch between layouts with the\n`mode` attribute.",
12
+ "name": "DiffViewer",
13
+ "cssProperties": [
14
+ {
15
+ "description": "Code font stack",
16
+ "name": "--uibit-diff-viewer-font-family",
17
+ "default": "var(--uibit-font-mono)"
18
+ },
19
+ {
20
+ "description": "Font size",
21
+ "name": "--uibit-diff-viewer-font-size",
22
+ "default": "0.8125rem"
23
+ },
24
+ {
25
+ "description": "Line height",
26
+ "name": "--uibit-diff-viewer-line-height",
27
+ "default": "1.6"
28
+ },
29
+ {
30
+ "description": "Border and divider color",
31
+ "name": "--uibit-diff-viewer-border-color",
32
+ "default": "var(--uibit-border-color)"
33
+ },
34
+ {
35
+ "description": "Corner radius",
36
+ "name": "--uibit-diff-viewer-radius",
37
+ "default": "var(--uibit-radius-2xl)"
38
+ },
39
+ {
40
+ "description": "Header background",
41
+ "name": "--uibit-diff-viewer-header-bg",
42
+ "default": "var(--uibit-bg-subtle)"
43
+ },
44
+ {
45
+ "description": "Header label text color",
46
+ "name": "--uibit-diff-viewer-label-color",
47
+ "default": "var(--uibit-text-muted)"
48
+ },
49
+ {
50
+ "description": "Line-number gutter background",
51
+ "name": "--uibit-diff-viewer-gutter-bg",
52
+ "default": "var(--uibit-bg-subtle)"
53
+ },
54
+ {
55
+ "description": "Line-number gutter text color",
56
+ "name": "--uibit-diff-viewer-gutter-color",
57
+ "default": "var(--uibit-color-gray-400)"
58
+ },
59
+ {
60
+ "description": "Deleted-line background",
61
+ "name": "--uibit-diff-viewer-delete-bg",
62
+ "default": "#fef2f2"
63
+ },
64
+ {
65
+ "description": "Deleted-line text color",
66
+ "name": "--uibit-diff-viewer-delete-color",
67
+ "default": "#991b1b"
68
+ },
69
+ {
70
+ "description": "Deleted-line gutter background",
71
+ "name": "--uibit-diff-viewer-delete-gutter-bg",
72
+ "default": "#fee2e2"
73
+ },
74
+ {
75
+ "description": "Inserted-line background",
76
+ "name": "--uibit-diff-viewer-insert-bg",
77
+ "default": "#f0fdf4"
78
+ },
79
+ {
80
+ "description": "Inserted-line text color",
81
+ "name": "--uibit-diff-viewer-insert-color",
82
+ "default": "#166534"
83
+ },
84
+ {
85
+ "description": "Inserted-line gutter background",
86
+ "name": "--uibit-diff-viewer-insert-gutter-bg",
87
+ "default": "#dcfce7"
88
+ },
89
+ {
90
+ "description": "Unchanged-line text color",
91
+ "name": "--uibit-diff-viewer-equal-color",
92
+ "default": "var(--uibit-text-secondary)"
93
+ }
94
+ ],
95
+ "members": [
96
+ {
97
+ "kind": "field",
98
+ "name": "oldText",
99
+ "type": {
100
+ "text": "string"
101
+ },
102
+ "privacy": "private",
103
+ "default": "''"
104
+ },
105
+ {
106
+ "kind": "field",
107
+ "name": "newText",
108
+ "type": {
109
+ "text": "string"
110
+ },
111
+ "privacy": "private",
112
+ "default": "''"
113
+ },
114
+ {
115
+ "kind": "field",
116
+ "name": "mode",
117
+ "type": {
118
+ "text": "'split' | 'inline'"
119
+ },
120
+ "default": "'split'",
121
+ "description": "Layout mode: 'split' shows two panes side by side, 'inline' shows a single unified view.",
122
+ "attribute": "mode",
123
+ "reflects": true
124
+ },
125
+ {
126
+ "kind": "field",
127
+ "name": "showLineNumbers",
128
+ "type": {
129
+ "text": "boolean"
130
+ },
131
+ "default": "true",
132
+ "description": "Show line numbers in the gutter.",
133
+ "attribute": "show-line-numbers"
134
+ },
135
+ {
136
+ "kind": "method",
137
+ "name": "_renderLine",
138
+ "privacy": "private",
139
+ "parameters": [
140
+ {
141
+ "name": "type",
142
+ "type": {
143
+ "text": "'equal' | 'insert' | 'delete'"
144
+ }
145
+ },
146
+ {
147
+ "name": "text",
148
+ "type": {
149
+ "text": "string"
150
+ }
151
+ },
152
+ {
153
+ "name": "lineNum",
154
+ "type": {
155
+ "text": "number | null"
156
+ }
157
+ }
158
+ ]
159
+ },
160
+ {
161
+ "kind": "method",
162
+ "name": "_renderSplit",
163
+ "privacy": "private",
164
+ "parameters": [
165
+ {
166
+ "name": "ops",
167
+ "type": {
168
+ "text": "DiffOp[]"
169
+ }
170
+ }
171
+ ]
172
+ },
173
+ {
174
+ "kind": "method",
175
+ "name": "_renderInline",
176
+ "privacy": "private",
177
+ "parameters": [
178
+ {
179
+ "name": "ops",
180
+ "type": {
181
+ "text": "DiffOp[]"
182
+ }
183
+ }
184
+ ]
185
+ },
186
+ {
187
+ "kind": "method",
188
+ "name": "_handleOldChange",
189
+ "privacy": "private",
190
+ "parameters": [
191
+ {
192
+ "name": "e",
193
+ "type": {
194
+ "text": "Event"
195
+ }
196
+ }
197
+ ]
198
+ },
199
+ {
200
+ "kind": "method",
201
+ "name": "_handleNewChange",
202
+ "privacy": "private",
203
+ "parameters": [
204
+ {
205
+ "name": "e",
206
+ "type": {
207
+ "text": "Event"
208
+ }
209
+ }
210
+ ]
211
+ }
212
+ ],
213
+ "attributes": [
214
+ {
215
+ "name": "mode",
216
+ "type": {
217
+ "text": "'split' | 'inline'"
218
+ },
219
+ "default": "'split'",
220
+ "description": "Layout mode: 'split' shows two panes side by side, 'inline' shows a single unified view.",
221
+ "fieldName": "mode"
222
+ },
223
+ {
224
+ "name": "show-line-numbers",
225
+ "type": {
226
+ "text": "boolean"
227
+ },
228
+ "default": "true",
229
+ "description": "Show line numbers in the gutter.",
230
+ "fieldName": "showLineNumbers"
231
+ }
232
+ ],
233
+ "superclass": {
234
+ "name": "UIBitElement",
235
+ "package": "@uibit/core"
236
+ },
237
+ "tagName": "uibit-diff-viewer",
238
+ "customElement": true
239
+ }
240
+ ],
241
+ "exports": [
242
+ {
243
+ "kind": "js",
244
+ "name": "DiffViewer",
245
+ "declaration": {
246
+ "name": "DiffViewer",
247
+ "module": "src/diff-viewer.ts"
248
+ }
249
+ },
250
+ {
251
+ "kind": "custom-element-definition",
252
+ "name": "uibit-diff-viewer",
253
+ "declaration": {
254
+ "name": "DiffViewer",
255
+ "module": "src/diff-viewer.ts"
256
+ }
257
+ },
258
+ {
259
+ "kind": "js",
260
+ "name": "default",
261
+ "declaration": {
262
+ "name": "DiffViewer",
263
+ "module": "src/diff-viewer.ts"
264
+ }
265
+ }
266
+ ]
267
+ },
268
+ {
269
+ "kind": "javascript-module",
270
+ "path": "src/diff.ts",
271
+ "declarations": [
272
+ {
273
+ "kind": "function",
274
+ "name": "diffLines",
275
+ "return": {
276
+ "type": {
277
+ "text": "DiffOp[]"
278
+ }
279
+ },
280
+ "parameters": [
281
+ {
282
+ "name": "oldText",
283
+ "type": {
284
+ "text": "string"
285
+ }
286
+ },
287
+ {
288
+ "name": "newText",
289
+ "type": {
290
+ "text": "string"
291
+ }
292
+ }
293
+ ]
294
+ }
295
+ ],
296
+ "exports": [
297
+ {
298
+ "kind": "js",
299
+ "name": "diffLines",
300
+ "declaration": {
301
+ "name": "diffLines",
302
+ "module": "src/diff.ts"
303
+ }
304
+ }
305
+ ]
306
+ },
307
+ {
308
+ "kind": "javascript-module",
309
+ "path": "src/index.ts",
310
+ "declarations": [],
311
+ "exports": [
312
+ {
313
+ "kind": "js",
314
+ "name": "default",
315
+ "declaration": {
316
+ "name": "default",
317
+ "module": "./diff-viewer"
318
+ }
319
+ },
320
+ {
321
+ "kind": "js",
322
+ "name": "DiffViewer",
323
+ "declaration": {
324
+ "name": "DiffViewer",
325
+ "module": "./diff-viewer"
326
+ }
327
+ },
328
+ {
329
+ "kind": "js",
330
+ "name": "DiffOp",
331
+ "declaration": {
332
+ "name": "DiffOp",
333
+ "module": "./diff"
334
+ }
335
+ },
336
+ {
337
+ "kind": "js",
338
+ "name": "*",
339
+ "declaration": {
340
+ "name": "*",
341
+ "module": "src/types"
342
+ }
343
+ }
344
+ ]
345
+ },
346
+ {
347
+ "kind": "javascript-module",
348
+ "path": "src/styles.ts",
349
+ "declarations": [
350
+ {
351
+ "kind": "variable",
352
+ "name": "styles",
353
+ "default": "css` :host { --uibit-diff-viewer-border-color: var(--uibit-border-color, var(--uibit-color-gray-200, #e5e7eb)); --uibit-diff-viewer-radius: var(--uibit-radius-2xl, 0.5rem); --uibit-diff-viewer-label-color: var(--uibit-text-muted, var(--uibit-color-gray-500, #6b7280)); --uibit-diff-viewer-gutter-color: var(--uibit-color-gray-400, #d1d5db); --uibit-diff-viewer-equal-color: var(--uibit-text-secondary, var(--uibit-color-gray-700, #374151)); display: block; font-family: var(--uibit-diff-viewer-font-family, var(--uibit-font-mono, ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, monospace)); font-size: var(--uibit-diff-viewer-font-size, var(--uibit-font-size-sm, calc(0.8125rem * var(--uibit-font-scale-factor, 1)))); line-height: var(--uibit-diff-viewer-line-height, var(--uibit-line-height-normal, 1.5)); border: 0.0625rem solid var(--uibit-diff-viewer-border-color); border-radius: var(--uibit-diff-viewer-radius); overflow: hidden; } .header { display: grid; border-bottom: 0.0625rem solid var(--uibit-diff-viewer-border-color); } :host([mode=\"split\"]) .header { grid-template-columns: 1fr 1fr; } :host([mode=\"inline\"]) .header { grid-template-columns: 1fr; } .header-cell { padding: calc(0.5rem * var(--uibit-spacing-factor, 1)) calc(1rem * var(--uibit-spacing-factor, 1)); font-size: var(--uibit-font-size-xs, calc(0.75rem * var(--uibit-font-scale-factor, 1))); font-weight: var(--uibit-font-weight-medium, 500); color: var(--uibit-diff-viewer-label-color, #6b7280); font-family: var(--uibit-diff-viewer-font-family, inherit); border-right: 0.0625rem solid var(--uibit-diff-viewer-border-color, #e5e7eb); } .header-cell:last-child { border-right: none; } .body { display: grid; overflow: auto; } :host([mode=\"split\"]) .body { grid-template-columns: 1fr 1fr; } :host([mode=\"inline\"]) .body { grid-template-columns: 1fr; } .pane { overflow: auto; border-right: 0.0625rem solid var(--uibit-diff-viewer-border-color, #e5e7eb); } .pane:last-child { border-right: none; } .line { display: flex; min-width: max-content; } .gutter { user-select: none; min-width: calc(3rem * var(--uibit-spacing-factor, 1)); padding: 0 calc(0.75rem * var(--uibit-spacing-factor, 1)); text-align: right; color: var(--uibit-diff-viewer-gutter-color, #d1d5db); border-right: 0.0625rem solid var(--uibit-diff-viewer-border-color, #e5e7eb); flex-shrink: 0; } .content { padding: 0 calc(1rem * var(--uibit-spacing-factor, 1)); white-space: pre; flex: 1; } .line.delete { background: rgba(239, 68, 68, 0.06); color: var(--uibit-diff-delete-color, #991b1b); } .line.delete .gutter { color: rgba(153, 27, 27, 0.4); } .line.insert { background: rgba(34, 197, 94, 0.06); color: var(--uibit-diff-insert-color, #166534); } .line.insert .gutter { color: rgba(22, 101, 52, 0.4); } .line.equal { background: transparent; color: var(--uibit-diff-viewer-equal-color, #374151); } .sign { display: inline-block; width: 1rem; margin-right: 0.25rem; flex-shrink: 0; opacity: 0.5; } .divider { width: 0.0625rem; background: var(--uibit-diff-viewer-border-color, #e5e7eb); } `"
354
+ }
355
+ ],
356
+ "exports": [
357
+ {
358
+ "kind": "js",
359
+ "name": "styles",
360
+ "declaration": {
361
+ "name": "styles",
362
+ "module": "src/styles.ts"
363
+ }
364
+ }
365
+ ]
366
+ },
367
+ {
368
+ "kind": "javascript-module",
369
+ "path": "src/types.ts",
370
+ "declarations": [],
371
+ "exports": []
372
+ }
373
+ ]
374
+ }
@@ -0,0 +1,46 @@
1
+ import { UIBitElement } from '@uibit/core';
2
+ /**
3
+ * Side-by-side or inline comparison block for two blocks of text or code.
4
+ * Computes a line-level diff internally using LCS — no external libraries needed.
5
+ * Deleted lines are highlighted red, inserted lines green, in the familiar
6
+ * code-review style.
7
+ *
8
+ * Supply the two texts via the `old` and `new` properties (or `old-text` /
9
+ * `new-text` attributes for HTML usage). Switch between layouts with the
10
+ * `mode` attribute.
11
+ *
12
+ * @cssprop [--uibit-diff-viewer-font-family=var(--uibit-font-mono)] - Code font stack
13
+ * @cssprop [--uibit-diff-viewer-font-size=0.8125rem] - Font size
14
+ * @cssprop [--uibit-diff-viewer-line-height=1.6] - Line height
15
+ * @cssprop [--uibit-diff-viewer-border-color=var(--uibit-border-color)] - Border and divider color
16
+ * @cssprop [--uibit-diff-viewer-radius=var(--uibit-radius-2xl)] - Corner radius
17
+ * @cssprop [--uibit-diff-viewer-header-bg=var(--uibit-bg-subtle)] - Header background
18
+ * @cssprop [--uibit-diff-viewer-label-color=var(--uibit-text-muted)] - Header label text color
19
+ * @cssprop [--uibit-diff-viewer-gutter-bg=var(--uibit-bg-subtle)] - Line-number gutter background
20
+ * @cssprop [--uibit-diff-viewer-gutter-color=var(--uibit-color-gray-400)] - Line-number gutter text color
21
+ * @cssprop [--uibit-diff-viewer-delete-bg=#fef2f2] - Deleted-line background
22
+ * @cssprop [--uibit-diff-viewer-delete-color=#991b1b] - Deleted-line text color
23
+ * @cssprop [--uibit-diff-viewer-delete-gutter-bg=#fee2e2] - Deleted-line gutter background
24
+ * @cssprop [--uibit-diff-viewer-insert-bg=#f0fdf4] - Inserted-line background
25
+ * @cssprop [--uibit-diff-viewer-insert-color=#166534] - Inserted-line text color
26
+ * @cssprop [--uibit-diff-viewer-insert-gutter-bg=#dcfce7] - Inserted-line gutter background
27
+ * @cssprop [--uibit-diff-viewer-equal-color=var(--uibit-text-secondary)] - Unchanged-line text color
28
+ */
29
+ export declare class DiffViewer extends UIBitElement {
30
+ static styles: import("lit").CSSResult;
31
+ private oldText;
32
+ private newText;
33
+ /** Layout mode: 'split' shows two panes side by side, 'inline' shows a single unified view. */
34
+ mode: 'split' | 'inline';
35
+ connectedCallback(): void;
36
+ /** Show line numbers in the gutter. */
37
+ showLineNumbers: boolean;
38
+ private _renderLine;
39
+ private _renderSplit;
40
+ private _renderInline;
41
+ private _handleOldChange;
42
+ private _handleNewChange;
43
+ render(): import("lit").TemplateResult<1>;
44
+ }
45
+ export default DiffViewer;
46
+ //# sourceMappingURL=diff-viewer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff-viewer.d.ts","sourceRoot":"","sources":["../src/diff-viewer.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,YAAY,EAAE,MAAM,aAAa,CAAC;AAM1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBACa,UAAW,SAAQ,YAAY;IAC1C,MAAM,CAAC,MAAM,0BAAU;IAEd,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,OAAO,CAAM;IAE9B,+FAA+F;IAClE,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAW;IAEhE,iBAAiB,SAQhB;IAED,uCAAuC;IACsB,eAAe,UAAQ;IAEpF,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,YAAY;IAgCpB,OAAO,CAAC,aAAa;IAwBrB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,gBAAgB;IAQxB,MAAM,oCAOL;CACF;eAEc,UAAU"}
@@ -0,0 +1,163 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, nothing } from 'lit';
8
+ import { customElement, UIBitElement } from '@uibit/core';
9
+ import { property, state } from 'lit/decorators.js';
10
+ import { styles } from './styles';
11
+ import { diffLines } from './diff';
12
+ /**
13
+ * Side-by-side or inline comparison block for two blocks of text or code.
14
+ * Computes a line-level diff internally using LCS — no external libraries needed.
15
+ * Deleted lines are highlighted red, inserted lines green, in the familiar
16
+ * code-review style.
17
+ *
18
+ * Supply the two texts via the `old` and `new` properties (or `old-text` /
19
+ * `new-text` attributes for HTML usage). Switch between layouts with the
20
+ * `mode` attribute.
21
+ *
22
+ * @cssprop [--uibit-diff-viewer-font-family=var(--uibit-font-mono)] - Code font stack
23
+ * @cssprop [--uibit-diff-viewer-font-size=0.8125rem] - Font size
24
+ * @cssprop [--uibit-diff-viewer-line-height=1.6] - Line height
25
+ * @cssprop [--uibit-diff-viewer-border-color=var(--uibit-border-color)] - Border and divider color
26
+ * @cssprop [--uibit-diff-viewer-radius=var(--uibit-radius-2xl)] - Corner radius
27
+ * @cssprop [--uibit-diff-viewer-header-bg=var(--uibit-bg-subtle)] - Header background
28
+ * @cssprop [--uibit-diff-viewer-label-color=var(--uibit-text-muted)] - Header label text color
29
+ * @cssprop [--uibit-diff-viewer-gutter-bg=var(--uibit-bg-subtle)] - Line-number gutter background
30
+ * @cssprop [--uibit-diff-viewer-gutter-color=var(--uibit-color-gray-400)] - Line-number gutter text color
31
+ * @cssprop [--uibit-diff-viewer-delete-bg=#fef2f2] - Deleted-line background
32
+ * @cssprop [--uibit-diff-viewer-delete-color=#991b1b] - Deleted-line text color
33
+ * @cssprop [--uibit-diff-viewer-delete-gutter-bg=#fee2e2] - Deleted-line gutter background
34
+ * @cssprop [--uibit-diff-viewer-insert-bg=#f0fdf4] - Inserted-line background
35
+ * @cssprop [--uibit-diff-viewer-insert-color=#166534] - Inserted-line text color
36
+ * @cssprop [--uibit-diff-viewer-insert-gutter-bg=#dcfce7] - Inserted-line gutter background
37
+ * @cssprop [--uibit-diff-viewer-equal-color=var(--uibit-text-secondary)] - Unchanged-line text color
38
+ */
39
+ let DiffViewer = class DiffViewer extends UIBitElement {
40
+ constructor() {
41
+ super(...arguments);
42
+ this.oldText = '';
43
+ this.newText = '';
44
+ /** Layout mode: 'split' shows two panes side by side, 'inline' shows a single unified view. */
45
+ this.mode = 'split';
46
+ /** Show line numbers in the gutter. */
47
+ this.showLineNumbers = true;
48
+ }
49
+ static { this.styles = styles; }
50
+ connectedCallback() {
51
+ super.connectedCallback();
52
+ if (!this.hasAttribute('role')) {
53
+ this.setAttribute('role', 'region');
54
+ }
55
+ if (!this.hasAttribute('aria-label')) {
56
+ this.setAttribute('aria-label', 'Text comparison');
57
+ }
58
+ }
59
+ _renderLine(type, text, lineNum) {
60
+ const sign = type === 'insert' ? '+' : type === 'delete' ? '-' : ' ';
61
+ return html `
62
+ <div class="line ${type}">
63
+ ${this.showLineNumbers
64
+ ? html `<span class="gutter">${lineNum ?? ''}</span>`
65
+ : nothing}
66
+ <span class="content"><span class="sign" aria-hidden="true">${sign}</span>${text}</span>
67
+ </div>
68
+ `;
69
+ }
70
+ _renderSplit(ops) {
71
+ let oldLine = 1;
72
+ let newLine = 1;
73
+ const leftLines = [];
74
+ const rightLines = [];
75
+ for (const op of ops) {
76
+ if (op.type === 'equal') {
77
+ leftLines.push(this._renderLine('equal', op.text, oldLine++));
78
+ rightLines.push(this._renderLine('equal', op.text, newLine++));
79
+ }
80
+ else if (op.type === 'delete') {
81
+ leftLines.push(this._renderLine('delete', op.text, oldLine++));
82
+ rightLines.push(html `<div class="line equal"><span class="gutter"></span><span class="content"></span></div>`);
83
+ }
84
+ else {
85
+ leftLines.push(html `<div class="line equal"><span class="gutter"></span><span class="content"></span></div>`);
86
+ rightLines.push(this._renderLine('insert', op.text, newLine++));
87
+ }
88
+ }
89
+ return html `
90
+ <div class="header">
91
+ <div class="header-cell"><slot name="old-label">Before</slot></div>
92
+ <div class="header-cell"><slot name="new-label">After</slot></div>
93
+ </div>
94
+ <div class="body">
95
+ <div class="pane">${leftLines}</div>
96
+ <div class="pane">${rightLines}</div>
97
+ </div>
98
+ `;
99
+ }
100
+ _renderInline(ops) {
101
+ let oldLine = 1;
102
+ let newLine = 1;
103
+ const lines = ops.map(op => {
104
+ if (op.type === 'equal') {
105
+ return this._renderLine('equal', op.text, oldLine++);
106
+ }
107
+ else if (op.type === 'delete') {
108
+ return this._renderLine('delete', op.text, oldLine++);
109
+ }
110
+ else {
111
+ return this._renderLine('insert', op.text, newLine++);
112
+ }
113
+ });
114
+ return html `
115
+ <div class="header">
116
+ <div class="header-cell"><slot name="old-label">Before</slot> → <slot name="new-label">After</slot></div>
117
+ </div>
118
+ <div class="body">
119
+ <div class="pane">${lines}</div>
120
+ </div>
121
+ `;
122
+ }
123
+ _handleOldChange(e) {
124
+ const slot = e.target;
125
+ const nodes = slot.assignedNodes({ flatten: true });
126
+ if (nodes.length > 0) {
127
+ this.oldText = nodes.map(n => n.textContent ?? '').join('');
128
+ }
129
+ }
130
+ _handleNewChange(e) {
131
+ const slot = e.target;
132
+ const nodes = slot.assignedNodes({ flatten: true });
133
+ if (nodes.length > 0) {
134
+ this.newText = nodes.map(n => n.textContent ?? '').join('');
135
+ }
136
+ }
137
+ render() {
138
+ const ops = diffLines(this.oldText, this.newText);
139
+ return html `
140
+ <slot name="old" @slotchange=${this._handleOldChange} style="display: none;"></slot>
141
+ <slot name="new" @slotchange=${this._handleNewChange} style="display: none;"></slot>
142
+ ${this.mode === 'split' ? this._renderSplit(ops) : this._renderInline(ops)}
143
+ `;
144
+ }
145
+ };
146
+ __decorate([
147
+ state()
148
+ ], DiffViewer.prototype, "oldText", void 0);
149
+ __decorate([
150
+ state()
151
+ ], DiffViewer.prototype, "newText", void 0);
152
+ __decorate([
153
+ property({ reflect: true })
154
+ ], DiffViewer.prototype, "mode", void 0);
155
+ __decorate([
156
+ property({ type: Boolean, attribute: 'show-line-numbers' })
157
+ ], DiffViewer.prototype, "showLineNumbers", void 0);
158
+ DiffViewer = __decorate([
159
+ customElement('uibit-diff-viewer')
160
+ ], DiffViewer);
161
+ export { DiffViewer };
162
+ export default DiffViewer;
163
+ //# sourceMappingURL=diff-viewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff-viewer.js","sourceRoot":"","sources":["../src/diff-viewer.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,YAAY;IAArC;;QAGY,YAAO,GAAG,EAAE,CAAC;QACb,YAAO,GAAG,EAAE,CAAC;QAE9B,+FAA+F;QAClE,SAAI,GAAuB,OAAO,CAAC;QAYhE,uCAAuC;QACsB,oBAAe,GAAG,IAAI,CAAC;IA8FtF,CAAC;aAjHQ,WAAM,GAAG,MAAM,AAAT,CAAU;IAQvB,iBAAiB;QACf,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACtC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAKO,WAAW,CAA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ED
@@ -0,0 +1,6 @@
1
+ export type DiffOp = {
2
+ type: 'equal' | 'insert' | 'delete';
3
+ text: string;
4
+ };
5
+ export declare function diffLines(oldText: string, newText: string): DiffOp[];
6
+ //# sourceMappingURL=diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IAAE,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAiB3E,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAuBpE"}
package/dist/diff.js ADDED
@@ -0,0 +1,39 @@
1
+ function lcs(a, b) {
2
+ const m = a.length;
3
+ const n = b.length;
4
+ const dp = [];
5
+ for (let i = 0; i <= m; i++) {
6
+ dp[i] = Array.from({ length: n + 1 }).fill(0);
7
+ }
8
+ for (let i = 1; i <= m; i++) {
9
+ for (let j = 1; j <= n; j++) {
10
+ dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] + 1 : Math.max(dp[i - 1][j], dp[i][j - 1]);
11
+ }
12
+ }
13
+ return dp;
14
+ }
15
+ export function diffLines(oldText, newText) {
16
+ const a = oldText.split('\n');
17
+ const b = newText.split('\n');
18
+ const dp = lcs(a, b);
19
+ const ops = [];
20
+ let i = a.length;
21
+ let j = b.length;
22
+ while (i > 0 || j > 0) {
23
+ if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
24
+ ops.push({ type: 'equal', text: a[i - 1] });
25
+ i--;
26
+ j--;
27
+ }
28
+ else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
29
+ ops.push({ type: 'insert', text: b[j - 1] });
30
+ j--;
31
+ }
32
+ else {
33
+ ops.push({ type: 'delete', text: a[i - 1] });
34
+ i--;
35
+ }
36
+ }
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CAAC,CAAC;YAC9C,CAAC,EAAE,CAAC;QACN,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { Component, ChangeDetectionStrategy, ElementRef, input, effect, booleanAttribute } from '@angular/core';
2
+ import '@uibit/diff-viewer';
3
+ import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
4
+
5
+ @Component({
6
+ selector: 'uibit-diff-viewer',
7
+ template: '<ng-content></ng-content>',
8
+ changeDetection: ChangeDetectionStrategy.OnPush,
9
+ standalone: true
10
+ })
11
+ export class NgxDiffViewer {
12
+ constructor(private el: ElementRef<HTMLElementClass>) {
13
+ effect(() => {
14
+ if (this.el.nativeElement) {
15
+ this.el.nativeElement.mode = this.mode();
16
+ }
17
+ });
18
+ effect(() => {
19
+ if (this.el.nativeElement) {
20
+ this.el.nativeElement.showLineNumbers = this.showLineNumbers();
21
+ }
22
+ });
23
+ }
24
+
25
+ readonly mode = input<'split' | 'inline', any>('split');
26
+ readonly showLineNumbers = input<boolean, any>(true, { transform: booleanAttribute });
27
+ }
@@ -0,0 +1,10 @@
1
+ import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
2
+ import '@uibit/diff-viewer';
3
+
4
+ declare global {
5
+ namespace astroHTML.JSX {
6
+ interface IntrinsicElements {
7
+ 'uibit-diff-viewer': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes;
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,7 @@
1
+ import { defineNuxtPlugin } from '#app';
2
+
3
+ export default defineNuxtPlugin(() => {
4
+ if (process.client) {
5
+ import('@uibit/diff-viewer');
6
+ }
7
+ });
@@ -0,0 +1,14 @@
1
+ import type { JSX } from 'preact';
2
+ import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
3
+ import '@uibit/diff-viewer';
4
+
5
+ declare module 'preact' {
6
+ namespace JSX {
7
+ interface IntrinsicElements {
8
+ 'uibit-diff-viewer': JSX.HTMLAttributes<HTMLElementClass> & {
9
+ mode?: 'split' | 'inline';
10
+ showLineNumbers?: boolean;
11
+ };
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,10 @@
1
+ import { component$, Slot } from '@builder.io/qwik';
2
+ import '@uibit/diff-viewer';
3
+
4
+ export const DiffViewer = component$<any>((props) => {
5
+ return (
6
+ <uibit-diff-viewer {...props}>
7
+ <Slot />
8
+ </uibit-diff-viewer>
9
+ );
10
+ });
@@ -0,0 +1,18 @@
1
+ import type { HTMLAttributes, ClassAttributes } from 'react';
2
+ import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
3
+ import '@uibit/diff-viewer';
4
+
5
+ declare global {
6
+ namespace React {
7
+ namespace JSX {
8
+ interface IntrinsicElements {
9
+ 'uibit-diff-viewer': ClassAttributes<HTMLElementClass> & HTMLAttributes<HTMLElementClass> & {
10
+ children?: React.ReactNode;
11
+ class?: string;
12
+ mode?: 'split' | 'inline';
13
+ showLineNumbers?: boolean;
14
+ };
15
+ }
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,15 @@
1
+ import type { JSX } from 'solid-js';
2
+ import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
3
+ import '@uibit/diff-viewer';
4
+
5
+ declare module 'solid-js' {
6
+ namespace JSX {
7
+ interface IntrinsicElements {
8
+ 'uibit-diff-viewer': Partial<HTMLElementClass> & JSX.HTMLAttributes<HTMLElementClass> & {
9
+ mode?: 'split' | 'inline';
10
+ showLineNumbers?: boolean;
11
+
12
+ };
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,13 @@
1
+ import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
2
+ import '@uibit/diff-viewer';
3
+
4
+ declare module '@stencil/core' {
5
+ export namespace JSX {
6
+ interface IntrinsicElements {
7
+ 'uibit-diff-viewer': HTMLElementClass & {
8
+ mode?: 'split' | 'inline';
9
+ showLineNumbers?: boolean;
10
+ };
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,36 @@
1
+ <script lang="ts">
2
+ import '@uibit/diff-viewer';
3
+ import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
4
+
5
+ let {
6
+ mode = undefined,
7
+ showLineNumbers = undefined,
8
+ children
9
+ } = $props<{
10
+ children?: any;
11
+ mode?: 'split' | 'inline';
12
+ showLineNumbers?: boolean;
13
+
14
+ }>();
15
+
16
+ let elementRef: HTMLElementClass | null = $state(null);
17
+
18
+ $effect(() => {
19
+ if (elementRef && mode !== undefined) {
20
+ elementRef.mode = mode;
21
+ }
22
+ if (elementRef && showLineNumbers !== undefined) {
23
+ elementRef.showLineNumbers = showLineNumbers;
24
+ }
25
+ });
26
+
27
+ </script>
28
+
29
+ <uibit-diff-viewer bind:this={elementRef} {...$$restProps}>
30
+
31
+ {#if children}
32
+ {@render children()}
33
+ {:else}
34
+ <slot />
35
+ {/if}
36
+ </uibit-diff-viewer>
@@ -0,0 +1,23 @@
1
+ import { defineComponent, h } from 'vue';
2
+ import type { DiffViewer as HTMLElementClass } from '@uibit/diff-viewer';
3
+ import '@uibit/diff-viewer';
4
+
5
+ export const DiffViewer = defineComponent({
6
+ name: 'DiffViewer',
7
+ props: {
8
+ mode: { type: [String, Number, Boolean, Array, Object] as any },
9
+ showLineNumbers: { type: [String, Number, Boolean, Array, Object] as any }
10
+ },
11
+ emits: [],
12
+ setup(props, { slots, emit }) {
13
+ return () => {
14
+ const eventListeners: Record<string, any> = {};
15
+
16
+
17
+ return h('uibit-diff-viewer', {
18
+ ...props,
19
+ ...eventListeners
20
+ }, slots.default?.());
21
+ };
22
+ }
23
+ });
@@ -0,0 +1,4 @@
1
+ export { default, DiffViewer } from './diff-viewer';
2
+ export type { DiffOp } from './diff';
3
+ export * from './types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { default, DiffViewer } from './diff-viewer';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEpD,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const styles: import("lit").CSSResult;
2
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,yBAyHlB,CAAC"}
package/dist/styles.js ADDED
@@ -0,0 +1,124 @@
1
+ import { css } from 'lit';
2
+ export const styles = css `
3
+ :host {
4
+ --uibit-diff-viewer-border-color: var(--uibit-border-color, var(--uibit-color-gray-200, #e5e7eb));
5
+ --uibit-diff-viewer-radius: var(--uibit-radius-2xl, 0.5rem);
6
+ --uibit-diff-viewer-label-color: var(--uibit-text-muted, var(--uibit-color-gray-500, #6b7280));
7
+ --uibit-diff-viewer-gutter-color: var(--uibit-color-gray-400, #d1d5db);
8
+ --uibit-diff-viewer-equal-color: var(--uibit-text-secondary, var(--uibit-color-gray-700, #374151));
9
+
10
+ display: block;
11
+ font-family: var(--uibit-diff-viewer-font-family, var(--uibit-font-mono, ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, monospace));
12
+ font-size: var(--uibit-diff-viewer-font-size, var(--uibit-font-size-sm, calc(0.8125rem * var(--uibit-font-scale-factor, 1))));
13
+ line-height: var(--uibit-diff-viewer-line-height, var(--uibit-line-height-normal, 1.5));
14
+ border: 0.0625rem solid var(--uibit-diff-viewer-border-color);
15
+ border-radius: var(--uibit-diff-viewer-radius);
16
+ overflow: hidden;
17
+ }
18
+
19
+ .header {
20
+ display: grid;
21
+ border-bottom: 0.0625rem solid var(--uibit-diff-viewer-border-color);
22
+ }
23
+
24
+ :host([mode="split"]) .header {
25
+ grid-template-columns: 1fr 1fr;
26
+ }
27
+
28
+ :host([mode="inline"]) .header {
29
+ grid-template-columns: 1fr;
30
+ }
31
+
32
+ .header-cell {
33
+ padding: calc(0.5rem * var(--uibit-spacing-factor, 1)) calc(1rem * var(--uibit-spacing-factor, 1));
34
+ font-size: var(--uibit-font-size-xs, calc(0.75rem * var(--uibit-font-scale-factor, 1)));
35
+ font-weight: var(--uibit-font-weight-medium, 500);
36
+ color: var(--uibit-diff-viewer-label-color, #6b7280);
37
+ font-family: var(--uibit-diff-viewer-font-family, inherit);
38
+ border-right: 0.0625rem solid var(--uibit-diff-viewer-border-color, #e5e7eb);
39
+ }
40
+
41
+ .header-cell:last-child {
42
+ border-right: none;
43
+ }
44
+
45
+ .body {
46
+ display: grid;
47
+ overflow: auto;
48
+ }
49
+
50
+ :host([mode="split"]) .body {
51
+ grid-template-columns: 1fr 1fr;
52
+ }
53
+
54
+ :host([mode="inline"]) .body {
55
+ grid-template-columns: 1fr;
56
+ }
57
+
58
+ .pane {
59
+ overflow: auto;
60
+ border-right: 0.0625rem solid var(--uibit-diff-viewer-border-color, #e5e7eb);
61
+ }
62
+
63
+ .pane:last-child {
64
+ border-right: none;
65
+ }
66
+
67
+ .line {
68
+ display: flex;
69
+ min-width: max-content;
70
+ }
71
+
72
+ .gutter {
73
+ user-select: none;
74
+ min-width: calc(3rem * var(--uibit-spacing-factor, 1));
75
+ padding: 0 calc(0.75rem * var(--uibit-spacing-factor, 1));
76
+ text-align: right;
77
+ color: var(--uibit-diff-viewer-gutter-color, #d1d5db);
78
+ border-right: 0.0625rem solid var(--uibit-diff-viewer-border-color, #e5e7eb);
79
+ flex-shrink: 0;
80
+ }
81
+
82
+ .content {
83
+ padding: 0 calc(1rem * var(--uibit-spacing-factor, 1));
84
+ white-space: pre;
85
+ flex: 1;
86
+ }
87
+
88
+ .line.delete {
89
+ background: rgba(239, 68, 68, 0.06);
90
+ color: var(--uibit-diff-delete-color, #991b1b);
91
+ }
92
+
93
+ .line.delete .gutter {
94
+ color: rgba(153, 27, 27, 0.4);
95
+ }
96
+
97
+ .line.insert {
98
+ background: rgba(34, 197, 94, 0.06);
99
+ color: var(--uibit-diff-insert-color, #166534);
100
+ }
101
+
102
+ .line.insert .gutter {
103
+ color: rgba(22, 101, 52, 0.4);
104
+ }
105
+
106
+ .line.equal {
107
+ background: transparent;
108
+ color: var(--uibit-diff-viewer-equal-color, #374151);
109
+ }
110
+
111
+ .sign {
112
+ display: inline-block;
113
+ width: 1rem;
114
+ margin-right: 0.25rem;
115
+ flex-shrink: 0;
116
+ opacity: 0.5;
117
+ }
118
+
119
+ .divider {
120
+ width: 0.0625rem;
121
+ background: var(--uibit-diff-viewer-border-color, #e5e7eb);
122
+ }
123
+ `;
124
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyHxB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type DiffViewer from './diff-viewer';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'uibit-diff-viewer': DiffViewer;
5
+ }
6
+ }
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C,OAAO,CAAC,MAAM,CAAC;IACf,UAAU,qBAAqB;QAC3B,mBAAmB,EAAE,UAAU,CAAC;KACnC;CACA"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@uibit/diff-viewer",
3
+ "version": "0.1.0",
4
+ "description": "Encapsulated side-by-side or inline comparison block for two text or code snippets. Computes a line-level diff internally using LCS and renders color-coded deleted/inserted/unchanged lines with optional line numbers.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./custom-elements.json": "./custom-elements.json",
14
+ "./react": "./dist/frameworks/react/index.d.ts",
15
+ "./vue": "./dist/frameworks/vue/index.ts",
16
+ "./svelte": "./dist/frameworks/svelte/index.svelte",
17
+ "./angular": "./dist/frameworks/angular/index.ts",
18
+ "./solid": "./dist/frameworks/solid/index.d.ts",
19
+ "./astro": "./dist/frameworks/astro/index.astro",
20
+ "./qwik": "./dist/frameworks/qwik/index.tsx",
21
+ "./nuxt": "./dist/frameworks/nuxt/index.ts",
22
+ "./preact": "./dist/frameworks/preact/index.d.ts",
23
+ "./stencil": "./dist/frameworks/stencil/index.d.ts"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "package.json",
28
+ "README.md",
29
+ "LICENSE",
30
+ "custom-elements.json"
31
+ ],
32
+ "keywords": [
33
+ "diff",
34
+ "code-comparison",
35
+ "web-component",
36
+ "lit"
37
+ ],
38
+ "author": "Jonathan Rawlings",
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/Rawlings/uibit",
43
+ "directory": "packages/components/diff-viewer"
44
+ },
45
+ "dependencies": {
46
+ "@uibit/core": "0.1.0"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^20.19.43",
50
+ "lit": "^3.3.3",
51
+ "typescript": "7.0.2",
52
+ "@uibit/codegen": "0.1.0"
53
+ },
54
+ "peerDependencies": {
55
+ "lit": "^3.0.0",
56
+ "react": ">=18",
57
+ "vue": ">=3",
58
+ "svelte": ">=4 || ^5",
59
+ "@angular/core": ">=14"
60
+ },
61
+ "customElements": "custom-elements.json",
62
+ "peerDependenciesMeta": {
63
+ "react": {
64
+ "optional": true
65
+ },
66
+ "vue": {
67
+ "optional": true
68
+ },
69
+ "svelte": {
70
+ "optional": true
71
+ },
72
+ "@angular/core": {
73
+ "optional": true
74
+ }
75
+ },
76
+ "uibit": {
77
+ "id": "diff-viewer",
78
+ "title": "Diff Viewer",
79
+ "category": "Data",
80
+ "tagName": "uibit-diff-viewer"
81
+ },
82
+ "scripts": {
83
+ "build": "cem analyze --globs 'src/**/*.ts' --litelement && uibit-codegen --package . && tsc",
84
+ "dev": "concurrently \"cem analyze --globs 'src/**/*.ts' --litelement --watch\" \"tsc --watch\"",
85
+ "analyze": "cem analyze --globs 'src/**/*.ts' --litelement",
86
+ "typecheck": "tsc --noEmit"
87
+ }
88
+ }