@m3ui-vue/electron 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +118 -2
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +196 -0
- package/dist/index.js.map +1 -0
- package/dist/main.cjs +2 -0
- package/dist/main.cjs.map +1 -0
- package/dist/main.d.ts +32 -0
- package/dist/main.js +92 -0
- package/dist/main.js.map +1 -0
- package/dist/preload.cjs +2 -0
- package/dist/preload.cjs.map +1 -0
- package/dist/preload.d.ts +17 -0
- package/dist/preload.js +31 -0
- package/dist/preload.js.map +1 -0
- package/dist/renderer/MTitleBar.vue.d.ts +48 -0
- package/dist/renderer/useElectronWindow.d.ts +29 -0
- package/dist/shared-B-ScY3hE.js +10 -0
- package/dist/shared-B-ScY3hE.js.map +1 -0
- package/dist/shared-CWEPeNW8.cjs +2 -0
- package/dist/shared-CWEPeNW8.cjs.map +1 -0
- package/dist/shared.d.ts +52 -0
- package/dist/styles.css +2 -0
- package/package.json +63 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fadel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @m3ui-vue/electron
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://www.npmjs.com/package/@m3ui-vue/electron"><img src="https://img.shields.io/npm/v/@m3ui-vue/electron?color=blue" alt="npm version"></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@m3ui-vue/electron"><img src="https://img.shields.io/npm/l/@m3ui-vue/electron" alt="license"></a>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
Electron integration for [m3ui-vue](https://m3ui.dev), the Material Design 3 component library for Vue 3 + Tailwind
|
|
9
|
+
CSS v4: a Material 3 title bar for your window, with the system's own window buttons or M3 ones, themed live from the
|
|
10
|
+
M3 tokens (dark mode and palette changes included).
|
|
11
|
+
|
|
12
|
+
> **0.x.** The API may still change between minor versions.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @m3ui-vue/electron @m3ui-vue/m3ui-vue
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Electron 33 or later. The package has three parts, one per Electron process.
|
|
21
|
+
|
|
22
|
+
### 1. Main process
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { app, BrowserWindow } from 'electron'
|
|
26
|
+
import { join } from 'node:path'
|
|
27
|
+
import { m3WindowOptions, setupM3Window, type M3WindowOptions } from '@m3ui-vue/electron/main'
|
|
28
|
+
|
|
29
|
+
const m3: M3WindowOptions = { controls: 'native' } // or 'custom'
|
|
30
|
+
|
|
31
|
+
app.whenReady().then(() => {
|
|
32
|
+
const win = new BrowserWindow({
|
|
33
|
+
width: 1100,
|
|
34
|
+
height: 720,
|
|
35
|
+
...m3WindowOptions(m3),
|
|
36
|
+
webPreferences: { preload: join(import.meta.dirname, '../preload/index.mjs') },
|
|
37
|
+
})
|
|
38
|
+
setupM3Window(win, m3)
|
|
39
|
+
win.loadURL(/* … */)
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Option | Default | |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `controls` | `'native'` | `'native'`: the system draws the window buttons over the bar (Windows 11 snap layouts, macOS traffic lights, your Linux desktop's buttons) and they're recolored with the theme. `'custom'`: a frameless window, MTitleBar draws the buttons |
|
|
46
|
+
| `titleBarHeight` | `40` | Height of the bar (and of the native buttons) |
|
|
47
|
+
| `overlay` | baseline light | Native button colors before the page loads; the bar sends the real ones once it mounts |
|
|
48
|
+
|
|
49
|
+
### 2. Preload
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { exposeM3UI } from '@m3ui-vue/electron/preload'
|
|
53
|
+
|
|
54
|
+
exposeM3UI() // window.m3ui
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
With a bundler for the preload (electron-vite, Electron Forge's Vite plugin…) that's all. A sandboxed preload can't
|
|
58
|
+
`require` npm packages at runtime: if yours isn't bundled, copy `node_modules/@m3ui-vue/electron/dist/preload.cjs`,
|
|
59
|
+
which only needs `electron`.
|
|
60
|
+
|
|
61
|
+
### 3. Renderer
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// main.css, after the library's own imports
|
|
65
|
+
@import '@m3ui-vue/electron/styles';
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```vue
|
|
69
|
+
<script setup lang="ts">
|
|
70
|
+
import { MTitleBar } from '@m3ui-vue/electron'
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<template>
|
|
74
|
+
<div class="flex h-screen flex-col">
|
|
75
|
+
<MTitleBar title="My app" color="surface-container">
|
|
76
|
+
<template #start><MIcon name="deployed_code" /></template>
|
|
77
|
+
<template #end><MIconButton icon="search" size="xs" /></template>
|
|
78
|
+
</MTitleBar>
|
|
79
|
+
<main class="min-h-0 flex-1 overflow-auto"><!-- … --></main>
|
|
80
|
+
</div>
|
|
81
|
+
</template>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The bar drags the window, and double-clicking it maximizes. Buttons, links and fields inside it stay clickable; mark
|
|
85
|
+
anything else that should be with `data-no-drag`.
|
|
86
|
+
|
|
87
|
+
| Prop | Default | |
|
|
88
|
+
|---|---|---|
|
|
89
|
+
| `title` | | Window title (or the default slot) |
|
|
90
|
+
| `color` | `'surface'` | An M3 role or any CSS color |
|
|
91
|
+
| `titleAlign` | `'start'` | `'start'` or `'center'` |
|
|
92
|
+
| `buttons` | all three | `custom` only: which of `'minimize'`, `'maximize'`, `'close'` |
|
|
93
|
+
| `side` | `'auto'` | `custom` only: `'start'`, `'end'`, or `'auto'` (start on macOS) |
|
|
94
|
+
| `look` | `'auto'` | `custom` only: `'m3'` icon buttons, `'traffic-lights'`, or `'auto'` (by platform) |
|
|
95
|
+
|
|
96
|
+
Slots: `default` (title), `start`, `end`, and `controls` to draw the buttons yourself
|
|
97
|
+
(`{ minimize, toggleMaximize, close, maximized, focused }`).
|
|
98
|
+
|
|
99
|
+
Outside Electron the bar renders without buttons, so the same app also runs in a browser.
|
|
100
|
+
|
|
101
|
+
### `useElectronWindow()`
|
|
102
|
+
|
|
103
|
+
The window's mode and state, reactive, and its actions, for anything besides the bar:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const { isElectron, ready, controls, platform, isMac, maximized, fullscreen, focused, minimize, toggleMaximize, close } = useElectronWindow()
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Playground
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pnpm install
|
|
113
|
+
pnpm -C playground dev # native controls
|
|
114
|
+
pnpm -C playground dev:custom # frameless, custom controls
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue"),t=require("@m3ui-vue/m3ui-vue");const n=require("./shared-CWEPeNW8.cjs");function r(){return typeof window<`u`?window[n.t]:void 0}var i=(0,e.ref)(!1),a=(0,e.ref)(`native`),o=(0,e.ref)(``),s=(0,e.ref)(40),c=(0,e.ref)(!1),l=(0,e.ref)(!1),u=(0,e.ref)(!0),d=0,f=null,p=null;function m(e){c.value=e.maximized,l.value=e.fullscreen,u.value=e.focused}function h(e){f||=e.onState(m),p??=e.info().then(e=>{e&&(a.value=e.controls,o.value=e.platform,s.value=e.titleBarHeight,m(e.state),i.value=!0)}).catch(()=>{p=null})}function g(){f?.(),f=null}function _(){let t=r();return t&&(d++,h(t),(0,e.getCurrentScope)()&&(0,e.onScopeDispose)(()=>{--d===0&&g()})),{isElectron:!!t,ready:(0,e.readonly)(i),controls:(0,e.readonly)(a),platform:(0,e.readonly)(o),isMac:(0,e.computed)(()=>o.value===`darwin`),titleBarHeight:(0,e.readonly)(s),maximized:(0,e.readonly)(c),fullscreen:(0,e.readonly)(l),focused:(0,e.readonly)(u),minimize:()=>t?.action(`minimize`),toggleMaximize:()=>t?.action(`toggle-maximize`),close:()=>t?.action(`close`),setOverlay:e=>t?.setOverlay(e)}}var v=[`data-controls`],y={class:`m3-title-bar-area`},b={class:`m3-title-bar-start`},x={class:`m3-title-bar-title`},S={class:`m3-title-bar-end`},C=[`aria-label`,`title`,`onClick`],w={key:1,viewBox:`0 0 12 12`,"aria-hidden":`true`},T={key:0,d:`M3.5 3.5l5 5M8.5 3.5l-5 5`},E={key:1,d:`M3 6h6`},D={key:2,d:`M6 3v6M3 6h6`},O=(0,e.defineComponent)({__name:`MTitleBar`,props:{title:{},color:{default:`surface`},titleAlign:{default:`start`},buttons:{default:()=>[`minimize`,`maximize`,`close`]},side:{default:`auto`},look:{default:`auto`}},setup(n){let r=n,i=(0,t.useLocale)(),a=_(),{controls:o,maximized:s,focused:c,fullscreen:l,isMac:u,titleBarHeight:d}=a,f=/^[a-z]+(-[a-z]+)*$/,p=(0,e.computed)(()=>f.test(r.color)?`var(--color-${r.color})`:r.color),m=(0,e.computed)(()=>a.isElectron&&o.value===`custom`),h=(0,e.computed)(()=>a.isElectron&&o.value===`native`),g=(0,e.computed)(()=>r.side===`auto`?u.value:r.side===`start`),O=(0,e.computed)(()=>r.look===`auto`?u.value:r.look===`traffic-lights`),k=(0,e.computed)(()=>{let e=r.buttons.filter((e,t,n)=>n.indexOf(e)===t);return O.value?[`close`,`minimize`,`maximize`].filter(t=>e.includes(t)):g.value?[...e].reverse():e}),A=(0,e.computed)(()=>s.value||l.value?i.windowRestore:i.windowMaximize),j=(0,e.computed)(()=>({minimize:i.windowMinimize,maximize:A.value,close:i.close})),M=e=>e===`minimize`?a.minimize():e===`maximize`?a.toggleMaximize():a.close();function N(e){m.value&&(e.target.closest(`button, a, input, select, textarea, [role="button"], [data-no-drag]`)||a.toggleMaximize())}let P=(0,e.ref)(),F=(0,e.ref)(),I=0,L=0,R=null,z=null;function B(e,t){let n=/rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?/.exec(e);if(!n)return null;let r=n[4]==null?1:n[4].endsWith(`%`)?parseFloat(n[4])/100:parseFloat(n[4]),i=[+n[1],+n[2],+n[3]];return r<1&&t?i.forEach((e,n)=>i[n]=e*r+t[n]*(1-r)):r=1,`#${i.map(e=>Math.round(Math.min(255,Math.max(0,e))).toString(16).padStart(2,`0`)).join(``)}`}function V(){let e=B(getComputedStyle(document.body).backgroundColor)??B(getComputedStyle(document.documentElement).backgroundColor)??`#ffffff`;return[1,3,5].map(t=>parseInt(e.slice(t,t+2),16))}function H(){if(!P.value||!F.value)return;let e=B(getComputedStyle(P.value).backgroundColor,V()),t=B(getComputedStyle(F.value).color);e&&t&&a.setOverlay({color:e,symbolColor:t})}function U(e=600){if(!h.value||u.value||(L=performance.now()+e,I))return;let t=()=>{H(),I=performance.now()<L?requestAnimationFrame(t):0};t()}let W=()=>U();function G(){R||!h.value||u.value||(U(),R=new MutationObserver(()=>U()),R.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`,`style`,`data-palette`,`data-theme`]}),z=window.matchMedia?.(`(prefers-color-scheme: dark)`)??null,z?.addEventListener?.(`change`,W))}function K(){R?.disconnect(),R=null,z?.removeEventListener?.(`change`,W),z=null,cancelAnimationFrame(I),I=0}return(0,e.onMounted)(()=>{a.ready.value&&G()}),(0,e.watch)([a.ready,h,u],()=>{K(),a.ready.value&&G()}),(0,e.watch)(()=>r.color,()=>U()),(0,e.onBeforeUnmount)(K),(r,i)=>((0,e.openBlock)(),(0,e.createElementBlock)(`header`,{ref_key:`bar`,ref:P,class:(0,e.normalizeClass)([`m3-title-bar`,{"m3-title-bar-native":h.value,"m3-title-bar-blurred":!(0,e.unref)(c),"m3-title-bar-center":n.titleAlign===`center`}]),style:(0,e.normalizeStyle)({height:`${(0,e.unref)(d)}px`,background:p.value}),"data-controls":(0,e.unref)(a).isElectron?(0,e.unref)(o):void 0,onDblclick:N},[(0,e.createElementVNode)(`span`,{ref_key:`probe`,ref:F,class:`m3-title-bar-probe`,"aria-hidden":`true`},null,512),(0,e.createElementVNode)(`div`,y,[(0,e.createElementVNode)(`div`,b,[(0,e.renderSlot)(r.$slots,`start`)]),(0,e.createElementVNode)(`div`,x,[(0,e.renderSlot)(r.$slots,`default`,{},()=>[(0,e.createTextVNode)((0,e.toDisplayString)(n.title),1)])]),(0,e.createElementVNode)(`div`,S,[(0,e.renderSlot)(r.$slots,`end`)]),m.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:(0,e.normalizeClass)([`m3-title-bar-side`,g.value&&`m3-title-bar-controls-start`])},[(0,e.renderSlot)(r.$slots,`controls`,(0,e.normalizeProps)((0,e.guardReactiveProps)({minimize:(0,e.unref)(a).minimize,toggleMaximize:(0,e.unref)(a).toggleMaximize,close:(0,e.unref)(a).close,maximized:(0,e.unref)(s),focused:(0,e.unref)(c)})),()=>[(0,e.createElementVNode)(`div`,{class:(0,e.normalizeClass)([`m3-title-bar-controls`,O.value&&`m3-title-bar-lights`])},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(k.value,n=>((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:n,type:`button`,class:(0,e.normalizeClass)([`m3-title-bar-btn`,`m3-title-bar-btn-${n}`]),"aria-label":j.value[n],title:j.value[n],onClick:e=>M(n)},[O.value?((0,e.openBlock)(),(0,e.createElementBlock)(`svg`,w,[n===`close`?((0,e.openBlock)(),(0,e.createElementBlock)(`path`,T)):n===`minimize`?((0,e.openBlock)(),(0,e.createElementBlock)(`path`,E)):((0,e.openBlock)(),(0,e.createElementBlock)(`path`,D))])):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(t.MIcon),{key:0,name:n===`minimize`?`minimize`:n===`close`?`close`:(0,e.unref)(s)||(0,e.unref)(l)?`close_fullscreen`:`open_in_full`,size:n===`maximize`?16:18},null,8,[`name`,`size`]))],10,C))),128))],2)])],2)):(0,e.createCommentVNode)(``,!0)])],46,v))}});exports.MTitleBar=O,exports.useElectronWindow=_;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["BRIDGE_KEY","ref","getCurrentScope","onScopeDispose","readonly","computed","useLocale","computed","ref","onMounted","watch","onBeforeUnmount","_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createElementVNode","_renderSlot","_createTextVNode","_toDisplayString","_normalizeProps","_guardReactiveProps","_Fragment","_renderList","_createBlock","MIcon","vue","_m3ui_vue_m3ui_vue","require_shared","bridge","ready","controls","platform","titleBarHeight","maximized","fullscreen","focused","users","unsubscribe","started","apply","s","start","b","info","stop","useElectronWindow","colors","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","MTitleBar_default","__props","props","locale","win","isMac","ROLE","background","custom","native","atStart","lights","order","set","i","a","maximizeLabel","labels","run","onDblclick","bar","probe","raf","until","observer","media","toHex","css","under","m","c","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 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 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}\n\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)\nlet users = 0\nlet unsubscribe: (() => 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 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 apply(info.state)\n ready.value = true\n }).catch(() => { started = null })\n}\n\nfunction stop() {\n unsubscribe?.()\n unsubscribe = 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 minimize: () => b?.action('minimize'),\n toggleMaximize: () => b?.action('toggle-maximize'),\n close: () => b?.action('close'),\n setOverlay: (colors) => b?.setOverlay(colors),\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}\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 leading controls (an app icon, a menu button…)\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 */\nimport { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { MIcon, useLocale } 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 /** 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 { color: 'surface', titleAlign: 'start', buttons: () => ['minimize', 'maximize', 'close'], side: 'auto', look: 'auto' },\n)\n\nconst locale = useLocale()\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())\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=\"{ height: `${titleBarHeight}px`, background }\"\n :data-controls=\"win.isElectron ? controls : undefined\"\n @dblclick=\"onDblclick\"\n >\n <span ref=\"probe\" class=\"m3-title-bar-probe\" aria-hidden=\"true\" />\n <div class=\"m3-title-bar-area\">\n <div class=\"m3-title-bar-start\"><slot name=\"start\" /></div>\n <div class=\"m3-title-bar-title\"><slot>{{ title }}</slot></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 </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-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 position: absolute;\n inset-block: 0;\n left: env(titlebar-area-x, 0px);\n width: env(titlebar-area-width, 100%);\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.m3-title-bar-center .m3-title-bar-title {\n text-align: center;\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":"A,iKA4BA,SAAS8B,GAA+B,CACtC,OAAO,OAAO,OAAW,IAAe,OAA2D9B,EAAAA,GAAc,IAAA,EACnH,CAGA,IAAM+B,GAAA,EAAQ9B,EAAAA,IAAAA,CAAI,EAAK,EACjB+B,GAAA,EAAW/B,EAAAA,IAAAA,CAAgB,QAAQ,EACnCgC,GAAA,EAAWhC,EAAAA,I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,CAbN,IAAK+B,EACN,KAAK,SACJ,OAAA,EAAK9B,EAAAA,eAAAA,CAAA,CAAA,mBAAA,oBAA2C8B,GAAC,CAAA,EACjD,aAAYgC,EAAA,MAAOhC,GACnB,MAAOgC,EAAA,MAAOhC,GACd,QAAK4D,GAAE3B,EAAIjC,CAAC,C,GAEC0B,EAAA,Q,EACd1D,EAAAA,UAAAA,CAAA,GAAA,EAAAC,EAAAA,mBAAAA,CAIM,MAJN0C,EAIM,CAHQX,IAAC,UAAA,EAAbhC,EAAAA,UAAAA,CAAA,GAAA,EAAAC,EAAAA,mBAAAA,CAA2D,OAA3D2C,CAA2D,GAC1CZ,IAAC,aAAA,EAAlBhC,EAAAA,UAAAA,CAAA,GAAA,EAAAC,EAAAA,mBAAAA,CAAgD,OAAhD4C,CAAgD,KAAA,EAChD7C,EAAAA,UAAAA,CAAA,GAAA,EAAAC,EAAAA,mBAAAA,CAAgC,OAAhC6C,CAAgC,E,MAJpB,EAAd9C,EAAAA,UAAAA,CAAA,GAAA,EAAAa,EAAAA,YAAAA,EAAAA,EAA2LV,EAAAA,MAAAA,CAAAW,EAAAA,KAAA,EAAA,C,MAApK,KAAMkB,IAAC,WAAA,WAA+BA,IAAC,QAAA,SAAA,EAAyB7B,EAAAA,MAAAA,CAAAoB,CAAA,IAAA,EAAapB,EAAAA,MAAAA,CAAAqB,CAAA,EAAU,mBAAA,eAAyC,KAAMQ,IAAC,WAAA,GAAA,E"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as MTitleBar } from './renderer/MTitleBar.vue';
|
|
2
|
+
export { useElectronWindow } from './renderer/useElectronWindow';
|
|
3
|
+
export type { ElectronWindow } from './renderer/useElectronWindow';
|
|
4
|
+
export type { M3Bridge, M3Controls, M3OverlayColors, M3WindowAction, M3WindowInfo, M3WindowState } from './shared';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createTextVNode as ee, defineComponent as o, getCurrentScope as s, guardReactiveProps as c, normalizeClass as l, normalizeProps as te, normalizeStyle as ne, onBeforeUnmount as u, onMounted as re, onScopeDispose as d, openBlock as f, readonly as p, ref as m, renderList as h, renderSlot as g, toDisplayString as ie, unref as _, watch as v } from "vue";
|
|
2
|
+
import { MIcon as ae, useLocale as oe } from "@m3ui-vue/m3ui-vue";
|
|
3
|
+
import { t as y } from "./shared-B-ScY3hE.js";
|
|
4
|
+
// src/renderer/useElectronWindow.ts
|
|
5
|
+
function b() {
|
|
6
|
+
return typeof window < "u" ? window[y] : void 0;
|
|
7
|
+
}
|
|
8
|
+
var x = m(!1), S = m("native"), C = m(""), w = m(40), T = m(!1), E = m(!1), D = m(!0), O = 0, k = null, A = null;
|
|
9
|
+
function j(e) {
|
|
10
|
+
T.value = e.maximized, E.value = e.fullscreen, D.value = e.focused;
|
|
11
|
+
}
|
|
12
|
+
function M(e) {
|
|
13
|
+
k ||= e.onState(j), A ??= e.info().then((e) => {
|
|
14
|
+
e && (S.value = e.controls, C.value = e.platform, w.value = e.titleBarHeight, j(e.state), x.value = !0);
|
|
15
|
+
}).catch(() => {
|
|
16
|
+
A = null;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function N() {
|
|
20
|
+
k?.(), k = null;
|
|
21
|
+
}
|
|
22
|
+
function P() {
|
|
23
|
+
let e = b();
|
|
24
|
+
return e && (O++, M(e), s() && d(() => {
|
|
25
|
+
--O === 0 && N();
|
|
26
|
+
})), {
|
|
27
|
+
isElectron: !!e,
|
|
28
|
+
ready: p(x),
|
|
29
|
+
controls: p(S),
|
|
30
|
+
platform: p(C),
|
|
31
|
+
isMac: t(() => C.value === "darwin"),
|
|
32
|
+
titleBarHeight: p(w),
|
|
33
|
+
maximized: p(T),
|
|
34
|
+
fullscreen: p(E),
|
|
35
|
+
focused: p(D),
|
|
36
|
+
minimize: () => e?.action("minimize"),
|
|
37
|
+
toggleMaximize: () => e?.action("toggle-maximize"),
|
|
38
|
+
close: () => e?.action("close"),
|
|
39
|
+
setOverlay: (t) => e?.setOverlay(t)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// src/renderer/MTitleBar.vue?vue&type=script&setup=true&lang.ts
|
|
43
|
+
var se = ["data-controls"], ce = { class: "m3-title-bar-area" }, le = { class: "m3-title-bar-start" }, ue = { class: "m3-title-bar-title" }, F = { class: "m3-title-bar-end" }, I = [
|
|
44
|
+
"aria-label",
|
|
45
|
+
"title",
|
|
46
|
+
"onClick"
|
|
47
|
+
], L = {
|
|
48
|
+
key: 1,
|
|
49
|
+
viewBox: "0 0 12 12",
|
|
50
|
+
"aria-hidden": "true"
|
|
51
|
+
}, R = {
|
|
52
|
+
key: 0,
|
|
53
|
+
d: "M3.5 3.5l5 5M8.5 3.5l-5 5"
|
|
54
|
+
}, z = {
|
|
55
|
+
key: 1,
|
|
56
|
+
d: "M3 6h6"
|
|
57
|
+
}, B = {
|
|
58
|
+
key: 2,
|
|
59
|
+
d: "M6 3v6M3 6h6"
|
|
60
|
+
}, V = /* @__PURE__ */ o({
|
|
61
|
+
__name: "MTitleBar",
|
|
62
|
+
props: {
|
|
63
|
+
title: {},
|
|
64
|
+
color: { default: "surface" },
|
|
65
|
+
titleAlign: { default: "start" },
|
|
66
|
+
buttons: { default: () => [
|
|
67
|
+
"minimize",
|
|
68
|
+
"maximize",
|
|
69
|
+
"close"
|
|
70
|
+
] },
|
|
71
|
+
side: { default: "auto" },
|
|
72
|
+
look: { default: "auto" }
|
|
73
|
+
},
|
|
74
|
+
setup(o) {
|
|
75
|
+
let s = o, d = oe(), p = P(), { controls: y, maximized: b, focused: x, fullscreen: S, isMac: C, titleBarHeight: w } = p, T = /^[a-z]+(-[a-z]+)*$/, E = t(() => T.test(s.color) ? `var(--color-${s.color})` : s.color), D = t(() => p.isElectron && y.value === "custom"), O = t(() => p.isElectron && y.value === "native"), k = t(() => s.side === "auto" ? C.value : s.side === "start"), A = t(() => s.look === "auto" ? C.value : s.look === "traffic-lights"), j = t(() => {
|
|
76
|
+
let e = s.buttons.filter((e, t, n) => n.indexOf(e) === t);
|
|
77
|
+
return A.value ? [
|
|
78
|
+
"close",
|
|
79
|
+
"minimize",
|
|
80
|
+
"maximize"
|
|
81
|
+
].filter((t) => e.includes(t)) : k.value ? [...e].reverse() : e;
|
|
82
|
+
}), M = t(() => b.value || S.value ? d.windowRestore : d.windowMaximize), N = t(() => ({
|
|
83
|
+
minimize: d.windowMinimize,
|
|
84
|
+
maximize: M.value,
|
|
85
|
+
close: d.close
|
|
86
|
+
})), V = (e) => e === "minimize" ? p.minimize() : e === "maximize" ? p.toggleMaximize() : p.close();
|
|
87
|
+
function H(e) {
|
|
88
|
+
D.value && (e.target.closest("button, a, input, select, textarea, [role=\"button\"], [data-no-drag]") || p.toggleMaximize());
|
|
89
|
+
}
|
|
90
|
+
let U = m(), W = m(), G = 0, K = 0, q = null, J = null;
|
|
91
|
+
function Y(e, t) {
|
|
92
|
+
let n = /rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?/.exec(e);
|
|
93
|
+
if (!n) return null;
|
|
94
|
+
let r = n[4] == null ? 1 : n[4].endsWith("%") ? parseFloat(n[4]) / 100 : parseFloat(n[4]), i = [
|
|
95
|
+
+n[1],
|
|
96
|
+
+n[2],
|
|
97
|
+
+n[3]
|
|
98
|
+
];
|
|
99
|
+
return r < 1 && t ? i.forEach((e, n) => i[n] = e * r + t[n] * (1 - r)) : r = 1, `#${i.map((e) => Math.round(Math.min(255, Math.max(0, e))).toString(16).padStart(2, "0")).join("")}`;
|
|
100
|
+
}
|
|
101
|
+
function de() {
|
|
102
|
+
let e = Y(getComputedStyle(document.body).backgroundColor) ?? Y(getComputedStyle(document.documentElement).backgroundColor) ?? "#ffffff";
|
|
103
|
+
return [
|
|
104
|
+
1,
|
|
105
|
+
3,
|
|
106
|
+
5
|
|
107
|
+
].map((t) => parseInt(e.slice(t, t + 2), 16));
|
|
108
|
+
}
|
|
109
|
+
function fe() {
|
|
110
|
+
if (!U.value || !W.value) return;
|
|
111
|
+
let e = Y(getComputedStyle(U.value).backgroundColor, de()), t = Y(getComputedStyle(W.value).color);
|
|
112
|
+
e && t && p.setOverlay({
|
|
113
|
+
color: e,
|
|
114
|
+
symbolColor: t
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function X(e = 600) {
|
|
118
|
+
if (!O.value || C.value || (K = performance.now() + e, G)) return;
|
|
119
|
+
let t = () => {
|
|
120
|
+
fe(), G = performance.now() < K ? requestAnimationFrame(t) : 0;
|
|
121
|
+
};
|
|
122
|
+
t();
|
|
123
|
+
}
|
|
124
|
+
let Z = () => X();
|
|
125
|
+
function Q() {
|
|
126
|
+
q || !O.value || C.value || (X(), q = new MutationObserver(() => X()), q.observe(document.documentElement, {
|
|
127
|
+
attributes: !0,
|
|
128
|
+
attributeFilter: [
|
|
129
|
+
"class",
|
|
130
|
+
"style",
|
|
131
|
+
"data-palette",
|
|
132
|
+
"data-theme"
|
|
133
|
+
]
|
|
134
|
+
}), J = window.matchMedia?.("(prefers-color-scheme: dark)") ?? null, J?.addEventListener?.("change", Z));
|
|
135
|
+
}
|
|
136
|
+
function $() {
|
|
137
|
+
q?.disconnect(), q = null, J?.removeEventListener?.("change", Z), J = null, cancelAnimationFrame(G), G = 0;
|
|
138
|
+
}
|
|
139
|
+
return re(() => {
|
|
140
|
+
p.ready.value && Q();
|
|
141
|
+
}), v([
|
|
142
|
+
p.ready,
|
|
143
|
+
O,
|
|
144
|
+
C
|
|
145
|
+
], () => {
|
|
146
|
+
$(), p.ready.value && Q();
|
|
147
|
+
}), v(() => s.color, () => X()), u($), (t, s) => (f(), i("header", {
|
|
148
|
+
ref_key: "bar",
|
|
149
|
+
ref: U,
|
|
150
|
+
class: l(["m3-title-bar", {
|
|
151
|
+
"m3-title-bar-native": O.value,
|
|
152
|
+
"m3-title-bar-blurred": !_(x),
|
|
153
|
+
"m3-title-bar-center": o.titleAlign === "center"
|
|
154
|
+
}]),
|
|
155
|
+
style: ne({
|
|
156
|
+
height: `${_(w)}px`,
|
|
157
|
+
background: E.value
|
|
158
|
+
}),
|
|
159
|
+
"data-controls": _(p).isElectron ? _(y) : void 0,
|
|
160
|
+
onDblclick: H
|
|
161
|
+
}, [a("span", {
|
|
162
|
+
ref_key: "probe",
|
|
163
|
+
ref: W,
|
|
164
|
+
class: "m3-title-bar-probe",
|
|
165
|
+
"aria-hidden": "true"
|
|
166
|
+
}, null, 512), a("div", ce, [
|
|
167
|
+
a("div", le, [g(t.$slots, "start")]),
|
|
168
|
+
a("div", ue, [g(t.$slots, "default", {}, () => [ee(ie(o.title), 1)])]),
|
|
169
|
+
a("div", F, [g(t.$slots, "end")]),
|
|
170
|
+
D.value ? (f(), i("div", {
|
|
171
|
+
key: 0,
|
|
172
|
+
class: l(["m3-title-bar-side", k.value && "m3-title-bar-controls-start"])
|
|
173
|
+
}, [g(t.$slots, "controls", te(c({
|
|
174
|
+
minimize: _(p).minimize,
|
|
175
|
+
toggleMaximize: _(p).toggleMaximize,
|
|
176
|
+
close: _(p).close,
|
|
177
|
+
maximized: _(b),
|
|
178
|
+
focused: _(x)
|
|
179
|
+
})), () => [a("div", { class: l(["m3-title-bar-controls", A.value && "m3-title-bar-lights"]) }, [(f(!0), i(e, null, h(j.value, (e) => (f(), i("button", {
|
|
180
|
+
key: e,
|
|
181
|
+
type: "button",
|
|
182
|
+
class: l(["m3-title-bar-btn", `m3-title-bar-btn-${e}`]),
|
|
183
|
+
"aria-label": N.value[e],
|
|
184
|
+
title: N.value[e],
|
|
185
|
+
onClick: (t) => V(e)
|
|
186
|
+
}, [A.value ? (f(), i("svg", L, [e === "close" ? (f(), i("path", R)) : e === "minimize" ? (f(), i("path", z)) : (f(), i("path", B))])) : (f(), n(_(ae), {
|
|
187
|
+
key: 0,
|
|
188
|
+
name: e === "minimize" ? "minimize" : e === "close" ? "close" : _(b) || _(S) ? "close_fullscreen" : "open_in_full",
|
|
189
|
+
size: e === "maximize" ? 16 : 18
|
|
190
|
+
}, null, 8, ["name", "size"]))], 10, I))), 128))], 2)])], 2)) : r("", !0)
|
|
191
|
+
])], 46, se));
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
export { V as MTitleBar, P as useElectronWindow };
|
|
195
|
+
|
|
196
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_openBlock","_createElementBlock","_normalizeClass","_unref","_normalizeStyle","_createElementVNode","_renderSlot","_createTextVNode","_toDisplayString","_normalizeProps","_guardReactiveProps","_Fragment","_renderList","_createBlock","Fragment","computed","createBlock","createCommentVNode","createElementBlock","createElementVNode","createTextVNode","defineComponent","getCurrentScope","guardReactiveProps","normalizeClass","normalizeProps","normalizeStyle","onBeforeUnmount","onMounted","onScopeDispose","openBlock","readonly","ref","renderList","renderSlot","toDisplayString","unref","watch","MIcon","useLocale","BRIDGE_KEY","bridge","ready","controls","platform","titleBarHeight","maximized","fullscreen","focused","users","unsubscribe","started","apply","s","start","b","info","stop","useElectronWindow","colors","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","MTitleBar_default","__props","props","locale","win","isMac","ROLE","background","custom","native","atStart","lights","order","set","i","a","maximizeLabel","labels","run","onDblclick","bar","probe","raf","until","observer","media","toHex","css","under","m","c","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 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 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}\n\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)\nlet users = 0\nlet unsubscribe: (() => 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 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 apply(info.state)\n ready.value = true\n }).catch(() => { started = null })\n}\n\nfunction stop() {\n unsubscribe?.()\n unsubscribe = 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 minimize: () => b?.action('minimize'),\n toggleMaximize: () => b?.action('toggle-maximize'),\n close: () => b?.action('close'),\n setOverlay: (colors) => b?.setOverlay(colors),\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}\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 leading controls (an app icon, a menu button…)\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 */\nimport { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { MIcon, useLocale } 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 /** 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 { color: 'surface', titleAlign: 'start', buttons: () => ['minimize', 'maximize', 'close'], side: 'auto', look: 'auto' },\n)\n\nconst locale = useLocale()\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())\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=\"{ height: `${titleBarHeight}px`, background }\"\n :data-controls=\"win.isElectron ? controls : undefined\"\n @dblclick=\"onDblclick\"\n >\n <span ref=\"probe\" class=\"m3-title-bar-probe\" aria-hidden=\"true\" />\n <div class=\"m3-title-bar-area\">\n <div class=\"m3-title-bar-start\"><slot name=\"start\" /></div>\n <div class=\"m3-title-bar-title\"><slot>{{ title }}</slot></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 </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-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 position: absolute;\n inset-block: 0;\n left: env(titlebar-area-x, 0px);\n width: env(titlebar-area-width, 100%);\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.m3-title-bar-center .m3-title-bar-title {\n text-align: center;\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":";;;;AA4BA,SAASyC,IAA+B;CACtC,OAAO,OAAO,SAAW,MAAe,OAA2DD,KAAc,KAAA;AACnH;AAGA,IAAME,IAAQV,EAAI,EAAK,GACjBW,IAAWX,EAAgB,QAAQ,GACnCY,IAAWZ,EAAI,EAAE,GACjBa,IAAiBb,EAAA,EAA4B,GAC7Cc,IAAYd,EAAI,EAAK,GACrBe,IAAaf,EAAI,EAAK,GACtBgB,IAAUhB,EAAI,EAAI,GACpBiB,IAAQ,GACRC,IAAmC,MACnCC,IAAgC;AAEpC,SAASC,EAAMC,GAAkB;CAC/BP,EAAU,QAAQO,EAAE,WACpBN,EAAW,QAAQM,EAAE,YACrBL,EAAQ,QAAQK,EAAE;AACpB;AAEA,SAASC,EAAMC,GAAa;CACRL,MAAcK,EAAE,QAAQH,CAAK,GAC/CD,MAAYI,EAAE,KAAK,CAAC,CAAC,MAAMC,MAAS;EAC7BA,MACLb,EAAS,QAAQa,EAAK,UACtBZ,EAAS,QAAQY,EAAK,UACtBX,EAAe,QAAQW,EAAK,gBAC5BJ,EAAMI,EAAK,KAAK,GAChBd,EAAM,QAAQ;CAChB,CAAC,CAAC,CAAC,YAAY;EAAES,IAAU;CAAK,CAAC;AACnC;AAEA,SAASM,IAAO;CACdP,IAAc,GACdA,IAAc;AAChB;AAEA,SAAgBQ,IAAoC;CAClD,IAAMH,IAAId,EAAO;CAMjB,OALIc,MACFN,KACAK,EAAMC,CAAC,GACHjC,EAAgB,KAAGO,QAAqB;EAAM,EAAEoB,MAAU,KAAGQ,EAAK;CAAE,CAAC,IAEpE;EACL,Y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Ac,OAASvE,EAAAuE,CAAA,CAAG,CAAC;IAAK,WAAEvE,EAAA2C,CAAA;IAAS,SAAE3C,EAAA6C,CAAA;GAAO,CAAA,CAAA,SAmBzH,CAlBL3C,EAiBM,OAAA,EAjBD,OAAKH,EAAA,CAAC,yBAAgC+E,EAAA,SAAM,qBAAA,CAAA,E,KAC/CjF,EAAA,EAAA,GAAAC,EAeSU,GAAA,MAAAC,EAdKsE,EAAA,QAAL3B,OADTvD,EAAA,GAAAC,EAeS,UAAA;IAbN,KAAKsD;IACN,MAAK;IACJ,OAAKrD,EAAA,CAAA,oBAAA,oBAA2CqD,GAAC,CAAA;IACjD,cAAYgC,EAAA,MAAOhC;IACnB,OAAOgC,EAAA,MAAOhC;IACd,UAAK4D,MAAE3B,EAAIjC,CAAC;G,IAEC0B,EAAA,SACdjF,EAAA,GAAAC,EAIM,OAJNiE,GAIM,CAHQX,MAAC,WAAbvD,EAAA,GAAAC,EAA2D,QAA3DkE,CAA2D,KAC1CZ,MAAC,cAAlBvD,EAAA,GAAAC,EAAgD,QAAhDmE,CAAgD,MAChDpE,EAAA,GAAAC,EAAgC,QAAhCoE,CAAgC,E,OAJlCrE,EAAA,GAAAa,EAA2LV,EAAAmC,EAAA,GAAA;;IAApK,MAAMiB,MAAC,aAAA,aAA+BA,MAAC,UAAA,UAAyBpD,EAAA2C,CAAA,KAAa3C,EAAA4C,CAAA,IAAU,qBAAA;IAAyC,MAAMQ,MAAC,aAAA,KAAA"}
|
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("electron");const t=require("./shared-CWEPeNW8.cjs");var n={color:`#fef7ff`,symbolColor:`#49454f`};function r(e={}){return{controls:e.controls===`custom`?`custom`:`native`,titleBarHeight:Math.max(24,Math.round(e.titleBarHeight??40)),overlay:{...n,...e.overlay}}}var i=new Map,a=!1,o=e=>({maximized:e.isMaximized(),fullscreen:e.isFullScreen(),focused:e.isFocused()});function s(e){return i.get(e.id)}function c(){a||(a=!0,e.ipcMain.handle(t.n.info,e=>{let t=s(e.sender);return t?{controls:t.o.controls,platform:process.platform,titleBarHeight:t.o.titleBarHeight,state:o(t.win)}:null}),e.ipcMain.on(t.n.action,(e,t)=>{let n=s(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())}),e.ipcMain.on(t.n.overlay,(e,t)=>{let n=s(e.sender);if(!n||n.win.isDestroyed()||n.o.controls!==`native`||process.platform===`darwin`||!l(t?.color)||!l(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}))}))}var l=e=>typeof e==`string`&&/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(e);exports.m3WindowOptions=function(e={}){let t=r(e);if(t.controls===`custom`)return{frame:!1};let n=process.platform===`darwin`;return{titleBarStyle:`hidden`,titleBarOverlay:n?!0:{...t.overlay,height:t.titleBarHeight},...n?{trafficLightPosition:{x:14,y:Math.round((t.titleBarHeight-16)/2)}}:{}}},exports.setupM3Window=function(e,n={}){c();let a=r(n),s=e.webContents.id;i.set(s,{win:e,o:a,overlay:``});let l=()=>{e.isDestroyed()||e.webContents.send(t.n.state,o(e))},u=[`maximize`,`unmaximize`,`enter-full-screen`,`leave-full-screen`,`focus`,`blur`,`restore`];for(let t of u)e.on(t,l);return e.once(`closed`,()=>i.delete(s)),()=>{if(i.delete(s),!e.isDestroyed())for(let t of u)e.off(t,l)}};
|
|
2
|
+
//# sourceMappingURL=main.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.cjs","names":["ipcMain","IPC","electron","require_shared","BASELINE","resolve","o","windows","registered","stateOf","win","entry","sender","register","w","action","colors","isHex","key","c","options","mac","id","send","events","ev"],"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).\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 { BrowserWindow, ipcMain, type BrowserWindowConstructorOptions, type IpcMainEvent, type IpcMainInvokeEvent, type WebContents } from 'electron'\nimport { DEFAULT_TITLE_BAR_HEIGHT, IPC, type M3Controls, type M3OverlayColors, type M3WindowAction, type M3WindowInfo, type M3WindowState } from './shared'\n\nexport type { M3Controls, 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\ninterface Resolved {\n controls: M3Controls\n titleBarHeight: number\n overlay: M3OverlayColors\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 }\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 if (o.controls === 'custom') return { frame: false }\n const mac = process.platform === 'darwin'\n return {\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 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) }\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}\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 const dispose = () => {\n windows.delete(id)\n if (!win.isDestroyed()) for (const ev of events) win.off(ev as 'maximize', send)\n }\n win.once('closed', () => windows.delete(id))\n return dispose\n}\n"],"mappings":"A,sIAiCA,IAAMI,EAA4B,CAAE,MAAO,UAAW,YAAa,SAAU,EAE7E,SAASC,EAAQC,EAAqB,CAAC,EAAa,CAClD,MAAO,CACL,SAAUA,EAAE,WAAa,SAAW,SAAW,SAC/C,eAAgB,KAAK,IAAI,GAAI,KAAK,MAAMA,EAAE,gBAAA,EAA0C,CAAC,EACrF,QAAS,CAAE,GAAGF,EAAU,GAAGE,EAAE,OAAQ,CACvC,CACF,CAkBA,IAAMC,EAAU,IAAI,IAChBC,EAAa,GAEXC,EAAWC,IAAuC,CACtD,UAAWA,EAAI,YAAY,EAC3B,WAAYA,EAAI,aAAa,EAC7B,QAASA,EAAI,UAAU,CACzB,GAEA,SAASC,EAAMC,EAAqB,CAClC,OAAOL,EAAQ,IAAIK,EAAO,EAAE,CAC9B,CAEA,SAASC,GAAW,CACdL,IACJA,EAAa,GACbR,EAAAA,QAAQ,OAAOC,EAAAA,EAAI,KAAO,GAA+C,CACvE,IAAMa,EAAIH,EAAM,EAAE,MAAM,EAExB,OADKG,EACE,CA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AiBA,EAAM,GAAO,CAAE,GAAGf,EAAE,QAAS,OAAQA,EAAE,cAAe,EAEvE,GAAIe,EAAM,CAAE,qBAAsB,CAAE,EAAG,GAAI,EAAG,KAAK,OAAOf,EAAE,eAAiB,IAAM,CAAC,CAAE,CAAE,EAAI,CAAC,CAC/F,CACF,E,sBAqDA,SAA8BI,EAAoBU,EAA2B,CAAC,EAAe,CAC3FP,EAAS,EACT,IAAMP,EAAID,EAAQe,CAAO,EACnBE,EAAKZ,EAAI,YAAY,GAC3BH,EAAQ,IAAIe,EAAI,CAAEZ,MAAKJ,IAAG,QAAS,EAAG,CAAC,EACvC,IAAMiB,MAAa,CAAOb,EAAI,YAAY,GAAGA,EAAI,YAAY,KAAKT,EAAAA,EAAI,MAAOQ,EAAQC,CAAG,CAAC,CAAE,EACrFc,EAAS,CAAC,WAAY,aAAc,oBAAqB,oBAAqB,QAAS,OAAQ,SAAS,EAC9G,IAAK,IAAMC,KAAMD,EAAQd,EAAI,GAAGe,EAAkBF,CAAI,EAMtD,OADAb,EAAI,KAAK,aAAgBH,EAAQ,OAAOe,CAAE,CAAC,MAJrB,CAEpB,GADAf,EAAQ,OAAOe,CAAE,EACb,CAACZ,EAAI,YAAY,EAAG,IAAK,IAAMe,KAAMD,EAAQd,EAAI,IAAIe,EAAkBF,CAAI,CACjF,CAGF"}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@m3ui-vue/electron/main`: the main-process half. `m3WindowOptions()` gives the BrowserWindow options for the mode
|
|
3
|
+
* you pick, `setupM3Window()` wires that window to MTitleBar (its state, its buttons, the native overlay's colors).
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const m3 = { controls: 'native' } as const
|
|
7
|
+
* const win = new BrowserWindow({ width: 1100, height: 720, ...m3WindowOptions(m3), webPreferences: { preload } })
|
|
8
|
+
* setupM3Window(win, m3)
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
import { BrowserWindow, type BrowserWindowConstructorOptions } from 'electron';
|
|
12
|
+
import { type M3Controls, type M3OverlayColors } from './shared';
|
|
13
|
+
export type { M3Controls, M3OverlayColors, M3WindowAction, M3WindowInfo, M3WindowState } from './shared';
|
|
14
|
+
export interface M3WindowOptions {
|
|
15
|
+
/** `'native'` (default): the system's buttons, recolored from the theme. `'custom'`: frameless, MTitleBar draws them */
|
|
16
|
+
controls?: M3Controls;
|
|
17
|
+
/** Title bar height in px (default 40) */
|
|
18
|
+
titleBarHeight?: number;
|
|
19
|
+
/**
|
|
20
|
+
* The native buttons' colors before the page has loaded (MTitleBar sends the real ones from the theme as soon as
|
|
21
|
+
* it mounts). Defaults to the M3 baseline light surface
|
|
22
|
+
*/
|
|
23
|
+
overlay?: Partial<M3OverlayColors>;
|
|
24
|
+
}
|
|
25
|
+
/** The BrowserWindow options for a mode: spread them into `new BrowserWindow({ ... })` */
|
|
26
|
+
export declare function m3WindowOptions(options?: M3WindowOptions): BrowserWindowConstructorOptions;
|
|
27
|
+
/**
|
|
28
|
+
* Connects `win` to MTitleBar: answers its questions, runs its buttons, sends it the window's state and recolors the
|
|
29
|
+
* native buttons with the theme. Pass the same options as to `m3WindowOptions()`. Returns a function that undoes it
|
|
30
|
+
* (it's undone on its own when the window closes).
|
|
31
|
+
*/
|
|
32
|
+
export declare function setupM3Window(win: BrowserWindow, options?: M3WindowOptions): () => void;
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ipcMain as e } from "electron";
|
|
2
|
+
import { n as t } from "./shared-B-ScY3hE.js";
|
|
3
|
+
// src/main.ts
|
|
4
|
+
var n = {
|
|
5
|
+
color: "#fef7ff",
|
|
6
|
+
symbolColor: "#49454f"
|
|
7
|
+
};
|
|
8
|
+
function r(e = {}) {
|
|
9
|
+
return {
|
|
10
|
+
controls: e.controls === "custom" ? "custom" : "native",
|
|
11
|
+
titleBarHeight: Math.max(24, Math.round(e.titleBarHeight ?? 40)),
|
|
12
|
+
overlay: {
|
|
13
|
+
...n,
|
|
14
|
+
...e.overlay
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function i(e = {}) {
|
|
19
|
+
let t = r(e);
|
|
20
|
+
if (t.controls === "custom") return { frame: !1 };
|
|
21
|
+
let n = process.platform === "darwin";
|
|
22
|
+
return {
|
|
23
|
+
titleBarStyle: "hidden",
|
|
24
|
+
titleBarOverlay: n ? !0 : {
|
|
25
|
+
...t.overlay,
|
|
26
|
+
height: t.titleBarHeight
|
|
27
|
+
},
|
|
28
|
+
...n ? { trafficLightPosition: {
|
|
29
|
+
x: 14,
|
|
30
|
+
y: Math.round((t.titleBarHeight - 16) / 2)
|
|
31
|
+
} } : {}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
var a = /* @__PURE__ */ new Map(), o = !1, s = (e) => ({
|
|
35
|
+
maximized: e.isMaximized(),
|
|
36
|
+
fullscreen: e.isFullScreen(),
|
|
37
|
+
focused: e.isFocused()
|
|
38
|
+
});
|
|
39
|
+
function c(e) {
|
|
40
|
+
return a.get(e.id);
|
|
41
|
+
}
|
|
42
|
+
function l() {
|
|
43
|
+
o || (o = !0, e.handle(t.info, (e) => {
|
|
44
|
+
let t = c(e.sender);
|
|
45
|
+
return t ? {
|
|
46
|
+
controls: t.o.controls,
|
|
47
|
+
platform: process.platform,
|
|
48
|
+
titleBarHeight: t.o.titleBarHeight,
|
|
49
|
+
state: s(t.win)
|
|
50
|
+
} : null;
|
|
51
|
+
}), e.on(t.action, (e, t) => {
|
|
52
|
+
let n = c(e.sender);
|
|
53
|
+
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());
|
|
54
|
+
}), e.on(t.overlay, (e, t) => {
|
|
55
|
+
let n = c(e.sender);
|
|
56
|
+
if (!n || n.win.isDestroyed() || n.o.controls !== "native" || process.platform === "darwin" || !u(t?.color) || !u(t?.symbolColor)) return;
|
|
57
|
+
let r = `${t.color}|${t.symbolColor}`;
|
|
58
|
+
r !== n.overlay && (n.overlay = r, n.win.setTitleBarOverlay({
|
|
59
|
+
color: t.color,
|
|
60
|
+
symbolColor: t.symbolColor,
|
|
61
|
+
height: n.o.titleBarHeight
|
|
62
|
+
}));
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
var u = (e) => typeof e == "string" && /^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(e);
|
|
66
|
+
function d(e, n = {}) {
|
|
67
|
+
l();
|
|
68
|
+
let i = r(n), o = e.webContents.id;
|
|
69
|
+
a.set(o, {
|
|
70
|
+
win: e,
|
|
71
|
+
o: i,
|
|
72
|
+
overlay: ""
|
|
73
|
+
});
|
|
74
|
+
let c = () => {
|
|
75
|
+
e.isDestroyed() || e.webContents.send(t.state, s(e));
|
|
76
|
+
}, u = [
|
|
77
|
+
"maximize",
|
|
78
|
+
"unmaximize",
|
|
79
|
+
"enter-full-screen",
|
|
80
|
+
"leave-full-screen",
|
|
81
|
+
"focus",
|
|
82
|
+
"blur",
|
|
83
|
+
"restore"
|
|
84
|
+
];
|
|
85
|
+
for (let t of u) e.on(t, c);
|
|
86
|
+
return e.once("closed", () => a.delete(o)), () => {
|
|
87
|
+
if (a.delete(o), !e.isDestroyed()) for (let t of u) e.off(t, c);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export { i as m3WindowOptions, d as setupM3Window };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","names":["ipcMain","IPC","BASELINE","resolve","o","m3WindowOptions","options","mac","windows","registered","stateOf","win","entry","sender","register","w","action","colors","isHex","key","c","setupM3Window","id","send","events","ev"],"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).\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 { BrowserWindow, ipcMain, type BrowserWindowConstructorOptions, type IpcMainEvent, type IpcMainInvokeEvent, type WebContents } from 'electron'\nimport { DEFAULT_TITLE_BAR_HEIGHT, IPC, type M3Controls, type M3OverlayColors, type M3WindowAction, type M3WindowInfo, type M3WindowState } from './shared'\n\nexport type { M3Controls, 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\ninterface Resolved {\n controls: M3Controls\n titleBarHeight: number\n overlay: M3OverlayColors\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 }\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 if (o.controls === 'custom') return { frame: false }\n const mac = process.platform === 'darwin'\n return {\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 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) }\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}\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 const dispose = () => {\n windows.delete(id)\n if (!win.isDestroyed()) for (const ev of events) win.off(ev as 'maximize', send)\n }\n win.once('closed', () => windows.delete(id))\n return dispose\n}\n"],"mappings":";;;AAiCA,IAAME,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;CACvC;AACF;AAGA,SAAgBC,EAAgBC,IAA2B,CAAC,GAAoC;CAC9F,IAAMF,IAAID,EAAQG,CAAO;CACzB,IAAIF,EAAE,aAAa,UAAU,OAAO,EAAE,OAAO,GAAM;CACnD,IAAMG,IAAM,QAAQ,aAAa;CACjC,OAAO;EACL,eAAe;EAGf,iBAAiBA,IAAM,KAAO;GAAE,GAAGH,EAAE;GAAS,QAAQA,EAAE;EAAe;EAEvE,GAAIG,IAAM,EAAE,sBAAsB;GAAE,GAAG;GAAI,GAAG,KAAK,OAAOH,EAAE,iBAAiB,MAAM,CAAC;EAAE,EAAE,IAAI,CAAC;CAC/F;AACF;AAGA,IAAMI,oBAAU,IAAI,IAAkE,GAClFC,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EAAe,CAAC;CAC/G,CAAC;AACH;AAEA,IAAMG,KAASE,MAA4B,OAAOA,KAAM,YAAY,gCAAgC,KAAKA,CAAC;AAO1G,SAAgBC,EAAcV,GAAoBL,IAA2B,CAAC,GAAe;CAC3FQ,EAAS;CACT,IAAMV,IAAID,EAAQG,CAAO,GACnBgB,IAAKX,EAAI,YAAY;CAC3BH,EAAQ,IAAIc,GAAI;EAAEX;EAAKP;EAAG,SAAS;CAAG,CAAC;CACvC,IAAMmB,UAAa;EAAOZ,EAAI,YAAY,KAAGA,EAAI,YAAY,KAAKV,EAAI,OAAOS,EAAQC,CAAG,CAAC;CAAE,GACrFa,IAAS;EAAC;EAAY;EAAc;EAAqB;EAAqB;EAAS;EAAQ;CAAS;CAC9G,KAAK,IAAMC,KAAMD,GAAQb,EAAI,GAAGc,GAAkBF,CAAI;CAMtD,OADAZ,EAAI,KAAK,gBAAgBH,EAAQ,OAAOc,CAAE,CAAC,SAJrB;EAEpB,IADAd,EAAQ,OAAOc,CAAE,GACb,CAACX,EAAI,YAAY,GAAG,KAAK,IAAMc,KAAMD,GAAQb,EAAI,IAAIc,GAAkBF,CAAI;CACjF;AAGF"}
|
package/dist/preload.cjs
ADDED
|
@@ -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`},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})}}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","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, 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 = { info: 'm3ui:info', state: 'm3ui:state', action: 'm3ui:action', overlay: 'm3ui:overlay' } 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 }\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,CAAE,KAAM,YAAa,MAAO,aAAc,OAAQ,cAAe,QAAS,cAAe,EAC/FC,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,CACjI,CACF,C,iFAMA,UAAmC,CACjC,IAAMC,EAASP,EAAe,EAC1B,QAAQ,gBAAiBJ,EAAAA,cAAc,kBAAkBG,EAAYQ,CAAM,EACzE,WAAkDR,GAAcQ,CACxE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
};
|
|
8
|
+
declare const BRIDGE_KEY = "m3ui";
|
|
9
|
+
export { IPC as _IPC, BRIDGE_KEY as _BRIDGE_KEY };
|
|
10
|
+
export type { M3Bridge } from './shared';
|
|
11
|
+
/** The bridge itself, to expose it yourself (it must end up as `window.m3ui`) */
|
|
12
|
+
export declare function createM3Bridge(): M3Bridge;
|
|
13
|
+
/**
|
|
14
|
+
* Exposes the bridge as `window.m3ui`, where `useElectronWindow()` and MTitleBar look for it. Uses `contextBridge`
|
|
15
|
+
* when context isolation is on (the default), a plain global otherwise.
|
|
16
|
+
*/
|
|
17
|
+
export declare function exposeM3UI(): void;
|
package/dist/preload.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
}, r = "m3ui";
|
|
9
|
+
function i() {
|
|
10
|
+
return {
|
|
11
|
+
info: () => t.invoke(n.info),
|
|
12
|
+
onState(e) {
|
|
13
|
+
let r = (t, n) => e(n);
|
|
14
|
+
return t.on(n.state, r), () => {
|
|
15
|
+
t.removeListener(n.state, r);
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
action: (e) => t.send(n.action, e),
|
|
19
|
+
setOverlay: (e) => t.send(n.overlay, {
|
|
20
|
+
color: e.color,
|
|
21
|
+
symbolColor: e.symbolColor
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function a() {
|
|
26
|
+
let t = i();
|
|
27
|
+
process.contextIsolated ? e.exposeInMainWorld(r, t) : globalThis[r] = t;
|
|
28
|
+
}
|
|
29
|
+
export { r as _BRIDGE_KEY, n as _IPC, i as createM3Bridge, a as exposeM3UI };
|
|
30
|
+
|
|
31
|
+
//# 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","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, 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 = { info: 'm3ui:info', state: 'm3ui:state', action: 'm3ui:action', overlay: 'm3ui:overlay' } 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 }\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;CAAE,MAAM;CAAa,OAAO;CAAc,QAAQ;CAAe,SAAS;AAAe,GAC/FC,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;CACjI;AACF;AAMA,SAAgBC,IAAmB;CACjC,IAAMC,IAASR,EAAe;CAC1B,QAAQ,kBAAiBJ,EAAc,kBAAkBG,GAAYS,CAAM,IACzE,WAAkDT,KAAcS;AACxE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
type Button = 'minimize' | 'maximize' | 'close';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/** The window title */
|
|
4
|
+
title?: string;
|
|
5
|
+
/** Bar color: an M3 role (`'surface-container'`) or any CSS color */
|
|
6
|
+
color?: string;
|
|
7
|
+
/** Where the title sits */
|
|
8
|
+
titleAlign?: 'start' | 'center';
|
|
9
|
+
/** Custom controls only: which buttons, in this order on the end side (mirrored on the start side) */
|
|
10
|
+
buttons?: Button[];
|
|
11
|
+
/** Custom controls only: the side they sit on; `auto` is the start on macOS, the end elsewhere */
|
|
12
|
+
side?: 'auto' | 'start' | 'end';
|
|
13
|
+
/** Custom controls only: M3 icon buttons or macOS-style traffic lights; `auto` picks by platform */
|
|
14
|
+
look?: 'auto' | 'm3' | 'traffic-lights';
|
|
15
|
+
};
|
|
16
|
+
declare const __VLS_template: () => {
|
|
17
|
+
__VLS_Slots: {
|
|
18
|
+
start?: (props: {}) => any;
|
|
19
|
+
} & {
|
|
20
|
+
default?: (props: {}) => any;
|
|
21
|
+
} & {
|
|
22
|
+
end?: (props: {}) => any;
|
|
23
|
+
} & {
|
|
24
|
+
controls?: (props: {
|
|
25
|
+
minimize: () => void;
|
|
26
|
+
toggleMaximize: () => void;
|
|
27
|
+
close: () => void;
|
|
28
|
+
maximized: boolean;
|
|
29
|
+
focused: boolean;
|
|
30
|
+
}) => any;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
34
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
35
|
+
color: string;
|
|
36
|
+
titleAlign: "start" | "center";
|
|
37
|
+
buttons: Button[];
|
|
38
|
+
side: "start" | "auto" | "end";
|
|
39
|
+
look: "auto" | "m3" | "traffic-lights";
|
|
40
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
41
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
42
|
+
declare const _default: typeof __VLS_export;
|
|
43
|
+
export default _default;
|
|
44
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
45
|
+
new (): {
|
|
46
|
+
$slots: S;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ComputedRef, type Ref } from 'vue';
|
|
2
|
+
import { type M3Controls, type M3OverlayColors } from '../shared';
|
|
3
|
+
/**
|
|
4
|
+
* The window MTitleBar sits in, from the renderer: its mode and state (reactive) and its buttons. Outside Electron (or
|
|
5
|
+
* without the preload's bridge) `isElectron` is false, nothing is ever `ready` and the actions do nothing, so the same
|
|
6
|
+
* app also runs in a browser.
|
|
7
|
+
*/
|
|
8
|
+
export interface ElectronWindow {
|
|
9
|
+
/** The preload's bridge is there */
|
|
10
|
+
isElectron: boolean;
|
|
11
|
+
/** The main process has answered (mode, platform and state are real from here on) */
|
|
12
|
+
ready: Readonly<Ref<boolean>>;
|
|
13
|
+
controls: Readonly<Ref<M3Controls>>;
|
|
14
|
+
/** `process.platform` of the main process (`''` until ready) */
|
|
15
|
+
platform: Readonly<Ref<string>>;
|
|
16
|
+
isMac: ComputedRef<boolean>;
|
|
17
|
+
titleBarHeight: Readonly<Ref<number>>;
|
|
18
|
+
maximized: Readonly<Ref<boolean>>;
|
|
19
|
+
fullscreen: Readonly<Ref<boolean>>;
|
|
20
|
+
focused: Readonly<Ref<boolean>>;
|
|
21
|
+
minimize(): void;
|
|
22
|
+
toggleMaximize(): void;
|
|
23
|
+
close(): void;
|
|
24
|
+
/** Recolors the native buttons (MTitleBar does it from the theme; for a bar of your own) */
|
|
25
|
+
setOverlay(colors: M3OverlayColors): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function useElectronWindow(): ElectronWindow;
|
|
28
|
+
/** For tests: forget the fetched state */
|
|
29
|
+
export declare function _resetElectronWindow(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-B-ScY3hE.js","names":["IPC","BRIDGE_KEY"],"sources":["../src/shared.ts"],"sourcesContent":["/**\n * The contract between the three sides: main (`@m3ui-vue/electron/main`), preload (`/preload`) and the renderer\n * (`@m3ui-vue/electron`). Types and IPC channel names only, no runtime dependency on either side.\n */\n\n/**\n * Who draws the window buttons.\n * - `native`: the system does (`titleBarStyle: 'hidden'` + `titleBarOverlay`): Windows 11 snap layouts, macOS\n * traffic lights, Linux's own buttons; their colors follow the M3 theme live.\n * - `custom`: a frameless window (`frame: false`) and MTitleBar draws M3 buttons (or traffic lights) itself.\n */\nexport type M3Controls = 'native' | 'custom'\n\n/** What the main process says about the window, once, when the renderer asks */\nexport interface M3WindowInfo {\n controls: M3Controls\n /** `process.platform` of the main process: `'darwin'`, `'win32'`, `'linux'`… */\n platform: string\n /** Height of the title bar in px (also the native overlay's height) */\n titleBarHeight: number\n state: M3WindowState\n}\n\n/** The window's state, sent again on every change */\nexport interface M3WindowState {\n maximized: boolean\n fullscreen: boolean\n focused: boolean\n}\n\nexport type M3WindowAction = 'minimize' | 'toggle-maximize' | 'close'\n\n/** Colors of the native buttons (Windows/Linux `titleBarOverlay`), as hex */\nexport interface M3OverlayColors {\n color: string\n symbolColor: string\n}\n\n/** What the preload exposes to the page (`window.m3ui` by default) */\nexport interface M3Bridge {\n /** Resolves with the window's mode and state */\n info(): Promise<M3WindowInfo>\n /** Calls `listener` on every state change; returns the unsubscribe */\n onState(listener: (state: M3WindowState) => void): () => void\n action(action: M3WindowAction): void\n /** Recolors the native buttons (ignored with `custom` controls and on macOS, whose traffic lights are fixed) */\n setOverlay(colors: M3OverlayColors): void\n}\n\nexport const IPC = {\n info: 'm3ui:info',\n state: 'm3ui:state',\n action: 'm3ui:action',\n overlay: 'm3ui:overlay',\n} as const\n\n/** The default key the bridge is exposed under (`window.m3ui`) */\nexport const BRIDGE_KEY = 'm3ui'\n\n/** Default title bar height: Windows 11 caption buttons are 32px, GNOME header bars ~46px; 40 sits between */\nexport const DEFAULT_TITLE_BAR_HEIGHT = 40\n"],"mappings":";AAiDA,IAAaA,IAAM;CACjB,MAAM;CACN,OAAO;CACP,QAAQ;CACR,SAAS;AACX,GAGaC,IAAa"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e={info:`m3ui:info`,state:`m3ui:state`,action:`m3ui:action`,overlay:`m3ui:overlay`},t=`m3ui`;Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
|
|
2
|
+
//# sourceMappingURL=shared-CWEPeNW8.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-CWEPeNW8.cjs","names":["IPC","BRIDGE_KEY"],"sources":["../src/shared.ts"],"sourcesContent":["/**\n * The contract between the three sides: main (`@m3ui-vue/electron/main`), preload (`/preload`) and the renderer\n * (`@m3ui-vue/electron`). Types and IPC channel names only, no runtime dependency on either side.\n */\n\n/**\n * Who draws the window buttons.\n * - `native`: the system does (`titleBarStyle: 'hidden'` + `titleBarOverlay`): Windows 11 snap layouts, macOS\n * traffic lights, Linux's own buttons; their colors follow the M3 theme live.\n * - `custom`: a frameless window (`frame: false`) and MTitleBar draws M3 buttons (or traffic lights) itself.\n */\nexport type M3Controls = 'native' | 'custom'\n\n/** What the main process says about the window, once, when the renderer asks */\nexport interface M3WindowInfo {\n controls: M3Controls\n /** `process.platform` of the main process: `'darwin'`, `'win32'`, `'linux'`… */\n platform: string\n /** Height of the title bar in px (also the native overlay's height) */\n titleBarHeight: number\n state: M3WindowState\n}\n\n/** The window's state, sent again on every change */\nexport interface M3WindowState {\n maximized: boolean\n fullscreen: boolean\n focused: boolean\n}\n\nexport type M3WindowAction = 'minimize' | 'toggle-maximize' | 'close'\n\n/** Colors of the native buttons (Windows/Linux `titleBarOverlay`), as hex */\nexport interface M3OverlayColors {\n color: string\n symbolColor: string\n}\n\n/** What the preload exposes to the page (`window.m3ui` by default) */\nexport interface M3Bridge {\n /** Resolves with the window's mode and state */\n info(): Promise<M3WindowInfo>\n /** Calls `listener` on every state change; returns the unsubscribe */\n onState(listener: (state: M3WindowState) => void): () => void\n action(action: M3WindowAction): void\n /** Recolors the native buttons (ignored with `custom` controls and on macOS, whose traffic lights are fixed) */\n setOverlay(colors: M3OverlayColors): void\n}\n\nexport const IPC = {\n info: 'm3ui:info',\n state: 'm3ui:state',\n action: 'm3ui:action',\n overlay: 'm3ui:overlay',\n} as const\n\n/** The default key the bridge is exposed under (`window.m3ui`) */\nexport const BRIDGE_KEY = 'm3ui'\n\n/** Default title bar height: Windows 11 caption buttons are 32px, GNOME header bars ~46px; 40 sits between */\nexport const DEFAULT_TITLE_BAR_HEIGHT = 40\n"],"mappings":"AAiDA,IAAaA,EAAM,CACjB,KAAM,YACN,MAAO,aACP,OAAQ,cACR,QAAS,cACX,EAGaC,EAAa,O"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between the three sides: main (`@m3ui-vue/electron/main`), preload (`/preload`) and the renderer
|
|
3
|
+
* (`@m3ui-vue/electron`). Types and IPC channel names only, no runtime dependency on either side.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Who draws the window buttons.
|
|
7
|
+
* - `native`: the system does (`titleBarStyle: 'hidden'` + `titleBarOverlay`): Windows 11 snap layouts, macOS
|
|
8
|
+
* traffic lights, Linux's own buttons; their colors follow the M3 theme live.
|
|
9
|
+
* - `custom`: a frameless window (`frame: false`) and MTitleBar draws M3 buttons (or traffic lights) itself.
|
|
10
|
+
*/
|
|
11
|
+
export type M3Controls = 'native' | 'custom';
|
|
12
|
+
/** What the main process says about the window, once, when the renderer asks */
|
|
13
|
+
export interface M3WindowInfo {
|
|
14
|
+
controls: M3Controls;
|
|
15
|
+
/** `process.platform` of the main process: `'darwin'`, `'win32'`, `'linux'`… */
|
|
16
|
+
platform: string;
|
|
17
|
+
/** Height of the title bar in px (also the native overlay's height) */
|
|
18
|
+
titleBarHeight: number;
|
|
19
|
+
state: M3WindowState;
|
|
20
|
+
}
|
|
21
|
+
/** The window's state, sent again on every change */
|
|
22
|
+
export interface M3WindowState {
|
|
23
|
+
maximized: boolean;
|
|
24
|
+
fullscreen: boolean;
|
|
25
|
+
focused: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type M3WindowAction = 'minimize' | 'toggle-maximize' | 'close';
|
|
28
|
+
/** Colors of the native buttons (Windows/Linux `titleBarOverlay`), as hex */
|
|
29
|
+
export interface M3OverlayColors {
|
|
30
|
+
color: string;
|
|
31
|
+
symbolColor: string;
|
|
32
|
+
}
|
|
33
|
+
/** What the preload exposes to the page (`window.m3ui` by default) */
|
|
34
|
+
export interface M3Bridge {
|
|
35
|
+
/** Resolves with the window's mode and state */
|
|
36
|
+
info(): Promise<M3WindowInfo>;
|
|
37
|
+
/** Calls `listener` on every state change; returns the unsubscribe */
|
|
38
|
+
onState(listener: (state: M3WindowState) => void): () => void;
|
|
39
|
+
action(action: M3WindowAction): void;
|
|
40
|
+
/** Recolors the native buttons (ignored with `custom` controls and on macOS, whose traffic lights are fixed) */
|
|
41
|
+
setOverlay(colors: M3OverlayColors): void;
|
|
42
|
+
}
|
|
43
|
+
export declare const IPC: {
|
|
44
|
+
readonly info: "m3ui:info";
|
|
45
|
+
readonly state: "m3ui:state";
|
|
46
|
+
readonly action: "m3ui:action";
|
|
47
|
+
readonly overlay: "m3ui:overlay";
|
|
48
|
+
};
|
|
49
|
+
/** The default key the bridge is exposed under (`window.m3ui`) */
|
|
50
|
+
export declare const BRIDGE_KEY = "m3ui";
|
|
51
|
+
/** Default title bar height: Windows 11 caption buttons are 32px, GNOME header bars ~46px; 40 sits between */
|
|
52
|
+
export declare const DEFAULT_TITLE_BAR_HEIGHT = 40;
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
@layer base{.m3-title-bar{width:100%;color:var(--color-on-surface);-webkit-user-select:none;user-select:none;app-region:drag;-webkit-app-region:drag;flex-shrink:0;display:block;position:relative}}.m3-title-bar :is(button,a,input,select,textarea,[role=button],[contenteditable],[data-no-drag]){app-region:no-drag;-webkit-app-region:no-drag}.m3-title-bar-area{box-sizing:border-box;align-items:center;gap:8px;height:100%;padding-inline:8px;display:flex}.m3-title-bar-native .m3-title-bar-area{inset-block:0;left:env(titlebar-area-x,0px);width:env(titlebar-area-width,100%);position:absolute}.m3-title-bar-start,.m3-title-bar-end{align-items:center;gap:4px;min-width:0;display:flex}.m3-title-bar-start:empty,.m3-title-bar-end:empty{display:none}.m3-title-bar-title{white-space:nowrap;text-overflow:ellipsis;min-width:0;font-size:var(--text-title-small,.875rem);line-height:var(--text-title-small--line-height,1.25rem);letter-spacing:.006em;flex:1;padding-inline:4px;font-weight:500;transition:color .15s;overflow:hidden}.m3-title-bar-center .m3-title-bar-title{text-align:center}.m3-title-bar-blurred .m3-title-bar-title{color:var(--color-on-surface-variant)}.m3-title-bar-probe{width:0;height:0;color:var(--color-on-surface-variant);position:absolute;overflow:hidden}.m3-title-bar-side{flex-shrink:0;display:flex}.m3-title-bar-controls-start{order:-1}.m3-title-bar-controls{flex-shrink:0;align-items:center;gap:4px;display:flex}.m3-title-bar-btn{width:32px;height:32px;color:var(--color-on-surface-variant);cursor:default;background:0 0;border:0;border-radius:9999px;outline:none;justify-content:center;align-items:center;padding:0;transition:background-color .15s,color .15s;display:inline-flex}.m3-title-bar-btn:hover{background-color:color-mix(in srgb, var(--color-on-surface-variant) 8%, transparent)}.m3-title-bar-btn:active{background-color:color-mix(in srgb, var(--color-on-surface-variant) 10%, transparent)}.m3-title-bar-btn:focus-visible{box-shadow:0 0 0 2px var(--color-secondary)}.m3-title-bar-btn-close:hover{color:var(--color-error);background-color:color-mix(in srgb, var(--color-error) 8%, transparent)}.m3-title-bar-btn-close:active{background-color:color-mix(in srgb, var(--color-error) 10%, transparent)}.m3-title-bar-lights{gap:8px;padding-inline:6px}.m3-title-bar-lights .m3-title-bar-btn{color:#0000008c;width:12px;height:12px;box-shadow:inset 0 0 0 .5px #0000002e}.m3-title-bar-lights .m3-title-bar-btn svg{fill:none;stroke:currentColor;stroke-width:1.4px;stroke-linecap:round;opacity:0;width:8px;height:8px}.m3-title-bar-lights:hover .m3-title-bar-btn svg,.m3-title-bar-lights .m3-title-bar-btn:focus-visible svg{opacity:1}.m3-title-bar-lights .m3-title-bar-btn-close{background-color:#ff5f57}.m3-title-bar-lights .m3-title-bar-btn-minimize{background-color:#febc2e}.m3-title-bar-lights .m3-title-bar-btn-maximize{background-color:#28c840}.m3-title-bar-lights .m3-title-bar-btn:hover,.m3-title-bar-lights .m3-title-bar-btn-close:hover{color:#0000008c;filter:brightness(.94)}.m3-title-bar-blurred .m3-title-bar-lights:not(:hover) .m3-title-bar-btn{background-color:color-mix(in srgb, var(--color-on-surface) 20%, transparent);box-shadow:none}
|
|
2
|
+
/*$vite$:1*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m3ui-vue/electron",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Electron integration for m3ui-vue: a Material Design 3 title bar with native or custom window controls, themed live from the M3 tokens",
|
|
5
|
+
"keywords": ["electron", "material-design", "material-3", "m3", "vue", "title-bar", "window-controls-overlay", "tailwindcss"],
|
|
6
|
+
"homepage": "https://m3ui.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/m3ui-vue/m3ui-vue-electron.git"
|
|
10
|
+
},
|
|
11
|
+
"funding": "https://github.com/sponsors/SrWither",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": ["**/*.css"],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./main": {
|
|
21
|
+
"types": "./dist/main.d.ts",
|
|
22
|
+
"import": "./dist/main.js",
|
|
23
|
+
"require": "./dist/main.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./preload": {
|
|
26
|
+
"types": "./dist/preload.d.ts",
|
|
27
|
+
"import": "./dist/preload.js",
|
|
28
|
+
"require": "./dist/preload.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./styles": "./dist/styles.css"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"files": ["dist"],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "vite build && vue-tsc -p tsconfig.build.json",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:watch": "vitest",
|
|
39
|
+
"typecheck": "vue-tsc -p tsconfig.build.json --noEmit",
|
|
40
|
+
"prepack": "pnpm build"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@m3ui-vue/m3ui-vue": "^1.12.0",
|
|
44
|
+
"electron": ">=33",
|
|
45
|
+
"vue": "^3.5.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"electron": { "optional": true }
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@m3ui-vue/m3ui-vue": "^1.12.0",
|
|
52
|
+
"@types/node": "^24.0.0",
|
|
53
|
+
"@vitejs/plugin-vue": "^6.0.11",
|
|
54
|
+
"@vue/test-utils": "^2.6.0",
|
|
55
|
+
"@vue/tsconfig": "^0.9.1",
|
|
56
|
+
"electron": "^45.6.1",
|
|
57
|
+
"happy-dom": "^21.0.4",
|
|
58
|
+
"typescript": "~6.0.3",
|
|
59
|
+
"vite": "^8.3.8",
|
|
60
|
+
"vitest": "^5.1.1",
|
|
61
|
+
"vue": "^3.5.46",
|
|
62
|
+
"vue-tsc": "^3.3.14"
|
|
63
|
+
},
|
|
64
|
+
"packageManager": "pnpm@12.11.2"
|
|
65
|
+
}
|