@affino/datagrid-chrome 0.1.1
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 +21 -0
- package/dist/contracts.d.ts +62 -0
- package/dist/contracts.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.js +126 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 affino
|
|
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.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type DataGridChromeRowMetric = {
|
|
2
|
+
top: number;
|
|
3
|
+
height: number;
|
|
4
|
+
};
|
|
5
|
+
export type DataGridChromeLine = {
|
|
6
|
+
position: number;
|
|
7
|
+
};
|
|
8
|
+
export type DataGridChromeVisibleRange = {
|
|
9
|
+
start: number;
|
|
10
|
+
end: number;
|
|
11
|
+
};
|
|
12
|
+
export type DataGridChromeRowBand = {
|
|
13
|
+
rowIndex?: number;
|
|
14
|
+
top: number;
|
|
15
|
+
height: number;
|
|
16
|
+
kind: string;
|
|
17
|
+
};
|
|
18
|
+
export type DataGridChromeBand = {
|
|
19
|
+
top: number;
|
|
20
|
+
height: number;
|
|
21
|
+
kind: string;
|
|
22
|
+
};
|
|
23
|
+
export type DataGridChromePaneModel = {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
bands: readonly DataGridChromeBand[];
|
|
27
|
+
horizontalLines: readonly DataGridChromeLine[];
|
|
28
|
+
verticalLines: readonly DataGridChromeLine[];
|
|
29
|
+
};
|
|
30
|
+
export type DataGridChromeRenderModel = {
|
|
31
|
+
left: DataGridChromePaneModel;
|
|
32
|
+
center: DataGridChromePaneModel;
|
|
33
|
+
right: DataGridChromePaneModel;
|
|
34
|
+
};
|
|
35
|
+
export type BuildDataGridChromePaneModelInput = {
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
rowMetrics: readonly DataGridChromeRowMetric[];
|
|
39
|
+
rowBands?: readonly DataGridChromeRowBand[];
|
|
40
|
+
visibleRowRange?: DataGridChromeVisibleRange | null;
|
|
41
|
+
scrollTop?: number;
|
|
42
|
+
columnWidths: readonly number[];
|
|
43
|
+
visibleColumnRange?: DataGridChromeVisibleRange | null;
|
|
44
|
+
scrollLeft?: number;
|
|
45
|
+
};
|
|
46
|
+
export type BuildDataGridChromeRenderModelInput = {
|
|
47
|
+
rowMetrics: readonly DataGridChromeRowMetric[];
|
|
48
|
+
rowBands?: readonly DataGridChromeRowBand[];
|
|
49
|
+
visibleRowRange?: DataGridChromeVisibleRange | null;
|
|
50
|
+
scrollTop?: number;
|
|
51
|
+
leftPaneWidth: number;
|
|
52
|
+
centerPaneWidth: number;
|
|
53
|
+
rightPaneWidth: number;
|
|
54
|
+
viewportHeight: number;
|
|
55
|
+
leftColumnWidths: readonly number[];
|
|
56
|
+
leftVisibleColumnRange?: DataGridChromeVisibleRange | null;
|
|
57
|
+
centerColumnWidths: readonly number[];
|
|
58
|
+
centerVisibleColumnRange?: DataGridChromeVisibleRange | null;
|
|
59
|
+
rightColumnWidths: readonly number[];
|
|
60
|
+
rightVisibleColumnRange?: DataGridChromeVisibleRange | null;
|
|
61
|
+
centerScrollLeft?: number;
|
|
62
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { DataGridChromeBand, BuildDataGridChromePaneModelInput, BuildDataGridChromeRenderModelInput, DataGridChromeLine, DataGridChromePaneModel, DataGridChromeRenderModel, DataGridChromeRowBand, DataGridChromeRowMetric, DataGridChromeVisibleRange, } from "./contracts.js";
|
|
2
|
+
export { buildDataGridChromePaneModel, buildDataGridChromeRenderModel, } from "./runtime.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { buildDataGridChromePaneModel, buildDataGridChromeRenderModel, } from "./runtime.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BuildDataGridChromePaneModelInput, BuildDataGridChromeRenderModelInput, DataGridChromePaneModel, DataGridChromeRenderModel } from "./contracts.js";
|
|
2
|
+
export declare function buildDataGridChromePaneModel(input: BuildDataGridChromePaneModelInput): DataGridChromePaneModel;
|
|
3
|
+
export declare function buildDataGridChromeRenderModel(input: BuildDataGridChromeRenderModelInput): DataGridChromeRenderModel;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
function normalizeDimension(value) {
|
|
2
|
+
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
3
|
+
}
|
|
4
|
+
function normalizeVisibleRange(range, length) {
|
|
5
|
+
if (!range || length <= 0) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const start = Math.max(0, Math.min(length - 1, Math.floor(range.start)));
|
|
9
|
+
const end = Math.max(start, Math.min(length - 1, Math.floor(range.end)));
|
|
10
|
+
return { start, end };
|
|
11
|
+
}
|
|
12
|
+
export function buildDataGridChromePaneModel(input) {
|
|
13
|
+
const width = normalizeDimension(input.width);
|
|
14
|
+
const height = normalizeDimension(input.height);
|
|
15
|
+
const scrollTop = Number.isFinite(input.scrollTop) ? input.scrollTop ?? 0 : 0;
|
|
16
|
+
const scrollLeft = Number.isFinite(input.scrollLeft) ? input.scrollLeft ?? 0 : 0;
|
|
17
|
+
const visibleRowRange = normalizeVisibleRange(input.visibleRowRange, input.rowMetrics.length);
|
|
18
|
+
const visibleColumnRange = normalizeVisibleRange(input.visibleColumnRange, input.columnWidths.length);
|
|
19
|
+
let currentX = 0;
|
|
20
|
+
const columnStart = visibleColumnRange?.start ?? 0;
|
|
21
|
+
const columnEnd = visibleColumnRange?.end ?? (input.columnWidths.length - 1);
|
|
22
|
+
for (let index = 0; index < columnStart; index += 1) {
|
|
23
|
+
const columnWidth = input.columnWidths[index];
|
|
24
|
+
if (columnWidth == null) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (Number.isFinite(columnWidth) && columnWidth > 0) {
|
|
28
|
+
currentX += columnWidth;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const verticalLines = [];
|
|
32
|
+
for (let index = columnStart; index <= columnEnd; index += 1) {
|
|
33
|
+
const columnWidth = input.columnWidths[index];
|
|
34
|
+
if (columnWidth == null) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (!Number.isFinite(columnWidth) || columnWidth <= 0) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
currentX += columnWidth;
|
|
41
|
+
verticalLines.push({
|
|
42
|
+
position: currentX - scrollLeft,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const rowStart = visibleRowRange?.start ?? 0;
|
|
46
|
+
const rowEnd = visibleRowRange?.end ?? (input.rowMetrics.length - 1);
|
|
47
|
+
const horizontalLines = [];
|
|
48
|
+
for (let index = rowStart; index <= rowEnd; index += 1) {
|
|
49
|
+
const metric = input.rowMetrics[index];
|
|
50
|
+
if (!metric) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (!Number.isFinite(metric.top) || !Number.isFinite(metric.height) || metric.height <= 0) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
horizontalLines.push({
|
|
57
|
+
position: (metric.top + metric.height) - scrollTop,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const bands = [];
|
|
61
|
+
const rowBands = input.rowBands ?? [];
|
|
62
|
+
for (let index = 0; index < rowBands.length; index += 1) {
|
|
63
|
+
const band = rowBands[index];
|
|
64
|
+
if (!band) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const bandRowIndex = Number.isFinite(band.rowIndex) ? Math.floor(band.rowIndex) : index;
|
|
68
|
+
if (bandRowIndex < rowStart || bandRowIndex > rowEnd) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (!Number.isFinite(band.top)
|
|
72
|
+
|| !Number.isFinite(band.height)
|
|
73
|
+
|| band.height <= 0
|
|
74
|
+
|| typeof band.kind !== "string"
|
|
75
|
+
|| band.kind.length === 0) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
bands.push({
|
|
79
|
+
top: band.top - scrollTop,
|
|
80
|
+
height: band.height,
|
|
81
|
+
kind: band.kind,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
width,
|
|
86
|
+
height,
|
|
87
|
+
bands,
|
|
88
|
+
horizontalLines,
|
|
89
|
+
verticalLines,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function buildDataGridChromeRenderModel(input) {
|
|
93
|
+
return {
|
|
94
|
+
left: buildDataGridChromePaneModel({
|
|
95
|
+
width: input.leftPaneWidth,
|
|
96
|
+
height: input.viewportHeight,
|
|
97
|
+
rowMetrics: input.rowMetrics,
|
|
98
|
+
rowBands: input.rowBands,
|
|
99
|
+
visibleRowRange: input.visibleRowRange,
|
|
100
|
+
scrollTop: input.scrollTop,
|
|
101
|
+
columnWidths: input.leftColumnWidths,
|
|
102
|
+
visibleColumnRange: input.leftVisibleColumnRange,
|
|
103
|
+
}),
|
|
104
|
+
center: buildDataGridChromePaneModel({
|
|
105
|
+
width: input.centerPaneWidth,
|
|
106
|
+
height: input.viewportHeight,
|
|
107
|
+
rowMetrics: input.rowMetrics,
|
|
108
|
+
rowBands: input.rowBands,
|
|
109
|
+
visibleRowRange: input.visibleRowRange,
|
|
110
|
+
scrollTop: input.scrollTop,
|
|
111
|
+
columnWidths: input.centerColumnWidths,
|
|
112
|
+
visibleColumnRange: input.centerVisibleColumnRange,
|
|
113
|
+
scrollLeft: input.centerScrollLeft,
|
|
114
|
+
}),
|
|
115
|
+
right: buildDataGridChromePaneModel({
|
|
116
|
+
width: input.rightPaneWidth,
|
|
117
|
+
height: input.viewportHeight,
|
|
118
|
+
rowMetrics: input.rowMetrics,
|
|
119
|
+
rowBands: input.rowBands,
|
|
120
|
+
visibleRowRange: input.visibleRowRange,
|
|
121
|
+
scrollTop: input.scrollTop,
|
|
122
|
+
columnWidths: input.rightColumnWidths,
|
|
123
|
+
visibleColumnRange: input.rightVisibleColumnRange,
|
|
124
|
+
}),
|
|
125
|
+
};
|
|
126
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@affino/datagrid-chrome",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"author": "Anton Pavlov <a.pavlov@affino.dev>",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Headless grid chrome geometry engine for Affino DataGrid",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/affinio/affinio.git",
|
|
22
|
+
"directory": "packages/datagrid-chrome"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/affinio/affinio/tree/main/packages/datagrid-chrome#readme",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"datagrid",
|
|
28
|
+
"chrome",
|
|
29
|
+
"grid",
|
|
30
|
+
"engine",
|
|
31
|
+
"headless"
|
|
32
|
+
],
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"vitest": "^4.0.18"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/affinio/affinio/issues"
|
|
38
|
+
},
|
|
39
|
+
"module": "dist/index.js",
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc -p tsconfig.json",
|
|
42
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
43
|
+
"test": "vitest run --passWithNoTests"
|
|
44
|
+
}
|
|
45
|
+
}
|