@rivm-loculus-tools/sequence-editor 0.1.4 → 0.1.5
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/dist/_chunks/Box.js +6737 -0
- package/dist/_chunks/Box.js.map +1 -0
- package/dist/_chunks/Close.js +7 -0
- package/dist/_chunks/Close.js.map +1 -0
- package/dist/_chunks/EditorWorkerService.js +126 -0
- package/dist/_chunks/EditorWorkerService.js.map +1 -0
- package/dist/_chunks/KeyboardArrowDown.js +1023 -0
- package/dist/_chunks/KeyboardArrowDown.js.map +1 -0
- package/dist/_chunks/Redo.js +2559 -0
- package/dist/_chunks/Redo.js.map +1 -0
- package/dist/_chunks/SequenceEditor.js +860 -0
- package/dist/_chunks/SequenceEditor.js.map +1 -0
- package/dist/_chunks/SequenceEditorEventBusService.js +102 -0
- package/dist/_chunks/SequenceEditorEventBusService.js.map +1 -0
- package/dist/_chunks/SequenceEditorMainPage.js +552 -0
- package/dist/_chunks/SequenceEditorMainPage.js.map +1 -0
- package/dist/_chunks/SequenceEditorPageDrawer.js +49842 -0
- package/dist/_chunks/SequenceEditorPageDrawer.js.map +1 -0
- package/dist/_chunks/SequenceEditorPageHeader.js +236 -0
- package/dist/_chunks/SequenceEditorPageHeader.js.map +1 -0
- package/dist/_chunks/SequenceEditorSearchBar.js +143 -0
- package/dist/_chunks/SequenceEditorSearchBar.js.map +1 -0
- package/dist/_chunks/TestIdUtil.js +4695 -0
- package/dist/_chunks/TestIdUtil.js.map +1 -0
- package/dist/_chunks/TextField.js +3083 -0
- package/dist/_chunks/TextField.js.map +1 -0
- package/dist/_chunks/rolldown-runtime.js +13 -0
- package/dist/_chunks/sequenceEditorStore.js +407 -0
- package/dist/_chunks/sequenceEditorStore.js.map +1 -0
- package/dist/_chunks/sequence_editor.js +517 -0
- package/dist/_chunks/sequence_editor.js.map +1 -0
- package/dist/_chunks/withDialog.js +289 -0
- package/dist/_chunks/withDialog.js.map +1 -0
- package/dist/assets/index-C5rc-pJV.js +8 -0
- package/dist/assets/index-C5rc-pJV.js.map +1 -0
- package/dist/classes/services/EditorWorkerService/EditorWorkerService.d.ts +27 -0
- package/dist/classes/services/EditorWorkerService/index.js +2 -0
- package/dist/classes/services/SequenceEditorEventBusService/SequenceEditorEventBusService.d.ts +25 -0
- package/dist/classes/services/SequenceEditorEventBusService/index.js +2 -0
- package/dist/classes/workers/EngineWorker/EngineWorker.d.ts +46 -0
- package/dist/classes/workers/EngineWorker/index.js +110 -0
- package/dist/classes/workers/EngineWorker/index.js.map +1 -0
- package/dist/components/app/App/App.d.ts +1 -0
- package/dist/components/app/App/index.js +957 -0
- package/dist/components/app/App/index.js.map +1 -0
- package/dist/components/pages/EmptyWorkspace.d.ts +3 -0
- package/dist/components/pages/SequenceEditorErrorPage/SequenceEditorErrorPage.d.ts +3 -0
- package/dist/components/pages/SequenceEditorErrorPage/index.js +12 -0
- package/dist/components/pages/SequenceEditorErrorPage/index.js.map +1 -0
- package/dist/components/pages/SequenceEditorMainPage/SequenceEditorMainPage.d.ts +1 -0
- package/dist/components/pages/SequenceEditorMainPage/index.js +2 -0
- package/dist/components/ui/SequenceEditor/SequenceEditor.d.ts +1 -0
- package/dist/components/ui/SequenceEditor/SequenceEditorGotoPositionDialog.d.ts +8 -0
- package/dist/components/ui/SequenceEditor/SequenceEditorStatusBar.d.ts +1 -0
- package/dist/components/ui/SequenceEditor/index.js +2 -0
- package/dist/components/ui/SequenceEditorPage/SequenceEditorPage.d.ts +5 -0
- package/dist/components/ui/SequenceEditorPage/index.js +15 -0
- package/dist/components/ui/SequenceEditorPage/index.js.map +1 -0
- package/dist/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawer.d.ts +1 -0
- package/dist/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerColorForm.d.ts +7 -0
- package/dist/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerKeyboardShortcuts.d.ts +1 -0
- package/dist/components/ui/SequenceEditorPageDrawer/index.js +2 -0
- package/dist/components/ui/SequenceEditorPageHeader/SequenceEditorPageHeader.d.ts +1 -0
- package/dist/components/ui/SequenceEditorPageHeader/index.js +2 -0
- package/dist/components/ui/SequenceEditorSearchBar/SequenceEditorSearchBar.d.ts +1 -0
- package/dist/components/ui/SequenceEditorSearchBar/index.js +2 -0
- package/dist/constants/editor.d.ts +4 -0
- package/dist/constants/editor.js +14 -0
- package/dist/constants/editor.js.map +1 -0
- package/dist/constants/index.js +4 -0
- package/dist/constants/keyboard.d.ts +10 -0
- package/dist/constants/keyboard.js +179 -0
- package/dist/constants/keyboard.js.map +1 -0
- package/dist/constants/palette.d.ts +15 -0
- package/dist/constants/palette.js +196 -0
- package/dist/constants/palette.js.map +1 -0
- package/dist/models/editor.d.ts +6 -0
- package/dist/models/editor.js +8 -0
- package/dist/models/editor.js.map +1 -0
- package/dist/models/model.d.ts +250 -0
- package/dist/models/model.js +10 -0
- package/dist/models/model.js.map +1 -0
- package/dist/models/palette.d.ts +61 -0
- package/dist/models/palette.js +10 -0
- package/dist/models/palette.js.map +1 -0
- package/dist/stores/sequenceEditorStore/index.js +2 -0
- package/dist/stores/sequenceEditorStore/sequenceEditorStore.d.ts +36 -0
- package/dist/utils/EditorUtil/EditorUtil.d.ts +96 -0
- package/dist/utils/EditorUtil/index.js +544 -0
- package/dist/utils/EditorUtil/index.js.map +1 -0
- package/dist/utils/EngineErrorUtil/EngineErrorUtil.d.ts +4 -0
- package/dist/utils/PaletteUtil/PaletteUtil.d.ts +6 -0
- package/dist/utils/PaletteUtil/index.js +19 -0
- package/dist/utils/PaletteUtil/index.js.map +1 -0
- package/package.json +5 -2
- package/.gitkeep +0 -0
- package/CHANGELOG.md +0 -37
- package/eslint.config.js +0 -16
- package/scripts/update-exports.js +0 -9
- package/src/classes/services/EditorWorkerService/EditorWorkerService.ts +0 -163
- package/src/classes/services/SequenceEditorEventBusService/SequenceEditorEventBusService.ts +0 -37
- package/src/classes/workers/EngineWorker/EngineWorker.ts +0 -196
- package/src/components/app/App/App.tsx +0 -22
- package/src/components/pages/EmptyWorkspace.tsx +0 -43
- package/src/components/pages/SequenceEditorErrorPage/SequenceEditorErrorPage.tsx +0 -16
- package/src/components/pages/SequenceEditorMainPage/SequenceEditorMainPage.tsx +0 -76
- package/src/components/ui/SequenceEditor/SequenceEditor.tsx +0 -896
- package/src/components/ui/SequenceEditor/SequenceEditorGotoPositionDialog.tsx +0 -108
- package/src/components/ui/SequenceEditor/SequenceEditorStatusBar.tsx +0 -72
- package/src/components/ui/SequenceEditorPage/SequenceEditorPage.tsx +0 -23
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawer.tsx +0 -234
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerColorForm.tsx +0 -73
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerKeyboardShortcuts.tsx +0 -230
- package/src/components/ui/SequenceEditorPageHeader/SequenceEditorPageHeader.tsx +0 -71
- package/src/components/ui/SequenceEditorSearchBar/SequenceEditorSearchBar.tsx +0 -35
- package/src/constants/editor.ts +0 -15
- package/src/constants/keyboard.ts +0 -154
- package/src/constants/palette.ts +0 -227
- package/src/models/editor.ts +0 -6
- package/src/models/model.ts +0 -295
- package/src/models/palette.ts +0 -68
- package/src/stores/sequenceEditorStore/sequenceEditorStore.ts +0 -103
- package/src/utils/EditorUtil/EditorUtil.ts +0 -892
- package/src/utils/EngineErrorUtil/EngineErrorUtil.ts +0 -25
- package/src/utils/PaletteUtil/PaletteUtil.ts +0 -31
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -32
- package/vite.config.ts +0 -177
- /package/{src/classes/services/EditorWorkerService/index.ts → dist/classes/services/EditorWorkerService/index.d.ts} +0 -0
- /package/{src/classes/services/SequenceEditorEventBusService/index.ts → dist/classes/services/SequenceEditorEventBusService/index.d.ts} +0 -0
- /package/{src/classes/workers/EngineWorker/index.ts → dist/classes/workers/EngineWorker/index.d.ts} +0 -0
- /package/{src/components/app/App/index.ts → dist/components/app/App/index.d.ts} +0 -0
- /package/{src/components/pages/SequenceEditorErrorPage/index.ts → dist/components/pages/SequenceEditorErrorPage/index.d.ts} +0 -0
- /package/{src/components/pages/SequenceEditorMainPage/index.ts → dist/components/pages/SequenceEditorMainPage/index.d.ts} +0 -0
- /package/{src/components/ui/SequenceEditor/index.ts → dist/components/ui/SequenceEditor/index.d.ts} +0 -0
- /package/{src/components/ui/SequenceEditorPage/index.ts → dist/components/ui/SequenceEditorPage/index.d.ts} +0 -0
- /package/{src/components/ui/SequenceEditorPageDrawer/index.ts → dist/components/ui/SequenceEditorPageDrawer/index.d.ts} +0 -0
- /package/{src/components/ui/SequenceEditorPageHeader/index.ts → dist/components/ui/SequenceEditorPageHeader/index.d.ts} +0 -0
- /package/{src/components/ui/SequenceEditorSearchBar/index.ts → dist/components/ui/SequenceEditorSearchBar/index.d.ts} +0 -0
- /package/{src/constants/index.ts → dist/constants/index.d.ts} +0 -0
- /package/{src/models/index.ts → dist/models/index.d.ts} +0 -0
- /package/{src/stores/sequenceEditorStore/index.ts → dist/stores/sequenceEditorStore/index.d.ts} +0 -0
- /package/{src/utils/EditorUtil/index.ts → dist/utils/EditorUtil/index.d.ts} +0 -0
- /package/{src/utils/PaletteUtil/index.ts → dist/utils/PaletteUtil/index.d.ts} +0 -0
|
@@ -1,892 +0,0 @@
|
|
|
1
|
-
import padStart from 'lodash/padStart';
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
AminoAcidPalette,
|
|
5
|
-
EditorAssembly,
|
|
6
|
-
EditorPathProperties,
|
|
7
|
-
EditorSelection,
|
|
8
|
-
EngineMeta,
|
|
9
|
-
EngineSearchResult,
|
|
10
|
-
EngineViewportResult,
|
|
11
|
-
GridGeometry,
|
|
12
|
-
GridRange,
|
|
13
|
-
NucleotidePalette,
|
|
14
|
-
SearchMatch,
|
|
15
|
-
SearchResult,
|
|
16
|
-
StatusBarSelectionStats,
|
|
17
|
-
VisibleGridRange,
|
|
18
|
-
} from '../../models';
|
|
19
|
-
import {
|
|
20
|
-
EDITOR_PATH_PROPERTIES_TYPE,
|
|
21
|
-
MATRIX_TYPE,
|
|
22
|
-
} from '../../models';
|
|
23
|
-
import { PaletteUtil } from '../PaletteUtil';
|
|
24
|
-
import { DEFAULT_GRID_GEOMETRY } from '../../constants';
|
|
25
|
-
import { EDITOR_DIRECTION } from '../../models/editor';
|
|
26
|
-
|
|
27
|
-
export class EditorUtil {
|
|
28
|
-
|
|
29
|
-
public static drawCanvas({
|
|
30
|
-
canvasElement,
|
|
31
|
-
devicePixelRatio,
|
|
32
|
-
geometry,
|
|
33
|
-
meta,
|
|
34
|
-
palette,
|
|
35
|
-
rowNames,
|
|
36
|
-
rowNamesStartRow,
|
|
37
|
-
scrollLeft,
|
|
38
|
-
scrollTop,
|
|
39
|
-
searchResult,
|
|
40
|
-
searchResultHighlightedIndex,
|
|
41
|
-
selection,
|
|
42
|
-
viewport,
|
|
43
|
-
viewportHeight,
|
|
44
|
-
viewportWidth,
|
|
45
|
-
}: {
|
|
46
|
-
canvasElement: HTMLCanvasElement;
|
|
47
|
-
devicePixelRatio: number;
|
|
48
|
-
geometry: GridGeometry;
|
|
49
|
-
meta: EngineMeta;
|
|
50
|
-
palette: AminoAcidPalette | NucleotidePalette;
|
|
51
|
-
rowNames: string[];
|
|
52
|
-
rowNamesStartRow: number;
|
|
53
|
-
scrollLeft: number;
|
|
54
|
-
scrollTop: number;
|
|
55
|
-
searchResult: EngineSearchResult | null;
|
|
56
|
-
searchResultHighlightedIndex: null | number;
|
|
57
|
-
selection: EditorSelection | null;
|
|
58
|
-
viewport: EngineViewportResult;
|
|
59
|
-
viewportHeight: number;
|
|
60
|
-
viewportWidth: number;
|
|
61
|
-
}): EditorAssembly {
|
|
62
|
-
const editorAssembly: EditorAssembly = {
|
|
63
|
-
cells: {
|
|
64
|
-
pathPropertiesMap: new Map(),
|
|
65
|
-
},
|
|
66
|
-
divider: {
|
|
67
|
-
pathPropertiesMap: new Map(),
|
|
68
|
-
},
|
|
69
|
-
labels: {
|
|
70
|
-
pathPropertiesMap: new Map(),
|
|
71
|
-
},
|
|
72
|
-
ruler: {
|
|
73
|
-
pathPropertiesMap: new Map(),
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
if (!canvasElement) {
|
|
78
|
-
return editorAssembly;
|
|
79
|
-
}
|
|
80
|
-
const context = canvasElement.getContext('2d');
|
|
81
|
-
if (!context) {
|
|
82
|
-
return editorAssembly;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const labelStringLength = meta.sequenceCount.toString().length;
|
|
86
|
-
const isRowSelected = (row: number): boolean => {
|
|
87
|
-
return selection?.rows?.includes(row) ?? false;
|
|
88
|
-
};
|
|
89
|
-
const isCellSelected = (row: number, col: number): boolean => Boolean(
|
|
90
|
-
selection?.cells &&
|
|
91
|
-
col >= selection.cells.startCol &&
|
|
92
|
-
col <= selection.cells.endCol &&
|
|
93
|
-
row >= selection.cells.startRow &&
|
|
94
|
-
row <= selection.cells.endRow,
|
|
95
|
-
) || Boolean(
|
|
96
|
-
selection?.cols?.includes(col),
|
|
97
|
-
) || Boolean(
|
|
98
|
-
isRowSelected(row),
|
|
99
|
-
);
|
|
100
|
-
const highlightedSearchHit = searchResult && searchResultHighlightedIndex !== null
|
|
101
|
-
? EditorUtil.searchHitAt(searchResult, searchResultHighlightedIndex)
|
|
102
|
-
: null;
|
|
103
|
-
|
|
104
|
-
EditorUtil.draw(canvasElement, devicePixelRatio, () => {
|
|
105
|
-
context.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
|
106
|
-
|
|
107
|
-
const { cellHeight, cellWidth, dividerWidth, labelWidth, rulerHeight } = geometry;
|
|
108
|
-
const gridStart = labelWidth + dividerWidth;
|
|
109
|
-
|
|
110
|
-
const { bytes, cols, rows, startCol, startRow } = viewport;
|
|
111
|
-
const hasSearchResult = (searchResult?.positions.length ?? 0) > 0;
|
|
112
|
-
const searchMatchFlags = hasSearchResult ? new Uint8Array(rows * cols) : null;
|
|
113
|
-
const highlightedSearchMatchFlags = highlightedSearchHit ? new Uint8Array(rows * cols) : null;
|
|
114
|
-
const searchMatchPath = hasSearchResult ? new Path2D() : null;
|
|
115
|
-
const highlightedSearchMatchPath = highlightedSearchHit ? new Path2D() : null;
|
|
116
|
-
let hasSearchMatches = false;
|
|
117
|
-
let hasHighlightedSearchMatches = false;
|
|
118
|
-
|
|
119
|
-
const addSearchHitToFlags = (
|
|
120
|
-
hit: EngineSearchResult['positions'][number],
|
|
121
|
-
flags: Uint8Array,
|
|
122
|
-
): void => {
|
|
123
|
-
if (!searchResult) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const hitLength = Math.max(1, searchResult.query.length);
|
|
127
|
-
const hitStartCol = Math.max(startCol, hit.col);
|
|
128
|
-
const hitEndCol = Math.min(startCol + cols, hit.col + hitLength);
|
|
129
|
-
const hitRow = hit.row - startRow;
|
|
130
|
-
if (
|
|
131
|
-
hitRow < 0 ||
|
|
132
|
-
hitRow >= rows ||
|
|
133
|
-
hitStartCol >= hitEndCol ||
|
|
134
|
-
!EditorUtil.searchHitContainsCell(hit, searchResult.query, hit.row, hitStartCol)
|
|
135
|
-
) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const startIndex = hitRow * cols + hitStartCol - startCol;
|
|
139
|
-
flags.fill(1, startIndex, startIndex + hitEndCol - hitStartCol);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
if (searchResult && searchMatchFlags) {
|
|
143
|
-
searchResult.positions.forEach((hit) => addSearchHitToFlags(hit, searchMatchFlags));
|
|
144
|
-
if (highlightedSearchHit && highlightedSearchMatchFlags) {
|
|
145
|
-
addSearchHitToFlags(highlightedSearchHit, highlightedSearchMatchFlags);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Render cells
|
|
150
|
-
context.font = '12px monospace';
|
|
151
|
-
context.textAlign = 'center';
|
|
152
|
-
context.textBaseline = 'middle';
|
|
153
|
-
for (let row = 0; row < rows; row++) {
|
|
154
|
-
// cell position on screen, offset by the viewport's grid origin and current scroll
|
|
155
|
-
const y = (startRow + row) * cellHeight + rulerHeight - scrollTop;
|
|
156
|
-
if (y + cellHeight < rulerHeight || y > viewportHeight) {
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
for (let col = 0; col < cols; col++) {
|
|
160
|
-
const x = (startCol + col) * cellWidth + gridStart - scrollLeft;
|
|
161
|
-
if (x + cellWidth < gridStart || x > viewportWidth) {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
const byte = bytes[row * cols + col];
|
|
165
|
-
const cellCol = startCol + col;
|
|
166
|
-
const cellRow = startRow + row;
|
|
167
|
-
const charCode = byte ?? '';
|
|
168
|
-
const label = String.fromCharCode(charCode);
|
|
169
|
-
const colors = PaletteUtil.paletteEntryFor(palette, label);
|
|
170
|
-
let cellBackground = colors.background;
|
|
171
|
-
if (byte === null) {
|
|
172
|
-
cellBackground = '#e9eef2';
|
|
173
|
-
} else if (label === ' ') {
|
|
174
|
-
cellBackground = '#f7f8f9';
|
|
175
|
-
}
|
|
176
|
-
let cellForeground = colors.foreground;
|
|
177
|
-
const isSelected = isCellSelected(cellRow, cellCol);
|
|
178
|
-
if (isSelected) {
|
|
179
|
-
cellBackground = colors.backgroundSelected;
|
|
180
|
-
cellForeground = colors.foregroundSelected;
|
|
181
|
-
}
|
|
182
|
-
const cellIndex = row * cols + col;
|
|
183
|
-
const matchesSearch = searchMatchFlags?.[cellIndex] === 1;
|
|
184
|
-
const matchesHighlightedSearch = highlightedSearchMatchFlags?.[cellIndex] === 1;
|
|
185
|
-
const rectanglePath = new Path2D();
|
|
186
|
-
rectanglePath.rect(x, y, cellWidth, cellHeight);
|
|
187
|
-
rectanglePath.closePath();
|
|
188
|
-
editorAssembly.cells.pathPropertiesMap.set(rectanglePath, {
|
|
189
|
-
col: cellCol,
|
|
190
|
-
row: cellRow,
|
|
191
|
-
type: EDITOR_PATH_PROPERTIES_TYPE.CELL,
|
|
192
|
-
});
|
|
193
|
-
// draw path on canvas
|
|
194
|
-
context.fillStyle = cellBackground;
|
|
195
|
-
context.fill(rectanglePath);
|
|
196
|
-
if (matchesHighlightedSearch) {
|
|
197
|
-
context.fillStyle = 'rgba(255, 193, 7, 0.35)';
|
|
198
|
-
context.fillRect(x + 2, y + 2, Math.max(0, cellWidth - 4), Math.max(0, cellHeight - 4));
|
|
199
|
-
}
|
|
200
|
-
context.fillStyle = cellForeground;
|
|
201
|
-
context.fillText(label, x + cellWidth / 2, y + cellHeight / 2);
|
|
202
|
-
if (matchesSearch && searchMatchPath) {
|
|
203
|
-
hasSearchMatches = true;
|
|
204
|
-
searchMatchPath.rect(x + 0.5, y + 0.5, cellWidth - 1, cellHeight - 1);
|
|
205
|
-
if (matchesHighlightedSearch && highlightedSearchMatchPath) {
|
|
206
|
-
hasHighlightedSearchMatches = true;
|
|
207
|
-
highlightedSearchMatchPath.rect(x + 1, y + 1, cellWidth - 2, cellHeight - 2);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (hasSearchMatches && searchMatchPath) {
|
|
214
|
-
context.strokeStyle = '#000000';
|
|
215
|
-
context.lineWidth = 1;
|
|
216
|
-
context.stroke(searchMatchPath);
|
|
217
|
-
}
|
|
218
|
-
if (hasHighlightedSearchMatches && highlightedSearchMatchPath) {
|
|
219
|
-
context.lineWidth = 2;
|
|
220
|
-
context.stroke(highlightedSearchMatchPath);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Render ruler
|
|
224
|
-
context.fillStyle = '#edf2f6';
|
|
225
|
-
context.fillRect(0, 0, viewportWidth, rulerHeight);
|
|
226
|
-
context.font = '12px monospace';
|
|
227
|
-
context.textBaseline = 'middle';
|
|
228
|
-
|
|
229
|
-
const tickCols: number[] = [];
|
|
230
|
-
context.strokeStyle = '#9fb3c8';
|
|
231
|
-
context.lineWidth = 1;
|
|
232
|
-
context.beginPath();
|
|
233
|
-
for (let col = 0; col < cols; col++) {
|
|
234
|
-
const isMajorTick = (startCol + col + 1) % 10 === 0;
|
|
235
|
-
if (isMajorTick) {
|
|
236
|
-
tickCols.push(col);
|
|
237
|
-
}
|
|
238
|
-
const rulerX = (startCol + col) * cellWidth + gridStart - scrollLeft;
|
|
239
|
-
const rulerPath = new Path2D();
|
|
240
|
-
rulerPath.rect(rulerX, 0, cellWidth, rulerHeight);
|
|
241
|
-
rulerPath.closePath();
|
|
242
|
-
editorAssembly.ruler.pathPropertiesMap.set(rulerPath, {
|
|
243
|
-
col: startCol + col,
|
|
244
|
-
type: EDITOR_PATH_PROPERTIES_TYPE.RULER,
|
|
245
|
-
});
|
|
246
|
-
const x = rulerX + 0.5;
|
|
247
|
-
const tickHeight = isMajorTick ? 8 : 4;
|
|
248
|
-
context.moveTo(x, rulerHeight);
|
|
249
|
-
context.lineTo(x, rulerHeight - tickHeight);
|
|
250
|
-
}
|
|
251
|
-
context.stroke();
|
|
252
|
-
|
|
253
|
-
context.fillStyle = '#486581';
|
|
254
|
-
context.textAlign = 'center';
|
|
255
|
-
tickCols.forEach((col) => {
|
|
256
|
-
const x = (startCol + col) * cellWidth + gridStart - scrollLeft;
|
|
257
|
-
const label = String(startCol + col + 1);
|
|
258
|
-
const textWidth = context.measureText(label).width;
|
|
259
|
-
// skip labels that would be clipped by the gutter or the canvas edge
|
|
260
|
-
if (x - textWidth / 2 < gridStart || x + textWidth / 2 > viewportWidth) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
context.fillText(label, x, rulerHeight / 2);
|
|
264
|
-
});
|
|
265
|
-
context.textAlign = 'start';
|
|
266
|
-
|
|
267
|
-
context.strokeStyle = '#bcccdc';
|
|
268
|
-
context.lineWidth = 1;
|
|
269
|
-
context.beginPath();
|
|
270
|
-
context.moveTo(gridStart + 0.5, 0);
|
|
271
|
-
context.lineTo(gridStart + 0.5, viewportHeight);
|
|
272
|
-
context.moveTo(0, rulerHeight + 0.5);
|
|
273
|
-
context.lineTo(viewportWidth, rulerHeight + 0.5);
|
|
274
|
-
context.stroke();
|
|
275
|
-
|
|
276
|
-
// Corner stays fixed above the label gutter; ruler marks scroll underneath it
|
|
277
|
-
context.fillStyle = '#edf2f6';
|
|
278
|
-
context.fillRect(0, 0, gridStart, rulerHeight);
|
|
279
|
-
context.fillStyle = '#d9e2ec';
|
|
280
|
-
context.fillRect(labelWidth, 0, dividerWidth, viewportHeight);
|
|
281
|
-
const dividerPath = new Path2D();
|
|
282
|
-
dividerPath.rect(labelWidth, 0, dividerWidth, viewportHeight);
|
|
283
|
-
dividerPath.closePath();
|
|
284
|
-
editorAssembly.divider.pathPropertiesMap.set(dividerPath, {
|
|
285
|
-
type: EDITOR_PATH_PROPERTIES_TYPE.DIVIDER,
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
// Render labels
|
|
289
|
-
context.fillStyle = '#f8fafb';
|
|
290
|
-
context.fillRect(0, rulerHeight, labelWidth, viewportHeight - rulerHeight);
|
|
291
|
-
context.font = '12px monospace';
|
|
292
|
-
context.textBaseline = 'middle';
|
|
293
|
-
context.save();
|
|
294
|
-
context.beginPath();
|
|
295
|
-
context.rect(0, rulerHeight, labelWidth, viewportHeight - rulerHeight);
|
|
296
|
-
context.clip();
|
|
297
|
-
for (let row = 0; row < rows; row++) {
|
|
298
|
-
const y = (startRow + row) * cellHeight + rulerHeight - scrollTop;
|
|
299
|
-
if (y + cellHeight < rulerHeight || y > viewportHeight) {
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
const labelPath = new Path2D();
|
|
303
|
-
labelPath.rect(0, y, labelWidth, cellHeight);
|
|
304
|
-
labelPath.closePath();
|
|
305
|
-
editorAssembly.labels.pathPropertiesMap.set(labelPath, {
|
|
306
|
-
row: startRow + row,
|
|
307
|
-
type: EDITOR_PATH_PROPERTIES_TYPE.LABEL,
|
|
308
|
-
});
|
|
309
|
-
const rowNameIndex = startRow + row - rowNamesStartRow;
|
|
310
|
-
const labelRow = startRow + row;
|
|
311
|
-
const isLabelSelected = Boolean(selection?.cols) || Boolean(
|
|
312
|
-
selection?.cells &&
|
|
313
|
-
labelRow >= selection.cells.startRow &&
|
|
314
|
-
labelRow <= selection.cells.endRow,
|
|
315
|
-
) || isRowSelected(labelRow);
|
|
316
|
-
context.fillStyle = isLabelSelected ? '#1565c0' : '#f8fafb';
|
|
317
|
-
context.fillRect(0, y, labelWidth, cellHeight);
|
|
318
|
-
context.fillStyle = isLabelSelected ? '#ffffff' : '#334e68';
|
|
319
|
-
context.fillText(`${padStart(String(startRow + row + 1), labelStringLength, '0')}: ${rowNames[rowNameIndex] ?? ''}`, 8, y + cellHeight / 2);
|
|
320
|
-
}
|
|
321
|
-
context.restore();
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
return editorAssembly;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
public static getExpandedSelection(currentSelection: EditorSelection, initialSelection: EditorSelection, direction: EDITOR_DIRECTION, metaData: EngineMeta): EditorSelection | null {
|
|
328
|
-
const cells = currentSelection.cells;
|
|
329
|
-
if (cells) {
|
|
330
|
-
if (direction === EDITOR_DIRECTION.LEFT) {
|
|
331
|
-
const initialCells = initialSelection.cells;
|
|
332
|
-
if (!initialCells) {
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
const expandsLeft = cells.startCol < initialCells.startCol || cells.endCol <= initialCells.startCol;
|
|
336
|
-
const nextStartCol = expandsLeft ? cells.startCol - 1 : cells.startCol;
|
|
337
|
-
const endCol = expandsLeft ? cells.endCol : cells.endCol - 1;
|
|
338
|
-
if (nextStartCol < 0) {
|
|
339
|
-
return null;
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
cells: {
|
|
343
|
-
...cells,
|
|
344
|
-
endCol,
|
|
345
|
-
startCol: nextStartCol,
|
|
346
|
-
},
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
if (direction === EDITOR_DIRECTION.RIGHT) {
|
|
350
|
-
const initialCells = initialSelection.cells;
|
|
351
|
-
if (!initialCells) {
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
|
-
const startCol = cells.startCol < initialCells.startCol ? cells.startCol + 1 : cells.startCol;
|
|
355
|
-
const endCol = cells.startCol < initialCells.startCol ? cells.endCol : cells.endCol + 1;
|
|
356
|
-
if (endCol >= metaData.alignmentWidth) {
|
|
357
|
-
return null;
|
|
358
|
-
}
|
|
359
|
-
return {
|
|
360
|
-
cells: {
|
|
361
|
-
...cells,
|
|
362
|
-
endCol,
|
|
363
|
-
startCol,
|
|
364
|
-
},
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
if (direction === EDITOR_DIRECTION.UP) {
|
|
368
|
-
const initialCells = initialSelection.cells;
|
|
369
|
-
if (!initialCells) {
|
|
370
|
-
return null;
|
|
371
|
-
}
|
|
372
|
-
const expandsUp = cells.startRow < initialCells.startRow || cells.endRow <= initialCells.startRow;
|
|
373
|
-
const nextStartRow = expandsUp ? cells.startRow - 1 : cells.startRow;
|
|
374
|
-
const endRow = expandsUp ? cells.endRow : cells.endRow - 1;
|
|
375
|
-
if (nextStartRow < 0) {
|
|
376
|
-
return null;
|
|
377
|
-
}
|
|
378
|
-
return {
|
|
379
|
-
cells: {
|
|
380
|
-
...cells,
|
|
381
|
-
endRow,
|
|
382
|
-
startRow: nextStartRow,
|
|
383
|
-
},
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
const initialCells = initialSelection.cells;
|
|
387
|
-
if (!initialCells) {
|
|
388
|
-
return null;
|
|
389
|
-
}
|
|
390
|
-
const startRow = cells.startRow < initialCells.startRow ? cells.startRow + 1 : cells.startRow;
|
|
391
|
-
const endRow = cells.startRow < initialCells.startRow ? cells.endRow : cells.endRow + 1;
|
|
392
|
-
if (endRow >= metaData.sequenceCount) {
|
|
393
|
-
return null;
|
|
394
|
-
}
|
|
395
|
-
return {
|
|
396
|
-
cells: {
|
|
397
|
-
...cells,
|
|
398
|
-
endRow,
|
|
399
|
-
startRow,
|
|
400
|
-
},
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
const cols = currentSelection.cols;
|
|
405
|
-
if (cols) {
|
|
406
|
-
if (cols.length === 0 || (direction !== EDITOR_DIRECTION.LEFT && direction !== EDITOR_DIRECTION.RIGHT)) {
|
|
407
|
-
return null;
|
|
408
|
-
}
|
|
409
|
-
const min = Math.min(...cols);
|
|
410
|
-
const max = Math.max(...cols);
|
|
411
|
-
const initialCols = initialSelection.cols;
|
|
412
|
-
if (!initialCols || initialCols.length === 0) {
|
|
413
|
-
return null;
|
|
414
|
-
}
|
|
415
|
-
const initialMin = Math.min(...initialCols);
|
|
416
|
-
if (direction === EDITOR_DIRECTION.LEFT) {
|
|
417
|
-
if (max > initialMin) {
|
|
418
|
-
return { cols: cols.slice(0, -1) };
|
|
419
|
-
}
|
|
420
|
-
return min > 0 ? { cols: [min - 1, ...cols] } : null;
|
|
421
|
-
}
|
|
422
|
-
if (min < initialMin) {
|
|
423
|
-
return { cols: cols.slice(1) };
|
|
424
|
-
}
|
|
425
|
-
return max < metaData.alignmentWidth - 1 ? { cols: [...cols, max + 1] } : null;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
const rows = currentSelection.rows;
|
|
429
|
-
if (rows) {
|
|
430
|
-
return currentSelection;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
return null;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
public static getMovedSelection(selection: EditorSelection | null, direction: EDITOR_DIRECTION, metaData: EngineMeta): EditorSelection | null {
|
|
438
|
-
if (!selection) {
|
|
439
|
-
return null;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
const offset = direction === EDITOR_DIRECTION.LEFT || direction === EDITOR_DIRECTION.UP ? -1 : 1;
|
|
443
|
-
const canMove = (min: number, max: number, limit: number): boolean => (
|
|
444
|
-
offset < 0 ? min > 0 : max < limit - 1
|
|
445
|
-
);
|
|
446
|
-
|
|
447
|
-
const cells = selection.cells;
|
|
448
|
-
if (cells) {
|
|
449
|
-
if (direction === EDITOR_DIRECTION.LEFT || direction === EDITOR_DIRECTION.RIGHT) {
|
|
450
|
-
if (!canMove(cells.startCol, cells.endCol, metaData.alignmentWidth)) {
|
|
451
|
-
return null;
|
|
452
|
-
}
|
|
453
|
-
return {
|
|
454
|
-
cells: {
|
|
455
|
-
endCol: cells.endCol + offset,
|
|
456
|
-
endRow: cells.endRow,
|
|
457
|
-
startCol: cells.startCol + offset,
|
|
458
|
-
startRow: cells.startRow,
|
|
459
|
-
},
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
if (!canMove(cells.startRow, cells.endRow, metaData.sequenceCount)) {
|
|
464
|
-
return null;
|
|
465
|
-
}
|
|
466
|
-
return {
|
|
467
|
-
cells: {
|
|
468
|
-
endCol: cells.endCol,
|
|
469
|
-
endRow: cells.endRow + offset,
|
|
470
|
-
startCol: cells.startCol,
|
|
471
|
-
startRow: cells.startRow + offset,
|
|
472
|
-
},
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
const cols = selection.cols;
|
|
477
|
-
if (cols) {
|
|
478
|
-
if ((direction !== EDITOR_DIRECTION.LEFT && direction !== EDITOR_DIRECTION.RIGHT) || cols.length === 0) {
|
|
479
|
-
return null;
|
|
480
|
-
}
|
|
481
|
-
const min = Math.min(...cols);
|
|
482
|
-
const max = Math.max(...cols);
|
|
483
|
-
if (!canMove(min, max, metaData.alignmentWidth)) {
|
|
484
|
-
return null;
|
|
485
|
-
}
|
|
486
|
-
return { cols: cols.map(col => col + offset) };
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
const rows = selection.rows;
|
|
490
|
-
if (rows) {
|
|
491
|
-
if ((direction !== EDITOR_DIRECTION.UP && direction !== EDITOR_DIRECTION.DOWN) || rows.length === 0) {
|
|
492
|
-
return null;
|
|
493
|
-
}
|
|
494
|
-
const min = Math.min(...rows);
|
|
495
|
-
const max = Math.max(...rows);
|
|
496
|
-
if (!canMove(min, max, metaData.sequenceCount)) {
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
499
|
-
return { rows: rows.map(row => row + offset) };
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
return null;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
public static getMutateArguments(selection: EditorSelection | null, metaData: EngineMeta, offset: number = 0): { endCol: number; rows: number[]; startCol: number } | undefined {
|
|
506
|
-
const cells = selection?.cells;
|
|
507
|
-
if (cells) {
|
|
508
|
-
return {
|
|
509
|
-
endCol: cells.endCol + offset,
|
|
510
|
-
rows: Array.from({ length: cells.endRow - cells.startRow + 1 }, (_, index) => cells.startRow + index),
|
|
511
|
-
startCol: cells.startCol + offset,
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
const cols = selection?.cols;
|
|
516
|
-
if (cols) {
|
|
517
|
-
return {
|
|
518
|
-
endCol: cols[cols.length - 1] + offset,
|
|
519
|
-
rows: Array.from({ length: metaData.sequenceCount }, (_, index) => index),
|
|
520
|
-
startCol: cols[0] + offset,
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const rows = selection?.rows;
|
|
525
|
-
if (rows) {
|
|
526
|
-
return {
|
|
527
|
-
endCol: metaData.alignmentWidth - 1 + offset,
|
|
528
|
-
rows,
|
|
529
|
-
startCol: 0 + offset,
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
return undefined;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
/**
|
|
537
|
-
* Performs a hit-test against the tree assembly's path maps to find the
|
|
538
|
-
* tree node or line segment under the mouse cursor.
|
|
539
|
-
*
|
|
540
|
-
* Checks in priority order: node dots (via `isPointInPath`) -> horizontal
|
|
541
|
-
* branch lines (with ±1 px vertical tolerance) -> vertical connector lines
|
|
542
|
-
* (with ±1 px horizontal tolerance).
|
|
543
|
-
*
|
|
544
|
-
* @param params.canvas - The canvas element that received the mouse event.
|
|
545
|
-
* @param params.event - The mouse event providing cursor coordinates.
|
|
546
|
-
* @param params.treeAssembly - The assembly containing path maps to hit-test against.
|
|
547
|
-
* @param params.devicePixelRatio - Screen DPR used when the canvas backing store is scaled.
|
|
548
|
-
* @returns The {@link EditorPathProperties} of the hit cell, or `undefined` if nothing was hit.
|
|
549
|
-
*/
|
|
550
|
-
public static getPathPropertiesFromCanvas(params: { canvas: HTMLCanvasElement; devicePixelRatio: number; editorAssembly: EditorAssembly; event: MouseEvent }): EditorPathProperties | undefined {
|
|
551
|
-
const { canvas, devicePixelRatio, editorAssembly, event } = params;
|
|
552
|
-
|
|
553
|
-
const ctx = EditorUtil.getCanvasContext(canvas);
|
|
554
|
-
const rect = canvas.getBoundingClientRect();
|
|
555
|
-
const canvasScaleX = canvas.width / rect.width;
|
|
556
|
-
const canvasScaleY = canvas.height / rect.height;
|
|
557
|
-
const canvasX = (event.clientX - rect.left) * canvasScaleX / devicePixelRatio;
|
|
558
|
-
const canvasY = (event.clientY - rect.top) * canvasScaleY / devicePixelRatio;
|
|
559
|
-
|
|
560
|
-
for (const [path, pathProperties] of editorAssembly.cells.pathPropertiesMap) {
|
|
561
|
-
if (ctx.isPointInPath(path, canvasX, canvasY)) {
|
|
562
|
-
return pathProperties;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
for (const [path, pathProperties] of editorAssembly.ruler.pathPropertiesMap) {
|
|
567
|
-
if (ctx.isPointInPath(path, canvasX, canvasY)) {
|
|
568
|
-
return pathProperties;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
for (const [path, pathProperties] of editorAssembly.labels.pathPropertiesMap) {
|
|
573
|
-
if (ctx.isPointInPath(path, canvasX, canvasY)) {
|
|
574
|
-
return pathProperties;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
for (const [path, pathProperties] of editorAssembly.divider.pathPropertiesMap) {
|
|
579
|
-
if (ctx.isPointInPath(path, canvasX, canvasY)) {
|
|
580
|
-
return pathProperties;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
return undefined;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
public static getPostUpsertSelection(selection: EditorSelection | null, direction: EDITOR_DIRECTION): EditorSelection | null {
|
|
588
|
-
if (!selection) {
|
|
589
|
-
return null;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
const offset = direction === EDITOR_DIRECTION.LEFT ? -1 : 1;
|
|
593
|
-
|
|
594
|
-
const cells = selection.cells;
|
|
595
|
-
if (cells) {
|
|
596
|
-
return {
|
|
597
|
-
cells: {
|
|
598
|
-
endCol: cells.endCol + offset,
|
|
599
|
-
endRow: cells.endRow,
|
|
600
|
-
startCol: cells.startCol + offset,
|
|
601
|
-
startRow: cells.startRow,
|
|
602
|
-
},
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
const cols = selection.cols;
|
|
607
|
-
if (cols) {
|
|
608
|
-
return {
|
|
609
|
-
cols: cols.map(col => col + offset),
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
const rows = selection.rows;
|
|
614
|
-
if (rows) {
|
|
615
|
-
return {
|
|
616
|
-
rows,
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
return null;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
public static getRowsToMove(selection: EditorSelection | null, direction: EDITOR_DIRECTION, metaData: EngineMeta): number[] | undefined {
|
|
624
|
-
const cells = selection?.cells;
|
|
625
|
-
const rows = selection?.rows ?? (cells
|
|
626
|
-
? Array.from({ length: cells.endRow - cells.startRow + 1 }, (_, index) => cells.startRow + index)
|
|
627
|
-
: undefined);
|
|
628
|
-
if (!rows || rows.length === 0) {
|
|
629
|
-
return undefined;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
const minRow = Math.min(...rows);
|
|
633
|
-
const maxRow = Math.max(...rows);
|
|
634
|
-
if (direction === EDITOR_DIRECTION.UP && minRow === 0) {
|
|
635
|
-
return undefined;
|
|
636
|
-
}
|
|
637
|
-
if (direction === EDITOR_DIRECTION.DOWN && maxRow === metaData.sequenceCount - 1) {
|
|
638
|
-
return undefined;
|
|
639
|
-
}
|
|
640
|
-
return rows;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
public static getSelectionFromPathProperties(params: { endPath: EditorPathProperties; startPath: EditorPathProperties }): EditorSelection | undefined {
|
|
644
|
-
const { endPath, startPath } = params;
|
|
645
|
-
|
|
646
|
-
if (startPath.type === EDITOR_PATH_PROPERTIES_TYPE.RULER && (
|
|
647
|
-
endPath.type === EDITOR_PATH_PROPERTIES_TYPE.RULER ||
|
|
648
|
-
endPath.type === EDITOR_PATH_PROPERTIES_TYPE.CELL
|
|
649
|
-
)) {
|
|
650
|
-
const startCol = Math.min(startPath.col, endPath.col);
|
|
651
|
-
const endCol = Math.max(startPath.col, endPath.col);
|
|
652
|
-
return {
|
|
653
|
-
cols: Array.from({ length: endCol - startCol + 1 }, (_, index) => startCol + index),
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
if (startPath.type === EDITOR_PATH_PROPERTIES_TYPE.CELL && endPath.type === EDITOR_PATH_PROPERTIES_TYPE.CELL) {
|
|
658
|
-
return {
|
|
659
|
-
cells: {
|
|
660
|
-
endCol: Math.max(startPath.col, endPath.col),
|
|
661
|
-
endRow: Math.max(startPath.row, endPath.row),
|
|
662
|
-
startCol: Math.min(startPath.col, endPath.col),
|
|
663
|
-
startRow: Math.min(startPath.row, endPath.row),
|
|
664
|
-
},
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
if (startPath.type === EDITOR_PATH_PROPERTIES_TYPE.LABEL && endPath.type === EDITOR_PATH_PROPERTIES_TYPE.LABEL) {
|
|
669
|
-
const startRow = Math.min(startPath.row, endPath.row);
|
|
670
|
-
const endRow = Math.max(startPath.row, endPath.row);
|
|
671
|
-
return {
|
|
672
|
-
rows: Array.from({ length: endRow - startRow + 1 }, (_, index) => startRow + index),
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
return undefined;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
public static getStatusBarSelectionStats(selection: EditorSelection | null, meta: EngineMeta | null = null): StatusBarSelectionStats {
|
|
680
|
-
if (!selection) {
|
|
681
|
-
return {
|
|
682
|
-
cols: 0,
|
|
683
|
-
pos: 0,
|
|
684
|
-
selectedSeqs: 0,
|
|
685
|
-
totalSelectedChars: 0,
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
if (selection.cells) {
|
|
690
|
-
const cols = selection.cells.endCol - selection.cells.startCol + 1;
|
|
691
|
-
const selectedSeqs = selection.cells.endRow - selection.cells.startRow + 1;
|
|
692
|
-
return {
|
|
693
|
-
cols,
|
|
694
|
-
pos: selection.cells.startCol + 1,
|
|
695
|
-
selectedSeqs,
|
|
696
|
-
totalSelectedChars: cols * selectedSeqs,
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
if (selection.cols) {
|
|
701
|
-
const cols = selection.cols.length;
|
|
702
|
-
const selectedSeqs = meta?.sequenceCount ?? 0;
|
|
703
|
-
return {
|
|
704
|
-
cols,
|
|
705
|
-
pos: selection.cols[0] === undefined ? 0 : selection.cols[0] + 1,
|
|
706
|
-
selectedSeqs,
|
|
707
|
-
totalSelectedChars: cols * selectedSeqs,
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
const selectedSeqs = selection.rows?.length ?? 0;
|
|
712
|
-
const cols = meta?.alignmentWidth ?? 0;
|
|
713
|
-
return {
|
|
714
|
-
cols,
|
|
715
|
-
pos: 0,
|
|
716
|
-
selectedSeqs,
|
|
717
|
-
totalSelectedChars: cols * selectedSeqs,
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
public static getUpsertArguments(selection: EditorSelection | null, metaData: EngineMeta, offset: number = 0): { col: number; rows: number[] } | undefined {
|
|
722
|
-
const cells = selection?.cells;
|
|
723
|
-
if (cells) {
|
|
724
|
-
return {
|
|
725
|
-
col: cells.startCol + offset,
|
|
726
|
-
rows: Array.from({ length: cells.endRow - cells.startRow + 1 }, (_, index) => cells.startRow + index),
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
const cols = selection?.cols;
|
|
731
|
-
if (cols) {
|
|
732
|
-
return {
|
|
733
|
-
col: cols[0] + offset,
|
|
734
|
-
rows: Array.from({ length: metaData.sequenceCount }, (_, index) => index),
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
const rows = selection?.rows;
|
|
739
|
-
if (rows) {
|
|
740
|
-
return {
|
|
741
|
-
col: 0 + offset,
|
|
742
|
-
rows,
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
return undefined;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
public static getVisibleGridRange(params: {
|
|
750
|
-
geometry?: GridGeometry;
|
|
751
|
-
numCols: number;
|
|
752
|
-
numRows: number;
|
|
753
|
-
scrollLeft: number;
|
|
754
|
-
scrollTop: number;
|
|
755
|
-
viewportHeight: number;
|
|
756
|
-
viewportWidth: number;
|
|
757
|
-
}): VisibleGridRange {
|
|
758
|
-
const {
|
|
759
|
-
geometry = DEFAULT_GRID_GEOMETRY,
|
|
760
|
-
numCols,
|
|
761
|
-
numRows,
|
|
762
|
-
scrollLeft,
|
|
763
|
-
scrollTop,
|
|
764
|
-
viewportHeight,
|
|
765
|
-
viewportWidth,
|
|
766
|
-
} = params;
|
|
767
|
-
const gridStart = geometry.labelWidth + geometry.dividerWidth;
|
|
768
|
-
const visibleStartCol = Math.max(0, Math.floor(scrollLeft / geometry.cellWidth));
|
|
769
|
-
const visibleEndCol = Math.min(
|
|
770
|
-
numCols,
|
|
771
|
-
visibleStartCol + Math.max(1, Math.ceil((viewportWidth - gridStart) / geometry.cellWidth) + 1),
|
|
772
|
-
);
|
|
773
|
-
const visibleStartRow = Math.max(0, Math.floor(Math.max(0, scrollTop - geometry.rulerHeight) / geometry.cellHeight));
|
|
774
|
-
const visibleEndRow = Math.min(
|
|
775
|
-
numRows,
|
|
776
|
-
visibleStartRow + Math.max(1, Math.ceil((viewportHeight - geometry.rulerHeight) / geometry.cellHeight) + 1),
|
|
777
|
-
);
|
|
778
|
-
|
|
779
|
-
return {
|
|
780
|
-
cache: {
|
|
781
|
-
endCol: Math.min(numCols, visibleEndCol + geometry.numOverscanCols),
|
|
782
|
-
endRow: Math.min(numRows, visibleEndRow + geometry.numOverscanRows),
|
|
783
|
-
startCol: Math.max(0, visibleStartCol - geometry.numOverscanCols),
|
|
784
|
-
startRow: Math.max(0, visibleStartRow - geometry.numOverscanRows),
|
|
785
|
-
},
|
|
786
|
-
visible: {
|
|
787
|
-
endCol: visibleEndCol,
|
|
788
|
-
endRow: visibleEndRow,
|
|
789
|
-
startCol: visibleStartCol,
|
|
790
|
-
startRow: visibleStartRow,
|
|
791
|
-
},
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
public static isWithinGridRange(params: { cachedGridRange: GridRange; visibleGridRange: GridRange }): boolean {
|
|
796
|
-
const { cachedGridRange, visibleGridRange } = params;
|
|
797
|
-
return (
|
|
798
|
-
visibleGridRange.startCol >= cachedGridRange.startCol &&
|
|
799
|
-
visibleGridRange.endCol <= cachedGridRange.endCol &&
|
|
800
|
-
visibleGridRange.startRow >= cachedGridRange.startRow &&
|
|
801
|
-
visibleGridRange.endRow <= cachedGridRange.endRow
|
|
802
|
-
);
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
public static scrollToPosition(params: {
|
|
806
|
-
geometry: GridGeometry;
|
|
807
|
-
scrollContainer: HTMLDivElement | null;
|
|
808
|
-
x: null | number;
|
|
809
|
-
y: null | number;
|
|
810
|
-
}): void {
|
|
811
|
-
const {
|
|
812
|
-
geometry,
|
|
813
|
-
scrollContainer,
|
|
814
|
-
x,
|
|
815
|
-
y,
|
|
816
|
-
} = params;
|
|
817
|
-
if (!scrollContainer) {
|
|
818
|
-
return;
|
|
819
|
-
}
|
|
820
|
-
scrollContainer.scrollTo({
|
|
821
|
-
left: x === null ? scrollContainer.scrollLeft : Math.max(0, x - 1) * geometry.cellWidth,
|
|
822
|
-
top: y === null ? scrollContainer.scrollTop : Math.max(0, y - 1) * geometry.cellHeight,
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
public static scrollToSearchResult(params: {
|
|
827
|
-
geometry: GridGeometry;
|
|
828
|
-
scrollContainer: HTMLDivElement | null;
|
|
829
|
-
searchResult: EngineSearchResult | null;
|
|
830
|
-
searchResultHighlightedIndex: null | number;
|
|
831
|
-
}): void {
|
|
832
|
-
const {
|
|
833
|
-
geometry,
|
|
834
|
-
scrollContainer,
|
|
835
|
-
searchResult,
|
|
836
|
-
searchResultHighlightedIndex,
|
|
837
|
-
} = params;
|
|
838
|
-
const searchHit = searchResult && searchResultHighlightedIndex !== null
|
|
839
|
-
? EditorUtil.searchHitAt(searchResult, searchResultHighlightedIndex)
|
|
840
|
-
: null;
|
|
841
|
-
if (!searchHit) {
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
EditorUtil.scrollToPosition({
|
|
845
|
-
geometry,
|
|
846
|
-
scrollContainer,
|
|
847
|
-
x: searchHit.col + 1,
|
|
848
|
-
y: searchHit.row + 1,
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
/**
|
|
853
|
-
* Helper that wraps a canvas drawing callback with a DPR-aware transform, then
|
|
854
|
-
* restores the context to its pre-call state.
|
|
855
|
-
*
|
|
856
|
-
* @param canvas - The canvas element whose 2D context to use.
|
|
857
|
-
* @param devicePixelRatio - Screen DPR to scale up for HiDPI rendering.
|
|
858
|
-
* @param callback - Drawing operations to perform inside the transform.
|
|
859
|
-
*/
|
|
860
|
-
private static draw(canvas: HTMLCanvasElement, devicePixelRatio: number, callback: (ctx: CanvasRenderingContext2D) => void): void {
|
|
861
|
-
const ctx = EditorUtil.getCanvasContext(canvas);
|
|
862
|
-
ctx.setTransform(devicePixelRatio, 0, 0, devicePixelRatio, 0, 0);
|
|
863
|
-
callback(ctx);
|
|
864
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
private static getCanvasContext(canvas: HTMLCanvasElement): CanvasRenderingContext2D {
|
|
868
|
-
const ctx = canvas.getContext('2d');
|
|
869
|
-
if (!ctx) {
|
|
870
|
-
throw new Error('Failed to acquire 2D canvas context.');
|
|
871
|
-
}
|
|
872
|
-
return ctx;
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
private static searchHitAt(result: null | SearchResult, index: number): null | SearchMatch {
|
|
876
|
-
return result?.positions[index] ?? null;
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
private static searchHitContainsCell(
|
|
880
|
-
hit: SearchMatch,
|
|
881
|
-
query: string,
|
|
882
|
-
row: number,
|
|
883
|
-
col: number,
|
|
884
|
-
): boolean {
|
|
885
|
-
return (
|
|
886
|
-
hit.matrix_type === MATRIX_TYPE.NUCLEOTIDE
|
|
887
|
-
&& hit.row === row
|
|
888
|
-
&& col >= hit.col
|
|
889
|
-
&& col < hit.col + Math.max(1, query.length)
|
|
890
|
-
);
|
|
891
|
-
}
|
|
892
|
-
}
|