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,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useToolbarAutoHide = useToolbarAutoHide;
|
|
7
|
+
var _vueDemi = require("vue-demi");
|
|
8
|
+
const EDGE_OFFSET = 20;
|
|
9
|
+
const DEFAULT_TOOLBAR_SIZE = 42;
|
|
10
|
+
const ACTIVATION_EDGE_DEPTH = 16;
|
|
11
|
+
const ACTIVATION_INLINE_PAD = 30;
|
|
12
|
+
const ACTIVATION_CORNER_SIZE = 32;
|
|
13
|
+
const KEEP_ALIVE_PADDING = 56;
|
|
14
|
+
const HIDE_DELAY_MS = 140;
|
|
15
|
+
const ENTER_LOCK_MS = 220;
|
|
16
|
+
const CLICK_LOCK_MS = 320;
|
|
17
|
+
function useToolbarAutoHide(options) {
|
|
18
|
+
const {
|
|
19
|
+
enabled,
|
|
20
|
+
expanded,
|
|
21
|
+
isDragging,
|
|
22
|
+
placement,
|
|
23
|
+
toolbarEl
|
|
24
|
+
} = options;
|
|
25
|
+
const isAutoHideRevealed = (0, _vueDemi.ref)(false);
|
|
26
|
+
const isAutoHideActive = (0, _vueDemi.computed)(() => enabled.value && !expanded.value && !isDragging.value);
|
|
27
|
+
let hideTimer = null;
|
|
28
|
+
let revealLockUntil = 0;
|
|
29
|
+
let listenersAttached = false;
|
|
30
|
+
function clearHideTimer() {
|
|
31
|
+
if (!hideTimer) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
clearTimeout(hideTimer);
|
|
35
|
+
hideTimer = null;
|
|
36
|
+
}
|
|
37
|
+
function reveal() {
|
|
38
|
+
isAutoHideRevealed.value = true;
|
|
39
|
+
clearHideTimer();
|
|
40
|
+
}
|
|
41
|
+
function lockReveal(durationMs) {
|
|
42
|
+
revealLockUntil = Math.max(revealLockUntil, Date.now() + durationMs);
|
|
43
|
+
reveal();
|
|
44
|
+
}
|
|
45
|
+
function hideNow() {
|
|
46
|
+
clearHideTimer();
|
|
47
|
+
revealLockUntil = 0;
|
|
48
|
+
isAutoHideRevealed.value = false;
|
|
49
|
+
}
|
|
50
|
+
function scheduleHide() {
|
|
51
|
+
clearHideTimer();
|
|
52
|
+
hideTimer = setTimeout(() => {
|
|
53
|
+
if (Date.now() < revealLockUntil) {
|
|
54
|
+
scheduleHide();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
isAutoHideRevealed.value = false;
|
|
58
|
+
hideTimer = null;
|
|
59
|
+
}, HIDE_DELAY_MS);
|
|
60
|
+
}
|
|
61
|
+
function getToolbarSize() {
|
|
62
|
+
const el = toolbarEl.value;
|
|
63
|
+
return {
|
|
64
|
+
width: el?.offsetWidth ?? DEFAULT_TOOLBAR_SIZE,
|
|
65
|
+
height: el?.offsetHeight ?? DEFAULT_TOOLBAR_SIZE
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function getCollapsedRect(anchor, size) {
|
|
69
|
+
const left = EDGE_OFFSET;
|
|
70
|
+
const top = EDGE_OFFSET;
|
|
71
|
+
const right = window.innerWidth - EDGE_OFFSET - size.width;
|
|
72
|
+
const bottom = window.innerHeight - EDGE_OFFSET - size.height;
|
|
73
|
+
const centerX = (window.innerWidth - size.width) / 2;
|
|
74
|
+
switch (anchor) {
|
|
75
|
+
case "top-left":
|
|
76
|
+
return {
|
|
77
|
+
left,
|
|
78
|
+
top,
|
|
79
|
+
right: left + size.width,
|
|
80
|
+
bottom: top + size.height
|
|
81
|
+
};
|
|
82
|
+
case "top-center":
|
|
83
|
+
return {
|
|
84
|
+
left: centerX,
|
|
85
|
+
top,
|
|
86
|
+
right: centerX + size.width,
|
|
87
|
+
bottom: top + size.height
|
|
88
|
+
};
|
|
89
|
+
case "top-right":
|
|
90
|
+
return {
|
|
91
|
+
left: right,
|
|
92
|
+
top,
|
|
93
|
+
right: right + size.width,
|
|
94
|
+
bottom: top + size.height
|
|
95
|
+
};
|
|
96
|
+
case "bottom-left":
|
|
97
|
+
return {
|
|
98
|
+
left,
|
|
99
|
+
top: bottom,
|
|
100
|
+
right: left + size.width,
|
|
101
|
+
bottom: bottom + size.height
|
|
102
|
+
};
|
|
103
|
+
case "bottom-center":
|
|
104
|
+
return {
|
|
105
|
+
left: centerX,
|
|
106
|
+
top: bottom,
|
|
107
|
+
right: centerX + size.width,
|
|
108
|
+
bottom: bottom + size.height
|
|
109
|
+
};
|
|
110
|
+
case "bottom-right":
|
|
111
|
+
default:
|
|
112
|
+
return {
|
|
113
|
+
left: right,
|
|
114
|
+
top: bottom,
|
|
115
|
+
right: right + size.width,
|
|
116
|
+
bottom: bottom + size.height
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function getActivationRect(anchor, size) {
|
|
121
|
+
const W = window.innerWidth;
|
|
122
|
+
const H = window.innerHeight;
|
|
123
|
+
const centerX = W / 2;
|
|
124
|
+
switch (anchor) {
|
|
125
|
+
case "top-left":
|
|
126
|
+
return {
|
|
127
|
+
left: 0,
|
|
128
|
+
top: 0,
|
|
129
|
+
right: ACTIVATION_CORNER_SIZE,
|
|
130
|
+
bottom: ACTIVATION_CORNER_SIZE
|
|
131
|
+
};
|
|
132
|
+
case "top-center":
|
|
133
|
+
return {
|
|
134
|
+
left: centerX - size.width / 2 - ACTIVATION_INLINE_PAD,
|
|
135
|
+
top: 0,
|
|
136
|
+
right: centerX + size.width / 2 + ACTIVATION_INLINE_PAD,
|
|
137
|
+
bottom: ACTIVATION_EDGE_DEPTH
|
|
138
|
+
};
|
|
139
|
+
case "top-right":
|
|
140
|
+
return {
|
|
141
|
+
left: W - ACTIVATION_CORNER_SIZE,
|
|
142
|
+
top: 0,
|
|
143
|
+
right: W,
|
|
144
|
+
bottom: ACTIVATION_CORNER_SIZE
|
|
145
|
+
};
|
|
146
|
+
case "bottom-left":
|
|
147
|
+
return {
|
|
148
|
+
left: 0,
|
|
149
|
+
top: H - ACTIVATION_CORNER_SIZE,
|
|
150
|
+
right: ACTIVATION_CORNER_SIZE,
|
|
151
|
+
bottom: H
|
|
152
|
+
};
|
|
153
|
+
case "bottom-center":
|
|
154
|
+
return {
|
|
155
|
+
left: centerX - size.width / 2 - ACTIVATION_INLINE_PAD,
|
|
156
|
+
top: H - ACTIVATION_EDGE_DEPTH,
|
|
157
|
+
right: centerX + size.width / 2 + ACTIVATION_INLINE_PAD,
|
|
158
|
+
bottom: H
|
|
159
|
+
};
|
|
160
|
+
case "bottom-right":
|
|
161
|
+
default:
|
|
162
|
+
return {
|
|
163
|
+
left: W - ACTIVATION_CORNER_SIZE,
|
|
164
|
+
top: H - ACTIVATION_CORNER_SIZE,
|
|
165
|
+
right: W,
|
|
166
|
+
bottom: H
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function inflateRect(rect, padding) {
|
|
171
|
+
return {
|
|
172
|
+
left: rect.left - padding,
|
|
173
|
+
top: rect.top - padding,
|
|
174
|
+
right: rect.right + padding,
|
|
175
|
+
bottom: rect.bottom + padding
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function isInside(point, rect) {
|
|
179
|
+
return point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom;
|
|
180
|
+
}
|
|
181
|
+
function isInActivationZone(point, anchor, size) {
|
|
182
|
+
return isInside(point, getActivationRect(anchor, size));
|
|
183
|
+
}
|
|
184
|
+
function onGlobalPointerMove(e) {
|
|
185
|
+
if (!isAutoHideActive.value) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const size = getToolbarSize();
|
|
189
|
+
const point = {
|
|
190
|
+
x: e.clientX,
|
|
191
|
+
y: e.clientY
|
|
192
|
+
};
|
|
193
|
+
const keepAliveRect = inflateRect(getCollapsedRect(placement.value, size), KEEP_ALIVE_PADDING);
|
|
194
|
+
if (isInActivationZone(point, placement.value, size) || isAutoHideRevealed.value && isInside(point, keepAliveRect)) {
|
|
195
|
+
reveal();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
scheduleHide();
|
|
199
|
+
}
|
|
200
|
+
function onWindowBlur() {
|
|
201
|
+
if (isAutoHideActive.value) {
|
|
202
|
+
hideNow();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function addGlobalListeners() {
|
|
206
|
+
if (listenersAttached || typeof window === "undefined") {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
listenersAttached = true;
|
|
210
|
+
window.addEventListener("pointermove", onGlobalPointerMove, true);
|
|
211
|
+
window.addEventListener("blur", onWindowBlur);
|
|
212
|
+
}
|
|
213
|
+
function removeGlobalListeners() {
|
|
214
|
+
if (!listenersAttached || typeof window === "undefined") {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
listenersAttached = false;
|
|
218
|
+
window.removeEventListener("pointermove", onGlobalPointerMove, true);
|
|
219
|
+
window.removeEventListener("blur", onWindowBlur);
|
|
220
|
+
}
|
|
221
|
+
function onToolbarPointerEnter() {
|
|
222
|
+
if (!isAutoHideActive.value) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
lockReveal(ENTER_LOCK_MS);
|
|
226
|
+
}
|
|
227
|
+
function onToolbarPointerLeave() {}
|
|
228
|
+
function onToolbarPointerDown() {
|
|
229
|
+
if (!isAutoHideActive.value) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
lockReveal(CLICK_LOCK_MS);
|
|
233
|
+
}
|
|
234
|
+
function onToolbarFocusIn() {
|
|
235
|
+
if (!isAutoHideActive.value) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
lockReveal(CLICK_LOCK_MS);
|
|
239
|
+
}
|
|
240
|
+
function onToolbarFocusOut() {
|
|
241
|
+
if (!isAutoHideActive.value) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
scheduleHide();
|
|
245
|
+
}
|
|
246
|
+
(0, _vueDemi.watch)(isAutoHideActive, active => {
|
|
247
|
+
if (!active) {
|
|
248
|
+
removeGlobalListeners();
|
|
249
|
+
hideNow();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
addGlobalListeners();
|
|
253
|
+
isAutoHideRevealed.value = false;
|
|
254
|
+
}, {
|
|
255
|
+
immediate: true
|
|
256
|
+
});
|
|
257
|
+
(0, _vueDemi.onBeforeUnmount)(() => {
|
|
258
|
+
removeGlobalListeners();
|
|
259
|
+
clearHideTimer();
|
|
260
|
+
});
|
|
261
|
+
return {
|
|
262
|
+
isAutoHideActive,
|
|
263
|
+
isAutoHideRevealed,
|
|
264
|
+
onToolbarPointerEnter,
|
|
265
|
+
onToolbarPointerLeave,
|
|
266
|
+
onToolbarPointerDown,
|
|
267
|
+
onToolbarFocusIn,
|
|
268
|
+
onToolbarFocusOut
|
|
269
|
+
};
|
|
270
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { computed, onBeforeUnmount, ref, watch } from "vue-demi";
|
|
2
|
+
const EDGE_OFFSET = 20;
|
|
3
|
+
const DEFAULT_TOOLBAR_SIZE = 42;
|
|
4
|
+
const ACTIVATION_EDGE_DEPTH = 16;
|
|
5
|
+
const ACTIVATION_INLINE_PAD = 30;
|
|
6
|
+
const ACTIVATION_CORNER_SIZE = 32;
|
|
7
|
+
const KEEP_ALIVE_PADDING = 56;
|
|
8
|
+
const HIDE_DELAY_MS = 140;
|
|
9
|
+
const ENTER_LOCK_MS = 220;
|
|
10
|
+
const CLICK_LOCK_MS = 320;
|
|
11
|
+
export function useToolbarAutoHide(options) {
|
|
12
|
+
const { enabled, expanded, isDragging, placement, toolbarEl } = options;
|
|
13
|
+
const isAutoHideRevealed = ref(false);
|
|
14
|
+
const isAutoHideActive = computed(() => enabled.value && !expanded.value && !isDragging.value);
|
|
15
|
+
let hideTimer = null;
|
|
16
|
+
let revealLockUntil = 0;
|
|
17
|
+
let listenersAttached = false;
|
|
18
|
+
function clearHideTimer() {
|
|
19
|
+
if (!hideTimer) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
clearTimeout(hideTimer);
|
|
23
|
+
hideTimer = null;
|
|
24
|
+
}
|
|
25
|
+
function reveal() {
|
|
26
|
+
isAutoHideRevealed.value = true;
|
|
27
|
+
clearHideTimer();
|
|
28
|
+
}
|
|
29
|
+
function lockReveal(durationMs) {
|
|
30
|
+
revealLockUntil = Math.max(revealLockUntil, Date.now() + durationMs);
|
|
31
|
+
reveal();
|
|
32
|
+
}
|
|
33
|
+
function hideNow() {
|
|
34
|
+
clearHideTimer();
|
|
35
|
+
revealLockUntil = 0;
|
|
36
|
+
isAutoHideRevealed.value = false;
|
|
37
|
+
}
|
|
38
|
+
function scheduleHide() {
|
|
39
|
+
clearHideTimer();
|
|
40
|
+
hideTimer = setTimeout(() => {
|
|
41
|
+
if (Date.now() < revealLockUntil) {
|
|
42
|
+
scheduleHide();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
isAutoHideRevealed.value = false;
|
|
46
|
+
hideTimer = null;
|
|
47
|
+
}, HIDE_DELAY_MS);
|
|
48
|
+
}
|
|
49
|
+
function getToolbarSize() {
|
|
50
|
+
const el = toolbarEl.value;
|
|
51
|
+
return {
|
|
52
|
+
width: el?.offsetWidth ?? DEFAULT_TOOLBAR_SIZE,
|
|
53
|
+
height: el?.offsetHeight ?? DEFAULT_TOOLBAR_SIZE
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function getCollapsedRect(anchor, size) {
|
|
57
|
+
const left = EDGE_OFFSET;
|
|
58
|
+
const top = EDGE_OFFSET;
|
|
59
|
+
const right = window.innerWidth - EDGE_OFFSET - size.width;
|
|
60
|
+
const bottom = window.innerHeight - EDGE_OFFSET - size.height;
|
|
61
|
+
const centerX = (window.innerWidth - size.width) / 2;
|
|
62
|
+
switch (anchor) {
|
|
63
|
+
case "top-left":
|
|
64
|
+
return { left, top, right: left + size.width, bottom: top + size.height };
|
|
65
|
+
case "top-center":
|
|
66
|
+
return { left: centerX, top, right: centerX + size.width, bottom: top + size.height };
|
|
67
|
+
case "top-right":
|
|
68
|
+
return { left: right, top, right: right + size.width, bottom: top + size.height };
|
|
69
|
+
case "bottom-left":
|
|
70
|
+
return { left, top: bottom, right: left + size.width, bottom: bottom + size.height };
|
|
71
|
+
case "bottom-center":
|
|
72
|
+
return { left: centerX, top: bottom, right: centerX + size.width, bottom: bottom + size.height };
|
|
73
|
+
case "bottom-right":
|
|
74
|
+
default:
|
|
75
|
+
return { left: right, top: bottom, right: right + size.width, bottom: bottom + size.height };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function getActivationRect(anchor, size) {
|
|
79
|
+
const W = window.innerWidth;
|
|
80
|
+
const H = window.innerHeight;
|
|
81
|
+
const centerX = W / 2;
|
|
82
|
+
switch (anchor) {
|
|
83
|
+
case "top-left":
|
|
84
|
+
return { left: 0, top: 0, right: ACTIVATION_CORNER_SIZE, bottom: ACTIVATION_CORNER_SIZE };
|
|
85
|
+
case "top-center":
|
|
86
|
+
return {
|
|
87
|
+
left: centerX - size.width / 2 - ACTIVATION_INLINE_PAD,
|
|
88
|
+
top: 0,
|
|
89
|
+
right: centerX + size.width / 2 + ACTIVATION_INLINE_PAD,
|
|
90
|
+
bottom: ACTIVATION_EDGE_DEPTH
|
|
91
|
+
};
|
|
92
|
+
case "top-right":
|
|
93
|
+
return { left: W - ACTIVATION_CORNER_SIZE, top: 0, right: W, bottom: ACTIVATION_CORNER_SIZE };
|
|
94
|
+
case "bottom-left":
|
|
95
|
+
return { left: 0, top: H - ACTIVATION_CORNER_SIZE, right: ACTIVATION_CORNER_SIZE, bottom: H };
|
|
96
|
+
case "bottom-center":
|
|
97
|
+
return {
|
|
98
|
+
left: centerX - size.width / 2 - ACTIVATION_INLINE_PAD,
|
|
99
|
+
top: H - ACTIVATION_EDGE_DEPTH,
|
|
100
|
+
right: centerX + size.width / 2 + ACTIVATION_INLINE_PAD,
|
|
101
|
+
bottom: H
|
|
102
|
+
};
|
|
103
|
+
case "bottom-right":
|
|
104
|
+
default:
|
|
105
|
+
return { left: W - ACTIVATION_CORNER_SIZE, top: H - ACTIVATION_CORNER_SIZE, right: W, bottom: H };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function inflateRect(rect, padding) {
|
|
109
|
+
return {
|
|
110
|
+
left: rect.left - padding,
|
|
111
|
+
top: rect.top - padding,
|
|
112
|
+
right: rect.right + padding,
|
|
113
|
+
bottom: rect.bottom + padding
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function isInside(point, rect) {
|
|
117
|
+
return point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom;
|
|
118
|
+
}
|
|
119
|
+
function isInActivationZone(point, anchor, size) {
|
|
120
|
+
return isInside(point, getActivationRect(anchor, size));
|
|
121
|
+
}
|
|
122
|
+
function onGlobalPointerMove(e) {
|
|
123
|
+
if (!isAutoHideActive.value) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const size = getToolbarSize();
|
|
127
|
+
const point = { x: e.clientX, y: e.clientY };
|
|
128
|
+
const keepAliveRect = inflateRect(getCollapsedRect(placement.value, size), KEEP_ALIVE_PADDING);
|
|
129
|
+
if (isInActivationZone(point, placement.value, size) || isAutoHideRevealed.value && isInside(point, keepAliveRect)) {
|
|
130
|
+
reveal();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
scheduleHide();
|
|
134
|
+
}
|
|
135
|
+
function onWindowBlur() {
|
|
136
|
+
if (isAutoHideActive.value) {
|
|
137
|
+
hideNow();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function addGlobalListeners() {
|
|
141
|
+
if (listenersAttached || typeof window === "undefined") {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
listenersAttached = true;
|
|
145
|
+
window.addEventListener("pointermove", onGlobalPointerMove, true);
|
|
146
|
+
window.addEventListener("blur", onWindowBlur);
|
|
147
|
+
}
|
|
148
|
+
function removeGlobalListeners() {
|
|
149
|
+
if (!listenersAttached || typeof window === "undefined") {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
listenersAttached = false;
|
|
153
|
+
window.removeEventListener("pointermove", onGlobalPointerMove, true);
|
|
154
|
+
window.removeEventListener("blur", onWindowBlur);
|
|
155
|
+
}
|
|
156
|
+
function onToolbarPointerEnter() {
|
|
157
|
+
if (!isAutoHideActive.value) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
lockReveal(ENTER_LOCK_MS);
|
|
161
|
+
}
|
|
162
|
+
function onToolbarPointerLeave() {
|
|
163
|
+
}
|
|
164
|
+
function onToolbarPointerDown() {
|
|
165
|
+
if (!isAutoHideActive.value) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
lockReveal(CLICK_LOCK_MS);
|
|
169
|
+
}
|
|
170
|
+
function onToolbarFocusIn() {
|
|
171
|
+
if (!isAutoHideActive.value) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
lockReveal(CLICK_LOCK_MS);
|
|
175
|
+
}
|
|
176
|
+
function onToolbarFocusOut() {
|
|
177
|
+
if (!isAutoHideActive.value) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
scheduleHide();
|
|
181
|
+
}
|
|
182
|
+
watch(
|
|
183
|
+
isAutoHideActive,
|
|
184
|
+
(active) => {
|
|
185
|
+
if (!active) {
|
|
186
|
+
removeGlobalListeners();
|
|
187
|
+
hideNow();
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
addGlobalListeners();
|
|
191
|
+
isAutoHideRevealed.value = false;
|
|
192
|
+
},
|
|
193
|
+
{ immediate: true }
|
|
194
|
+
);
|
|
195
|
+
onBeforeUnmount(() => {
|
|
196
|
+
removeGlobalListeners();
|
|
197
|
+
clearHideTimer();
|
|
198
|
+
});
|
|
199
|
+
return {
|
|
200
|
+
isAutoHideActive,
|
|
201
|
+
isAutoHideRevealed,
|
|
202
|
+
onToolbarPointerEnter,
|
|
203
|
+
onToolbarPointerLeave,
|
|
204
|
+
onToolbarPointerDown,
|
|
205
|
+
onToolbarFocusIn,
|
|
206
|
+
onToolbarFocusOut
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Ref } from 'vue-demi';
|
|
2
|
+
import type { ToolbarAnchor } from '../types';
|
|
3
|
+
export type { ToolbarAnchor } from '../types';
|
|
4
|
+
interface UseToolbarDragSnapOptions {
|
|
5
|
+
expanded: Ref<boolean>;
|
|
6
|
+
initialPlacement?: ToolbarAnchor;
|
|
7
|
+
onDragStart?: () => void;
|
|
8
|
+
onDragEnd?: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function useToolbarDragSnap(options: UseToolbarDragSnapOptions): {
|
|
11
|
+
placement: Ref<ToolbarAnchor, ToolbarAnchor>;
|
|
12
|
+
isDragging: Ref<boolean, boolean>;
|
|
13
|
+
toolbarStyle: import("vue-demi").ComputedRef<{
|
|
14
|
+
left: string;
|
|
15
|
+
top: string;
|
|
16
|
+
transform: string;
|
|
17
|
+
} | undefined>;
|
|
18
|
+
toolbarEl: Ref<HTMLElement | null, HTMLElement | null>;
|
|
19
|
+
snapAnchors: ToolbarAnchor[];
|
|
20
|
+
activeSnapAnchor: import("vue-demi").ComputedRef<ToolbarAnchor | null>;
|
|
21
|
+
isExpandedDrag: import("vue-demi").ComputedRef<boolean>;
|
|
22
|
+
getSnapStyle: (anchor: ToolbarAnchor) => Record<string, string>;
|
|
23
|
+
onTogglePointerDown: (e: PointerEvent) => void;
|
|
24
|
+
onHandlePointerDown: (e: PointerEvent) => void;
|
|
25
|
+
onPointerMove: (e: PointerEvent) => void;
|
|
26
|
+
onPointerUp: (e: PointerEvent) => void;
|
|
27
|
+
onPointerCancel: () => void;
|
|
28
|
+
consumeToggleClickSuppression: () => boolean;
|
|
29
|
+
cleanup: () => void;
|
|
30
|
+
};
|