;(function () {
const TAURI_DRAG_REGION_ATTR = 'data-tauri-drag-region'
const CLICKABLE_TAGS = new Set([
'A',
'BUTTON',
'INPUT',
'SELECT',
'TEXTAREA',
'LABEL',
'SUMMARY'
])
const INTERACTIVE_ROLES = new Set([
'button',
'link',
'menuitem',
'tab',
'checkbox',
'radio',
'switch',
'option'
])
function isClickableElement(el) {
return (
CLICKABLE_TAGS.has(el.tagName)
|| (el.hasAttribute('contenteditable')
&& el.getAttribute('contenteditable') !== 'false')
|| (el.hasAttribute('tabindex') && el.getAttribute('tabindex') !== '-1')
|| INTERACTIVE_ROLES.has(el.getAttribute('role'))
)
}
function isDragRegion(composedPath) {
for (const el of composedPath) {
if (!(el instanceof HTMLElement)) continue
const attr = el.getAttribute(TAURI_DRAG_REGION_ATTR)
if (isClickableElement(el) && attr === null) return false
if (attr === null) continue
if (attr === 'false') return false
if (attr === 'deep') return true
if (attr === '' || attr === 'true') return el === composedPath[0]
}
return false
}
const osName = __TEMPLATE_os_name__
let initialX = 0
let initialY = 0
document.addEventListener('mousedown', (e) => {
if (
e.button === 0
&& (e.detail === 1 || e.detail === 2)
&& isDragRegion(e.composedPath())
) {
if (osName === 'macos' && e.detail === 2) {
initialX = e.clientX
initialY = e.clientY
return
}
e.preventDefault()
e.stopImmediatePropagation()
const cmd = e.detail === 2 ? 'internal_toggle_maximize' : 'start_dragging'
window.__TAURI_INTERNALS__.invoke('plugin:window|' + cmd)
}
})
if (osName === 'macos') {
document.addEventListener('mouseup', (e) => {
if (
e.button === 0
&& e.detail === 2
&& e.clientX === initialX
&& e.clientY === initialY
&& isDragRegion(e.composedPath())
) {
window.__TAURI_INTERNALS__.invoke(
'plugin:window|internal_toggle_maximize'
)
}
})
}
})()