@g9tm/lynxcontrols-studio 0.0.0-stage → 2.8.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/README.md +184 -2
- package/catalog/cards/G9NleTimeline.md +17 -0
- package/catalog/cards/G9Surface.md +16 -0
- package/catalog/cards/G9TransformBox.md +17 -0
- package/catalog/catalog.json +2255 -0
- package/catalog/index.md +7 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +3 -0
- package/dist/nle-timeline/core.d.ts +5 -0
- package/dist/nle-timeline/core.d.ts.map +1 -0
- package/dist/nle-timeline/core.js +4 -0
- package/dist/nle-timeline/core.jsx +4 -0
- package/dist/nle-timeline/edits.d.ts +65 -0
- package/dist/nle-timeline/edits.d.ts.map +1 -0
- package/dist/nle-timeline/edits.js +344 -0
- package/dist/nle-timeline/edits.js.map +1 -0
- package/dist/nle-timeline/edits.jsx +342 -0
- package/dist/nle-timeline/engine.d.ts +159 -0
- package/dist/nle-timeline/engine.d.ts.map +1 -0
- package/dist/nle-timeline/engine.js +899 -0
- package/dist/nle-timeline/engine.js.map +1 -0
- package/dist/nle-timeline/engine.jsx +897 -0
- package/dist/nle-timeline/index.d.ts +6 -0
- package/dist/nle-timeline/index.d.ts.map +1 -0
- package/dist/nle-timeline/index.jsx +5 -0
- package/dist/nle-timeline/layout.d.ts +116 -0
- package/dist/nle-timeline/layout.d.ts.map +1 -0
- package/dist/nle-timeline/layout.js +310 -0
- package/dist/nle-timeline/layout.js.map +1 -0
- package/dist/nle-timeline/layout.jsx +308 -0
- package/dist/nle-timeline/model.d.ts +140 -0
- package/dist/nle-timeline/model.d.ts.map +1 -0
- package/dist/nle-timeline/model.js +155 -0
- package/dist/nle-timeline/model.js.map +1 -0
- package/dist/nle-timeline/model.jsx +153 -0
- package/dist/nle-timeline/nle.d.ts +72 -0
- package/dist/nle-timeline/nle.d.ts.map +1 -0
- package/dist/nle-timeline/nle.jsx +92 -0
- package/dist/surface/core.d.ts +2 -0
- package/dist/surface/core.d.ts.map +1 -0
- package/dist/surface/core.js +1 -0
- package/dist/surface/core.jsx +1 -0
- package/dist/surface/index.d.ts +3 -0
- package/dist/surface/index.d.ts.map +1 -0
- package/dist/surface/index.jsx +2 -0
- package/dist/surface/protocol.d.ts +40 -0
- package/dist/surface/protocol.d.ts.map +1 -0
- package/dist/surface/protocol.js +19 -0
- package/dist/surface/protocol.js.map +1 -0
- package/dist/surface/protocol.jsx +17 -0
- package/dist/surface/surface.d.ts +53 -0
- package/dist/surface/surface.d.ts.map +1 -0
- package/dist/surface/surface.jsx +62 -0
- package/dist/transform-box/core.d.ts +3 -0
- package/dist/transform-box/core.d.ts.map +1 -0
- package/dist/transform-box/core.js +2 -0
- package/dist/transform-box/core.jsx +2 -0
- package/dist/transform-box/engine.d.ts +152 -0
- package/dist/transform-box/engine.d.ts.map +1 -0
- package/dist/transform-box/engine.js +636 -0
- package/dist/transform-box/engine.js.map +1 -0
- package/dist/transform-box/engine.jsx +634 -0
- package/dist/transform-box/geometry.d.ts +129 -0
- package/dist/transform-box/geometry.d.ts.map +1 -0
- package/dist/transform-box/geometry.js +506 -0
- package/dist/transform-box/geometry.js.map +1 -0
- package/dist/transform-box/geometry.jsx +504 -0
- package/dist/transform-box/index.d.ts +4 -0
- package/dist/transform-box/index.d.ts.map +1 -0
- package/dist/transform-box/index.jsx +3 -0
- package/dist/transform-box/transform-box.d.ts +65 -0
- package/dist/transform-box/transform-box.d.ts.map +1 -0
- package/dist/transform-box/transform-box.jsx +104 -0
- package/package.json +56 -4
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import { aabbOf, fitOf, frameOf, hitBox, hitHandle, mapBoxes, moveBoxes, normDeg, resizeFrame, rotateBoxes, selectionFrame, snapAngle, snapMove, snapResize, toStage } from "./geometry.js";
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
const TB_KEYS = [
|
|
13
|
+
[
|
|
14
|
+
'arrows',
|
|
15
|
+
'nudge one unit (shift: ten)'
|
|
16
|
+
],
|
|
17
|
+
[
|
|
18
|
+
'[ ]',
|
|
19
|
+
'rotate one degree (shift: fifteen)'
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
'- =',
|
|
23
|
+
'scale 5 % down / up'
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
'tab / shift+tab',
|
|
27
|
+
'select the next / previous box'
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
'ctrl+a',
|
|
31
|
+
'select all'
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
'ctrl+= ctrl+- ctrl+0',
|
|
35
|
+
'zoom the stage in / out, fit'
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
'delete, backspace',
|
|
39
|
+
'delete (asked of the app)'
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
'ctrl+z, ctrl+shift+z, ctrl+y',
|
|
43
|
+
'undo, redo (asked of the app)'
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
'ctrl+d, ctrl+c, ctrl+v',
|
|
47
|
+
'duplicate, copy, paste (asked of the app)'
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
'ctrl+] ctrl+[',
|
|
51
|
+
'bring forward, send backward (asked of the app)'
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
'enter',
|
|
55
|
+
'open the selected box'
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
'escape',
|
|
59
|
+
'clear the selection'
|
|
60
|
+
]
|
|
61
|
+
];
|
|
62
|
+
const SLOP = 4;
|
|
63
|
+
const DOUBLE_MS = 350;
|
|
64
|
+
const MIN_ZOOM = 0.25;
|
|
65
|
+
const MAX_ZOOM = 16;
|
|
66
|
+
class TbEngine {
|
|
67
|
+
get fit() {
|
|
68
|
+
return fitOf(this.stage, this.size, this.view.zoom, this.view.panX, this.view.panY, this.padding);
|
|
69
|
+
}
|
|
70
|
+
get busy() {
|
|
71
|
+
return null !== this.drag && 'pending' !== this.drag.kind;
|
|
72
|
+
}
|
|
73
|
+
apply(m) {
|
|
74
|
+
if (m.stage) this.stage = {
|
|
75
|
+
w: Math.max(1, m.stage.w),
|
|
76
|
+
h: Math.max(1, m.stage.h)
|
|
77
|
+
};
|
|
78
|
+
if (m.boxes) this.boxes = m.boxes.slice();
|
|
79
|
+
if (m.update) for (const box of m.update){
|
|
80
|
+
const i = this.boxes.findIndex((b)=>b.id === box.id);
|
|
81
|
+
if (i >= 0) this.boxes[i] = box;
|
|
82
|
+
else this.boxes.push(box);
|
|
83
|
+
}
|
|
84
|
+
if (m.remove) {
|
|
85
|
+
const gone = new Set(m.remove);
|
|
86
|
+
this.boxes = this.boxes.filter((b)=>!gone.has(b.id));
|
|
87
|
+
}
|
|
88
|
+
if (m.selection) this.selection = m.selection.slice();
|
|
89
|
+
const ids = new Set(this.boxes.map((b)=>b.id));
|
|
90
|
+
this.selection = this.selection.filter((id)=>ids.has(id));
|
|
91
|
+
if (m.safeZones) this.safeZones = m.safeZones.slice();
|
|
92
|
+
if (m.view) this.view = {
|
|
93
|
+
...this.view,
|
|
94
|
+
...m.view
|
|
95
|
+
};
|
|
96
|
+
if (!this.drag) this.live = null;
|
|
97
|
+
this.invalidate();
|
|
98
|
+
}
|
|
99
|
+
resize(w, h) {
|
|
100
|
+
this.size = {
|
|
101
|
+
w,
|
|
102
|
+
h
|
|
103
|
+
};
|
|
104
|
+
this.announceView();
|
|
105
|
+
this.invalidate();
|
|
106
|
+
}
|
|
107
|
+
shown() {
|
|
108
|
+
const live = this.live;
|
|
109
|
+
return live ? this.boxes.map((b)=>{
|
|
110
|
+
var _live_get;
|
|
111
|
+
return null != (_live_get = live.get(b.id)) ? _live_get : b;
|
|
112
|
+
}) : this.boxes;
|
|
113
|
+
}
|
|
114
|
+
selected() {
|
|
115
|
+
const set = new Set(this.selection);
|
|
116
|
+
return this.shown().filter((b)=>set.has(b.id));
|
|
117
|
+
}
|
|
118
|
+
frame() {
|
|
119
|
+
return selectionFrame(this.selected());
|
|
120
|
+
}
|
|
121
|
+
select(ids) {
|
|
122
|
+
if (ids.length === this.selection.length && ids.every((id, i)=>this.selection[i] === id)) return;
|
|
123
|
+
this.selection = ids;
|
|
124
|
+
this.emit('tbselect', {
|
|
125
|
+
ids: ids.slice()
|
|
126
|
+
});
|
|
127
|
+
this.invalidate();
|
|
128
|
+
}
|
|
129
|
+
announceView() {
|
|
130
|
+
const fit = this.fit;
|
|
131
|
+
this.emit('tbview', {
|
|
132
|
+
...this.view,
|
|
133
|
+
scale: fit.scale,
|
|
134
|
+
offsetX: fit.ox,
|
|
135
|
+
offsetY: fit.oy
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
setView(view, announce = true) {
|
|
139
|
+
this.view = {
|
|
140
|
+
...this.view,
|
|
141
|
+
...view
|
|
142
|
+
};
|
|
143
|
+
this.view = {
|
|
144
|
+
...this.view,
|
|
145
|
+
zoom: Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, this.view.zoom))
|
|
146
|
+
};
|
|
147
|
+
if (announce) this.announceView();
|
|
148
|
+
this.invalidate();
|
|
149
|
+
}
|
|
150
|
+
zoomAt(factor, x, y) {
|
|
151
|
+
const [sx, sy] = toStage(this.fit, x, y);
|
|
152
|
+
const zoom = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, this.view.zoom * factor));
|
|
153
|
+
this.view = {
|
|
154
|
+
...this.view,
|
|
155
|
+
zoom
|
|
156
|
+
};
|
|
157
|
+
const after = this.fit;
|
|
158
|
+
this.setView({
|
|
159
|
+
panX: this.view.panX + (x - (after.ox + sx * after.scale)),
|
|
160
|
+
panY: this.view.panY + (y - (after.oy + sy * after.scale))
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
within() {
|
|
164
|
+
return this.snapPx / this.fit.scale;
|
|
165
|
+
}
|
|
166
|
+
others(moving) {
|
|
167
|
+
return this.boxes.filter((b)=>!moving.has(b.id)).map((b)=>aabbOf([
|
|
168
|
+
frameOf(b)
|
|
169
|
+
]));
|
|
170
|
+
}
|
|
171
|
+
pointerDown(p) {
|
|
172
|
+
this.pointers.set(p.id, p);
|
|
173
|
+
if (2 === this.pointers.size && [
|
|
174
|
+
...this.pointers.values()
|
|
175
|
+
].every((q)=>'touch' === q.type)) {
|
|
176
|
+
this.live = null;
|
|
177
|
+
this.guides = [];
|
|
178
|
+
const [a, b] = [
|
|
179
|
+
...this.pointers.values()
|
|
180
|
+
];
|
|
181
|
+
const mid = [
|
|
182
|
+
(a.x + b.x) / 2,
|
|
183
|
+
(a.y + b.y) / 2
|
|
184
|
+
];
|
|
185
|
+
this.drag = {
|
|
186
|
+
kind: 'pinch',
|
|
187
|
+
ids: [
|
|
188
|
+
a.id,
|
|
189
|
+
b.id
|
|
190
|
+
],
|
|
191
|
+
dist: Math.max(10, Math.hypot(a.x - b.x, a.y - b.y)),
|
|
192
|
+
zoom: this.view.zoom,
|
|
193
|
+
mid,
|
|
194
|
+
stagePt: toStage(this.fit, mid[0], mid[1])
|
|
195
|
+
};
|
|
196
|
+
this.invalidate();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (this.pointers.size > 1) return;
|
|
200
|
+
const fit = this.fit;
|
|
201
|
+
const frame = this.frame();
|
|
202
|
+
const radius = 'touch' === p.type ? 18 : 9;
|
|
203
|
+
if (frame && this.editable && !this.selected().some((b)=>b.locked)) {
|
|
204
|
+
const handle = hitHandle(frame, fit, p.x, p.y, radius);
|
|
205
|
+
if ('rot' === handle) {
|
|
206
|
+
const [sx, sy] = toStage(fit, p.x, p.y);
|
|
207
|
+
this.drag = {
|
|
208
|
+
kind: 'rotate',
|
|
209
|
+
start: this.selected(),
|
|
210
|
+
cx: frame.cx,
|
|
211
|
+
cy: frame.cy,
|
|
212
|
+
a0: 180 * Math.atan2(sy - frame.cy, sx - frame.cx) / Math.PI,
|
|
213
|
+
r0: frame.rotation
|
|
214
|
+
};
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (handle) {
|
|
218
|
+
this.drag = {
|
|
219
|
+
kind: 'scale',
|
|
220
|
+
handle,
|
|
221
|
+
start: this.selected(),
|
|
222
|
+
frame
|
|
223
|
+
};
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const [sx, sy] = toStage(fit, p.x, p.y);
|
|
228
|
+
const hit = hitBox(this.boxes, sx, sy, ('touch' === p.type ? 6 : 2) / fit.scale);
|
|
229
|
+
this.drag = {
|
|
230
|
+
kind: 'pending',
|
|
231
|
+
x: p.x,
|
|
232
|
+
y: p.y,
|
|
233
|
+
hit,
|
|
234
|
+
pointer: p
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
pointerMove(p) {
|
|
238
|
+
if (!this.pointers.has(p.id)) return;
|
|
239
|
+
this.pointers.set(p.id, p);
|
|
240
|
+
const drag = this.drag;
|
|
241
|
+
if (!drag) return;
|
|
242
|
+
const fit = this.fit;
|
|
243
|
+
if ('pinch' === drag.kind) {
|
|
244
|
+
const a = this.pointers.get(drag.ids[0]);
|
|
245
|
+
const b = this.pointers.get(drag.ids[1]);
|
|
246
|
+
if (!a || !b) return;
|
|
247
|
+
const dist = Math.max(10, Math.hypot(a.x - b.x, a.y - b.y));
|
|
248
|
+
const mid = [
|
|
249
|
+
(a.x + b.x) / 2,
|
|
250
|
+
(a.y + b.y) / 2
|
|
251
|
+
];
|
|
252
|
+
const zoom = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, drag.zoom * dist / drag.dist));
|
|
253
|
+
this.view = {
|
|
254
|
+
...this.view,
|
|
255
|
+
zoom
|
|
256
|
+
};
|
|
257
|
+
const after = this.fit;
|
|
258
|
+
this.setView({
|
|
259
|
+
panX: this.view.panX + (mid[0] - (after.ox + drag.stagePt[0] * after.scale)),
|
|
260
|
+
panY: this.view.panY + (mid[1] - (after.oy + drag.stagePt[1] * after.scale))
|
|
261
|
+
});
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if ('pending' === drag.kind) {
|
|
265
|
+
if (Math.abs(p.x - drag.x) < SLOP && Math.abs(p.y - drag.y) < SLOP) return;
|
|
266
|
+
this.startDrag(drag, p);
|
|
267
|
+
this.pointerMove(p);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if ('pan' === drag.kind) return void this.setView({
|
|
271
|
+
panX: drag.panX + p.x - drag.x,
|
|
272
|
+
panY: drag.panY + p.y - drag.y
|
|
273
|
+
});
|
|
274
|
+
if ('marquee' === drag.kind) {
|
|
275
|
+
drag.x1 = p.x;
|
|
276
|
+
drag.y1 = p.y;
|
|
277
|
+
this.marquee = {
|
|
278
|
+
x0: drag.x0,
|
|
279
|
+
y0: drag.y0,
|
|
280
|
+
x1: p.x,
|
|
281
|
+
y1: p.y
|
|
282
|
+
};
|
|
283
|
+
const [ax, ay] = toStage(fit, Math.min(drag.x0, p.x), Math.min(drag.y0, p.y));
|
|
284
|
+
const [bx, by] = toStage(fit, Math.max(drag.x0, p.x), Math.max(drag.y0, p.y));
|
|
285
|
+
const inside = this.boxes.filter((b)=>{
|
|
286
|
+
const a = aabbOf([
|
|
287
|
+
frameOf(b)
|
|
288
|
+
]);
|
|
289
|
+
return a.x0 >= ax && a.y0 >= ay && a.x1 <= bx && a.y1 <= by;
|
|
290
|
+
}).map((b)=>b.id);
|
|
291
|
+
this.select(drag.additive ? [
|
|
292
|
+
...new Set([
|
|
293
|
+
...drag.base,
|
|
294
|
+
...inside
|
|
295
|
+
])
|
|
296
|
+
] : inside);
|
|
297
|
+
this.invalidate();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const [sx, sy] = toStage(fit, p.x, p.y);
|
|
301
|
+
let boxes;
|
|
302
|
+
let kind;
|
|
303
|
+
this.guides = [];
|
|
304
|
+
if ('move' === drag.kind) {
|
|
305
|
+
let dx = sx - drag.sx;
|
|
306
|
+
let dy = sy - drag.sy;
|
|
307
|
+
if (p.shift) if (Math.abs(dx) > Math.abs(dy)) dy = 0;
|
|
308
|
+
else dx = 0;
|
|
309
|
+
const moved = moveBoxes(drag.start, dx, dy);
|
|
310
|
+
if (this.guidesOn && !p.alt) {
|
|
311
|
+
const snap = snapMove(aabbOf(moved.map(frameOf)), this.others(new Set(drag.start.map((b)=>b.id))), this.stage, this.safeZones, this.within());
|
|
312
|
+
boxes = moveBoxes(moved, snap.dx, snap.dy);
|
|
313
|
+
this.guides = snap.guides;
|
|
314
|
+
} else boxes = moved;
|
|
315
|
+
kind = 'move';
|
|
316
|
+
} else if ('scale' === drag.kind) {
|
|
317
|
+
const one = 1 === drag.start.length ? drag.start[0] : void 0;
|
|
318
|
+
const corner = 2 === drag.handle.length;
|
|
319
|
+
const keepAspect = corner && !p.shift || Boolean(null == one ? void 0 : one.keepAspect) || !corner && Boolean(p.shift);
|
|
320
|
+
let frame = resizeFrame(drag.frame, drag.handle, sx, sy, {
|
|
321
|
+
keepAspect,
|
|
322
|
+
fromCenter: Boolean(p.alt),
|
|
323
|
+
min: 4 / fit.scale
|
|
324
|
+
});
|
|
325
|
+
if (this.guidesOn && !keepAspect && !p.alt) {
|
|
326
|
+
const snapped = snapResize(frame, drag.handle, this.others(new Set(drag.start.map((b)=>b.id))), this.stage, this.safeZones, this.within());
|
|
327
|
+
frame = snapped.frame;
|
|
328
|
+
this.guides = snapped.guides;
|
|
329
|
+
}
|
|
330
|
+
boxes = mapBoxes(drag.start, drag.frame, frame);
|
|
331
|
+
kind = 'scale';
|
|
332
|
+
} else {
|
|
333
|
+
const a = 180 * Math.atan2(sy - drag.cy, sx - drag.cx) / Math.PI;
|
|
334
|
+
const target = snapAngle(drag.r0 + a - drag.a0, p.shift ? 15 : null);
|
|
335
|
+
boxes = rotateBoxes(drag.start, drag.cx, drag.cy, normDeg(target - drag.r0));
|
|
336
|
+
kind = 'rotate';
|
|
337
|
+
}
|
|
338
|
+
this.live = new Map(boxes.map((b)=>[
|
|
339
|
+
b.id,
|
|
340
|
+
b
|
|
341
|
+
]));
|
|
342
|
+
this.emit('tbtransform', {
|
|
343
|
+
phase: 'move',
|
|
344
|
+
kind,
|
|
345
|
+
via: 'pointer',
|
|
346
|
+
boxes
|
|
347
|
+
});
|
|
348
|
+
this.invalidate();
|
|
349
|
+
}
|
|
350
|
+
pointerUp(p) {
|
|
351
|
+
this.pointers.delete(p.id);
|
|
352
|
+
const drag = this.drag;
|
|
353
|
+
if ((null == drag ? void 0 : drag.kind) === 'pinch') {
|
|
354
|
+
if (!this.pointers.size) this.drag = null;
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
this.drag = null;
|
|
358
|
+
this.guides = [];
|
|
359
|
+
this.marquee = null;
|
|
360
|
+
if (!drag) return;
|
|
361
|
+
if ('pending' === drag.kind) return void this.tap(drag, p);
|
|
362
|
+
if ('move' === drag.kind || 'scale' === drag.kind || 'rotate' === drag.kind) {
|
|
363
|
+
const live = this.live;
|
|
364
|
+
this.live = null;
|
|
365
|
+
if (live) {
|
|
366
|
+
this.boxes = this.boxes.map((b)=>{
|
|
367
|
+
var _live_get;
|
|
368
|
+
return null != (_live_get = live.get(b.id)) ? _live_get : b;
|
|
369
|
+
});
|
|
370
|
+
this.emit('tbtransform', {
|
|
371
|
+
phase: 'end',
|
|
372
|
+
kind: drag.kind,
|
|
373
|
+
via: 'pointer',
|
|
374
|
+
boxes: [
|
|
375
|
+
...live.values()
|
|
376
|
+
]
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
this.invalidate();
|
|
381
|
+
}
|
|
382
|
+
pointerCancel(p) {
|
|
383
|
+
this.pointers.delete(p.id);
|
|
384
|
+
this.drag = null;
|
|
385
|
+
this.live = null;
|
|
386
|
+
this.guides = [];
|
|
387
|
+
this.marquee = null;
|
|
388
|
+
this.invalidate();
|
|
389
|
+
}
|
|
390
|
+
startDrag(pending, p) {
|
|
391
|
+
const touch = 'touch' === pending.pointer.type;
|
|
392
|
+
const hit = pending.hit;
|
|
393
|
+
if (hit && this.editable && !hit.locked && (!touch || this.selection.includes(hit.id))) {
|
|
394
|
+
if (!this.selection.includes(hit.id)) this.select(pending.pointer.shift || pending.pointer.ctrl ? [
|
|
395
|
+
...this.selection,
|
|
396
|
+
hit.id
|
|
397
|
+
] : [
|
|
398
|
+
hit.id
|
|
399
|
+
]);
|
|
400
|
+
const start = this.selected().filter((b)=>!b.locked);
|
|
401
|
+
const [sx, sy] = toStage(this.fit, pending.x, pending.y);
|
|
402
|
+
this.drag = {
|
|
403
|
+
kind: 'move',
|
|
404
|
+
start,
|
|
405
|
+
sx,
|
|
406
|
+
sy
|
|
407
|
+
};
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
if (!touch && !hit) {
|
|
411
|
+
const additive = Boolean(pending.pointer.shift || pending.pointer.ctrl);
|
|
412
|
+
this.drag = {
|
|
413
|
+
kind: 'marquee',
|
|
414
|
+
x0: pending.x,
|
|
415
|
+
y0: pending.y,
|
|
416
|
+
x1: p.x,
|
|
417
|
+
y1: p.y,
|
|
418
|
+
additive,
|
|
419
|
+
base: this.selection.slice()
|
|
420
|
+
};
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
this.drag = {
|
|
424
|
+
kind: 'pan',
|
|
425
|
+
x: pending.x,
|
|
426
|
+
y: pending.y,
|
|
427
|
+
panX: this.view.panX,
|
|
428
|
+
panY: this.view.panY
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
tap(pending, p) {
|
|
432
|
+
const double = null !== this.lastTap && p.time - this.lastTap.time < DOUBLE_MS && Math.hypot(p.x - this.lastTap.x, p.y - this.lastTap.y) < 12;
|
|
433
|
+
this.lastTap = double ? null : {
|
|
434
|
+
x: p.x,
|
|
435
|
+
y: p.y,
|
|
436
|
+
time: p.time
|
|
437
|
+
};
|
|
438
|
+
const hit = pending.hit;
|
|
439
|
+
const additive = Boolean(pending.pointer.shift || pending.pointer.ctrl);
|
|
440
|
+
if (hit) {
|
|
441
|
+
if (double) {
|
|
442
|
+
this.select([
|
|
443
|
+
hit.id
|
|
444
|
+
]);
|
|
445
|
+
this.emit('tbopen', {
|
|
446
|
+
id: hit.id
|
|
447
|
+
});
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (additive) this.select(this.selection.includes(hit.id) ? this.selection.filter((id)=>id !== hit.id) : [
|
|
451
|
+
...this.selection,
|
|
452
|
+
hit.id
|
|
453
|
+
]);
|
|
454
|
+
else this.select([
|
|
455
|
+
hit.id
|
|
456
|
+
]);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (!additive) this.select([]);
|
|
460
|
+
const [sx, sy] = toStage(this.fit, p.x, p.y);
|
|
461
|
+
this.emit('tbtap', {
|
|
462
|
+
x: sx,
|
|
463
|
+
y: sy
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
wheel(w) {
|
|
467
|
+
if (w.ctrl) return void this.zoomAt(Math.exp(0.0025 * -w.dy), w.x, w.y);
|
|
468
|
+
this.setView({
|
|
469
|
+
panX: this.view.panX - w.dx,
|
|
470
|
+
panY: this.view.panY - w.dy
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
key(k) {
|
|
474
|
+
const key = 1 === k.key.length ? k.key.toLowerCase() : k.key;
|
|
475
|
+
const command = (name)=>{
|
|
476
|
+
this.emit('tbcommand', {
|
|
477
|
+
name
|
|
478
|
+
});
|
|
479
|
+
return true;
|
|
480
|
+
};
|
|
481
|
+
const center = ()=>[
|
|
482
|
+
this.size.w / 2,
|
|
483
|
+
this.size.h / 2
|
|
484
|
+
];
|
|
485
|
+
if (k.ctrl) {
|
|
486
|
+
if ('z' === key) return command(k.shift ? 'redo' : 'undo');
|
|
487
|
+
if ('y' === key) return command('redo');
|
|
488
|
+
if ('d' === key) return command('duplicate');
|
|
489
|
+
if ('c' === key) return command('copy');
|
|
490
|
+
if ('v' === key) return command('paste');
|
|
491
|
+
if (']' === key) return command('forward');
|
|
492
|
+
if ('[' === key) return command('backward');
|
|
493
|
+
if ('a' === key) return this.select(this.boxes.map((b)=>b.id)), true;
|
|
494
|
+
if ('=' === key || '+' === key) return this.zoomAt(1.25, ...center()), true;
|
|
495
|
+
if ('-' === key) return this.zoomAt(0.8, ...center()), true;
|
|
496
|
+
if ('0' === key) return this.setView({
|
|
497
|
+
zoom: 1,
|
|
498
|
+
panX: 0,
|
|
499
|
+
panY: 0
|
|
500
|
+
}), true;
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
const sel = this.selected().filter((b)=>!b.locked);
|
|
504
|
+
switch(key){
|
|
505
|
+
case 'ArrowLeft':
|
|
506
|
+
case 'ArrowRight':
|
|
507
|
+
case 'ArrowUp':
|
|
508
|
+
case 'ArrowDown':
|
|
509
|
+
{
|
|
510
|
+
if (!sel.length || !this.editable) return Boolean(sel.length);
|
|
511
|
+
const step = k.shift ? 10 : 1;
|
|
512
|
+
const dx = 'ArrowLeft' === key ? -step : 'ArrowRight' === key ? step : 0;
|
|
513
|
+
const dy = 'ArrowUp' === key ? -step : 'ArrowDown' === key ? step : 0;
|
|
514
|
+
this.commitKeys('move', moveBoxes(sel, dx, dy));
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
case '[':
|
|
518
|
+
case ']':
|
|
519
|
+
{
|
|
520
|
+
if (!sel.length || !this.editable) return Boolean(sel.length);
|
|
521
|
+
const frame = selectionFrame(sel);
|
|
522
|
+
const step = (k.shift ? 15 : 1) * ('[' === key ? -1 : 1);
|
|
523
|
+
this.commitKeys('rotate', rotateBoxes(sel, frame.cx, frame.cy, step));
|
|
524
|
+
return true;
|
|
525
|
+
}
|
|
526
|
+
case '-':
|
|
527
|
+
case '=':
|
|
528
|
+
case '+':
|
|
529
|
+
{
|
|
530
|
+
if (!sel.length || !this.editable) return Boolean(sel.length);
|
|
531
|
+
const frame = selectionFrame(sel);
|
|
532
|
+
const s = '-' === key ? 1 / 1.05 : 1.05;
|
|
533
|
+
this.commitKeys('scale', mapBoxes(sel, frame, {
|
|
534
|
+
...frame,
|
|
535
|
+
w: frame.w * s,
|
|
536
|
+
h: frame.h * s
|
|
537
|
+
}));
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
case 'Tab':
|
|
541
|
+
{
|
|
542
|
+
if (!this.boxes.length) return false;
|
|
543
|
+
const last = this.selection[this.selection.length - 1];
|
|
544
|
+
const i = this.boxes.findIndex((b)=>b.id === last);
|
|
545
|
+
const n = this.boxes.length;
|
|
546
|
+
const next = i < 0 ? k.shift ? n - 1 : 0 : (i + (k.shift ? -1 : 1) + n) % n;
|
|
547
|
+
this.select([
|
|
548
|
+
this.boxes[next].id
|
|
549
|
+
]);
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
case 'Delete':
|
|
553
|
+
case 'Backspace':
|
|
554
|
+
return this.selection.length ? command('delete') : false;
|
|
555
|
+
case 'Enter':
|
|
556
|
+
if (1 === this.selection.length) this.emit('tbopen', {
|
|
557
|
+
id: this.selection[0]
|
|
558
|
+
});
|
|
559
|
+
return 1 === this.selection.length;
|
|
560
|
+
case 'Escape':
|
|
561
|
+
if (this.selection.length) this.select([]);
|
|
562
|
+
else command('escape');
|
|
563
|
+
return true;
|
|
564
|
+
default:
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
commitKeys(kind, boxes) {
|
|
569
|
+
const map = new Map(boxes.map((b)=>[
|
|
570
|
+
b.id,
|
|
571
|
+
b
|
|
572
|
+
]));
|
|
573
|
+
this.boxes = this.boxes.map((b)=>{
|
|
574
|
+
var _map_get;
|
|
575
|
+
return null != (_map_get = map.get(b.id)) ? _map_get : b;
|
|
576
|
+
});
|
|
577
|
+
this.emit('tbtransform', {
|
|
578
|
+
phase: 'end',
|
|
579
|
+
kind,
|
|
580
|
+
via: 'keyboard',
|
|
581
|
+
boxes
|
|
582
|
+
});
|
|
583
|
+
this.invalidate();
|
|
584
|
+
}
|
|
585
|
+
constructor(emit, invalidate){
|
|
586
|
+
_define_property(this, "emit", void 0);
|
|
587
|
+
_define_property(this, "invalidate", void 0);
|
|
588
|
+
_define_property(this, "boxes", void 0);
|
|
589
|
+
_define_property(this, "selection", void 0);
|
|
590
|
+
_define_property(this, "stage", void 0);
|
|
591
|
+
_define_property(this, "safeZones", void 0);
|
|
592
|
+
_define_property(this, "view", void 0);
|
|
593
|
+
_define_property(this, "size", void 0);
|
|
594
|
+
_define_property(this, "padding", void 0);
|
|
595
|
+
_define_property(this, "snapPx", void 0);
|
|
596
|
+
_define_property(this, "guidesOn", void 0);
|
|
597
|
+
_define_property(this, "editable", void 0);
|
|
598
|
+
_define_property(this, "live", void 0);
|
|
599
|
+
_define_property(this, "guides", void 0);
|
|
600
|
+
_define_property(this, "marquee", void 0);
|
|
601
|
+
_define_property(this, "drag", void 0);
|
|
602
|
+
_define_property(this, "pointers", void 0);
|
|
603
|
+
_define_property(this, "lastTap", void 0);
|
|
604
|
+
this.emit = emit;
|
|
605
|
+
this.invalidate = invalidate;
|
|
606
|
+
this.boxes = [];
|
|
607
|
+
this.selection = [];
|
|
608
|
+
this.stage = {
|
|
609
|
+
w: 1080,
|
|
610
|
+
h: 1920
|
|
611
|
+
};
|
|
612
|
+
this.safeZones = [];
|
|
613
|
+
this.view = {
|
|
614
|
+
zoom: 1,
|
|
615
|
+
panX: 0,
|
|
616
|
+
panY: 0
|
|
617
|
+
};
|
|
618
|
+
this.size = {
|
|
619
|
+
w: 0,
|
|
620
|
+
h: 0
|
|
621
|
+
};
|
|
622
|
+
this.padding = 16;
|
|
623
|
+
this.snapPx = 6;
|
|
624
|
+
this.guidesOn = true;
|
|
625
|
+
this.editable = true;
|
|
626
|
+
this.live = null;
|
|
627
|
+
this.guides = [];
|
|
628
|
+
this.marquee = null;
|
|
629
|
+
this.drag = null;
|
|
630
|
+
this.pointers = new Map();
|
|
631
|
+
this.lastTap = null;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
export { TB_KEYS, TbEngine };
|
|
635
|
+
|
|
636
|
+
//# sourceMappingURL=engine.js.map
|