merge: upstream

This commit is contained in:
Marie 2024-02-03 20:19:44 +01:00
commit 11628e4b6a
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
285 changed files with 3413 additions and 1913 deletions

View file

@ -63,7 +63,7 @@ import { defaultStore } from '@/store.js';
const minHeight = 50;
const minWidth = 250;
function dragListen(fn: (ev: MouseEvent) => void) {
function dragListen(fn: (ev: MouseEvent | TouchEvent) => void) {
window.addEventListener('mousemove', fn);
window.addEventListener('touchmove', fn);
window.addEventListener('mouseleave', dragClear.bind(null, fn));
@ -138,7 +138,7 @@ function onContextmenu(ev: MouseEvent) {
//
function top() {
if (rootEl.value) {
rootEl.value.style.zIndex = os.claimZIndex(props.front ? 'middle' : 'low');
rootEl.value.style.zIndex = os.claimZIndex(props.front ? 'middle' : 'low').toString();
}
}
@ -202,9 +202,17 @@ function onDblClick() {
}
}
function onHeaderMousedown(evt: MouseEvent) {
function getPositionX(event: MouseEvent | TouchEvent) {
return 'touches' in event && event.touches.length > 0 ? event.touches[0].clientX : 'clientX' in event ? event.clientX : 0;
}
function getPositionY(event: MouseEvent | TouchEvent) {
return 'touches' in event && event.touches.length > 0 ? event.touches[0].clientY : 'clientY' in event ? event.clientY : 0;
}
function onHeaderMousedown(evt: MouseEvent | TouchEvent) {
//
if (evt.button === 2) return;
if ('button' in evt && evt.button === 2) return;
let beforeMaximized = false;
@ -229,8 +237,8 @@ function onHeaderMousedown(evt: MouseEvent) {
const position = main.getBoundingClientRect();
const clickX = evt.touches && evt.touches.length > 0 ? evt.touches[0].clientX : evt.clientX;
const clickY = evt.touches && evt.touches.length > 0 ? evt.touches[0].clientY : evt.clientY;
const clickX = getPositionX(evt);
const clickY = getPositionY(evt);
const moveBaseX = beforeMaximized ? parseInt(unResizedWidth, 10) / 2 : clickX - position.left; // TODO: parseInt
const moveBaseY = beforeMaximized ? 20 : clickY - position.top;
const browserWidth = window.innerWidth;
@ -254,8 +262,10 @@ function onHeaderMousedown(evt: MouseEvent) {
//
if (moveLeft + windowWidth > browserWidth) moveLeft = browserWidth - windowWidth;
rootEl.value.style.left = moveLeft + 'px';
rootEl.value.style.top = moveTop + 'px';
if (rootEl.value) {
rootEl.value.style.left = moveLeft + 'px';
rootEl.value.style.top = moveTop + 'px';
}
}
if (beforeMaximized) {
@ -264,26 +274,26 @@ function onHeaderMousedown(evt: MouseEvent) {
//
dragListen(me => {
const x = me.touches && me.touches.length > 0 ? me.touches[0].clientX : me.clientX;
const y = me.touches && me.touches.length > 0 ? me.touches[0].clientY : me.clientY;
const x = getPositionX(me);
const y = getPositionY(me);
move(x, y);
});
}
//
function onTopHandleMousedown(evt) {
function onTopHandleMousedown(evt: MouseEvent | TouchEvent) {
const main = rootEl.value;
// null
if (main == null) return;
const base = evt.clientY;
const base = getPositionY(evt);
const height = parseInt(getComputedStyle(main, '').height, 10);
const top = parseInt(getComputedStyle(main, '').top, 10);
//
dragListen(me => {
const move = me.clientY - base;
const move = getPositionY(me) - base;
if (top + move > 0) {
if (height + -move > minHeight) {
applyTransformHeight(height + -move);
@ -300,18 +310,18 @@ function onTopHandleMousedown(evt) {
}
//
function onRightHandleMousedown(evt) {
function onRightHandleMousedown(evt: MouseEvent | TouchEvent) {
const main = rootEl.value;
if (main == null) return;
const base = evt.clientX;
const base = getPositionX(evt);
const width = parseInt(getComputedStyle(main, '').width, 10);
const left = parseInt(getComputedStyle(main, '').left, 10);
const browserWidth = window.innerWidth;
//
dragListen(me => {
const move = me.clientX - base;
const move = getPositionX(me) - base;
if (left + width + move < browserWidth) {
if (width + move > minWidth) {
applyTransformWidth(width + move);
@ -325,18 +335,18 @@ function onRightHandleMousedown(evt) {
}
//
function onBottomHandleMousedown(evt) {
function onBottomHandleMousedown(evt: MouseEvent | TouchEvent) {
const main = rootEl.value;
if (main == null) return;
const base = evt.clientY;
const base = getPositionY(evt);
const height = parseInt(getComputedStyle(main, '').height, 10);
const top = parseInt(getComputedStyle(main, '').top, 10);
const browserHeight = window.innerHeight;
//
dragListen(me => {
const move = me.clientY - base;
const move = getPositionY(me) - base;
if (top + height + move < browserHeight) {
if (height + move > minHeight) {
applyTransformHeight(height + move);
@ -350,17 +360,17 @@ function onBottomHandleMousedown(evt) {
}
//
function onLeftHandleMousedown(evt) {
function onLeftHandleMousedown(evt: MouseEvent | TouchEvent) {
const main = rootEl.value;
if (main == null) return;
const base = evt.clientX;
const base = getPositionX(evt);
const width = parseInt(getComputedStyle(main, '').width, 10);
const left = parseInt(getComputedStyle(main, '').left, 10);
//
dragListen(me => {
const move = me.clientX - base;
const move = getPositionX(me) - base;
if (left + move > 0) {
if (width + -move > minWidth) {
applyTransformWidth(width + -move);
@ -377,25 +387,25 @@ function onLeftHandleMousedown(evt) {
}
//
function onTopLeftHandleMousedown(evt) {
function onTopLeftHandleMousedown(evt: MouseEvent | TouchEvent) {
onTopHandleMousedown(evt);
onLeftHandleMousedown(evt);
}
//
function onTopRightHandleMousedown(evt) {
function onTopRightHandleMousedown(evt: MouseEvent | TouchEvent) {
onTopHandleMousedown(evt);
onRightHandleMousedown(evt);
}
//
function onBottomRightHandleMousedown(evt) {
function onBottomRightHandleMousedown(evt: MouseEvent | TouchEvent) {
onBottomHandleMousedown(evt);
onRightHandleMousedown(evt);
}
//
function onBottomLeftHandleMousedown(evt) {
function onBottomLeftHandleMousedown(evt: MouseEvent | TouchEvent) {
onBottomHandleMousedown(evt);
onLeftHandleMousedown(evt);
}
@ -403,23 +413,23 @@ function onBottomLeftHandleMousedown(evt) {
//
function applyTransformHeight(height) {
if (height > window.innerHeight) height = window.innerHeight;
rootEl.value.style.height = height + 'px';
if (rootEl.value) rootEl.value.style.height = height + 'px';
}
//
function applyTransformWidth(width) {
if (width > window.innerWidth) width = window.innerWidth;
rootEl.value.style.width = width + 'px';
if (rootEl.value) rootEl.value.style.width = width + 'px';
}
// Y
function applyTransformTop(top) {
rootEl.value.style.top = top + 'px';
if (rootEl.value) rootEl.value.style.top = top + 'px';
}
// X
function applyTransformLeft(left) {
rootEl.value.style.left = left + 'px';
if (rootEl.value) rootEl.value.style.left = left + 'px';
}
function onBrowserResize() {
@ -441,8 +451,10 @@ onMounted(() => {
applyTransformWidth(props.initialWidth);
if (props.initialHeight) applyTransformHeight(props.initialHeight);
applyTransformTop((window.innerHeight / 2) - (rootEl.value.offsetHeight / 2));
applyTransformLeft((window.innerWidth / 2) - (rootEl.value.offsetWidth / 2));
if (rootEl.value) {
applyTransformTop((window.innerHeight / 2) - (rootEl.value.offsetHeight / 2));
applyTransformLeft((window.innerWidth / 2) - (rootEl.value.offsetWidth / 2));
}
//
top();