@dxos/react-ui-canvas 0.8.2-staging.7ac8446 → 0.8.2
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/lib/browser/index.mjs +349 -299
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +340 -290
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +349 -299
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FPS.d.ts.map +1 -1
- package/dist/types/src/components/Grid/Grid.d.ts.map +1 -1
- package/dist/types/src/hooks/projection.d.ts.map +1 -1
- package/dist/types/src/hooks/useWheel.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +16 -16
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util/svg.d.ts.map +1 -1
- package/dist/types/src/util/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -13
- package/src/hooks/projection.tsx +8 -8
- package/src/types.ts +7 -7
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// packages/ui/react-ui-canvas/src/components/Canvas/Canvas.tsx
|
|
2
|
+
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
2
3
|
import React2, { forwardRef, useEffect as useEffect2, useImperativeHandle, useMemo, useState } from "react";
|
|
3
4
|
import { useResizeDetector } from "react-resize-detector";
|
|
4
5
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
5
6
|
|
|
6
7
|
// packages/ui/react-ui-canvas/src/hooks/projection.tsx
|
|
7
|
-
import
|
|
8
|
+
import { interpolate, interpolateObject, transition, easeSinOut } from "d3";
|
|
8
9
|
import { applyToPoints, compose, identity, inverse, scale as scaleMatrix, translate as translateMatrix } from "transformation-matrix";
|
|
9
10
|
var defaultOrigin = {
|
|
10
11
|
x: 0,
|
|
@@ -62,8 +63,8 @@ var getZoomTransform = ({ scale, offset, pos, newScale }) => {
|
|
|
62
63
|
};
|
|
63
64
|
};
|
|
64
65
|
var zoomInPlace = (setTransform, pos, offset, current, next, delay = 200) => {
|
|
65
|
-
const is =
|
|
66
|
-
|
|
66
|
+
const is = interpolate(current, next);
|
|
67
|
+
transition().ease(easeSinOut).duration(delay).tween("zoom", () => (t) => {
|
|
67
68
|
const newScale = is(t);
|
|
68
69
|
setTransform(getZoomTransform({
|
|
69
70
|
scale: current,
|
|
@@ -76,14 +77,14 @@ var zoomInPlace = (setTransform, pos, offset, current, next, delay = 200) => {
|
|
|
76
77
|
var noop = () => {
|
|
77
78
|
};
|
|
78
79
|
var zoomTo = (setTransform, current, next, delay = 200, cb = noop) => {
|
|
79
|
-
const is =
|
|
80
|
+
const is = interpolateObject({
|
|
80
81
|
scale: current.scale,
|
|
81
82
|
...current.offset
|
|
82
83
|
}, {
|
|
83
84
|
scale: next.scale,
|
|
84
85
|
...next.offset
|
|
85
86
|
});
|
|
86
|
-
|
|
87
|
+
transition().ease(easeSinOut).duration(delay).tween("zoom", () => (t) => {
|
|
87
88
|
const { scale, x, y } = is(t);
|
|
88
89
|
setTransform({
|
|
89
90
|
scale,
|
|
@@ -108,6 +109,7 @@ import { bindAll } from "bind-event-listener";
|
|
|
108
109
|
import { useEffect } from "react";
|
|
109
110
|
|
|
110
111
|
// packages/ui/react-ui-canvas/src/util/svg.tsx
|
|
112
|
+
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
111
113
|
import React from "react";
|
|
112
114
|
import { mx } from "@dxos/react-ui-theme";
|
|
113
115
|
var createPath = (points, join = false) => {
|
|
@@ -118,118 +120,144 @@ var createPath = (points, join = false) => {
|
|
|
118
120
|
].join(" ");
|
|
119
121
|
};
|
|
120
122
|
var Markers = ({ id = "dx-marker", classNames }) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
123
|
+
var _effect = _useSignals();
|
|
124
|
+
try {
|
|
125
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Arrow, {
|
|
126
|
+
id: `${id}-arrow-start`,
|
|
127
|
+
dir: "start",
|
|
128
|
+
classNames
|
|
129
|
+
}), /* @__PURE__ */ React.createElement(Arrow, {
|
|
130
|
+
id: `${id}-arrow-end`,
|
|
131
|
+
dir: "end",
|
|
132
|
+
classNames
|
|
133
|
+
}), /* @__PURE__ */ React.createElement(Arrow, {
|
|
134
|
+
id: `${id}-triangle-start`,
|
|
135
|
+
dir: "start",
|
|
136
|
+
closed: true,
|
|
137
|
+
classNames
|
|
138
|
+
}), /* @__PURE__ */ React.createElement(Arrow, {
|
|
139
|
+
id: `${id}-triangle-end`,
|
|
140
|
+
dir: "end",
|
|
141
|
+
closed: true,
|
|
142
|
+
classNames
|
|
143
|
+
}), /* @__PURE__ */ React.createElement(Marker, {
|
|
144
|
+
id: `${id}-circle`,
|
|
145
|
+
pos: {
|
|
146
|
+
x: 8,
|
|
147
|
+
y: 8
|
|
148
|
+
},
|
|
149
|
+
size: {
|
|
150
|
+
width: 16,
|
|
151
|
+
height: 16
|
|
152
|
+
}
|
|
153
|
+
}, /* @__PURE__ */ React.createElement("circle", {
|
|
154
|
+
cx: 8,
|
|
155
|
+
cy: 8,
|
|
156
|
+
r: 5,
|
|
157
|
+
stroke: "context-stroke",
|
|
158
|
+
className: mx(classNames)
|
|
159
|
+
})));
|
|
160
|
+
} finally {
|
|
161
|
+
_effect.f();
|
|
162
|
+
}
|
|
156
163
|
};
|
|
157
|
-
var Marker = ({ id, className, children, pos: { x: refX, y: refY }, size: { width: markerWidth, height: markerHeight }, fill, ...rest }) =>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
},
|
|
174
|
-
pos: dir === "end" ? {
|
|
175
|
-
x: size,
|
|
176
|
-
y: size / 2
|
|
177
|
-
} : {
|
|
178
|
-
x: 0,
|
|
179
|
-
y: size / 2
|
|
164
|
+
var Marker = ({ id, className, children, pos: { x: refX, y: refY }, size: { width: markerWidth, height: markerHeight }, fill, ...rest }) => {
|
|
165
|
+
var _effect = _useSignals();
|
|
166
|
+
try {
|
|
167
|
+
return /* @__PURE__ */ React.createElement("marker", {
|
|
168
|
+
id,
|
|
169
|
+
className,
|
|
170
|
+
refX,
|
|
171
|
+
refY,
|
|
172
|
+
markerWidth,
|
|
173
|
+
markerHeight,
|
|
174
|
+
markerUnits: "strokeWidth",
|
|
175
|
+
orient: "auto",
|
|
176
|
+
...rest
|
|
177
|
+
}, children);
|
|
178
|
+
} finally {
|
|
179
|
+
_effect.f();
|
|
180
180
|
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
181
|
+
};
|
|
182
|
+
var Arrow = ({ classNames, id, size = 16, dir = "end", closed = false }) => {
|
|
183
|
+
var _effect = _useSignals();
|
|
184
|
+
try {
|
|
185
|
+
return /* @__PURE__ */ React.createElement(Marker, {
|
|
186
|
+
id,
|
|
187
|
+
size: {
|
|
188
|
+
width: size,
|
|
189
|
+
height: size
|
|
190
|
+
},
|
|
191
|
+
pos: dir === "end" ? {
|
|
192
|
+
x: size,
|
|
193
|
+
y: size / 2
|
|
194
|
+
} : {
|
|
195
|
+
x: 0,
|
|
196
|
+
y: size / 2
|
|
197
|
+
}
|
|
198
|
+
}, /* @__PURE__ */ React.createElement("path", {
|
|
199
|
+
fill: closed ? void 0 : "none",
|
|
200
|
+
stroke: "context-stroke",
|
|
201
|
+
className: mx(classNames),
|
|
202
|
+
d: createPath(dir === "end" ? [
|
|
203
|
+
{
|
|
204
|
+
x: 1,
|
|
205
|
+
y: 1
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
x: size,
|
|
209
|
+
y: size / 2
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
x: 1,
|
|
213
|
+
y: size - 1
|
|
214
|
+
}
|
|
215
|
+
] : [
|
|
216
|
+
{
|
|
217
|
+
x: size - 1,
|
|
218
|
+
y: 1
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
x: 0,
|
|
222
|
+
y: size / 2
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
x: size - 1,
|
|
226
|
+
y: size - 1
|
|
227
|
+
}
|
|
228
|
+
], closed)
|
|
229
|
+
}));
|
|
230
|
+
} finally {
|
|
231
|
+
_effect.f();
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var GridPattern = ({ classNames, id, size, offset }) => {
|
|
235
|
+
var _effect = _useSignals();
|
|
236
|
+
try {
|
|
237
|
+
return /* @__PURE__ */ React.createElement("pattern", {
|
|
238
|
+
id,
|
|
239
|
+
x: (size / 2 + offset.x) % size,
|
|
240
|
+
y: (size / 2 + offset.y) % size,
|
|
241
|
+
width: size,
|
|
242
|
+
height: size,
|
|
243
|
+
patternUnits: "userSpaceOnUse"
|
|
244
|
+
}, /* @__PURE__ */ React.createElement("g", {
|
|
245
|
+
className: mx(classNames)
|
|
246
|
+
}, /* @__PURE__ */ React.createElement("line", {
|
|
247
|
+
x1: 0,
|
|
248
|
+
y1: size / 2,
|
|
249
|
+
x2: size,
|
|
250
|
+
y2: size / 2
|
|
251
|
+
}), /* @__PURE__ */ React.createElement("line", {
|
|
252
|
+
x1: size / 2,
|
|
253
|
+
y1: 0,
|
|
254
|
+
x2: size / 2,
|
|
255
|
+
y2: size
|
|
256
|
+
})));
|
|
257
|
+
} finally {
|
|
258
|
+
_effect.f();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
233
261
|
|
|
234
262
|
// packages/ui/react-ui-canvas/src/util/util.ts
|
|
235
263
|
var logged = false;
|
|
@@ -352,155 +380,167 @@ var hasFocus = (element) => {
|
|
|
352
380
|
|
|
353
381
|
// packages/ui/react-ui-canvas/src/components/Canvas/Canvas.tsx
|
|
354
382
|
var Canvas = /* @__PURE__ */ forwardRef(({ children, classNames, scale: _scale = 1, offset: _offset = defaultOrigin, ...props }, forwardedRef) => {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
offset
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
width,
|
|
373
|
-
height,
|
|
374
|
-
scale,
|
|
375
|
-
offset
|
|
376
|
-
]);
|
|
377
|
-
const projection = useMemo(() => new ProjectionMapper(), []);
|
|
378
|
-
useEffect2(() => {
|
|
379
|
-
projection.update({
|
|
380
|
-
width,
|
|
381
|
-
height
|
|
382
|
-
}, scale, offset);
|
|
383
|
-
if (offset !== defaultOrigin) {
|
|
384
|
-
setReady(true);
|
|
385
|
-
}
|
|
386
|
-
}, [
|
|
387
|
-
projection,
|
|
388
|
-
scale,
|
|
389
|
-
offset,
|
|
390
|
-
width,
|
|
391
|
-
height
|
|
392
|
-
]);
|
|
393
|
-
const styles = useMemo(() => {
|
|
394
|
-
return {
|
|
395
|
-
// NOTE: Order is important.
|
|
396
|
-
transform: `translate(${offset.x}px, ${offset.y}px) scale(${scale})`,
|
|
397
|
-
visibility: width && height ? "visible" : "hidden"
|
|
398
|
-
};
|
|
399
|
-
}, [
|
|
400
|
-
scale,
|
|
401
|
-
offset
|
|
402
|
-
]);
|
|
403
|
-
useImperativeHandle(forwardedRef, () => {
|
|
404
|
-
return {
|
|
405
|
-
setProjection: async (projection2) => {
|
|
406
|
-
setProjection(projection2);
|
|
383
|
+
var _effect = _useSignals2();
|
|
384
|
+
try {
|
|
385
|
+
const { ref, width = 0, height = 0 } = useResizeDetector();
|
|
386
|
+
const [ready, setReady] = useState(false);
|
|
387
|
+
const [{ scale, offset }, setProjection] = useState({
|
|
388
|
+
scale: _scale,
|
|
389
|
+
offset: _offset
|
|
390
|
+
});
|
|
391
|
+
useEffect2(() => {
|
|
392
|
+
if (width && height && offset === defaultOrigin) {
|
|
393
|
+
setProjection({
|
|
394
|
+
scale,
|
|
395
|
+
offset: {
|
|
396
|
+
x: width / 2,
|
|
397
|
+
y: height / 2
|
|
398
|
+
}
|
|
399
|
+
});
|
|
407
400
|
}
|
|
408
|
-
}
|
|
409
|
-
}, [
|
|
410
|
-
ref
|
|
411
|
-
]);
|
|
412
|
-
return /* @__PURE__ */ React2.createElement(CanvasContext.Provider, {
|
|
413
|
-
value: {
|
|
414
|
-
root: ref.current,
|
|
415
|
-
ready,
|
|
401
|
+
}, [
|
|
416
402
|
width,
|
|
417
403
|
height,
|
|
418
404
|
scale,
|
|
419
|
-
offset
|
|
420
|
-
|
|
405
|
+
offset
|
|
406
|
+
]);
|
|
407
|
+
const projection = useMemo(() => new ProjectionMapper(), []);
|
|
408
|
+
useEffect2(() => {
|
|
409
|
+
projection.update({
|
|
410
|
+
width,
|
|
411
|
+
height
|
|
412
|
+
}, scale, offset);
|
|
413
|
+
if (offset !== defaultOrigin) {
|
|
414
|
+
setReady(true);
|
|
415
|
+
}
|
|
416
|
+
}, [
|
|
421
417
|
projection,
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
418
|
+
scale,
|
|
419
|
+
offset,
|
|
420
|
+
width,
|
|
421
|
+
height
|
|
422
|
+
]);
|
|
423
|
+
const styles = useMemo(() => {
|
|
424
|
+
return {
|
|
425
|
+
// NOTE: Order is important.
|
|
426
|
+
transform: `translate(${offset.x}px, ${offset.y}px) scale(${scale})`,
|
|
427
|
+
visibility: width && height ? "visible" : "hidden"
|
|
428
|
+
};
|
|
429
|
+
}, [
|
|
430
|
+
scale,
|
|
431
|
+
offset
|
|
432
|
+
]);
|
|
433
|
+
useImperativeHandle(forwardedRef, () => {
|
|
434
|
+
return {
|
|
435
|
+
setProjection: async (projection2) => {
|
|
436
|
+
setProjection(projection2);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
}, [
|
|
440
|
+
ref
|
|
441
|
+
]);
|
|
442
|
+
return /* @__PURE__ */ React2.createElement(CanvasContext.Provider, {
|
|
443
|
+
value: {
|
|
444
|
+
root: ref.current,
|
|
445
|
+
ready,
|
|
446
|
+
width,
|
|
447
|
+
height,
|
|
448
|
+
scale,
|
|
449
|
+
offset,
|
|
450
|
+
styles,
|
|
451
|
+
projection,
|
|
452
|
+
setProjection
|
|
453
|
+
}
|
|
454
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
455
|
+
role: "none",
|
|
456
|
+
...props,
|
|
457
|
+
className: mx2("absolute inset-0 overflow-hidden", classNames),
|
|
458
|
+
ref
|
|
459
|
+
}, ready ? children : null));
|
|
460
|
+
} finally {
|
|
461
|
+
_effect.f();
|
|
462
|
+
}
|
|
430
463
|
});
|
|
431
464
|
|
|
432
465
|
// packages/ui/react-ui-canvas/src/components/FPS.tsx
|
|
466
|
+
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
|
433
467
|
import React3, { useEffect as useEffect3, useReducer, useRef } from "react";
|
|
434
468
|
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
435
469
|
var SEC = 1e3;
|
|
436
470
|
var FPS = ({ classNames, width = 60, height = 30, bar = "bg-cyan-500" }) => {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
max: 0,
|
|
462
|
-
len: 0,
|
|
463
|
-
fps: [],
|
|
464
|
-
frames: 0,
|
|
465
|
-
prevTime: Date.now()
|
|
466
|
-
});
|
|
467
|
-
const requestRef = useRef();
|
|
468
|
-
const tick = () => {
|
|
469
|
-
dispatch();
|
|
470
|
-
requestRef.current = requestAnimationFrame(tick);
|
|
471
|
-
};
|
|
472
|
-
useEffect3(() => {
|
|
473
|
-
requestRef.current = requestAnimationFrame(tick);
|
|
474
|
-
return () => {
|
|
475
|
-
if (requestRef.current) {
|
|
476
|
-
cancelAnimationFrame(requestRef.current);
|
|
471
|
+
var _effect = _useSignals3();
|
|
472
|
+
try {
|
|
473
|
+
const [{ fps, max, len }, dispatch] = useReducer((state) => {
|
|
474
|
+
const currentTime = Date.now();
|
|
475
|
+
if (currentTime > state.prevTime + SEC) {
|
|
476
|
+
const nextFPS = [
|
|
477
|
+
...new Array(Math.floor((currentTime - state.prevTime - SEC) / SEC)).fill(0),
|
|
478
|
+
Math.max(1, Math.round(state.frames * SEC / (currentTime - state.prevTime)))
|
|
479
|
+
];
|
|
480
|
+
return {
|
|
481
|
+
max: Math.max(state.max, ...nextFPS),
|
|
482
|
+
len: Math.min(state.len + nextFPS.length, width),
|
|
483
|
+
fps: [
|
|
484
|
+
...state.fps,
|
|
485
|
+
...nextFPS
|
|
486
|
+
].slice(-width),
|
|
487
|
+
frames: 1,
|
|
488
|
+
prevTime: currentTime
|
|
489
|
+
};
|
|
490
|
+
} else {
|
|
491
|
+
return {
|
|
492
|
+
...state,
|
|
493
|
+
frames: state.frames + 1
|
|
494
|
+
};
|
|
477
495
|
}
|
|
496
|
+
}, {
|
|
497
|
+
max: 0,
|
|
498
|
+
len: 0,
|
|
499
|
+
fps: [],
|
|
500
|
+
frames: 0,
|
|
501
|
+
prevTime: Date.now()
|
|
502
|
+
});
|
|
503
|
+
const requestRef = useRef();
|
|
504
|
+
const tick = () => {
|
|
505
|
+
dispatch();
|
|
506
|
+
requestRef.current = requestAnimationFrame(tick);
|
|
478
507
|
};
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
508
|
+
useEffect3(() => {
|
|
509
|
+
requestRef.current = requestAnimationFrame(tick);
|
|
510
|
+
return () => {
|
|
511
|
+
if (requestRef.current) {
|
|
512
|
+
cancelAnimationFrame(requestRef.current);
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
}, []);
|
|
516
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
517
|
+
style: {
|
|
518
|
+
width: width + 6
|
|
519
|
+
},
|
|
520
|
+
className: mx3("relative flex flex-col p-0.5", "bg-baseSurface text-xs text-subdued font-thin pointer-events-none border border-separator", classNames)
|
|
521
|
+
}, /* @__PURE__ */ React3.createElement("div", null, fps[len - 1], " FPS"), /* @__PURE__ */ React3.createElement("div", {
|
|
522
|
+
className: "w-full relative",
|
|
523
|
+
style: {
|
|
524
|
+
height
|
|
525
|
+
}
|
|
526
|
+
}, fps.map((frame, i) => /* @__PURE__ */ React3.createElement("div", {
|
|
527
|
+
key: `fps-${i}`,
|
|
528
|
+
className: bar,
|
|
529
|
+
style: {
|
|
530
|
+
position: "absolute",
|
|
531
|
+
bottom: 0,
|
|
532
|
+
right: `${len - 1 - i}px`,
|
|
533
|
+
height: `${height * frame / max}px`,
|
|
534
|
+
width: 1
|
|
535
|
+
}
|
|
536
|
+
}))));
|
|
537
|
+
} finally {
|
|
538
|
+
_effect.f();
|
|
539
|
+
}
|
|
501
540
|
};
|
|
502
541
|
|
|
503
542
|
// packages/ui/react-ui-canvas/src/components/Grid/Grid.tsx
|
|
543
|
+
import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
|
|
504
544
|
import React4, { forwardRef as forwardRef2, useMemo as useMemo2, useId } from "react";
|
|
505
545
|
import { useForwardedRef } from "@dxos/react-ui";
|
|
506
546
|
import { mx as mx4 } from "@dxos/react-ui-theme";
|
|
@@ -517,65 +557,75 @@ var defaultOffset = {
|
|
|
517
557
|
};
|
|
518
558
|
var createId = (parent, grid) => `dx-canvas-grid-${parent}-${grid}`;
|
|
519
559
|
var GridComponent = /* @__PURE__ */ forwardRef2(({ size: gridSize = defaultGridSize, scale = 1, offset = defaultOffset, showAxes = true, classNames }, forwardedRef) => {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
560
|
+
var _effect = _useSignals4();
|
|
561
|
+
try {
|
|
562
|
+
const svgRef = useForwardedRef(forwardedRef);
|
|
563
|
+
const instanceId = useId();
|
|
564
|
+
const grids = useMemo2(() => gridRatios.map((ratio) => ({
|
|
565
|
+
id: ratio,
|
|
566
|
+
size: ratio * gridSize * scale
|
|
567
|
+
})).filter(({ size }) => size >= gridSize && size <= 256), [
|
|
568
|
+
gridSize,
|
|
569
|
+
scale
|
|
570
|
+
]);
|
|
571
|
+
const { width = 0, height = 0 } = svgRef.current?.getBoundingClientRect() ?? {};
|
|
572
|
+
return /* @__PURE__ */ React4.createElement("svg", {
|
|
573
|
+
...testId("dx-canvas-grid"),
|
|
574
|
+
ref: svgRef,
|
|
575
|
+
className: mx4("absolute inset-0 w-full h-full pointer-events-none touch-none select-none", "stroke-neutral-500", classNames)
|
|
576
|
+
}, /* @__PURE__ */ React4.createElement("defs", null, grids.map(({ id, size }) => /* @__PURE__ */ React4.createElement(GridPattern, {
|
|
577
|
+
key: id,
|
|
578
|
+
id: createId(instanceId, id),
|
|
579
|
+
offset,
|
|
580
|
+
size
|
|
581
|
+
}))), showAxes && /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement("line", {
|
|
582
|
+
x1: 0,
|
|
583
|
+
y1: offset.y,
|
|
584
|
+
x2: width,
|
|
585
|
+
y2: offset.y,
|
|
586
|
+
className: "stroke-neutral-500 opacity-40"
|
|
587
|
+
}), /* @__PURE__ */ React4.createElement("line", {
|
|
588
|
+
x1: offset.x,
|
|
589
|
+
y1: 0,
|
|
590
|
+
x2: offset.x,
|
|
591
|
+
y2: height,
|
|
592
|
+
className: "stroke-neutral-500 opacity-40"
|
|
593
|
+
})), /* @__PURE__ */ React4.createElement("g", null, grids.map(({ id }, i) => /* @__PURE__ */ React4.createElement("rect", {
|
|
594
|
+
key: id,
|
|
595
|
+
opacity: 0.1 + i * 0.05,
|
|
596
|
+
fill: `url(#${createId(instanceId, id)})`,
|
|
597
|
+
width: "100%",
|
|
598
|
+
height: "100%"
|
|
599
|
+
}))));
|
|
600
|
+
} finally {
|
|
601
|
+
_effect.f();
|
|
602
|
+
}
|
|
558
603
|
});
|
|
559
604
|
var Grid = (props) => {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
605
|
+
var _effect = _useSignals4();
|
|
606
|
+
try {
|
|
607
|
+
const { scale, offset } = useCanvasContext();
|
|
608
|
+
return /* @__PURE__ */ React4.createElement(GridComponent, {
|
|
609
|
+
...props,
|
|
610
|
+
scale,
|
|
611
|
+
offset
|
|
612
|
+
});
|
|
613
|
+
} finally {
|
|
614
|
+
_effect.f();
|
|
615
|
+
}
|
|
566
616
|
};
|
|
567
617
|
|
|
568
618
|
// packages/ui/react-ui-canvas/src/types.ts
|
|
569
|
-
import { Schema
|
|
570
|
-
var Point =
|
|
571
|
-
x:
|
|
572
|
-
y:
|
|
619
|
+
import { Schema } from "effect";
|
|
620
|
+
var Point = Schema.Struct({
|
|
621
|
+
x: Schema.Number,
|
|
622
|
+
y: Schema.Number
|
|
573
623
|
});
|
|
574
|
-
var Dimension =
|
|
575
|
-
width:
|
|
576
|
-
height:
|
|
624
|
+
var Dimension = Schema.Struct({
|
|
625
|
+
width: Schema.Number,
|
|
626
|
+
height: Schema.Number
|
|
577
627
|
});
|
|
578
|
-
var Rect =
|
|
628
|
+
var Rect = Schema.extend(Point, Dimension);
|
|
579
629
|
export {
|
|
580
630
|
Arrow,
|
|
581
631
|
Canvas,
|