tauri-plugin-decoration 2.0.2

Native window controls, custom decorations, and Windows 11 Snap Layout for Tauri v2 apps.

(() => {
	const setup = () => {
		let tbEl = document.querySelector("[data-tauri-decoration-tb]");

		if (!tbEl) {
			console.log(
				"DECORATION: Element with data-tauri-decoration-tb not found. Creating one.",
			);

			// Create titlebar element
			tbEl = document.createElement("div");
			tbEl.setAttribute("data-tauri-decoration-tb", "");
			tbEl.setAttribute("role", "group");
			tbEl.setAttribute("lang", "en");
			tbEl.setAttribute("aria-label", "Window controls");
			tbEl.style.top = 0;
			tbEl.style.left = 0;
			tbEl.style.zIndex = 100;
			tbEl.style.width = "100%";
			tbEl.style.height = "32px";
			tbEl.style.display = "flex";
			tbEl.style.position = "fixed";
			tbEl.style.alignItems = "end";
			tbEl.style.justifyContent = "end";
			tbEl.style.backgroundColor = "transparent";

			// Create draggable area
			const drag = document.createElement("div");
			drag.style.width = "100%";
			drag.style.height = "100%";
			drag.style.background = "transparent";
			drag.setAttribute("data-tauri-drag-region", "");
			tbEl.appendChild(drag);

			// add tbEl to the body
			document.body.prepend(tbEl);
		}
	};

	// Fix for #50/#32: scripts may be injected after DOMContentLoaded
	// has already fired, so check readyState instead of always waiting.
	if (document.readyState === "loading") {
		document.addEventListener("DOMContentLoaded", setup);
	} else {
		setup();
	}
})();