super-browser-window-kit
Version:
Super toolkit for enhanced Electron BrowserWindow with rounded corners and macOS liquid glass effects
536 lines (531 loc) • 20.9 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
//#region rolldown:runtime
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
//#endregion
const os = __toESM(require("os"));
const url = __toESM(require("url"));
const path = __toESM(require("path"));
//#region js/variants.ts
const GlassMaterialVariant = {
regular: 0,
clear: 1,
dock: 2,
appIcons: 3,
widgets: 4,
text: 5,
avplayer: 6,
facetime: 7,
controlCenter: 8,
notificationCenter: 9,
monogram: 10,
bubbles: 11,
identity: 12,
focusBorder: 13,
focusPlatter: 14,
keyboard: 15,
sidebar: 16,
abuttedSidebar: 17,
inspector: 18,
control: 19,
loupe: 20,
slider: 21,
camera: 22,
cartouchePopover: 23
};
//#endregion
//#region js/native-loader.ts
const __filename$1 = (0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
const __dirname$1 = (0, path.dirname)(__filename$1);
const nodeGypBuild = require("node-gyp-build");
var native_loader_default = nodeGypBuild((0, path.join)(__dirname$1, ".."));
//#endregion
//#region js/index.ts
let NSWindowToolbarStyle = /* @__PURE__ */ function(NSWindowToolbarStyle$1) {
NSWindowToolbarStyle$1[NSWindowToolbarStyle$1["Automatic"] = 0] = "Automatic";
NSWindowToolbarStyle$1[NSWindowToolbarStyle$1["Expanded"] = 1] = "Expanded";
NSWindowToolbarStyle$1[NSWindowToolbarStyle$1["Preference"] = 2] = "Preference";
NSWindowToolbarStyle$1[NSWindowToolbarStyle$1["Unified"] = 3] = "Unified";
NSWindowToolbarStyle$1[NSWindowToolbarStyle$1["UnifiedCompact"] = 4] = "UnifiedCompact";
return NSWindowToolbarStyle$1;
}({});
let AutoresizingMask = /* @__PURE__ */ function(AutoresizingMask$1) {
AutoresizingMask$1[AutoresizingMask$1["NotSizable"] = 0] = "NotSizable";
AutoresizingMask$1[AutoresizingMask$1["MinXMargin"] = 1] = "MinXMargin";
AutoresizingMask$1[AutoresizingMask$1["WidthSizable"] = 2] = "WidthSizable";
AutoresizingMask$1[AutoresizingMask$1["MaxXMargin"] = 4] = "MaxXMargin";
AutoresizingMask$1[AutoresizingMask$1["MinYMargin"] = 8] = "MinYMargin";
AutoresizingMask$1[AutoresizingMask$1["HeightSizable"] = 16] = "HeightSizable";
AutoresizingMask$1[AutoresizingMask$1["MaxYMargin"] = 32] = "MaxYMargin";
AutoresizingMask$1[AutoresizingMask$1["FlexibleWidth"] = 2] = "FlexibleWidth";
AutoresizingMask$1[AutoresizingMask$1["FlexibleHeight"] = 16] = "FlexibleHeight";
AutoresizingMask$1[AutoresizingMask$1["FlexibleSize"] = 18] = "FlexibleSize";
AutoresizingMask$1[AutoresizingMask$1["FlexibleLeftMargin"] = 1] = "FlexibleLeftMargin";
AutoresizingMask$1[AutoresizingMask$1["FlexibleRightMargin"] = 4] = "FlexibleRightMargin";
AutoresizingMask$1[AutoresizingMask$1["FlexibleTopMargin"] = 32] = "FlexibleTopMargin";
AutoresizingMask$1[AutoresizingMask$1["FlexibleBottomMargin"] = 8] = "FlexibleBottomMargin";
AutoresizingMask$1[AutoresizingMask$1["FlexibleMargins"] = 45] = "FlexibleMargins";
AutoresizingMask$1[AutoresizingMask$1["All"] = 63] = "All";
return AutoresizingMask$1;
}({});
var TahoeFidelityKit = class {
_addon;
_macosVersion = process.platform === "darwin" ? Number(os.release().split(".")[0]) : 0;
GlassMaterialVariant = GlassMaterialVariant;
constructor() {
if (process.platform !== "darwin") {
console.warn("super-browser-window-kit only supports macOS.");
return;
}
try {
this._addon = new native_loader_default.TahoeFidelityKitNative(require);
} catch (err) {
console.error("super-browser-window-kit failed to load its native addon.", err);
}
}
/**
* 设置全屏通知监听器。
* @param handle BrowserWindow.getNativeWindowHandle()
* @param callback 回调函数 (FullScreenNotificationInfo) => void
* @returns true if listener was set, false otherwise
*/
setFullScreenNotificationListener(handle, callback) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon || typeof this._addon.setFullScreenNotificationListener !== "function") {
console.warn("super-browser-window-kit is unavailable on this platform – setFullScreenNotificationListener will be a no-op.");
return false;
}
return this._addon.setFullScreenNotificationListener(handle, callback);
}
/**
* 移除全屏通知监听器。
* @param handle BrowserWindow.getNativeWindowHandle()
* @returns true if listener was removed, false otherwise
*/
removeFullScreenNotificationListener(handle) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon || typeof this._addon.removeFullScreenNotificationListener !== "function") {
console.warn("super-browser-window-kit is unavailable on this platform – removeFullScreenNotificationListener will be a no-op.");
return false;
}
return this._addon.removeFullScreenNotificationListener(handle);
}
/**
* Dynamically add window:willUseFullScreenPresentationOptions: to NSWindow.delegate.
* This enables autoHideToolbar/fullScreen/autoHideMenuBar for full screen transitions.
* @param handle BrowserWindow.getNativeWindowHandle()
* @returns true if method was added, false otherwise
*/
addFullScreenOptionsMethod(handle) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon || typeof this._addon.addFullScreenOptionsMethod !== "function") {
console.warn("super-browser-window-kit is unavailable on this platform – addFullScreenOptionsMethod will be a no-op.");
return false;
}
return this._addon.addFullScreenOptionsMethod(handle);
}
/**
* Wrap the Electron window with a glass / vibrancy view.
* @param handle BrowserWindow.getNativeWindowHandle()
* @param options Glass effect options
* @returns id – can be used for future API (remove/update)
*/
addGlassEffectView(handle, options = {}) {
if (this._macosVersion < 25) {
console.warn("super-browser-window-kit addGlassEffectView requires macOS 26 or higher.");
return -1;
}
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return -1;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – addGlassEffectView will be a no-op.");
return -1;
}
const viewId = this._addon.addGlassEffectView(handle);
if (viewId >= 0 && options) {
if (options.cornerRadius !== void 0) this._addon.setGlassCornerRadius(handle, viewId, options.cornerRadius);
if (options.tintColor !== void 0) this.setGlassColor(handle, viewId, options.tintColor);
}
return viewId;
}
/**
* Remove a view (glass or background) by its ID.
* This method works for both glass views and background views.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param id The view ID returned by addGlassEffectView or addBackgroundView
* @returns true if the view was successfully removed, false otherwise
*/
removeView(handle, id) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – removeView will be a no-op.");
return false;
}
return this._addon.removeView(handle, id);
}
setVariant(handle, id, variant) {
if (this._macosVersion < 25) {
console.warn("super-browser-window-kit setVariant requires macOS 26 or higher.");
return;
}
if (!this._addon || typeof this._addon.setVariant !== "function") return;
this._addon.setVariant(handle, id, variant);
}
setScrim(handle, id, scrim) {
if (this._macosVersion < 25) {
console.warn("super-browser-window-kit setScrim requires macOS 26 or higher.");
return;
}
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return;
}
if (!this._addon || typeof this._addon.setScrimState !== "function") return;
this._addon.setScrimState(handle, id, scrim);
}
setSubdued(handle, id, subdued) {
if (this._macosVersion < 25) {
console.warn("super-browser-window-kit setSubdued requires macOS 26 or higher.");
return;
}
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return;
}
if (!this._addon || typeof this._addon.setSubduedState !== "function") return;
this._addon.setSubduedState(handle, id, subdued);
}
/**
* Set the corner radius of a glass view.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param id The glass view ID returned by addGlassEffectView
* @param cornerRadius Corner radius in points
*/
setGlassCornerRadius(handle, id, cornerRadius) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – setGlassCornerRadius will be a no-op.");
return;
}
this._addon.setGlassCornerRadius(handle, id, cornerRadius);
}
/**
* Set the color of a glass view.
* Supports both single color and dynamic color (light/dark mode).
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param id The glass view ID returned by addGlassEffectView
* @param color Hex color string (e.g., "#FF0000") or object with light/dark colors
*/
setGlassColor(handle, id, color) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – setGlassColor will be a no-op.");
return;
}
if (typeof color === "string") this._addon.setGlassColor(handle, id, color);
else if (typeof color === "object" && color.light && color.dark) this._addon.setGlassDynamicColor(handle, id, color.light, color.dark);
else console.error("super-browser-window-kit: color must be a string or an object with light and dark properties");
}
/**
* Set the autoresizing mask of a view (glass or background).
*
* The autoresizing mask determines how the view resizes and repositions
* when its parent (the window) changes size. This follows macOS NSView conventions.
*
* Common patterns:
* - AutoresizingMask.NotSizable: Fixed position and size (use with setFrame)
* - AutoresizingMask.FlexibleSize: Fill entire parent
* - AutoresizingMask.FlexibleMargins: Maintain size, center in parent
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param id The view ID returned by addGlassEffectView or addBackgroundView
* @param mask The autoresizing mask (use AutoresizingMask enum values)
* @returns true if the mask was successfully set, false otherwise
*/
setAutoresizingMask(handle, id, mask) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – setAutoresizingMask will be a no-op.");
return false;
}
return this._addon.setAutoresizingMask(handle, id, mask);
}
/**
* Get the current frame (position and size) of a view (glass or background).
* @param handle BrowserWindow.getNativeWindowHandle()
* @param id The view ID returned by addGlassEffectView or addBackgroundView
* @returns The frame object with x, y, width, height properties, or null if not found
*/
getFrame(handle, id) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return null;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – getFrame will return null.");
return null;
}
return this._addon.getFrame(handle, id);
}
/**
* Set frame components selectively. Pass null/undefined for values you want to keep unchanged.
* This provides maximum flexibility for partial frame updates.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param id The view ID returned by addGlassEffectView
* @param options Object with optional x, y, width, height properties
* @returns true if the frame was successfully updated, false otherwise
*/
updateFrame(handle, id, options) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – updateFrame will be a no-op.");
return false;
}
const x = options.x !== void 0 ? options.x : NaN;
const y = options.y !== void 0 ? options.y : NaN;
const width = options.width !== void 0 ? options.width : NaN;
const height = options.height !== void 0 ? options.height : NaN;
return this._addon.setFrame(handle, id, x, y, width, height);
}
/**
* Add a background view to the window.
* Background views are managed independently from glass views,
* allowing you to have multiple glass views with a single background.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param options Background view options (optional)
* @returns background view ID that can be used for future operations
*/
addBackgroundView(handle, options = {}) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return -1;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – addBackgroundView will be a no-op.");
return -1;
}
const viewId = this._addon.addBackgroundView(handle);
if (viewId >= 0 && options) {
if (options.cornerRadius !== void 0) this._addon.setBackgroundCornerRadius(handle, viewId, options.cornerRadius);
if (options.color !== void 0) this.setBackgroundColor(handle, viewId, options.color);
}
return viewId;
}
/**
* Set the corner radius of a background view.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param id The background view ID returned by addBackgroundView
* @param cornerRadius Corner radius in points
*/
setBackgroundCornerRadius(handle, id, cornerRadius) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – setBackgroundCornerRadius will be a no-op.");
return;
}
this._addon.setBackgroundCornerRadius(handle, id, cornerRadius);
}
/**
* Set the color of a background view.
* Supports both single color and dynamic color (light/dark mode).
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param id The background view ID returned by addBackgroundView
* @param color Hex color string (e.g., "#FF0000") or object with light/dark colors
*/
setBackgroundColor(handle, id, color) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – setBackgroundColor will be a no-op.");
return;
}
if (typeof color === "string") this._addon.setBackgroundColor(handle, id, color);
else if (typeof color === "object" && color.light && color.dark) this._addon.setBackgroundDynamicColor(handle, id, color.light, color.dark);
else console.error("super-browser-window-kit: color must be a string or an object with light and dark properties");
}
/**
* Set a toolbar for the window with the specified identifier.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param toolbarIdentifier A unique identifier for the toolbar
* @returns true if the toolbar was successfully set, false otherwise
*/
setWindowToolbar(handle, toolbarIdentifier) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – setWindowToolbar will be a no-op.");
return false;
}
return this._addon.setWindowToolbar(handle, toolbarIdentifier);
}
/**
* Set the toolbar style for the window.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param toolbarStyle NSWindowToolbarStyle value
* @returns true if the toolbar style was successfully set, false otherwise
*/
setWindowToolbarStyle(handle, toolbarStyle) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – setWindowToolbarStyle will be a no-op.");
return false;
}
return this._addon.setWindowToolbarStyle(handle, toolbarStyle);
}
/**
* Get the current toolbar identifier for the window.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @returns The toolbar identifier string, or null if no toolbar is set
*/
getWindowToolbar(handle) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return null;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – getWindowToolbar will return null.");
return null;
}
return this._addon.getWindowToolbar(handle);
}
/**
* Remove the toolbar from the window.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @returns true if the toolbar was successfully removed, false otherwise
*/
removeWindowToolbar(handle) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – removeWindowToolbar will be a no-op.");
return false;
}
return this._addon.removeWindowToolbar(handle);
}
/**
* Enable custom window corner radius support globally.
* Must be called before using setWindowCornerRadius.
*
* @returns true if corner customization was successfully enabled, false otherwise
*/
enableWindowCornerCustomization() {
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – enableWindowCornerCustomization will be a no-op.");
return false;
}
return this._addon.enableWindowCornerCustomization();
}
/**
* Set a custom corner radius for the specified window.
* Note: enableWindowCornerCustomization() must be called first.
*
* @param handle BrowserWindow.getNativeWindowHandle()
* @param radius Corner radius in points
* @returns true if the corner radius was successfully set, false otherwise
*/
setWindowCornerRadius(handle, radius) {
if (!Buffer.isBuffer(handle)) {
console.error("super-browser-window-kit: handle must be a Buffer");
return false;
}
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – setWindowCornerRadius will be a no-op.");
return false;
}
return this._addon.setWindowCornerRadius(handle, radius);
}
/**
* Disable custom window corner radius support globally.
* This restores the original corner mask behavior and clears all custom settings.
*
* @returns true if corner customization was successfully disabled, false otherwise
*/
disableWindowCornerCustomization() {
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – disableWindowCornerCustomization will be a no-op.");
return false;
}
return this._addon.disableWindowCornerCustomization();
}
setLicense(license) {
if (!this._addon) {
console.warn("super-browser-window-kit is unavailable on this platform – disableWindowCornerCustomization will be a no-op.");
return false;
}
return this._addon.setLicense(license);
}
};
const superBrowserWindowKit = new TahoeFidelityKit();
var js_default = superBrowserWindowKit;
//#endregion
exports.AutoresizingMask = AutoresizingMask;
exports.GlassMaterialVariant = GlassMaterialVariant;
exports.NSWindowToolbarStyle = NSWindowToolbarStyle;
exports.default = js_default;