@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.
Files changed (83) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +6 -2
  3. package/dist/camera/CameraInput.d.ts +106 -0
  4. package/dist/camera/CameraInput.js +398 -0
  5. package/dist/clipboard/ObjectClipboard.d.ts +40 -0
  6. package/dist/clipboard/ObjectClipboard.js +243 -0
  7. package/dist/clipboard/PasteCommitError.d.ts +4 -0
  8. package/dist/clipboard/PasteCommitError.js +7 -0
  9. package/dist/clipboard/carrier.d.ts +5 -0
  10. package/dist/clipboard/carrier.js +59 -0
  11. package/dist/clipboard/objects.d.ts +21 -0
  12. package/dist/clipboard/objects.js +362 -0
  13. package/dist/clipboard/placement.d.ts +11 -0
  14. package/dist/clipboard/placement.js +21 -0
  15. package/dist/clipboard/systemImages.d.ts +1 -0
  16. package/dist/clipboard/systemImages.js +24 -0
  17. package/dist/index.d.ts +23 -0
  18. package/dist/index.js +22 -0
  19. package/dist/input/TouchInput.d.ts +159 -0
  20. package/dist/input/TouchInput.js +656 -0
  21. package/dist/input/visiblePart.d.ts +8 -0
  22. package/dist/input/visiblePart.js +15 -0
  23. package/dist/interaction/InteractionLayer.d.ts +83 -0
  24. package/dist/interaction/InteractionLayer.js +520 -0
  25. package/dist/props/PropertyController.d.ts +130 -0
  26. package/dist/props/PropertyController.js +1448 -0
  27. package/dist/props/PropertyRegistry.d.ts +38 -0
  28. package/dist/props/PropertyRegistry.js +21 -0
  29. package/dist/props/builtinProperties.d.ts +23 -0
  30. package/dist/props/builtinProperties.js +350 -0
  31. package/dist/props/defaults.d.ts +6 -0
  32. package/dist/props/defaults.js +29 -0
  33. package/dist/selection/SelectionModel.d.ts +25 -0
  34. package/dist/selection/SelectionModel.js +79 -0
  35. package/dist/text/CanvasEditorView.d.ts +99 -0
  36. package/dist/text/CanvasEditorView.js +308 -0
  37. package/dist/text/InputSink.d.ts +157 -0
  38. package/dist/text/InputSink.js +841 -0
  39. package/dist/text/TextEditSession.d.ts +173 -0
  40. package/dist/text/TextEditSession.js +1328 -0
  41. package/dist/text/clipboard.d.ts +11 -0
  42. package/dist/text/clipboard.js +489 -0
  43. package/dist/text/commands.d.ts +48 -0
  44. package/dist/text/commands.js +329 -0
  45. package/dist/text/contextMirror.d.ts +51 -0
  46. package/dist/text/contextMirror.js +292 -0
  47. package/dist/text/flat.d.ts +35 -0
  48. package/dist/text/flat.js +556 -0
  49. package/dist/text/graphemes.d.ts +16 -0
  50. package/dist/text/graphemes.js +219 -0
  51. package/dist/text/index.d.ts +13 -0
  52. package/dist/text/index.js +13 -0
  53. package/dist/text/inputReducer.d.ts +24 -0
  54. package/dist/text/inputReducer.js +44 -0
  55. package/dist/text/keymap.d.ts +17 -0
  56. package/dist/text/keymap.js +148 -0
  57. package/dist/text/schema.d.ts +12 -0
  58. package/dist/text/schema.js +44 -0
  59. package/dist/text/sessionFocus.d.ts +20 -0
  60. package/dist/text/sessionFocus.js +51 -0
  61. package/dist/text/types.d.ts +114 -0
  62. package/dist/text/types.js +1 -0
  63. package/dist/tools/CreateTool.d.ts +78 -0
  64. package/dist/tools/CreateTool.js +258 -0
  65. package/dist/tools/SelectTool.d.ts +155 -0
  66. package/dist/tools/SelectTool.js +808 -0
  67. package/dist/tools/ToolManager.d.ts +63 -0
  68. package/dist/tools/ToolManager.js +146 -0
  69. package/dist/tools/connectorEndpoints.d.ts +17 -0
  70. package/dist/tools/connectorEndpoints.js +53 -0
  71. package/dist/tools/frameRotation.d.ts +8 -0
  72. package/dist/tools/frameRotation.js +66 -0
  73. package/dist/tools/gradientHandles.d.ts +67 -0
  74. package/dist/tools/gradientHandles.js +110 -0
  75. package/dist/tools/presetPaths.d.ts +5 -0
  76. package/dist/tools/presetPaths.js +49 -0
  77. package/dist/tools/snapResize.d.ts +7 -0
  78. package/dist/tools/snapResize.js +65 -0
  79. package/dist/tools/snapping.d.ts +30 -0
  80. package/dist/tools/snapping.js +280 -0
  81. package/dist/tools/transform.d.ts +52 -0
  82. package/dist/tools/transform.js +277 -0
  83. package/package.json +36 -3
@@ -0,0 +1,114 @@
1
+ import type { Rect, Renderer, SceneObject, TextContent, TextLayoutHandle } from "@daasboard/render-core";
2
+ import type { Transaction as DocTransaction } from "@daasboard/doc";
3
+ import type { EditorState, Transaction } from "prosemirror-state";
4
+ import type { ClipboardContent } from "./clipboard.js";
5
+ export interface LayoutProvider {
6
+ readonly renderer: Renderer;
7
+ layout(): TextLayoutHandle | null;
8
+ origin(): {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ }
13
+ export type TextblockDir = "up" | "down" | "left" | "right" | "forward" | "backward";
14
+ export interface HeadlessEditorView {
15
+ state: EditorState;
16
+ dispatch(tr: Transaction): void;
17
+ updateState(state: EditorState): void;
18
+ composing: boolean;
19
+ hasFocus(): boolean;
20
+ focus(): void;
21
+ someProp(name: string, f?: (value: unknown) => unknown): unknown;
22
+ endOfTextblock(dir: TextblockDir, state?: EditorState): boolean;
23
+ coordsAtPos(pos: number): Rect;
24
+ posAtCoords(coords: {
25
+ left: number;
26
+ top: number;
27
+ }): {
28
+ pos: number;
29
+ inside: number;
30
+ } | null;
31
+ }
32
+ export interface KeyInfo {
33
+ key: string;
34
+ code: string;
35
+ shiftKey: boolean;
36
+ ctrlKey: boolean;
37
+ altKey: boolean;
38
+ metaKey: boolean;
39
+ }
40
+ export interface InputTarget {
41
+ insertText(text: string): void;
42
+ deleteBackward(unit: "char" | "word" | "line"): void;
43
+ deleteForward(unit: "char" | "word" | "line"): void;
44
+ splitBlock(): void;
45
+ insertLineBreak(): void;
46
+ keydown(e: KeyInfo): boolean;
47
+ compositionStart(): void;
48
+ compositionUpdate(data: string): void;
49
+ compositionEnd(data: string): void;
50
+ copyText(): string;
51
+ copyClipboard?(): ClipboardContent | null;
52
+ pasteClipboard?(content: ClipboardContent): boolean;
53
+ cut(): string;
54
+ undo(): void;
55
+ redo(): void;
56
+ blur(): void;
57
+ caretClientRect(): {
58
+ left: number;
59
+ top: number;
60
+ height: number;
61
+ } | null;
62
+ readonly mirror?: TextMirror;
63
+ }
64
+ export interface TextMirror {
65
+ length(): number;
66
+ text(from: number, to: number): string;
67
+ selection(): {
68
+ anchor: number;
69
+ head: number;
70
+ };
71
+ textVersion(): unknown;
72
+ replace(from: number, to: number, text: string, anchor: number, head: number): void;
73
+ select(anchor: number, head: number): void;
74
+ compose(from: number, to: number, text: string): void;
75
+ composition(): {
76
+ from: number;
77
+ to: number;
78
+ } | null;
79
+ connect(hooks: TextMirrorHooks): () => void;
80
+ }
81
+ export interface TextMirrorHooks {
82
+ changed(): void;
83
+ sync(commit: boolean): void;
84
+ focused(): void;
85
+ }
86
+ export type TextMarks = Readonly<Record<string, unknown>>;
87
+ export interface TextPropertyTarget {
88
+ readonly objectId: string;
89
+ readMark(name: string): {
90
+ value: unknown;
91
+ mixed: boolean;
92
+ values?: unknown[];
93
+ };
94
+ writeMark(name: string, value: unknown): void;
95
+ previewMarks?(marks: TextMarks | null): void;
96
+ commitMarks?(marks: TextMarks, label: string, also?: (tx: DocTransaction) => void, text?: TextContent): void;
97
+ }
98
+ export interface TextSessionView {
99
+ readonly objectId: string;
100
+ liveObject(): SceneObject;
101
+ preedit(): {
102
+ from: number;
103
+ to: number;
104
+ } | null;
105
+ preeditRects(): Rect[];
106
+ caretRect(): Rect | null;
107
+ selectionRects(): Rect[];
108
+ caretVisible(now: number): boolean;
109
+ selectionEnds?(): readonly {
110
+ end: "anchor" | "head" | "caret";
111
+ rect: Rect;
112
+ }[];
113
+ drawnAs?(drawn: ((live: SceneObject) => SceneObject) | null): void;
114
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,78 @@
1
+ import { type Point, type Rect, type SceneStore, type Style } from "@daasboard/render-core";
2
+ import type { PropertyController } from "../props/PropertyController.js";
3
+ import type { SelectionModel } from "../selection/SelectionModel.js";
4
+ import type { PointerInfo } from "./SelectTool.js";
5
+ import { type SnapGuide } from "./snapping.js";
6
+ import { type ToolCursor } from "./transform.js";
7
+ import { type PresetName } from "./presetPaths.js";
8
+ export type CreateKind = "rect" | "ellipse" | "sticky" | "text" | "frame" | "section" | "connector" | "path";
9
+ export declare const CREATE_KINDS: readonly CreateKind[];
10
+ export type CreateToolName = Exclude<CreateKind, "path"> | PresetName;
11
+ export declare const CREATE_TOOL_NAMES: readonly CreateToolName[];
12
+ export interface CreationPreview {
13
+ kind: CreateKind;
14
+ rect: Rect | null;
15
+ line: {
16
+ from: Point;
17
+ to: Point;
18
+ } | null;
19
+ }
20
+ export interface CreateToolOptions {
21
+ parentToContainer?: boolean;
22
+ }
23
+ export interface CreateToolState {
24
+ mode: "idle" | "pressed" | "dragging";
25
+ preview: CreationPreview | null;
26
+ guides: readonly SnapGuide[];
27
+ }
28
+ export interface CreatePress {
29
+ readonly start: {
30
+ readonly ref: string;
31
+ readonly side: "t" | "r" | "b" | "l";
32
+ } | null;
33
+ }
34
+ export declare class CreateTool {
35
+ readonly name: CreateToolName;
36
+ private readonly store;
37
+ private readonly selection;
38
+ private readonly ctrl;
39
+ readonly kind: CreateKind;
40
+ private mode;
41
+ private cancelledPress;
42
+ private press;
43
+ private pointer;
44
+ private rawPress;
45
+ private snapDisabled;
46
+ private guides;
47
+ private previewBox;
48
+ private threshold;
49
+ private start;
50
+ private end;
51
+ onCreated?: (id: string, kind: CreateKind) => void;
52
+ private readonly parentToContainer;
53
+ private creationStyle_;
54
+ constructor(name: CreateToolName, store: SceneStore, selection: SelectionModel, ctrl: PropertyController, opts?: CreateToolOptions);
55
+ setCreationStyle(style: Style | undefined): void;
56
+ creationStyle(): Style | undefined;
57
+ private style;
58
+ state(): CreateToolState;
59
+ cursor(): ToolCursor;
60
+ creationPreview(): CreationPreview | null;
61
+ private dragRect;
62
+ private shapeAt;
63
+ private attach;
64
+ hover(_p: PointerInfo): void;
65
+ capturePress(p: PointerInfo): CreatePress;
66
+ pointerDown(p: PointerInfo, press?: CreatePress): boolean;
67
+ pointerMove(p: PointerInfo): void;
68
+ private endAt;
69
+ pointerUp(p: PointerInfo): string | null;
70
+ private createConnector;
71
+ private containerFor;
72
+ private adoptable;
73
+ cancel(): void;
74
+ key(key: string, _mods: {
75
+ shift: boolean;
76
+ ctrl: boolean;
77
+ }): boolean;
78
+ }
@@ -0,0 +1,258 @@
1
+ import { connectorBounds, endpointAnchor, hitTest, rotatedBounds } from "@daasboard/render-core";
2
+ import { defaultSize } from "../props/defaults.js";
3
+ import { snapBox } from "./snapping.js";
4
+ import { isTransformable, MIN_SIZE, nearestSide, pointerHit, pointerProfile, whole } from "./transform.js";
5
+ import { isPresetName, PRESET_NAMES, PRESET_PATHS } from "./presetPaths.js";
6
+ export const CREATE_KINDS = ["rect", "ellipse", "sticky", "text", "frame", "section", "connector", "path"];
7
+ export const CREATE_TOOL_NAMES = ["rect", "ellipse", ...PRESET_NAMES, "text", "sticky", "connector", "frame", "section"];
8
+ const CONTAINER_KINDS = new Set(["frame", "section"]);
9
+ export class CreateTool {
10
+ name;
11
+ store;
12
+ selection;
13
+ ctrl;
14
+ kind;
15
+ mode = "idle";
16
+ cancelledPress = false;
17
+ press = { x: 0, y: 0 };
18
+ pointer = { x: 0, y: 0 };
19
+ rawPress = { x: 0, y: 0 };
20
+ snapDisabled = false;
21
+ guides = [];
22
+ previewBox = null;
23
+ threshold = 3;
24
+ start = null;
25
+ end = null;
26
+ onCreated;
27
+ parentToContainer;
28
+ creationStyle_;
29
+ constructor(name, store, selection, ctrl, opts = {}) {
30
+ this.name = name;
31
+ this.store = store;
32
+ this.selection = selection;
33
+ this.ctrl = ctrl;
34
+ this.kind = isPresetName(name) ? "path" : name;
35
+ this.parentToContainer = opts.parentToContainer ?? true;
36
+ void this.selection;
37
+ }
38
+ setCreationStyle(style) {
39
+ this.creationStyle_ = style === undefined ? undefined : structuredClone(style);
40
+ }
41
+ creationStyle() {
42
+ return this.creationStyle_ === undefined ? undefined : structuredClone(this.creationStyle_);
43
+ }
44
+ style() {
45
+ return this.creationStyle() ?? {};
46
+ }
47
+ state() {
48
+ return { mode: this.mode, preview: this.creationPreview(), guides: this.guides };
49
+ }
50
+ cursor() {
51
+ return "crosshair";
52
+ }
53
+ creationPreview() {
54
+ if (this.mode !== "dragging")
55
+ return null;
56
+ if (this.kind === "connector") {
57
+ const from = this.start ? { x: this.start.at[0], y: this.start.at[1] } : this.press;
58
+ const to = this.end ? { x: this.end.at[0], y: this.end.at[1] } : this.pointer;
59
+ return { kind: this.kind, rect: null, line: { from, to } };
60
+ }
61
+ return { kind: this.kind, rect: this.previewBox ?? this.dragRect(), line: null };
62
+ }
63
+ dragRect(round = true) {
64
+ const finish = round ? whole : (v) => v;
65
+ const def = defaultSize(this.kind);
66
+ const dx = Math.abs(this.pointer.x - this.press.x);
67
+ const dy = Math.abs(this.pointer.y - this.press.y);
68
+ const rawDx = this.pointer.x - this.rawPress.x;
69
+ const rawDy = this.pointer.y - this.rawPress.y;
70
+ const openX = Math.abs(rawDx) >= this.threshold;
71
+ const openY = Math.abs(rawDy) >= this.threshold;
72
+ const x0 = Math.min(this.press.x, this.pointer.x);
73
+ const y0 = Math.min(this.press.y, this.pointer.y);
74
+ const w = openX ? Math.max(MIN_SIZE, finish(dx)) : def.w;
75
+ const h = openY ? Math.max(MIN_SIZE, finish(dy)) : def.h;
76
+ return { x: finish(openX ? x0 : this.press.x + rawDx / 2 - w / 2), y: finish(openY ? y0 : this.press.y + rawDy / 2 - h / 2), w, h };
77
+ }
78
+ shapeAt(p) {
79
+ return pointerHit(this.store, p, isTransformable);
80
+ }
81
+ attach(o, p) {
82
+ const side = nearestSide(o, p);
83
+ return { ref: o.id, side, at: endpointAnchor(o, side, o.rot) };
84
+ }
85
+ hover(_p) {
86
+ }
87
+ capturePress(p) {
88
+ const hit = this.kind === "connector" ? this.shapeAt(p) : undefined;
89
+ return { start: hit ? { ref: hit.id, side: nearestSide(hit, p) } : null };
90
+ }
91
+ pointerDown(p, press) {
92
+ let start = null;
93
+ if (this.kind === "connector" && press?.start) {
94
+ const o = this.store.scene.objects.get(press.start.ref);
95
+ if (!o || !isTransformable(o))
96
+ return false;
97
+ start = { ref: o.id, side: press.start.side, at: endpointAnchor(o, press.start.side, o.rot) };
98
+ }
99
+ else if (this.kind === "connector" && !press) {
100
+ const hit = this.shapeAt(p);
101
+ if (hit)
102
+ start = this.attach(hit, p);
103
+ }
104
+ this.cancelledPress = false;
105
+ this.rawPress = { x: p.x, y: p.y };
106
+ this.snapDisabled = !!p.snapOff;
107
+ this.guides = [];
108
+ this.previewBox = null;
109
+ this.press = { x: p.x, y: p.y };
110
+ this.pointer = { x: p.x, y: p.y };
111
+ this.threshold = pointerProfile(p).dragThreshold;
112
+ this.mode = "pressed";
113
+ this.end = null;
114
+ this.start = start;
115
+ return true;
116
+ }
117
+ pointerMove(p) {
118
+ if (this.mode === "idle")
119
+ return;
120
+ this.snapDisabled ||= !!p.snapOff;
121
+ this.pointer = { x: p.x, y: p.y };
122
+ if (this.mode === "pressed") {
123
+ if (Math.abs(p.x - this.press.x) < this.threshold && Math.abs(p.y - this.press.y) < this.threshold)
124
+ return;
125
+ this.mode = "dragging";
126
+ }
127
+ this.guides = [];
128
+ this.press = { ...this.rawPress };
129
+ if (this.kind === "connector") {
130
+ this.end = this.endAt(p);
131
+ if (!this.snapDisabled) {
132
+ if (!this.start) {
133
+ const start = snapBox(this.store, { ...this.press, w: 0, h: 0 }, p.zoom, undefined, { spacing: false });
134
+ this.press = { x: this.press.x + start.dx, y: this.press.y + start.dy };
135
+ }
136
+ if (!this.end) {
137
+ const end = snapBox(this.store, { ...this.pointer, w: 0, h: 0 }, p.zoom, undefined, { spacing: false });
138
+ this.pointer = { x: p.x + end.dx, y: p.y + end.dy };
139
+ this.guides = end.guides;
140
+ }
141
+ }
142
+ return;
143
+ }
144
+ let startGuides = [];
145
+ if (!this.snapDisabled) {
146
+ const start = snapBox(this.store, { ...this.press, w: 0, h: 0 }, p.zoom, undefined, { spacing: false });
147
+ this.press = { x: this.press.x + start.dx, y: this.press.y + start.dy };
148
+ startGuides = start.guides;
149
+ }
150
+ let box = this.dragRect(this.snapDisabled);
151
+ if (!this.snapDisabled) {
152
+ const openX = Math.abs(p.x - this.rawPress.x) >= this.threshold;
153
+ const openY = Math.abs(p.y - this.rawPress.y) >= this.threshold;
154
+ const x = p.x >= this.press.x ? box.x + box.w : box.x;
155
+ const y = p.y >= this.press.y ? box.y + box.h : box.y;
156
+ const snap = snapBox(this.store, box, p.zoom, undefined, { x: openX ? [x] : [], y: openY ? [y] : [] });
157
+ const x0 = p.x >= this.press.x ? box.x : box.x + snap.dx;
158
+ const x1 = p.x >= this.press.x ? box.x + box.w + snap.dx : box.x + box.w;
159
+ const y0 = p.y >= this.press.y ? box.y : box.y + snap.dy;
160
+ const y1 = p.y >= this.press.y ? box.y + box.h + snap.dy : box.y + box.h;
161
+ box = { x: x0, y: y0, w: Math.max(MIN_SIZE, x1 - x0), h: Math.max(MIN_SIZE, y1 - y0) };
162
+ this.guides = snap.guides.filter((g) => Math.abs(g.at - (g.axis === "x" ? p.x >= this.press.x ? box.x + box.w : box.x : p.y >= this.press.y ? box.y + box.h : box.y)) < 1e-7);
163
+ const all = [...startGuides, ...this.guides];
164
+ if (!all.some(g => g.axis === "x"))
165
+ box = { ...box, x: whole(box.x), w: Math.max(MIN_SIZE, whole(box.w)) };
166
+ if (!all.some(g => g.axis === "y"))
167
+ box = { ...box, y: whole(box.y), h: Math.max(MIN_SIZE, whole(box.h)) };
168
+ this.guides = all.filter(g => {
169
+ const low = box[g.axis], size = g.axis === "x" ? box.w : box.h;
170
+ return [low, low + size / 2, low + size].some(value => Math.abs(value - g.at) < 1e-7);
171
+ });
172
+ }
173
+ this.previewBox = box;
174
+ }
175
+ endAt(p) {
176
+ const hit = this.shapeAt(p);
177
+ return hit && hit.id !== this.start?.ref ? this.attach(hit, p) : null;
178
+ }
179
+ pointerUp(p) {
180
+ this.cancelledPress = false;
181
+ if (this.mode === "idle")
182
+ return null;
183
+ const dragged = this.mode === "dragging";
184
+ if (dragged)
185
+ this.pointerMove(p);
186
+ this.mode = "idle";
187
+ this.guides = [];
188
+ if (this.kind === "connector") {
189
+ const id = dragged ? this.createConnector(p) : null;
190
+ this.start = this.end = null;
191
+ return id;
192
+ }
193
+ let box;
194
+ if (dragged)
195
+ box = this.previewBox ?? this.dragRect();
196
+ else {
197
+ const { w, h } = defaultSize(this.kind);
198
+ box = { x: whole(this.press.x - w / 2), y: whole(this.press.y - h / 2), w, h };
199
+ }
200
+ const parent = this.containerFor(box);
201
+ const path = isPresetName(this.name) ? { path: PRESET_PATHS[this.name].map(cmd => ({ ...cmd })) } : {};
202
+ const id = this.ctrl.create({ kind: this.kind, ...box, ...path, style: this.style() }, { parent, adopt: this.adoptable(box, parent) });
203
+ this.onCreated?.(id, this.kind);
204
+ return id;
205
+ }
206
+ createConnector(p) {
207
+ const under = this.shapeAt(p);
208
+ if (this.start && under && under.id === this.start.ref)
209
+ return null;
210
+ const end = under ? this.attach(under, p) : null;
211
+ const start = this.start ? { ref: this.start.ref, side: this.start.side } : {};
212
+ const endpoint = end ? { ref: end.ref, side: end.side } : {};
213
+ const conn = { route: "curve", start, end: endpoint, startAt: this.start ? this.start.at : [this.press.x, this.press.y], endAt: end ? end.at : [this.pointer.x, this.pointer.y] };
214
+ const box = connectorBounds(conn, this.store.scene);
215
+ const id = this.ctrl.create({ kind: "connector", x: box.x, y: box.y, w: box.w, h: box.h, conn, style: this.style() }, { parent: null });
216
+ this.onCreated?.(id, "connector");
217
+ return id;
218
+ }
219
+ containerFor(box) {
220
+ if (!this.parentToContainer || CONTAINER_KINDS.has(this.kind))
221
+ return null;
222
+ return hitTest(this.store, box.x + box.w / 2, box.y + box.h / 2).find((o) => CONTAINER_KINDS.has(o.kind))?.id ?? null;
223
+ }
224
+ adoptable(box, parent) {
225
+ if (!this.parentToContainer || !CONTAINER_KINDS.has(this.kind))
226
+ return [];
227
+ const out = [];
228
+ for (const id of this.store.index.search(box)) {
229
+ const o = this.store.scene.objects.get(id);
230
+ if (!o || o.hidden || o.kind === "connector" || (o.parent ?? null) !== parent)
231
+ continue;
232
+ const b = rotatedBounds({ x: o.x, y: o.y, w: o.w, h: o.h }, o.rot);
233
+ if (b.x >= box.x && b.y >= box.y && b.x + b.w <= box.x + box.w && b.y + b.h <= box.y + box.h)
234
+ out.push(o);
235
+ }
236
+ out.sort((a, b) => this.store.rankOf(a.id) - this.store.rankOf(b.id));
237
+ return out.map((o) => o.id);
238
+ }
239
+ cancel() {
240
+ this.cancelledPress = false;
241
+ this.mode = "idle";
242
+ this.guides = [];
243
+ this.previewBox = null;
244
+ this.start = this.end = null;
245
+ }
246
+ key(key, _mods) {
247
+ if (this.cancelledPress)
248
+ return true;
249
+ if (this.mode !== "idle") {
250
+ if (key === "Escape") {
251
+ this.cancel();
252
+ this.cancelledPress = true;
253
+ }
254
+ return true;
255
+ }
256
+ return false;
257
+ }
258
+ }
@@ -0,0 +1,155 @@
1
+ import { type Point, type Rect, type SceneStore } from "@daasboard/render-core";
2
+ import { type PresenceDrag } from "@daasboard/doc";
3
+ import type { PropertyController } from "../props/PropertyController.js";
4
+ import type { SelectionModel } from "../selection/SelectionModel.js";
5
+ import { type GradientHandleEdit, type GradientHandleGeometry, type GradientHandleKind, type GradientHandleTarget } from "./gradientHandles.js";
6
+ import { type ConnectorEnd, type ConnectorEndpointRef } from "./connectorEndpoints.js";
7
+ import { type SnapGuide } from "./snapping.js";
8
+ import { type HandleFrame, type HandleKind, type HandleProfile, type ToolCursor } from "./transform.js";
9
+ export interface SelectToolOptions {
10
+ reparentOnDrop?: boolean;
11
+ onPresenceDrag?: (drag: PresenceDrag | null) => void;
12
+ }
13
+ export interface PointerInfo {
14
+ pointer?: "mouse" | "pen" | "touch";
15
+ x: number;
16
+ y: number;
17
+ shift: boolean;
18
+ alt: boolean;
19
+ snapOff?: boolean;
20
+ tolerance: number;
21
+ zoom: number;
22
+ }
23
+ export interface SelectToolState {
24
+ handleProfile?: HandleProfile;
25
+ mode: "idle" | "pressed" | "moving" | "marquee" | "handle" | "resizing" | "rotating" | "gradient" | "endpoint";
26
+ marquee: Rect | null;
27
+ hover: string | null;
28
+ handle: HandleKind | null;
29
+ guides: readonly SnapGuide[];
30
+ sizeLabel: {
31
+ width: number;
32
+ height: number;
33
+ at: Point;
34
+ } | null;
35
+ gradient?: GradientHandleState | null;
36
+ endpoint?: ConnectorEndpointRef | null;
37
+ }
38
+ export interface GradientHandleState extends GradientHandleGeometry {
39
+ active: GradientHandleKind | null;
40
+ }
41
+ export interface GradientHandleEvents {
42
+ preview(edit: GradientHandleEdit): void;
43
+ commit(edit: GradientHandleEdit): void;
44
+ cancel(): void;
45
+ }
46
+ export interface GradientHandleSession {
47
+ cancelDrag(): void;
48
+ hide(): void;
49
+ }
50
+ export type SelectPress = {
51
+ readonly kind: "gradient";
52
+ readonly handle: GradientHandleKind;
53
+ readonly type: "linear" | "radial";
54
+ readonly target: GradientHandleTarget;
55
+ } | {
56
+ readonly kind: "handle";
57
+ readonly handle: HandleKind;
58
+ readonly ids: readonly string[];
59
+ readonly profile: HandleProfile | undefined;
60
+ } | {
61
+ readonly kind: "endpoint";
62
+ readonly id: string;
63
+ readonly end: ConnectorEnd;
64
+ readonly grab: Point;
65
+ } | {
66
+ readonly kind: "object";
67
+ readonly id: string;
68
+ readonly selected: boolean;
69
+ } | {
70
+ readonly kind: "canvas";
71
+ };
72
+ export declare class SelectTool {
73
+ private readonly store;
74
+ private readonly selection;
75
+ private readonly ctrl;
76
+ private mode;
77
+ private handleProfile_;
78
+ private cancelledPress;
79
+ private pressWorld;
80
+ private pressedId;
81
+ private pressedWasSelected;
82
+ private starts;
83
+ private moveObjects;
84
+ private snapDisabled;
85
+ private guides;
86
+ private sizeLabel;
87
+ private marqueeRect;
88
+ private hoverId;
89
+ private hoverHandle;
90
+ private hoverRot;
91
+ private handle;
92
+ private transform;
93
+ private editingId;
94
+ private gradient;
95
+ private gradientHover;
96
+ private gradientDrag;
97
+ private hoverEndpoint;
98
+ private endpointDrag;
99
+ private threshold;
100
+ private preciseGrab;
101
+ onEditText?: (id: string, at?: {
102
+ x: number;
103
+ y: number;
104
+ }) => void;
105
+ private readonly reparentOnDrop;
106
+ private readonly onPresenceDrag;
107
+ constructor(store: SceneStore, selection: SelectionModel, ctrl: PropertyController, opts?: SelectToolOptions);
108
+ state(): SelectToolState;
109
+ setPointerProfile(p: Pick<PointerInfo, "pointer" | "tolerance" | "zoom">): void;
110
+ cursor(): ToolCursor;
111
+ showGradientHandles(target: GradientHandleTarget, events: GradientHandleEvents, opts?: {
112
+ presses?: boolean;
113
+ }): GradientHandleSession;
114
+ gradientHandleAt(p: PointerInfo): GradientHandleKind | null;
115
+ pressTarget(p: PointerInfo): "gradient" | "handle" | "selected" | "object" | "canvas";
116
+ capturePress(p: PointerInfo): SelectPress;
117
+ private pressable;
118
+ private hitProfile;
119
+ private viewScene;
120
+ private endpointConnector;
121
+ private hoveredEndpoint;
122
+ private endpointHandles;
123
+ private endpointMarkerAt;
124
+ private previewEndpoint;
125
+ private endEndpointDrag;
126
+ gradientHandleTarget(): GradientHandleTarget | null;
127
+ private gradientGeometry;
128
+ private gradientNow;
129
+ private hideGradientHandles;
130
+ private endGradientDrag;
131
+ private beginGradientDrag;
132
+ private gradientEdit;
133
+ setTextEditing(id: string | null): void;
134
+ private transformTargets;
135
+ private hasAncestorIn;
136
+ transformBounds(): Rect | null;
137
+ handleFrame(): HandleFrame | null;
138
+ handlePositions(zoom: number, p?: Pick<PointerInfo, "pointer" | "tolerance" | "zoom">): Record<HandleKind, Point> | null;
139
+ hover(p: PointerInfo): void;
140
+ pointerDown(p: PointerInfo, press?: SelectPress): boolean;
141
+ pointerMove(p: PointerInfo): void;
142
+ private stillPressed;
143
+ private publishPresenceDrag;
144
+ private previewResize;
145
+ private previewRotate;
146
+ pointerUp(p: PointerInfo): void;
147
+ private dropContainerAt;
148
+ doubleClick(p: PointerInfo): void;
149
+ private editableSelected;
150
+ cancel(): void;
151
+ key(key: string, mods: {
152
+ shift: boolean;
153
+ ctrl: boolean;
154
+ }): boolean;
155
+ }