@m3ui-vue/electron 0.0.0-stage → 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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["$slots","_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createElementVNode","_renderSlot","_createBlock","_createTextVNode","_toDisplayString","_normalizeProps","_guardReactiveProps","_Fragment","_renderList","_createVNode","Fragment","computed","createBlock","createCommentVNode","createElementBlock","createElementVNode","createTextVNode","createVNode","defineComponent","getCurrentScope","guardReactiveProps","nextTick","normalizeClass","normalizeProps","normalizeStyle","onBeforeUnmount","onMounted","onScopeDispose","openBlock","readonly","ref","renderList","renderSlot","toDisplayString","unref","watch","MIcon","MMenuBar","useLocale","useTheme","BRIDGE_KEY","bridge","ready","controls","platform","titleBarHeight","maximized","fullscreen","focused","accentColor","users","unsubscribe","unsubscribeAccent","started","apply","s","start","b","c","info","stop","useElectronWindow","colors","theme","value","count","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","MTitleBar_default","__props","__emit","props","emit","locale","revealed","shownMenus","menus","m","menusBelow","contains","items","item","i","onMenuSelect","altAlone","onKeydown","onKeyup","bar","hideLater","menubar","onBarKeydown","iconIsImage","win","isMac","ROLE","background","custom","native","atStart","lights","order","set","a","maximizeLabel","labels","run","onDblclick","probe","raf","until","observer","media","toHex","css","under","v","pageColor","hex","sendOverlay","color","symbolColor","follow","ms","step","onScheme","startSync","stopSync","_ctx","_cache","$event"],"sources":["../src/renderer/useElectronWindow.ts","../src/renderer/MTitleBar.vue"],"sourcesContent":["import { computed, onScopeDispose, readonly, ref, getCurrentScope, type ComputedRef, type Ref } from 'vue'\nimport { BRIDGE_KEY, DEFAULT_TITLE_BAR_HEIGHT, type M3Bridge, type M3Controls, type M3NativeTheme, type M3OverlayColors, type M3WindowState } from '../shared'\n\n/**\n * The window MTitleBar sits in, from the renderer: its mode and state (reactive) and its buttons. Outside Electron (or\n * without the preload's bridge) `isElectron` is false, nothing is ever `ready` and the actions do nothing, so the same\n * app also runs in a browser.\n */\nexport interface ElectronWindow {\n /** The preload's bridge is there */\n isElectron: boolean\n /** The main process has answered (mode, platform and state are real from here on) */\n ready: Readonly<Ref<boolean>>\n controls: Readonly<Ref<M3Controls>>\n /** `process.platform` of the main process (`''` until ready) */\n platform: Readonly<Ref<string>>\n isMac: ComputedRef<boolean>\n titleBarHeight: Readonly<Ref<number>>\n maximized: Readonly<Ref<boolean>>\n fullscreen: Readonly<Ref<boolean>>\n focused: Readonly<Ref<boolean>>\n /**\n * The system accent color (`#rrggbb`, Windows and macOS; null elsewhere), live. Seed the palette with it:\n * `watchEffect(() => accentColor.value && setSeed(accentColor.value))` with `useColorPalette()`\n */\n accentColor: Readonly<Ref<string | null>>\n minimize(): void\n toggleMaximize(): void\n close(): void\n /** Recolors the native buttons (MTitleBar does it from the theme; for a bar of your own) */\n setOverlay(colors: M3OverlayColors): void\n /** Native UI theme (MTitleBar keeps it in step with `useTheme()`; for an app without the bar) */\n setTheme(theme: M3NativeTheme): void\n /** Taskbar / dock progress, 0–1; `null` removes it, `'indeterminate'` for an unknown amount (Windows) */\n setProgress(value: number | 'indeterminate' | null): void\n /** Badge count on the dock / launcher icon (macOS, Linux Unity launchers); 0 removes it */\n setBadge(count: number): void\n /** Flashes the taskbar button / bounces the dock icon until the window gets focus */\n requestAttention(): void\n}\n\n// The methods added after 0.1.0 are called with ?.(): a preload bundled from an older version (an app that updated\n// the package but not its preload build) must not break the renderer, it just doesn't get those features\nfunction bridge(): M3Bridge | undefined {\n return typeof window !== 'undefined' ? (window as unknown as Record<string, M3Bridge | undefined>)[BRIDGE_KEY] : undefined\n}\n\n// One window per renderer: the state is shared by every caller, fetched once, and kept while anyone uses it\nconst ready = ref(false)\nconst controls = ref<M3Controls>('native')\nconst platform = ref('')\nconst titleBarHeight = ref(DEFAULT_TITLE_BAR_HEIGHT)\nconst maximized = ref(false)\nconst fullscreen = ref(false)\nconst focused = ref(true)\nconst accentColor = ref<string | null>(null)\nlet users = 0\nlet unsubscribe: (() => void) | null = null\nlet unsubscribeAccent: (() => void) | null = null\nlet started: Promise<void> | null = null\n\nfunction apply(s: M3WindowState) {\n maximized.value = s.maximized\n fullscreen.value = s.fullscreen\n focused.value = s.focused\n}\n\nfunction start(b: M3Bridge) {\n if (!unsubscribe) unsubscribe = b.onState(apply)\n if (!unsubscribeAccent) unsubscribeAccent = b.onAccent?.((c) => { accentColor.value = c }) ?? null\n started ??= b.info().then((info) => {\n if (!info) return\n controls.value = info.controls\n platform.value = info.platform\n titleBarHeight.value = info.titleBarHeight\n accentColor.value = info.accentColor ?? null\n apply(info.state)\n ready.value = true\n }).catch(() => { started = null })\n}\n\nfunction stop() {\n unsubscribe?.()\n unsubscribe = null\n unsubscribeAccent?.()\n unsubscribeAccent = null\n}\n\nexport function useElectronWindow(): ElectronWindow {\n const b = bridge()\n if (b) {\n users++\n start(b)\n if (getCurrentScope()) onScopeDispose(() => { if (--users === 0) stop() })\n }\n return {\n isElectron: !!b,\n ready: readonly(ready),\n controls: readonly(controls),\n platform: readonly(platform),\n isMac: computed(() => platform.value === 'darwin'),\n titleBarHeight: readonly(titleBarHeight),\n maximized: readonly(maximized),\n fullscreen: readonly(fullscreen),\n focused: readonly(focused),\n accentColor: readonly(accentColor),\n minimize: () => b?.action('minimize'),\n toggleMaximize: () => b?.action('toggle-maximize'),\n close: () => b?.action('close'),\n setOverlay: (colors) => b?.setOverlay(colors),\n setTheme: (theme) => b?.setTheme?.(theme),\n setProgress: (value) => b?.setProgress?.(value),\n setBadge: (count) => b?.setBadge?.(count),\n requestAttention: () => b?.attention?.(),\n }\n}\n\n/** For tests: forget the fetched state */\nexport function _resetElectronWindow() {\n stop()\n users = 0\n started = null\n ready.value = false\n controls.value = 'native'\n platform.value = ''\n titleBarHeight.value = DEFAULT_TITLE_BAR_HEIGHT\n maximized.value = false\n fullscreen.value = false\n focused.value = true\n accentColor.value = null\n}\n","<script setup lang=\"ts\">\n/**\n * MTitleBar — the window's title bar for an Electron app, in M3: drags the window, double-click maximizes, and holds\n * the title plus anything you put at its start or end. The controls mode comes from the main process\n * (`m3WindowOptions({ controls })`), not a prop, so the two can't disagree:\n * - `native`: the system draws the buttons over the bar (Windows 11 snap layouts, macOS traffic lights) and the bar\n * leaves their room free; their colors follow the bar's background and the theme live, palette changes included.\n * - `custom`: a frameless window; the bar draws M3 buttons (or traffic lights), on the side and with the buttons\n * you choose, or your own through `#controls`.\n * Outside Electron it renders as a plain bar without buttons, so the same app runs in a browser.\n *\n * @slot default The title (replaces `title`)\n * @slot start Content after the icon and the menus (a back button, a breadcrumb…)\n * @slot end Content before the trailing controls (a search field, account button…)\n * @slot controls Replaces the custom controls (`{ minimize, toggleMaximize, close, maximized, focused }`)\n * @slot icon Replaces the app icon\n * @event menu-select Emitted with the menu item chosen (and its menu's index), as MMenuBar's `select`\n */\nimport { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { MIcon, MMenuBar, useLocale, useTheme, type MenuBarItem, type MenuBarMenu } from '@m3ui-vue/m3ui-vue'\nimport { useElectronWindow } from './useElectronWindow'\n\ntype Button = 'minimize' | 'maximize' | 'close'\n\nconst props = withDefaults(\n defineProps<{\n /** The window title */\n title?: string\n /**\n * The app icon at the start: an image URL (`'/icon.png'`, an import, a data: URL) or a Material Symbol name.\n * Clicking it does nothing (the `#icon` slot takes a button of yours)\n */\n icon?: string\n /** Menus (File, Edit…) after the icon, as an MMenuBar: items with submenus, dividers, checks, shortcut hints */\n menus?: MenuBarMenu[]\n /** `inline`: the menus sit in the title bar, after the icon. `below`: in a row of their own under it (classic) */\n menusPosition?: 'inline' | 'below'\n /**\n * Like VS Code's \"menu bar visibility\": `visible`; `compact`, one ☰ button in the bar holding every menu;\n * `toggle`, hidden until Alt is pressed (and hidden again after a pick, Esc or a click elsewhere); `hidden`\n */\n menusVisibility?: 'visible' | 'compact' | 'toggle' | 'hidden'\n /** Bar color: an M3 role (`'surface-container'`) or any CSS color */\n color?: string\n /** Where the title sits */\n titleAlign?: 'start' | 'center'\n /** Custom controls only: which buttons, in this order on the end side (mirrored on the start side) */\n buttons?: Button[]\n /** Custom controls only: the side they sit on; `auto` is the start on macOS, the end elsewhere */\n side?: 'auto' | 'start' | 'end'\n /** Custom controls only: M3 icon buttons or macOS-style traffic lights; `auto` picks by platform */\n look?: 'auto' | 'm3' | 'traffic-lights'\n /**\n * Keep the native UI's theme (dialogs, context menus, scrollbars, macOS's frame) on the app's `useTheme()`\n * choice: light, dark or system\n */\n syncNativeTheme?: boolean\n }>(),\n { color: 'surface', titleAlign: 'start', buttons: () => ['minimize', 'maximize', 'close'], side: 'auto', look: 'auto', syncNativeTheme: true, menusPosition: 'inline', menusVisibility: 'visible' },\n)\n\nconst emit = defineEmits<{ 'menu-select': [item: MenuBarItem, menu: number] }>()\n\nconst locale = useLocale()\n// ── Menus ─────────────────────────────────────────────────────────────────────────────────────────────────────\nconst revealed = ref(false) // toggle mode: shown by Alt\nconst shownMenus = computed<MenuBarMenu[]>(() => {\n const menus = props.menus ?? []\n if (!menus.length || props.menusVisibility === 'hidden') return []\n if (props.menusVisibility === 'toggle' && !revealed.value) return []\n if (props.menusVisibility === 'compact') {\n return [{ label: locale.appMenuLabel, icon: 'menu', items: menus.map((m) => ({ label: m.label, disabled: m.disabled, children: m.items })) }]\n }\n return menus\n})\n// The ☰ button always sits in the bar; a row below for it alone would waste a row\nconst menusBelow = computed(() => props.menusPosition === 'below' && props.menusVisibility !== 'compact')\n\nconst contains = (items: MenuBarItem[], item: MenuBarItem): boolean => items.some((i) => i === item || (!!i.children && contains(i.children, item)))\nfunction onMenuSelect(item: MenuBarItem) {\n // The index in `menus`, also from the compact button (where MMenuBar only sees one menu)\n emit('menu-select', item, Math.max(0, (props.menus ?? []).findIndex((m) => contains(m.items, item))))\n if (props.menusVisibility === 'toggle') revealed.value = false\n}\n\n// Alt pressed and released alone shows the menus and focuses the first one, as on Windows and Linux\nlet altAlone = false\nfunction onKeydown(e: KeyboardEvent) {\n altAlone = e.key === 'Alt' && !e.repeat && !e.ctrlKey && !e.shiftKey && !e.metaKey\n}\nfunction onKeyup(e: KeyboardEvent) {\n if (e.key !== 'Alt' || !altAlone || props.menusVisibility !== 'toggle' || !props.menus?.length) return\n altAlone = false\n e.preventDefault()\n revealed.value = !revealed.value\n if (revealed.value) void nextTick(() => bar.value?.querySelector<HTMLElement>('.m3-menu-bar [role=\"menuitem\"]')?.focus())\n}\n// Hidden again once nothing in it is open or focused (a click elsewhere, Esc on a title, Tab away)\nfunction hideLater() {\n if (!revealed.value) return\n setTimeout(() => {\n const menubar = bar.value?.querySelector('.m3-menu-bar')\n if (!menubar) return\n if (menubar.querySelector('[aria-expanded=\"true\"]') || menubar.contains(document.activeElement)) return\n revealed.value = false\n }, 0)\n}\nfunction onBarKeydown(e: KeyboardEvent) {\n if (e.key !== 'Escape' || !revealed.value) return\n const t = e.target as Element\n if (t.closest('.m3-menu-bar') && t.getAttribute('aria-expanded') !== 'true') revealed.value = false\n}\nwatch(() => props.menusVisibility, () => { revealed.value = false })\nonMounted(() => {\n window.addEventListener('keydown', onKeydown, true)\n window.addEventListener('keyup', onKeyup, true)\n document.addEventListener('pointerdown', hideLater, true)\n document.addEventListener('focusin', hideLater)\n})\nonBeforeUnmount(() => {\n window.removeEventListener('keydown', onKeydown, true)\n window.removeEventListener('keyup', onKeyup, true)\n document.removeEventListener('pointerdown', hideLater, true)\n document.removeEventListener('focusin', hideLater)\n})\n\n// An image when it looks like one (a path, a URL, a file name), a Material Symbol otherwise\nconst iconIsImage = computed(() => !!props.icon && /[/.:]/.test(props.icon))\nconst win = useElectronWindow()\nconst { controls, maximized, focused, fullscreen, isMac, titleBarHeight } = win\n\nconst ROLE = /^[a-z]+(-[a-z]+)*$/\nconst background = computed(() => (ROLE.test(props.color) ? `var(--color-${props.color})` : props.color))\nconst custom = computed(() => win.isElectron && controls.value === 'custom')\nconst native = computed(() => win.isElectron && controls.value === 'native')\nconst atStart = computed(() => (props.side === 'auto' ? isMac.value : props.side === 'start'))\nconst lights = computed(() => (props.look === 'auto' ? isMac.value : props.look === 'traffic-lights'))\nconst order = computed<Button[]>(() => {\n const set = props.buttons.filter((b, i, a) => a.indexOf(b) === i)\n // Traffic lights always read close, minimize, maximize; M3 buttons put close at the outer edge\n if (lights.value) return (['close', 'minimize', 'maximize'] as Button[]).filter((b) => set.includes(b))\n return atStart.value ? [...set].reverse() : set\n})\nconst maximizeLabel = computed(() => (maximized.value || fullscreen.value ? locale.windowRestore : locale.windowMaximize))\nconst labels = computed<Record<Button, string>>(() => ({ minimize: locale.windowMinimize, maximize: maximizeLabel.value, close: locale.close }))\nconst run = (b: Button) => (b === 'minimize' ? win.minimize() : b === 'maximize' ? win.toggleMaximize() : win.close())\n\n// Double-click on the bar itself (not on its content) maximizes, as on every desktop. Native title bars do it on\n// their own over the drag region; frameless ones on Linux don't\nfunction onDblclick(e: MouseEvent) {\n if (!custom.value) return\n if ((e.target as Element).closest('button, a, input, select, textarea, [role=\"button\"], [data-no-drag]')) return\n win.toggleMaximize()\n}\n\n// ── Native buttons follow the theme ────────────────────────────────────────────────────────────────────────────\n// They aren't CSS, so on every theme or palette change (and while its transition runs, ~300ms) the bar's computed\n// colors are sent each frame; main skips the ones that didn't change. macOS's traffic lights have fixed colors.\nconst bar = ref<HTMLElement>()\nconst probe = ref<HTMLElement>()\nlet raf = 0\nlet until = 0\nlet observer: MutationObserver | null = null\nlet media: MediaQueryList | null = null\n\nfunction toHex(css: string, under?: [number, number, number]): string | null {\n const m = /rgba?\\(\\s*([\\d.]+)[\\s,]+([\\d.]+)[\\s,]+([\\d.]+)(?:[\\s,/]+([\\d.]+%?))?/.exec(css)\n if (!m) return null\n let a = m[4] == null ? 1 : m[4].endsWith('%') ? parseFloat(m[4]) / 100 : parseFloat(m[4])\n const c = [+m[1]!, +m[2]!, +m[3]!]\n // A see-through bar: blend it over what's under it (the page), since the overlay can't be translucent\n if (a < 1 && under) c.forEach((v, i) => (c[i] = v * a + under[i]! * (1 - a)))\n else a = 1\n return `#${c.map((v) => Math.round(Math.min(255, Math.max(0, v))).toString(16).padStart(2, '0')).join('')}`\n}\n\nfunction pageColor(): [number, number, number] {\n const hex = toHex(getComputedStyle(document.body).backgroundColor) ?? toHex(getComputedStyle(document.documentElement).backgroundColor) ?? '#ffffff'\n return [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16)) as [number, number, number]\n}\n\nfunction sendOverlay() {\n if (!bar.value || !probe.value) return\n const color = toHex(getComputedStyle(bar.value).backgroundColor, pageColor())\n const symbolColor = toHex(getComputedStyle(probe.value).color)\n if (color && symbolColor) win.setOverlay({ color, symbolColor })\n}\n\nfunction follow(ms = 600) {\n if (!native.value || isMac.value) return\n until = performance.now() + ms\n if (raf) return\n const step = () => {\n sendOverlay()\n raf = performance.now() < until ? requestAnimationFrame(step) : 0\n }\n step()\n}\nconst onScheme = () => follow()\n\nfunction startSync() {\n if (observer || !native.value || isMac.value) return\n follow()\n observer = new MutationObserver(() => follow())\n observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style', 'data-palette', 'data-theme'] })\n media = window.matchMedia?.('(prefers-color-scheme: dark)') ?? null\n media?.addEventListener?.('change', onScheme)\n}\n\nfunction stopSync() {\n observer?.disconnect()\n observer = null\n media?.removeEventListener?.('change', onScheme)\n media = null\n cancelAnimationFrame(raf)\n raf = 0\n}\n\nonMounted(() => { if (win.ready.value) startSync() })\nwatch([win.ready, native, isMac], () => { stopSync(); if (win.ready.value) startSync() })\nwatch(() => props.color, () => follow())\n\nconst { theme } = useTheme()\nwatch([theme, () => props.syncNativeTheme, win.ready], () => {\n if (props.syncNativeTheme && win.ready.value) win.setTheme(theme.value)\n}, { immediate: true })\nonBeforeUnmount(stopSync)\n</script>\n\n<template>\n <header\n ref=\"bar\"\n class=\"m3-title-bar\"\n :class=\"{ 'm3-title-bar-native': native, 'm3-title-bar-blurred': !focused, 'm3-title-bar-center': titleAlign === 'center' }\"\n :style=\"{ background }\"\n :data-controls=\"win.isElectron ? controls : undefined\"\n >\n <span ref=\"probe\" class=\"m3-title-bar-probe\" aria-hidden=\"true\" />\n <div class=\"m3-title-bar-row\" :style=\"{ height: `${titleBarHeight}px` }\" @dblclick=\"onDblclick\">\n <div class=\"m3-title-bar-area\">\n <div v-if=\"icon || $slots.icon\" class=\"m3-title-bar-icon\">\n <slot name=\"icon\">\n <img v-if=\"iconIsImage\" :src=\"icon\" alt=\"\" draggable=\"false\" />\n <MIcon v-else :name=\"icon!\" :size=\"20\" />\n </slot>\n </div>\n <MMenuBar v-if=\"shownMenus.length && !menusBelow\" :menus=\"shownMenus\" :height=\"Math.min(32, titleBarHeight - 8)\" class=\"m3-title-bar-menus\" @select=\"onMenuSelect\" @keydown=\"onBarKeydown\" />\n <div class=\"m3-title-bar-start\"><slot name=\"start\" /></div>\n <div class=\"m3-title-bar-title\"><span class=\"m3-title-bar-text\"><slot>{{ title }}</slot></span></div>\n <div class=\"m3-title-bar-end\"><slot name=\"end\" /></div>\n\n <!-- One set of controls (yours or ours); on the start side it moves first with `order` -->\n <div v-if=\"custom\" class=\"m3-title-bar-side\" :class=\"atStart && 'm3-title-bar-controls-start'\">\n <slot name=\"controls\" v-bind=\"{ minimize: win.minimize, toggleMaximize: win.toggleMaximize, close: win.close, maximized, focused }\">\n <div class=\"m3-title-bar-controls\" :class=\"lights && 'm3-title-bar-lights'\">\n <button\n v-for=\"b in order\"\n :key=\"b\"\n type=\"button\"\n :class=\"['m3-title-bar-btn', `m3-title-bar-btn-${b}`]\"\n :aria-label=\"labels[b]\"\n :title=\"labels[b]\"\n @click=\"run(b)\"\n >\n <MIcon v-if=\"!lights\" :name=\"b === 'minimize' ? 'minimize' : b === 'close' ? 'close' : maximized || fullscreen ? 'close_fullscreen' : 'open_in_full'\" :size=\"b === 'maximize' ? 16 : 18\" />\n <svg v-else viewBox=\"0 0 12 12\" aria-hidden=\"true\">\n <path v-if=\"b === 'close'\" d=\"M3.5 3.5l5 5M8.5 3.5l-5 5\" />\n <path v-else-if=\"b === 'minimize'\" d=\"M3 6h6\" />\n <path v-else d=\"M6 3v6M3 6h6\" />\n </svg>\n </button>\n </div>\n </slot>\n </div>\n </div>\n </div>\n <!-- The classic menu row: not a drag area, like every app's -->\n <div v-if=\"shownMenus.length && menusBelow\" class=\"m3-title-bar-menu-row\">\n <MMenuBar :menus=\"shownMenus\" :height=\"32\" @select=\"onMenuSelect\" @keydown=\"onBarKeydown\" />\n </div>\n </header>\n</template>\n\n<style>\n/* Plain CSS on the M3 tokens: the lib's Tailwind build doesn't scan this package, so no utility classes here */\n@layer base {\n .m3-title-bar {\n position: relative;\n display: block;\n flex-shrink: 0;\n width: 100%;\n color: var(--color-on-surface);\n user-select: none;\n -webkit-user-select: none;\n app-region: drag;\n -webkit-app-region: drag;\n }\n}\n.m3-title-bar :is(button, a, input, select, textarea, [role='button'], [contenteditable], [data-no-drag]) {\n app-region: no-drag;\n -webkit-app-region: no-drag;\n}\n.m3-title-bar-row {\n position: relative;\n}\n.m3-title-bar-menu-row {\n display: flex;\n align-items: center;\n padding: 0 8px 4px;\n app-region: no-drag;\n -webkit-app-region: no-drag;\n}\n.m3-title-bar-area {\n display: flex;\n align-items: center;\n gap: 8px;\n height: 100%;\n padding-inline: 8px;\n box-sizing: border-box;\n}\n/* The system's buttons sit over the bar: keep to the area Window Controls Overlay leaves free */\n.m3-title-bar-native .m3-title-bar-area {\n /* not positioned, so a centered title centers on the whole row, not on this area */\n margin-left: env(titlebar-area-x, 0px);\n width: env(titlebar-area-width, 100%);\n}\n.m3-title-bar-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n width: 28px;\n color: var(--color-primary);\n}\n.m3-title-bar-icon img {\n width: 20px;\n height: 20px;\n object-fit: contain;\n pointer-events: none;\n}\n.m3-title-bar-menus {\n flex-shrink: 0;\n}\n.m3-title-bar-start,\n.m3-title-bar-end {\n display: flex;\n align-items: center;\n gap: 4px;\n min-width: 0;\n}\n.m3-title-bar-start:empty,\n.m3-title-bar-end:empty {\n display: none;\n}\n.m3-title-bar-title {\n flex: 1;\n min-width: 0;\n overflow: hidden;\n padding-inline: 4px;\n white-space: nowrap;\n text-overflow: ellipsis;\n font-size: var(--text-title-small, 0.875rem);\n line-height: var(--text-title-small--line-height, 1.25rem);\n font-weight: 500;\n letter-spacing: 0.006em;\n transition: color 150ms;\n}\n/* Centered on the whole bar, not on the room the menus and controls leave; the empty title box still takes that\n room so the end content stays at the end */\n.m3-title-bar-center .m3-title-bar-text {\n position: absolute;\n inset-inline-start: 50%;\n top: 50%;\n max-width: 40%;\n overflow: hidden;\n text-overflow: ellipsis;\n transform: translate(calc(-50% * var(--m3-dir, 1)), -50%);\n pointer-events: none;\n}\n.m3-title-bar-blurred .m3-title-bar-title {\n color: var(--color-on-surface-variant);\n}\n/* What the native buttons' symbols are colored from */\n.m3-title-bar-probe {\n position: absolute;\n width: 0;\n height: 0;\n overflow: hidden;\n color: var(--color-on-surface-variant);\n}\n\n.m3-title-bar-side {\n display: flex;\n flex-shrink: 0;\n}\n.m3-title-bar-controls-start {\n order: -1;\n}\n.m3-title-bar-controls {\n display: flex;\n align-items: center;\n gap: 4px;\n flex-shrink: 0;\n}\n.m3-title-bar-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 32px;\n height: 32px;\n padding: 0;\n border: 0;\n border-radius: 9999px;\n background: transparent;\n color: var(--color-on-surface-variant);\n cursor: default;\n outline: none;\n transition: background-color 150ms, color 150ms;\n}\n.m3-title-bar-btn:hover {\n background-color: color-mix(in srgb, var(--color-on-surface-variant) 8%, transparent);\n}\n.m3-title-bar-btn:active {\n background-color: color-mix(in srgb, var(--color-on-surface-variant) 10%, transparent);\n}\n.m3-title-bar-btn:focus-visible {\n box-shadow: 0 0 0 2px var(--color-secondary);\n}\n.m3-title-bar-btn-close:hover {\n color: var(--color-error);\n background-color: color-mix(in srgb, var(--color-error) 8%, transparent);\n}\n.m3-title-bar-btn-close:active {\n background-color: color-mix(in srgb, var(--color-error) 10%, transparent);\n}\n\n/* Traffic lights: 12px dots 8px apart, glyphs on hover of the group, gray when the window is in the background */\n.m3-title-bar-lights {\n gap: 8px;\n padding-inline: 6px;\n}\n.m3-title-bar-lights .m3-title-bar-btn {\n width: 12px;\n height: 12px;\n color: rgb(0 0 0 / 0.55);\n box-shadow: inset 0 0 0 0.5px rgb(0 0 0 / 0.18);\n}\n.m3-title-bar-lights .m3-title-bar-btn svg {\n width: 8px;\n height: 8px;\n fill: none;\n stroke: currentColor;\n stroke-width: 1.4;\n stroke-linecap: round;\n opacity: 0;\n}\n.m3-title-bar-lights:hover .m3-title-bar-btn svg,\n.m3-title-bar-lights .m3-title-bar-btn:focus-visible svg {\n opacity: 1;\n}\n.m3-title-bar-lights .m3-title-bar-btn-close { background-color: #ff5f57; }\n.m3-title-bar-lights .m3-title-bar-btn-minimize { background-color: #febc2e; }\n.m3-title-bar-lights .m3-title-bar-btn-maximize { background-color: #28c840; }\n.m3-title-bar-lights .m3-title-bar-btn:hover,\n.m3-title-bar-lights .m3-title-bar-btn-close:hover { color: rgb(0 0 0 / 0.55); filter: brightness(0.94); }\n.m3-title-bar-blurred .m3-title-bar-lights:not(:hover) .m3-title-bar-btn {\n background-color: color-mix(in srgb, var(--color-on-surface) 20%, transparent);\n box-shadow: none;\n}\n</style>\n"],"mappings":";;;;AA2CA,SAAS+C,IAA+B;CACtC,OAAO,OAAO,SAAW,MAAe,OAA2DD,KAAc,KAAA;AACnH;AAGA,IAAME,IAAQZ,EAAI,EAAK,GACjBa,IAAWb,EAAgB,QAAQ,GACnCc,IAAWd,EAAI,EAAE,GACjBe,IAAiBf,EAAA,EAA4B,GAC7CgB,IAAYhB,EAAI,EAAK,GACrBiB,IAAajB,EAAI,EAAK,GACtBkB,IAAUl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MAAMU,MAAC,aAAA,KAAA;;;GAa7J8B,EAAA,MAAW,UAAUG,EAAA,SAAhC/F,EAAA,GAAAC,EAEM,OAFNmF,IAEM,CADJtE,GAA4FX,EAAAuC,CAAA,GAAA;IAAjF,OAAOkD,EAAA;IAAa,QAAQ;IAAK,UAAQQ;IAAe,WAASO"}
package/dist/main.cjs ADDED
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("node:fs"),t=require("node:path"),n=require("electron");const r=require("./shared-BLenUWPr.cjs");var i={color:`#fef7ff`,symbolColor:`#49454f`};function a(e={}){return{controls:e.controls===`custom`?`custom`:`native`,titleBarHeight:Math.max(24,Math.round(e.titleBarHeight??40)),overlay:{...i,...e.overlay},bounds:e.rememberBounds?`m3-window${typeof e.rememberBounds==`string`?`-${e.rememberBounds.replace(/[^\w-]/g,`_`)}`:``}.json`:null,externalLinks:e.externalLinks!==!1}}var o=e=>(0,t.join)(n.app.getPath(`userData`),e);function s(t){try{let n=JSON.parse((0,e.readFileSync)(o(t),`utf8`));return[n.x,n.y,n.width,n.height].every(Number.isFinite)?n:null}catch{return null}}function c(e){let t=s(e);return t?n.screen.getAllDisplays().some(({workArea:e})=>Math.min(t.x+t.width,e.x+e.width)-Math.max(t.x,e.x)>=100&&Math.min(t.y+40,e.y+e.height)-Math.max(t.y,e.y)>=20)?t:{width:t.width,height:t.height,maximized:t.maximized}:{}}var l=new Map,u=!1,d=()=>{try{let e=process.platform===`win32`||process.platform===`darwin`?n.systemPreferences.getAccentColor():``;return/^[0-9a-f]{6}/i.test(e)?`#${e.slice(0,6).toLowerCase()}`:null}catch{return null}},f=e=>({maximized:e.isMaximized(),fullscreen:e.isFullScreen(),focused:e.isFocused()});function p(e){return l.get(e.id)}function m(){u||(u=!0,n.ipcMain.handle(r.n.info,e=>{let t=p(e.sender);return t?{controls:t.o.controls,platform:process.platform,titleBarHeight:t.o.titleBarHeight,state:f(t.win),accentColor:d()}:null}),n.ipcMain.on(r.n.action,(e,t)=>{let n=p(e.sender);n&&!n.win.isDestroyed()&&(t===`minimize`?n.win.minimize():t===`toggle-maximize`?n.win.isFullScreen()?n.win.setFullScreen(!1):n.win.isMaximized()?n.win.unmaximize():n.win.maximize():t===`close`&&n.win.close())}),n.ipcMain.on(r.n.overlay,(e,t)=>{let n=p(e.sender);if(!n||n.win.isDestroyed()||n.o.controls!==`native`||process.platform===`darwin`||!g(t?.color)||!g(t?.symbolColor))return;let r=`${t.color}|${t.symbolColor}`;r!==n.overlay&&(n.overlay=r,n.win.setTitleBarOverlay({color:t.color,symbolColor:t.symbolColor,height:n.o.titleBarHeight}))}),n.ipcMain.on(r.n.theme,(e,t)=>{p(e.sender)&&[`light`,`dark`,`system`].includes(t)&&n.nativeTheme.themeSource!==t&&(n.nativeTheme.themeSource=t)}),n.ipcMain.on(r.n.progress,(e,t)=>{let n=p(e.sender);n&&!n.win.isDestroyed()&&(t===`indeterminate`?n.win.setProgressBar(2,{mode:`indeterminate`}):typeof t==`number`&&Number.isFinite(t)?n.win.setProgressBar(Math.min(1,Math.max(0,t))):n.win.setProgressBar(-1))}),n.ipcMain.on(r.n.badge,(e,t)=>{p(e.sender)&&n.app.setBadgeCount(Math.max(0,Math.floor(Number(t)||0)))}),n.ipcMain.on(r.n.attention,e=>{let t=p(e.sender);!t||t.win.isDestroyed()||t.win.isFocused()||(process.platform===`darwin`?n.app.dock?.bounce(`informational`):(t.win.flashFrame(!0),t.win.once(`focus`,()=>{t.win.isDestroyed()||t.win.flashFrame(!1)})))}),n.systemPreferences.on?.(`accent-color-changed`,()=>{for(let{win:e}of l.values())e.isDestroyed()||e.webContents.send(r.n.accent,d())}))}var h=/^(https?|mailto):/i,g=e=>typeof e==`string`&&/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(e);exports.m3WindowOptions=function(e={}){let t=a(e),n={};if(t.bounds){let{x:e,y:r,width:i,height:a}=c(t.bounds);n={...i?{width:i,height:a}:{},...e==null?{}:{x:e,y:r}}}if(t.controls===`custom`)return{...n,frame:!1};let r=process.platform===`darwin`;return{...n,titleBarStyle:`hidden`,titleBarOverlay:r?!0:{...t.overlay,height:t.titleBarHeight},...r?{trafficLightPosition:{x:14,y:Math.round((t.titleBarHeight-16)/2)}}:{}}},exports.setupM3Window=function(t,i={}){m();let c=a(i),u=t.webContents.id;l.set(u,{win:t,o:c,overlay:``});let d=()=>{t.isDestroyed()||t.webContents.send(r.n.state,f(t))},p=[`maximize`,`unmaximize`,`enter-full-screen`,`leave-full-screen`,`focus`,`blur`,`restore`];for(let e of p)t.on(e,d);let g=()=>{},_,v=()=>{clearTimeout(_),_=setTimeout(g,400)};if(c.bounds){let n=c.bounds;s(n)?.maximized&&t.maximize(),g=()=>{if(!(t.isDestroyed()||t.isMinimized()||t.isFullScreen()))try{(0,e.writeFileSync)(o(n),JSON.stringify({...t.getNormalBounds(),maximized:t.isMaximized()}))}catch{}};for(let e of[`resize`,`move`,`maximize`,`unmaximize`])t.on(e,v);t.on(`close`,()=>{clearTimeout(_),g()})}return c.externalLinks&&(t.webContents.setWindowOpenHandler(({url:e})=>(h.test(e)&&n.shell.openExternal(e),{action:`deny`})),t.webContents.on(`will-navigate`,(e,r)=>{let i=t.webContents.getURL(),a=!1;try{a=new URL(r).origin!==new URL(i).origin}catch{}h.test(r)&&a&&(e.preventDefault(),n.shell.openExternal(r))})),t.once(`closed`,()=>{l.delete(u),clearTimeout(_)}),()=>{if(l.delete(u),clearTimeout(_),!t.isDestroyed()){for(let e of p)t.off(e,d);for(let e of[`resize`,`move`,`maximize`,`unmaximize`])t.off(e,v)}}};
2
+ //# sourceMappingURL=main.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.cjs","names":["join","app","readFileSync","screen","systemPreferences","ipcMain","IPC","nativeTheme","writeFileSync","shell","node_fs","node_path","electron","require_shared","BASELINE","resolve","o","boundsFile","name","readBounds","b","restoredBounds","a","windows","registered","accent","c","stateOf","win","entry","sender","register","w","action","colors","isHex","key","theme","value","count","EXTERNAL","options","saved","x","y","width","height","mac","id","send","events","ev","save","timer","later","url","here","other"],"sources":["../src/main.ts"],"sourcesContent":["/**\n * `@m3ui-vue/electron/main`: the main-process half. `m3WindowOptions()` gives the BrowserWindow options for the mode\n * you pick, `setupM3Window()` wires that window to MTitleBar (its state, its buttons, the native overlay's colors) and\n * to `useElectronWindow()` (native theme, accent color, taskbar progress and badge, attention), remembers its bounds\n * and sends outside links to the browser.\n *\n * ```ts\n * const m3 = { controls: 'native' } as const\n * const win = new BrowserWindow({ width: 1100, height: 720, ...m3WindowOptions(m3), webPreferences: { preload } })\n * setupM3Window(win, m3)\n * ```\n */\nimport { readFileSync, writeFileSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { app, BrowserWindow, ipcMain, nativeTheme, screen, shell, systemPreferences, type BrowserWindowConstructorOptions, type IpcMainEvent, type IpcMainInvokeEvent, type Rectangle, type WebContents } from 'electron'\nimport { DEFAULT_TITLE_BAR_HEIGHT, IPC, type M3Controls, type M3NativeTheme, type M3OverlayColors, type M3WindowAction, type M3WindowInfo, type M3WindowState } from './shared'\n\nexport type { M3Controls, M3NativeTheme, M3OverlayColors, M3WindowAction, M3WindowInfo, M3WindowState } from './shared'\n\nexport interface M3WindowOptions {\n /** `'native'` (default): the system's buttons, recolored from the theme. `'custom'`: frameless, MTitleBar draws them */\n controls?: M3Controls\n /** Title bar height in px (default 40) */\n titleBarHeight?: number\n /**\n * The native buttons' colors before the page has loaded (MTitleBar sends the real ones from the theme as soon as\n * it mounts). Defaults to the M3 baseline light surface\n */\n overlay?: Partial<M3OverlayColors>\n /**\n * Reopen the window with the size, position and maximized state it closed with (kept in the app's userData\n * folder). `true`, or a name per window when the app has several. Spread `m3WindowOptions()` after your own\n * width/height so the remembered ones win\n */\n rememberBounds?: boolean | string\n /**\n * Open http(s) and mailto links that would leave the app (`target=\"_blank\"`, `window.open`, a link to another\n * site) in the system browser instead of a new Electron window. Default true\n */\n externalLinks?: boolean\n}\n\ninterface Resolved {\n controls: M3Controls\n titleBarHeight: number\n overlay: M3OverlayColors\n bounds: string | null\n externalLinks: boolean\n}\n\nconst BASELINE: M3OverlayColors = { color: '#fef7ff', symbolColor: '#49454f' }\n\nfunction resolve(o: M3WindowOptions = {}): Resolved {\n return {\n controls: o.controls === 'custom' ? 'custom' : 'native',\n titleBarHeight: Math.max(24, Math.round(o.titleBarHeight ?? DEFAULT_TITLE_BAR_HEIGHT)),\n overlay: { ...BASELINE, ...o.overlay },\n bounds: o.rememberBounds ? `m3-window${typeof o.rememberBounds === 'string' ? `-${o.rememberBounds.replace(/[^\\w-]/g, '_')}` : ''}.json` : null,\n externalLinks: o.externalLinks !== false,\n }\n}\n\n// ── Remembered bounds ───────────────────────────────────────────────────────────────────────────────────────────\ninterface Saved extends Rectangle { maximized: boolean }\nconst boundsFile = (name: string) => join(app.getPath('userData'), name)\n\nfunction readBounds(name: string): Saved | null {\n try {\n const b = JSON.parse(readFileSync(boundsFile(name), 'utf8')) as Saved\n if (![b.x, b.y, b.width, b.height].every(Number.isFinite)) return null\n return b\n } catch {\n return null\n }\n}\n\n/** The saved bounds, without the position when no screen shows enough of the window anymore (a monitor unplugged) */\nfunction restoredBounds(name: string): Partial<Rectangle> & { maximized?: boolean } {\n const b = readBounds(name)\n if (!b) return {}\n const visible = screen.getAllDisplays().some(({ workArea: a }) =>\n Math.min(b.x + b.width, a.x + a.width) - Math.max(b.x, a.x) >= 100 && Math.min(b.y + 40, a.y + a.height) - Math.max(b.y, a.y) >= 20)\n return visible ? b : { width: b.width, height: b.height, maximized: b.maximized }\n}\n\n/** The BrowserWindow options for a mode: spread them into `new BrowserWindow({ ... })` */\nexport function m3WindowOptions(options: M3WindowOptions = {}): BrowserWindowConstructorOptions {\n const o = resolve(options)\n let saved: BrowserWindowConstructorOptions = {}\n if (o.bounds) {\n const { x, y, width, height } = restoredBounds(o.bounds)\n saved = { ...(width ? { width, height } : {}), ...(x != null ? { x, y } : {}) }\n }\n if (o.controls === 'custom') return { ...saved, frame: false }\n const mac = process.platform === 'darwin'\n return {\n ...saved,\n titleBarStyle: 'hidden',\n // macOS keeps its traffic lights (`true` only turns on the overlay's CSS env() area); elsewhere the system's\n // buttons are drawn over the page in these colors, at the bar's height\n titleBarOverlay: mac ? true : { ...o.overlay, height: o.titleBarHeight },\n // Traffic lights (12px, 20px apart) centered in the bar\n ...(mac ? { trafficLightPosition: { x: 14, y: Math.round((o.titleBarHeight - 16) / 2) } } : {}),\n }\n}\n\n// One handler per channel for the whole app; each message finds its window's settings by the sender\nconst windows = new Map<number, { win: BrowserWindow; o: Resolved; overlay: string }>()\nlet registered = false\n\nconst accent = (): string | null => {\n try {\n const c = process.platform === 'win32' || process.platform === 'darwin' ? systemPreferences.getAccentColor() : ''\n return /^[0-9a-f]{6}/i.test(c) ? `#${c.slice(0, 6).toLowerCase()}` : null\n } catch {\n return null\n }\n}\n\nconst stateOf = (win: BrowserWindow): M3WindowState => ({\n maximized: win.isMaximized(),\n fullscreen: win.isFullScreen(),\n focused: win.isFocused(),\n})\n\nfunction entry(sender: WebContents) {\n return windows.get(sender.id)\n}\n\nfunction register() {\n if (registered) return\n registered = true\n ipcMain.handle(IPC.info, (e: IpcMainInvokeEvent): M3WindowInfo | null => {\n const w = entry(e.sender)\n if (!w) return null\n return { controls: w.o.controls, platform: process.platform, titleBarHeight: w.o.titleBarHeight, state: stateOf(w.win), accentColor: accent() }\n })\n ipcMain.on(IPC.action, (e: IpcMainEvent, action: M3WindowAction) => {\n const w = entry(e.sender)\n if (!w || w.win.isDestroyed()) return\n if (action === 'minimize') w.win.minimize()\n else if (action === 'toggle-maximize') {\n if (w.win.isFullScreen()) w.win.setFullScreen(false)\n else if (w.win.isMaximized()) w.win.unmaximize()\n else w.win.maximize()\n } else if (action === 'close') w.win.close()\n })\n ipcMain.on(IPC.overlay, (e: IpcMainEvent, colors: M3OverlayColors) => {\n const w = entry(e.sender)\n if (!w || w.win.isDestroyed() || w.o.controls !== 'native' || process.platform === 'darwin') return\n if (!isHex(colors?.color) || !isHex(colors?.symbolColor)) return\n // The renderer sends every frame of a theme transition: skip what wouldn't change anything\n const key = `${colors.color}|${colors.symbolColor}`\n if (key === w.overlay) return\n w.overlay = key\n w.win.setTitleBarOverlay({ color: colors.color, symbolColor: colors.symbolColor, height: w.o.titleBarHeight })\n })\n // The app's theme choice drives the native UI too (dialogs, context menus, scrollbars, macOS's frame). The\n // choice, not the result: 'system' must stay 'system', or prefers-color-scheme would follow the app back\n ipcMain.on(IPC.theme, (e: IpcMainEvent, theme: M3NativeTheme) => {\n if (!entry(e.sender) || !['light', 'dark', 'system'].includes(theme)) return\n if (nativeTheme.themeSource !== theme) nativeTheme.themeSource = theme\n })\n ipcMain.on(IPC.progress, (e: IpcMainEvent, value: number | 'indeterminate' | null) => {\n const w = entry(e.sender)\n if (!w || w.win.isDestroyed()) return\n if (value === 'indeterminate') w.win.setProgressBar(2, { mode: 'indeterminate' })\n else if (typeof value === 'number' && Number.isFinite(value)) w.win.setProgressBar(Math.min(1, Math.max(0, value)))\n else w.win.setProgressBar(-1)\n })\n ipcMain.on(IPC.badge, (e: IpcMainEvent, count: number) => {\n if (!entry(e.sender)) return\n app.setBadgeCount(Math.max(0, Math.floor(Number(count) || 0)))\n })\n ipcMain.on(IPC.attention, (e: IpcMainEvent) => {\n const w = entry(e.sender)\n if (!w || w.win.isDestroyed() || w.win.isFocused()) return\n if (process.platform === 'darwin') app.dock?.bounce('informational')\n else {\n w.win.flashFrame(true)\n w.win.once('focus', () => { if (!w.win.isDestroyed()) w.win.flashFrame(false) })\n }\n })\n // Accent color changes (Windows sends them; macOS asks for a relaunch of most apps anyway)\n const sendAccent = () => { for (const { win } of windows.values()) if (!win.isDestroyed()) win.webContents.send(IPC.accent, accent()) }\n systemPreferences.on?.('accent-color-changed', sendAccent)\n}\n\nconst EXTERNAL = /^(https?|mailto):/i\n\nconst isHex = (c: unknown): c is string => typeof c === 'string' && /^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(c)\n\n/**\n * Connects `win` to MTitleBar: answers its questions, runs its buttons, sends it the window's state and recolors the\n * native buttons with the theme. Pass the same options as to `m3WindowOptions()`. Returns a function that undoes it\n * (it's undone on its own when the window closes).\n */\nexport function setupM3Window(win: BrowserWindow, options: M3WindowOptions = {}): () => void {\n register()\n const o = resolve(options)\n const id = win.webContents.id\n windows.set(id, { win, o, overlay: '' })\n const send = () => { if (!win.isDestroyed()) win.webContents.send(IPC.state, stateOf(win)) }\n const events = ['maximize', 'unmaximize', 'enter-full-screen', 'leave-full-screen', 'focus', 'blur', 'restore'] as const\n for (const ev of events) win.on(ev as 'maximize', send)\n\n // Bounds: the size it had before being maximized (getNormalBounds), saved after moves and resizes settle\n let save = () => {}\n let timer: ReturnType<typeof setTimeout> | undefined\n const later = () => { clearTimeout(timer); timer = setTimeout(save, 400) }\n if (o.bounds) {\n const name = o.bounds\n if (readBounds(name)?.maximized) win.maximize()\n save = () => {\n if (win.isDestroyed() || win.isMinimized() || win.isFullScreen()) return\n try {\n writeFileSync(boundsFile(name), JSON.stringify({ ...win.getNormalBounds(), maximized: win.isMaximized() }))\n } catch { /* a read-only profile: nothing to remember */ }\n }\n for (const ev of ['resize', 'move', 'maximize', 'unmaximize'] as const) win.on(ev as 'resize', later)\n win.on('close', () => { clearTimeout(timer); save() })\n }\n\n // Links that leave the app open in the browser\n if (o.externalLinks) {\n win.webContents.setWindowOpenHandler(({ url }) => {\n if (EXTERNAL.test(url)) void shell.openExternal(url)\n return { action: 'deny' }\n })\n win.webContents.on('will-navigate', (e, url) => {\n const here = win.webContents.getURL()\n let other = false\n try { other = new URL(url).origin !== new URL(here).origin } catch { /* about:blank and the like */ }\n if (EXTERNAL.test(url) && other) {\n e.preventDefault()\n void shell.openExternal(url)\n }\n })\n }\n\n const dispose = () => {\n windows.delete(id)\n clearTimeout(timer)\n if (!win.isDestroyed()) {\n for (const ev of events) win.off(ev as 'maximize', send)\n for (const ev of ['resize', 'move', 'maximize', 'unmaximize'] as const) win.off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D,CA4BA,OAzBIpC,EAAE,gBACJY,EAAI,YAAY,sBAAsB,CAAE2B,UAClCf,EAAS,KAAKe,CAAG,GAAQ9C,EAAAA,MAAM,aAAa8C,CAAG,EAC5C,CAAE,OAAQ,MAAO,EACzB,EACD3B,EAAI,YAAY,GAAG,iBAAkB,EAAG2B,IAAQ,CAC9C,IAAMC,EAAO5B,EAAI,YAAY,OAAO,EAChC6B,EAAQ,GACZ,GAAI,CAAEA,EAAQ,IAAI,IAAIF,CAAG,CAAC,CAAC,SAAW,IAAI,IAAIC,CAAI,CAAC,CAAC,MAAO,MAAQ,CAAiC,CAChGhB,EAAS,KAAKe,CAAG,GAAKE,IACxB,EAAE,eAAe,EACZhD,EAAAA,MAAM,aAAa8C,CAAG,EAE/B,CAAC,GAWH3B,EAAI,KAAK,aAAgB,CAAEL,EAAQ,OAAOyB,CAAE,EAAG,aAAaK,CAAK,CAAE,CAAC,MAR9C,CAGpB,GAFA9B,EAAQ,OAAOyB,CAAE,EACjB,aAAaK,CAAK,EACd,CAACzB,EAAI,YAAY,EAAG,CACtB,IAAK,IAAMuB,KAAMD,EAAQtB,EAAI,IAAIuB,EAAkBF,CAAI,EACvD,IAAK,IAAME,IAAM,CAAC,SAAU,OAAQ,WAAY,YAAY,EAAYvB,EAAI,IAAIuB,EAAgBG,CAAK,CACvG,CACF,CAGF"}
package/dist/main.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { BrowserWindow, type BrowserWindowConstructorOptions } from 'electron';
2
+ import { type M3Controls, type M3OverlayColors } from './shared';
3
+ export type { M3Controls, M3NativeTheme, M3OverlayColors, M3WindowAction, M3WindowInfo, M3WindowState } from './shared';
4
+ export interface M3WindowOptions {
5
+ /** `'native'` (default): the system's buttons, recolored from the theme. `'custom'`: frameless, MTitleBar draws them */
6
+ controls?: M3Controls;
7
+ /** Title bar height in px (default 40) */
8
+ titleBarHeight?: number;
9
+ /**
10
+ * The native buttons' colors before the page has loaded (MTitleBar sends the real ones from the theme as soon as
11
+ * it mounts). Defaults to the M3 baseline light surface
12
+ */
13
+ overlay?: Partial<M3OverlayColors>;
14
+ /**
15
+ * Reopen the window with the size, position and maximized state it closed with (kept in the app's userData
16
+ * folder). `true`, or a name per window when the app has several. Spread `m3WindowOptions()` after your own
17
+ * width/height so the remembered ones win
18
+ */
19
+ rememberBounds?: boolean | string;
20
+ /**
21
+ * Open http(s) and mailto links that would leave the app (`target="_blank"`, `window.open`, a link to another
22
+ * site) in the system browser instead of a new Electron window. Default true
23
+ */
24
+ externalLinks?: boolean;
25
+ }
26
+ /** The BrowserWindow options for a mode: spread them into `new BrowserWindow({ ... })` */
27
+ export declare function m3WindowOptions(options?: M3WindowOptions): BrowserWindowConstructorOptions;
28
+ /**
29
+ * Connects `win` to MTitleBar: answers its questions, runs its buttons, sends it the window's state and recolors the
30
+ * native buttons with the theme. Pass the same options as to `m3WindowOptions()`. Returns a function that undoes it
31
+ * (it's undone on its own when the window closes).
32
+ */
33
+ export declare function setupM3Window(win: BrowserWindow, options?: M3WindowOptions): () => void;
package/dist/main.js ADDED
@@ -0,0 +1,200 @@
1
+ import { readFileSync as e, writeFileSync as t } from "node:fs";
2
+ import { join as n } from "node:path";
3
+ import { app as r, ipcMain as i, nativeTheme as a, screen as o, shell as s, systemPreferences as c } from "electron";
4
+ import { n as l } from "./shared-OD5t8cpt.js";
5
+ // src/main.ts
6
+ var u = {
7
+ color: "#fef7ff",
8
+ symbolColor: "#49454f"
9
+ };
10
+ function d(e = {}) {
11
+ return {
12
+ controls: e.controls === "custom" ? "custom" : "native",
13
+ titleBarHeight: Math.max(24, Math.round(e.titleBarHeight ?? 40)),
14
+ overlay: {
15
+ ...u,
16
+ ...e.overlay
17
+ },
18
+ bounds: e.rememberBounds ? `m3-window${typeof e.rememberBounds == "string" ? `-${e.rememberBounds.replace(/[^\w-]/g, "_")}` : ""}.json` : null,
19
+ externalLinks: e.externalLinks !== !1
20
+ };
21
+ }
22
+ var f = (e) => n(r.getPath("userData"), e);
23
+ function p(t) {
24
+ try {
25
+ let n = JSON.parse(e(f(t), "utf8"));
26
+ return [
27
+ n.x,
28
+ n.y,
29
+ n.width,
30
+ n.height
31
+ ].every(Number.isFinite) ? n : null;
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+ function m(e) {
37
+ let t = p(e);
38
+ return t ? o.getAllDisplays().some(({ workArea: e }) => Math.min(t.x + t.width, e.x + e.width) - Math.max(t.x, e.x) >= 100 && Math.min(t.y + 40, e.y + e.height) - Math.max(t.y, e.y) >= 20) ? t : {
39
+ width: t.width,
40
+ height: t.height,
41
+ maximized: t.maximized
42
+ } : {};
43
+ }
44
+ function h(e = {}) {
45
+ let t = d(e), n = {};
46
+ if (t.bounds) {
47
+ let { x: e, y: r, width: i, height: a } = m(t.bounds);
48
+ n = {
49
+ ...i ? {
50
+ width: i,
51
+ height: a
52
+ } : {},
53
+ ...e == null ? {} : {
54
+ x: e,
55
+ y: r
56
+ }
57
+ };
58
+ }
59
+ if (t.controls === "custom") return {
60
+ ...n,
61
+ frame: !1
62
+ };
63
+ let r = process.platform === "darwin";
64
+ return {
65
+ ...n,
66
+ titleBarStyle: "hidden",
67
+ titleBarOverlay: r ? !0 : {
68
+ ...t.overlay,
69
+ height: t.titleBarHeight
70
+ },
71
+ ...r ? { trafficLightPosition: {
72
+ x: 14,
73
+ y: Math.round((t.titleBarHeight - 16) / 2)
74
+ } } : {}
75
+ };
76
+ }
77
+ var g = /* @__PURE__ */ new Map(), _ = !1, v = () => {
78
+ try {
79
+ let e = process.platform === "win32" || process.platform === "darwin" ? c.getAccentColor() : "";
80
+ return /^[0-9a-f]{6}/i.test(e) ? `#${e.slice(0, 6).toLowerCase()}` : null;
81
+ } catch {
82
+ return null;
83
+ }
84
+ }, y = (e) => ({
85
+ maximized: e.isMaximized(),
86
+ fullscreen: e.isFullScreen(),
87
+ focused: e.isFocused()
88
+ });
89
+ function b(e) {
90
+ return g.get(e.id);
91
+ }
92
+ function x() {
93
+ _ || (_ = !0, i.handle(l.info, (e) => {
94
+ let t = b(e.sender);
95
+ return t ? {
96
+ controls: t.o.controls,
97
+ platform: process.platform,
98
+ titleBarHeight: t.o.titleBarHeight,
99
+ state: y(t.win),
100
+ accentColor: v()
101
+ } : null;
102
+ }), i.on(l.action, (e, t) => {
103
+ let n = b(e.sender);
104
+ n && !n.win.isDestroyed() && (t === "minimize" ? n.win.minimize() : t === "toggle-maximize" ? n.win.isFullScreen() ? n.win.setFullScreen(!1) : n.win.isMaximized() ? n.win.unmaximize() : n.win.maximize() : t === "close" && n.win.close());
105
+ }), i.on(l.overlay, (e, t) => {
106
+ let n = b(e.sender);
107
+ if (!n || n.win.isDestroyed() || n.o.controls !== "native" || process.platform === "darwin" || !C(t?.color) || !C(t?.symbolColor)) return;
108
+ let r = `${t.color}|${t.symbolColor}`;
109
+ r !== n.overlay && (n.overlay = r, n.win.setTitleBarOverlay({
110
+ color: t.color,
111
+ symbolColor: t.symbolColor,
112
+ height: n.o.titleBarHeight
113
+ }));
114
+ }), i.on(l.theme, (e, t) => {
115
+ b(e.sender) && [
116
+ "light",
117
+ "dark",
118
+ "system"
119
+ ].includes(t) && a.themeSource !== t && (a.themeSource = t);
120
+ }), i.on(l.progress, (e, t) => {
121
+ let n = b(e.sender);
122
+ n && !n.win.isDestroyed() && (t === "indeterminate" ? n.win.setProgressBar(2, { mode: "indeterminate" }) : typeof t == "number" && Number.isFinite(t) ? n.win.setProgressBar(Math.min(1, Math.max(0, t))) : n.win.setProgressBar(-1));
123
+ }), i.on(l.badge, (e, t) => {
124
+ b(e.sender) && r.setBadgeCount(Math.max(0, Math.floor(Number(t) || 0)));
125
+ }), i.on(l.attention, (e) => {
126
+ let t = b(e.sender);
127
+ !t || t.win.isDestroyed() || t.win.isFocused() || (process.platform === "darwin" ? r.dock?.bounce("informational") : (t.win.flashFrame(!0), t.win.once("focus", () => {
128
+ t.win.isDestroyed() || t.win.flashFrame(!1);
129
+ })));
130
+ }), c.on?.("accent-color-changed", () => {
131
+ for (let { win: e } of g.values()) e.isDestroyed() || e.webContents.send(l.accent, v());
132
+ }));
133
+ }
134
+ var S = /^(https?|mailto):/i, C = (e) => typeof e == "string" && /^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(e);
135
+ function w(e, n = {}) {
136
+ x();
137
+ let r = d(n), i = e.webContents.id;
138
+ g.set(i, {
139
+ win: e,
140
+ o: r,
141
+ overlay: ""
142
+ });
143
+ let a = () => {
144
+ e.isDestroyed() || e.webContents.send(l.state, y(e));
145
+ }, o = [
146
+ "maximize",
147
+ "unmaximize",
148
+ "enter-full-screen",
149
+ "leave-full-screen",
150
+ "focus",
151
+ "blur",
152
+ "restore"
153
+ ];
154
+ for (let t of o) e.on(t, a);
155
+ let c = () => {}, u, m = () => {
156
+ clearTimeout(u), u = setTimeout(c, 400);
157
+ };
158
+ if (r.bounds) {
159
+ let n = r.bounds;
160
+ p(n)?.maximized && e.maximize(), c = () => {
161
+ if (!(e.isDestroyed() || e.isMinimized() || e.isFullScreen())) try {
162
+ t(f(n), JSON.stringify({
163
+ ...e.getNormalBounds(),
164
+ maximized: e.isMaximized()
165
+ }));
166
+ } catch {}
167
+ };
168
+ for (let t of [
169
+ "resize",
170
+ "move",
171
+ "maximize",
172
+ "unmaximize"
173
+ ]) e.on(t, m);
174
+ e.on("close", () => {
175
+ clearTimeout(u), c();
176
+ });
177
+ }
178
+ return r.externalLinks && (e.webContents.setWindowOpenHandler(({ url: e }) => (S.test(e) && s.openExternal(e), { action: "deny" })), e.webContents.on("will-navigate", (t, n) => {
179
+ let r = e.webContents.getURL(), i = !1;
180
+ try {
181
+ i = new URL(n).origin !== new URL(r).origin;
182
+ } catch {}
183
+ S.test(n) && i && (t.preventDefault(), s.openExternal(n));
184
+ })), e.once("closed", () => {
185
+ g.delete(i), clearTimeout(u);
186
+ }), () => {
187
+ if (g.delete(i), clearTimeout(u), !e.isDestroyed()) {
188
+ for (let t of o) e.off(t, a);
189
+ for (let t of [
190
+ "resize",
191
+ "move",
192
+ "maximize",
193
+ "unmaximize"
194
+ ]) e.off(t, m);
195
+ }
196
+ };
197
+ }
198
+ export { h as m3WindowOptions, w as setupM3Window };
199
+
200
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","names":["readFileSync","writeFileSync","join","app","ipcMain","nativeTheme","screen","shell","systemPreferences","IPC","BASELINE","resolve","o","boundsFile","name","readBounds","b","restoredBounds","a","m3WindowOptions","options","saved","x","y","width","height","mac","windows","registered","accent","c","stateOf","win","entry","sender","register","w","action","colors","isHex","key","theme","value","count","EXTERNAL","setupM3Window","id","send","events","ev","save","timer","later","url","e","here","other"],"sources":["../src/main.ts"],"sourcesContent":["/**\n * `@m3ui-vue/electron/main`: the main-process half. `m3WindowOptions()` gives the BrowserWindow options for the mode\n * you pick, `setupM3Window()` wires that window to MTitleBar (its state, its buttons, the native overlay's colors) and\n * to `useElectronWindow()` (native theme, accent color, taskbar progress and badge, attention), remembers its bounds\n * and sends outside links to the browser.\n *\n * ```ts\n * const m3 = { controls: 'native' } as const\n * const win = new BrowserWindow({ width: 1100, height: 720, ...m3WindowOptions(m3), webPreferences: { preload } })\n * setupM3Window(win, m3)\n * ```\n */\nimport { readFileSync, writeFileSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { app, BrowserWindow, ipcMain, nativeTheme, screen, shell, systemPreferences, type BrowserWindowConstructorOptions, type IpcMainEvent, type IpcMainInvokeEvent, type Rectangle, type WebContents } from 'electron'\nimport { DEFAULT_TITLE_BAR_HEIGHT, IPC, type M3Controls, type M3NativeTheme, type M3OverlayColors, type M3WindowAction, type M3WindowInfo, type M3WindowState } from './shared'\n\nexport type { M3Controls, M3NativeTheme, M3OverlayColors, M3WindowAction, M3WindowInfo, M3WindowState } from './shared'\n\nexport interface M3WindowOptions {\n /** `'native'` (default): the system's buttons, recolored from the theme. `'custom'`: frameless, MTitleBar draws them */\n controls?: M3Controls\n /** Title bar height in px (default 40) */\n titleBarHeight?: number\n /**\n * The native buttons' colors before the page has loaded (MTitleBar sends the real ones from the theme as soon as\n * it mounts). Defaults to the M3 baseline light surface\n */\n overlay?: Partial<M3OverlayColors>\n /**\n * Reopen the window with the size, position and maximized state it closed with (kept in the app's userData\n * folder). `true`, or a name per window when the app has several. Spread `m3WindowOptions()` after your own\n * width/height so the remembered ones win\n */\n rememberBounds?: boolean | string\n /**\n * Open http(s) and mailto links that would leave the app (`target=\"_blank\"`, `window.open`, a link to another\n * site) in the system browser instead of a new Electron window. Default true\n */\n externalLinks?: boolean\n}\n\ninterface Resolved {\n controls: M3Controls\n titleBarHeight: number\n overlay: M3OverlayColors\n bounds: string | null\n externalLinks: boolean\n}\n\nconst BASELINE: M3OverlayColors = { color: '#fef7ff', symbolColor: '#49454f' }\n\nfunction resolve(o: M3WindowOptions = {}): Resolved {\n return {\n controls: o.controls === 'custom' ? 'custom' : 'native',\n titleBarHeight: Math.max(24, Math.round(o.titleBarHeight ?? DEFAULT_TITLE_BAR_HEIGHT)),\n overlay: { ...BASELINE, ...o.overlay },\n bounds: o.rememberBounds ? `m3-window${typeof o.rememberBounds === 'string' ? `-${o.rememberBounds.replace(/[^\\w-]/g, '_')}` : ''}.json` : null,\n externalLinks: o.externalLinks !== false,\n }\n}\n\n// ── Remembered bounds ───────────────────────────────────────────────────────────────────────────────────────────\ninterface Saved extends Rectangle { maximized: boolean }\nconst boundsFile = (name: string) => join(app.getPath('userData'), name)\n\nfunction readBounds(name: string): Saved | null {\n try {\n const b = JSON.parse(readFileSync(boundsFile(name), 'utf8')) as Saved\n if (![b.x, b.y, b.width, b.height].every(Number.isFinite)) return null\n return b\n } catch {\n return null\n }\n}\n\n/** The saved bounds, without the position when no screen shows enough of the window anymore (a monitor unplugged) */\nfunction restoredBounds(name: string): Partial<Rectangle> & { maximized?: boolean } {\n const b = readBounds(name)\n if (!b) return {}\n const visible = screen.getAllDisplays().some(({ workArea: a }) =>\n Math.min(b.x + b.width, a.x + a.width) - Math.max(b.x, a.x) >= 100 && Math.min(b.y + 40, a.y + a.height) - Math.max(b.y, a.y) >= 20)\n return visible ? b : { width: b.width, height: b.height, maximized: b.maximized }\n}\n\n/** The BrowserWindow options for a mode: spread them into `new BrowserWindow({ ... })` */\nexport function m3WindowOptions(options: M3WindowOptions = {}): BrowserWindowConstructorOptions {\n const o = resolve(options)\n let saved: BrowserWindowConstructorOptions = {}\n if (o.bounds) {\n const { x, y, width, height } = restoredBounds(o.bounds)\n saved = { ...(width ? { width, height } : {}), ...(x != null ? { x, y } : {}) }\n }\n if (o.controls === 'custom') return { ...saved, frame: false }\n const mac = process.platform === 'darwin'\n return {\n ...saved,\n titleBarStyle: 'hidden',\n // macOS keeps its traffic lights (`true` only turns on the overlay's CSS env() area); elsewhere the system's\n // buttons are drawn over the page in these colors, at the bar's height\n titleBarOverlay: mac ? true : { ...o.overlay, height: o.titleBarHeight },\n // Traffic lights (12px, 20px apart) centered in the bar\n ...(mac ? { trafficLightPosition: { x: 14, y: Math.round((o.titleBarHeight - 16) / 2) } } : {}),\n }\n}\n\n// One handler per channel for the whole app; each message finds its window's settings by the sender\nconst windows = new Map<number, { win: BrowserWindow; o: Resolved; overlay: string }>()\nlet registered = false\n\nconst accent = (): string | null => {\n try {\n const c = process.platform === 'win32' || process.platform === 'darwin' ? systemPreferences.getAccentColor() : ''\n return /^[0-9a-f]{6}/i.test(c) ? `#${c.slice(0, 6).toLowerCase()}` : null\n } catch {\n return null\n }\n}\n\nconst stateOf = (win: BrowserWindow): M3WindowState => ({\n maximized: win.isMaximized(),\n fullscreen: win.isFullScreen(),\n focused: win.isFocused(),\n})\n\nfunction entry(sender: WebContents) {\n return windows.get(sender.id)\n}\n\nfunction register() {\n if (registered) return\n registered = true\n ipcMain.handle(IPC.info, (e: IpcMainInvokeEvent): M3WindowInfo | null => {\n const w = entry(e.sender)\n if (!w) return null\n return { controls: w.o.controls, platform: process.platform, titleBarHeight: w.o.titleBarHeight, state: stateOf(w.win), accentColor: accent() }\n })\n ipcMain.on(IPC.action, (e: IpcMainEvent, action: M3WindowAction) => {\n const w = entry(e.sender)\n if (!w || w.win.isDestroyed()) return\n if (action === 'minimize') w.win.minimize()\n else if (action === 'toggle-maximize') {\n if (w.win.isFullScreen()) w.win.setFullScreen(false)\n else if (w.win.isMaximized()) w.win.unmaximize()\n else w.win.maximize()\n } else if (action === 'close') w.win.close()\n })\n ipcMain.on(IPC.overlay, (e: IpcMainEvent, colors: M3OverlayColors) => {\n const w = entry(e.sender)\n if (!w || w.win.isDestroyed() || w.o.controls !== 'native' || process.platform === 'darwin') return\n if (!isHex(colors?.color) || !isHex(colors?.symbolColor)) return\n // The renderer sends every frame of a theme transition: skip what wouldn't change anything\n const key = `${colors.color}|${colors.symbolColor}`\n if (key === w.overlay) return\n w.overlay = key\n w.win.setTitleBarOverlay({ color: colors.color, symbolColor: colors.symbolColor, height: w.o.titleBarHeight })\n })\n // The app's theme choice drives the native UI too (dialogs, context menus, scrollbars, macOS's frame). The\n // choice, not the result: 'system' must stay 'system', or prefers-color-scheme would follow the app back\n ipcMain.on(IPC.theme, (e: IpcMainEvent, theme: M3NativeTheme) => {\n if (!entry(e.sender) || !['light', 'dark', 'system'].includes(theme)) return\n if (nativeTheme.themeSource !== theme) nativeTheme.themeSource = theme\n })\n ipcMain.on(IPC.progress, (e: IpcMainEvent, value: number | 'indeterminate' | null) => {\n const w = entry(e.sender)\n if (!w || w.win.isDestroyed()) return\n if (value === 'indeterminate') w.win.setProgressBar(2, { mode: 'indeterminate' })\n else if (typeof value === 'number' && Number.isFinite(value)) w.win.setProgressBar(Math.min(1, Math.max(0, value)))\n else w.win.setProgressBar(-1)\n })\n ipcMain.on(IPC.badge, (e: IpcMainEvent, count: number) => {\n if (!entry(e.sender)) return\n app.setBadgeCount(Math.max(0, Math.floor(Number(count) || 0)))\n })\n ipcMain.on(IPC.attention, (e: IpcMainEvent) => {\n const w = entry(e.sender)\n if (!w || w.win.isDestroyed() || w.win.isFocused()) return\n if (process.platform === 'darwin') app.dock?.bounce('informational')\n else {\n w.win.flashFrame(true)\n w.win.once('focus', () => { if (!w.win.isDestroyed()) w.win.flashFrame(false) })\n }\n })\n // Accent color changes (Windows sends them; macOS asks for a relaunch of most apps anyway)\n const sendAccent = () => { for (const { win } of windows.values()) if (!win.isDestroyed()) win.webContents.send(IPC.accent, accent()) }\n systemPreferences.on?.('accent-color-changed', sendAccent)\n}\n\nconst EXTERNAL = /^(https?|mailto):/i\n\nconst isHex = (c: unknown): c is string => typeof c === 'string' && /^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(c)\n\n/**\n * Connects `win` to MTitleBar: answers its questions, runs its buttons, sends it the window's state and recolors the\n * native buttons with the theme. Pass the same options as to `m3WindowOptions()`. Returns a function that undoes it\n * (it's undone on its own when the window closes).\n */\nexport function setupM3Window(win: BrowserWindow, options: M3WindowOptions = {}): () => void {\n register()\n const o = resolve(options)\n const id = win.webContents.id\n windows.set(id, { win, o, overlay: '' })\n const send = () => { if (!win.isDestroyed()) win.webContents.send(IPC.state, stateOf(win)) }\n const events = ['maximize', 'unmaximize', 'enter-full-screen', 'leave-full-screen', 'focus', 'blur', 'restore'] as const\n for (const ev of events) win.on(ev as 'maximize', send)\n\n // Bounds: the size it had before being maximized (getNormalBounds), saved after moves and resizes settle\n let save = () => {}\n let timer: ReturnType<typeof setTimeout> | undefined\n const later = () => { clearTimeout(timer); timer = setTimeout(save, 400) }\n if (o.bounds) {\n const name = o.bounds\n if (readBounds(name)?.maximized) win.maximize()\n save = () => {\n if (win.isDestroyed() || win.isMinimized() || win.isFullScreen()) return\n try {\n writeFileSync(boundsFile(name), JSON.stringify({ ...win.getNormalBounds(), maximized: win.isMaximized() }))\n } catch { /* a read-only profile: nothing to remember */ }\n }\n for (const ev of ['resize', 'move', 'maximize', 'unmaximize'] as const) win.on(ev as 'resize', later)\n win.on('close', () => { clearTimeout(timer); save() })\n }\n\n // Links that leave the app open in the browser\n if (o.externalLinks) {\n win.webContents.setWindowOpenHandler(({ url }) => {\n if (EXTERNAL.test(url)) void shell.openExternal(url)\n return { action: 'deny' }\n })\n win.webContents.on('will-navigate', (e, url) => {\n const here = win.webContents.getURL()\n let other = false\n try { other = new URL(url).origin !== new URL(here).origin } catch { /* about:blank and the like */ }\n if (EXTERNAL.test(url) && other) {\n e.preventDefault()\n void shell.openExternal(url)\n }\n })\n }\n\n const dispose = () => {\n windows.delete(id)\n clearTimeout(timer)\n if (!win.isDestroyed()) {\n for (const ev of events) win.off(ev as 'maximize', send)\n for (const ev of ['resize', 'move', 'maximize', 'unmaximize'] as const) win.off(ev as 'resize', later)\n }\n }\n win.once('closed', () => { windows.delete(id); clearTimeout(timer) })\n return dispose\n}\n"],"mappings":";;;;;AAkDA,IAAMU,IAA4B;CAAE,OAAO;CAAW,aAAa;AAAU;AAE7E,SAASC,EAAQC,IAAqB,CAAC,GAAa;CAClD,OAAO;EACL,UAAUA,EAAE,aAAa,WAAW,WAAW;EAC/C,gBAAgB,KAAK,IAAI,IAAI,KAAK,MAAMA,EAAE,kBAAA,EAA0C,CAAC;EACrF,SAAS;GAAE,GAAGF;GAAU,GAAGE,EAAE;EAAQ;EACrC,QAAQA,EAAE,iBAAiB,YAAY,OAAOA,EAAE,kBAAmB,WAAW,IAAIA,EAAE,eAAe,QAAQ,WAAW,GAAG,MAAM,GAAG,SAAS;EAC3I,eAAeA,EAAE,kBAAkB;CACrC;AACF;AAIA,IAAMC,KAAcC,MAAiBZ,EAAKC,EAAI,QAAQ,UAAU,GAAGW,CAAI;AAEvE,SAASC,EAAWD,GAA4B;CAC9C,IAAI;EACF,IAAME,IAAI,KAAK,MAAMhB,EAAaa,EAAWC,CAAI,GAAG,MAAM,CAAC;EAE3D,OADK;GAACE,EAAE;GAAGA,EAAE;GAAGA,EAAE;GAAOA,EAAE;EAAM,CAAC,CAAC,MAAM,OAAO,QAAQ,IACjDA,IAD2D;CAEpE,QAAQ;EACN,OAAO;CACT;AACF;AAGA,SAASC,EAAeH,GAA4D;CAClF,IAAME,IAAID,EAAWD,CAAI;CAI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AGiB,GAAgBG,CAAK;EACpGpB,EAAI,GAAG,eAAe;GAAE,aAAamB,CAAK,GAAGD,EAAK;EAAE,CAAC;CACvD;CA4BA,OAzBItC,EAAE,kBACJoB,EAAI,YAAY,sBAAsB,EAAEqB,cAClCT,EAAS,KAAKS,CAAG,KAAQ9C,EAAM,aAAa8C,CAAG,GAC5C,EAAE,QAAQ,OAAO,EACzB,GACDrB,EAAI,YAAY,GAAG,kBAAkBsB,GAAGD,MAAQ;EAC9C,IAAME,IAAOvB,EAAI,YAAY,OAAO,GAChCwB,IAAQ;EACZ,IAAI;GAAEA,IAAQ,IAAI,IAAIH,CAAG,CAAC,CAAC,WAAW,IAAI,IAAIE,CAAI,CAAC,CAAC;EAAO,QAAQ,CAAiC;EAChGX,EAAS,KAAKS,CAAG,KAAKG,MACxBF,EAAE,eAAe,GACZ/C,EAAM,aAAa8C,CAAG;CAE/B,CAAC,IAWHrB,EAAI,KAAK,gBAAgB;EAAEL,EAAQ,OAAOmB,CAAE,GAAG,aAAaK,CAAK;CAAE,CAAC,SAR9C;EAGpB,IAFAxB,EAAQ,OAAOmB,CAAE,GACjB,aAAaK,CAAK,GACd,CAACnB,EAAI,YAAY,GAAG;GACtB,KAAK,IAAMiB,KAAMD,GAAQhB,EAAI,IAAIiB,GAAkBF,CAAI;GACvD,KAAK,IAAME,KAAM;IAAC;IAAU;IAAQ;IAAY;GAAY,GAAYjB,EAAI,IAAIiB,GAAgBG,CAAK;EACvG;CACF;AAGF"}
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("electron");var t={info:`m3ui:info`,state:`m3ui:state`,action:`m3ui:action`,overlay:`m3ui:overlay`,theme:`m3ui:theme`,progress:`m3ui:progress`,badge:`m3ui:badge`,attention:`m3ui:attention`,accent:`m3ui:accent`},n=`m3ui`;function r(){return{info:()=>e.ipcRenderer.invoke(t.info),onState(n){let r=(e,t)=>n(t);return e.ipcRenderer.on(t.state,r),()=>{e.ipcRenderer.removeListener(t.state,r)}},action:n=>e.ipcRenderer.send(t.action,n),setOverlay:n=>e.ipcRenderer.send(t.overlay,{color:n.color,symbolColor:n.symbolColor}),setTheme:n=>e.ipcRenderer.send(t.theme,n),setProgress:n=>e.ipcRenderer.send(t.progress,n),setBadge:n=>e.ipcRenderer.send(t.badge,n),attention:()=>e.ipcRenderer.send(t.attention),onAccent(n){let r=(e,t)=>n(t);return e.ipcRenderer.on(t.accent,r),()=>{e.ipcRenderer.removeListener(t.accent,r)}}}}exports._BRIDGE_KEY=n,exports._IPC=t,exports.createM3Bridge=r,exports.exposeM3UI=function(){let t=r();process.contextIsolated?e.contextBridge.exposeInMainWorld(n,t):globalThis[n]=t};
2
+ //# sourceMappingURL=preload.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preload.cjs","names":["ipcRenderer","contextBridge","electron","IPC","BRIDGE_KEY","createM3Bridge","listener","handler","_e","state","action","colors","theme","value","count","color","bridge"],"sources":["../src/preload.ts"],"sourcesContent":["/**\n * `@m3ui-vue/electron/preload`: exposes the bridge MTitleBar talks through.\n *\n * ```ts\n * // preload.ts (bundled, as electron-vite does)\n * import { exposeM3UI } from '@m3ui-vue/electron/preload'\n * exposeM3UI()\n * ```\n *\n * A sandboxed preload can't `require` npm packages at runtime: bundle it, or paste `createM3Bridge()`'s body (it only\n * needs `ipcRenderer`).\n */\nimport { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron'\nimport type { M3Bridge, M3NativeTheme, M3OverlayColors, M3WindowAction, M3WindowState } from './shared'\n\n// Copies of shared.ts's constants (a test keeps them equal): with no runtime import, the built preload is one\n// self-contained file, which a sandboxed preload needs (it can only `require('electron')`)\nconst IPC = {\n info: 'm3ui:info',\n state: 'm3ui:state',\n action: 'm3ui:action',\n overlay: 'm3ui:overlay',\n theme: 'm3ui:theme',\n progress: 'm3ui:progress',\n badge: 'm3ui:badge',\n attention: 'm3ui:attention',\n accent: 'm3ui:accent',\n} as const\nconst BRIDGE_KEY = 'm3ui'\nexport { IPC as _IPC, BRIDGE_KEY as _BRIDGE_KEY }\n\nexport type { M3Bridge } from './shared'\n\n/** The bridge itself, to expose it yourself (it must end up as `window.m3ui`) */\nexport function createM3Bridge(): M3Bridge {\n return {\n info: () => ipcRenderer.invoke(IPC.info),\n onState(listener: (state: M3WindowState) => void) {\n const handler = (_e: IpcRendererEvent, state: M3WindowState) => listener(state)\n ipcRenderer.on(IPC.state, handler)\n return () => { ipcRenderer.removeListener(IPC.state, handler) }\n },\n action: (action: M3WindowAction) => ipcRenderer.send(IPC.action, action),\n setOverlay: (colors: M3OverlayColors) => ipcRenderer.send(IPC.overlay, { color: colors.color, symbolColor: colors.symbolColor }),\n setTheme: (theme: M3NativeTheme) => ipcRenderer.send(IPC.theme, theme),\n setProgress: (value: number | 'indeterminate' | null) => ipcRenderer.send(IPC.progress, value),\n setBadge: (count: number) => ipcRenderer.send(IPC.badge, count),\n attention: () => ipcRenderer.send(IPC.attention),\n onAccent(listener: (color: string | null) => void) {\n const handler = (_e: IpcRendererEvent, color: string | null) => listener(color)\n ipcRenderer.on(IPC.accent, handler)\n return () => { ipcRenderer.removeListener(IPC.accent, handler) }\n },\n }\n}\n\n/**\n * Exposes the bridge as `window.m3ui`, where `useElectronWindow()` and MTitleBar look for it. Uses `contextBridge`\n * when context isolation is on (the default), a plain global otherwise.\n */\nexport function exposeM3UI(): void {\n const bridge = createM3Bridge()\n if (process.contextIsolated) contextBridge.exposeInMainWorld(BRIDGE_KEY, bridge)\n else (globalThis as unknown as Record<string, unknown>)[BRIDGE_KEY] = bridge\n}\n"],"mappings":"A,6FAiBA,IAAMG,EAAM,CACV,KAAM,YACN,MAAO,aACP,OAAQ,cACR,QAAS,eACT,MAAO,aACP,SAAU,gBACV,MAAO,aACP,UAAW,iBACX,OAAQ,aACV,EACMC,EAAa,OAMnB,SAAgBC,GAA2B,CACzC,MAAO,CACL,SAAYL,EAAAA,YAAY,OAAOG,EAAI,IAAI,EACvC,QAAQG,EAA0C,CAChD,IAAMC,GAAWC,EAAsBC,IAAyBH,EAASG,CAAK,EAE9E,OADAT,EAAAA,YAAY,GAAGG,EAAI,MAAOI,CAAO,MACpB,CAAEP,EAAAA,YAAY,eAAeG,EAAI,MAAOI,CAAO,CAAE,CAChE,EACA,OAASG,GAA2BV,EAAAA,YAAY,KAAKG,EAAI,OAAQO,CAAM,EACvE,WAAaC,GAA4BX,EAAAA,YAAY,KAAKG,EAAI,QAAS,CAAE,MAAOQ,EAAO,MAAO,YAAaA,EAAO,WAAY,CAAC,EAC/H,SAAWC,GAAyBZ,EAAAA,YAAY,KAAKG,EAAI,MAAOS,CAAK,EACrE,YAAcC,GAA2Cb,EAAAA,YAAY,KAAKG,EAAI,SAAUU,CAAK,EAC7F,SAAWC,GAAkBd,EAAAA,YAAY,KAAKG,EAAI,MAAOW,CAAK,EAC9D,cAAiBd,EAAAA,YAAY,KAAKG,EAAI,SAAS,EAC/C,SAASG,EAA0C,CACjD,IAAMC,GAAWC,EAAsBO,IAAyBT,EAASS,CAAK,EAE9E,OADAf,EAAAA,YAAY,GAAGG,EAAI,OAAQI,CAAO,MACrB,CAAEP,EAAAA,YAAY,eAAeG,EAAI,OAAQI,CAAO,CAAE,CACjE,CACF,CACF,C,iFAMA,UAAmC,CACjC,IAAMS,EAASX,EAAe,EAC1B,QAAQ,gBAAiBJ,EAAAA,cAAc,kBAAkBG,EAAYY,CAAM,EACzE,WAAkDZ,GAAcY,CACxE"}
@@ -0,0 +1,22 @@
1
+ import type { M3Bridge } from './shared';
2
+ declare const IPC: {
3
+ readonly info: "m3ui:info";
4
+ readonly state: "m3ui:state";
5
+ readonly action: "m3ui:action";
6
+ readonly overlay: "m3ui:overlay";
7
+ readonly theme: "m3ui:theme";
8
+ readonly progress: "m3ui:progress";
9
+ readonly badge: "m3ui:badge";
10
+ readonly attention: "m3ui:attention";
11
+ readonly accent: "m3ui:accent";
12
+ };
13
+ declare const BRIDGE_KEY = "m3ui";
14
+ export { IPC as _IPC, BRIDGE_KEY as _BRIDGE_KEY };
15
+ export type { M3Bridge } from './shared';
16
+ /** The bridge itself, to expose it yourself (it must end up as `window.m3ui`) */
17
+ export declare function createM3Bridge(): M3Bridge;
18
+ /**
19
+ * Exposes the bridge as `window.m3ui`, where `useElectronWindow()` and MTitleBar look for it. Uses `contextBridge`
20
+ * when context isolation is on (the default), a plain global otherwise.
21
+ */
22
+ export declare function exposeM3UI(): void;
@@ -0,0 +1,46 @@
1
+ import { contextBridge as e, ipcRenderer as t } from "electron";
2
+ // src/preload.ts
3
+ var n = {
4
+ info: "m3ui:info",
5
+ state: "m3ui:state",
6
+ action: "m3ui:action",
7
+ overlay: "m3ui:overlay",
8
+ theme: "m3ui:theme",
9
+ progress: "m3ui:progress",
10
+ badge: "m3ui:badge",
11
+ attention: "m3ui:attention",
12
+ accent: "m3ui:accent"
13
+ }, r = "m3ui";
14
+ function i() {
15
+ return {
16
+ info: () => t.invoke(n.info),
17
+ onState(e) {
18
+ let r = (t, n) => e(n);
19
+ return t.on(n.state, r), () => {
20
+ t.removeListener(n.state, r);
21
+ };
22
+ },
23
+ action: (e) => t.send(n.action, e),
24
+ setOverlay: (e) => t.send(n.overlay, {
25
+ color: e.color,
26
+ symbolColor: e.symbolColor
27
+ }),
28
+ setTheme: (e) => t.send(n.theme, e),
29
+ setProgress: (e) => t.send(n.progress, e),
30
+ setBadge: (e) => t.send(n.badge, e),
31
+ attention: () => t.send(n.attention),
32
+ onAccent(e) {
33
+ let r = (t, n) => e(n);
34
+ return t.on(n.accent, r), () => {
35
+ t.removeListener(n.accent, r);
36
+ };
37
+ }
38
+ };
39
+ }
40
+ function a() {
41
+ let t = i();
42
+ process.contextIsolated ? e.exposeInMainWorld(r, t) : globalThis[r] = t;
43
+ }
44
+ export { r as _BRIDGE_KEY, n as _IPC, i as createM3Bridge, a as exposeM3UI };
45
+
46
+ //# sourceMappingURL=preload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preload.js","names":["contextBridge","ipcRenderer","IPC","BRIDGE_KEY","createM3Bridge","listener","handler","_e","state","action","colors","theme","value","count","color","exposeM3UI","bridge"],"sources":["../src/preload.ts"],"sourcesContent":["/**\n * `@m3ui-vue/electron/preload`: exposes the bridge MTitleBar talks through.\n *\n * ```ts\n * // preload.ts (bundled, as electron-vite does)\n * import { exposeM3UI } from '@m3ui-vue/electron/preload'\n * exposeM3UI()\n * ```\n *\n * A sandboxed preload can't `require` npm packages at runtime: bundle it, or paste `createM3Bridge()`'s body (it only\n * needs `ipcRenderer`).\n */\nimport { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron'\nimport type { M3Bridge, M3NativeTheme, M3OverlayColors, M3WindowAction, M3WindowState } from './shared'\n\n// Copies of shared.ts's constants (a test keeps them equal): with no runtime import, the built preload is one\n// self-contained file, which a sandboxed preload needs (it can only `require('electron')`)\nconst IPC = {\n info: 'm3ui:info',\n state: 'm3ui:state',\n action: 'm3ui:action',\n overlay: 'm3ui:overlay',\n theme: 'm3ui:theme',\n progress: 'm3ui:progress',\n badge: 'm3ui:badge',\n attention: 'm3ui:attention',\n accent: 'm3ui:accent',\n} as const\nconst BRIDGE_KEY = 'm3ui'\nexport { IPC as _IPC, BRIDGE_KEY as _BRIDGE_KEY }\n\nexport type { M3Bridge } from './shared'\n\n/** The bridge itself, to expose it yourself (it must end up as `window.m3ui`) */\nexport function createM3Bridge(): M3Bridge {\n return {\n info: () => ipcRenderer.invoke(IPC.info),\n onState(listener: (state: M3WindowState) => void) {\n const handler = (_e: IpcRendererEvent, state: M3WindowState) => listener(state)\n ipcRenderer.on(IPC.state, handler)\n return () => { ipcRenderer.removeListener(IPC.state, handler) }\n },\n action: (action: M3WindowAction) => ipcRenderer.send(IPC.action, action),\n setOverlay: (colors: M3OverlayColors) => ipcRenderer.send(IPC.overlay, { color: colors.color, symbolColor: colors.symbolColor }),\n setTheme: (theme: M3NativeTheme) => ipcRenderer.send(IPC.theme, theme),\n setProgress: (value: number | 'indeterminate' | null) => ipcRenderer.send(IPC.progress, value),\n setBadge: (count: number) => ipcRenderer.send(IPC.badge, count),\n attention: () => ipcRenderer.send(IPC.attention),\n onAccent(listener: (color: string | null) => void) {\n const handler = (_e: IpcRendererEvent, color: string | null) => listener(color)\n ipcRenderer.on(IPC.accent, handler)\n return () => { ipcRenderer.removeListener(IPC.accent, handler) }\n },\n }\n}\n\n/**\n * Exposes the bridge as `window.m3ui`, where `useElectronWindow()` and MTitleBar look for it. Uses `contextBridge`\n * when context isolation is on (the default), a plain global otherwise.\n */\nexport function exposeM3UI(): void {\n const bridge = createM3Bridge()\n if (process.contextIsolated) contextBridge.exposeInMainWorld(BRIDGE_KEY, bridge)\n else (globalThis as unknown as Record<string, unknown>)[BRIDGE_KEY] = bridge\n}\n"],"mappings":";;AAiBA,IAAME,IAAM;CACV,MAAM;CACN,OAAO;CACP,QAAQ;CACR,SAAS;CACT,OAAO;CACP,UAAU;CACV,OAAO;CACP,WAAW;CACX,QAAQ;AACV,GACMC,IAAa;AAMnB,SAAgBC,IAA2B;CACzC,OAAO;EACL,YAAYH,EAAY,OAAOC,EAAI,IAAI;EACvC,QAAQG,GAA0C;GAChD,IAAMC,KAAWC,GAAsBC,MAAyBH,EAASG,CAAK;GAE9E,OADAP,EAAY,GAAGC,EAAI,OAAOI,CAAO,SACpB;IAAEL,EAAY,eAAeC,EAAI,OAAOI,CAAO;GAAE;EAChE;EACA,SAASG,MAA2BR,EAAY,KAAKC,EAAI,QAAQO,CAAM;EACvE,aAAaC,MAA4BT,EAAY,KAAKC,EAAI,SAAS;GAAE,OAAOQ,EAAO;GAAO,aAAaA,EAAO;EAAY,CAAC;EAC/H,WAAWC,MAAyBV,EAAY,KAAKC,EAAI,OAAOS,CAAK;EACrE,cAAcC,MAA2CX,EAAY,KAAKC,EAAI,UAAUU,CAAK;EAC7F,WAAWC,MAAkBZ,EAAY,KAAKC,EAAI,OAAOW,CAAK;EAC9D,iBAAiBZ,EAAY,KAAKC,EAAI,SAAS;EAC/C,SAASG,GAA0C;GACjD,IAAMC,KAAWC,GAAsBO,MAAyBT,EAASS,CAAK;GAE9E,OADAb,EAAY,GAAGC,EAAI,QAAQI,CAAO,SACrB;IAAEL,EAAY,eAAeC,EAAI,QAAQI,CAAO;GAAE;EACjE;CACF;AACF;AAMA,SAAgBS,IAAmB;CACjC,IAAMC,IAASZ,EAAe;CAC1B,QAAQ,kBAAiBJ,EAAc,kBAAkBG,GAAYa,CAAM,IACzE,WAAkDb,KAAca;AACxE"}
@@ -0,0 +1,77 @@
1
+ import { type MenuBarItem, type MenuBarMenu } from '@m3ui-vue/m3ui-vue';
2
+ type Button = 'minimize' | 'maximize' | 'close';
3
+ type __VLS_Props = {
4
+ /** The window title */
5
+ title?: string;
6
+ /**
7
+ * The app icon at the start: an image URL (`'/icon.png'`, an import, a data: URL) or a Material Symbol name.
8
+ * Clicking it does nothing (the `#icon` slot takes a button of yours)
9
+ */
10
+ icon?: string;
11
+ /** Menus (File, Edit…) after the icon, as an MMenuBar: items with submenus, dividers, checks, shortcut hints */
12
+ menus?: MenuBarMenu[];
13
+ /** `inline`: the menus sit in the title bar, after the icon. `below`: in a row of their own under it (classic) */
14
+ menusPosition?: 'inline' | 'below';
15
+ /**
16
+ * Like VS Code's "menu bar visibility": `visible`; `compact`, one ☰ button in the bar holding every menu;
17
+ * `toggle`, hidden until Alt is pressed (and hidden again after a pick, Esc or a click elsewhere); `hidden`
18
+ */
19
+ menusVisibility?: 'visible' | 'compact' | 'toggle' | 'hidden';
20
+ /** Bar color: an M3 role (`'surface-container'`) or any CSS color */
21
+ color?: string;
22
+ /** Where the title sits */
23
+ titleAlign?: 'start' | 'center';
24
+ /** Custom controls only: which buttons, in this order on the end side (mirrored on the start side) */
25
+ buttons?: Button[];
26
+ /** Custom controls only: the side they sit on; `auto` is the start on macOS, the end elsewhere */
27
+ side?: 'auto' | 'start' | 'end';
28
+ /** Custom controls only: M3 icon buttons or macOS-style traffic lights; `auto` picks by platform */
29
+ look?: 'auto' | 'm3' | 'traffic-lights';
30
+ /**
31
+ * Keep the native UI's theme (dialogs, context menus, scrollbars, macOS's frame) on the app's `useTheme()`
32
+ * choice: light, dark or system
33
+ */
34
+ syncNativeTheme?: boolean;
35
+ };
36
+ declare const __VLS_template: () => {
37
+ __VLS_Slots: {
38
+ icon?: (props: {}) => any;
39
+ } & {
40
+ start?: (props: {}) => any;
41
+ } & {
42
+ default?: (props: {}) => any;
43
+ } & {
44
+ end?: (props: {}) => any;
45
+ } & {
46
+ controls?: (props: {
47
+ minimize: () => void;
48
+ toggleMaximize: () => void;
49
+ close: () => void;
50
+ maximized: boolean;
51
+ focused: boolean;
52
+ }) => any;
53
+ };
54
+ };
55
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
56
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
57
+ "menu-select": (item: MenuBarItem, menu: number) => any;
58
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
59
+ "onMenu-select"?: ((item: MenuBarItem, menu: number) => any) | undefined;
60
+ }>, {
61
+ menusPosition: "inline" | "below";
62
+ menusVisibility: "visible" | "compact" | "toggle" | "hidden";
63
+ color: string;
64
+ titleAlign: "start" | "center";
65
+ buttons: Button[];
66
+ side: "start" | "auto" | "end";
67
+ look: "auto" | "m3" | "traffic-lights";
68
+ syncNativeTheme: boolean;
69
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
70
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
71
+ declare const _default: typeof __VLS_export;
72
+ export default _default;
73
+ type __VLS_WithSlots<T, S> = T & {
74
+ new (): {
75
+ $slots: S;
76
+ };
77
+ };