@daasboard/editor 0.0.0-stage → 0.1.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/LICENSE +5 -0
- package/README.md +6 -2
- package/dist/camera/CameraInput.d.ts +106 -0
- package/dist/camera/CameraInput.js +398 -0
- package/dist/clipboard/ObjectClipboard.d.ts +40 -0
- package/dist/clipboard/ObjectClipboard.js +243 -0
- package/dist/clipboard/PasteCommitError.d.ts +4 -0
- package/dist/clipboard/PasteCommitError.js +7 -0
- package/dist/clipboard/carrier.d.ts +5 -0
- package/dist/clipboard/carrier.js +59 -0
- package/dist/clipboard/objects.d.ts +21 -0
- package/dist/clipboard/objects.js +362 -0
- package/dist/clipboard/placement.d.ts +11 -0
- package/dist/clipboard/placement.js +21 -0
- package/dist/clipboard/systemImages.d.ts +1 -0
- package/dist/clipboard/systemImages.js +24 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +22 -0
- package/dist/input/TouchInput.d.ts +159 -0
- package/dist/input/TouchInput.js +656 -0
- package/dist/input/visiblePart.d.ts +8 -0
- package/dist/input/visiblePart.js +15 -0
- package/dist/interaction/InteractionLayer.d.ts +83 -0
- package/dist/interaction/InteractionLayer.js +520 -0
- package/dist/props/PropertyController.d.ts +130 -0
- package/dist/props/PropertyController.js +1448 -0
- package/dist/props/PropertyRegistry.d.ts +38 -0
- package/dist/props/PropertyRegistry.js +21 -0
- package/dist/props/builtinProperties.d.ts +23 -0
- package/dist/props/builtinProperties.js +350 -0
- package/dist/props/defaults.d.ts +6 -0
- package/dist/props/defaults.js +29 -0
- package/dist/selection/SelectionModel.d.ts +25 -0
- package/dist/selection/SelectionModel.js +79 -0
- package/dist/text/CanvasEditorView.d.ts +99 -0
- package/dist/text/CanvasEditorView.js +308 -0
- package/dist/text/InputSink.d.ts +157 -0
- package/dist/text/InputSink.js +841 -0
- package/dist/text/TextEditSession.d.ts +173 -0
- package/dist/text/TextEditSession.js +1328 -0
- package/dist/text/clipboard.d.ts +11 -0
- package/dist/text/clipboard.js +489 -0
- package/dist/text/commands.d.ts +48 -0
- package/dist/text/commands.js +329 -0
- package/dist/text/contextMirror.d.ts +51 -0
- package/dist/text/contextMirror.js +292 -0
- package/dist/text/flat.d.ts +35 -0
- package/dist/text/flat.js +556 -0
- package/dist/text/graphemes.d.ts +16 -0
- package/dist/text/graphemes.js +219 -0
- package/dist/text/index.d.ts +13 -0
- package/dist/text/index.js +13 -0
- package/dist/text/inputReducer.d.ts +24 -0
- package/dist/text/inputReducer.js +44 -0
- package/dist/text/keymap.d.ts +17 -0
- package/dist/text/keymap.js +148 -0
- package/dist/text/schema.d.ts +12 -0
- package/dist/text/schema.js +44 -0
- package/dist/text/sessionFocus.d.ts +20 -0
- package/dist/text/sessionFocus.js +51 -0
- package/dist/text/types.d.ts +114 -0
- package/dist/text/types.js +1 -0
- package/dist/tools/CreateTool.d.ts +78 -0
- package/dist/tools/CreateTool.js +258 -0
- package/dist/tools/SelectTool.d.ts +155 -0
- package/dist/tools/SelectTool.js +808 -0
- package/dist/tools/ToolManager.d.ts +63 -0
- package/dist/tools/ToolManager.js +146 -0
- package/dist/tools/connectorEndpoints.d.ts +17 -0
- package/dist/tools/connectorEndpoints.js +53 -0
- package/dist/tools/frameRotation.d.ts +8 -0
- package/dist/tools/frameRotation.js +66 -0
- package/dist/tools/gradientHandles.d.ts +67 -0
- package/dist/tools/gradientHandles.js +110 -0
- package/dist/tools/presetPaths.d.ts +5 -0
- package/dist/tools/presetPaths.js +49 -0
- package/dist/tools/snapResize.d.ts +7 -0
- package/dist/tools/snapResize.js +65 -0
- package/dist/tools/snapping.d.ts +30 -0
- package/dist/tools/snapping.js +280 -0
- package/dist/tools/transform.d.ts +52 -0
- package/dist/tools/transform.js +277 -0
- package/package.json +36 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright (c) 2026 Spotworks AI LLC. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software is proprietary. No license or other right to use, copy, modify,
|
|
4
|
+
merge, publish, distribute, sublicense or sell it, in whole or in part, is
|
|
5
|
+
granted except under a separate written agreement with Spotworks AI LLC.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @daasboard/editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Headless tools, selection, text editing and property controllers for daasboard.
|
|
4
|
+
|
|
5
|
+
Hosts normally start from [`@daasboard/embed`](https://www.npmjs.com/package/@daasboard/embed), which mounts the editor and documents the required wasm and font assets. Keep every `@daasboard` package on the same exact release version.
|
|
6
|
+
|
|
7
|
+
This package provides ES modules and TypeScript declarations through its root entry point. Public availability grants no license; see `LICENSE`. Third-party components retain their own licenses.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type Camera, type Point, type SchedulerTimers } from "@daasboard/render-core";
|
|
2
|
+
export declare const MIN_ZOOM = 0.02;
|
|
3
|
+
export declare const MAX_ZOOM = 64;
|
|
4
|
+
export declare function clampZoom(zoom: number): number;
|
|
5
|
+
export declare const PINCH_UNITS = 100;
|
|
6
|
+
export declare const NOTCH_RATE = 0.002;
|
|
7
|
+
export declare const LINE_PX = 16;
|
|
8
|
+
export declare const MAC_WHEEL_TICK = 4.000244140625;
|
|
9
|
+
export declare const PINCH_FIRST_MAX = 20;
|
|
10
|
+
export declare const NOTCH_PX: readonly number[];
|
|
11
|
+
export declare const PAGE_ZOOM_FACTORS: readonly number[];
|
|
12
|
+
export declare const DISPLAY_SCALES: readonly number[];
|
|
13
|
+
export declare const STREAM_GAP_MS = 150;
|
|
14
|
+
export declare const PINCH_HOLD_MS = 1000;
|
|
15
|
+
export declare const RELEASE_WINDOW_MS = 48;
|
|
16
|
+
export declare const KINETIC_MIN_SPEED = 0.8;
|
|
17
|
+
export declare const KINETIC_MAX_SPEED = 6;
|
|
18
|
+
export declare const KINETIC_MS = 360;
|
|
19
|
+
export interface WheelInput {
|
|
20
|
+
readonly deltaX: number;
|
|
21
|
+
readonly deltaY: number;
|
|
22
|
+
readonly deltaMode: number;
|
|
23
|
+
readonly ctrlKey: boolean;
|
|
24
|
+
readonly metaKey: boolean;
|
|
25
|
+
readonly clientX: number;
|
|
26
|
+
readonly clientY: number;
|
|
27
|
+
readonly timeStamp?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface GestureInput {
|
|
30
|
+
readonly type: string;
|
|
31
|
+
readonly scale: number;
|
|
32
|
+
readonly clientX?: number;
|
|
33
|
+
readonly clientY?: number;
|
|
34
|
+
readonly timeStamp?: number;
|
|
35
|
+
}
|
|
36
|
+
export type WheelZoomKind = "pinch" | "notch";
|
|
37
|
+
export interface CameraInputOptions {
|
|
38
|
+
camera: Camera;
|
|
39
|
+
local(clientX: number, clientY: number): Point;
|
|
40
|
+
size(): {
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
};
|
|
44
|
+
onChange(kind: "zoom" | "pan"): void;
|
|
45
|
+
timers?: SchedulerTimers;
|
|
46
|
+
}
|
|
47
|
+
export interface CameraInputStats {
|
|
48
|
+
pinchUpdates: number;
|
|
49
|
+
notches: number;
|
|
50
|
+
pans: number;
|
|
51
|
+
finishes: number;
|
|
52
|
+
finishSteps: number;
|
|
53
|
+
finishesStopped: number;
|
|
54
|
+
finishesDone: number;
|
|
55
|
+
takenBack: number;
|
|
56
|
+
releasesDropped: number;
|
|
57
|
+
}
|
|
58
|
+
export interface PinchSample {
|
|
59
|
+
at: number;
|
|
60
|
+
ln: number;
|
|
61
|
+
}
|
|
62
|
+
export declare function wheelZoomKind(deltaY: number, deltaMode: number): WheelZoomKind;
|
|
63
|
+
export declare function releaseSpeed(samples: readonly PinchSample[], end: number, windowMs?: number): number;
|
|
64
|
+
export declare function zoomAbout(cam: Camera, ln: number, anchor: Point): {
|
|
65
|
+
moved: number;
|
|
66
|
+
clamped: boolean;
|
|
67
|
+
};
|
|
68
|
+
export declare class CameraInput {
|
|
69
|
+
private readonly o;
|
|
70
|
+
private readonly timers;
|
|
71
|
+
private stream;
|
|
72
|
+
private pinch;
|
|
73
|
+
private endTimer;
|
|
74
|
+
private endDue;
|
|
75
|
+
private stallEnd;
|
|
76
|
+
private finish;
|
|
77
|
+
private safari;
|
|
78
|
+
private safariEndedAt;
|
|
79
|
+
private lapseTimer;
|
|
80
|
+
private pointer;
|
|
81
|
+
private disposed;
|
|
82
|
+
readonly stats: CameraInputStats;
|
|
83
|
+
constructor(o: CameraInputOptions);
|
|
84
|
+
get kinetic(): boolean;
|
|
85
|
+
wheel(e: WheelInput): "zoom" | "pan" | null;
|
|
86
|
+
gesture(e: GestureInput): boolean;
|
|
87
|
+
pointerMove(clientX: number, clientY: number): void;
|
|
88
|
+
stop(): void;
|
|
89
|
+
dispose(): void;
|
|
90
|
+
private update;
|
|
91
|
+
private zoom;
|
|
92
|
+
private armEnd;
|
|
93
|
+
private release;
|
|
94
|
+
private readonly step;
|
|
95
|
+
private endFinish;
|
|
96
|
+
private clearEnd;
|
|
97
|
+
private armLapse;
|
|
98
|
+
private clearLapse;
|
|
99
|
+
private interval;
|
|
100
|
+
private continueMs;
|
|
101
|
+
private center;
|
|
102
|
+
private time;
|
|
103
|
+
}
|
|
104
|
+
export declare function listenTrackpadGestures(target: EventTarget, input: CameraInput, nav?: {
|
|
105
|
+
readonly maxTouchPoints?: number;
|
|
106
|
+
} | undefined, touching?: () => boolean): () => void;
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { browserTimers } from "@daasboard/render-core";
|
|
2
|
+
export const MIN_ZOOM = 0.02;
|
|
3
|
+
export const MAX_ZOOM = 64;
|
|
4
|
+
export function clampZoom(zoom) {
|
|
5
|
+
return Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom));
|
|
6
|
+
}
|
|
7
|
+
export const PINCH_UNITS = 100;
|
|
8
|
+
export const NOTCH_RATE = 0.002;
|
|
9
|
+
export const LINE_PX = 16;
|
|
10
|
+
export const MAC_WHEEL_TICK = 4.000244140625;
|
|
11
|
+
export const PINCH_FIRST_MAX = 20;
|
|
12
|
+
export const NOTCH_PX = [53, 100, 120];
|
|
13
|
+
export const PAGE_ZOOM_FACTORS = [0.25, 1 / 3, 0.5, 2 / 3, 0.75, 0.8, 0.9, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5];
|
|
14
|
+
export const DISPLAY_SCALES = [1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 3];
|
|
15
|
+
const WHEEL_STEPS = [MAC_WHEEL_TICK, ...NOTCH_PX];
|
|
16
|
+
const LAYOUT_ZOOMS = (() => {
|
|
17
|
+
const pairs = new Map();
|
|
18
|
+
for (const zoom of [1, ...PAGE_ZOOM_FACTORS]) {
|
|
19
|
+
for (const display of DISPLAY_SCALES) {
|
|
20
|
+
const scale = Math.fround(display);
|
|
21
|
+
const layout = Math.fround(scale * Math.fround(zoom));
|
|
22
|
+
pairs.set(`${scale} ${layout}`, { scale, layout });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return [...pairs.values()];
|
|
26
|
+
})();
|
|
27
|
+
export const STREAM_GAP_MS = 150;
|
|
28
|
+
export const PINCH_HOLD_MS = 1000;
|
|
29
|
+
const STALL_MS = 50;
|
|
30
|
+
const STALL_GRACE_MS = 100;
|
|
31
|
+
export const RELEASE_WINDOW_MS = 48;
|
|
32
|
+
export const KINETIC_MIN_SPEED = 0.8;
|
|
33
|
+
export const KINETIC_MAX_SPEED = 6;
|
|
34
|
+
export const KINETIC_MS = 360;
|
|
35
|
+
const END_INTERVALS = 2;
|
|
36
|
+
const END_MIN_MS = 24;
|
|
37
|
+
const END_MAX_MS = 100;
|
|
38
|
+
const CONTINUE_INTERVALS = 4;
|
|
39
|
+
const CONTINUE_MIN_MS = 60;
|
|
40
|
+
const DEFAULT_INTERVAL_MS = 16;
|
|
41
|
+
const MIN_SPAN_MS = 8;
|
|
42
|
+
const POINTER_SLOP_PX = 3;
|
|
43
|
+
const GESTURE_TAIL_MS = 100;
|
|
44
|
+
const GESTURE_LAPSE_MS = 500;
|
|
45
|
+
export function wheelZoomKind(deltaY, deltaMode) {
|
|
46
|
+
return !onlyWheel(deltaY, deltaMode) && Math.abs(deltaY) < PINCH_FIRST_MAX ? "pinch" : "notch";
|
|
47
|
+
}
|
|
48
|
+
function onlyWheel(deltaY, deltaMode) {
|
|
49
|
+
if (deltaMode !== 0)
|
|
50
|
+
return true;
|
|
51
|
+
const a = Math.abs(deltaY);
|
|
52
|
+
if (Number.isInteger(a) || multipleOf(a, MAC_WHEEL_TICK, 1e-6))
|
|
53
|
+
return true;
|
|
54
|
+
return LAYOUT_ZOOMS.some(({ scale, layout }) => chromiumSteps(a, scale, layout));
|
|
55
|
+
}
|
|
56
|
+
function chromiumSteps(a, scale, layout) {
|
|
57
|
+
const px = a * layout;
|
|
58
|
+
for (const step of WHEEL_STEPS) {
|
|
59
|
+
const k = Math.round(px / (step * scale));
|
|
60
|
+
if (k >= 1 && Math.fround(Math.fround(k * step) * scale) / layout === a)
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
function multipleOf(px, unit, epsilon) {
|
|
66
|
+
const k = px / unit;
|
|
67
|
+
const whole = Math.round(k);
|
|
68
|
+
return whole >= 1 && Math.abs(k - whole) <= epsilon * whole;
|
|
69
|
+
}
|
|
70
|
+
export function releaseSpeed(samples, end, windowMs = RELEASE_WINDOW_MS) {
|
|
71
|
+
const n = samples.length;
|
|
72
|
+
if (n < 2)
|
|
73
|
+
return 0;
|
|
74
|
+
let j = n;
|
|
75
|
+
while (j > 1 && samples[j - 1].at > end - windowMs)
|
|
76
|
+
j--;
|
|
77
|
+
if (j === n)
|
|
78
|
+
return 0;
|
|
79
|
+
let ln = 0;
|
|
80
|
+
for (let i = j; i < n; i++)
|
|
81
|
+
ln += samples[i].ln;
|
|
82
|
+
return ln / Math.max(MIN_SPAN_MS, end - samples[j - 1].at);
|
|
83
|
+
}
|
|
84
|
+
export function zoomAbout(cam, ln, anchor) {
|
|
85
|
+
if (!Number.isFinite(ln) || ln === 0)
|
|
86
|
+
return { moved: 0, clamped: false };
|
|
87
|
+
const before = cam.zoom;
|
|
88
|
+
const raw = before * Math.exp(ln);
|
|
89
|
+
const next = clampZoom(raw);
|
|
90
|
+
const clamped = next !== raw;
|
|
91
|
+
if (next === before)
|
|
92
|
+
return { moved: 0, clamped };
|
|
93
|
+
const wx = cam.x + anchor.x / before;
|
|
94
|
+
const wy = cam.y + anchor.y / before;
|
|
95
|
+
cam.zoom = next;
|
|
96
|
+
cam.x = wx - anchor.x / next;
|
|
97
|
+
cam.y = wy - anchor.y / next;
|
|
98
|
+
return { moved: Math.log(next / before), clamped };
|
|
99
|
+
}
|
|
100
|
+
const median = (xs) => [...xs].sort((a, b) => a - b)[Math.floor(xs.length / 2)];
|
|
101
|
+
const sameCamera = (a, b) => a.x === b.x && a.y === b.y && a.zoom === b.zoom;
|
|
102
|
+
export class CameraInput {
|
|
103
|
+
o;
|
|
104
|
+
timers;
|
|
105
|
+
stream = null;
|
|
106
|
+
pinch = null;
|
|
107
|
+
endTimer = null;
|
|
108
|
+
endDue = Infinity;
|
|
109
|
+
stallEnd = -Infinity;
|
|
110
|
+
finish = null;
|
|
111
|
+
safari = null;
|
|
112
|
+
safariEndedAt = -Infinity;
|
|
113
|
+
lapseTimer = null;
|
|
114
|
+
pointer = null;
|
|
115
|
+
disposed = false;
|
|
116
|
+
stats = { pinchUpdates: 0, notches: 0, pans: 0, finishes: 0, finishSteps: 0, finishesStopped: 0, finishesDone: 0, takenBack: 0, releasesDropped: 0 };
|
|
117
|
+
constructor(o) {
|
|
118
|
+
this.o = o;
|
|
119
|
+
this.timers = o.timers ?? browserTimers();
|
|
120
|
+
}
|
|
121
|
+
get kinetic() {
|
|
122
|
+
return this.finish !== null;
|
|
123
|
+
}
|
|
124
|
+
wheel(e) {
|
|
125
|
+
if (this.disposed)
|
|
126
|
+
return null;
|
|
127
|
+
const mode = e.deltaMode;
|
|
128
|
+
const unit = mode === 1 ? LINE_PX : mode === 2 ? Math.max(1, this.o.size().height) : 1;
|
|
129
|
+
const dx = e.deltaX * unit;
|
|
130
|
+
const dy = e.deltaY * unit;
|
|
131
|
+
const at = this.time(e.timeStamp);
|
|
132
|
+
this.pointer = { x: e.clientX, y: e.clientY };
|
|
133
|
+
if (!e.ctrlKey && !e.metaKey) {
|
|
134
|
+
this.stop();
|
|
135
|
+
if (!Number.isFinite(dx) || !Number.isFinite(dy) || (!dx && !dy))
|
|
136
|
+
return null;
|
|
137
|
+
const cam = this.o.camera;
|
|
138
|
+
cam.x += dx / cam.zoom;
|
|
139
|
+
cam.y += dy / cam.zoom;
|
|
140
|
+
this.stats.pans++;
|
|
141
|
+
this.o.onChange("pan");
|
|
142
|
+
return "pan";
|
|
143
|
+
}
|
|
144
|
+
if (this.safari || at - this.safariEndedAt < GESTURE_TAIL_MS)
|
|
145
|
+
return null;
|
|
146
|
+
if (!dy || !Number.isFinite(dy))
|
|
147
|
+
return null;
|
|
148
|
+
let s = this.stream;
|
|
149
|
+
const gap = s ? at - s.at : Infinity;
|
|
150
|
+
const now = this.timers.now();
|
|
151
|
+
const stalled = (this.endTimer !== null && now - this.endDue > STALL_MS) || now - this.stallEnd < STALL_GRACE_MS;
|
|
152
|
+
if (!s || (s.kind === "pinch" ? (gap > PINCH_HOLD_MS && !stalled) || onlyWheel(e.deltaY, mode) : gap > STREAM_GAP_MS)) {
|
|
153
|
+
s = this.stream = { kind: wheelZoomKind(e.deltaY, mode), at };
|
|
154
|
+
this.clearEnd();
|
|
155
|
+
this.pinch = null;
|
|
156
|
+
}
|
|
157
|
+
else
|
|
158
|
+
s.at = at;
|
|
159
|
+
if (s.kind === "notch") {
|
|
160
|
+
this.stop();
|
|
161
|
+
this.stats.notches++;
|
|
162
|
+
return this.zoom(-dy * NOTCH_RATE, this.o.local(e.clientX, e.clientY)) ? "zoom" : null;
|
|
163
|
+
}
|
|
164
|
+
return this.update(-dy / PINCH_UNITS, { x: e.clientX, y: e.clientY }, at, true) ? "zoom" : null;
|
|
165
|
+
}
|
|
166
|
+
gesture(e) {
|
|
167
|
+
if (this.disposed)
|
|
168
|
+
return false;
|
|
169
|
+
const type = e.type;
|
|
170
|
+
if (type !== "gesturestart" && type !== "gesturechange" && type !== "gestureend")
|
|
171
|
+
return false;
|
|
172
|
+
const at = this.time(e.timeStamp);
|
|
173
|
+
if (Number.isFinite(e.clientX) && Number.isFinite(e.clientY))
|
|
174
|
+
this.pointer = { x: e.clientX, y: e.clientY };
|
|
175
|
+
const scale = Number.isFinite(e.scale) && e.scale > 0 ? e.scale : null;
|
|
176
|
+
if (type === "gesturestart" || !this.safari) {
|
|
177
|
+
this.stop();
|
|
178
|
+
this.stream = null;
|
|
179
|
+
if (type === "gestureend")
|
|
180
|
+
return true;
|
|
181
|
+
this.safari = { scale: type === "gesturestart" ? 1 : (scale ?? 1) };
|
|
182
|
+
this.armLapse();
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if (scale !== null && scale !== this.safari.scale) {
|
|
186
|
+
const ln = Math.log(scale / this.safari.scale);
|
|
187
|
+
this.safari.scale = scale;
|
|
188
|
+
this.update(ln, this.pointer, at, false);
|
|
189
|
+
}
|
|
190
|
+
if (type === "gestureend") {
|
|
191
|
+
this.safari = null;
|
|
192
|
+
this.safariEndedAt = at;
|
|
193
|
+
this.clearLapse();
|
|
194
|
+
if (this.pinch)
|
|
195
|
+
this.release(this.pinch, at);
|
|
196
|
+
}
|
|
197
|
+
else
|
|
198
|
+
this.armLapse();
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
pointerMove(clientX, clientY) {
|
|
202
|
+
if (this.disposed)
|
|
203
|
+
return;
|
|
204
|
+
this.pointer = { x: clientX, y: clientY };
|
|
205
|
+
const c = this.finish?.client;
|
|
206
|
+
if (c && Math.hypot(clientX - c.x, clientY - c.y) > POINTER_SLOP_PX)
|
|
207
|
+
this.stop();
|
|
208
|
+
}
|
|
209
|
+
stop() {
|
|
210
|
+
if (this.finish) {
|
|
211
|
+
this.stats.finishesStopped++;
|
|
212
|
+
this.endFinish();
|
|
213
|
+
}
|
|
214
|
+
this.clearEnd();
|
|
215
|
+
this.pinch = null;
|
|
216
|
+
}
|
|
217
|
+
dispose() {
|
|
218
|
+
if (this.disposed)
|
|
219
|
+
return;
|
|
220
|
+
this.stop();
|
|
221
|
+
this.clearLapse();
|
|
222
|
+
this.safari = null;
|
|
223
|
+
this.stream = null;
|
|
224
|
+
this.disposed = true;
|
|
225
|
+
}
|
|
226
|
+
update(ln, client, at, wheel) {
|
|
227
|
+
this.stats.pinchUpdates++;
|
|
228
|
+
const cam = this.o.camera;
|
|
229
|
+
let p = this.pinch;
|
|
230
|
+
let take = 0;
|
|
231
|
+
const f = this.finish;
|
|
232
|
+
const written = f ? !sameCamera(cam, f.wrote) : p !== null && !sameCamera(cam, p.wrote);
|
|
233
|
+
if (f) {
|
|
234
|
+
if (!written && p !== null && f.pinch === p && (at - p.last <= this.continueMs(p) || at - f.start <= CONTINUE_MIN_MS)) {
|
|
235
|
+
take = f.moved;
|
|
236
|
+
this.stats.takenBack++;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
p = null;
|
|
240
|
+
this.stats.finishesStopped++;
|
|
241
|
+
}
|
|
242
|
+
this.endFinish();
|
|
243
|
+
}
|
|
244
|
+
else if (written)
|
|
245
|
+
p = null;
|
|
246
|
+
const anchor = client ? this.o.local(client.x, client.y) : this.center();
|
|
247
|
+
if (!p)
|
|
248
|
+
p = this.pinch = { samples: [], intervals: [], last: at, anchor, client, wrote: { x: cam.x, y: cam.y, zoom: cam.zoom } };
|
|
249
|
+
else {
|
|
250
|
+
if (at > p.last) {
|
|
251
|
+
p.intervals.push(at - p.last);
|
|
252
|
+
if (p.intervals.length > 4)
|
|
253
|
+
p.intervals.shift();
|
|
254
|
+
}
|
|
255
|
+
p.last = Math.max(p.last, at);
|
|
256
|
+
p.anchor = anchor;
|
|
257
|
+
p.client = client;
|
|
258
|
+
}
|
|
259
|
+
p.samples.push({ at, ln });
|
|
260
|
+
if (p.samples.length > 16)
|
|
261
|
+
p.samples.shift();
|
|
262
|
+
const moved = this.zoom(ln - take, anchor);
|
|
263
|
+
p.wrote = { x: cam.x, y: cam.y, zoom: cam.zoom };
|
|
264
|
+
if (wheel)
|
|
265
|
+
this.armEnd(p);
|
|
266
|
+
return moved;
|
|
267
|
+
}
|
|
268
|
+
zoom(ln, anchor) {
|
|
269
|
+
const r = zoomAbout(this.o.camera, ln, anchor);
|
|
270
|
+
if (r.moved !== 0)
|
|
271
|
+
this.o.onChange("zoom");
|
|
272
|
+
return r.moved !== 0;
|
|
273
|
+
}
|
|
274
|
+
armEnd(p) {
|
|
275
|
+
this.clearEnd();
|
|
276
|
+
const ms = Math.min(END_MAX_MS, Math.max(END_MIN_MS, END_INTERVALS * this.interval(p)));
|
|
277
|
+
this.endDue = this.timers.now() + ms;
|
|
278
|
+
this.endTimer = this.timers.setTimeout(() => {
|
|
279
|
+
this.endTimer = null;
|
|
280
|
+
const now = this.timers.now();
|
|
281
|
+
if (now - this.endDue > STALL_MS)
|
|
282
|
+
this.stallEnd = now;
|
|
283
|
+
if (this.pinch === p)
|
|
284
|
+
this.release(p, p.last);
|
|
285
|
+
}, ms);
|
|
286
|
+
}
|
|
287
|
+
release(p, end) {
|
|
288
|
+
const cam = this.o.camera;
|
|
289
|
+
if (!sameCamera(cam, p.wrote)) {
|
|
290
|
+
this.stats.releasesDropped++;
|
|
291
|
+
this.pinch = null;
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const speed = releaseSpeed(p.samples, end) * 1000;
|
|
295
|
+
if (!(Math.abs(speed) >= KINETIC_MIN_SPEED))
|
|
296
|
+
return;
|
|
297
|
+
const v = Math.max(-KINETIC_MAX_SPEED, Math.min(KINETIC_MAX_SPEED, speed));
|
|
298
|
+
this.finish = { pinch: p, anchor: p.anchor, client: p.client, start: this.timers.now(), distance: (v * KINETIC_MS) / 3000, moved: 0, wrote: { x: cam.x, y: cam.y, zoom: cam.zoom }, frame: null };
|
|
299
|
+
this.stats.finishes++;
|
|
300
|
+
this.finish.frame = this.timers.requestFrame(this.step);
|
|
301
|
+
}
|
|
302
|
+
step = () => {
|
|
303
|
+
const f = this.finish;
|
|
304
|
+
if (!f)
|
|
305
|
+
return;
|
|
306
|
+
f.frame = null;
|
|
307
|
+
const cam = this.o.camera;
|
|
308
|
+
if (!sameCamera(cam, f.wrote)) {
|
|
309
|
+
this.stats.finishesStopped++;
|
|
310
|
+
this.endFinish();
|
|
311
|
+
this.pinch = null;
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const u = Math.min(1, Math.max(0, (this.timers.now() - f.start) / KINETIC_MS));
|
|
315
|
+
const target = f.distance * (1 - (1 - u) ** 3);
|
|
316
|
+
const r = zoomAbout(cam, target - f.moved, f.anchor);
|
|
317
|
+
f.moved += r.moved;
|
|
318
|
+
f.wrote = { x: cam.x, y: cam.y, zoom: cam.zoom };
|
|
319
|
+
if (r.moved !== 0) {
|
|
320
|
+
this.stats.finishSteps++;
|
|
321
|
+
this.o.onChange("zoom");
|
|
322
|
+
}
|
|
323
|
+
if (u >= 1 || r.clamped) {
|
|
324
|
+
this.stats.finishesDone++;
|
|
325
|
+
this.endFinish();
|
|
326
|
+
this.pinch = null;
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
f.frame = this.timers.requestFrame(this.step);
|
|
330
|
+
};
|
|
331
|
+
endFinish() {
|
|
332
|
+
const f = this.finish;
|
|
333
|
+
if (!f)
|
|
334
|
+
return;
|
|
335
|
+
if (f.frame !== null)
|
|
336
|
+
this.timers.cancelFrame(f.frame);
|
|
337
|
+
this.finish = null;
|
|
338
|
+
}
|
|
339
|
+
clearEnd() {
|
|
340
|
+
if (this.endTimer === null)
|
|
341
|
+
return;
|
|
342
|
+
this.timers.clearTimeout(this.endTimer);
|
|
343
|
+
this.endTimer = null;
|
|
344
|
+
}
|
|
345
|
+
armLapse() {
|
|
346
|
+
this.clearLapse();
|
|
347
|
+
this.lapseTimer = this.timers.setTimeout(() => {
|
|
348
|
+
this.lapseTimer = null;
|
|
349
|
+
this.safari = null;
|
|
350
|
+
}, GESTURE_LAPSE_MS);
|
|
351
|
+
}
|
|
352
|
+
clearLapse() {
|
|
353
|
+
if (this.lapseTimer === null)
|
|
354
|
+
return;
|
|
355
|
+
this.timers.clearTimeout(this.lapseTimer);
|
|
356
|
+
this.lapseTimer = null;
|
|
357
|
+
}
|
|
358
|
+
interval(p) {
|
|
359
|
+
return p.intervals.length ? median(p.intervals) : DEFAULT_INTERVAL_MS;
|
|
360
|
+
}
|
|
361
|
+
continueMs(p) {
|
|
362
|
+
return Math.min(STREAM_GAP_MS, Math.max(CONTINUE_MIN_MS, CONTINUE_INTERVALS * this.interval(p)));
|
|
363
|
+
}
|
|
364
|
+
center() {
|
|
365
|
+
const { width, height } = this.o.size();
|
|
366
|
+
return { x: width / 2, y: height / 2 };
|
|
367
|
+
}
|
|
368
|
+
time(ts) {
|
|
369
|
+
const now = this.timers.now();
|
|
370
|
+
return ts !== undefined && Number.isFinite(ts) && ts > 0 && Math.abs(now - ts) < 10_000 ? Math.min(ts, now) : now;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
export function listenTrackpadGestures(target, input, nav = globalThis.navigator, touching) {
|
|
374
|
+
if (!nav || ((nav.maxTouchPoints ?? 0) > 0 && !touching))
|
|
375
|
+
return () => { };
|
|
376
|
+
const types = ["gesturestart", "gesturechange", "gestureend"];
|
|
377
|
+
let fingers = false;
|
|
378
|
+
const on = (e) => {
|
|
379
|
+
if (touching) {
|
|
380
|
+
if (e.type === "gesturestart")
|
|
381
|
+
fingers = touching();
|
|
382
|
+
if (fingers || touching()) {
|
|
383
|
+
if (e.type === "gestureend")
|
|
384
|
+
fingers = false;
|
|
385
|
+
e.preventDefault();
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (input.gesture(e))
|
|
390
|
+
e.preventDefault();
|
|
391
|
+
};
|
|
392
|
+
for (const type of types)
|
|
393
|
+
target.addEventListener(type, on, { passive: false });
|
|
394
|
+
return () => {
|
|
395
|
+
for (const type of types)
|
|
396
|
+
target.removeEventListener(type, on);
|
|
397
|
+
};
|
|
398
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Point, Rect, SceneObject } from "@daasboard/render-core";
|
|
2
|
+
import type { PropertyController } from "../props/PropertyController.js";
|
|
3
|
+
import { type ClipboardAssets, type ClipboardAssetShare } from "./objects.js";
|
|
4
|
+
import { type PasteOptions } from "./placement.js";
|
|
5
|
+
export interface ObjectClipboardContent {
|
|
6
|
+
objects?: string;
|
|
7
|
+
text?: string;
|
|
8
|
+
html?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ClipboardWriter {
|
|
11
|
+
setData(type: string, value: string): void;
|
|
12
|
+
}
|
|
13
|
+
export type ClipboardSource = ObjectClipboardContent | {
|
|
14
|
+
getData(type: string): string;
|
|
15
|
+
readonly types?: readonly string[];
|
|
16
|
+
};
|
|
17
|
+
export interface ObjectPasteResult {
|
|
18
|
+
ids: string[];
|
|
19
|
+
pending: Promise<string[]> | null;
|
|
20
|
+
}
|
|
21
|
+
export interface ObjectClipboardOptions {
|
|
22
|
+
controller: PropertyController;
|
|
23
|
+
viewport(): Rect;
|
|
24
|
+
parentAt?(point: Point, excludedIds: ReadonlySet<string>): string | null;
|
|
25
|
+
measureText?(object: SceneObject): number;
|
|
26
|
+
readOnly?(): boolean;
|
|
27
|
+
activeText?(): boolean;
|
|
28
|
+
ownerDocument?: Document;
|
|
29
|
+
share?(hash: string): ClipboardAssetShare | null;
|
|
30
|
+
insert?(objects: readonly SceneObject[], placement: PasteOptions, commit: (objects: readonly SceneObject[], options?: PasteOptions) => string[], assets?: ClipboardAssets): string[] | Promise<string[]>;
|
|
31
|
+
onError?(error: unknown): void;
|
|
32
|
+
}
|
|
33
|
+
export interface ObjectClipboard {
|
|
34
|
+
copy(writer?: ClipboardWriter): ObjectClipboardContent | null;
|
|
35
|
+
cut(writer?: ClipboardWriter): ObjectClipboardContent | null;
|
|
36
|
+
paste(source: ClipboardSource): ObjectPasteResult;
|
|
37
|
+
pasteAt(point: Point, source: ClipboardSource): ObjectPasteResult;
|
|
38
|
+
}
|
|
39
|
+
export declare const PASTED_TEXT_WIDTH = 400;
|
|
40
|
+
export declare function createObjectClipboard(options: ObjectClipboardOptions): ObjectClipboard;
|