agentation-vue 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +27 -0
- package/dist/AgentationVue.d.vue.ts +27 -0
- package/dist/AgentationVue.vue +839 -0
- package/dist/AgentationVue.vue.d.ts +27 -0
- package/dist/components/AgentationToolbar.d.vue.ts +36 -0
- package/dist/components/AgentationToolbar.vue +233 -0
- package/dist/components/AgentationToolbar.vue.d.ts +36 -0
- package/dist/components/AnnotationInput.d.vue.ts +21 -0
- package/dist/components/AnnotationInput.vue +105 -0
- package/dist/components/AnnotationInput.vue.d.ts +21 -0
- package/dist/components/AnnotationMarker.d.vue.ts +15 -0
- package/dist/components/AnnotationMarker.vue +46 -0
- package/dist/components/AnnotationMarker.vue.d.ts +15 -0
- package/dist/components/ComponentChain.d.vue.ts +10 -0
- package/dist/components/ComponentChain.vue +91 -0
- package/dist/components/ComponentChain.vue.d.ts +10 -0
- package/dist/components/ElementHighlight.d.vue.ts +9 -0
- package/dist/components/ElementHighlight.vue +33 -0
- package/dist/components/ElementHighlight.vue.d.ts +9 -0
- package/dist/components/SettingsPanel.d.vue.ts +10 -0
- package/dist/components/SettingsPanel.vue +143 -0
- package/dist/components/SettingsPanel.vue.d.ts +10 -0
- package/dist/components/SettingsPopover.d.vue.ts +14 -0
- package/dist/components/SettingsPopover.vue +235 -0
- package/dist/components/SettingsPopover.vue.d.ts +14 -0
- package/dist/components/VaButton.d.vue.ts +23 -0
- package/dist/components/VaButton.vue +19 -0
- package/dist/components/VaButton.vue.d.ts +23 -0
- package/dist/components/VaIcon.d.vue.ts +6 -0
- package/dist/components/VaIcon.vue +18 -0
- package/dist/components/VaIcon.vue.d.ts +6 -0
- package/dist/components/VaIconButton.d.vue.ts +25 -0
- package/dist/components/VaIconButton.vue +43 -0
- package/dist/components/VaIconButton.vue.d.ts +25 -0
- package/dist/components/VaToggle.d.vue.ts +10 -0
- package/dist/components/VaToggle.vue +23 -0
- package/dist/components/VaToggle.vue.d.ts +10 -0
- package/dist/composables/useAnimationPause.d.ts +7 -0
- package/dist/composables/useAnimationPause.js +52 -0
- package/dist/composables/useAnimationPause.mjs +43 -0
- package/dist/composables/useAnnotations.d.ts +105 -0
- package/dist/composables/useAnnotations.js +106 -0
- package/dist/composables/useAnnotations.mjs +108 -0
- package/dist/composables/useAreaSelect.d.ts +21 -0
- package/dist/composables/useAreaSelect.js +62 -0
- package/dist/composables/useAreaSelect.mjs +41 -0
- package/dist/composables/useElementDetection.d.ts +22 -0
- package/dist/composables/useElementDetection.js +85 -0
- package/dist/composables/useElementDetection.mjs +82 -0
- package/dist/composables/useInteractionMode.d.ts +5 -0
- package/dist/composables/useInteractionMode.js +29 -0
- package/dist/composables/useInteractionMode.mjs +20 -0
- package/dist/composables/useKeyboardShortcuts.d.ts +43 -0
- package/dist/composables/useKeyboardShortcuts.js +202 -0
- package/dist/composables/useKeyboardShortcuts.mjs +223 -0
- package/dist/composables/useMarkerPositions.d.ts +5 -0
- package/dist/composables/useMarkerPositions.js +45 -0
- package/dist/composables/useMarkerPositions.mjs +36 -0
- package/dist/composables/useMultiSelect.d.ts +20 -0
- package/dist/composables/useMultiSelect.js +108 -0
- package/dist/composables/useMultiSelect.mjs +85 -0
- package/dist/composables/useOutputFormatter.d.ts +5 -0
- package/dist/composables/useOutputFormatter.js +100 -0
- package/dist/composables/useOutputFormatter.mjs +91 -0
- package/dist/composables/useSettings.d.ts +14 -0
- package/dist/composables/useSettings.js +48 -0
- package/dist/composables/useSettings.mjs +38 -0
- package/dist/composables/useTextSelection.d.ts +11 -0
- package/dist/composables/useTextSelection.js +33 -0
- package/dist/composables/useTextSelection.mjs +22 -0
- package/dist/composables/useToolbarAutoHide.d.ts +19 -0
- package/dist/composables/useToolbarAutoHide.js +270 -0
- package/dist/composables/useToolbarAutoHide.mjs +208 -0
- package/dist/composables/useToolbarDragSnap.d.ts +30 -0
- package/dist/composables/useToolbarDragSnap.js +296 -0
- package/dist/composables/useToolbarDragSnap.mjs +245 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +8 -0
- package/dist/constants.mjs +2 -0
- package/dist/directives/vaTooltip.d.ts +22 -0
- package/dist/directives/vaTooltip.js +241 -0
- package/dist/directives/vaTooltip.mjs +257 -0
- package/dist/icons.d.ts +16 -0
- package/dist/icons.js +21 -0
- package/dist/icons.mjs +15 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +168 -0
- package/dist/index.mjs +30 -0
- package/dist/styles/agentation.css +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +1 -0
- package/dist/types.mjs +0 -0
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.js +22 -0
- package/dist/utils/clipboard.mjs +16 -0
- package/dist/utils/dom-inspector.d.ts +7 -0
- package/dist/utils/dom-inspector.js +168 -0
- package/dist/utils/dom-inspector.mjs +242 -0
- package/dist/utils/math.d.ts +1 -0
- package/dist/utils/math.js +9 -0
- package/dist/utils/math.mjs +3 -0
- package/dist/utils/portal.d.ts +2 -0
- package/dist/utils/portal.js +18 -0
- package/dist/utils/portal.mjs +11 -0
- package/dist/utils/selectors.d.ts +3 -0
- package/dist/utils/selectors.js +103 -0
- package/dist/utils/selectors.mjs +105 -0
- package/dist/utils/style.d.ts +2 -0
- package/dist/utils/style.js +14 -0
- package/dist/utils/style.mjs +8 -0
- package/package.json +49 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useToolbarDragSnap = useToolbarDragSnap;
|
|
7
|
+
var _vueDemi = require("vue-demi");
|
|
8
|
+
var _math = require("../utils/math");
|
|
9
|
+
const TOOLBAR_SIZE = 42;
|
|
10
|
+
const EDGE_OFFSET = 20;
|
|
11
|
+
const LONG_PRESS_MS = 350;
|
|
12
|
+
const HALF_TOOLBAR_SIZE = TOOLBAR_SIZE / 2;
|
|
13
|
+
const TOOLBAR_ANCHORS = ["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right"];
|
|
14
|
+
function isToolbarAnchor(value) {
|
|
15
|
+
return typeof value === "string" && TOOLBAR_ANCHORS.includes(value);
|
|
16
|
+
}
|
|
17
|
+
function useToolbarDragSnap(options) {
|
|
18
|
+
const {
|
|
19
|
+
expanded,
|
|
20
|
+
initialPlacement,
|
|
21
|
+
onDragStart,
|
|
22
|
+
onDragEnd
|
|
23
|
+
} = options;
|
|
24
|
+
const placement = (0, _vueDemi.ref)(isToolbarAnchor(initialPlacement) ? initialPlacement : "bottom-right");
|
|
25
|
+
const isDragging = (0, _vueDemi.ref)(false);
|
|
26
|
+
const dragPosition = (0, _vueDemi.ref)(null);
|
|
27
|
+
const suppressNextClick = (0, _vueDemi.ref)(false);
|
|
28
|
+
const activePointerId = (0, _vueDemi.ref)(null);
|
|
29
|
+
const toolbarEl = (0, _vueDemi.ref)(null);
|
|
30
|
+
const dragOffset = (0, _vueDemi.ref)({
|
|
31
|
+
x: HALF_TOOLBAR_SIZE,
|
|
32
|
+
y: HALF_TOOLBAR_SIZE
|
|
33
|
+
});
|
|
34
|
+
const dragSize = (0, _vueDemi.ref)({
|
|
35
|
+
width: TOOLBAR_SIZE,
|
|
36
|
+
height: TOOLBAR_SIZE
|
|
37
|
+
});
|
|
38
|
+
const dragSource = (0, _vueDemi.ref)(null);
|
|
39
|
+
const dragRotation = (0, _vueDemi.ref)(0);
|
|
40
|
+
let longPressTimer = null;
|
|
41
|
+
const snapAnchors = TOOLBAR_ANCHORS;
|
|
42
|
+
const isExpandedDrag = (0, _vueDemi.computed)(() => isDragging.value && dragSource.value === "handle");
|
|
43
|
+
const toolbarStyle = (0, _vueDemi.computed)(() => {
|
|
44
|
+
if (!isDragging.value || !dragPosition.value) {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
left: `${dragPosition.value.x}px`,
|
|
49
|
+
top: `${dragPosition.value.y}px`,
|
|
50
|
+
transform: `rotate(${dragRotation.value}deg)`
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
const activeSnapAnchor = (0, _vueDemi.computed)(() => {
|
|
54
|
+
const current = dragPosition.value;
|
|
55
|
+
if (!current) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return findClosestAnchor(current.x + dragSize.value.width / 2, current.y + dragSize.value.height / 2);
|
|
59
|
+
});
|
|
60
|
+
function getAnchorRects(size) {
|
|
61
|
+
const top = EDGE_OFFSET;
|
|
62
|
+
const bottom = window.innerHeight - EDGE_OFFSET - size.height;
|
|
63
|
+
const left = EDGE_OFFSET;
|
|
64
|
+
const right = window.innerWidth - EDGE_OFFSET - size.width;
|
|
65
|
+
const centerX = (window.innerWidth - size.width) / 2;
|
|
66
|
+
return {
|
|
67
|
+
"top-left": {
|
|
68
|
+
x: left,
|
|
69
|
+
y: top,
|
|
70
|
+
width: size.width,
|
|
71
|
+
height: size.height
|
|
72
|
+
},
|
|
73
|
+
"top-center": {
|
|
74
|
+
x: centerX,
|
|
75
|
+
y: top,
|
|
76
|
+
width: size.width,
|
|
77
|
+
height: size.height
|
|
78
|
+
},
|
|
79
|
+
"top-right": {
|
|
80
|
+
x: right,
|
|
81
|
+
y: top,
|
|
82
|
+
width: size.width,
|
|
83
|
+
height: size.height
|
|
84
|
+
},
|
|
85
|
+
"bottom-left": {
|
|
86
|
+
x: left,
|
|
87
|
+
y: bottom,
|
|
88
|
+
width: size.width,
|
|
89
|
+
height: size.height
|
|
90
|
+
},
|
|
91
|
+
"bottom-center": {
|
|
92
|
+
x: centerX,
|
|
93
|
+
y: bottom,
|
|
94
|
+
width: size.width,
|
|
95
|
+
height: size.height
|
|
96
|
+
},
|
|
97
|
+
"bottom-right": {
|
|
98
|
+
x: right,
|
|
99
|
+
y: bottom,
|
|
100
|
+
width: size.width,
|
|
101
|
+
height: size.height
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function getSnapPoints(size) {
|
|
106
|
+
const rects = getAnchorRects(size);
|
|
107
|
+
const result = {};
|
|
108
|
+
for (const anchor of snapAnchors) {
|
|
109
|
+
const r = rects[anchor];
|
|
110
|
+
result[anchor] = {
|
|
111
|
+
x: r.x + r.width / 2,
|
|
112
|
+
y: r.y + r.height / 2
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
function findClosestAnchor(x, y) {
|
|
118
|
+
const points = getSnapPoints(dragSize.value);
|
|
119
|
+
let closest = "bottom-right";
|
|
120
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
121
|
+
for (const [anchor, point] of Object.entries(points)) {
|
|
122
|
+
const dx = point.x - x;
|
|
123
|
+
const dy = point.y - y;
|
|
124
|
+
const distance = dx * dx + dy * dy;
|
|
125
|
+
if (distance < bestDistance) {
|
|
126
|
+
bestDistance = distance;
|
|
127
|
+
closest = anchor;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return closest;
|
|
131
|
+
}
|
|
132
|
+
function captureDragMetrics(clientX, clientY) {
|
|
133
|
+
const rect = toolbarEl.value?.getBoundingClientRect();
|
|
134
|
+
if (!rect) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
dragOffset.value = {
|
|
138
|
+
x: clientX - rect.left,
|
|
139
|
+
y: clientY - rect.top
|
|
140
|
+
};
|
|
141
|
+
dragSize.value = {
|
|
142
|
+
width: rect.width,
|
|
143
|
+
height: rect.height
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function updateDragPosition(clientX, clientY) {
|
|
147
|
+
const {
|
|
148
|
+
width,
|
|
149
|
+
height
|
|
150
|
+
} = dragSize.value;
|
|
151
|
+
dragPosition.value = {
|
|
152
|
+
x: (0, _math.clamp)(clientX - dragOffset.value.x, 0, window.innerWidth - width),
|
|
153
|
+
y: (0, _math.clamp)(clientY - dragOffset.value.y, 0, window.innerHeight - height)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function clearLongPressTimer() {
|
|
157
|
+
if (longPressTimer) {
|
|
158
|
+
clearTimeout(longPressTimer);
|
|
159
|
+
longPressTimer = null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function finishDrag(clientX, clientY) {
|
|
163
|
+
updateDragPosition(clientX, clientY);
|
|
164
|
+
const current = dragPosition.value;
|
|
165
|
+
if (current) {
|
|
166
|
+
placement.value = findClosestAnchor(current.x + dragSize.value.width / 2, current.y + dragSize.value.height / 2);
|
|
167
|
+
}
|
|
168
|
+
isDragging.value = false;
|
|
169
|
+
dragPosition.value = null;
|
|
170
|
+
onDragEnd?.();
|
|
171
|
+
}
|
|
172
|
+
function getSnapStyle(anchor) {
|
|
173
|
+
const rect = getAnchorRects(dragSize.value)[anchor];
|
|
174
|
+
if (isExpandedDrag.value) {
|
|
175
|
+
return {
|
|
176
|
+
left: `${rect.x}px`,
|
|
177
|
+
top: `${rect.y}px`,
|
|
178
|
+
width: `${rect.width}px`,
|
|
179
|
+
height: `${rect.height}px`
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
left: `${rect.x + rect.width / 2}px`,
|
|
184
|
+
top: `${rect.y + rect.height / 2}px`
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function startDragPointer(e, source, options2) {
|
|
188
|
+
if (e.button !== 0) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
activePointerId.value = e.pointerId;
|
|
192
|
+
dragSource.value = source;
|
|
193
|
+
captureDragMetrics(e.clientX, e.clientY);
|
|
194
|
+
const target = e.currentTarget;
|
|
195
|
+
target?.setPointerCapture?.(e.pointerId);
|
|
196
|
+
clearLongPressTimer();
|
|
197
|
+
dragRotation.value = (2 + Math.random() * 3) * (Math.random() < 0.5 ? -1 : 1);
|
|
198
|
+
if (options2.immediate) {
|
|
199
|
+
dragRotation.value = (Math.random() * 4 + 1) * (Math.random() < 0.5 ? -1 : 1);
|
|
200
|
+
isDragging.value = true;
|
|
201
|
+
onDragStart?.();
|
|
202
|
+
updateDragPosition(e.clientX, e.clientY);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
longPressTimer = setTimeout(() => {
|
|
206
|
+
if (activePointerId.value !== e.pointerId || expanded.value) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
dragRotation.value = (Math.random() * 4 + 1) * (Math.random() < 0.5 ? -1 : 1);
|
|
210
|
+
isDragging.value = true;
|
|
211
|
+
onDragStart?.();
|
|
212
|
+
updateDragPosition(e.clientX, e.clientY);
|
|
213
|
+
}, LONG_PRESS_MS);
|
|
214
|
+
}
|
|
215
|
+
function onTogglePointerDown(e) {
|
|
216
|
+
if (expanded.value) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
startDragPointer(e, "toggle", {
|
|
220
|
+
immediate: false
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function onHandlePointerDown(e) {
|
|
224
|
+
if (!expanded.value) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
startDragPointer(e, "handle", {
|
|
228
|
+
immediate: true
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function onPointerMove(e) {
|
|
232
|
+
if (!isDragging.value || activePointerId.value !== e.pointerId) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
updateDragPosition(e.clientX, e.clientY);
|
|
236
|
+
}
|
|
237
|
+
function onPointerUp(e) {
|
|
238
|
+
if (activePointerId.value !== e.pointerId) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
clearLongPressTimer();
|
|
242
|
+
if (isDragging.value) {
|
|
243
|
+
finishDrag(e.clientX, e.clientY);
|
|
244
|
+
if (dragSource.value === "toggle") {
|
|
245
|
+
suppressNextClick.value = true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
activePointerId.value = null;
|
|
249
|
+
dragSource.value = null;
|
|
250
|
+
const target = e.currentTarget;
|
|
251
|
+
target?.releasePointerCapture?.(e.pointerId);
|
|
252
|
+
}
|
|
253
|
+
function onPointerCancel() {
|
|
254
|
+
if (isDragging.value) {
|
|
255
|
+
onDragEnd?.();
|
|
256
|
+
}
|
|
257
|
+
clearLongPressTimer();
|
|
258
|
+
isDragging.value = false;
|
|
259
|
+
dragPosition.value = null;
|
|
260
|
+
activePointerId.value = null;
|
|
261
|
+
dragSource.value = null;
|
|
262
|
+
}
|
|
263
|
+
function consumeToggleClickSuppression() {
|
|
264
|
+
if (!suppressNextClick.value) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
suppressNextClick.value = false;
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
function cleanup() {
|
|
271
|
+
clearLongPressTimer();
|
|
272
|
+
if (isDragging.value) {
|
|
273
|
+
isDragging.value = false;
|
|
274
|
+
onDragEnd?.();
|
|
275
|
+
}
|
|
276
|
+
activePointerId.value = null;
|
|
277
|
+
dragSource.value = null;
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
placement,
|
|
281
|
+
isDragging,
|
|
282
|
+
toolbarStyle,
|
|
283
|
+
toolbarEl,
|
|
284
|
+
snapAnchors,
|
|
285
|
+
activeSnapAnchor,
|
|
286
|
+
isExpandedDrag,
|
|
287
|
+
getSnapStyle,
|
|
288
|
+
onTogglePointerDown,
|
|
289
|
+
onHandlePointerDown,
|
|
290
|
+
onPointerMove,
|
|
291
|
+
onPointerUp,
|
|
292
|
+
onPointerCancel,
|
|
293
|
+
consumeToggleClickSuppression,
|
|
294
|
+
cleanup
|
|
295
|
+
};
|
|
296
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { computed, ref } from "vue-demi";
|
|
2
|
+
import { clamp } from "../utils/math.mjs";
|
|
3
|
+
const TOOLBAR_SIZE = 42;
|
|
4
|
+
const EDGE_OFFSET = 20;
|
|
5
|
+
const LONG_PRESS_MS = 350;
|
|
6
|
+
const HALF_TOOLBAR_SIZE = TOOLBAR_SIZE / 2;
|
|
7
|
+
const TOOLBAR_ANCHORS = ["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right"];
|
|
8
|
+
function isToolbarAnchor(value) {
|
|
9
|
+
return typeof value === "string" && TOOLBAR_ANCHORS.includes(value);
|
|
10
|
+
}
|
|
11
|
+
export function useToolbarDragSnap(options) {
|
|
12
|
+
const { expanded, initialPlacement, onDragStart, onDragEnd } = options;
|
|
13
|
+
const placement = ref(isToolbarAnchor(initialPlacement) ? initialPlacement : "bottom-right");
|
|
14
|
+
const isDragging = ref(false);
|
|
15
|
+
const dragPosition = ref(null);
|
|
16
|
+
const suppressNextClick = ref(false);
|
|
17
|
+
const activePointerId = ref(null);
|
|
18
|
+
const toolbarEl = ref(null);
|
|
19
|
+
const dragOffset = ref({ x: HALF_TOOLBAR_SIZE, y: HALF_TOOLBAR_SIZE });
|
|
20
|
+
const dragSize = ref({ width: TOOLBAR_SIZE, height: TOOLBAR_SIZE });
|
|
21
|
+
const dragSource = ref(null);
|
|
22
|
+
const dragRotation = ref(0);
|
|
23
|
+
let longPressTimer = null;
|
|
24
|
+
const snapAnchors = TOOLBAR_ANCHORS;
|
|
25
|
+
const isExpandedDrag = computed(() => isDragging.value && dragSource.value === "handle");
|
|
26
|
+
const toolbarStyle = computed(() => {
|
|
27
|
+
if (!isDragging.value || !dragPosition.value) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
left: `${dragPosition.value.x}px`,
|
|
32
|
+
top: `${dragPosition.value.y}px`,
|
|
33
|
+
transform: `rotate(${dragRotation.value}deg)`
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
const activeSnapAnchor = computed(() => {
|
|
37
|
+
const current = dragPosition.value;
|
|
38
|
+
if (!current) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return findClosestAnchor(
|
|
42
|
+
current.x + dragSize.value.width / 2,
|
|
43
|
+
current.y + dragSize.value.height / 2
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
function getAnchorRects(size) {
|
|
47
|
+
const top = EDGE_OFFSET;
|
|
48
|
+
const bottom = window.innerHeight - EDGE_OFFSET - size.height;
|
|
49
|
+
const left = EDGE_OFFSET;
|
|
50
|
+
const right = window.innerWidth - EDGE_OFFSET - size.width;
|
|
51
|
+
const centerX = (window.innerWidth - size.width) / 2;
|
|
52
|
+
return {
|
|
53
|
+
"top-left": { x: left, y: top, width: size.width, height: size.height },
|
|
54
|
+
"top-center": { x: centerX, y: top, width: size.width, height: size.height },
|
|
55
|
+
"top-right": { x: right, y: top, width: size.width, height: size.height },
|
|
56
|
+
"bottom-left": { x: left, y: bottom, width: size.width, height: size.height },
|
|
57
|
+
"bottom-center": { x: centerX, y: bottom, width: size.width, height: size.height },
|
|
58
|
+
"bottom-right": { x: right, y: bottom, width: size.width, height: size.height }
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function getSnapPoints(size) {
|
|
62
|
+
const rects = getAnchorRects(size);
|
|
63
|
+
const result = {};
|
|
64
|
+
for (const anchor of snapAnchors) {
|
|
65
|
+
const r = rects[anchor];
|
|
66
|
+
result[anchor] = { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function findClosestAnchor(x, y) {
|
|
71
|
+
const points = getSnapPoints(dragSize.value);
|
|
72
|
+
let closest = "bottom-right";
|
|
73
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
74
|
+
for (const [anchor, point] of Object.entries(points)) {
|
|
75
|
+
const dx = point.x - x;
|
|
76
|
+
const dy = point.y - y;
|
|
77
|
+
const distance = dx * dx + dy * dy;
|
|
78
|
+
if (distance < bestDistance) {
|
|
79
|
+
bestDistance = distance;
|
|
80
|
+
closest = anchor;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return closest;
|
|
84
|
+
}
|
|
85
|
+
function captureDragMetrics(clientX, clientY) {
|
|
86
|
+
const rect = toolbarEl.value?.getBoundingClientRect();
|
|
87
|
+
if (!rect) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
dragOffset.value = {
|
|
91
|
+
x: clientX - rect.left,
|
|
92
|
+
y: clientY - rect.top
|
|
93
|
+
};
|
|
94
|
+
dragSize.value = {
|
|
95
|
+
width: rect.width,
|
|
96
|
+
height: rect.height
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function updateDragPosition(clientX, clientY) {
|
|
100
|
+
const { width, height } = dragSize.value;
|
|
101
|
+
dragPosition.value = {
|
|
102
|
+
x: clamp(clientX - dragOffset.value.x, 0, window.innerWidth - width),
|
|
103
|
+
y: clamp(clientY - dragOffset.value.y, 0, window.innerHeight - height)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function clearLongPressTimer() {
|
|
107
|
+
if (longPressTimer) {
|
|
108
|
+
clearTimeout(longPressTimer);
|
|
109
|
+
longPressTimer = null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function finishDrag(clientX, clientY) {
|
|
113
|
+
updateDragPosition(clientX, clientY);
|
|
114
|
+
const current = dragPosition.value;
|
|
115
|
+
if (current) {
|
|
116
|
+
placement.value = findClosestAnchor(
|
|
117
|
+
current.x + dragSize.value.width / 2,
|
|
118
|
+
current.y + dragSize.value.height / 2
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
isDragging.value = false;
|
|
122
|
+
dragPosition.value = null;
|
|
123
|
+
onDragEnd?.();
|
|
124
|
+
}
|
|
125
|
+
function getSnapStyle(anchor) {
|
|
126
|
+
const rect = getAnchorRects(dragSize.value)[anchor];
|
|
127
|
+
if (isExpandedDrag.value) {
|
|
128
|
+
return {
|
|
129
|
+
left: `${rect.x}px`,
|
|
130
|
+
top: `${rect.y}px`,
|
|
131
|
+
width: `${rect.width}px`,
|
|
132
|
+
height: `${rect.height}px`
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
left: `${rect.x + rect.width / 2}px`,
|
|
137
|
+
top: `${rect.y + rect.height / 2}px`
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function startDragPointer(e, source, options2) {
|
|
141
|
+
if (e.button !== 0) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
activePointerId.value = e.pointerId;
|
|
145
|
+
dragSource.value = source;
|
|
146
|
+
captureDragMetrics(e.clientX, e.clientY);
|
|
147
|
+
const target = e.currentTarget;
|
|
148
|
+
target?.setPointerCapture?.(e.pointerId);
|
|
149
|
+
clearLongPressTimer();
|
|
150
|
+
dragRotation.value = (2 + Math.random() * 3) * (Math.random() < 0.5 ? -1 : 1);
|
|
151
|
+
if (options2.immediate) {
|
|
152
|
+
dragRotation.value = (Math.random() * 4 + 1) * (Math.random() < 0.5 ? -1 : 1);
|
|
153
|
+
isDragging.value = true;
|
|
154
|
+
onDragStart?.();
|
|
155
|
+
updateDragPosition(e.clientX, e.clientY);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
longPressTimer = setTimeout(() => {
|
|
159
|
+
if (activePointerId.value !== e.pointerId || expanded.value) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
dragRotation.value = (Math.random() * 4 + 1) * (Math.random() < 0.5 ? -1 : 1);
|
|
163
|
+
isDragging.value = true;
|
|
164
|
+
onDragStart?.();
|
|
165
|
+
updateDragPosition(e.clientX, e.clientY);
|
|
166
|
+
}, LONG_PRESS_MS);
|
|
167
|
+
}
|
|
168
|
+
function onTogglePointerDown(e) {
|
|
169
|
+
if (expanded.value) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
startDragPointer(e, "toggle", { immediate: false });
|
|
173
|
+
}
|
|
174
|
+
function onHandlePointerDown(e) {
|
|
175
|
+
if (!expanded.value) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
startDragPointer(e, "handle", { immediate: true });
|
|
179
|
+
}
|
|
180
|
+
function onPointerMove(e) {
|
|
181
|
+
if (!isDragging.value || activePointerId.value !== e.pointerId) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
updateDragPosition(e.clientX, e.clientY);
|
|
185
|
+
}
|
|
186
|
+
function onPointerUp(e) {
|
|
187
|
+
if (activePointerId.value !== e.pointerId) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
clearLongPressTimer();
|
|
191
|
+
if (isDragging.value) {
|
|
192
|
+
finishDrag(e.clientX, e.clientY);
|
|
193
|
+
if (dragSource.value === "toggle") {
|
|
194
|
+
suppressNextClick.value = true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
activePointerId.value = null;
|
|
198
|
+
dragSource.value = null;
|
|
199
|
+
const target = e.currentTarget;
|
|
200
|
+
target?.releasePointerCapture?.(e.pointerId);
|
|
201
|
+
}
|
|
202
|
+
function onPointerCancel() {
|
|
203
|
+
if (isDragging.value) {
|
|
204
|
+
onDragEnd?.();
|
|
205
|
+
}
|
|
206
|
+
clearLongPressTimer();
|
|
207
|
+
isDragging.value = false;
|
|
208
|
+
dragPosition.value = null;
|
|
209
|
+
activePointerId.value = null;
|
|
210
|
+
dragSource.value = null;
|
|
211
|
+
}
|
|
212
|
+
function consumeToggleClickSuppression() {
|
|
213
|
+
if (!suppressNextClick.value) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
suppressNextClick.value = false;
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
function cleanup() {
|
|
220
|
+
clearLongPressTimer();
|
|
221
|
+
if (isDragging.value) {
|
|
222
|
+
isDragging.value = false;
|
|
223
|
+
onDragEnd?.();
|
|
224
|
+
}
|
|
225
|
+
activePointerId.value = null;
|
|
226
|
+
dragSource.value = null;
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
placement,
|
|
230
|
+
isDragging,
|
|
231
|
+
toolbarStyle,
|
|
232
|
+
toolbarEl,
|
|
233
|
+
snapAnchors,
|
|
234
|
+
activeSnapAnchor,
|
|
235
|
+
isExpandedDrag,
|
|
236
|
+
getSnapStyle,
|
|
237
|
+
onTogglePointerDown,
|
|
238
|
+
onHandlePointerDown,
|
|
239
|
+
onPointerMove,
|
|
240
|
+
onPointerUp,
|
|
241
|
+
onPointerCancel,
|
|
242
|
+
consumeToggleClickSuppression,
|
|
243
|
+
cleanup
|
|
244
|
+
};
|
|
245
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VA_DATA_ATTR_SELECTOR = exports.VA_DATA_ATTR = void 0;
|
|
7
|
+
const VA_DATA_ATTR = exports.VA_DATA_ATTR = "data-agentation-vue";
|
|
8
|
+
const VA_DATA_ATTR_SELECTOR = exports.VA_DATA_ATTR_SELECTOR = "[data-agentation-vue]";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type VaTooltipPlacement = 'top' | 'bottom';
|
|
2
|
+
export interface VaTooltipOptions {
|
|
3
|
+
text: string;
|
|
4
|
+
shortcut?: string;
|
|
5
|
+
placement?: VaTooltipPlacement;
|
|
6
|
+
offset?: number;
|
|
7
|
+
showDelay?: number;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type VaTooltipValue = string | VaTooltipOptions | null | undefined;
|
|
11
|
+
interface DirectiveBindingLike {
|
|
12
|
+
value: VaTooltipValue;
|
|
13
|
+
}
|
|
14
|
+
export declare const vaTooltipDirective: {
|
|
15
|
+
beforeMount(el: HTMLElement, binding: DirectiveBindingLike): void;
|
|
16
|
+
updated(el: HTMLElement, binding: DirectiveBindingLike): void;
|
|
17
|
+
unmounted(el: HTMLElement): void;
|
|
18
|
+
bind(el: HTMLElement, binding: DirectiveBindingLike): void;
|
|
19
|
+
componentUpdated(el: HTMLElement, binding: DirectiveBindingLike): void;
|
|
20
|
+
unbind(el: HTMLElement): void;
|
|
21
|
+
};
|
|
22
|
+
export default vaTooltipDirective;
|