@stacksjs/desktop 0.2.638 → 0.2.640

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/dist/browser.d.ts CHANGED
@@ -54,7 +54,8 @@ export * from './network';
54
54
  export * from './notifications';
55
55
  export * from './pdf';
56
56
  export * from './permissions';
57
- export * from './power';
57
+ // Host IOKit assertions require bun:ffi. Import them from the host entry.
58
+ // In-window power operations belong to Craft's native bridge.
58
59
  export * from './printing';
59
60
  export * from './screen';
60
61
  export * from './screen-capture';
package/dist/browser.js CHANGED
@@ -1,2 +1,345 @@
1
- // @bun
2
- import{P,c,r,S,k,A,C,I,T,E,M,D,t,p,B,O,R,f,L,_,N,F,W,z,H,U,n,q,V,j,K,G,Y,X,l,J,Q,Z,ee,m,te,re,g,ne,oe,ie,ae,se,ce,le,de,ue,pe,fe,me,ge,he,we,be,xe,ye,ve,Pe,Se,ke,Ae,Ce,h,Ie,$e,Te,Ee,Me,De,Be,Oe,Re,o,w,b,Le,i,_e,Ne,Fe,x,y,a,s,We,d,ze,He,Ue,qe,Ve,je,Ke,Ge,Ye,Xe,Je,Qe,Ze,et,tt,rt,nt,ot,it,at,v,st}from"./chunk-tyk2bp3f.js";export{a as DEFAULT_WATCH_INTERVAL_MS,y as MAX_WATCH_INTERVAL_MS,x as MIN_WATCH_INTERVAL_MS,z as MODAL_STYLES,D as TOAST_STYLES,_ as alert,Se as app,je as appleScript,Ve as audio,xe as battery,qe as biometric,Oe as bluetooth,Je as bonjour,X as caffeinate,de as clipboard,W as closeAllModals,L as confirm,Ce as contextMenu,nt as continuityCamera,rt as coreml,o as crashReporter,ae as createInterval,ie as createTimer,l as decaffeinate,be as deepLinks,se as delay,T as dismissAlertById,E as dismissAllAlerts,he as dragOut,Ke as fileAssociations,d as focus,He as focusShortcutsReady,le as formatCompact,ee as formatDuration,Z as formatRemainingTime,te as formatShortcut,ce as formatTime,pe as fs,M as getActiveAlertCount,F as getActiveModalCount,Q as getCaffeinateStatus,at as getCapabilities,v as getCapability,Y as getDialogBridgeScript,oe as getRegisteredHotkeys,me as globalShortcuts,i as handoff,ze as hasFocusShortcuts,Le as iap,st as isAvailable,J as isCaffeinated,we as isDragOutAvailable,$e as keychain,_e as liveActivities,Ue as localServer,Ne as location,Xe as log,Ae as menu,tt as midi,Me as nativeAutoLaunch,De as nativeWindow,ye as network,ue as notifications,I as notify,m as parseShortcut,Ye as pdf,Te as permissions,Ee as printing,N as prompt,w as redactPII,re as registerHotkey,P as requestNotificationPermission,Ie as screen,Fe as screenCapture,s as screenSharing,it as serial,ot as serviceMenu,fe as shell,c as showAlert,V as showAlertDialog,q as showColorPicker,j as showConfirmDialog,K as showErrorDialog,O as showErrorModal,C as showErrorToast,p as showInfoModal,S as showInfoToast,n as showMessageBox,t as showModal,H as showOpenDialog,f as showQuestionModal,U as showSaveDialog,R as showSuccessModal,k as showSuccessToast,r as showToast,G as showWarningDialog,B as showWarningModal,A as showWarningToast,h as sidebar,b as signPayload,Re as speech,Ze as speechRecognition,Qe as spotlight,ke as standardMenus,Ge as tags,ge as theme,Be as touchbar,ne as unregisterAllHotkeys,g as unregisterHotkey,ve as updater,et as vision,We as watchScreenSharing,Pe as windowEvents};
1
+ function Be(){if(typeof Notification<"u"&&Notification.permission==="granted")return!0;return!1}function U(){return typeof window<"u"&&typeof document<"u"}async function At(){if(typeof Notification>"u")return!1;if(Notification.permission==="granted")return!0;if(Notification.permission==="denied")return!1;return await Notification.requestPermission()==="granted"}var x=new Map;function De(){return`alert-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function Te(e){switch(e){case"info":return"&#x2139;";case"success":return"&#x2714;";case"warning":return"&#x26A0;";case"error":return"&#x2716;";default:return"&#x2139;"}}function Re(e="top-right"){if(!U())throw Error("Toast container requires browser environment");try{let n=document.querySelector(`.stx-toast-container[data-position="${e}"]`);if(n)return n}catch{}let t=document.createElement("div");t.className=`stx-toast-container ${e}`,t.dataset.position=e;try{if(document.body)document.body.appendChild(t)}catch{}return t}function Le(e){let{options:t}=e,n=Te(t.type),i=t.type||"info",o=t.duration!==0;return`
2
+ <div class="stx-toast ${i}" data-alert-id="${e.id}" role="alert" aria-live="polite">
3
+ <div class="stx-toast-icon">${n}</div>
4
+ <div class="stx-toast-content">
5
+ ${t.title?`<div class="stx-toast-title">${ne(t.title)}</div>`:""}
6
+ <div class="stx-toast-message">${ne(t.message)}</div>
7
+ </div>
8
+ ${o?'<button class="stx-toast-close" aria-label="Close">&times;</button>':""}
9
+ </div>
10
+ `}function ne(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function B(e){if(e.timeout)clearTimeout(e.timeout);if(x.delete(e.id),e.element&&U())e.element.classList.add("dismissing"),setTimeout(()=>{e.element?.remove()},200)}async function ie(e){let t=De(),n=Be(),i=e.duration??5000,o={id:t,options:e};if(x.set(t,o),n&&e.type!=="error")try{let s=new Notification(e.title||"Notification",{body:e.message,icon:e.type==="success"?"✓":e.type==="warning"?"⚠":"ℹ",tag:t});if(s.onclick=()=>{if(e.onClick)e.onClick();s.close()},i>0)o.timeout=setTimeout(()=>{s.close(),x.delete(t)},i);return}catch{}if(U())try{let s=Re(e.position),c=document.createElement("div");c.innerHTML=Le(o);let d=c.firstElementChild;if(!d){let l=(e.type||"info").toUpperCase();console.log(`[stx-alert] ${l}: ${e.title||""}`),console.log(`[stx-alert] ${e.message}`);return}o.element=d;try{s.appendChild(d)}catch{let l=(e.type||"info").toUpperCase();console.log(`[stx-alert] ${l}: ${e.title||""}`),console.log(`[stx-alert] ${e.message}`);return}if(typeof requestAnimationFrame==="function")requestAnimationFrame(()=>{try{d.classList.add("visible")}catch{}});try{d.addEventListener("click",(l)=>{if(l.target.classList?.contains("stx-toast-close")){B(o);return}if(e.onClick)e.onClick()})}catch{}if(i>0)o.timeout=setTimeout(()=>{B(o)},i)}catch{let s=(e.type||"info").toUpperCase();console.log(`[stx-alert] ${s}: ${e.title||""}`),console.log(`[stx-alert] ${e.message}`)}else{let s=(e.type||"info").toUpperCase();if(console.log(`[stx-alert] ${s}: ${e.title||""}`),console.log(`[stx-alert] ${e.message}`),i>0)o.timeout=setTimeout(()=>{x.delete(t)},i)}}async function D(e){return ie({...e,position:e.position||"top-right"})}async function It(e,t=3000){return D({message:e,type:"info",duration:t})}async function kt(e,t=3000){return D({message:e,type:"success",duration:t})}async function Et(e,t=3000){return D({message:e,type:"warning",duration:t})}async function Ct(e,t=5000){return D({message:e,type:"error",duration:t})}async function Mt(e,t,n="info"){return ie({title:e,message:t,type:n})}function Bt(e){let t=x.get(e);if(t)B(t)}function Dt(){for(let e of x.values())B(e)}function Tt(){return x.size}var Rt=`
11
+ .stx-toast-container {
12
+ position: fixed;
13
+ z-index: 10001;
14
+ display: flex;
15
+ flex-direction: column;
16
+ gap: 8px;
17
+ max-width: 400px;
18
+ pointer-events: none;
19
+ }
20
+
21
+ .stx-toast-container.top-left { top: 16px; left: 16px; }
22
+ .stx-toast-container.top-center { top: 16px; left: 50%; transform: translateX(-50%); }
23
+ .stx-toast-container.top-right { top: 16px; right: 16px; }
24
+ .stx-toast-container.bottom-left { bottom: 16px; left: 16px; }
25
+ .stx-toast-container.bottom-center { bottom: 16px; left: 50%; transform: translateX(-50%); }
26
+ .stx-toast-container.bottom-right { bottom: 16px; right: 16px; }
27
+
28
+ .stx-toast {
29
+ display: flex;
30
+ align-items: flex-start;
31
+ gap: 12px;
32
+ padding: 12px 16px;
33
+ background: #fff;
34
+ border-radius: 8px;
35
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
36
+ pointer-events: auto;
37
+ cursor: pointer;
38
+ opacity: 0;
39
+ transform: translateY(-10px);
40
+ transition: opacity 0.2s, transform 0.2s;
41
+ }
42
+
43
+ .stx-toast.visible {
44
+ opacity: 1;
45
+ transform: translateY(0);
46
+ }
47
+
48
+ .stx-toast.dismissing {
49
+ opacity: 0;
50
+ transform: translateX(100%);
51
+ }
52
+
53
+ @media (prefers-color-scheme: dark) {
54
+ .stx-toast {
55
+ background: #2d2d2d;
56
+ color: #fff;
57
+ }
58
+ }
59
+
60
+ .stx-toast-icon {
61
+ font-size: 20px;
62
+ flex-shrink: 0;
63
+ margin-top: 2px;
64
+ }
65
+
66
+ .stx-toast.info .stx-toast-icon { color: #3498db; }
67
+ .stx-toast.success .stx-toast-icon { color: #27ae60; }
68
+ .stx-toast.warning .stx-toast-icon { color: #f39c12; }
69
+ .stx-toast.error .stx-toast-icon { color: #e74c3c; }
70
+
71
+ .stx-toast-content {
72
+ flex: 1;
73
+ min-width: 0;
74
+ }
75
+
76
+ .stx-toast-title {
77
+ font-weight: 600;
78
+ margin-bottom: 4px;
79
+ }
80
+
81
+ .stx-toast-message {
82
+ color: #666;
83
+ font-size: 14px;
84
+ line-height: 1.4;
85
+ }
86
+
87
+ @media (prefers-color-scheme: dark) {
88
+ .stx-toast-message { color: #aaa; }
89
+ }
90
+
91
+ .stx-toast-close {
92
+ background: none;
93
+ border: none;
94
+ font-size: 20px;
95
+ cursor: pointer;
96
+ opacity: 0.5;
97
+ padding: 0;
98
+ line-height: 1;
99
+ color: inherit;
100
+ transition: opacity 0.15s;
101
+ }
102
+
103
+ .stx-toast-close:hover {
104
+ opacity: 1;
105
+ }
106
+
107
+ /* Border accent for different types */
108
+ .stx-toast.info { border-left: 4px solid #3498db; }
109
+ .stx-toast.success { border-left: 4px solid #27ae60; }
110
+ .stx-toast.warning { border-left: 4px solid #f39c12; }
111
+ .stx-toast.error { border-left: 4px solid #e74c3c; }
112
+ `;function r(e){if(typeof window>"u")return!1;let t=window.craft;return!!(t&&t[e])}function u(e){if(!r(e))throw Error(`craft.${e} is not available — this API requires a Craft native window`);return window.craft[e]}function a(e,t){if(typeof window>"u")return()=>{};let n=(i)=>t(i.detail??{});return window.addEventListener(e,n),()=>window.removeEventListener(e,n)}var oe={name:"",version:"0.0.0"},Ft={async hideDockIcon(){if(r("app"))await window.craft.app.hideDockIcon()},async showDockIcon(){if(r("app"))await window.craft.app.showDockIcon()},async quit(){if(r("app"))await window.craft.app.quit()},async getInfo(){if(!r("app"))return oe;let e=await window.craft.app.getInfo();return{...oe,...e||{}}},async notify(e){if(!e.title)throw Error("notify: title is required");if(r("app"))await window.craft.app.notify(e)},async setBadge(e){if(r("app"))await window.craft.app.setBadge(e)},async bounce(e="informational"){if(r("app"))await window.craft.app.bounce(e)}};var Ut={async execute(e){if(!e)throw Error("appleScript.execute: source is required");if(!r("appleScript"))return{ok:!1};return await window.craft.appleScript.execute(e)}};var p=null,$t={async play(e,t){if(r("audio"))return await window.craft.audio.play(e,t);if(typeof window>"u"||typeof Audio>"u")return!1;if(p)p.pause(),p=null;if(p=new Audio(e),t?.volume!=null)p.volume=t.volume;if(t?.loops)p.loop=!0;try{return await p.play(),!0}catch{return!1}},async playSystemSound(e){if(r("audio"))return await window.craft.audio.playSystemSound(e);if(typeof window>"u"||typeof Audio>"u")return!1;try{return p=new Audio(`/System/Library/Sounds/${e}.aiff`),await p.play(),!0}catch{return!1}},async stop(){if(r("audio")){await window.craft.audio.stop();return}if(p)p.pause(),p.currentTime=0,p=null},async isPlaying(){if(r("audio"))return await window.craft.audio.isPlaying();return!!(p&&!p.paused)},async startRecording(e,t){if(r("audio"))return await window.craft.audio.startRecording(e,t);return!1},async stopRecording(){if(r("audio"))await window.craft.audio.stopRecording()},async isRecording(){if(r("audio"))return await window.craft.audio.isRecording();return!1}};var jt={async isCharging(){if(r("power"))return await window.craft.power.isCharging();let e=await T();return e?!!e.charging:!1},async isPluggedIn(){if(r("power"))return await window.craft.power.isPluggedIn();let e=await T();return e?!!e.charging||e.level>=0.999:!1},async isLowPowerMode(){if(r("power"))return await window.craft.power.isLowPowerMode();return!1},async level(){if(r("power")){let t=await window.craft.power.batteryLevel();return typeof t==="number"?t:null}let e=await T();return e?e.level:null},async timeRemaining(){if(r("power")){let n=await window.craft.power.timeRemaining();return typeof n==="number"?n:null}let e=await T();if(!e)return null;let t=e.charging?e.chargingTime:e.dischargingTime;return Number.isFinite(t)?Math.round(t/60):null},async thermalState(){if(r("power"))return await window.craft.power.thermalState()||"unknown";return"unknown"},async uptimeSeconds(){if(r("power"))return await window.craft.power.uptimeSeconds();if(typeof performance<"u"&&typeof performance.now==="function")return Math.round(performance.now()/1000);return 0},async preventSleep(e="app is busy"){if(r("power")){await window.craft.power.preventSleep(e);return}if(typeof navigator>"u"||!navigator.wakeLock)return;let t=window;if(t.__craftWebWakeLock?.release){try{await t.__craftWebWakeLock.release()}catch{}t.__craftWebWakeLock=null}try{let n=await navigator.wakeLock.request("screen");t.__craftWebWakeLock=n}catch{}},async allowSleep(){if(r("power")){await window.craft.power.allowSleep();return}let e=window.__craftWebWakeLock;if(e&&typeof e.release==="function"){try{await e.release()}catch{}window.__craftWebWakeLock=null}},onSleep(e){return a("craft:powerSleep",e)},onWake(e){return a("craft:powerWake",e)}};async function T(){if(typeof navigator>"u")return null;let e=navigator;if(typeof e.getBattery!=="function")return null;try{return await e.getBattery()}catch{return null}}var Gt={async isAvailable(){if(!r("biometric"))return!1;return await window.craft.biometric.isAvailable()},async getBiometryType(){if(!r("biometric"))return"none";return await window.craft.biometric.getBiometryType()},async evaluate(e,t){if(!e)throw Error("biometric.evaluate: reason is required");if(!r("biometric"))return{success:!1,errorCode:-1};return await window.craft.biometric.evaluate(e,t)}};var Oe=/^[\da-f]*$/i;function _e(e,t){if(typeof t!=="string"||!Oe.test(t)||t.length%2!==0)throw Error(`${e}: must be a hex string with even length, got ${JSON.stringify(t)}`)}var Qt={async isEnabled(){return r("bluetooth")?await window.craft.bluetooth.isEnabled():!1},async powerState(){return r("bluetooth")?await window.craft.bluetooth.powerState():"unknown"},async connectedDevices(){return r("bluetooth")?await window.craft.bluetooth.connectedDevices():[]},async pairedDevices(){return r("bluetooth")?await window.craft.bluetooth.pairedDevices():[]},async startDiscovery(){if(r("bluetooth"))await window.craft.bluetooth.startDiscovery()},async stopDiscovery(){if(r("bluetooth"))await window.craft.bluetooth.stopDiscovery()},async isDiscovering(){return r("bluetooth")?await window.craft.bluetooth.isDiscovering():!1},async connect(e){if(r("bluetooth"))await window.craft.bluetooth.connect(e)},async disconnect(e){if(r("bluetooth"))await window.craft.bluetooth.disconnect(e)},async openPreferences(){if(r("bluetooth"))await window.craft.bluetooth.openPreferences()},async discoverServices(e){if(!e)throw Error("bluetooth.discoverServices: deviceId is required");if(!r("bluetooth"))return[];let t=await window.craft.bluetooth.discoverServices(e);return Array.isArray(t)?t:[]},async discoverCharacteristics(e,t){if(!e||!t)throw Error("bluetooth.discoverCharacteristics: deviceId and serviceUuid are required");if(!r("bluetooth"))return[];let n=await window.craft.bluetooth.discoverCharacteristics(e,t);return Array.isArray(n)?n:[]},async readCharacteristic(e,t,n){if(!e||!t||!n)throw Error("bluetooth.readCharacteristic: deviceId, serviceUuid, characteristicUuid are required");if(!r("bluetooth"))return{ok:!1,reason:"bridge unavailable"};return await window.craft.bluetooth.readCharacteristic(e,t,n)},async writeCharacteristic(e,t,n,i,o="with-response"){if(!e||!t||!n)throw Error("bluetooth.writeCharacteristic: deviceId, serviceUuid, characteristicUuid are required");if(_e("bluetooth.writeCharacteristic.valueHex",i),!r("bluetooth"))return{ok:!1,reason:"bridge unavailable"};return await window.craft.bluetooth.writeCharacteristic(e,t,n,i,o)},async setCharacteristicNotify(e,t,n,i){if(!e||!t||!n)throw Error("bluetooth.setCharacteristicNotify: deviceId, serviceUuid, characteristicUuid are required");if(!r("bluetooth"))return{ok:!1,reason:"bridge unavailable"};return await window.craft.bluetooth.setCharacteristicNotify(e,t,n,i)},onDeviceFound(e){return a("craft:bluetooth:deviceFound",e)},onDeviceConnected(e){return a("craft:bluetooth:deviceConnected",e)},onDeviceDisconnected(e){return a("craft:bluetooth:deviceDisconnected",e)},onCharacteristicValue(e){return a("craft:bluetooth:characteristicValue",e)}};var tr={async browse(e){if(!r("bonjour"))return{started:!1,reason:"bridge unavailable"};return await window.craft.bonjour.browse(e)},async stop(){if(r("bonjour"))await window.craft.bonjour.stop()},onFound(e){return a("craft:bonjour:found",e)},onLost(e){return a("craft:bonjour:lost",e)}};var ae=[{name:"fs",support:"native"},{name:"shell",support:"native"},{name:"system",support:"all"},{name:"clipboard",support:"all"},{name:"dialog",support:"all"},{name:"window",support:"native"},{name:"tray",support:"native"},{name:"menu",support:"native"},{name:"theme",support:"all"},{name:"screen",support:"all"},{name:"network",support:"all"},{name:"power",support:"all"},{name:"battery",support:"all"},{name:"notifications",support:"all"},{name:"globalShortcuts",support:"native"},{name:"autolaunch",support:"native"},{name:"appInfo",support:"all"},{name:"localServer",support:"native"},{name:"bluetooth",support:"native"},{name:"crashReporter",support:"all"},{name:"updater",support:"native"},{name:"iap",support:"macos"},{name:"keychain",support:"native"},{name:"log",support:"all"},{name:"biometric",support:"macos"},{name:"location",support:"macos"},{name:"audio",support:"macos"},{name:"deepLink",support:"native"},{name:"handoff",support:"macos"},{name:"liveActivities",support:"macos"},{name:"touchbar",support:"macos"},{name:"dragOut",support:"macos"},{name:"appleScript",support:"macos"},{name:"fileAssociations",support:"native"},{name:"tags",support:"macos"},{name:"pdf",support:"macos"},{name:"bonjour",support:"macos"},{name:"spotlight",support:"macos"},{name:"speechRecognition",support:"macos"},{name:"vision",support:"macos"},{name:"midi",support:"macos"},{name:"coreml",support:"macos"},{name:"continuityCamera",support:"macos"},{name:"serviceMenu",support:"macos"},{name:"serial",support:"native"}];function ir(){return ae.map(({name:e,support:t})=>({name:e,support:t,available:r(e)}))}function Fe(e){let t=ae.find((n)=>n.name===e);if(!t)return;return{...t,available:r(e)}}function or(e){let t=Fe(e);return!!t&&t.available}var cr={async writeText(e){if(r("clipboard")){await window.craft.clipboard.writeText(e);return}if(typeof navigator<"u"&&navigator.clipboard)await navigator.clipboard.writeText(e)},async readText(){if(r("clipboard")){let e=await window.craft.clipboard.readText();return typeof e==="string"?e:""}if(typeof navigator<"u"&&navigator.clipboard?.readText)try{return await navigator.clipboard.readText()}catch{return""}return""},async writeHTML(e){if(r("clipboard")){await window.craft.clipboard.writeHTML(e);return}if(typeof navigator<"u"&&navigator.clipboard?.write)try{let t=new window.ClipboardItem({"text/html":new Blob([e],{type:"text/html"}),"text/plain":new Blob([Ne(e)],{type:"text/plain"})});await navigator.clipboard.write([t])}catch{}},async readHTML(){if(r("clipboard")){let e=await window.craft.clipboard.readHTML();return typeof e==="string"?e:""}if(typeof navigator<"u"&&navigator.clipboard?.read)try{let e=await navigator.clipboard.read();for(let t of e)if(t.types.includes("text/html"))return await(await t.getType("text/html")).text()}catch{}return""},async clear(){if(r("clipboard")){await window.craft.clipboard.clear();return}if(typeof navigator<"u"&&navigator.clipboard?.writeText)try{await navigator.clipboard.writeText("")}catch{}},async hasText(){if(r("clipboard"))return await window.craft.clipboard.hasText();return(await this.readText()).length>0},async hasHTML(){if(r("clipboard"))return await window.craft.clipboard.hasHTML();return(await this.readHTML()).length>0},async hasImage(){if(r("clipboard"))return await window.craft.clipboard.hasImage();return!1}};function Ne(e){return e.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi,"").replace(/<\/?(br|p|div|li|h[1-6])\b[^>]*>/gi,`
113
+ `).replace(/<[^>]+>/g,"").replace(/&nbsp;/g," ").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/\n{3,}/g,`
114
+
115
+ `).trim()}function ce(e){if(e.separator)return{id:e.id||"",title:"",type:"separator"};return{id:e.id||"",title:e.title||"",icon:e.icon,shortcut:e.shortcut,enabled:e.disabled?!1:void 0,checked:e.checked?!0:void 0,type:e.submenu?"submenu":void 0,submenu:e.submenu?.map(ce)}}async function se(e){if(!e.items||e.items.length===0)throw Error("contextMenu.show requires at least one item");if(!r("nativeUI"))return null;let t=window.craft?.nativeUI;if(!t)return null;let n=await t.showContextMenu({targetId:e.targetId||"",targetType:"general",x:Math.round(e.x),y:Math.round(e.y),items:e.items.map(ce)});return{id:typeof n?.id==="string"?n.id:null,targetId:n?.targetId}}var ur={available(){return r("nativeUI")},async show(e){return await se(e)!==null},async pick(e){return(await se(e))?.id??null},onAction(e){return a("craft:contextmenu:action",(t)=>{if(typeof t.id==="string")e({id:t.id,targetId:t.targetId??""})})}};var mr={async listCameras(){if(!r("continuityCamera"))return[];return await window.craft.continuityCamera.listCameras()}};var hr={async loadModel(e,t){if(!e||!t)throw Error("coreml.loadModel: id and path are required");if(!r("coreml"))return!1;return await window.craft.coreml.loadModel(e,t)},async unloadModel(e){if(!r("coreml"))return;await window.craft.coreml.unloadModel(e)},async predict(e,t){if(!e)throw Error("coreml.predict: id is required");if(!r("coreml"))return null;return await window.craft.coreml.predict(e,t)}};var I=[],H=!0,W,z,R={async report(e){if(r("crashReporter")){await window.craft.crashReporter.report(e);return}if(!H)return;let t=e instanceof Error?{timestamp:Date.now(),severity:"error",message:e.message,source:"js",stack:e.stack||"",userId:W,appVersion:z}:{timestamp:Date.now(),severity:e.severity||"error",message:e.message||"",source:e.source||"js",stack:e.stack||"",userId:W,appVersion:z};if(I.length>=64)I.shift();I.push(t)},async flush(){if(r("crashReporter"))return await window.craft.crashReporter.flush();return[...I]},async clear(){if(r("crashReporter")){await window.craft.crashReporter.clear();return}I.length=0},async setEnabled(e){if(r("crashReporter")){await window.craft.crashReporter.setEnabled(e);return}H=e},async isEnabled(){if(r("crashReporter"))return await window.craft.crashReporter.isEnabled();return H},async setUser(e){if(r("crashReporter")){await window.craft.crashReporter.setUser(e);return}W=e||void 0},async setAppVersion(e){if(r("crashReporter")){await window.craft.crashReporter.setAppVersion(e);return}z=e||void 0},attachGlobalHandlers(){if(r("crashReporter")&&window.craft.crashReporter.attachGlobalHandlers)return window.craft.crashReporter.attachGlobalHandlers();if(typeof window>"u")return()=>{};let e=(n)=>{R.report({severity:"error",message:n.message,source:"js",stack:n.error?.stack||`${n.message}
116
+ at ${n.filename}:${n.lineno}:${n.colno}`}).catch(()=>{})},t=(n)=>{let i=n.reason;R.report({severity:"error",message:i?.message||String(i),source:"js",stack:i?.stack||""}).catch(()=>{})};return window.addEventListener("error",e),window.addEventListener("unhandledrejection",t),()=>{window.removeEventListener("error",e),window.removeEventListener("unhandledrejection",t)}},forwardTo(e){return je(e)}},qe="craft:crashReporter:pending",Ue=/[\w.+-]+@[\w-]+\.[\w.-]+/g,He=/\b(?:\d{1,3}\.){3}\d{1,3}\b/g,We=/\/(?:Users|home)\/[^\s/'"`]+/g;function $e(e){let t=(n)=>n.replace(Ue,"<email>").replace(He,"<ip>").replace(We,"/<home>");return{...e,message:t(e.message),stack:t(e.stack)}}async function ze(e,t){let n=new TextEncoder,i=await crypto.subtle.importKey("raw",n.encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),o=await crypto.subtle.sign("HMAC",i,n.encode(t));return[...new Uint8Array(o)].map((s)=>s.toString(16).padStart(2,"0")).join("")}function Ke(e){if(!e||typeof localStorage>"u")return[];try{let t=localStorage.getItem(e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n:[]}catch{return[]}}function de(e,t){if(!e||typeof localStorage>"u")return;try{if(t.length===0)localStorage.removeItem(e);else localStorage.setItem(e,JSON.stringify(t))}catch{}}function je(e){let{endpoint:t,intervalMs:n=60000,signingSecret:i,redact:o=!0,headers:s={},maxRetries:c=5,persistKey:d}=e,l=d===null?null:d??qe,f=Ke(l),w=!1,y=null,m=null,Ee=typeof o==="function"?o:o===!1?(b)=>b:$e;async function Ce(b){let C=JSON.stringify({entries:b}),M={"Content-Type":"application/json",...s};if(i)M["X-Craft-Signature"]=await ze(i,C);let re=0,q=1000;while(!w)try{let A=await fetch(t,{method:"POST",headers:M,body:C});if(A.ok)return;if(A.status>=400&&A.status<500)return;throw Error(`HTTP ${A.status}`)}catch(A){if(re+=1,re>c)throw f=[...b,...f],de(l,f),A;await new Promise((Me)=>{setTimeout(Me,q)}),q=Math.min(q*2,60000)}}async function te(){if(w||m)return m??void 0;let b=await R.flush();if(b.length>0)await R.clear();if(f=[...f,...b.map((M)=>Ee(M))],f.length===0)return;let C=f;return f=[],de(l,f),m=Ce(C).catch(()=>{}).finally(()=>{m=null}),m}if(n>0)y=setInterval(()=>{te().catch(()=>{})},n);return{async flushNow(){await te()},stop(){if(w=!0,y)clearInterval(y);y=null},pending(){return[...f]}}}var Pr={onUrl(e){if(!r("deepLink"))return()=>{};return a("craft:deepLink",e)},getInitialUrl(){if(typeof window>"u")return null;if(r("deepLink"))try{return window.craft.deepLink.getInitialUrl()}catch{return null}return window.__craftPendingDeepLink||null},consumeInitialUrl(){let e=this.getInitialUrl();if(typeof window<"u")window.__craftPendingDeepLink=void 0;return e},isAvailable(){return r("deepLink")}};function le(e){let t=new Set(e.properties??[]);if(e.canChooseDirectories)t.add("openDirectory");if(e.canChooseFiles)t.add("openFile");if(e.multiSelections)t.add("multiSelections");if(e.showHiddenFiles)t.add("showHiddenFiles");if(e.canCreateDirectories)t.add("createDirectory");return{...e,properties:[...t]}}function Ve(){if(typeof window>"u")return;return window.craft?.dialog}var Ye={error:"critical",warning:"warning",question:"info",info:"info",none:"info"};function Ge(e){let t=[e.title?e.message:"",e.detail??""].filter(Boolean).join(`
117
+
118
+ `);return{title:e.title||e.message,message:t||void 0,style:Ye[e.type??"none"]??"info",buttons:e.buttons}}function ue(e,t){if(typeof e==="number"&&Number.isFinite(e))return{response:e};if(e&&typeof e==="object"){let i=e;if(typeof i.response==="number")return{response:i.response};if(typeof i.buttonIndex==="number")return{response:i.buttonIndex}}let n=t.buttons??["OK"];return{response:t.cancelButton??Math.max(0,n.length-1)}}function K(){if(typeof window<"u"&&window.craft?.dialog)return!0;return!1}async function Ar(e={}){if(K())return await window.craft.dialog.showOpenDialog(le(e));return new Promise((t)=>{if(typeof document>"u"){t({canceled:!0,filePaths:[]});return}let n=new Set(le(e).properties),i=document.createElement("input");if(i.type="file",i.multiple=n.has("multiSelections"),e.filters?.length){let o=e.filters.flatMap((s)=>s.extensions.map((c)=>`.${c}`));i.accept=o.join(",")}if(n.has("openDirectory")&&!n.has("openFile"))i.webkitdirectory=!0;i.onchange=()=>{let o=Array.from(i.files||[]);if(o.length===0)t({canceled:!0,filePaths:[]});else{let s=o.map((c)=>c.name);t({canceled:!1,filePaths:s})}},i.oncancel=()=>{t({canceled:!0,filePaths:[]})},i.click()})}async function Ir(e={}){if(K()){let n=window;try{return await n.craft.dialog.showSaveDialog(e)}catch(i){console.warn("[stx-dialog] Failed to show native save dialog:",i)}}if(typeof window<"u"&&"showSaveFilePicker"in window)try{let n=e.filters?.map((o)=>({description:o.name,accept:{"*/*":o.extensions.map((s)=>`.${s}`)}}));return{canceled:!1,filePath:(await window.showSaveFilePicker({suggestedName:e.defaultPath,types:n})).name}}catch(n){return{canceled:!0}}console.warn("[stx-dialog] Save dialog not available, using prompt fallback");let t=prompt("Enter filename:",e.defaultPath||"file.txt");if(t)return{canceled:!1,filePath:t};return{canceled:!0}}async function L(e){let t=Ve();if(typeof t?.showMessageBox==="function")try{return ue(await t.showMessageBox(e),e)}catch(d){console.warn("[stx-dialog] Failed to show native message box:",d)}else if(typeof t?.showAlert==="function")try{return ue(await t.showAlert(Ge(e)),e)}catch(d){console.warn("[stx-dialog] Failed to show native alert:",d)}let n=e.buttons||["OK"],i=e.detail?`
119
+
120
+ ${e.detail}`:"",o=`${e.message}${i}`;if(n.length===1)return alert(o),{response:0};let s=e.cancelButton??n.length-1,c=e.defaultButton!==void 0&&e.defaultButton!==s?e.defaultButton:n.findIndex((d,l)=>l!==s);if(n.length>2)console.warn(`[stx-dialog] ${n.length} buttons requested; a browser confirm offers two. Reachable: "${n[c]}" and "${n[s]}".`);return{response:confirm(o)?c:s}}async function kr(e={}){if(K()){let t=window;try{return await t.craft.dialog.showColorPicker(e)}catch(n){console.warn("[stx-dialog] Failed to show native color picker:",n)}}return new Promise((t)=>{if(typeof document>"u"){t({canceled:!0});return}let n=document.createElement("input");n.type="color",n.value=e.color||"#000000",n.onchange=()=>{t({canceled:!1,color:n.value})},n.oncancel=()=>{t({canceled:!0})},n.click()})}async function Er(e,t){await L({type:"info",title:t||"Alert",message:e,buttons:["OK"]})}async function Cr(e,t){return(await L({type:"question",title:t||"Confirm",message:e,buttons:["OK","Cancel"],defaultButton:0,cancelButton:1})).response===0}async function Mr(e,t){await L({type:"error",title:t||"Error",message:e,buttons:["OK"]})}async function Br(e,t){await L({type:"warning",title:t||"Warning",message:e,buttons:["OK"]})}function Dr(){return`
121
+ // STX Desktop Dialog Bridge
122
+ // Provides convenient wrappers around window.craft.dialog APIs
123
+ window.stxDialog = {
124
+ // File dialogs
125
+ showOpenDialog: (options) => window.craft?.dialog?.showOpenDialog(options),
126
+ showSaveDialog: (options) => window.craft?.dialog?.showSaveDialog(options),
127
+
128
+ // Message dialogs.
129
+ //
130
+ // The bridge's dialog namespace has no showMessageBox -- showAlert is the
131
+ // method it actually implements, and it answers with the button index. So
132
+ // this prefers showMessageBox when a host provides one and uses showAlert
133
+ // otherwise, instead of calling a method that is not there (stacksjs/stx#2040).
134
+ showMessageBox: async (options) => {
135
+ const api = window.craft?.dialog;
136
+ if (typeof api?.showMessageBox === 'function') {
137
+ const raw = await api.showMessageBox(options);
138
+ if (typeof raw === 'number') return { response: raw };
139
+ if (raw && typeof raw.response === 'number') return { response: raw.response };
140
+ if (raw && typeof raw.buttonIndex === 'number') return { response: raw.buttonIndex };
141
+ }
142
+ else if (typeof api?.showAlert === 'function') {
143
+ const index = await api.showAlert({
144
+ title: options.title || options.message,
145
+ message: options.title ? options.message : options.detail,
146
+ buttons: options.buttons,
147
+ });
148
+ if (typeof index === 'number') return { response: index };
149
+ }
150
+ // Unreadable: answer with cancel, never with the action button.
151
+ const buttons = options.buttons || ['OK'];
152
+ return { response: options.cancelButton ?? Math.max(0, buttons.length - 1) };
153
+ },
154
+
155
+ // Color picker
156
+ showColorPicker: (options) => window.craft?.dialog?.showColorPicker(options),
157
+
158
+ // Font picker
159
+ showFontPicker: (options) => window.craft?.dialog?.showFontPicker(options),
160
+
161
+ // Convenience functions
162
+ alert: async (message, title) => {
163
+ return window.stxDialog.showMessageBox({
164
+ type: 'info',
165
+ title: title || 'Alert',
166
+ message,
167
+ buttons: ['OK'],
168
+ });
169
+ },
170
+
171
+ // OK first, matching showConfirmDialog: NSAlert adds buttons right-to-left
172
+ // and makes the first one the default, so ['Cancel', 'OK'] built a confirm
173
+ // that defaulted to Cancel and put OK on the left. This wrapper still had
174
+ // the old order after the typed path was corrected.
175
+ confirm: async (message, title) => {
176
+ const result = await window.stxDialog.showMessageBox({
177
+ type: 'question',
178
+ title: title || 'Confirm',
179
+ message,
180
+ buttons: ['OK', 'Cancel'],
181
+ defaultButton: 0,
182
+ cancelButton: 1,
183
+ });
184
+ return result?.response === 0;
185
+ },
186
+
187
+ error: async (message, title) => {
188
+ return window.stxDialog.showMessageBox({
189
+ type: 'error',
190
+ title: title || 'Error',
191
+ message,
192
+ buttons: ['OK'],
193
+ });
194
+ },
195
+
196
+ // Check if dialog is available
197
+ isAvailable: () => typeof window.craft?.dialog !== 'undefined',
198
+ };
199
+ `}async function Lr(e,t={}){if(!r("dragOut"))throw Error("dragOut requires a Craft native window");let n=Array.isArray(e)?e:[e];if(n.length===0)throw Error("dragOut: at least one path required");await window.craft.dragOut.start(n,t)}function Or(){return r("dragOut")}var Nr={async getDefault(e){if(!e)throw Error("fileAssociations.getDefault: uti is required");if(!r("fileAssociations"))return null;let t=await window.craft.fileAssociations.getDefault(e);return t?String(t):null},async setDefault(e,t){if(!e||!t)throw Error("fileAssociations.setDefault: uti and bundleId are required");if(!r("fileAssociations"))return!1;return await window.craft.fileAssociations.setDefault(e,t)}};var Xe={supported:!1,isFocused:null,authorization:"unsupported"};function fe(){return{ok:!1,error:"Focus control is only available in a Craft window on macOS"}}var pe={async getStatus(){if(!r("focus"))return{...Xe};return await window.craft.focus.getStatus()},async requestAuthorization(){if(!r("focus"))return"unsupported";return await window.craft.focus.requestAuthorization()},async setEnabled(e,t={}){if(!r("focus"))return fe();if(!(e?t.onShortcut:t.offShortcut))return{ok:!1,error:`focus.setEnabled: no ${e?"onShortcut":"offShortcut"} configured`};return await window.craft.focus.setEnabled(e,t)},async runShortcut(e){if(!r("focus"))return fe();if(!e)throw Error("focus.runShortcut: name is required");return await window.craft.focus.runShortcut(e)},async listShortcuts(){if(!r("focus"))return[];return await window.craft.focus.listShortcuts()},async listShortcutsResult(){if(!r("focus"))return{canList:!1,shortcuts:[]};let t=await window.craft.focus.listShortcutsResult?.();return{canList:Boolean(t?.canList),shortcuts:t?.shortcuts??[]}}};async function Hr(...e){if(e.length===0)return!1;let t=new Set(await pe.listShortcuts());return e.every((n)=>t.has(n))}async function Wr(...e){if(e.length===0)return!1;let{canList:t,shortcuts:n}=await pe.listShortcutsResult();if(!t)return"unknown";let i=new Set(n);return e.every((o)=>i.has(o))}var Kr={async readFile(e){let t=await u("fs").readFile(e);return t&&t.data||""},async readBuffer(e){let t=await u("fs").readFile(e),n=t&&t.data||"";if(t&&t.base64===!0)return Qe(n);return new TextEncoder().encode(n)},async writeFile(e,t){await u("fs").writeFile(e,t)},async writeBuffer(e,t){let n=Je(t),i=u("fs");if(typeof i.writeFileBytes==="function")await i.writeFileBytes(e,n);else await i.writeFile(e,n)},async copy(e,t){if(e===t)throw Error("fs.copy: source and destination must differ");await u("fs").copy(e,t)},async move(e,t){if(e===t)throw Error("fs.move: source and destination must differ");await u("fs").move(e,t)},async appendFile(e,t){await u("fs").appendFile(e,t)},async deleteFile(e){await u("fs").deleteFile(e)},async exists(e){return await u("fs").exists(e)},async stat(e){return Ze(await u("fs").stat(e))},async readDir(e){let t=await u("fs").readDir(e),n=t&&t.entries||[],i=e.endsWith("/")?e.slice(0,-1):e;return n.map((o)=>({name:o.name,path:`${i}/${o.name}`,isDirectory:!!o.isDirectory}))},async mkdir(e,t){await u("fs").mkdir(e,t)},async rmdir(e,t){await u("fs").rmdir(e,t)},async watch(e,t){await u("fs").watch(e,t)},async unwatch(e){await u("fs").unwatch(e)},onChange(e){return a("craft:fs:change",e)},async watchTree(e,t,n){let i=`watch-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,o=u("fs");await o.watch(e,i,{recursive:!!t.recursive});let s=t.kinds&&t.kinds.length>0?new Set(t.kinds):null,c=Math.max(0,Math.floor(t.coalesceMs??0)),d=[],l=null,f=!1,w=()=>{if(l=null,d.length===0)return;let m=d;d=[];try{n(m)}catch{}},y=a("craft:fs:change",(m)=>{if(f)return;if(m.id!==i)return;if(s&&m.kind&&!s.has(m.kind))return;if(d.push(m),c===0){w();return}if(l==null)l=setTimeout(w,c)});return{id:i,async stop(){if(f)return;if(f=!0,y(),l)clearTimeout(l),l=null;if(d.length>0)w();try{await o.unwatch(i)}catch{}}}},async homeDir(){return await u("fs").homeDir()},async tempDir(){return await u("fs").tempDir()},async appDataDir(){return await u("fs").appDataDir()}};function Je(e){let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return typeof btoa==="function"?btoa(t):Buffer.from(e).toString("base64")}function Qe(e){let t=typeof atob==="function"?atob(e):Buffer.from(e,"base64").toString("binary"),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n}function Ze(e){return{isFile:!!e.isFile,isDirectory:!!e.isDirectory,isSymlink:!!e.isSymlink,size:Number(e.size)||0,modifiedAt:e.modifiedAt!=null?e.modifiedAt<1000000000000?e.modifiedAt*1000:e.modifiedAt:0}}function P(){return window.craft.shortcuts}var Yr={async register(e,t,n){if(!r("shortcuts"))return;await P().register(e,t,n)},async unregister(e){if(!r("shortcuts"))return;await P().unregister(e)},async unregisterAll(){if(!r("shortcuts"))return;await P().unregisterAll()},async enable(e){if(!r("shortcuts"))return;await P().enable(e)},async disable(e){if(!r("shortcuts"))return;await P().disable(e)},async isRegistered(e){if(!r("shortcuts"))return!1;return await P().isRegistered(e)},async list(){if(!r("shortcuts"))return[];return await P().list()},on(e){return a("craft:shortcut",e)}};var O={async startActivity(e,t){if(!e)throw Error("handoff.startActivity: type is required");if(!r("handoff"))return!1;let n=await window.craft.handoff.startActivity(e,t);return typeof n==="boolean"?n:!!(n&&n.ok)},async updateActivity(e){if(!r("handoff"))return!1;let t=await window.craft.handoff.updateActivity(e);return typeof t==="boolean"?t:!!(t&&t.ok)},async stopActivity(){if(!r("handoff"))return;await window.craft.handoff.stopActivity()},async getCurrentActivity(){if(!r("handoff"))return null;let e=await window.craft.handoff.getCurrentActivity();return e&&typeof e.type==="string"?e:null},onIncoming(e){return a("craft:handoff:incoming",e)}};var h=new Map,et=0,_=!1;function tt(e){let t=e.split("+").map((i)=>i.trim()),n={key:"",meta:!1,ctrl:!1,shift:!1,alt:!1};for(let i of t){let o=i.toLowerCase();switch(o){case"cmd":case"command":case"meta":case"⌘":n.meta=!0;break;case"ctrl":case"control":case"⌃":n.ctrl=!0;break;case"shift":case"⇧":n.shift=!0;break;case"alt":case"option":case"opt":case"⌥":n.alt=!0;break;case"cmdorctrl":case"commandorcontrol":if(typeof process<"u"&&process.platform==="darwin")n.meta=!0;else n.ctrl=!0;break;default:n.key=o}}return n}function Qr(e){let t=[];if(e.ctrl)t.push("⌃");if(e.alt)t.push("⌥");if(e.shift)t.push("⇧");if(e.meta)t.push("⌘");return t.push(e.key.toUpperCase()),t.join("")}function rt(e,t){if(t.meta!==e.metaKey)return!1;if(t.ctrl!==e.ctrlKey)return!1;if(t.shift!==e.shiftKey)return!1;if(t.alt!==e.altKey)return!1;return e.key.toLowerCase()===t.key||e.code.toLowerCase()===`key${t.key}`}function me(e){for(let[,t]of h)if(rt(e,t.parsed)){e.preventDefault(),e.stopPropagation();try{t.handler()}catch{}break}}function nt(){if(_)return;if(typeof document>"u")return;document.addEventListener("keydown",me,!0),_=!0}function j(){if(!_)return;if(typeof document>"u")return;document.removeEventListener("keydown",me,!0),_=!1}async function it(e,t){if(typeof window>"u")return!1;let n=window.craft;if(!n?.hotkeys?.register)return!1;try{return await n.hotkeys.register(e,t),!0}catch{return!1}}async function V(e){if(typeof window>"u")return;let t=window.craft;if(!t?.hotkeys?.unregister)return;try{await t.hotkeys.unregister(e)}catch{}}function Zr(e,t){let n=`hotkey_${++et}_${Date.now()}`,i=tt(e);h.set(n,{shortcut:e,handler:t,parsed:i}),it(n,e),nt();let o={shortcut:e,id:n,unregister(){ot(o)}};return o}function ot(e){if(h.delete(e.id),V(e.id),h.size===0)j()}function en(){for(let[e]of h)V(e);h.clear(),j()}function tn(){return Array.from(h.entries()).map(([e,t])=>({shortcut:t.shortcut,id:e,unregister(){if(h.delete(e),V(e),h.size===0)j()}}))}var an={async isAvailable(){if(!r("iap"))return!1;return await window.craft.iap.isAvailable()},async getProducts(e){if(!r("iap"))return[];let t=Array.isArray(e)?e:[String(e)];return await window.craft.iap.getProducts(t)},async purchase(e){if(!r("iap"))return{queued:!1,productId:e,reason:"IAP bridge not available"};let t=await window.craft.iap.purchase(e);return{queued:!!(t&&t.queued),productId:t?.productId,reason:t?.reason}},async restorePurchases(){if(!r("iap"))return{ok:!1};let e=await window.craft.iap.restorePurchases();return{ok:!!(e&&e.ok)}},async finishTransaction(e){if(!r("iap"))return;await window.craft.iap.finishTransaction(e)},async getReceiptData(){if(!r("iap"))return null;let e=await window.craft.iap.getReceiptData();return e?String(e):null},onPurchased(e){return a("craft:iap:purchased",e)},onFailed(e){return a("craft:iap:failed",e)},onRestored(e){return a("craft:iap:restored",e)},onProductsLoaded(e){return a("craft:iap:productsLoaded",(t)=>e(t.products||[]))},onRefunded(e){return a("craft:iap:refunded",e)},onSubscriptionStatusChanged(e){return a("craft:iap:subscriptionStatusChanged",e)},async getActiveSubscriptions(){if(!r("iap"))return[];let e=window.craft.iap.getActiveSubscriptions;if(typeof e!=="function")return[];let t=await e();return Array.isArray(t)?t:[]},async isEligibleForIntroOffer(e){if(!r("iap"))return!1;let t=window.craft.iap.isEligibleForIntroOffer;if(typeof t!=="function")return!1;return!!await t(e)}};var dn={async set(e,t,n){if(!e)throw Error("keychain.set: service is required");if(!t)throw Error("keychain.set: account is required");await u("keychain").set(e,t,n)},async get(e,t){if(!e)throw Error("keychain.get: service is required");if(!t)throw Error("keychain.get: account is required");let n=await u("keychain").get(e,t);return typeof n==="string"?n:null},async delete(e,t){if(!e)throw Error("keychain.delete: service is required");if(!t)throw Error("keychain.delete: account is required");await u("keychain").delete(e,t)},async has(e,t){if(!e)throw Error("keychain.has: service is required");if(!t)throw Error("keychain.has: account is required");return await u("keychain").has(e,t)}};var fn={async start(e,t){return O.startActivity(e,{title:t?.title,webpageURL:t?.webpageURL,userInfo:t?.state})},async update(e){return O.updateActivity({title:e.title,webpageURL:e.webpageURL,userInfo:e.state})},async stop(){await O.stopActivity()}};var gn={async start(e=0,t="127.0.0.1"){if(!r("localServer"))return{port:0,started:!1,reason:"bridge unavailable"};return await window.craft.localServer.start(e,t)},async stop(){if(!r("localServer"))return;await window.craft.localServer.stop()},async respond(e){if(!r("localServer"))return;await window.craft.localServer.respond(e||{status:200,body:"OK"})},onRequest(e){return a("craft:localServer:request",e)},async awaitOAuthCallback(e={}){u("localServer");let{port:t=0,host:n="127.0.0.1",timeoutMs:i=300000,successHTML:o}=e,s=await this.start(t,n);if(!s.started)throw Error(`localServer: start failed${s.reason?` — ${s.reason}`:""}`);return new Promise((c,d)=>{let l=setTimeout(()=>{f(),this.stop().catch(()=>{}),d(Error("localServer: OAuth callback timed out"))},i),f=this.onRequest(({url:w})=>{clearTimeout(l),f();let y=o??`<!doctype html><meta charset="utf-8"><title>Done</title>
200
+ <style>body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;display:flex;align-items:center;justify-content:center;height:100vh;margin:0;background:#f5f5f7}</style>
201
+ <div><h1>You can close this tab.</h1><p>Returning to the app…</p></div>
202
+ <script>setTimeout(()=>window.close(),1500)</script>`;this.respond({status:200,body:y,contentType:"text/html; charset=utf-8"}).catch(()=>{}).finally(()=>this.stop().catch(()=>{})),c({url:w,port:s.port})})})}};var vn={async requestPermission(e="whenInUse"){if(r("location"))return await window.craft.location.requestPermission(e);if(typeof navigator<"u"&&navigator.geolocation)return"undetermined";return"not-supported"},async getAuthorization(){if(r("location"))return await window.craft.location.getAuthorization();return"unknown"},async getCurrentLocation(){if(r("location"))return await window.craft.location.getCurrentLocation();if(typeof navigator<"u"&&navigator.geolocation)return navigator.geolocation.getCurrentPosition((e)=>{window.dispatchEvent(new CustomEvent("craft:location:update",{detail:{latitude:e.coords.latitude,longitude:e.coords.longitude,altitude:e.coords.altitude,horizontalAccuracy:e.coords.accuracy,verticalAccuracy:e.coords.altitudeAccuracy,speed:e.coords.speed}}))},(e)=>{window.dispatchEvent(new CustomEvent("craft:location:error",{detail:{message:e.message||String(e)}}))}),{requested:!0};return{requested:!1}},async startWatching(e){if(r("location"))return await window.craft.location.startWatching(e);if(typeof navigator<"u"&&navigator.geolocation){let t=navigator.geolocation.watchPosition((n)=>{window.dispatchEvent(new CustomEvent("craft:location:update",{detail:{latitude:n.coords.latitude,longitude:n.coords.longitude,altitude:n.coords.altitude,horizontalAccuracy:n.coords.accuracy,verticalAccuracy:n.coords.altitudeAccuracy,speed:n.coords.speed}}))});return window.__craftWebLocationWatchId=t,!0}return!1},async stopWatching(){if(r("location")){await window.craft.location.stopWatching();return}if(typeof navigator<"u"&&navigator.geolocation){let e=window.__craftWebLocationWatchId;if(e!=null)navigator.geolocation.clearWatch(e),window.__craftWebLocationWatchId=null}},onUpdate(e){return a("craft:location:update",e)},onError(e){return a("craft:location:error",e)},onAuthChanged(e){return a("craft:location:authChanged",e)}};var xn={async debug(e){if(r("log"))await window.craft.log.debug(e);else console.debug(e)},async info(e){if(r("log"))await window.craft.log.info(e);else console.info(e)},async warn(e){if(r("log"))await window.craft.log.warn(e);else console.warn(e)},async error(e){if(r("log"))await window.craft.log.error(e);else console.error(e)}};var An={app(e,t={}){return{label:e,items:[{label:`About ${e}`,role:"about"},{separator:!0},...t.settings?[{id:"stx.menu.settings",label:"Settings…",shortcut:"cmd+,",onClick:t.settings},{separator:!0}]:[],{label:`Hide ${e}`,role:"hide",shortcut:"cmd+h"},{label:"Hide Others",role:"hideOthers",shortcut:"cmd+alt+h"},{label:"Show All",role:"showAll"},{separator:!0},{label:`Quit ${e}`,role:"quit",shortcut:"cmd+q"}]}},edit(){return{label:"Edit",items:[{label:"Undo",role:"undo",shortcut:"cmd+z"},{label:"Redo",role:"redo",shortcut:"cmd+shift+z"},{separator:!0},{label:"Cut",role:"cut",shortcut:"cmd+x"},{label:"Copy",role:"copy",shortcut:"cmd+c"},{label:"Paste",role:"paste",shortcut:"cmd+v"},{label:"Select All",role:"selectAll",shortcut:"cmd+a"}]}},window(){return{label:"Window",items:[{label:"Minimize",role:"minimize",shortcut:"cmd+m"},{label:"Zoom",role:"zoom"},{separator:!0},{label:"Close Window",role:"close",shortcut:"cmd+w"}]}},leading(e,t={}){return[this.app(e,t),this.edit()]}},at=0;function st(e){let t=new Map;return{payload:{menus:e.menus.map((i)=>({label:i.label,items:i.items.map((o)=>{let{onClick:s,...c}=o;if(c.separator)return c;let d=c.id??`stx.menu.${at++}`;if(s)t.set(d,s);return{...c,id:d}})}))},handlers:t}}var Y=null,In={async set(e){if(!r("menu"))return!1;let{payload:t,handlers:n}=st(e);if(Y?.(),Y=null,n.size>0)Y=a("craft:menu:action",(i)=>{n.get(i.id)?.()});return await window.craft.menu.set(t),!0},async setDock(e){if(r("menu"))await window.craft.menu.setDock(e)},async addItem(e,t){if(r("menu"))await window.craft.menu.addItem(e,t)},async removeItem(e){if(r("menu"))await window.craft.menu.removeItem(e)},async enableItem(e){if(r("menu"))await window.craft.menu.enableItem(e)},async disableItem(e){if(r("menu"))await window.craft.menu.disableItem(e)},async checkItem(e){if(r("menu"))await window.craft.menu.checkItem(e)},async uncheckItem(e){if(r("menu"))await window.craft.menu.uncheckItem(e)},async setItemLabel(e,t){if(r("menu"))await window.craft.menu.setItemLabel(e,t)},async clearDock(){if(r("menu"))await window.craft.menu.clearDock()},onAction(e){return a("craft:menu:action",e)}};var Cn={async listSources(){if(!r("midi"))return[];return await window.craft.midi.listSources()},async listDestinations(){if(!r("midi"))return[];return await window.craft.midi.listDestinations()},async send(e,t){if(!r("midi"))return{ok:!1,reason:"bridge unavailable"};return await window.craft.midi.send(e,t)},async subscribe(e){if(!r("midi"))return{ok:!1,reason:"bridge unavailable"};return await window.craft.midi.subscribe(e)},async unsubscribe(e){if(!r("midi"))return{ok:!1};return await window.craft.midi.unsubscribe(e)},onMessage(e){return a("craft:midi:message",e)}};function ct(){return!1}function G(){return typeof window<"u"&&typeof document<"u"}var S=[];function dt(){return`modal-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function lt(e){switch(e){case"info":return"&#x2139;";case"warning":return"&#x26A0;";case"error":return"&#x2716;";case"success":return"&#x2714;";case"question":return"&#x2753;";default:return"&#x2139;"}}function F(e){if(e==="question")return[{label:"No",style:"default"},{label:"Yes",style:"primary"}];return[{label:"OK",style:"primary"}]}function ut(e){let{options:t}=e,n=lt(t.type),i=t.buttons||F(t.type),o=t.type||"info",s="";return i.forEach((c,d)=>{let l=c.style==="destructive"?"destructive":c.style==="primary"?"primary":"default",f=d===(t.defaultButton??i.length-1)?"autofocus":"";s+=`<button class="stx-modal-btn ${l}" data-index="${d}" ${f}>${c.label}</button>`}),`
203
+ <div class="stx-modal-overlay" data-modal-id="${e.id}">
204
+ <div class="stx-modal ${o}" role="dialog" aria-modal="true" aria-labelledby="${e.id}-title">
205
+ <div class="stx-modal-icon">${n}</div>
206
+ <div class="stx-modal-content">
207
+ ${t.title?`<h2 id="${e.id}-title" class="stx-modal-title">${ge(t.title)}</h2>`:""}
208
+ <p class="stx-modal-message">${ge(t.message)}</p>
209
+ </div>
210
+ <div class="stx-modal-buttons">${s}</div>
211
+ </div>
212
+ </div>
213
+ `}function ge(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function g(e,t,n=!1){let i=S.indexOf(e);if(i>-1)S.splice(i,1);if(e.element&&G())e.element.remove();let s=(e.options.buttons||F(e.options.type))[t];if(s?.action)s.action();e.resolve({buttonIndex:t,cancelled:n})}async function k(e){let t=ct(),n=dt();return new Promise((i)=>{let o={id:n,options:e,resolve:i};if(S.push(o),t)console.log(`[stx-modal] Showing native modal: ${e.title||"Modal"}`),setTimeout(()=>{g(o,e.defaultButton??0,!1)},0);else if(G())try{let s=document.createElement("div");s.innerHTML=ut(o);let c=s.firstElementChild;if(!c){console.log(`[stx-modal] ${e.type?.toUpperCase()||"INFO"}: ${e.title||"Modal"}`),console.log(`[stx-modal] ${e.message}`),setTimeout(()=>{g(o,e.defaultButton??0,!1)},0);return}o.element=c;try{document.body.appendChild(c)}catch{console.log(`[stx-modal] ${e.type?.toUpperCase()||"INFO"}: ${e.title||"Modal"}`),console.log(`[stx-modal] ${e.message}`),setTimeout(()=>{g(o,e.defaultButton??0,!1)},0);return}try{c.querySelectorAll(".stx-modal-btn").forEach((d)=>{d.addEventListener("click",()=>{let l=Number.parseInt(d.dataset.index||"0",10);g(o,l,!1)})})}catch{}try{c.addEventListener("click",(d)=>{if(d.target===c){let l=e.cancelButton??0;g(o,l,!0)}})}catch{}try{let d=(l)=>{if(l.key==="Escape"){let f=e.cancelButton??0;g(o,f,!0),document.removeEventListener("keydown",d)}else if(l.key==="Enter"){let f=e.defaultButton??(e.buttons||F(e.type)).length-1;g(o,f,!1),document.removeEventListener("keydown",d)}};document.addEventListener("keydown",d)}catch{}try{let d=c.querySelector(".stx-modal-btn[autofocus]");if(d)d.focus()}catch{}if(typeof process<"u"&&process.env.BUN_TEST)setTimeout(()=>{g(o,e.defaultButton??0,!1)},0)}catch{console.log(`[stx-modal] ${e.type?.toUpperCase()||"INFO"}: ${e.title||"Modal"}`),console.log(`[stx-modal] ${e.message}`),setTimeout(()=>{g(o,e.defaultButton??0,!1)},0)}else{console.log(`[stx-modal] ${e.type?.toUpperCase()||"INFO"}: ${e.title||"Modal"}`),console.log(`[stx-modal] ${e.message}`);let s=e.buttons||F(e.type);console.log(`[stx-modal] Buttons: ${s.map((c)=>c.label).join(", ")}`),setTimeout(()=>{g(o,e.defaultButton??0,!1)},0)}})}async function ft(e,t){return k({title:e,message:t,type:"info"})}async function Bn(e,t){return k({title:e,message:t,type:"warning"})}async function Dn(e,t){return k({title:e,message:t,type:"error"})}async function Tn(e,t){return k({title:e,message:t,type:"success"})}async function pt(e,t){return k({title:e,message:t,type:"question",buttons:[{label:"No",style:"default"},{label:"Yes",style:"primary"}],defaultButton:1,cancelButton:0})}async function Rn(e,t="Confirm"){return(await pt(t,e)).buttonIndex===1}async function Ln(e,t="Alert"){await ft(t,e)}async function On(e,t="",n="Input"){if(G()&&typeof window.prompt==="function")return window.prompt(e,t);return console.log(`[stx-modal] PROMPT: ${n}`),console.log(`[stx-modal] ${e}`),console.log(`[stx-modal] Default: ${t}`),t}function _n(){return S.length}function Fn(){while(S.length>0){let e=S[S.length-1];g(e,0,!0)}}var Nn=`
214
+ .stx-modal-overlay {
215
+ position: fixed;
216
+ inset: 0;
217
+ background: rgba(0, 0, 0, 0.5);
218
+ display: flex;
219
+ align-items: center;
220
+ justify-content: center;
221
+ z-index: 10000;
222
+ animation: stx-modal-fade-in 0.15s ease-out;
223
+ }
224
+
225
+ @keyframes stx-modal-fade-in {
226
+ from { opacity: 0; }
227
+ to { opacity: 1; }
228
+ }
229
+
230
+ .stx-modal {
231
+ background: #fff;
232
+ border-radius: 12px;
233
+ padding: 24px;
234
+ max-width: 400px;
235
+ width: 90%;
236
+ box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
237
+ animation: stx-modal-slide-up 0.2s ease-out;
238
+ }
239
+
240
+ @keyframes stx-modal-slide-up {
241
+ from { transform: translateY(20px); opacity: 0; }
242
+ to { transform: translateY(0); opacity: 1; }
243
+ }
244
+
245
+ @media (prefers-color-scheme: dark) {
246
+ .stx-modal {
247
+ background: #2d2d2d;
248
+ color: #fff;
249
+ }
250
+ }
251
+
252
+ .stx-modal-icon {
253
+ font-size: 48px;
254
+ text-align: center;
255
+ margin-bottom: 16px;
256
+ }
257
+
258
+ .stx-modal.info .stx-modal-icon { color: #3498db; }
259
+ .stx-modal.warning .stx-modal-icon { color: #f39c12; }
260
+ .stx-modal.error .stx-modal-icon { color: #e74c3c; }
261
+ .stx-modal.success .stx-modal-icon { color: #27ae60; }
262
+ .stx-modal.question .stx-modal-icon { color: #9b59b6; }
263
+
264
+ .stx-modal-content {
265
+ text-align: center;
266
+ margin-bottom: 24px;
267
+ }
268
+
269
+ .stx-modal-title {
270
+ margin: 0 0 8px;
271
+ font-size: 20px;
272
+ font-weight: 600;
273
+ }
274
+
275
+ .stx-modal-message {
276
+ margin: 0;
277
+ color: #666;
278
+ line-height: 1.5;
279
+ }
280
+
281
+ @media (prefers-color-scheme: dark) {
282
+ .stx-modal-message { color: #aaa; }
283
+ }
284
+
285
+ .stx-modal-buttons {
286
+ display: flex;
287
+ gap: 8px;
288
+ justify-content: center;
289
+ }
290
+
291
+ .stx-modal-btn {
292
+ padding: 10px 24px;
293
+ border-radius: 6px;
294
+ font-size: 14px;
295
+ font-weight: 500;
296
+ cursor: pointer;
297
+ border: none;
298
+ transition: background 0.15s, transform 0.1s;
299
+ }
300
+
301
+ .stx-modal-btn:hover {
302
+ transform: translateY(-1px);
303
+ }
304
+
305
+ .stx-modal-btn:active {
306
+ transform: translateY(0);
307
+ }
308
+
309
+ .stx-modal-btn.default {
310
+ background: #e0e0e0;
311
+ color: #333;
312
+ }
313
+
314
+ .stx-modal-btn.default:hover {
315
+ background: #d0d0d0;
316
+ }
317
+
318
+ .stx-modal-btn.primary {
319
+ background: #3498db;
320
+ color: #fff;
321
+ }
322
+
323
+ .stx-modal-btn.primary:hover {
324
+ background: #2980b9;
325
+ }
326
+
327
+ .stx-modal-btn.destructive {
328
+ background: #e74c3c;
329
+ color: #fff;
330
+ }
331
+
332
+ .stx-modal-btn.destructive:hover {
333
+ background: #c0392b;
334
+ }
335
+
336
+ @media (prefers-color-scheme: dark) {
337
+ .stx-modal-btn.default {
338
+ background: #444;
339
+ color: #fff;
340
+ }
341
+ .stx-modal-btn.default:hover {
342
+ background: #555;
343
+ }
344
+ }
345
+ `;var Hn={async enable(){if(!r("autoLaunch"))return!1;return await window.craft.autoLaunch.enable()},async disable(){if(!r("autoLaunch"))return!1;return await window.craft.autoLaunch.disable()},async isEnabled(){if(!r("autoLaunch"))return!1;return await window.craft.autoLaunch.isEnabled()}};function X(){if(!r("window"))return null;return window.craft.window}function v(e){let t=X();if(!t)return Promise.resolve();try{return Promise.resolve(e(t)).then(()=>{return},()=>{return})}catch{return Promise.resolve()}}var zn={get available(){return X()!==null},open(e){let t=()=>{if(typeof window<"u"&&e.url)window.open(e.url,e.name);return{name:e.name}},n=X();if(!n?.open)return Promise.resolve(t());return n.open(e).then((i)=>({name:i?.name||e.name})).catch(t)},close:()=>v((e)=>e.close?.()),focus:()=>v((e)=>e.focus?.()),minimize:()=>v((e)=>e.minimize?.()),maximize:()=>v((e)=>e.maximize?.()),center:()=>v((e)=>e.center?.()),startDrag:()=>v((e)=>e.startDrag?.()),setTitle:(e)=>v((t)=>t.setTitle?.(e)),setSize:(e,t)=>v((n)=>n.setSize?.(e,t)),setAppearance:(e)=>v((t)=>t.setAppearance?.(e))};var Vn={async connectionType(){if(r("network"))return await window.craft.network.connectionType();return we()},async wifiSSID(){if(r("network"))return await window.craft.network.wifiSSID()||void 0;return},async wifiSignalStrength(){if(r("network")){let e=await window.craft.network.wifiSignalStrength();return typeof e==="number"?e:void 0}return},async ipAddress(){if(r("network"))return await window.craft.network.ipAddress();return""},async macAddress(){if(r("network"))return await window.craft.network.macAddress();return""},async interfaces(){if(r("network"))return await window.craft.network.interfaces();return[]},async isVPNConnected(){if(r("network"))return await window.craft.network.isVPNConnected();return!1},async proxySettings(){if(r("network"))return await window.craft.network.proxySettings()||{};return{}},async openPreferences(){if(r("network"))await window.craft.network.openPreferences()},onChange(e){if(r("network"))return a("craft:networkChange",e);if(typeof window>"u")return()=>{};let t=()=>e({type:we(),online:!0}),n=()=>e({type:"none",online:!1});return window.addEventListener("online",t),window.addEventListener("offline",n),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",n)}}};function we(){if(typeof navigator>"u")return"unknown";if(navigator.onLine===!1)return"none";let e=navigator.connection;if(!e)return"unknown";let t=String(e.type||e.effectiveType||"unknown").toLowerCase();if(t==="wifi"||t==="cellular"||t==="ethernet"||t==="bluetooth"||t==="none")return t;return"unknown"}var Xn={async show(e){if(!e.title)throw Error("notification title is required");if(r("notifications")){await window.craft.notifications.show(e);return}if(typeof window<"u"&&"Notification"in window){let t=window.Notification;if(t.permission==="granted")new t(e.title,{body:e.body,icon:e.icon});else if(t.permission==="default"){if(await t.requestPermission()==="granted")new t(e.title,{body:e.body,icon:e.icon})}}},async schedule(e){if(r("notifications")){let i={...e};if(i.triggerAt instanceof Date)i.triggerAt=i.triggerAt.toISOString();await window.craft.notifications.schedule(i);return}let t=mt(e.triggerAt),n=Math.max(0,t-Date.now());setTimeout(()=>{this.show(e).catch(()=>{})},n)},async cancel(e){if(r("notifications"))await window.craft.notifications.cancel(e)},async cancelAll(){if(r("notifications"))await window.craft.notifications.cancelAll()},async setBadge(e){let t=Math.max(0,Math.round(Number.isFinite(e)?e:0));if(r("notifications")){await window.craft.notifications.setBadge(t);return}if(typeof navigator<"u"&&navigator.setAppBadge)try{await navigator.setAppBadge(t)}catch{}},async clearBadge(){if(r("notifications")){await window.craft.notifications.clearBadge();return}if(typeof navigator<"u"&&navigator.clearAppBadge)try{await navigator.clearAppBadge()}catch{}},async requestPermission(){if(r("notifications"))return await window.craft.notifications.requestPermission();if(typeof window<"u"&&"Notification"in window){let e=window.Notification;if(e.permission==="granted")return!0;if(e.permission==="denied")return!1;return await e.requestPermission()==="granted"}return!1},async registerCategories(e){if(!Array.isArray(e)||e.length===0)return;if(r("notifications")){let t=window.craft.notifications.registerCategories;if(typeof t==="function")await t(e)}},onActionClicked(e){return a("craft:notification:actionClicked",e)},onReply(e){return a("craft:notification:reply",e)}};function mt(e){if(e==null)return Date.now();if(e instanceof Date)return e.getTime();if(typeof e==="number")return e;let t=Date.parse(e);return Number.isNaN(t)?Date.now():t}var Zn={async countPages(e){if(!e)throw Error("pdf.countPages: path is required");if(!r("pdf"))return 0;return await window.craft.pdf.countPages(e)},async extractText(e){if(!e)throw Error("pdf.extractText: path is required");if(!r("pdf"))return"";return await window.craft.pdf.extractText(e)}};var ri={async check(e){if(r("permissions"))return await window.craft.permissions.check(e);return await he(e)},async request(e){if(r("permissions"))return await window.craft.permissions.request(e);return await gt(e)},async openSettings(e){if(r("permissions"))await window.craft.permissions.openSettings(e)}};async function he(e){if(typeof navigator>"u"||!navigator.permissions?.query)return"not-supported";try{let t=await navigator.permissions.query({name:e});return wt(t.state)}catch{return"not-supported"}}async function gt(e){if(e==="notifications"&&typeof window<"u"&&"Notification"in window){let t=await window.Notification.requestPermission();return t==="granted"?"granted":t==="denied"?"denied":"undetermined"}return await he(e)}function wt(e){if(e==="granted")return"granted";if(e==="denied")return"denied";if(e==="prompt")return"undetermined";return"undetermined"}var oi={async print(){if(r("printing")){await window.craft.printing.print();return}if(typeof window<"u"&&typeof window.print==="function")window.print()},async printToPDF(e){if(!e)throw Error("printToPDF: path is required");let t=e.startsWith("/"),n=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\");if(!t&&!n)throw Error("printToPDF: path must be absolute");let i=await u("printing").printToPDF(e);return{ok:!!(i&&i.ok),path:i?.path}}};var ci={async getDisplays(){if(r("screen"))return await window.craft.screen.getDisplays();return ve()},async getPrimary(){if(r("screen")){let e=await window.craft.screen.getPrimary();return e&&typeof e.width==="number"?e:null}return ve()[0]??null},onChange(e){if(r("screen"))return a("craft:screen:change",()=>e());if(typeof window>"u")return()=>{};let t=()=>e();return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)}};function ve(){if(typeof window>"u"||!window.screen)return[];let e=window.screen;return[{id:0,x:e.left??0,y:e.top??0,width:e.width||0,height:e.height||0,workX:e.availLeft??0,workY:e.availTop??0,workWidth:e.availWidth??e.width??0,workHeight:e.availHeight??e.height??0,scaleFactor:window.devicePixelRatio||1}]}var ui={async captureScreen(){if(!r("screenCapture"))return null;let e=await window.craft.screenCapture.captureScreen();return e?String(e):null},async captureWindow(e){if(!r("screenCapture"))return null;if(!Number.isFinite(e)||e<=0)throw Error("captureWindow: id must be a positive number");let t=await window.craft.screenCapture.captureWindow(e);return t?String(t):null},async listWindows(){if(!r("screenCapture"))return[];return await window.craft.screenCapture.listWindows()}};var ht=250,vt=60000,Q=2000,ye={sharing:!1,signals:{systemScreenShare:!1,remoteSession:!1,conferenceSharing:!1,screenRecording:!1},sources:[]};function yt(){return{...ye,signals:{...ye.signals},sources:[]}}var J={async getState(){if(!r("screenSharing"))return yt();return await window.craft.screenSharing.getState()},async watch(e=Q){let t=Number.isFinite(e)?Math.min(vt,Math.max(ht,Math.round(e))):Q;if(!r("screenSharing"))return t;let n=await window.craft.screenSharing.watch(t);return n&&n.intervalMs||t},async stop(){if(!r("screenSharing"))return;await window.craft.screenSharing.unwatch()},onChange(e){return a("craft:screenSharing:change",e)}};async function mi(e,t=Q){let n=J.onChange(e);try{await J.watch(t)}catch(o){throw n(),o}let i;return()=>{if(!i)n(),i=J.stop();return i}}var hi={async list(){if(!r("serial"))return[];return await window.craft.serial.list()},async open(e,t=9600){if(!e)throw Error("serial.open: path is required");if(!r("serial"))return{ok:!1,reason:"bridge unavailable"};return await window.craft.serial.open(e,t)},async write(e,t){if(!e)throw Error("serial.write: id is required");if(!r("serial"))return{ok:!1,reason:"bridge unavailable"};return await window.craft.serial.write(e,t)},async close(e){if(!r("serial"))return;await window.craft.serial.close(e)},onData(e){return a("craft:serial:data",e)}};var bi={async register(e){if(!e)throw Error("serviceMenu.register: name is required");if(!r("serviceMenu"))return{ok:!1,reason:"bridge unavailable"};return await window.craft.serviceMenu.register(e)},async unregister(e){if(!e)throw Error("serviceMenu.unregister: name is required");if(!r("serviceMenu"))return;await window.craft.serviceMenu.unregister(e)},onInvoked(e){return a("craft:serviceMenu:invoked",e)}};var E=new Set,be=!1;function bt(){if(be)return;if(typeof window>"u"||typeof window.addEventListener!=="function")return;window.addEventListener("craft:shell:exit",(e)=>{let t=e.detail;if(t?.id)E.delete(t.id)}),be=!0}var xt=new Set(["javascript:","data:","file:","vbscript:"]),Si={async openExternal(e){let t=e.trim().toLowerCase();for(let n of xt)if(t.startsWith(n))throw Error(`shell.openExternal: ${n} URLs are blocked for safety`);if(r("shell")){await window.craft.shell.openExternal(e);return}if(typeof window<"u"&&typeof window.open==="function")window.open(e,"_blank","noopener,noreferrer")},async openPath(e){await u("shell").openPath(e)},async showInFinder(e){await u("shell").showInFinder(e)},async spawn(e,t,n=[],i={}){if(bt(),!e||typeof e!=="string")throw Error("shell.spawn: id must be a non-empty string");if(!t||typeof t!=="string")throw Error("shell.spawn: command must be a non-empty string");if(!Array.isArray(n))throw Error("shell.spawn: args must be an array");for(let o of n)if(typeof o!=="string")throw Error("shell.spawn: args entries must be strings");if(E.has(e))throw Error(`shell.spawn: id "${e}" is already in use — call kill(id) first or pick a different id`);E.add(e);try{await u("shell").spawn(e,t,n,i)}catch(o){throw E.delete(e),o}},async kill(e){await u("shell").kill(e),E.delete(e)},async getEnv(e){if(r("shell")){let t=await window.craft.shell.getEnv(e);return t==null?void 0:String(t)}return},async setEnv(e,t){await u("shell").setEnv(e,t)},onStdout(e){return a("craft:shell:stdout",e)},onStderr(e){return a("craft:shell:stderr",e)},onExit(e){return a("craft:shell:exit",e)}};function Z(e){if(e===null||e===void 0||e===0)return"";return String(e)}function xe(e){return e.map((t)=>({id:t.id,header:t.header,items:t.items.map((n)=>({id:n.id,label:n.label,icon:n.icon,badge:Z(n.badge)||void 0}))}))}function Pe(e){return JSON.stringify(e.map((t)=>[t.id,t.header??"",t.items.map((n)=>[n.id,n.label,n.icon??""])]))}function Se(e){return new Map(e.flatMap((t)=>t.items.map((n)=>[n.id,Z(n.badge)])))}var Pt={available(){return r("nativeUI")&&typeof window.craft?.nativeUI?._emitSidebarSelect==="function"},create(e){if(!Pt.available())return null;let t=window.craft?.nativeUI;if(!t)return null;let n=t.createSidebar({id:e.id,sections:xe(e.sections),selected:e.selected}),i=e.sections,o=new Set;return n.onSelect((s)=>{for(let c of[...o])c(s)}),{id:n.id,update(s){if(Pe(s)===Pe(i)){let c=Se(i);for(let[d,l]of Se(s))if(c.get(d)!==l)n.updateItem(d,{badge:l})}else n.setSections(xe(s));i=s},updateItem(s,c){n.updateItem(s,{...c.label!==void 0?{label:c.label}:{},...c.icon!==void 0?{icon:c.icon}:{},..."badge"in c?{badge:Z(c.badge)}:{}}),i=i.map((d)=>({...d,items:d.items.map((l)=>l.id===s?{...l,...c}:l)}))},select(s){n.setSelectedItem(s)},onSelect(s){return o.add(s),()=>o.delete(s)},destroy(){o.clear(),n.destroy()}}}};var Ci={async speak(e,t){if(!e)throw Error("speech.speak: text is required");if(r("speech")){await window.craft.speech.speak(e,t);return}if(typeof window<"u"&&window.speechSynthesis){let n=new window.SpeechSynthesisUtterance(e);if(t){if(t.rate!=null)n.rate=t.rate;if(t.pitch!=null)n.pitch=t.pitch;if(t.volume!=null)n.volume=t.volume;if(t.voice){let o=window.speechSynthesis.getVoices().find((s)=>s.voiceURI===t.voice||s.name===t.voice||s.lang===t.voice);if(o)n.voice=o}}window.speechSynthesis.speak(n)}},async stop(){if(r("speech")){await window.craft.speech.stop();return}if(typeof window<"u"&&window.speechSynthesis)window.speechSynthesis.cancel()},async pause(){if(r("speech")){await window.craft.speech.pause();return}if(typeof window<"u"&&window.speechSynthesis)window.speechSynthesis.pause()},async resume(){if(r("speech")){await window.craft.speech.resume();return}if(typeof window<"u"&&window.speechSynthesis)window.speechSynthesis.resume()},async isSpeaking(){if(r("speech"))return await window.craft.speech.isSpeaking();if(typeof window<"u"&&window.speechSynthesis)return!!window.speechSynthesis.speaking;return!1},async getVoices(){if(r("speech"))return await window.craft.speech.getVoices();if(typeof window<"u"&&window.speechSynthesis)return window.speechSynthesis.getVoices().map((t)=>({id:t.voiceURI||t.name,name:t.name,language:t.lang||"",quality:"default"}));return[]}};var Di={async isAvailable(){if(!r("speechRecognition"))return!1;return await window.craft.speechRecognition.isAvailable()},async start(e){if(!r("speechRecognition"))return{started:!1,reason:"bridge unavailable"};return await window.craft.speechRecognition.start(e)},async stop(){if(r("speechRecognition"))await window.craft.speechRecognition.stop()},onPartial(e){return a("craft:speechRecognition:partial",e)},onFinal(e){return a("craft:speechRecognition:final",e)}};var Li={async index(e){if(!r("spotlight"))return{ok:!1,reason:"bridge unavailable"};return await window.craft.spotlight.index(e)},async remove(e){if(!r("spotlight"))return{ok:!1};return await window.craft.spotlight.remove(e)},async removeAll(){if(!r("spotlight"))return{ok:!1};return await window.craft.spotlight.removeAll()}};var Fi={async get(e){if(!e)throw Error("tags.get: path is required");if(!r("tags"))return[];return await window.craft.tags.get(e)},async set(e,t){if(!e)throw Error("tags.set: path is required");if(!r("tags"))return!1;let n=Array.isArray(t)?t:[String(t)];return await window.craft.tags.set(e,n)},async clear(e){if(!e)throw Error("tags.clear: path is required");if(!r("tags"))return!1;return await window.craft.tags.clear(e)}};var Ui={get(){if(r("theme"))try{return window.craft.theme.get()}catch{}return{appearance:St()}},onChange(e){if(e(this.get()),r("theme"))return a("craft:theme",e);if(typeof window<"u"&&window.matchMedia){let t=window.matchMedia("(prefers-color-scheme: dark)"),n=()=>e({appearance:t.matches?"dark":"light"});return t.addEventListener("change",n),()=>t.removeEventListener("change",n)}return()=>{}},async current(){return this.get()}};function St(){if(typeof window>"u"||!window.matchMedia)return"light";return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}class Ae{_duration;_tickInterval;_remaining;_running=!1;_paused=!1;_complete=!1;_intervalId=null;_lastTick=0;_completionHandlers=new Set;_tickHandlers=new Set;constructor(e){if(this._duration=e.duration,this._tickInterval=e.tickInterval||1000,this._remaining=e.duration,e.onComplete)this._completionHandlers.add(e.onComplete);if(e.onTick)this._tickHandlers.add(e.onTick);if(e.autoStart)this.start()}get isRunning(){return this._running&&!this._paused}get isPaused(){return this._paused}get isComplete(){return this._complete}get remaining(){if(this._running&&!this._paused){let e=Date.now()-this._lastTick;return Math.max(0,this._remaining-e)}return Math.max(0,this._remaining)}get elapsed(){return this._duration-this.remaining}get duration(){return this._duration}get progress(){if(this._duration===0)return 1;return Math.min(1,this.elapsed/this._duration)}start(){if(this._running)return;this._running=!0,this._paused=!1,this._complete=!1,this._lastTick=Date.now(),this._startInterval()}stop(){this._clearInterval(),this._running=!1,this._paused=!1,this._remaining=this._duration}pause(){if(!this._running||this._paused)return;let e=Date.now()-this._lastTick;this._remaining=Math.max(0,this._remaining-e),this._clearInterval(),this._paused=!0}resume(){if(!this._paused)return;this._paused=!1,this._lastTick=Date.now(),this._startInterval()}reset(){this._clearInterval(),this._running=!1,this._paused=!1,this._complete=!1,this._remaining=this._duration}onComplete(e){return this._completionHandlers.add(e),()=>{this._completionHandlers.delete(e)}}onTick(e){return this._tickHandlers.add(e),()=>{this._tickHandlers.delete(e)}}_startInterval(){this._clearInterval(),this._intervalId=setInterval(()=>{let e=Date.now(),t=e-this._lastTick;this._lastTick=e,this._remaining=Math.max(0,this._remaining-t);for(let n of this._tickHandlers)try{n(this._remaining)}catch{}if(this._remaining<=0){this._clearInterval(),this._running=!1,this._complete=!0;for(let n of this._completionHandlers)try{n()}catch{}}},this._tickInterval)}_clearInterval(){if(this._intervalId!==null)clearInterval(this._intervalId),this._intervalId=null}}class Ie{_interval;_handler;_immediate;_running=!1;_intervalId=null;constructor(e){if(this._interval=e.interval,this._handler=e.handler,this._immediate=e.immediate!==!1,this._immediate)this.start()}get isRunning(){return this._running}start(){if(this._running)return;this._running=!0,this._intervalId=setInterval(()=>{try{this._handler()}catch{}},this._interval)}stop(){if(this._intervalId!==null)clearInterval(this._intervalId),this._intervalId=null;this._running=!1}}function Wi(e){return new Ae(e)}function $i(e){return new Ie(e)}function zi(e){return new Promise((t)=>setTimeout(t,e))}function Ki(e){let t=Math.ceil(e/1000),n=Math.floor(t/3600),i=Math.floor(t%3600/60),o=t%60;if(n>0)return`${n}:${String(i).padStart(2,"0")}:${String(o).padStart(2,"0")}`;return`${i}:${String(o).padStart(2,"0")}`}function ji(e){let t=Math.ceil(e/1000),n=Math.floor(t/3600),i=Math.floor(t%3600/60),o=t%60;if(n>0){if(i>0)return`${n}h ${i}m`;return`${n}h`}if(i>0){if(o>0)return`${i}m ${o}s`;return`${i}m`}return`${o}s`}var Gi={async addItem(e){if(r("touchbar"))await window.craft.touchbar.addItem(e)},async removeItem(e){if(r("touchbar"))await window.craft.touchbar.removeItem(e)},async updateItem(e,t){if(r("touchbar"))await window.craft.touchbar.updateItem(e,t)},async setLabel(e,t){if(r("touchbar"))await window.craft.touchbar.setLabel(e,t)},async setIcon(e,t){if(r("touchbar"))await window.craft.touchbar.setIcon(e,t)},async setEnabled(e,t){if(r("touchbar"))await window.craft.touchbar.setEnabled(e,t)},async setSliderValue(e,t){if(r("touchbar"))await window.craft.touchbar.setSliderValue(e,t)},async clear(){if(r("touchbar"))await window.craft.touchbar.clear()},async show(){if(r("touchbar"))await window.craft.touchbar.show()},async hide(){if(r("touchbar"))await window.craft.touchbar.hide()},onAction(e){return a("craft:touchbar:action",e)}};var Qi={async checkForUpdates(){if(!r("updater"))return;await window.craft.updater.checkForUpdates()},async checkInBackground(){if(!r("updater"))return;await window.craft.updater.checkInBackground()},async setAutomaticChecks(e){if(!r("updater"))return;await window.craft.updater.setAutomaticChecks(e)},async setCheckInterval(e){if(!r("updater"))return;if(!Number.isFinite(e))throw Error("setCheckInterval: must be a finite number");let t=e<=0?0:Math.max(60,Math.round(e));await window.craft.updater.setCheckInterval(t)},async setFeedURL(e){if(!r("updater"))return;await window.craft.updater.setFeedURL(e)},async getLastUpdateCheckDate(){if(!r("updater"))return null;return await window.craft.updater.getLastUpdateCheckDate()||null},async getUpdateInfo(){if(!r("updater"))return null;let e=await window.craft.updater.getUpdateInfo();if(!e||typeof e.version!=="string"||e.version.length===0)return null;return e},onAvailable(e){return a("craft:updateAvailable",e)},onDownloaded(e){return a("craft:updateDownloaded",e)},async verifySignature({payload:e,signatureB64:t,publicKeyB64:n}){let i=ke(e),o;try{o=await crypto.subtle.importKey("raw",N(n),{name:"Ed25519"},!1,["verify"])}catch{return!1}try{return await crypto.subtle.verify("Ed25519",o,N(t),i)}catch{return!1}},async verifyDownload({url:e,signatureB64:t,publicKeyB64:n,fetchInit:i}){let o;try{o=await fetch(e,i)}catch{return{ok:!1,reason:"fetch-failed"}}if(!o.ok)return{ok:!1,reason:"http-error",status:o.status};let s=new Uint8Array(await o.arrayBuffer()),c;try{c=await crypto.subtle.importKey("raw",N(n),{name:"Ed25519"},!1,["verify"])}catch{return{ok:!1,reason:"bad-key"}}let d=!1;try{d=await crypto.subtle.verify("Ed25519",c,N(t),ke(s))}catch{d=!1}if(!d)return{ok:!1,reason:"bad-signature"};return{ok:!0,payload:s}}};function ke(e){if(e instanceof ArrayBuffer)return new Uint8Array(e);let t=new ArrayBuffer(e.byteLength),n=new Uint8Array(t);return n.set(e),n}function N(e){if(typeof atob==="function"){let i=atob(e),o=new ArrayBuffer(i.length),s=new Uint8Array(o);for(let c=0;c<i.length;c++)s[c]=i.charCodeAt(c);return s}let t=Buffer.from(e,"base64"),n=new ArrayBuffer(t.length);return new Uint8Array(n).set(t),new Uint8Array(n)}var to={async recognizeText(e){if(!e)throw Error("vision.recognizeText: path is required");if(!r("vision"))return[];return await window.craft.vision.recognizeText(e)},async detectFaces(e){if(!e)throw Error("vision.detectFaces: path is required");if(!r("vision"))return[];return await window.craft.vision.detectFaces(e)},async detectBarcodes(e){if(!e)throw Error("vision.detectBarcodes: path is required");if(!r("vision"))return[];return await window.craft.vision.detectBarcodes(e)}};var io={onFocus(e){if(r("window"))return a("craft:window:focus",()=>e());return ee("focus",e)},onBlur(e){if(r("window"))return a("craft:window:blur",()=>e());return ee("blur",e)},onResize(e){if(r("window"))return a("craft:window:resize",e);if(typeof window>"u")return()=>{};let t=()=>e({width:window.innerWidth,height:window.innerHeight});return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},onMove(e){if(r("window"))return a("craft:window:move",e);return()=>{}},onClose(e){if(r("window"))return a("craft:window:close",()=>e());return ee("beforeunload",e)},onMinimize(e){if(r("window"))return a("craft:window:minimize",()=>e());if(typeof document>"u")return()=>{};let t=()=>{if(document.visibilityState==="hidden")e()};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},onRestore(e){if(r("window"))return a("craft:window:restore",()=>e());if(typeof document>"u")return()=>{};let t=()=>{if(document.visibilityState==="visible")e()};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)}};function ee(e,t){if(typeof window>"u")return()=>{};let n=()=>t();return window.addEventListener(e,n),()=>window.removeEventListener(e,n)}export{Q as DEFAULT_WATCH_INTERVAL_MS,vt as MAX_WATCH_INTERVAL_MS,ht as MIN_WATCH_INTERVAL_MS,Nn as MODAL_STYLES,Rt as TOAST_STYLES,Ln as alert,Ft as app,Ut as appleScript,$t as audio,jt as battery,Gt as biometric,Qt as bluetooth,tr as bonjour,cr as clipboard,Fn as closeAllModals,Rn as confirm,ur as contextMenu,mr as continuityCamera,hr as coreml,R as crashReporter,$i as createInterval,Wi as createTimer,Pr as deepLinks,zi as delay,Bt as dismissAlertById,Dt as dismissAllAlerts,Lr as dragOut,Nr as fileAssociations,pe as focus,Wr as focusShortcutsReady,ji as formatCompact,Qr as formatShortcut,Ki as formatTime,Kr as fs,Tt as getActiveAlertCount,_n as getActiveModalCount,ir as getCapabilities,Fe as getCapability,Dr as getDialogBridgeScript,tn as getRegisteredHotkeys,Yr as globalShortcuts,O as handoff,Hr as hasFocusShortcuts,an as iap,or as isAvailable,Or as isDragOutAvailable,dn as keychain,fn as liveActivities,gn as localServer,vn as location,xn as log,In as menu,Cn as midi,Hn as nativeAutoLaunch,zn as nativeWindow,Vn as network,Xn as notifications,Mt as notify,tt as parseShortcut,Zn as pdf,ri as permissions,oi as printing,On as prompt,$e as redactPII,Zr as registerHotkey,At as requestNotificationPermission,ci as screen,ui as screenCapture,J as screenSharing,hi as serial,bi as serviceMenu,Si as shell,ie as showAlert,Er as showAlertDialog,kr as showColorPicker,Cr as showConfirmDialog,Mr as showErrorDialog,Dn as showErrorModal,Ct as showErrorToast,ft as showInfoModal,It as showInfoToast,L as showMessageBox,k as showModal,Ar as showOpenDialog,pt as showQuestionModal,Ir as showSaveDialog,Tn as showSuccessModal,kt as showSuccessToast,D as showToast,Br as showWarningDialog,Bn as showWarningModal,Et as showWarningToast,Pt as sidebar,ze as signPayload,Ci as speech,Di as speechRecognition,Li as spotlight,An as standardMenus,Fi as tags,Ui as theme,Gi as touchbar,en as unregisterAllHotkeys,ot as unregisterHotkey,Qi as updater,to as vision,mi as watchScreenSharing,io as windowEvents};