omni-viewer-core 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 +21 -1
- package/dist/i18n/catalog.en.js +13 -0
- package/dist/i18n/catalog.ja.js +13 -1
- package/dist/i18n/catalog.ko.js +13 -0
- package/dist/i18n/catalog.zh-cn.js +10 -0
- package/dist/parsers/safetensors/index.d.ts +56 -0
- package/dist/parsers/safetensors/index.js +294 -0
- package/dist/parsers/safetensors/node.d.ts +13 -0
- package/dist/parsers/safetensors/node.js +52 -0
- package/dist/parsers/toml/model.d.ts +10 -0
- package/dist/parsers/toml/parse.js +104 -34
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.js +5 -1
- package/dist/styles/pdf.css +177 -0
- package/dist/styles/safetensors.css +3 -0
- package/dist/styles/toml.css +1 -1
- package/dist/styles/yaml.css +1 -1
- package/dist/viewers/pdf/controller.d.ts +8 -0
- package/dist/viewers/pdf/controller.js +4 -0
- package/dist/viewers/pdf/editing.d.ts +11 -0
- package/dist/viewers/pdf/editing.js +19 -16
- package/dist/viewers/pdf/index.d.ts +3 -2
- package/dist/viewers/pdf/index.js +195 -23
- package/dist/viewers/pdf/styles.d.ts +1 -1
- package/dist/viewers/pdf/styles.js +177 -0
- package/dist/viewers/safetensors/index.d.ts +27 -0
- package/dist/viewers/safetensors/index.js +198 -0
- package/dist/viewers/safetensors/styles.d.ts +1 -0
- package/dist/viewers/safetensors/styles.js +4 -0
- package/dist/viewers/structured-styles.d.ts +1 -1
- package/dist/viewers/structured-styles.js +1 -1
- package/dist/viewers/structured.d.ts +15 -0
- package/dist/viewers/structured.js +196 -47
- package/dist/viewers/toml/controller.d.ts +27 -1
- package/dist/viewers/toml/controller.js +64 -10
- package/package.json +13 -1
|
@@ -186,6 +186,17 @@ export const pdfViewerCss = `
|
|
|
186
186
|
min-width: 56px;
|
|
187
187
|
text-align: center;
|
|
188
188
|
}
|
|
189
|
+
.omni-pdf__thumbs-toggle {
|
|
190
|
+
width: 30px;
|
|
191
|
+
height: 28px;
|
|
192
|
+
padding: 0;
|
|
193
|
+
margin-right: auto;
|
|
194
|
+
font-size: 16px;
|
|
195
|
+
line-height: 1;
|
|
196
|
+
}
|
|
197
|
+
.omni-pdf__thumbs-toggle.is-collapsed {
|
|
198
|
+
opacity: 0.6;
|
|
199
|
+
}
|
|
189
200
|
.omni-pdf__view-menu-wrap { position: relative; }
|
|
190
201
|
.omni-pdf__view-menu-btn {
|
|
191
202
|
width: 30px;
|
|
@@ -230,12 +241,19 @@ export const pdfViewerCss = `
|
|
|
230
241
|
background: var(--omni-border, #3c3c3c);
|
|
231
242
|
}
|
|
232
243
|
.omni-pdf__body {
|
|
244
|
+
position: relative;
|
|
233
245
|
flex: 1;
|
|
234
246
|
min-height: 0;
|
|
235
247
|
display: grid;
|
|
236
248
|
grid-template-columns: 160px minmax(0, 1fr);
|
|
237
249
|
overflow: hidden;
|
|
238
250
|
}
|
|
251
|
+
.omni-pdf__body--thumbs-collapsed {
|
|
252
|
+
grid-template-columns: minmax(0, 1fr);
|
|
253
|
+
}
|
|
254
|
+
.omni-pdf__body--thumbs-collapsed .omni-pdf__thumbs {
|
|
255
|
+
display: none;
|
|
256
|
+
}
|
|
239
257
|
.omni-pdf__thumbs {
|
|
240
258
|
overflow: auto;
|
|
241
259
|
min-height: 0;
|
|
@@ -467,6 +485,161 @@ export const pdfViewerCss = `
|
|
|
467
485
|
content: '';
|
|
468
486
|
background: var(--omni-hl-color, #ffeb3b);
|
|
469
487
|
}
|
|
488
|
+
/* Floating action bar shown above a selected text-markup annotation. */
|
|
489
|
+
.omni-pdf__markup-toolbar {
|
|
490
|
+
position: absolute;
|
|
491
|
+
z-index: 5;
|
|
492
|
+
display: flex;
|
|
493
|
+
align-items: center;
|
|
494
|
+
gap: 2px;
|
|
495
|
+
padding: 4px;
|
|
496
|
+
transform: translateY(calc(-100% - 8px));
|
|
497
|
+
background: var(--omni-bg-secondary, #252526);
|
|
498
|
+
border: 1px solid var(--omni-border, #3c3c3c);
|
|
499
|
+
border-radius: 10px;
|
|
500
|
+
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
|
|
501
|
+
cursor: default;
|
|
502
|
+
}
|
|
503
|
+
.omni-pdf button.omni-pdf__markup-tool {
|
|
504
|
+
display: inline-flex;
|
|
505
|
+
align-items: center;
|
|
506
|
+
justify-content: center;
|
|
507
|
+
width: 30px;
|
|
508
|
+
height: 30px;
|
|
509
|
+
padding: 0;
|
|
510
|
+
border: 0;
|
|
511
|
+
border-radius: 8px;
|
|
512
|
+
background: transparent;
|
|
513
|
+
color: var(--omni-fg, #e8e8e8);
|
|
514
|
+
font-size: 15px;
|
|
515
|
+
line-height: 1;
|
|
516
|
+
cursor: pointer;
|
|
517
|
+
}
|
|
518
|
+
.omni-pdf button.omni-pdf__markup-tool:hover:not(:disabled) { background: var(--omni-button-hover-bg, #45494e); }
|
|
519
|
+
.omni-pdf button.omni-pdf__markup-tool:disabled { opacity: 0.4; cursor: default; }
|
|
520
|
+
.omni-pdf__markup-color::before {
|
|
521
|
+
content: '';
|
|
522
|
+
width: 18px;
|
|
523
|
+
height: 18px;
|
|
524
|
+
border-radius: 5px;
|
|
525
|
+
background: var(--omni-hl-color, #ffeb3b);
|
|
526
|
+
border: 1px solid rgba(0, 0, 0, 0.25);
|
|
527
|
+
}
|
|
528
|
+
.omni-pdf__markup-color-wrap { position: relative; display: inline-flex; }
|
|
529
|
+
.omni-pdf__markup-palette {
|
|
530
|
+
position: absolute;
|
|
531
|
+
top: calc(100% + 6px);
|
|
532
|
+
left: 50%;
|
|
533
|
+
transform: translateX(-50%);
|
|
534
|
+
display: none;
|
|
535
|
+
grid-template-columns: repeat(3, auto);
|
|
536
|
+
gap: 6px;
|
|
537
|
+
padding: 8px;
|
|
538
|
+
background: var(--omni-bg-secondary, #252526);
|
|
539
|
+
border: 1px solid var(--omni-border, #3c3c3c);
|
|
540
|
+
border-radius: 8px;
|
|
541
|
+
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
|
|
542
|
+
z-index: 6;
|
|
543
|
+
}
|
|
544
|
+
.omni-pdf__markup-palette.is-open { display: grid; }
|
|
545
|
+
.omni-pdf button.omni-pdf__markup-swatch,
|
|
546
|
+
.omni-pdf button.omni-pdf__markup-swatch:hover:not(:disabled) {
|
|
547
|
+
width: 22px;
|
|
548
|
+
height: 22px;
|
|
549
|
+
padding: 0;
|
|
550
|
+
border-radius: 5px;
|
|
551
|
+
border: 1px solid rgba(255, 255, 255, 0.25);
|
|
552
|
+
background: var(--omni-hl-color, #ffeb3b);
|
|
553
|
+
cursor: pointer;
|
|
554
|
+
}
|
|
555
|
+
.omni-pdf button.omni-pdf__markup-swatch.is-current {
|
|
556
|
+
outline: 2px solid var(--omni-accent, #0e639c);
|
|
557
|
+
outline-offset: 1px;
|
|
558
|
+
}
|
|
559
|
+
/* Left overlay panel listing every text-markup annotation. */
|
|
560
|
+
.omni-pdf__markup-list {
|
|
561
|
+
position: absolute;
|
|
562
|
+
top: 0;
|
|
563
|
+
left: 0;
|
|
564
|
+
bottom: 0;
|
|
565
|
+
z-index: 6;
|
|
566
|
+
display: none;
|
|
567
|
+
flex-direction: column;
|
|
568
|
+
width: min(280px, 70%);
|
|
569
|
+
background: var(--omni-bg-secondary, #252526);
|
|
570
|
+
border-right: 1px solid var(--omni-border, #3c3c3c);
|
|
571
|
+
box-shadow: 2px 0 12px rgba(0, 0, 0, 0.35);
|
|
572
|
+
overflow-y: auto;
|
|
573
|
+
}
|
|
574
|
+
.omni-pdf__markup-list.is-open { display: flex; }
|
|
575
|
+
.omni-pdf__markup-list-head {
|
|
576
|
+
position: sticky;
|
|
577
|
+
top: 0;
|
|
578
|
+
display: flex;
|
|
579
|
+
align-items: center;
|
|
580
|
+
justify-content: space-between;
|
|
581
|
+
padding: 10px 12px;
|
|
582
|
+
background: var(--omni-bg-secondary, #252526);
|
|
583
|
+
border-bottom: 1px solid var(--omni-border, #3c3c3c);
|
|
584
|
+
}
|
|
585
|
+
.omni-pdf__markup-list-title { font-weight: 600; }
|
|
586
|
+
.omni-pdf button.omni-pdf__markup-list-close {
|
|
587
|
+
width: 26px;
|
|
588
|
+
height: 26px;
|
|
589
|
+
padding: 0;
|
|
590
|
+
border: 0;
|
|
591
|
+
border-radius: 6px;
|
|
592
|
+
background: transparent;
|
|
593
|
+
color: var(--omni-fg, #e8e8e8);
|
|
594
|
+
font-size: 18px;
|
|
595
|
+
line-height: 1;
|
|
596
|
+
cursor: pointer;
|
|
597
|
+
}
|
|
598
|
+
.omni-pdf button.omni-pdf__markup-list-close:hover:not(:disabled) { background: var(--omni-button-hover-bg, #45494e); }
|
|
599
|
+
.omni-pdf__markup-list-empty {
|
|
600
|
+
padding: 16px 12px;
|
|
601
|
+
color: var(--omni-fg-muted, #9d9d9d);
|
|
602
|
+
font-size: 13px;
|
|
603
|
+
}
|
|
604
|
+
.omni-pdf button.omni-pdf__markup-item {
|
|
605
|
+
display: flex;
|
|
606
|
+
align-items: center;
|
|
607
|
+
gap: 8px;
|
|
608
|
+
width: 100%;
|
|
609
|
+
padding: 10px 12px;
|
|
610
|
+
border: 0;
|
|
611
|
+
border-bottom: 1px solid var(--omni-border, #3c3c3c);
|
|
612
|
+
background: transparent;
|
|
613
|
+
color: var(--omni-fg, #e8e8e8);
|
|
614
|
+
text-align: left;
|
|
615
|
+
cursor: pointer;
|
|
616
|
+
}
|
|
617
|
+
.omni-pdf button.omni-pdf__markup-item:hover:not(:disabled) { background: var(--omni-button-hover-bg, #45494e); }
|
|
618
|
+
.omni-pdf button.omni-pdf__markup-item.is-selected {
|
|
619
|
+
background: var(--omni-button-hover-bg, #45494e);
|
|
620
|
+
box-shadow: inset 3px 0 0 var(--omni-accent, #0e639c);
|
|
621
|
+
}
|
|
622
|
+
.omni-pdf__markup-item-dot {
|
|
623
|
+
flex: none;
|
|
624
|
+
width: 14px;
|
|
625
|
+
height: 14px;
|
|
626
|
+
border-radius: 3px;
|
|
627
|
+
border: 1px solid rgba(255, 255, 255, 0.25);
|
|
628
|
+
background: var(--omni-hl-color, #ffeb3b);
|
|
629
|
+
}
|
|
630
|
+
.omni-pdf__markup-item-text {
|
|
631
|
+
flex: 1;
|
|
632
|
+
min-width: 0;
|
|
633
|
+
overflow: hidden;
|
|
634
|
+
text-overflow: ellipsis;
|
|
635
|
+
white-space: nowrap;
|
|
636
|
+
font-size: 13px;
|
|
637
|
+
}
|
|
638
|
+
.omni-pdf__markup-item-page {
|
|
639
|
+
flex: none;
|
|
640
|
+
color: var(--omni-fg-muted, #9d9d9d);
|
|
641
|
+
font-size: 12px;
|
|
642
|
+
}
|
|
470
643
|
.omni-pdf__text-editor {
|
|
471
644
|
position: absolute;
|
|
472
645
|
z-index: 3;
|
|
@@ -572,10 +745,14 @@ export const pdfViewerCss = `
|
|
|
572
745
|
grid-template-columns: minmax(0, 1fr);
|
|
573
746
|
grid-template-rows: minmax(120px, 30vh) minmax(0, 1fr);
|
|
574
747
|
}
|
|
748
|
+
.omni-pdf__body--thumbs-collapsed {
|
|
749
|
+
grid-template-rows: minmax(0, 1fr);
|
|
750
|
+
}
|
|
575
751
|
.omni-pdf__thumbs {
|
|
576
752
|
border-right: 0;
|
|
577
753
|
border-bottom: 1px solid var(--omni-border, #3c3c3c);
|
|
578
754
|
}
|
|
579
755
|
.omni-pdf__pages { grid-row: 2; }
|
|
756
|
+
.omni-pdf__body--thumbs-collapsed .omni-pdf__pages { grid-row: 1; }
|
|
580
757
|
}
|
|
581
758
|
`;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ClipboardService, HostContext } from '../../host/index.js';
|
|
2
|
+
import { type SafetensorsDocument, type SafetensorsSource } from '../../parsers/safetensors/index.js';
|
|
3
|
+
import { type MountOptions, type ViewerHandle, type ViewerInput } from '../types.js';
|
|
4
|
+
export { safetensorsViewerCss } from './styles.js';
|
|
5
|
+
export declare const SAFETENSORS_VIEWER_META: {
|
|
6
|
+
id: string;
|
|
7
|
+
displayNameKey: string;
|
|
8
|
+
extensions: string[];
|
|
9
|
+
priority: number;
|
|
10
|
+
requiredServices: readonly [];
|
|
11
|
+
optionalServices: readonly ["clipboard"];
|
|
12
|
+
inputOwnership: "borrows";
|
|
13
|
+
};
|
|
14
|
+
export type SafetensorsViewerContext = HostContext & {
|
|
15
|
+
clipboard?: ClipboardService;
|
|
16
|
+
};
|
|
17
|
+
/** Lazy input used by large-file hosts to avoid materializing tensor payloads. */
|
|
18
|
+
export interface SafetensorsViewerSource extends SafetensorsSource {
|
|
19
|
+
fileName: string;
|
|
20
|
+
lastModified?: number;
|
|
21
|
+
}
|
|
22
|
+
/** Creates a lazy safetensors input backed by browser `Blob.slice()` range reads. */
|
|
23
|
+
export declare function createSafetensorsBlobSource(blob: Blob, fileName?: string): SafetensorsViewerSource;
|
|
24
|
+
export declare function mountSafetensorsViewer(input: ViewerInput, container: HTMLElement, ctx: SafetensorsViewerContext, options?: MountOptions): Promise<ViewerHandle>;
|
|
25
|
+
export declare function mountSafetensorsViewer(input: SafetensorsViewerSource, container: HTMLElement, ctx: SafetensorsViewerContext, options?: MountOptions): Promise<ViewerHandle>;
|
|
26
|
+
/** Mount a pre-parsed model, allowing Node adapters to retain random-access parsing. */
|
|
27
|
+
export declare function mountSafetensorsDocument(document: SafetensorsDocument, fileName: string, container: HTMLElement, ctx: SafetensorsViewerContext, options?: MountOptions): ViewerHandle;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { parseSafetensors, parseSafetensorsSource } from '../../parsers/safetensors/index.js';
|
|
2
|
+
import { MountAbortedError, VIEWER_ROOT_CLASS } from '../types.js';
|
|
3
|
+
import { safetensorsViewerCss } from './styles.js';
|
|
4
|
+
export { safetensorsViewerCss } from './styles.js';
|
|
5
|
+
export const SAFETENSORS_VIEWER_META = {
|
|
6
|
+
id: 'safetensors',
|
|
7
|
+
displayNameKey: 'safetensors.title',
|
|
8
|
+
extensions: ['safetensors'],
|
|
9
|
+
priority: 20,
|
|
10
|
+
requiredServices: [],
|
|
11
|
+
optionalServices: ['clipboard'],
|
|
12
|
+
inputOwnership: 'borrows'
|
|
13
|
+
};
|
|
14
|
+
/** Creates a lazy safetensors input backed by browser `Blob.slice()` range reads. */
|
|
15
|
+
export function createSafetensorsBlobSource(blob, fileName = 'model.safetensors') {
|
|
16
|
+
return {
|
|
17
|
+
fileName,
|
|
18
|
+
size: blob.size,
|
|
19
|
+
async read(offset, length, signal) {
|
|
20
|
+
throwIfAborted(signal);
|
|
21
|
+
const bytes = new Uint8Array(await blob.slice(offset, offset + length).arrayBuffer());
|
|
22
|
+
throwIfAborted(signal);
|
|
23
|
+
return bytes;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export async function mountSafetensorsViewer(input, container, ctx, options = {}) {
|
|
28
|
+
if (options.signal?.aborted)
|
|
29
|
+
throw new MountAbortedError();
|
|
30
|
+
let document;
|
|
31
|
+
try {
|
|
32
|
+
document = 'data' in input
|
|
33
|
+
? parseSafetensors(input.data)
|
|
34
|
+
: await parseSafetensorsSource(input, { ...(options.signal ? { signal: options.signal } : {}) });
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (options.signal?.aborted)
|
|
38
|
+
throw new MountAbortedError();
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
if (options.signal?.aborted)
|
|
42
|
+
throw new MountAbortedError();
|
|
43
|
+
return mountSafetensorsDocument(document, input.fileName, container, ctx, options);
|
|
44
|
+
}
|
|
45
|
+
/** Mount a pre-parsed model, allowing Node adapters to retain random-access parsing. */
|
|
46
|
+
export function mountSafetensorsDocument(document, fileName, container, ctx, options = {}) {
|
|
47
|
+
if (options.signal?.aborted)
|
|
48
|
+
throw new MountAbortedError();
|
|
49
|
+
let root = container;
|
|
50
|
+
let injectedStyle;
|
|
51
|
+
if ((options.styleIsolation ?? 'shadow') === 'shadow' && container.attachShadow) {
|
|
52
|
+
root = container.shadowRoot ?? container.attachShadow({ mode: 'open' });
|
|
53
|
+
const style = element('style');
|
|
54
|
+
style.textContent = safetensorsViewerCss;
|
|
55
|
+
root.append(style);
|
|
56
|
+
injectedStyle = style;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
container.classList.add(VIEWER_ROOT_CLASS, 'omni-viewer--safetensors');
|
|
60
|
+
}
|
|
61
|
+
const frame = element('div', 'omni-safetensors');
|
|
62
|
+
const header = element('header', 'omni-safetensors__header');
|
|
63
|
+
const heading = element('div');
|
|
64
|
+
heading.append(element('div', 'omni-safetensors__eyebrow', document.format), element('h1', undefined, fileName), element('div', 'omni-safetensors__subtitle', `${document.title} · ${document.fileSize}`));
|
|
65
|
+
header.append(heading);
|
|
66
|
+
const summary = element('section', 'omni-safetensors__summary');
|
|
67
|
+
for (const item of document.summary) {
|
|
68
|
+
const card = element('div', 'omni-safetensors__summary-item');
|
|
69
|
+
card.append(element('div', 'omni-safetensors__summary-value', String(item.value)), element('div', 'omni-safetensors__summary-label', item.label));
|
|
70
|
+
summary.append(card);
|
|
71
|
+
}
|
|
72
|
+
const toolbar = element('div', 'omni-safetensors__toolbar');
|
|
73
|
+
const search = element('input', 'omni-safetensors__search');
|
|
74
|
+
search.type = 'search';
|
|
75
|
+
search.placeholder = ctx.i18n.t('safetensors.search');
|
|
76
|
+
search.setAttribute('aria-label', ctx.i18n.t('safetensors.search'));
|
|
77
|
+
const tabs = element('div', 'omni-safetensors__tabs');
|
|
78
|
+
const copy = element('button', undefined, ctx.i18n.t('safetensors.copyJson'));
|
|
79
|
+
copy.type = 'button';
|
|
80
|
+
if (!ctx.clipboard) {
|
|
81
|
+
copy.disabled = true;
|
|
82
|
+
copy.title = ctx.i18n.t('common.noClipboard');
|
|
83
|
+
}
|
|
84
|
+
toolbar.append(search, tabs, copy);
|
|
85
|
+
const warnings = element('section', 'omni-safetensors__warnings');
|
|
86
|
+
warnings.setAttribute('role', 'status');
|
|
87
|
+
for (const warning of document.warnings)
|
|
88
|
+
warnings.append(element('div', undefined, warning));
|
|
89
|
+
if (document.warnings.length === 0)
|
|
90
|
+
warnings.hidden = true;
|
|
91
|
+
const content = element('main', 'omni-safetensors__content');
|
|
92
|
+
frame.append(header, summary, toolbar, warnings, content);
|
|
93
|
+
root.append(frame);
|
|
94
|
+
let activeTab = 0;
|
|
95
|
+
let raw = false;
|
|
96
|
+
let copyResetTimer;
|
|
97
|
+
const disposers = [];
|
|
98
|
+
const on = (target, type, listener) => {
|
|
99
|
+
target.addEventListener(type, listener);
|
|
100
|
+
disposers.push(() => target.removeEventListener(type, listener));
|
|
101
|
+
};
|
|
102
|
+
const renderTabs = () => {
|
|
103
|
+
tabs.replaceChildren();
|
|
104
|
+
document.tables.forEach((table, index) => {
|
|
105
|
+
const button = element('button', undefined, table.title);
|
|
106
|
+
button.type = 'button';
|
|
107
|
+
button.setAttribute('aria-pressed', String(!raw && activeTab === index));
|
|
108
|
+
button.onclick = () => { activeTab = index; raw = false; renderTabs(); renderContent(); };
|
|
109
|
+
tabs.append(button);
|
|
110
|
+
});
|
|
111
|
+
if (document.rawPreview) {
|
|
112
|
+
const button = element('button', undefined, ctx.i18n.t('safetensors.structure'));
|
|
113
|
+
button.type = 'button';
|
|
114
|
+
button.setAttribute('aria-pressed', String(raw));
|
|
115
|
+
button.onclick = () => { raw = true; renderTabs(); renderContent(); };
|
|
116
|
+
tabs.append(button);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const matchingRows = (table) => {
|
|
120
|
+
const query = search.value.trim().toLowerCase();
|
|
121
|
+
if (!query)
|
|
122
|
+
return table.rows;
|
|
123
|
+
return table.rows.filter(row => row.some(cell => String(cell).toLowerCase().includes(query)));
|
|
124
|
+
};
|
|
125
|
+
const renderContent = () => {
|
|
126
|
+
content.replaceChildren();
|
|
127
|
+
if (raw) {
|
|
128
|
+
content.append(element('pre', undefined, document.rawPreview ?? ''));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const table = document.tables[activeTab];
|
|
132
|
+
if (!table) {
|
|
133
|
+
content.append(element('div', 'omni-safetensors__empty', ctx.i18n.t('safetensors.noData')));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const rows = matchingRows(table);
|
|
137
|
+
const visible = rows.slice(0, 1000);
|
|
138
|
+
const panelHeader = element('div', 'omni-safetensors__panel-header');
|
|
139
|
+
panelHeader.append(element('h2', undefined, table.title), element('span', undefined, ctx.i18n.t(rows.length > visible.length ? 'safetensors.matchingRowsLimited' : 'safetensors.matchingRows', rows.length > visible.length ? { visible: visible.length, total: rows.length } : { count: rows.length })));
|
|
140
|
+
const wrap = element('div', 'omni-safetensors__table-wrap');
|
|
141
|
+
const tableElement = element('table');
|
|
142
|
+
const head = element('thead');
|
|
143
|
+
const headerRow = element('tr');
|
|
144
|
+
for (const label of table.headers)
|
|
145
|
+
headerRow.append(element('th', undefined, label));
|
|
146
|
+
head.append(headerRow);
|
|
147
|
+
const body = element('tbody');
|
|
148
|
+
for (const row of visible) {
|
|
149
|
+
const tr = element('tr');
|
|
150
|
+
for (const cell of row) {
|
|
151
|
+
const value = String(cell);
|
|
152
|
+
const td = element('td', undefined, value);
|
|
153
|
+
td.title = value;
|
|
154
|
+
tr.append(td);
|
|
155
|
+
}
|
|
156
|
+
body.append(tr);
|
|
157
|
+
}
|
|
158
|
+
tableElement.append(head, body);
|
|
159
|
+
wrap.append(tableElement);
|
|
160
|
+
content.append(panelHeader, wrap);
|
|
161
|
+
};
|
|
162
|
+
on(search, 'input', () => renderContent());
|
|
163
|
+
on(copy, 'click', () => {
|
|
164
|
+
if (!ctx.clipboard)
|
|
165
|
+
return;
|
|
166
|
+
void ctx.clipboard.writeText(JSON.stringify(document, null, 2));
|
|
167
|
+
copy.textContent = ctx.i18n.t('common.copied');
|
|
168
|
+
if (copyResetTimer !== undefined)
|
|
169
|
+
clearTimeout(copyResetTimer);
|
|
170
|
+
copyResetTimer = setTimeout(() => { copy.textContent = ctx.i18n.t('safetensors.copyJson'); }, 1200);
|
|
171
|
+
});
|
|
172
|
+
renderTabs();
|
|
173
|
+
renderContent();
|
|
174
|
+
return {
|
|
175
|
+
dispose() {
|
|
176
|
+
if (copyResetTimer !== undefined)
|
|
177
|
+
clearTimeout(copyResetTimer);
|
|
178
|
+
disposers.splice(0).forEach(dispose => dispose());
|
|
179
|
+
frame.remove();
|
|
180
|
+
injectedStyle?.remove();
|
|
181
|
+
if (!(root instanceof ShadowRoot))
|
|
182
|
+
container.classList.remove(VIEWER_ROOT_CLASS, 'omni-viewer--safetensors');
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function element(tag, className, text) {
|
|
187
|
+
const node = document.createElement(tag);
|
|
188
|
+
if (className)
|
|
189
|
+
node.className = className;
|
|
190
|
+
if (text !== undefined)
|
|
191
|
+
node.textContent = text;
|
|
192
|
+
return node;
|
|
193
|
+
}
|
|
194
|
+
function throwIfAborted(signal) {
|
|
195
|
+
if (!signal?.aborted)
|
|
196
|
+
return;
|
|
197
|
+
throw signal.reason ?? new DOMException('The operation was aborted.', 'AbortError');
|
|
198
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const safetensorsViewerCss = "\n.omni-safetensors{height:100%;min-height:0;display:flex;flex-direction:column;background:var(--omni-bg,#fff);color:var(--omni-fg,#222);font:13px system-ui,sans-serif}.omni-safetensors__header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;padding:18px 20px 12px;border-bottom:1px solid var(--omni-border,#ddd);background:var(--omni-panel-bg,#f7f7f7)}.omni-safetensors__eyebrow{color:var(--omni-muted,#666);font-size:12px;text-transform:uppercase}.omni-safetensors h1{margin:2px 0 4px;font-size:20px}.omni-safetensors__subtitle{color:var(--omni-muted,#666);font-size:12px}.omni-safetensors__summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:1px;background:var(--omni-border,#ddd);border-bottom:1px solid var(--omni-border,#ddd)}.omni-safetensors__summary-item{min-height:64px;padding:12px 14px;background:var(--omni-bg,#fff)}.omni-safetensors__summary-value{font-size:20px;font-weight:650}.omni-safetensors__summary-label{margin-top:4px;color:var(--omni-muted,#666);font-size:12px}.omni-safetensors__toolbar{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--omni-border,#ddd);background:var(--omni-toolbar-bg,#f5f5f5)}.omni-safetensors__search{width:min(320px,36vw);min-width:180px;border:1px solid var(--omni-border,#ccc);background:var(--omni-input-bg,#fff);color:inherit;padding:7px 9px;border-radius:4px}.omni-safetensors__tabs{display:flex;flex-wrap:wrap;gap:4px;flex:1}.omni-safetensors button{border:1px solid var(--omni-border,#ccc);border-radius:4px;background:var(--omni-button-bg,#eee);color:inherit;cursor:pointer;padding:7px 10px}.omni-safetensors button:hover{background:var(--omni-hover,#e5e5e5)}.omni-safetensors button[aria-pressed=true]{background:var(--omni-accent,#0e639c);color:var(--omni-accent-fg,#fff)}.omni-safetensors button:disabled{opacity:.5;cursor:default}.omni-safetensors__warnings{padding:10px 14px;border-bottom:1px solid var(--omni-border,#ddd);background:var(--omni-warning-bg,#fff4ce);color:var(--omni-warning-fg,#5f4700)}.omni-safetensors__content{min-height:0;flex:1;overflow:auto}.omni-safetensors__panel-header{position:sticky;top:0;z-index:1;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 14px;border-bottom:1px solid var(--omni-border,#ddd);background:var(--omni-bg,#fff)}.omni-safetensors__panel-header h2{margin:0;font-size:15px}.omni-safetensors__panel-header span{color:var(--omni-muted,#666);font-size:12px}.omni-safetensors__table-wrap{overflow:auto}.omni-safetensors table{width:100%;border-collapse:collapse}.omni-safetensors th,.omni-safetensors td{border-bottom:1px solid var(--omni-border,#ddd);padding:7px 9px;text-align:left;vertical-align:top;white-space:nowrap}.omni-safetensors th{background:var(--omni-header-bg,#f5f5f5);font-weight:650}.omni-safetensors td{max-width:520px;overflow:hidden;text-overflow:ellipsis}.omni-safetensors tr:hover td{background:var(--omni-hover,#f4f4f4)}.omni-safetensors pre{margin:0;padding:14px;font:13px/1.45 ui-monospace,SFMono-Regular,Consolas,monospace;white-space:pre-wrap}.omni-safetensors__empty{padding:24px;color:var(--omni-muted,#666)}\n@media(max-width:720px){.omni-safetensors__header,.omni-safetensors__toolbar{align-items:stretch;flex-direction:column}.omni-safetensors__search{width:auto}}\n";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const safetensorsViewerCss = `
|
|
2
|
+
.omni-safetensors{height:100%;min-height:0;display:flex;flex-direction:column;background:var(--omni-bg,#fff);color:var(--omni-fg,#222);font:13px system-ui,sans-serif}.omni-safetensors__header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;padding:18px 20px 12px;border-bottom:1px solid var(--omni-border,#ddd);background:var(--omni-panel-bg,#f7f7f7)}.omni-safetensors__eyebrow{color:var(--omni-muted,#666);font-size:12px;text-transform:uppercase}.omni-safetensors h1{margin:2px 0 4px;font-size:20px}.omni-safetensors__subtitle{color:var(--omni-muted,#666);font-size:12px}.omni-safetensors__summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:1px;background:var(--omni-border,#ddd);border-bottom:1px solid var(--omni-border,#ddd)}.omni-safetensors__summary-item{min-height:64px;padding:12px 14px;background:var(--omni-bg,#fff)}.omni-safetensors__summary-value{font-size:20px;font-weight:650}.omni-safetensors__summary-label{margin-top:4px;color:var(--omni-muted,#666);font-size:12px}.omni-safetensors__toolbar{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--omni-border,#ddd);background:var(--omni-toolbar-bg,#f5f5f5)}.omni-safetensors__search{width:min(320px,36vw);min-width:180px;border:1px solid var(--omni-border,#ccc);background:var(--omni-input-bg,#fff);color:inherit;padding:7px 9px;border-radius:4px}.omni-safetensors__tabs{display:flex;flex-wrap:wrap;gap:4px;flex:1}.omni-safetensors button{border:1px solid var(--omni-border,#ccc);border-radius:4px;background:var(--omni-button-bg,#eee);color:inherit;cursor:pointer;padding:7px 10px}.omni-safetensors button:hover{background:var(--omni-hover,#e5e5e5)}.omni-safetensors button[aria-pressed=true]{background:var(--omni-accent,#0e639c);color:var(--omni-accent-fg,#fff)}.omni-safetensors button:disabled{opacity:.5;cursor:default}.omni-safetensors__warnings{padding:10px 14px;border-bottom:1px solid var(--omni-border,#ddd);background:var(--omni-warning-bg,#fff4ce);color:var(--omni-warning-fg,#5f4700)}.omni-safetensors__content{min-height:0;flex:1;overflow:auto}.omni-safetensors__panel-header{position:sticky;top:0;z-index:1;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 14px;border-bottom:1px solid var(--omni-border,#ddd);background:var(--omni-bg,#fff)}.omni-safetensors__panel-header h2{margin:0;font-size:15px}.omni-safetensors__panel-header span{color:var(--omni-muted,#666);font-size:12px}.omni-safetensors__table-wrap{overflow:auto}.omni-safetensors table{width:100%;border-collapse:collapse}.omni-safetensors th,.omni-safetensors td{border-bottom:1px solid var(--omni-border,#ddd);padding:7px 9px;text-align:left;vertical-align:top;white-space:nowrap}.omni-safetensors th{background:var(--omni-header-bg,#f5f5f5);font-weight:650}.omni-safetensors td{max-width:520px;overflow:hidden;text-overflow:ellipsis}.omni-safetensors tr:hover td{background:var(--omni-hover,#f4f4f4)}.omni-safetensors pre{margin:0;padding:14px;font:13px/1.45 ui-monospace,SFMono-Regular,Consolas,monospace;white-space:pre-wrap}.omni-safetensors__empty{padding:24px;color:var(--omni-muted,#666)}
|
|
3
|
+
@media(max-width:720px){.omni-safetensors__header,.omni-safetensors__toolbar{align-items:stretch;flex-direction:column}.omni-safetensors__search{width:auto}}
|
|
4
|
+
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const structuredViewerCss = ":host,.omni-viewer--toml,.omni-viewer--yaml{display:block;height:100%;color:var(--omni-fg,#ddd);background:var(--omni-bg,#1e1e1e);font:13px var(--omni-font,system-ui)}.omni-structured{height:100%;display:flex;flex-direction:column;box-sizing:border-box}.omni-structured__bar{display:flex;gap:5px;align-items:center;padding:6px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured button,.omni-structured input,.omni-structured select{font:inherit;background:var(--omni-button-bg,#333);color:inherit;border:1px solid var(--omni-border,#555);border-radius:3px;padding:3px 7px}.omni-structured button:disabled{opacity:.5}.omni-structured__search{min-width:180px}.omni-structured__diagnostics{white-space:pre-wrap;color:var(--omni-error,#f48771);padding:6px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured__workspace{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:12px;flex:1;min-height:0;padding:12px}.omni-structured__pane{display:flex;flex-direction:column;min-width:0;min-height:0;border:1px solid var(--omni-border,#444);border-radius:8px;overflow:hidden;background:var(--omni-input-bg,#171717)}.omni-structured__pane-header{display:flex;justify-content:space-between;gap:12px;padding:10px 12px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured__pane-header span{color:var(--omni-fg-muted,#999)}.omni-structured__editor,.omni-structured__tree{box-sizing:border-box;flex:1;min-height:0;padding:10px;background:transparent;color:inherit;font:inherit;font-family:var(--omni-font-mono,ui-monospace,monospace)}.omni-structured__editor{resize:none;border:0;outline:none;line-height:1.5;white-space:pre;overflow:auto}.omni-structured__source-surface{position:relative;flex:1;min-height:0;overflow:hidden}.omni-structured__source-highlight{position:absolute;inset:0;box-sizing:border-box;margin:0;padding:10px;overflow:auto;pointer-events:none;font:inherit;font-family:var(--omni-font-mono,ui-monospace,monospace);line-height:1.5;white-space:pre}.omni-structured__pane--highlighted-source .omni-structured__editor{position:relative;z-index:1;width:100%;height:100%;padding:10px;color:transparent;caret-color:var(--omni-fg,#ddd);-webkit-text-fill-color:transparent}.omni-structured__source-key{color:#9cdcfe}.omni-structured__source-value{color:#ce9178}.omni-structured__source-table{color:#c586c0}.omni-structured__source-comment{color:var(--omni-fg-muted,#999)}.omni-structured__tree{overflow:auto}.omni-structured__preview-body{position:relative;flex:1;min-height:200px}.omni-structured__preview-body>.omni-structured__tree,.omni-structured__preview-body>.omni-structured__json-preview,.omni-structured__preview-body>.omni-structured__raw-preview{position:absolute;inset:0}.omni-structured__node{display:flex;gap:6px;align-items:baseline;min-height:25px}.omni-structured__toggle{width:24px;padding:0!important;border:0!important;background:transparent!important}.omni-structured__key{color:var(--omni-accent,#5aa9e6)}.omni-structured__kind{color:var(--omni-fg-muted,#999)}.omni-structured__value{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.omni-structured__actions{margin-left:auto;display:flex;gap:4px;opacity:0}.omni-structured__node:hover .omni-structured__actions,.omni-structured__actions:focus-within{opacity:1}.omni-structured__raw-preview,.omni-structured__json-preview{flex:1;min-height:0;margin:0;padding:10px;overflow:auto;font-family:var(--omni-font-mono,ui-monospace,monospace);line-height:1.5}.omni-structured__flat-row .omni-structured__key{flex-shrink:0}@media(max-width:720px){.omni-structured__workspace{grid-template-columns:1fr;overflow:auto}.omni-structured__pane{min-height:320px}}";
|
|
1
|
+
export declare const structuredViewerCss = ":host,.omni-viewer--toml,.omni-viewer--yaml{display:block;height:100%;color:var(--omni-fg,#ddd);background:var(--omni-bg,#1e1e1e);font:13px var(--omni-font,system-ui)}.omni-structured{height:100%;display:flex;flex-direction:column;box-sizing:border-box}.omni-structured__bar{display:flex;gap:5px;align-items:center;padding:6px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured button,.omni-structured input,.omni-structured select{font:inherit;background:var(--omni-button-bg,#333);color:inherit;border:1px solid var(--omni-border,#555);border-radius:3px;padding:3px 7px}.omni-structured button:disabled{opacity:.5}.omni-structured__search{min-width:180px}.omni-structured__diagnostics{white-space:pre-wrap;color:var(--omni-error,#f48771);padding:6px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured__workspace{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:12px;flex:1;min-height:0;padding:12px}.omni-structured__pane{display:flex;flex-direction:column;min-width:0;min-height:0;border:1px solid var(--omni-border,#444);border-radius:8px;overflow:hidden;background:var(--omni-input-bg,#171717)}.omni-structured__pane-header{display:flex;justify-content:space-between;gap:12px;padding:10px 12px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured__pane-header span{color:var(--omni-fg-muted,#999)}.omni-structured__editor,.omni-structured__tree{box-sizing:border-box;flex:1;min-height:0;padding:10px;background:transparent;color:inherit;font:inherit;font-family:var(--omni-font-mono,ui-monospace,monospace)}.omni-structured__editor{resize:none;border:0;outline:none;line-height:1.5;white-space:pre;overflow:auto}.omni-structured__source-surface{position:relative;flex:1;min-height:0;overflow:hidden}.omni-structured__source-highlight{position:absolute;inset:0;box-sizing:border-box;margin:0;padding:10px;overflow:auto;pointer-events:none;font:inherit;font-family:var(--omni-font-mono,ui-monospace,monospace);line-height:1.5;white-space:pre}.omni-structured__pane--highlighted-source .omni-structured__editor{position:relative;z-index:1;width:100%;height:100%;padding:10px;color:transparent;caret-color:var(--omni-fg,#ddd);-webkit-text-fill-color:transparent}.omni-structured__source-key{color:#9cdcfe}.omni-structured__source-value{color:#ce9178}.omni-structured__source-table{color:#c586c0}.omni-structured__source-comment{color:var(--omni-fg-muted,#999)}.omni-structured__tree{overflow:auto}.omni-structured__preview-body{position:relative;flex:1;min-height:200px}.omni-structured__preview-body>.omni-structured__tree,.omni-structured__preview-body>.omni-structured__json-preview,.omni-structured__preview-body>.omni-structured__raw-preview{position:absolute;inset:0}.omni-structured__node{display:flex;gap:6px;align-items:baseline;min-height:25px}.omni-structured__toggle{width:24px;padding:0!important;border:0!important;background:transparent!important}.omni-structured__key{color:var(--omni-accent,#5aa9e6)}.omni-structured__kind{color:var(--omni-fg-muted,#999)}.omni-structured__value{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.omni-structured__actions{margin-left:auto;display:flex;gap:4px;opacity:0}.omni-structured__node:hover .omni-structured__actions,.omni-structured__actions:focus-within{opacity:1}.omni-structured__raw-preview,.omni-structured__json-preview{flex:1;min-height:0;margin:0;padding:10px;overflow:auto;font-family:var(--omni-font-mono,ui-monospace,monospace);line-height:1.5}.omni-structured__flat-row .omni-structured__key{flex-shrink:0}.omni-structured__status{margin-left:auto;color:var(--omni-fg-muted,#999);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.omni-structured__node-comment{color:var(--omni-fg-muted,#999);font-style:italic;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.omni-structured__node--interactive{cursor:pointer;border-radius:3px}.omni-structured__node--interactive:hover{background:var(--omni-hover-bg,#2a2a2a)}.omni-structured__node--selected{background:var(--omni-selection-bg,#0a3a5e);outline:1px solid var(--omni-accent,#5aa9e6)}@media(max-width:720px){.omni-structured__workspace{grid-template-columns:1fr;overflow:auto}.omni-structured__pane{min-height:320px}}";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const structuredViewerCss = `:host,.omni-viewer--toml,.omni-viewer--yaml{display:block;height:100%;color:var(--omni-fg,#ddd);background:var(--omni-bg,#1e1e1e);font:13px var(--omni-font,system-ui)}.omni-structured{height:100%;display:flex;flex-direction:column;box-sizing:border-box}.omni-structured__bar{display:flex;gap:5px;align-items:center;padding:6px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured button,.omni-structured input,.omni-structured select{font:inherit;background:var(--omni-button-bg,#333);color:inherit;border:1px solid var(--omni-border,#555);border-radius:3px;padding:3px 7px}.omni-structured button:disabled{opacity:.5}.omni-structured__search{min-width:180px}.omni-structured__diagnostics{white-space:pre-wrap;color:var(--omni-error,#f48771);padding:6px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured__workspace{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:12px;flex:1;min-height:0;padding:12px}.omni-structured__pane{display:flex;flex-direction:column;min-width:0;min-height:0;border:1px solid var(--omni-border,#444);border-radius:8px;overflow:hidden;background:var(--omni-input-bg,#171717)}.omni-structured__pane-header{display:flex;justify-content:space-between;gap:12px;padding:10px 12px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured__pane-header span{color:var(--omni-fg-muted,#999)}.omni-structured__editor,.omni-structured__tree{box-sizing:border-box;flex:1;min-height:0;padding:10px;background:transparent;color:inherit;font:inherit;font-family:var(--omni-font-mono,ui-monospace,monospace)}.omni-structured__editor{resize:none;border:0;outline:none;line-height:1.5;white-space:pre;overflow:auto}.omni-structured__source-surface{position:relative;flex:1;min-height:0;overflow:hidden}.omni-structured__source-highlight{position:absolute;inset:0;box-sizing:border-box;margin:0;padding:10px;overflow:auto;pointer-events:none;font:inherit;font-family:var(--omni-font-mono,ui-monospace,monospace);line-height:1.5;white-space:pre}.omni-structured__pane--highlighted-source .omni-structured__editor{position:relative;z-index:1;width:100%;height:100%;padding:10px;color:transparent;caret-color:var(--omni-fg,#ddd);-webkit-text-fill-color:transparent}.omni-structured__source-key{color:#9cdcfe}.omni-structured__source-value{color:#ce9178}.omni-structured__source-table{color:#c586c0}.omni-structured__source-comment{color:var(--omni-fg-muted,#999)}.omni-structured__tree{overflow:auto}.omni-structured__preview-body{position:relative;flex:1;min-height:200px}.omni-structured__preview-body>.omni-structured__tree,.omni-structured__preview-body>.omni-structured__json-preview,.omni-structured__preview-body>.omni-structured__raw-preview{position:absolute;inset:0}.omni-structured__node{display:flex;gap:6px;align-items:baseline;min-height:25px}.omni-structured__toggle{width:24px;padding:0!important;border:0!important;background:transparent!important}.omni-structured__key{color:var(--omni-accent,#5aa9e6)}.omni-structured__kind{color:var(--omni-fg-muted,#999)}.omni-structured__value{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.omni-structured__actions{margin-left:auto;display:flex;gap:4px;opacity:0}.omni-structured__node:hover .omni-structured__actions,.omni-structured__actions:focus-within{opacity:1}.omni-structured__raw-preview,.omni-structured__json-preview{flex:1;min-height:0;margin:0;padding:10px;overflow:auto;font-family:var(--omni-font-mono,ui-monospace,monospace);line-height:1.5}.omni-structured__flat-row .omni-structured__key{flex-shrink:0}@media(max-width:720px){.omni-structured__workspace{grid-template-columns:1fr;overflow:auto}.omni-structured__pane{min-height:320px}}`;
|
|
1
|
+
export const structuredViewerCss = `:host,.omni-viewer--toml,.omni-viewer--yaml{display:block;height:100%;color:var(--omni-fg,#ddd);background:var(--omni-bg,#1e1e1e);font:13px var(--omni-font,system-ui)}.omni-structured{height:100%;display:flex;flex-direction:column;box-sizing:border-box}.omni-structured__bar{display:flex;gap:5px;align-items:center;padding:6px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured button,.omni-structured input,.omni-structured select{font:inherit;background:var(--omni-button-bg,#333);color:inherit;border:1px solid var(--omni-border,#555);border-radius:3px;padding:3px 7px}.omni-structured button:disabled{opacity:.5}.omni-structured__search{min-width:180px}.omni-structured__diagnostics{white-space:pre-wrap;color:var(--omni-error,#f48771);padding:6px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured__workspace{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:12px;flex:1;min-height:0;padding:12px}.omni-structured__pane{display:flex;flex-direction:column;min-width:0;min-height:0;border:1px solid var(--omni-border,#444);border-radius:8px;overflow:hidden;background:var(--omni-input-bg,#171717)}.omni-structured__pane-header{display:flex;justify-content:space-between;gap:12px;padding:10px 12px;border-bottom:1px solid var(--omni-border,#444)}.omni-structured__pane-header span{color:var(--omni-fg-muted,#999)}.omni-structured__editor,.omni-structured__tree{box-sizing:border-box;flex:1;min-height:0;padding:10px;background:transparent;color:inherit;font:inherit;font-family:var(--omni-font-mono,ui-monospace,monospace)}.omni-structured__editor{resize:none;border:0;outline:none;line-height:1.5;white-space:pre;overflow:auto}.omni-structured__source-surface{position:relative;flex:1;min-height:0;overflow:hidden}.omni-structured__source-highlight{position:absolute;inset:0;box-sizing:border-box;margin:0;padding:10px;overflow:auto;pointer-events:none;font:inherit;font-family:var(--omni-font-mono,ui-monospace,monospace);line-height:1.5;white-space:pre}.omni-structured__pane--highlighted-source .omni-structured__editor{position:relative;z-index:1;width:100%;height:100%;padding:10px;color:transparent;caret-color:var(--omni-fg,#ddd);-webkit-text-fill-color:transparent}.omni-structured__source-key{color:#9cdcfe}.omni-structured__source-value{color:#ce9178}.omni-structured__source-table{color:#c586c0}.omni-structured__source-comment{color:var(--omni-fg-muted,#999)}.omni-structured__tree{overflow:auto}.omni-structured__preview-body{position:relative;flex:1;min-height:200px}.omni-structured__preview-body>.omni-structured__tree,.omni-structured__preview-body>.omni-structured__json-preview,.omni-structured__preview-body>.omni-structured__raw-preview{position:absolute;inset:0}.omni-structured__node{display:flex;gap:6px;align-items:baseline;min-height:25px}.omni-structured__toggle{width:24px;padding:0!important;border:0!important;background:transparent!important}.omni-structured__key{color:var(--omni-accent,#5aa9e6)}.omni-structured__kind{color:var(--omni-fg-muted,#999)}.omni-structured__value{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.omni-structured__actions{margin-left:auto;display:flex;gap:4px;opacity:0}.omni-structured__node:hover .omni-structured__actions,.omni-structured__actions:focus-within{opacity:1}.omni-structured__raw-preview,.omni-structured__json-preview{flex:1;min-height:0;margin:0;padding:10px;overflow:auto;font-family:var(--omni-font-mono,ui-monospace,monospace);line-height:1.5}.omni-structured__flat-row .omni-structured__key{flex-shrink:0}.omni-structured__status{margin-left:auto;color:var(--omni-fg-muted,#999);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.omni-structured__node-comment{color:var(--omni-fg-muted,#999);font-style:italic;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.omni-structured__node--interactive{cursor:pointer;border-radius:3px}.omni-structured__node--interactive:hover{background:var(--omni-hover-bg,#2a2a2a)}.omni-structured__node--selected{background:var(--omni-selection-bg,#0a3a5e);outline:1px solid var(--omni-accent,#5aa9e6)}@media(max-width:720px){.omni-structured__workspace{grid-template-columns:1fr;overflow:auto}.omni-structured__pane{min-height:320px}}`;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { ClipboardService, FileSaveService, FileWritebackService, HostContext } from '../host/index.js';
|
|
2
2
|
import { type MountOptions, type ViewerHandle, type ViewerInput } from './types.js';
|
|
3
|
+
export interface StructuredRange {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
}
|
|
3
7
|
export interface StructuredNode {
|
|
4
8
|
key: string;
|
|
5
9
|
path: string;
|
|
6
10
|
kind: string;
|
|
7
11
|
raw?: string;
|
|
8
12
|
value?: unknown;
|
|
13
|
+
comment?: string;
|
|
14
|
+
range?: StructuredRange;
|
|
9
15
|
children?: readonly StructuredNode[];
|
|
10
16
|
}
|
|
11
17
|
export interface StructuredState {
|
|
@@ -18,7 +24,13 @@ export interface StructuredState {
|
|
|
18
24
|
args?: Record<string, string | number>;
|
|
19
25
|
location?: string;
|
|
20
26
|
}[];
|
|
27
|
+
searchScope?: string;
|
|
28
|
+
searchScopes?: readonly string[];
|
|
29
|
+
selected?: string | null;
|
|
30
|
+
matchCount?: number;
|
|
21
31
|
}
|
|
32
|
+
/** The optional members are progressive enhancements: a controller that omits
|
|
33
|
+
* them simply renders without source sync, scoped search or a match count. */
|
|
22
34
|
export interface StructuredController<S extends StructuredState> {
|
|
23
35
|
readonly state: S;
|
|
24
36
|
subscribe(listener: (state: S) => void): () => void;
|
|
@@ -27,6 +39,9 @@ export interface StructuredController<S extends StructuredState> {
|
|
|
27
39
|
nodeValue(id: string): string;
|
|
28
40
|
nodeJson?(id: string): string;
|
|
29
41
|
documentJson?(): string;
|
|
42
|
+
nodeRange?(id: string): StructuredRange | null;
|
|
43
|
+
nodeAtOffset?(offset: number): string | null;
|
|
44
|
+
nodeMatches?(node: StructuredNode): boolean;
|
|
30
45
|
}
|
|
31
46
|
export type StructuredContext = HostContext & {
|
|
32
47
|
clipboard?: ClipboardService;
|