@stacksjs/desktop 0.2.726 → 0.2.727

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.js CHANGED
@@ -1,4 +1,4 @@
1
- function De(){if(typeof Notification<"u"&&Notification.permission==="granted")return!0;return!1}function H(){return typeof window<"u"&&typeof document<"u"}async function kt(){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 Te(){return`alert-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function Re(e){switch(e){case"info":return"&#x2139;";case"success":return"&#x2714;";case"warning":return"&#x26A0;";case"error":return"&#x2716;";default:return"&#x2139;"}}function Le(e="top-right"){if(!H())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 Oe(e){let{options:t}=e,n=Re(t.type),i=t.type||"info",o=t.duration!==0;return`
1
+ function Te(){if(typeof Notification<"u"&&Notification.permission==="granted")return!0;return!1}function U(){return typeof window<"u"&&typeof document<"u"}async function kt(){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 Re(e){switch(e){case"info":return"&#x2139;";case"success":return"&#x2714;";case"warning":return"&#x26A0;";case"error":return"&#x2716;";default:return"&#x2139;"}}function Le(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 Oe(e){let{options:t}=e,n=Re(t.type),i=t.type||"info",o=t.duration!==0;return`
2
2
  <div class="stx-toast ${i}" data-alert-id="${e.id}" role="alert" aria-live="polite">
3
3
  <div class="stx-toast-icon">${n}</div>
4
4
  <div class="stx-toast-content">
@@ -7,7 +7,7 @@ function De(){if(typeof Notification<"u"&&Notification.permission==="granted")re
7
7
  </div>
8
8
  ${o?'<button class="stx-toast-close" aria-label="Close">&times;</button>':""}
9
9
  </div>
10
- `}function ie(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function M(e){if(e.timeout)clearTimeout(e.timeout);if(x.delete(e.id),e.element&&H())e.element.classList.add("dismissing"),setTimeout(()=>{e.element?.remove()},200)}async function oe(e){let t=Te(),n=De(),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(H())try{let s=Le(e.position),c=document.createElement("div");c.innerHTML=Oe(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")){M(o);return}if(e.onClick)e.onClick()})}catch{}if(i>0)o.timeout=setTimeout(()=>{M(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 oe({...e,position:e.position||"top-right"})}async function Et(e,t=3000){return D({message:e,type:"info",duration:t})}async function Ct(e,t=3000){return D({message:e,type:"success",duration:t})}async function Bt(e,t=3000){return D({message:e,type:"warning",duration:t})}async function Mt(e,t=5000){return D({message:e,type:"error",duration:t})}async function Dt(e,t,n="info"){return oe({title:e,message:t,type:n})}function Tt(e){let t=x.get(e);if(t)M(t)}function Rt(){for(let e of x.values())M(e)}function Lt(){return x.size}var Ot=`
10
+ `}function ie(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 oe(e){let t=De(),n=Te(),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=Le(e.position),c=document.createElement("div");c.innerHTML=Oe(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 T(e){return oe({...e,position:e.position||"top-right"})}async function Et(e,t=3000){return T({message:e,type:"info",duration:t})}async function Ct(e,t=3000){return T({message:e,type:"success",duration:t})}async function Mt(e,t=3000){return T({message:e,type:"warning",duration:t})}async function Bt(e,t=5000){return T({message:e,type:"error",duration:t})}async function Tt(e,t,n="info"){return oe({title:e,message:t,type:n})}function Dt(e){let t=x.get(e);if(t)B(t)}function Rt(){for(let e of x.values())B(e)}function Lt(){return x.size}var Ot=`
11
11
  .stx-toast-container {
12
12
  position: fixed;
13
13
  z-index: 10001;
@@ -109,15 +109,15 @@ function De(){if(typeof Notification<"u"&&Notification.permission==="granted")re
109
109
  .stx-toast.success { border-left: 4px solid #27ae60; }
110
110
  .stx-toast.warning { border-left: 4px solid #f39c12; }
111
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 ae={name:"",version:"0.0.0"},qt={async icon(e){if(!e.startsWith("/")||!e.endsWith(".app")||e.includes("\x00"))throw Error("Application icons require an absolute .app path.");let t=u("app");if(!t.icon)throw Error("This Craft runtime does not support native application icons.");return t.icon(e)},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 ae;let e=await window.craft.app.getInfo();return{...ae,...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 Wt={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,jt={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 Yt={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 Jt={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 _e=/^[\da-f]*$/i;function Fe(e,t){if(typeof t!=="string"||!_e.test(t)||t.length%2!==0)throw Error(`${e}: must be a hex string with even length, got ${JSON.stringify(t)}`)}var er={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(Fe("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 nr={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 se=[{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 ar(){return se.map(({name:e,support:t})=>({name:e,support:t,available:r(e)}))}function Ne(e){let t=se.find((n)=>n.name===e);if(!t)return;return{...t,available:r(e)}}function sr(e){let t=Ne(e);return!!t&&t.available}var ur={async historySnapshot(e=-1){if(!Number.isSafeInteger(e))throw Error("Clipboard history requires an integer change cursor.");let t=u("clipboard");if(!t.historySnapshot)throw Error("This Craft runtime does not support protected clipboard history.");return t.historySnapshot(e)},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([qe(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 qe(e){return e.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi,"").replace(/<\/?(br|p|div|li|h[1-6])\b[^>]*>/gi,`
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 ae={name:"",version:"0.0.0"},qt={async icon(e){if(!e.startsWith("/")||!e.endsWith(".app")||e.includes("\x00"))throw Error("Application icons require an absolute .app path.");let t=u("app");if(!t.icon)throw Error("This Craft runtime does not support native application icons.");return t.icon(e)},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 ae;let e=await window.craft.app.getInfo();return{...ae,...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 Wt={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,jt={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 Yt={async isCharging(){if(r("power"))return await window.craft.power.isCharging();let e=await D();return e?!!e.charging:!1},async isPluggedIn(){if(r("power"))return await window.craft.power.isPluggedIn();let e=await D();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 D();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 D();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 D(){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 Jt={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 _e=/^[\da-f]*$/i;function Fe(e,t){if(typeof t!=="string"||!_e.test(t)||t.length%2!==0)throw Error(`${e}: must be a hex string with even length, got ${JSON.stringify(t)}`)}var er={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(Fe("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 nr={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 se=[{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 ar(){return se.map(({name:e,support:t})=>({name:e,support:t,available:r(e)}))}function Ne(e){let t=se.find((n)=>n.name===e);if(!t)return;return{...t,available:r(e)}}function sr(e){let t=Ne(e);return!!t&&t.available}var ur={async historySnapshot(e=-1){if(!Number.isSafeInteger(e))throw Error("Clipboard history requires an integer change cursor.");let t=u("clipboard");if(!t.historySnapshot)throw Error("This Craft runtime does not support protected clipboard history.");return t.historySnapshot(e)},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([qe(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 qe(e){return e.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi,"").replace(/<\/?(br|p|div|li|h[1-6])\b[^>]*>/gi,`
113
113
  `).replace(/<[^>]+>/g,"").replace(/&nbsp;/g," ").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/\n{3,}/g,`
114
114
 
115
- `).trim()}function de(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(de)}}async function ce(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(de)});return{id:typeof n?.id==="string"?n.id:null,targetId:n?.targetId}}var pr={available(){return r("nativeUI")},async show(e){return await ce(e)!==null},async pick(e){return(await ce(e))?.id??null},onAction(e){return a("craft:contextmenu:action",(t)=>{if(typeof t.id==="string")e({id:t.id,targetId:t.targetId??""})})}};var wr={async listCameras(){if(!r("continuityCamera"))return[];return await window.craft.continuityCamera.listCameras()}};var yr={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=[],U=!0,W,z,R={async report(e){if(r("crashReporter")){await window.craft.crashReporter.report(e);return}if(!U)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}U=e},async isEnabled(){if(r("crashReporter"))return await window.craft.crashReporter.isEnabled();return U},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 Ve(e)}},He="craft:crashReporter:pending",Ue=/[\w.+-]+@[\w-]+\.[\w.-]+/g,We=/\b(?:\d{1,3}\.){3}\d{1,3}\b/g,$e=/\/(?:Users|home)\/[^\s/'"`]+/g;function ze(e){let t=(n)=>n.replace(Ue,"<email>").replace(We,"<ip>").replace($e,"/<home>");return{...e,message:t(e.message),stack:t(e.stack)}}async function je(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 ue(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 Ve(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??He,f=Ke(l),h=!1,y=null,m=null,Ce=typeof o==="function"?o:o===!1?(b)=>b:ze;async function Be(b){let C=JSON.stringify({entries:b}),B={"Content-Type":"application/json",...s};if(i)B["X-Craft-Signature"]=await je(i,C);let ne=0,q=1000;while(!h)try{let A=await fetch(t,{method:"POST",headers:B,body:C});if(A.ok)return;if(A.status>=400&&A.status<500)return;throw Error(`HTTP ${A.status}`)}catch(A){if(ne+=1,ne>c)throw f=[...b,...f],ue(l,f),A;await new Promise((Me)=>{setTimeout(Me,q)}),q=Math.min(q*2,60000)}}async function re(){if(h||m)return m??void 0;let b=await R.flush();if(b.length>0)await R.clear();if(f=[...f,...b.map((B)=>Ce(B))],f.length===0)return;let C=f;return f=[],ue(l,f),m=Be(C).catch(()=>{}).finally(()=>{m=null}),m}if(n>0)y=setInterval(()=>{re().catch(()=>{})},n);return{async flushNow(){await re()},stop(){if(h=!0,y)clearInterval(y);y=null},pending(){return[...f]}}}var Ar={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 Ye(){if(typeof window>"u")return;return window.craft?.dialog}var Ge={error:"critical",warning:"warning",question:"info",info:"info",none:"info"};function Xe(e){let t=[e.title?e.message:"",e.detail??""].filter(Boolean).join(`
115
+ `).trim()}function de(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(de)}}async function ce(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(de)});return{id:typeof n?.id==="string"?n.id:null,targetId:n?.targetId}}var pr={available(){return r("nativeUI")},async show(e){return await ce(e)!==null},async pick(e){return(await ce(e))?.id??null},onAction(e){return a("craft:contextmenu:action",(t)=>{if(typeof t.id==="string")e({id:t.id,targetId:t.targetId??""})})}};var wr={async listCameras(){if(!r("continuityCamera"))return[];return await window.craft.continuityCamera.listCameras()}};var yr={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=[],W=!0,z,j,R={async report(e){if(r("crashReporter")){await window.craft.crashReporter.report(e);return}if(!W)return;let t=e instanceof Error?{timestamp:Date.now(),severity:"error",message:e.message,source:"js",stack:e.stack||"",userId:z,appVersion:j}:{timestamp:Date.now(),severity:e.severity||"error",message:e.message||"",source:e.source||"js",stack:e.stack||"",userId:z,appVersion:j};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}W=e},async isEnabled(){if(r("crashReporter"))return await window.craft.crashReporter.isEnabled();return W},async setUser(e){if(r("crashReporter")){await window.craft.crashReporter.setUser(e);return}z=e||void 0},async setAppVersion(e){if(r("crashReporter")){await window.craft.crashReporter.setAppVersion(e);return}j=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 Ve(e)}},He="craft:crashReporter:pending",Ue=/[\w.+-]+@[\w-]+\.[\w.-]+/g,We=/\b(?:\d{1,3}\.){3}\d{1,3}\b/g,$e=/\/(?:Users|home)\/[^\s/'"`]+/g;function ze(e){let t=(n)=>n.replace(Ue,"<email>").replace(We,"<ip>").replace($e,"/<home>");return{...e,message:t(e.message),stack:t(e.stack)}}async function je(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 ue(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 Ve(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??He,f=Ke(l),h=!1,y=null,m=null,Ce=typeof o==="function"?o:o===!1?(b)=>b:ze;async function Me(b){let C=JSON.stringify({entries:b}),M={"Content-Type":"application/json",...s};if(i)M["X-Craft-Signature"]=await je(i,C);let ne=0,H=1000;while(!h)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(ne+=1,ne>c)throw f=[...b,...f],ue(l,f),A;await new Promise((Be)=>{setTimeout(Be,H)}),H=Math.min(H*2,60000)}}async function re(){if(h||m)return m??void 0;let b=await R.flush();if(b.length>0)await R.clear();if(f=[...f,...b.map((M)=>Ce(M))],f.length===0)return;let C=f;return f=[],ue(l,f),m=Me(C).catch(()=>{}).finally(()=>{m=null}),m}if(n>0)y=setInterval(()=>{re().catch(()=>{})},n);return{async flushNow(){await re()},stop(){if(h=!0,y)clearInterval(y);y=null},pending(){return[...f]}}}var Ar={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 Ye(){if(typeof window>"u")return;return window.craft?.dialog}var Ge={error:"critical",warning:"warning",question:"info",info:"info",none:"info"};function Xe(e){let t=[e.title?e.message:"",e.detail??""].filter(Boolean).join(`
117
117
 
118
- `);return{title:e.title||e.message,message:t||void 0,style:Ge[e.type??"none"]??"info",buttons:e.buttons}}function fe(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 j(){if(typeof window<"u"&&window.craft?.dialog)return!0;return!1}async function kr(e={}){if(j())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 Er(e={}){if(j()){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=Ye();if(typeof t?.showMessageBox==="function")try{return fe(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 fe(await t.showAlert(Xe(e)),e)}catch(d){console.warn("[stx-dialog] Failed to show native alert:",d)}let n=e.buttons||["OK"],i=e.detail?`
118
+ `);return{title:e.title||e.message,message:t||void 0,style:Ge[e.type??"none"]??"info",buttons:e.buttons}}function fe(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 kr(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 Er(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=Ye();if(typeof t?.showMessageBox==="function")try{return fe(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 fe(await t.showAlert(Xe(e)),e)}catch(d){console.warn("[stx-dialog] Failed to show native alert:",d)}let n=e.buttons||["OK"],i=e.detail?`
119
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 Cr(e={}){if(j()){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 Br(e,t){await L({type:"info",title:t||"Alert",message:e,buttons:["OK"]})}async function Mr(e,t){return(await L({type:"question",title:t||"Confirm",message:e,buttons:["OK","Cancel"],defaultButton:0,cancelButton:1})).response===0}async function Dr(e,t){await L({type:"error",title:t||"Error",message:e,buttons:["OK"]})}async function Tr(e,t){await L({type:"warning",title:t||"Warning",message:e,buttons:["OK"]})}function Rr(){return`
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 Cr(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 Mr(e,t){await L({type:"info",title:t||"Alert",message:e,buttons:["OK"]})}async function Br(e,t){return(await L({type:"question",title:t||"Confirm",message:e,buttons:["OK","Cancel"],defaultButton:0,cancelButton:1})).response===0}async function Tr(e,t){await L({type:"error",title:t||"Error",message:e,buttons:["OK"]})}async function Dr(e,t){await L({type:"warning",title:t||"Warning",message:e,buttons:["OK"]})}function Rr(){return`
121
121
  // STX Desktop Dialog Bridge
122
122
  // Provides convenient wrappers around window.craft.dialog APIs
123
123
  window.stxDialog = {
@@ -196,10 +196,10 @@ window.stxDialog = {
196
196
  // Check if dialog is available
197
197
  isAvailable: () => typeof window.craft?.dialog !== 'undefined',
198
198
  };
199
- `}async function _r(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 Fr(){return r("dragOut")}var Hr={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 Je={supported:!1,isFocused:null,authorization:"unsupported"};function pe(){return{ok:!1,error:"Focus control is only available in a Craft window on macOS"}}var me={async getStatus(){if(!r("focus"))return{...Je};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 pe();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 pe();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 $r(...e){if(e.length===0)return!1;let t=new Set(await me.listShortcuts());return e.every((n)=>t.has(n))}async function zr(...e){if(e.length===0)return!1;let{canList:t,shortcuts:n}=await me.listShortcutsResult();if(!t)return"unknown";let i=new Set(n);return e.every((o)=>i.has(o))}var Vr={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 Ze(n);return new TextEncoder().encode(n)},async writeFile(e,t){await u("fs").writeFile(e,t)},async writeBuffer(e,t){let n=Qe(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 et(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,h=()=>{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){h();return}if(l==null)l=setTimeout(h,c)});return{id:i,async stop(){if(f)return;if(f=!0,y(),l)clearTimeout(l),l=null;if(d.length>0)h();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 Qe(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 Ze(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 et(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 Xr={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 v=new Map,tt=0,_=!1;function rt(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 en(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 nt(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 ge(e){for(let[,t]of v)if(nt(e,t.parsed)){e.preventDefault(),e.stopPropagation();try{t.handler()}catch{}break}}function it(){if(_)return;if(typeof document>"u")return;document.addEventListener("keydown",ge,!0),_=!0}function K(){if(!_)return;if(typeof document>"u")return;document.removeEventListener("keydown",ge,!0),_=!1}async function ot(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 tn(e,t){let n=`hotkey_${++tt}_${Date.now()}`,i=rt(e);v.set(n,{shortcut:e,handler:t,parsed:i}),ot(n,e),it();let o={shortcut:e,id:n,unregister(){at(o)}};return o}function at(e){if(v.delete(e.id),V(e.id),v.size===0)K()}function rn(){for(let[e]of v)V(e);v.clear(),K()}function nn(){return Array.from(v.entries()).map(([e,t])=>({shortcut:t.shortcut,id:e,unregister(){if(v.delete(e),V(e),v.size===0)K()}}))}var cn={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 ln={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 mn={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 hn={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:h})=>{clearTimeout(l),f();let y=o??`<!doctype html><meta charset="utf-8"><title>Done</title>
199
+ `}async function _r(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 Fr(){return r("dragOut")}var Hr={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 Je={supported:!1,isFocused:null,authorization:"unsupported"};function pe(){return{ok:!1,error:"Focus control is only available in a Craft window on macOS"}}var me={async getStatus(){if(!r("focus"))return{...Je};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 pe();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 pe();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 $r(...e){if(e.length===0)return!1;let t=new Set(await me.listShortcuts());return e.every((n)=>t.has(n))}async function zr(...e){if(e.length===0)return!1;let{canList:t,shortcuts:n}=await me.listShortcutsResult();if(!t)return"unknown";let i=new Set(n);return e.every((o)=>i.has(o))}var Vr={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 Ze(n);return new TextEncoder().encode(n)},async writeFile(e,t){await u("fs").writeFile(e,t)},async writeBuffer(e,t){let n=Qe(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 et(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,h=()=>{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){h();return}if(l==null)l=setTimeout(h,c)});return{id:i,async stop(){if(f)return;if(f=!0,y(),l)clearTimeout(l),l=null;if(d.length>0)h();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 Qe(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 Ze(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 et(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 Xr={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 v=new Map,tt=0,_=!1;function rt(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 en(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 nt(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 ge(e){for(let[,t]of v)if(nt(e,t.parsed)){e.preventDefault(),e.stopPropagation();try{t.handler()}catch{}break}}function it(){if(_)return;if(typeof document>"u")return;document.addEventListener("keydown",ge,!0),_=!0}function V(){if(!_)return;if(typeof document>"u")return;document.removeEventListener("keydown",ge,!0),_=!1}async function ot(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 Y(e){if(typeof window>"u")return;let t=window.craft;if(!t?.hotkeys?.unregister)return;try{await t.hotkeys.unregister(e)}catch{}}function tn(e,t){let n=`hotkey_${++tt}_${Date.now()}`,i=rt(e);v.set(n,{shortcut:e,handler:t,parsed:i}),ot(n,e),it();let o={shortcut:e,id:n,unregister(){at(o)}};return o}function at(e){if(v.delete(e.id),Y(e.id),v.size===0)V()}function rn(){for(let[e]of v)Y(e);v.clear(),V()}function nn(){return Array.from(v.entries()).map(([e,t])=>({shortcut:t.shortcut,id:e,unregister(){if(v.delete(e),Y(e),v.size===0)V()}}))}var cn={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 ln={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 mn={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 hn={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:h})=>{clearTimeout(l),f();let y=o??`<!doctype html><meta charset="utf-8"><title>Done</title>
200
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
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:h,port:s.port})})})}};var bn={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 Sn={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 kn={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()]}},st=0;function ct(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.${st++}`;if(s)t.set(d,s);return{...c,id:d}})}))},handlers:t}}var Y=null,En={async set(e){if(!r("menu"))return!1;let{payload:t,handlers:n}=ct(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 Mn={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 dt(){return!1}function G(){return typeof window<"u"&&typeof document<"u"}var S=[];function ut(){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 ft(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>`}),`
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:h,port:s.port})})})}};var bn={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 Sn={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 kn={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()]}},st=0;function ct(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.${st++}`;if(s)t.set(d,s);return{...c,id:d}})}))},handlers:t}}var G=null,En={async set(e){if(!r("menu"))return!1;let{payload:t,handlers:n}=ct(e);if(G?.(),G=null,n.size>0)G=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 Bn={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 dt(){return!1}function X(){return typeof window<"u"&&typeof document<"u"}var S=[];function ut(){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 ft(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
203
  <div class="stx-modal-overlay" data-modal-id="${e.id}">
204
204
  <div class="stx-modal ${o}" role="dialog" aria-modal="true" aria-labelledby="${e.id}-title">
205
205
  <div class="stx-modal-icon">${n}</div>
@@ -210,7 +210,7 @@ window.stxDialog = {
210
210
  <div class="stx-modal-buttons">${s}</div>
211
211
  </div>
212
212
  </div>
213
- `}function we(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=dt(),n=ut();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=ft(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 pt(e,t){return k({title:e,message:t,type:"info"})}async function Tn(e,t){return k({title:e,message:t,type:"warning"})}async function Rn(e,t){return k({title:e,message:t,type:"error"})}async function Ln(e,t){return k({title:e,message:t,type:"success"})}async function mt(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 On(e,t="Confirm"){return(await mt(t,e)).buttonIndex===1}async function _n(e,t="Alert"){await pt(t,e)}async function Fn(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 Nn(){return S.length}function qn(){while(S.length>0){let e=S[S.length-1];g(e,0,!0)}}var Hn=`
213
+ `}function we(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&&X())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=dt(),n=ut();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(X())try{let s=document.createElement("div");s.innerHTML=ft(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 pt(e,t){return k({title:e,message:t,type:"info"})}async function Dn(e,t){return k({title:e,message:t,type:"warning"})}async function Rn(e,t){return k({title:e,message:t,type:"error"})}async function Ln(e,t){return k({title:e,message:t,type:"success"})}async function mt(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 On(e,t="Confirm"){return(await mt(t,e)).buttonIndex===1}async function _n(e,t="Alert"){await pt(t,e)}async function Fn(e,t="",n="Input"){if(X()&&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 Nn(){return S.length}function qn(){while(S.length>0){let e=S[S.length-1];g(e,0,!0)}}var Hn=`
214
214
  .stx-modal-overlay {
215
215
  position: fixed;
216
216
  inset: 0;
@@ -342,4 +342,4 @@ window.stxDialog = {
342
342
  background: #555;
343
343
  }
344
344
  }
345
- `;var $n={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 w(e){let t=X();if(!t)return Promise.resolve();try{return Promise.resolve(e(t)).then(()=>{return},()=>{return})}catch{return Promise.resolve()}}var Kn={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:()=>w((e)=>e.close?.()),show:()=>w((e)=>e.show?.()),hide:()=>w((e)=>e.hide?.()),focus:()=>w((e)=>e.focus?.()),minimize:()=>w((e)=>e.minimize?.()),maximize:()=>w((e)=>e.maximize?.()),center:()=>w((e)=>e.center?.()),startDrag:()=>w((e)=>e.startDrag?.()),setTitle:(e)=>w((t)=>t.setTitle?.(e)),setSize:(e,t)=>w((n)=>n.setSize?.(e,t)),setAppearance:(e)=>w((t)=>t.setAppearance?.(e))};async function J(e){if(!r("tray"))return;let t=window.craft.tray;await e(t)}var Gn={setIcon:(e)=>J((t)=>t.setIcon(e)),setTitle:(e)=>J((t)=>t.setTitle(e)),setTooltip:(e)=>J((t)=>t.setTooltip(e))};var Qn={async connectionType(){if(r("network"))return await window.craft.network.connectionType();return he()},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:he(),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 he(){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 ti={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=gt(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 gt(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 ii={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 si={async check(e){if(r("permissions"))return await window.craft.permissions.check(e);return await ve(e)},async request(e){if(r("permissions"))return await window.craft.permissions.request(e);return await wt(e)},async openSettings(e){if(r("permissions"))await window.craft.permissions.openSettings(e)}};async function ve(e){if(typeof navigator>"u"||!navigator.permissions?.query)return"not-supported";try{let t=await navigator.permissions.query({name:e});return ht(t.state)}catch{return"not-supported"}}async function wt(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 ve(e)}function ht(e){if(e==="granted")return"granted";if(e==="denied")return"denied";if(e==="prompt")return"undetermined";return"undetermined"}var ui={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 pi={async getDisplays(){if(r("screen"))return await window.craft.screen.getDisplays();return ye()},async getPrimary(){if(r("screen")){let e=await window.craft.screen.getPrimary();return e&&typeof e.width==="number"?e:null}return ye()[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 ye(){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 wi={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 vt=250,yt=60000,Z=2000,be={sharing:!1,signals:{systemScreenShare:!1,remoteSession:!1,conferenceSharing:!1,screenRecording:!1},sources:[]};function bt(){return{...be,signals:{...be.signals},sources:[]}}var Q={async getState(){if(!r("screenSharing"))return bt();return await window.craft.screenSharing.getState()},async watch(e=Z){let t=Number.isFinite(e)?Math.min(yt,Math.max(vt,Math.round(e))):Z;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 yi(e,t=Z){let n=Q.onChange(e);try{await Q.watch(t)}catch(o){throw n(),o}let i;return()=>{if(!i)n(),i=Q.stop();return i}}var Pi={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 Ii={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,xe=!1;function xt(){if(xe)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)}),xe=!0}var Pt=new Set(["javascript:","data:","file:","vbscript:"]),Ci={async openExternal(e){let t=e.trim().toLowerCase();for(let n of Pt)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(xt(),!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 ee(e){if(e===null||e===void 0||e===0)return"";return String(e)}function Pe(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:ee(n.badge)||void 0}))}))}function Se(e){return JSON.stringify(e.map((t)=>[t.id,t.header??"",t.items.map((n)=>[n.id,n.label,n.icon??""])]))}function Ae(e){return new Map(e.flatMap((t)=>t.items.map((n)=>[n.id,ee(n.badge)])))}var St={available(){return r("nativeUI")&&typeof window.craft?.nativeUI?._emitSidebarSelect==="function"},create(e){if(!St.available())return null;let t=window.craft?.nativeUI;if(!t)return null;let n=t.createSidebar({id:e.id,sections:Pe(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(Se(s)===Se(i)){let c=Ae(i);for(let[d,l]of Ae(s))if(c.get(d)!==l)n.updateItem(d,{badge:l})}else n.setSections(Pe(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:ee(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 Ri={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 _i={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 qi={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 Wi={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 ji={get(){if(r("theme"))try{return window.craft.theme.get()}catch{}return{appearance:At()}},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 At(){if(typeof window>"u"||!window.matchMedia)return"light";return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}class Ie{_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 ke{_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 Vi(e){return new Ie(e)}function Yi(e){return new ke(e)}function Gi(e){return new Promise((t)=>setTimeout(t,e))}function Xi(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 eo={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 no={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=Ee(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),Ee(s))}catch{d=!1}if(!d)return{ok:!1,reason:"bad-signature"};return{ok:!0,payload:s}}};function Ee(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 ao={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 uo={onFocus(e){if(r("window"))return a("craft:window:focus",()=>e());return te("focus",e)},onBlur(e){if(r("window"))return a("craft:window:blur",()=>e());return te("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 te("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 te(e,t){if(typeof window>"u")return()=>{};let n=()=>t();return window.addEventListener(e,n),()=>window.removeEventListener(e,n)}function It(e,t={}){if(!Number.isInteger(e)||e<0||e>86400000)return Promise.reject(RangeError("delayMs must be an integer between 0 and 86400000"));let{signal:n}=t,i=()=>new DOMException("Background delay aborted","AbortError");if(n?.aborted)return Promise.reject(i());if(r("timers"))return u("timers").sleep(e,t);if(typeof window<"u"&&window.craft)return Promise.reject(Error("Native background deadlines require a Craft runtime with timers.sleep support"));return new Promise((o,s)=>{let c=setTimeout(()=>{n?.removeEventListener("abort",d),o()},e);function d(){clearTimeout(c),n?.removeEventListener("abort",d),s(i())}n?.addEventListener("abort",d,{once:!0})})}export{Z as DEFAULT_WATCH_INTERVAL_MS,yt as MAX_WATCH_INTERVAL_MS,vt as MIN_WATCH_INTERVAL_MS,Hn as MODAL_STYLES,Ot as TOAST_STYLES,_n as alert,qt as app,Wt as appleScript,jt as audio,It as backgroundDelay,Yt as battery,Jt as biometric,er as bluetooth,nr as bonjour,ur as clipboard,qn as closeAllModals,On as confirm,pr as contextMenu,wr as continuityCamera,yr as coreml,R as crashReporter,Yi as createInterval,Vi as createTimer,Ar as deepLinks,Gi as delay,Tt as dismissAlertById,Rt as dismissAllAlerts,_r as dragOut,Hr as fileAssociations,me as focus,zr as focusShortcutsReady,Ji as formatCompact,en as formatShortcut,Xi as formatTime,Vr as fs,Lt as getActiveAlertCount,Nn as getActiveModalCount,ar as getCapabilities,Ne as getCapability,Rr as getDialogBridgeScript,nn as getRegisteredHotkeys,Xr as globalShortcuts,O as handoff,$r as hasFocusShortcuts,cn as iap,sr as isAvailable,Fr as isDragOutAvailable,ln as keychain,mn as liveActivities,hn as localServer,bn as location,Sn as log,En as menu,Mn as midi,$n as nativeAutoLaunch,Gn as nativeTray,Kn as nativeWindow,Qn as network,ti as notifications,Dt as notify,rt as parseShortcut,ii as pdf,si as permissions,ui as printing,Fn as prompt,ze as redactPII,tn as registerHotkey,kt as requestNotificationPermission,pi as screen,wi as screenCapture,Q as screenSharing,Pi as serial,Ii as serviceMenu,Ci as shell,oe as showAlert,Br as showAlertDialog,Cr as showColorPicker,Mr as showConfirmDialog,Dr as showErrorDialog,Rn as showErrorModal,Mt as showErrorToast,pt as showInfoModal,Et as showInfoToast,L as showMessageBox,k as showModal,kr as showOpenDialog,mt as showQuestionModal,Er as showSaveDialog,Ln as showSuccessModal,Ct as showSuccessToast,D as showToast,Tr as showWarningDialog,Tn as showWarningModal,Bt as showWarningToast,St as sidebar,je as signPayload,Ri as speech,_i as speechRecognition,qi as spotlight,kn as standardMenus,Wi as tags,ji as theme,eo as touchbar,rn as unregisterAllHotkeys,at as unregisterHotkey,no as updater,ao as vision,yi as watchScreenSharing,uo as windowEvents};
345
+ `;var $n={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 J(){if(!r("window"))return null;return window.craft.window}function w(e){let t=J();if(!t)return Promise.resolve();try{return Promise.resolve(e(t)).then(()=>{return},()=>{return})}catch{return Promise.resolve()}}var Kn={get available(){return J()!==null},open(e){let t=()=>{if(typeof window<"u"&&e.url)window.open(e.url,e.name);return{name:e.name}},n=J();if(!n?.open)return Promise.resolve(t());return n.open(e).then((i)=>({name:i?.name||e.name})).catch(t)},close:()=>w((e)=>e.close?.()),show:()=>w((e)=>e.show?.()),hide:()=>w((e)=>e.hide?.()),focus:()=>w((e)=>e.focus?.()),minimize:()=>w((e)=>e.minimize?.()),maximize:()=>w((e)=>e.maximize?.()),center:()=>w((e)=>e.center?.()),startDrag:()=>w((e)=>e.startDrag?.()),setTitle:(e)=>w((t)=>t.setTitle?.(e)),setSize:(e,t)=>w((n)=>n.setSize?.(e,t)),setAppearance:(e)=>w((t)=>t.setAppearance?.(e))};async function N(e){if(!r("tray"))return;let t=window.craft.tray;await e(t)}var Gn={setIcon:(e)=>N((t)=>t.setIcon(e)),setTitle:(e)=>N((t)=>t.setTitle(e)),setTooltip:(e)=>N((t)=>t.setTooltip(e)),setMenu:(e)=>N((t)=>t.setMenu(e)),onClick:(e)=>a("craft:tray:click",e),onMenuAction:(e)=>a("craft:tray:menuAction",e)};var Qn={async connectionType(){if(r("network"))return await window.craft.network.connectionType();return he()},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:he(),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 he(){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 ti={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=gt(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 gt(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 ii={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 si={async check(e){if(r("permissions"))return await window.craft.permissions.check(e);return await ve(e)},async request(e){if(r("permissions"))return await window.craft.permissions.request(e);return await wt(e)},async openSettings(e){if(r("permissions"))await window.craft.permissions.openSettings(e)}};async function ve(e){if(typeof navigator>"u"||!navigator.permissions?.query)return"not-supported";try{let t=await navigator.permissions.query({name:e});return ht(t.state)}catch{return"not-supported"}}async function wt(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 ve(e)}function ht(e){if(e==="granted")return"granted";if(e==="denied")return"denied";if(e==="prompt")return"undetermined";return"undetermined"}var ui={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 pi={async getDisplays(){if(r("screen"))return await window.craft.screen.getDisplays();return ye()},async getPrimary(){if(r("screen")){let e=await window.craft.screen.getPrimary();return e&&typeof e.width==="number"?e:null}return ye()[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 ye(){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 wi={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 vt=250,yt=60000,Z=2000,be={sharing:!1,signals:{systemScreenShare:!1,remoteSession:!1,conferenceSharing:!1,screenRecording:!1},sources:[]};function bt(){return{...be,signals:{...be.signals},sources:[]}}var Q={async getState(){if(!r("screenSharing"))return bt();return await window.craft.screenSharing.getState()},async watch(e=Z){let t=Number.isFinite(e)?Math.min(yt,Math.max(vt,Math.round(e))):Z;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 yi(e,t=Z){let n=Q.onChange(e);try{await Q.watch(t)}catch(o){throw n(),o}let i;return()=>{if(!i)n(),i=Q.stop();return i}}var Pi={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 Ii={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,xe=!1;function xt(){if(xe)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)}),xe=!0}var Pt=new Set(["javascript:","data:","file:","vbscript:"]),Ci={async openExternal(e){let t=e.trim().toLowerCase();for(let n of Pt)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(xt(),!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 ee(e){if(e===null||e===void 0||e===0)return"";return String(e)}function Pe(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:ee(n.badge)||void 0}))}))}function Se(e){return JSON.stringify(e.map((t)=>[t.id,t.header??"",t.items.map((n)=>[n.id,n.label,n.icon??""])]))}function Ae(e){return new Map(e.flatMap((t)=>t.items.map((n)=>[n.id,ee(n.badge)])))}var St={available(){return r("nativeUI")&&typeof window.craft?.nativeUI?._emitSidebarSelect==="function"},create(e){if(!St.available())return null;let t=window.craft?.nativeUI;if(!t)return null;let n=t.createSidebar({id:e.id,sections:Pe(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(Se(s)===Se(i)){let c=Ae(i);for(let[d,l]of Ae(s))if(c.get(d)!==l)n.updateItem(d,{badge:l})}else n.setSections(Pe(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:ee(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 Ri={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 _i={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 qi={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 Wi={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 ji={get(){if(r("theme"))try{return window.craft.theme.get()}catch{}return{appearance:At()}},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 At(){if(typeof window>"u"||!window.matchMedia)return"light";return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}class Ie{_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 ke{_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 Vi(e){return new Ie(e)}function Yi(e){return new ke(e)}function Gi(e){return new Promise((t)=>setTimeout(t,e))}function Xi(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 eo={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 no={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=Ee(e),o;try{o=await crypto.subtle.importKey("raw",q(n),{name:"Ed25519"},!1,["verify"])}catch{return!1}try{return await crypto.subtle.verify("Ed25519",o,q(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",q(n),{name:"Ed25519"},!1,["verify"])}catch{return{ok:!1,reason:"bad-key"}}let d=!1;try{d=await crypto.subtle.verify("Ed25519",c,q(t),Ee(s))}catch{d=!1}if(!d)return{ok:!1,reason:"bad-signature"};return{ok:!0,payload:s}}};function Ee(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 q(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 ao={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 uo={onFocus(e){if(r("window"))return a("craft:window:focus",()=>e());return te("focus",e)},onBlur(e){if(r("window"))return a("craft:window:blur",()=>e());return te("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 te("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 te(e,t){if(typeof window>"u")return()=>{};let n=()=>t();return window.addEventListener(e,n),()=>window.removeEventListener(e,n)}function It(e,t={}){if(!Number.isInteger(e)||e<0||e>86400000)return Promise.reject(RangeError("delayMs must be an integer between 0 and 86400000"));let{signal:n}=t,i=()=>new DOMException("Background delay aborted","AbortError");if(n?.aborted)return Promise.reject(i());if(r("timers"))return u("timers").sleep(e,t);if(typeof window<"u"&&window.craft)return Promise.reject(Error("Native background deadlines require a Craft runtime with timers.sleep support"));return new Promise((o,s)=>{let c=setTimeout(()=>{n?.removeEventListener("abort",d),o()},e);function d(){clearTimeout(c),n?.removeEventListener("abort",d),s(i())}n?.addEventListener("abort",d,{once:!0})})}export{Z as DEFAULT_WATCH_INTERVAL_MS,yt as MAX_WATCH_INTERVAL_MS,vt as MIN_WATCH_INTERVAL_MS,Hn as MODAL_STYLES,Ot as TOAST_STYLES,_n as alert,qt as app,Wt as appleScript,jt as audio,It as backgroundDelay,Yt as battery,Jt as biometric,er as bluetooth,nr as bonjour,ur as clipboard,qn as closeAllModals,On as confirm,pr as contextMenu,wr as continuityCamera,yr as coreml,R as crashReporter,Yi as createInterval,Vi as createTimer,Ar as deepLinks,Gi as delay,Dt as dismissAlertById,Rt as dismissAllAlerts,_r as dragOut,Hr as fileAssociations,me as focus,zr as focusShortcutsReady,Ji as formatCompact,en as formatShortcut,Xi as formatTime,Vr as fs,Lt as getActiveAlertCount,Nn as getActiveModalCount,ar as getCapabilities,Ne as getCapability,Rr as getDialogBridgeScript,nn as getRegisteredHotkeys,Xr as globalShortcuts,O as handoff,$r as hasFocusShortcuts,cn as iap,sr as isAvailable,Fr as isDragOutAvailable,ln as keychain,mn as liveActivities,hn as localServer,bn as location,Sn as log,En as menu,Bn as midi,$n as nativeAutoLaunch,Gn as nativeTray,Kn as nativeWindow,Qn as network,ti as notifications,Tt as notify,rt as parseShortcut,ii as pdf,si as permissions,ui as printing,Fn as prompt,ze as redactPII,tn as registerHotkey,kt as requestNotificationPermission,pi as screen,wi as screenCapture,Q as screenSharing,Pi as serial,Ii as serviceMenu,Ci as shell,oe as showAlert,Mr as showAlertDialog,Cr as showColorPicker,Br as showConfirmDialog,Tr as showErrorDialog,Rn as showErrorModal,Bt as showErrorToast,pt as showInfoModal,Et as showInfoToast,L as showMessageBox,k as showModal,kr as showOpenDialog,mt as showQuestionModal,Er as showSaveDialog,Ln as showSuccessModal,Ct as showSuccessToast,T as showToast,Dr as showWarningDialog,Dn as showWarningModal,Mt as showWarningToast,St as sidebar,je as signPayload,Ri as speech,_i as speechRecognition,qi as spotlight,kn as standardMenus,Wi as tags,ji as theme,eo as touchbar,rn as unregisterAllHotkeys,at as unregisterHotkey,no as updater,ao as vision,yi as watchScreenSharing,uo as windowEvents};