uplot-webgpu 0.1.0 → 0.2.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/index.js +0 -17
- package/index.ts +5 -0
- package/package.json +4 -69
- package/paths/ts/bars.ts +253 -0
- package/paths/ts/catmullRomCentrip.ts +127 -0
- package/paths/ts/index.ts +9 -0
- package/paths/ts/linear.ts +172 -0
- package/paths/ts/monotoneCubic.ts +70 -0
- package/paths/ts/points.ts +70 -0
- package/paths/ts/spline.ts +105 -0
- package/paths/ts/stepped.ts +126 -0
- package/paths/ts/types.ts +143 -0
- package/paths/ts/utils.ts +303 -0
- package/scripts/ts/uPlot.ts +3732 -0
- package/scripts/ts/utils/dom.ts +124 -0
- package/scripts/ts/utils/domClasses.ts +22 -0
- package/scripts/ts/utils/feats.ts +13 -0
- package/scripts/ts/utils/fmtDate.ts +398 -0
- package/scripts/ts/utils/opts.ts +844 -0
- package/scripts/ts/utils/strings.ts +22 -0
- package/scripts/ts/utils/sync.ts +27 -0
- package/scripts/ts/utils/utils.ts +692 -0
- package/scripts/{webgpu → ts/webgpu}/GPUPath.ts +92 -41
- package/scripts/{webgpu → ts/webgpu}/WebGPURenderer.ts +176 -84
- package/scripts/ts/webgpu/exporters.ts +221 -0
- package/scripts/ts/webgpu/index.ts +31 -0
- package/scripts/{webgpu → ts/webgpu}/shaders.ts +0 -1
- package/scripts/uPlot.js +0 -2
- package/scripts/webgpu/GPUPath.js +513 -606
- package/scripts/webgpu/WebGPURenderer.js +3484 -4018
- package/scripts/webgpu/exporters.js +191 -201
- package/scripts/webgpu/index.js +12 -0
- package/scripts/webgpu/shaders.js +6 -3
- package/tinybuild.config.js +6 -6
- package/tsconfig.json +64 -0
- package/scripts/uPlot.d.ts +0 -26
- package/scripts/webgpu/GPUPath.d.ts +0 -46
- package/scripts/webgpu/WebGPURenderer.d.ts +0 -176
- package/scripts/webgpu/exporters.d.ts +0 -8
- package/scripts/webgpu/shaders.d.ts +0 -2
- package/scripts/webgpu/smokeTest.d.ts +0 -2
- package/scripts/webgpu/webgpu-ambient.d.ts +0 -41
|
@@ -1,16 +1,58 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
const TAU = Math.PI * 2;
|
|
3
2
|
const EPS = 1e-9;
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type Matrix2DArray = [number, number, number, number, number, number];
|
|
5
|
+
export type GPUPathPoint = [number, number];
|
|
6
|
+
export type GPUPathArcFlag = 0 | 1;
|
|
7
|
+
export type GPUPathMoveCommand = [0, number, number];
|
|
8
|
+
export type GPUPathLineCommand = [1, number, number];
|
|
9
|
+
export type GPUPathCubicCommand = [2, number, number, number, number, number, number];
|
|
10
|
+
export type GPUPathArcCommand = [3, number, number, number, number, number, GPUPathArcFlag];
|
|
11
|
+
export type GPUPathRectCommand = [4, number, number, number, number];
|
|
12
|
+
export type GPUPathCloseCommand = [5];
|
|
13
|
+
export type GPUPathEllipseCommand = [6, number, number, number, number, number, number, number, GPUPathArcFlag];
|
|
14
|
+
|
|
15
|
+
export type GPUPathCommand =
|
|
16
|
+
| GPUPathMoveCommand
|
|
17
|
+
| GPUPathLineCommand
|
|
18
|
+
| GPUPathCubicCommand
|
|
19
|
+
| GPUPathArcCommand
|
|
20
|
+
| GPUPathRectCommand
|
|
21
|
+
| GPUPathCloseCommand
|
|
22
|
+
| GPUPathEllipseCommand;
|
|
23
|
+
|
|
24
|
+
export interface GPUPathBounds {
|
|
25
|
+
minX: number;
|
|
26
|
+
minY: number;
|
|
27
|
+
maxX: number;
|
|
28
|
+
maxY: number;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
7
31
|
}
|
|
8
32
|
|
|
9
|
-
|
|
33
|
+
export interface GPUPathRect {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
w: number;
|
|
37
|
+
h: number;
|
|
38
|
+
winding: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type GPUPathSubpath = GPUPathPoint[] & {closed?: boolean};
|
|
42
|
+
export interface GPUPathLike {
|
|
43
|
+
cmds?: GPUPathCommand[];
|
|
44
|
+
toSubpaths?: (curveSteps?: number) => GPUPathSubpath[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function cloneCommand(cmd: GPUPathCommand): GPUPathCommand {
|
|
48
|
+
return cmd.slice() as GPUPathCommand;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isFiniteNumber(v: unknown): v is number {
|
|
10
52
|
return typeof v == 'number' && Number.isFinite(v);
|
|
11
53
|
}
|
|
12
54
|
|
|
13
|
-
function allFinite(vals) {
|
|
55
|
+
function allFinite(vals: readonly unknown[]): vals is readonly number[] {
|
|
14
56
|
for (let v of vals) {
|
|
15
57
|
if (!isFiniteNumber(v))
|
|
16
58
|
return false;
|
|
@@ -18,18 +60,18 @@ function allFinite(vals) {
|
|
|
18
60
|
return true;
|
|
19
61
|
}
|
|
20
62
|
|
|
21
|
-
function dist(a, b, c, d) {
|
|
63
|
+
function dist(a: number, b: number, c: number, d: number): number {
|
|
22
64
|
let dx = c - a;
|
|
23
65
|
let dy = d - b;
|
|
24
66
|
return Math.sqrt(dx * dx + dy * dy);
|
|
25
67
|
}
|
|
26
68
|
|
|
27
|
-
function cubicAt(a, b, c, d, t) {
|
|
69
|
+
function cubicAt(a: number, b: number, c: number, d: number, t: number): number {
|
|
28
70
|
let mt = 1 - t;
|
|
29
71
|
return mt * mt * mt * a + 3 * mt * mt * t * b + 3 * mt * t * t * c + t * t * t * d;
|
|
30
72
|
}
|
|
31
73
|
|
|
32
|
-
function normalizeAngle(a) {
|
|
74
|
+
function normalizeAngle(a: number): number {
|
|
33
75
|
while (a < 0)
|
|
34
76
|
a += TAU;
|
|
35
77
|
while (a >= TAU)
|
|
@@ -37,7 +79,7 @@ function normalizeAngle(a) {
|
|
|
37
79
|
return a;
|
|
38
80
|
}
|
|
39
81
|
|
|
40
|
-
function arcSweep(start, end, ccw) {
|
|
82
|
+
function arcSweep(start: number, end: number, ccw: boolean): number {
|
|
41
83
|
let raw = end - start;
|
|
42
84
|
|
|
43
85
|
if (!Number.isFinite(raw))
|
|
@@ -62,27 +104,29 @@ function arcSweep(start, end, ccw) {
|
|
|
62
104
|
}
|
|
63
105
|
|
|
64
106
|
|
|
65
|
-
function matrixFrom(transform) {
|
|
107
|
+
function matrixFrom(transform: DOMMatrix | DOMMatrix2DInit | readonly number[] | null | undefined): Matrix2DArray | null {
|
|
66
108
|
if (transform == null)
|
|
67
109
|
return null;
|
|
68
110
|
|
|
69
|
-
if (Array.isArray(transform))
|
|
70
|
-
return transform;
|
|
111
|
+
if (Array.isArray(transform) && transform.length >= 6)
|
|
112
|
+
return transform.slice(0, 6) as Matrix2DArray;
|
|
71
113
|
|
|
72
114
|
if (typeof DOMMatrix != 'undefined' && transform instanceof DOMMatrix)
|
|
73
115
|
return [transform.a, transform.b, transform.c, transform.d, transform.e, transform.f];
|
|
74
116
|
|
|
75
|
-
if (typeof transform == 'object')
|
|
76
|
-
|
|
117
|
+
if (typeof transform == 'object') {
|
|
118
|
+
let m = transform as DOMMatrix2DInit;
|
|
119
|
+
return [m.a ?? 1, m.b ?? 0, m.c ?? 0, m.d ?? 1, m.e ?? 0, m.f ?? 0];
|
|
120
|
+
}
|
|
77
121
|
|
|
78
122
|
return null;
|
|
79
123
|
}
|
|
80
124
|
|
|
81
|
-
function applyMatrix(m, x, y) {
|
|
125
|
+
function applyMatrix(m: Matrix2DArray, x: number, y: number): GPUPathPoint {
|
|
82
126
|
return [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
|
|
83
127
|
}
|
|
84
128
|
|
|
85
|
-
function ellipsePoint(cx, cy, rx, ry, rotation, angle) {
|
|
129
|
+
function ellipsePoint(cx: number, cy: number, rx: number, ry: number, rotation: number, angle: number): GPUPathPoint {
|
|
86
130
|
let ca = Math.cos(angle);
|
|
87
131
|
let sa = Math.sin(angle);
|
|
88
132
|
let cr = Math.cos(rotation);
|
|
@@ -92,7 +136,7 @@ function ellipsePoint(cx, cy, rx, ry, rotation, angle) {
|
|
|
92
136
|
return [cx + x * cr - y * sr, cy + x * sr + y * cr];
|
|
93
137
|
}
|
|
94
138
|
|
|
95
|
-
function normalizeRadii(radii) {
|
|
139
|
+
function normalizeRadii(radii: number | number[] | DOMPointInit | DOMPointInit[] | null | undefined): [number, number, number, number] {
|
|
96
140
|
if (radii == null)
|
|
97
141
|
return [0, 0, 0, 0];
|
|
98
142
|
|
|
@@ -100,7 +144,7 @@ function normalizeRadii(radii) {
|
|
|
100
144
|
return [radii, radii, radii, radii];
|
|
101
145
|
|
|
102
146
|
let arr = Array.isArray(radii) ? radii : [radii];
|
|
103
|
-
let vals = arr.map(v => typeof v == 'number' ? v : Math.max(v
|
|
147
|
+
let vals = arr.map(v => typeof v == 'number' ? v : Math.max(v?.x || 0, v?.y || 0));
|
|
104
148
|
|
|
105
149
|
if (vals.length == 1)
|
|
106
150
|
return [vals[0], vals[0], vals[0], vals[0]];
|
|
@@ -112,7 +156,7 @@ function normalizeRadii(radii) {
|
|
|
112
156
|
return [vals[0], vals[1], vals[2], vals[3]];
|
|
113
157
|
}
|
|
114
158
|
|
|
115
|
-
function pushPoint(points, x, y) {
|
|
159
|
+
function pushPoint(points: GPUPathSubpath, x: number, y: number): void {
|
|
116
160
|
let p = points[points.length - 1];
|
|
117
161
|
|
|
118
162
|
if (p == null || Math.abs(p[0] - x) > EPS || Math.abs(p[1] - y) > EPS)
|
|
@@ -120,7 +164,14 @@ function pushPoint(points, x, y) {
|
|
|
120
164
|
}
|
|
121
165
|
|
|
122
166
|
export class GPUPath {
|
|
123
|
-
|
|
167
|
+
cmds: GPUPathCommand[];
|
|
168
|
+
commands?: GPUPathCommand[];
|
|
169
|
+
_x?: number;
|
|
170
|
+
_y?: number;
|
|
171
|
+
_sx?: number;
|
|
172
|
+
_sy?: number;
|
|
173
|
+
_hasPoint?: boolean;
|
|
174
|
+
constructor(copyFrom: GPUPathLike | null = null) {
|
|
124
175
|
this.cmds = [];
|
|
125
176
|
this._x = 0;
|
|
126
177
|
this._y = 0;
|
|
@@ -147,7 +198,7 @@ export class GPUPath {
|
|
|
147
198
|
return this;
|
|
148
199
|
}
|
|
149
200
|
|
|
150
|
-
syncCurrentFromCommands() {
|
|
201
|
+
syncCurrentFromCommands(): void {
|
|
151
202
|
this._x = 0;
|
|
152
203
|
this._y = 0;
|
|
153
204
|
this._sx = 0;
|
|
@@ -216,7 +267,7 @@ export class GPUPath {
|
|
|
216
267
|
}
|
|
217
268
|
}
|
|
218
269
|
|
|
219
|
-
moveTo(x, y) {
|
|
270
|
+
moveTo(x: number, y: number): void {
|
|
220
271
|
if (!allFinite([x, y]))
|
|
221
272
|
return;
|
|
222
273
|
this.cmds.push([0, x, y]);
|
|
@@ -225,7 +276,7 @@ export class GPUPath {
|
|
|
225
276
|
this._hasPoint = true;
|
|
226
277
|
}
|
|
227
278
|
|
|
228
|
-
lineTo(x, y) {
|
|
279
|
+
lineTo(x: number, y: number): void {
|
|
229
280
|
if (!allFinite([x, y]))
|
|
230
281
|
return;
|
|
231
282
|
if (!this._hasPoint)
|
|
@@ -237,7 +288,7 @@ export class GPUPath {
|
|
|
237
288
|
}
|
|
238
289
|
}
|
|
239
290
|
|
|
240
|
-
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
291
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void {
|
|
241
292
|
if (!allFinite([cp1x, cp1y, cp2x, cp2y, x, y]))
|
|
242
293
|
return;
|
|
243
294
|
if (!this._hasPoint)
|
|
@@ -249,7 +300,7 @@ export class GPUPath {
|
|
|
249
300
|
}
|
|
250
301
|
}
|
|
251
302
|
|
|
252
|
-
quadraticCurveTo(cpx, cpy, x, y) {
|
|
303
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void {
|
|
253
304
|
if (!allFinite([cpx, cpy, x, y]))
|
|
254
305
|
return;
|
|
255
306
|
if (!this._hasPoint)
|
|
@@ -263,7 +314,7 @@ export class GPUPath {
|
|
|
263
314
|
}
|
|
264
315
|
}
|
|
265
316
|
|
|
266
|
-
arc(x, y, r, startAngle, endAngle, counterclockwise = false) {
|
|
317
|
+
arc(x: number, y: number, r: number, startAngle: number, endAngle: number, counterclockwise = false): void {
|
|
267
318
|
if (!allFinite([x, y, r, startAngle, endAngle]) || r <= 0)
|
|
268
319
|
return;
|
|
269
320
|
|
|
@@ -282,7 +333,7 @@ export class GPUPath {
|
|
|
282
333
|
this._y = ey;
|
|
283
334
|
}
|
|
284
335
|
|
|
285
|
-
ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise = false) {
|
|
336
|
+
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise = false): void {
|
|
286
337
|
if (!allFinite([x, y, radiusX, radiusY, rotation, startAngle, endAngle]) || radiusX <= 0 || radiusY <= 0)
|
|
287
338
|
return;
|
|
288
339
|
|
|
@@ -301,7 +352,7 @@ export class GPUPath {
|
|
|
301
352
|
this._y = end[1];
|
|
302
353
|
}
|
|
303
354
|
|
|
304
|
-
roundRect(x, y, w, h, radii = 0) {
|
|
355
|
+
roundRect(x: number, y: number, w: number, h: number, radii: number | number[] | DOMPointInit | DOMPointInit[] = 0): void {
|
|
305
356
|
if (!allFinite([x, y, w, h]))
|
|
306
357
|
return;
|
|
307
358
|
let [tl, tr, br, bl] = normalizeRadii(radii);
|
|
@@ -333,7 +384,7 @@ export class GPUPath {
|
|
|
333
384
|
this.closePath();
|
|
334
385
|
}
|
|
335
386
|
|
|
336
|
-
arcTo(x1, y1, x2, y2, r) {
|
|
387
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, r: number): void {
|
|
337
388
|
if (!allFinite([x1, y1, x2, y2, r]))
|
|
338
389
|
return;
|
|
339
390
|
if (!this._hasPoint || r <= 0) {
|
|
@@ -393,7 +444,7 @@ export class GPUPath {
|
|
|
393
444
|
this.arc(cx, cy, r, start, end, cross < 0);
|
|
394
445
|
}
|
|
395
446
|
|
|
396
|
-
rect(x, y, w, h) {
|
|
447
|
+
rect(x: number, y: number, w: number, h: number): void {
|
|
397
448
|
if (!allFinite([x, y, w, h]))
|
|
398
449
|
return;
|
|
399
450
|
this.cmds.push([4, x, y, w, h]);
|
|
@@ -404,7 +455,7 @@ export class GPUPath {
|
|
|
404
455
|
this._hasPoint = true;
|
|
405
456
|
}
|
|
406
457
|
|
|
407
|
-
closePath() {
|
|
458
|
+
closePath(): void {
|
|
408
459
|
if (!this._hasPoint)
|
|
409
460
|
return;
|
|
410
461
|
this.cmds.push([5]);
|
|
@@ -412,15 +463,15 @@ export class GPUPath {
|
|
|
412
463
|
this._y = this._sy;
|
|
413
464
|
}
|
|
414
465
|
|
|
415
|
-
isEmpty() {
|
|
466
|
+
isEmpty(): boolean {
|
|
416
467
|
return this.cmds.length == 0;
|
|
417
468
|
}
|
|
418
469
|
|
|
419
|
-
clone() {
|
|
470
|
+
clone(): GPUPath {
|
|
420
471
|
return new GPUPath(this);
|
|
421
472
|
}
|
|
422
473
|
|
|
423
|
-
addPath(path, transform = null) {
|
|
474
|
+
addPath(path: GPUPathLike | null | undefined, transform: DOMMatrix | DOMMatrix2DInit | readonly number[] | null = null): void {
|
|
424
475
|
if (path == null)
|
|
425
476
|
return;
|
|
426
477
|
|
|
@@ -448,8 +499,8 @@ export class GPUPath {
|
|
|
448
499
|
}
|
|
449
500
|
}
|
|
450
501
|
|
|
451
|
-
getRects() {
|
|
452
|
-
let rects = [];
|
|
502
|
+
getRects(): GPUPathRect[] | null {
|
|
503
|
+
let rects: GPUPathRect[] = [];
|
|
453
504
|
|
|
454
505
|
for (let cmd of this.cmds) {
|
|
455
506
|
if (cmd[0] != 4)
|
|
@@ -477,16 +528,16 @@ export class GPUPath {
|
|
|
477
528
|
return rects;
|
|
478
529
|
}
|
|
479
530
|
|
|
480
|
-
toSubpaths(curveSteps = 12) {
|
|
481
|
-
let paths = [];
|
|
482
|
-
let pts = [];
|
|
531
|
+
toSubpaths(curveSteps = 12): GPUPathSubpath[] {
|
|
532
|
+
let paths: GPUPathSubpath[] = [];
|
|
533
|
+
let pts: GPUPathSubpath = [];
|
|
483
534
|
let x = 0;
|
|
484
535
|
let y = 0;
|
|
485
536
|
let sx = 0;
|
|
486
537
|
let sy = 0;
|
|
487
538
|
let hasPoint = false;
|
|
488
539
|
|
|
489
|
-
function flush(closed = false) {
|
|
540
|
+
function flush(closed = false): void {
|
|
490
541
|
if (pts.length > 0) {
|
|
491
542
|
pts.closed = closed;
|
|
492
543
|
paths.push(pts);
|
|
@@ -609,7 +660,7 @@ export class GPUPath {
|
|
|
609
660
|
let ry = cmd[2];
|
|
610
661
|
let rw = cmd[3];
|
|
611
662
|
let rh = cmd[4];
|
|
612
|
-
pts = [[rx, ry], [rx + rw, ry], [rx + rw, ry + rh], [rx, ry + rh], [rx, ry]];
|
|
663
|
+
pts = [[rx, ry], [rx + rw, ry], [rx + rw, ry + rh], [rx, ry + rh], [rx, ry]] as GPUPathSubpath;
|
|
613
664
|
flush(true);
|
|
614
665
|
x = sx = rx;
|
|
615
666
|
y = sy = ry;
|