@gjsify/example-gtk-adwaita-storybook 0.58.0 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/gjs.js CHANGED
@@ -78,7 +78,7 @@ if(globalThis.__gjsifyBundleUrl??=import.meta.url,Symbol.dispose||(Symbol.dispos
78
78
  </method>${e.length>0?`\n${e.join(`
79
79
  `)}`:``}
80
80
  </interface>
81
- </node>`}function isWin32(){return e.DIR_SEPARATOR===92}function defaultListenAddress(){return isWin32()?`nonce-tcp:host=127.0.0.1`:`unix:tmpdir=${e.get_tmp_dir()}`}var DevtoolsPeerServerError=class extends Error{constructor(e,t,n,r){super(e),this.address=t,this.reason=n,this.name=`DevtoolsPeerServerError`,this.cause=r}};function isAddressInUse(t){return t instanceof e.Error&&t.matches(r.io_error_quark(),r.IOErrorEnum.ADDRESS_IN_USE)}function unixSocketPath(e){if(!e.startsWith(`unix:`))return null;for(let t of e.slice(5).split(`,`)){let e=t.indexOf(`=`);if(!(e<0||t.slice(0,e)!==`path`))try{return decodeURIComponent(t.slice(e+1))}catch{return null}}return null}function inspectExistingSocket(e){try{if((r.File.new_for_path(e).query_info(`unix::mode`,r.FileQueryInfoFlags.NONE,null).get_attribute_uint32(`unix::mode`)&61440)!=49152)return`not-a-socket`}catch{return`not-a-socket`}let t=new r.SocketClient;t.set_timeout(2);let n;try{n=t.connect(r.UnixSocketAddress.new(e),null)}catch{return`dead`}return n.close(null),`live`}function clearReclaimableSocket(t){let n=unixSocketPath(t);if(!n||!e.file_test(n,e.FileTest.EXISTS))return;let i=inspectExistingSocket(n);if(i===`live`)throw new DevtoolsPeerServerError(`cannot listen on ${t}: another process is already listening there. Stop it, or point ${q} (or options.address) at a different socket — GJSIFY_DEVTOOLS_INSTANCE=<label> lets two devtools-enabled apps run side by side.`,t,`address-in-use`);if(i===`not-a-socket`)throw new DevtoolsPeerServerError(`cannot listen on ${t}: ${n} already exists and is not a socket, so it will NOT be removed. Point ${q} (or options.address) at a free path.`,t,`occupied-by-other-file`);try{r.File.new_for_path(n).delete(null)}catch(e){throw new DevtoolsPeerServerError(`cannot listen on ${t}: ${n} is a socket nothing listens on, but removing it failed (${e}). Delete it by hand, or point ${q} at a free path.`,t,`address-in-use`,e)}v.log(`[gjsify-devtools] reclaimed the stale socket ${n}: nothing was listening on it (an abnormal exit — Ctrl-C, SIGKILL, a crash — leaves the inode behind).`)}function flagsForAddress(e){return e.startsWith(`tcp:`)||e.startsWith(`nonce-tcp:`)?r.DBusServerFlags.NONE:r.DBusServerFlags.AUTHENTICATION_REQUIRE_SAME_USER}function startDevtoolsPeerServer(e,t,n){let i=n&&n!==``?n:defaultListenAddress();clearReclaimableSocket(i);let o;try{o=r.DBusServer.new_sync(i,flagsForAddress(i),r.dbus_generate_guid(),null,null)}catch(e){let t=isAddressInUse(e);throw new DevtoolsPeerServerError(t?`cannot listen on ${i}: the address is already in use (${e}). Stop whatever holds it, or point ${q} (or options.address) at a different address.`:`cannot listen on ${i}: ${e}. Check the address form — \`unix:path=/tmp/app.sock\`, \`unix:tmpdir=/tmp\` or \`nonce-tcp:host=127.0.0.1\`.`,i,t?`address-in-use`:`listen-failed`,e)}let s=new Set;o.connect(`new-connection`,(n,r)=>(s.add(r),r.connect(`closed`,()=>{e.unexport(r),s.delete(r)}),e.export(r,t),!0)),o.start();let c=!1;return{address:o.get_client_address(),objectPath:t,get connectionCount(){return s.size},stop(){if(!c){c=!0,o.stop();for(let t of s)e.unexport(t),!t.is_closed()&&t.close(null,(e,t)=>{try{e.close_finish(t)}catch{}});s.clear()}}}}function writeDevtoolsAddressFile(t,n){try{if(e.mkdir_with_parents(e.path_get_dirname(t),448),!e.file_set_contents(t,`${n}\n`))return null}catch(e){return v.error(`[gjsify-devtools] could not publish the peer address to ${t}: ${e}`),null}try{r.File.new_for_path(t).set_attribute_uint32(`unix::mode`,384,r.FileQueryInfoFlags.NONE,null)}catch(e){v.error(`[gjsify-devtools] could not restrict ${t} to the current user: ${e}`)}return t}function removeDevtoolsAddressFile(e){try{r.File.new_for_path(e).delete(null)}catch{}}function captureWidget(e){let t=e.get_native()?.get_renderer();if(!t)return{png:null,blocker:`no-renderer`};let r=e.get_width(),o=e.get_height();if(r<=0||o<=0)return{png:null,blocker:`zero-size`};let s=n.WidgetPaintable.new(e),c=n.Snapshot.new();s.snapshot(c,r,o);let l=c.to_node();if(!l)return{png:null,blocker:`empty-snapshot`};let u=new i.Rect;u.init(0,0,r,o);let d=t.render_texture(l,u).save_to_png_bytes().get_data();return d?{png:new Uint8Array(d)}:{png:null,blocker:`empty-png`}}function captureWidgetPng(e){return captureWidget(e).png}function dumpGSettings(e){let t=r.SettingsSchemaSource.get_default()?.lookup(e,!0);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`GSettings schema '${e}' is not installed`));let n=new r.Settings({settings_schema:t}),i={};for(let e of t.list_keys())i[e]=n.get_value(e).recursiveUnpack();return i}function parseWidgetPath(e){let t=e.split(`/`).filter(e=>e.length>0);if(t.length===0)return null;let n=t[0].match(/^toplevel:(\d+)$/);if(!n)return null;let r=[];for(let e of t.slice(1)){let t=e.match(/^child:(\d+)$/);if(!t)return null;r.push(Number(t[1]))}return{toplevel:Number(n[1]),children:r}}function buildWidgetPath(e,t){return[`toplevel:${e}`,...t.map(e=>`child:${e}`)].join(`/`)}function widgetType(e){return gtypeName(e)??`GtkWidget`}function gtypeName(e){let t=e;return typeof t?.$typeName==`string`&&t.$typeName.length>0?t.$typeName:t?.constructor?.$gtype?.name??null}function widgetIsA(e,t){let n=gtypeName(e);if(n===null||!t)return!1;if(n===t)return!0;let r=o.type_from_name(n),i=o.type_from_name(t);return!r||!i?!1:o.type_is_a(r,i)}function activateWidget(e){let t=e,n=typeof t.get_parent==`function`?t.get_parent():null,r=!!n&&widgetIsA(n,`GtkListBox`);if(!(r&&widgetIsA(e,`GtkListBoxRow`))&&typeof t.activate==`function`&&t.activate()===!0)return!0;if(r){let t=n,r=!1;return typeof t.select_row==`function`&&(t.select_row(e),r=!0),typeof t.emit==`function`&&(t.emit(`row-activated`,e),r=!0),r}return!1}function sendKeyToWidget(e,t,n){let r=e.observe_controllers(),i=!1;for(let e=0;e<r.get_n_items();e++){let o=r.get_item(e);widgetIsA(o,`GtkEventControllerKey`)&&(o.emit(`key-pressed`,t,0,n),i=!0)}return i}function nthChild(e,t){let n=e.get_first_child(),r=0;for(;n&&r<t;)n=n.get_next_sibling(),r++;return r===t?n:null}function listToplevels(){let e=n.Window.get_toplevels(),t=e.get_n_items(),r=[];for(let n=0;n<t;n++){let t=e.get_item(n);t&&r.push({path:`toplevel:${n}`,type:widgetType(t),title:t.get_title?.()??null,mapped:t.get_mapped(),focused:t.is_active??!1})}return r}function resolveWidgetPath(e){let t=parseWidgetPath(e);if(!t)return null;let r=n.Window.get_toplevels().get_item(t.toplevel);if(!r)return null;for(let e of t.children)if(r=nthChild(r,e),!r)return null;return r}function parseWidgetSelector(e){let t=e.indexOf(`:`),n=(t<0?e:e.slice(0,t)).trim(),r=(t<0?``:e.slice(t+1)).trim();return!n&&!r?null:{type:n,cssClass:r}}function findWidgetPath(e,t,n){let r={path:null};return walkForSelector(e,t,n,r)??r.path}function walkForSelector(e,t,n,r){if(!e.get_visible()||!e.get_mapped())return null;if(!t.cssClass||e.get_css_classes().includes(t.cssClass)){if(!t.type||widgetType(e)===t.type)return n;r.path===null&&widgetIsA(e,t.type)&&(r.path=n)}let i=e.get_first_child(),o=0;for(;i;){let e=walkForSelector(i,t,`${n}/child:${o}`,r);if(e)return e;i=i.get_next_sibling(),o++}return null}function geometryOf(e){if(!e.get_mapped())return;let t=e.get_allocation(),r=t.width+e.get_margin_start()+e.get_margin_end(),i=t.height+e.get_margin_top()+e.get_margin_bottom(),[o,s]=e.measure(n.Orientation.HORIZONTAL,-1),c=r>0?Math.max(r,o):-1,[l,u]=e.measure(n.Orientation.VERTICAL,c),d={width:r,height:i,widthRequest:[o,s],heightRequest:[l,u]};return(r<o||i<l)&&(d.short=!0),d}function dumpTree(e,t,n){let r={path:n,type:widgetType(e),name:e.get_name()||null,cssClasses:e.get_css_classes(),mapped:e.get_mapped(),visible:e.get_visible(),children:[]},i=geometryOf(e);if(i!==void 0&&(r.geometry=i),t<=0)return e.get_first_child()&&(r.truncated=!0),r;let o=e.get_first_child(),s=0;for(;o;)r.children.push(dumpTree(o,t-1,`${n}/child:${s}`)),o=o.get_next_sibling(),s++;return r}function jsonSafe(e){let t=typeof e;return e==null||t===`string`||t===`number`||t===`boolean`?e??null:`[${t}]`}function getWidgetProperty(e,t){let n=e,r=t.replace(/-/g,`_`),i=t.replace(/[-_]([a-z])/g,(e,t)=>t.toUpperCase());for(let e of[t,r,i])if(e in n)return jsonSafe(n[e])}function childIndex(e,t){let n=e.get_first_child(),r=0;for(;n;){if(n===t)return r;n=n.get_next_sibling(),r++}return-1}function pathOfWidget(e){let t=[],r=e,i=r.get_parent();for(;i;){let e=childIndex(i,r);if(e<0)return null;t.unshift(e),r=i,i=r.get_parent()}let o=n.Window.get_toplevels(),s=o.get_n_items();for(let e=0;e<s;e++)if(o.get_item(e)===r)return buildWidgetPath(e,t);return null}function isActiveWindowScope(e){return!e||e===`window`||e===`active`}function frameDelay(t){return new Promise(n=>{e.timeout_add(e.PRIORITY_DEFAULT,t,()=>(n(),e.SOURCE_REMOVE))})}async function captureWidgetWhenRenderable(e,t=12,n=50){let r=null;for(let i=0;i<t;i++){let t=captureWidget(e);if(t.png)return{png:t.png,blocker:null};r=t.blocker,await frameDelay(n)}let i=captureWidget(e);return{png:i.png,blocker:i.png?null:i.blocker??r}}var DevtoolsService=class{constructor(e,t){this._app=e,this._options=t,this._exported=new Map,this._peer=null,this._addressFile=null,this._kinds=new Map,this._extensions=t.extend??[];for(let[e,t]of Object.entries(Et))this._kinds.set(e,t);for(let e of this._extensions){for(let[t,n]of Object.entries(e.methodKinds))this._kinds.set(t,n);for(let[t,n]of Object.entries(e.handlers)){let e=n;this[t]=(...n)=>(this._guard(t),e(...n))}}}export(e,t){if(this._exported.has(e))return;let n=buildDevtoolsIfaceXml(this._extensions.flatMap(e=>e.methodsXml??[])),i=r.DBusExportedObject.wrapJSObject(n,this);i.export(e,t),this._exported.set(e,i)}unexport(e){if(e){this._exported.get(e)?.unexport(),this._exported.delete(e);return}for(let e of this._exported.values())e.unexport();this._exported.clear(),this._peer?.stop(),this._peer=null,this._addressFile&&=(removeDevtoolsAddressFile(this._addressFile),null)}attachPeerServer(e,t){this._peer=e,this._addressFile=t??null}get peerAddress(){return this._peer?.address??null}get addressFile(){return this._addressFile}GetStatus(){let e=this._app.get_active_window(),t={appId:this._app.get_application_id()??`unknown`,instance:this._options.instance??`default`,activeWindow:e?{id:e.get_name()||`window`,title:e.get_title()??``,mapped:e.get_mapped()}:null,toplevelCount:n.Window.get_toplevels().get_n_items(),focusedWidget:null,paused:this._isPaused()};for(let e of this._extensions){let n=e.contributeStatus?.();n&&Object.assign(t,n)}return JSON.stringify(t)}async ScreenshotAsync(t,n){try{let r=typeof t?.[0]==`string`?t[0]:``,i=await this._captureScopePng(r);n.return_value(new e.Variant(`(ay)`,[i]))}catch(e){n.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e){let t=this._resolveRootWidget(e);if(!t){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let r=captureWidget(t.widget);if(r.png)return r.png;let i=t.widget.get_root();i instanceof n.Window&&i.present();let o=await captureWidgetWhenRenderable(t.widget);return o.png?o.png:(v.warn(`[devtools] Screenshot('${e}') has no image: ${o.blocker??`unknown`} after 12 tries. Empty bytes follow.`),new Uint8Array)}ListActions(){let e={app:describeActions(this._actionGroup(`app`)),win:describeActions(this._actionGroup(`win`))};return JSON.stringify(e)}ActivateAction(e,t,n){this._guard(`ActivateAction`);let r=this._scope(e);activateAction(this._requireGroup(r,t),t,this._parseValue(n))}ChangeActionState(e,t,n){this._guard(`ChangeActionState`);let r=this._scope(e);changeActionState(this._requireGroup(r,t),t,this._parseValue(n))}PresentWindow(){this._app.get_active_window()?.present()}ResizeWindow(e,t){this._guard(`ResizeWindow`);let n=this._app.get_active_window();if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no active window to resize`));let r=Math.max(1,Math.round(e)),i=Math.max(1,Math.round(t));return n.is_maximized()&&n.unmaximize(),n.is_fullscreen()&&n.unfullscreen(),n.set_default_size(r,i),[r,i]}ListToplevels(){return JSON.stringify(listToplevels())}DumpTree(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e||`active window`}'`));return JSON.stringify(dumpTree(n.widget,t>0?t:40,n.path))}GetProperty(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));let r=getWidgetProperty(n.widget,t);if(r===void 0)throw Error(formatDbusErrorMessage(`not-found`,`widget has no property '${t}'`));return JSON.stringify(r)}GetFocused(){let e=this._app.get_active_window(),t=e?e.get_focus():null;return JSON.stringify(t?{path:pathOfWidget(t),name:t.get_name()||null,type:widgetType(t)}:null)}ActivateWidget(e){this._guard(`ActivateWidget`);let t=this._resolveRootWidget(e);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));return activateWidget(t.widget)}FindWidget(e){let t=parseWidgetSelector(e);if(!t)throw Error(formatDbusErrorMessage(`invalid-params`,`empty selector '${e}'`));let n=this._resolveRootWidget(``);return n?findWidgetPath(n.widget,t,n.path)??``:``}SendKey(e,t){this._guard(`SendKey`);let[r,i,o]=n.accelerator_parse(e);if(!r)throw Error(formatDbusErrorMessage(`invalid-params`,`cannot parse accelerator '${e}'`));let s;if(s=t?this._resolveRootWidget(t)?.widget??null:this._app.get_active_window()?.get_focus()??null,!s)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${t||`focus`}'`));return sendKeyToWidget(s,i,o??0)}DumpGSettings(e){return JSON.stringify(dumpGSettings(e))}DumpCss(){return JSON.stringify(dumpCss())}SwapCss(e,t){return this._guard(`SwapCss`),swapCss(e,t)}_resolveRootWidget(e){if(isActiveWindowScope(e)){let e=this._app.get_active_window();return e?{widget:e,path:pathOfWidget(e)??`toplevel:0`}:null}let t=resolveWidgetPath(e);return t?{widget:t,path:e}:null}_isPaused(){return this._options.paused?.()??!1}_guard(e){let t=this._kinds.get(e);if(!t)throw Error(formatDbusErrorMessage(`internal`,`unclassified devtools method '${e}'`));if(t===`mutating`&&this._isPaused())throw Error(formatDbusErrorMessage(`paused`,`${e} rejected — external control is paused. Read-only methods keep working.`))}_scope(e){return e===`app`?`app`:`win`}_actionGroup(e){if(e===`app`)return this._app;if(this._options.winActionGroup)return this._options.winActionGroup;let t=this._app.get_active_window();return t instanceof n.ApplicationWindow?t:null}_requireGroup(e,t){let n=this._actionGroup(e);if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no '${e}' action group`));if(!n.has_action(t))throw Error(formatDbusErrorMessage(`not-found`,`unknown action ${e}.${t}`));return n}_parseValue(e){if(!e||e===`null`)return null;try{return JSON.parse(e)}catch{throw Error(formatDbusErrorMessage(`invalid-params`,`value_json is not valid JSON: ${e}`))}}};const Dt=`DBUS_SESSION_BUS_ADDRESS`,Ot=new Set;function envEnabled(){return isDevtoolsEnabledValue(e.getenv(`GJSIFY_DEVTOOLS`))}function envValue(t){let n=e.getenv(t);return n&&n!==``?n:null}function sessionBusUsable(){if(!envValue(Dt))return!1;try{return r.bus_get_sync(r.BusType.SESSION,null),!0}catch{return!1}}function chooseDevtoolsTransport(e){return e.requestedAddress?{kind:`peer`,address:e.requestedAddress,reason:`requested`}:e.hasAppConnection?{kind:`session-bus`}:e.sessionBusUsable?{kind:`unregistered`}:{kind:`peer`,address:null,reason:`no-session-bus`}}function describeMissingConnection(e,t){return e?t?`[gjsify-devtools] the session bus answers but this application is not registered on it yet — call installDevtools() from the GtkApplication "startup" handler (the bus connection and object path exist only after registration).`:`[gjsify-devtools] ${Dt} is set (${e}) but no bus answers there — using the bus-less peer transport instead. On macOS this is the usual state: Homebrew's dbus listens on launchd, so the advertised address only works while that socket is live.`:`[gjsify-devtools] this machine has no session bus (${Dt} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${q} on both the app and \`gjsify debug\` to pin it yourself.`}function installDevtools(e,t={}){if(!(t.enabled??envEnabled()))return null;let n=t.instance??envValue(`GJSIFY_DEVTOOLS_INSTANCE`)??void 0,r=new DevtoolsService(e,{...t,instance:n});try{return exportDevtools(e,r,t,n)}catch(e){return r.unexport(),v.error(`[gjsify-devtools] devtools stayed OFF, the app is unaffected — ${describeInstallFailure(e)}`),null}}function describeInstallFailure(e){return e instanceof DevtoolsPeerServerError||e instanceof Error?e.message:String(e)}function exportDevtools(t,n,r,i){let o=t.get_is_registered(),s=o?t.get_dbus_connection():null,c=o?t.get_dbus_object_path():null,l=envValue(Dt),u=!!(s&&c),d=u||sessionBusUsable(),f=chooseDevtoolsTransport({requestedAddress:r.address??envValue(q),hasAppConnection:u,sessionBusUsable:d}),p=t.get_application_id()??`unknown`,m=`${c??appIdToObjectPath(p)}/devtools`;if((f.kind===`unregistered`||f.kind===`peer`&&f.reason===`no-session-bus`)&&v.error(describeMissingConnection(l,d)),f.kind===`session-bus`&&s)n.export(s,m),v.log(`[gjsify-devtools] exported ${Tt} at ${m} (dest ${p})`);else if(f.kind===`peer`){let r=startDevtoolsPeerServer(n,m,f.address??void 0),o=writeDevtoolsAddressFile(devtoolsAddressFilePath(e.get_user_runtime_dir(),p,i),r.address);n.attachPeerServer(r,o),v.log(`[gjsify-devtools] exported ${Tt} at ${m} (peer address ${r.address}${o?`, published to ${o}`:``})`),o&&t.connect(`shutdown`,()=>removeDevtoolsAddressFile(o))}return Ot.add(n),n}const kt=`&(?![a-zA-Z][a-zA-Z0-9]*;|#\\d+;|#x[0-9a-fA-F]+;)|<(?![a-zA-Z/!?])`;RegExp(kt),RegExp(kt,`g`);const At=[`AdwNavigationSplitView`,`GtkListBox`,`AdwOverlaySplitView`];function probeEnabled(){let t=e.getenv(`GJSIFY_STORYBOOK_PROBE`);if(t==null)return!1;let n=t.toLowerCase();return n!==``&&n!==`0`&&n!==`false`}const jt=5e3;function exitIfNotDrained(){if(typeof process>`u`||typeof process.exit!=`function`)return;let e=setTimeout(()=>{v.error(`STORYBOOK PROBE: host still alive ${jt}ms after quit(), exiting`),process.exit(process.exitCode??0)},jt);typeof e==`object`&&typeof e.unref==`function`&&e.unref()}function collectTypes(e,t){t.add(e.type);for(let n of e.children)collectTypes(n,t)}function installStorybookProbe(t,n,r={}){let i=r.requireChrome??At,o=r.out??e.getenv(`GJSIFY_STORYBOOK_PROBE_OUT`)??void 0,s=r.timeoutMs??8e3,c=r.storyWidget??e.getenv(`GJSIFY_STORYBOOK_PROBE_STORY_WIDGET`)??void 0,l=n.controller.listStories(),u=[...new Set(l.map(e=>e.category))],d=r.story??e.getenv(`GJSIFY_STORYBOOK_PROBE_STORY`)??l[0]?.title,f=d?n.openStoryByTitle(d):!1,p=n.activeStory,m=new Set;collectTypes(dumpTree(n,60,`toplevel:0`),m);let h=i.filter(e=>!m.has(e)),g=new Set;p&&collectTypes(dumpTree(p,60,`story`),g);let _=g.size,y=c?g.has(c):null,finish=n=>{let r=JSON.stringify(n);if(n.ok)v.log(`STORYBOOK PROBE: PASS ${r}`);else{v.error(`STORYBOOK PROBE: FAIL ${r}`);try{typeof process<`u`&&(process.exitCode=1)}catch{}}if(o)try{e.file_set_contents(o,JSON.stringify(n,null,2))}catch{}t.quit(),exitIfNotDrained()},ee=0;e.timeout_add(e.PRIORITY_DEFAULT,100,()=>{ee+=100;let t=captureWidgetPng(n),r=n.get_width()>0&&n.get_height()>0;if(!t&&!(ee>=s))return e.SOURCE_CONTINUE;let o=p?captureWidgetPng(p):null,m=l.length>=1&&u.length>=1&&h.length===0&&f&&p!=null&&_>1,v;return l.length<1?v=`no stories registered`:u.length<1?v=`no categories`:h.length>0?v=`chrome missing: ${h.join(`, `)}`:!f||p==null?v=`could not open story: ${d??`(none)`}`:_<=1&&(v=`opened story rendered an empty subtree`),m&&c&&!g.has(c)&&(m=!1,v=`story widget ${c} not found in the opened story subtree`),m&&r&&(!t||t.length===0)&&(m=!1,v=`window realized (${n.get_width()}x${n.get_height()}) but the GSK capture was empty`),finish({ok:m,reason:v,stories:l.length,categories:u,opened:f,activeStory:p?p.meta.title:null,requiredChrome:i,missingChrome:h,storySubtreeWidgets:_,storyWidgetPresent:y,windowRealized:r,windowPngBytes:t?t.length:0,storyPngBytes:o?o.length:0}),e.SOURCE_REMOVE})}const Mt={UNKNOWN:0,CUSTOM:1,GPL_2_0:2,GPL_3_0:3,LGPL_2_1:4,LGPL_3_0:5,BSD:6,MIT_X11:7,ARTISTIC:8,GPL_2_0_ONLY:9,GPL_3_0_ONLY:10,LGPL_2_1_ONLY:11,LGPL_3_0_ONLY:12,AGPL_3_0:13,AGPL_3_0_ONLY:14,BSD_3:15,APACHE_2_0:16,MPL_2_0:17,"0BSD":18};Mt.GPL_2_0_ONLY,Mt.GPL_3_0_ONLY,Mt.UNKNOWN;const Nt=[`blue`,`teal`,`green`,`yellow`,`orange`,`red`,`pink`,`purple`,`slate`],Pt={blue:`#3584e4`,teal:`#2190a4`,green:`#3a944a`,yellow:`#c88800`,orange:`#ed5b00`,red:`#e62d42`,pink:`#d56199`,purple:`#9141ac`,slate:`#6f8396`};function parseHex(e){let t=/^#([0-9a-f]{6})$/i.exec(e.trim());if(!t)return null;let n=Number.parseInt(t[1],16);return[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255]}function toHex(e,t,n){let channel=e=>Math.round(Math.min(1,Math.max(0,e))*255).toString(16).padStart(2,`0`);return`#${channel(e)}${channel(t)}${channel(n)}`}const toLinear=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,fromLinear=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function linearToOklab(e,t,n){let r=Math.cbrt(.4122214708*e+.5363325363*t+.0514459929*n),i=Math.cbrt(.2119034982*e+.6806995451*t+.1073969566*n),o=Math.cbrt(.0883024619*e+.2817188376*t+.6299787005*n);return[.2104542553*r+.793617785*i-.0040720468*o,1.9779984951*r-2.428592205*i+.4505937099*o,.0259040371*r+.7827717662*i-.808675766*o]}function oklabToLinear(e,t,n){let r=(e+.3963377774*t+.2158037573*n)**3,i=(e-.1055613458*t-.0638541728*n)**3,o=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*i+.2309699292*o,-1.2684380046*r+2.6097574011*i-.3413193965*o,-.0041960863*r-.7034186147*i+1.707614701*o]}function adwaitaStandaloneColor(e,t){let n=parseHex(e);if(!n)return e;let[r,i,o]=linearToOklab(toLinear(n[0]),toLinear(n[1]),toLinear(n[2])),[s,c,l]=oklabToLinear(t?Math.max(r,.85):Math.min(r,.5),i,o);return toHex(fromLinear(s),fromLinear(c),fromLinear(l))}function adwaitaAccentBgColor(e){return Pt[e]}function adwaitaAccentColor(e,t){return adwaitaStandaloneColor(Pt[e],t)}var UnsupportedGObjectError=class extends Error{constructor(e,t){super(t),this.name=`UnsupportedGObjectError`,this.feature=e}};const Ft=new WeakSet;function makeType(e){let t=Object.freeze({name:e});return Ft.add(t),t}makeType(`gchararray`),makeType(`gboolean`),makeType(`gint`),makeType(`guint`),makeType(`gdouble`);const J={READABLE:1,WRITABLE:2,READWRITE:3,CONSTRUCT:4,CONSTRUCT_ONLY:8};var It=class ParamSpec{constructor(e,t,n,r,i,o,s,c){this.kind=e,this.name=t,this.nick=n,this.blurb=r,this.flags=i,this.defaultValue=o,this.minimum=s,this.maximum=c}static boolean(e,t,n,r,i){return new ParamSpec(`boolean`,e,t,n,r,i)}static string(e,t,n,r,i){return new ParamSpec(`string`,e,t,n,r,i)}static int(e,t,n,r,i,o,s){return new ParamSpec(`int`,e,t,n,r,s,i,o)}static uint(e,t,n,r,i,o,s){return new ParamSpec(`uint`,e,t,n,r,s,i,o)}static double(e,t,n,r,i,o,s){return new ParamSpec(`double`,e,t,n,r,s,i,o)}get_default_value(){return this.defaultValue}};const Y={GTypeName:Symbol(`GType name`),GTypeFlags:Symbol(`GType flags`),interfaces:Symbol(`GType interfaces`),properties:Symbol(`GObject properties`),signals:Symbol(`GObject signals`),requires:Symbol(`GObject interface requires`),template:Symbol(`GTK widget template`),cssName:Symbol(`GTK widget CSS name`),children:Symbol(`GTK widget template children`),internalChildren:Symbol(`GTK widget template internal children`)};Y.GTypeName,Y.template,Y.internalChildren,Y.properties,Y.signals,Y.cssName,Y.children,Y.interfaces,Y.requires,Y.GTypeFlags;const Lt=new WeakMap;function chainOf(e){let t=[];for(let n=e;typeof n==`function`;n=Object.getPrototypeOf(n)){let e=Lt.get(n);e&&t.push(e)}return t}function chainOfInstance(e){return chainOf(e.constructor)}function typeNameOf(e,t){return t[0]?.typeName??e.constructor.name}function aliasesOf(e){return[e,e.replace(/-/g,`_`),e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())]}function findProperty(e,t){for(let n of e)for(let e of n.properties)if(aliasesOf(e.name).includes(t))return e}function findSignal(e,t){for(let n of e)if(Object.prototype.hasOwnProperty.call(n.signals,t))return n.signals[t]}const Rt=new WeakMap;let zt=0;function stateOf$1(e){let t=Rt.get(e);return t||(t={values:new Map,handlers:new Map,connections:new Map,emissions:[]},Rt.set(e,t)),t}__name(stateOf$1,`stateOf`);function parseSignal(e){let t=e.indexOf(`::`);return t===-1?{name:e}:{name:e.slice(0,t),detail:e.slice(t+2)}}function addHandler(e,t,n){let r=stateOf$1(e),i=++zt,o=r.handlers.get(t)??[];return o.push({id:i,handler:n}),r.handlers.set(t,o),r.connections.set(i,()=>{o.splice(o.findIndex(e=>e.id===i),1)}),i}function runHandlers(e,t,n){let r=stateOf$1(e),i={key:t,stopped:!1};r.emissions.push(i);try{for(let{id:o,handler:s}of(r.handlers.get(t)??[]).slice()){if(i.stopped)break;r.connections.has(o)&&s(e,...n)}}finally{r.emissions.pop()}}function connectInstance(e,t,n){let r=chainOfInstance(e),i=typeNameOf(e,r),{name:o,detail:s}=parseSignal(t),foreign=()=>{let o=r[0]?.door;if(!o)throw Error(`No signal '${t}' on object '${i}'`);let s=++zt,c=o.listen(e,t,n);return stateOf$1(e).connections.set(s,c),s};if(o===`notify`){if(s===void 0)throw new UnsupportedGObjectError(`connect("notify")`,`connect('notify') without a property is outside the GObject subset; connect 'notify::<property>' on '${i}'.`);let t=findProperty(r,s);return t?addHandler(e,`notify::${t.name}`,n):foreign()}if(findSignal(r,o)){if(s!==void 0)throw Error(`Signal '${o}' on object '${i}' has no detail`);return addHandler(e,o,n)}return foreign()}function disconnectInstance(e,t){let n=stateOf$1(e),r=n.connections.get(t);if(!r)throw Error(`No handler with id ${t} is connected to ${String(e)}`);n.connections.delete(t),r()}function emitInstance(e,t,...n){let r=chainOfInstance(e),i=typeNameOf(e,r),o=findSignal(r,t);if(o){if(n.length!==o.length)throw Error(`Signal '${t}' on ${i} requires ${o.length} args got ${n.length}`);runHandlers(e,t,n);return}let s=r[0]?.door;if(!s)throw Error(`No signal '${t}' on object '${i}'`);s.dispatch(e,t,n)}function notifyInstance(e,t){let n=chainOfInstance(e),r=findProperty(n,t);if(r){runHandlers(e,`notify::${r.name}`,[r]);return}let i=n[0]?.door;if(!i)throw Error(`No property ${t} on ${typeNameOf(e,n)}`);i.dispatch(e,`notify::${t}`,[])}function generateAccessors(e,t){let{name:n,flags:r}=e,i=r&J.READABLE,o=r&J.WRITABLE,s=t??{configurable:!0,enumerable:!0};return i&&o?!s.get&&!s.set?(s.get=function(){let{values:t}=stateOf$1(this);return t.has(n)||t.set(n,e.get_default_value()),t.get(n)},s.set=function(e){let{values:t}=stateOf$1(this);e!==t.get(n)&&(t.set(n,e),this.notify(n))}):s.get?s.set||=function(){throw Error(`getter defined without setter for property ${n}`)}:s.get=function(){throw Error(`setter defined without getter for property ${n}`)}:i&&!s.get?s.get=function(){throw Error(`missing getter for read-only property ${n}`)}:o&&!s.set&&(s.set=function(){throw Error(`missing setter for write-only property ${n}`)}),s}function checkAccessors(e,t){let{name:n,flags:r}=t;if(r&J.CONSTRUCT_ONLY)return;let[,i,o]=aliasesOf(n),own=t=>Object.getOwnPropertyDescriptor(e,t),s=own(n),c=s,l=n.includes(`-`),u,d;l&&(u=own(i),d=own(o),s??=u,s??=d);let f=r&J.READABLE,p=r&J.WRITABLE;(!s||f&&!s.get||p&&!s.set)&&(s=generateAccessors(t,s)),c||Object.defineProperty(e,n,s),l&&(u||Object.defineProperty(e,i,s),d||Object.defineProperty(e,o,s))}function defineConstructOnly(e,t,n){let{values:r}=stateOf$1(e);r.set(t.name,n);for(let n of new Set(aliasesOf(t.name)))Object.defineProperty(e,n,{get:()=>r.get(t.name),enumerable:!0,configurable:!0})}function bindProperties(e,t,n,r,i=[]){let o=i.includes(`invert-boolean`),s=!1,transfer=(e,t,n,r)=>()=>{if(!s){s=!0;try{let i=e[t];n[r]=o?!i:i}finally{s=!1}}},c=transfer(e,t,n,r),l=[[e,e.connect(`notify::${t}`,c)]];if(i.includes(`bidirectional`)){let i=transfer(n,r,e,t);l.push([n,n.connect(`notify::${r}`,i)])}return i.includes(`sync-create`)&&c(),{unbind(){for(let[e,t]of l.splice(0))e.disconnect(t)}}}function createClosure(e,t,n,r){let i=r??e;if(n)throw new UnsupportedGObjectError(`swapped`,`Unsupported template signal flag "swapped"`);let o=e[t];if(o===void 0)throw Error(`A handler called ${t} was not defined on ${String(e)}`);return o.bind(i)}function scopeOf(e){return{instance:e,handler:(t,n)=>createClosure(e,t,n?.flags?.includes(`swapped`)??!1,n?.object),bind:bindProperties}}function constructRegistered(e,t={}){let n=chainOfInstance(e),r={},i=new Map;for(let[e,o]of Object.entries(t)){let t=findProperty(n,e);t?i.set(t,o):r[e]=o}let o=[];for(let t of[...n].reverse())t.template&&o.push([t,t.door.createFromTree(t.template,scopeOf(e),e)]);for(let t of n)for(let n of t.properties)n.flags&J.CONSTRUCT_ONLY&&defineConstructOnly(e,n,i.has(n)?i.get(n):n.get_default_value());for(let[t,n]of i)t.flags&J.CONSTRUCT_ONLY||(e[t.name]=n);for(let[t,n]of o){for(let r of t.internalChildren){let i=n.objects[r];if(i===void 0)throw Error(`Template of ${t.typeName} has no child object '${r}' for InternalChildren`);e[`_${r.replace(/-/g,`_`)}`]=i}t.door.attach(e,n)}return r}const Bt=Symbol(`GIR type`);function registerBaseClass(e,t,n,r=[]){let missing=e=>{throw Error(`No signal '${e}' on object '${t}'`)},i=makeType(t);Object.defineProperty(e,"$gtype",{get:()=>i,enumerable:!1,configurable:!1});for(let t of r)checkAccessors(e.prototype,t);Lt.set(e,{klass:e,typeName:t,gtype:i,properties:r,signals:n,internalChildren:[],door:{name:t,dispatch:(e,t)=>missing(t),listen:(e,t)=>missing(t),createFromTree:()=>missing(`template`),attach(){},register(){}}})}var GObjectObject=class{constructor(e){let t=constructRegistered(this,e),n=Object.keys(t)[0];if(n!==void 0)throw Error(`No property ${n} on ${typeNameOf(this,chainOfInstance(this))}`)}notify(e){notifyInstance(this,e)}connect(e,t){return connectInstance(this,e,t)}disconnect(e){disconnectInstance(this,e)}emit(e,...t){emitInstance(this,e,...t)}};function refuse$1(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}__name(refuse$1,`refuse`);var ActionRegistry=class{constructor(){this._actions=new Map}add(e){this._actions.set(e.name,e)}remove(e){this._actions.delete(e)}lookup_action(e){return this._actions.get(e)??null}has(e){return this._actions.has(e)}list(){return[...this._actions.keys()]}};const Vt=new WeakMap;function actionRegistryOf(e,t=!0){let n=Vt.get(e);return n===void 0&&t&&(n=new ActionRegistry,Vt.set(e,n)),n}function requireAction(e){let t=e;if(typeof t?.name!=`string`||typeof t.activate!=`function`)throw TypeError(`add_action: needs a Gio.Action (a Gio.SimpleAction)`);return t}const Ht={add_action(e){actionRegistryOf(this).add(requireAction(e))},lookup_action(e){return actionRegistryOf(this,!1)?.lookup_action(e)??null},remove_action(e){actionRegistryOf(this,!1)?.remove(e)}},Ut={has_action(e){return actionRegistryOf(this,!1)?.has(e)??!1},list_actions(){return actionRegistryOf(this,!1)?.list()??[]},activate_action(e,t=null){if(t!==null)throw refuse$1(`activate_action with a parameter`,`needs a GLib.Variant`);actionRegistryOf(this,!1)?.lookup_action(e)?.activate(null)},get_action_enabled(e){return actionRegistryOf(this,!1)?.lookup_action(e)?.enabled??!1}};function installActionMap(e,t=!1){let n=t?{...Ht,...Ut}:{...Ht};for(let[t,r]of Object.entries(n))Object.defineProperty(e,t,{value:r,writable:!0,configurable:!0,enumerable:!1})}const Wt=new WeakMap;function linkWindow(e,t){t===null?Wt.delete(e):Wt.set(e,t)}const Gt={NONE:0,FLAGS_NONE:0,DEFAULT_FLAGS:0,IS_SERVICE:1,IS_LAUNCHER:2,HANDLES_OPEN:4,HANDLES_COMMAND_LINE:8,SEND_ENVIRONMENT:16,NON_UNIQUE:32,CAN_OVERRIDE_APP_ID:64,ALLOW_REPLACEMENT:128,REPLACE:256};function isValidApplicationId(e){if(typeof e!=`string`||e.length>255||e===``)return!1;let t=e.split(`.`);return t.length>=2&&t.every(e=>/^[A-Za-z_-][A-Za-z0-9_-]*$/.test(e))}function refuse(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}const Kt=`register.hold.release.mark_busy.unmark_busy.open.set_inactivity_timeout.send_notification.withdraw_notification.register_session.set_option_context_parameter_string.set_option_context_summary.set_option_context_description.add_main_option.add_main_option_entries.add_option_group.set_resource_base_path.get_resource_base_path.set_flags.get_is_remote.get_is_registered.get_dbus_connection.get_dbus_object_path.bind_busy_property.add_action_entries.set_default`.split(`.`),qt=[`is_remote`,`is_registered`,`is_busy`,`resource_base_path`,`inactivity_timeout`,`action_group`],Jt=[`open`,`command-line`,`handle-local-options`,`shutdown`,`name-lost`],Yt=[`set_accels_for_action`,`get_accels_for_action`,`list_action_descriptions`,`get_actions_for_accel`,`set_menubar`,`get_menubar`,`get_menu_by_id`,`set_app_menu`,`get_app_menu`,`get_menu_by_id`,`inhibit`,`uninhibit`],Xt=new WeakMap;let Zt=null;function rememberDefault(e){Zt??=e}function stateOf(e){let t=Xt.get(e);return t===void 0&&(t={id:null,windows:[],running:!1,resolve:()=>{}},Xt.set(e,t)),t}function hostOf(e){let t=e.constructor.host;if(t===void 0)throw Error(`Gio.Application: this class has no ApplicationHost; use the Gtk.Application of a port.`);return t}var GioApplicationBase=class extends GObjectObject{static{this[Bt]=`Gio.Application`}static id_is_valid(e){return isValidApplicationId(e)}static get_default(){return Zt}constructor(e){super(e),rememberDefault(this)}get application_id(){return stateOf(this).id}set application_id(e){let t=e??null;if(t!==null&&!isValidApplicationId(t))throw Error(`Gio.Application: '${String(t)}' is not a valid application id (g_application_id_is_valid)`);let n=stateOf(this);if(n.running)throw Error(`Gio.Application: the application id cannot change while it runs`);n.id!==t&&(n.id=t,this.notify(`application-id`))}get flags(){return 0}set flags(e){if(e!==void 0&&e!==Gt.NONE)throw refuse(`Gio.ApplicationFlags value ${String(e)}`,`is a flag other than the default`)}get_application_id(){return this.application_id}set_application_id(e){this.application_id=e}get_flags(){return 0}vfunc_startup(){}vfunc_activate(){}run(){throw refuse(`Gio.Application.run()`,`blocks, and a page cannot; use runAsync()`)}connect(e,t){let n=e.split(`::`)[0]??e;if(Jt.includes(n))throw refuse(`the '${n}' signal`,`is not emitted`);return super.connect(e,t)}async runAsync(e=[]){let t=stateOf(this);if(t.running)throw Error(`Gio.Application.runAsync(): the application is already running`);let n=hostOf(this);t.running=!0;let r=new Promise(e=>{t.resolve=e}),i,o=!1,body=()=>{try{if(this.vfunc_startup(),this.emit(`startup`),this.emit(`activate`),this.vfunc_activate(),t.running&&t.windows.length===0&&n.requiresWindow)throw Error(`Gio.Application.runAsync(): activate added no window on ${n.name}; a window must be added synchronously by activate (ADR 0098 § 3).`)}catch(e){i=e,o=!0}return t.windows[0]??null};try{await n.start(body)}catch(e){i=e,o=!0}if(o)throw t.running=!1,n.exit(),i;return t.windows.length===0&&this._finish(0),r}quit(){let e=stateOf(this);if(e.running){for(let t of e.windows.splice(0))linkWindow(t,null),hostOf(this).detach(t);this._finish(0)}}_finish(e){let t=stateOf(this);t.running&&(t.running=!1,t.resolve(e),hostOf(this).exit())}};registerBaseClass(GioApplicationBase,`GApplication`,{startup:[],activate:[]},[It.string(`application-id`,``,``,J.READWRITE|J.CONSTRUCT,null),It.uint(`flags`,``,``,J.READWRITE|J.CONSTRUCT,0,4294967295,0)]),installActionMap(GioApplicationBase.prototype,!0);function refuseMembers(e,t,n){for(let n of t)Object.defineProperty(e,n,{value:()=>{throw refuse(`${n}()`,`is not implemented`)},writable:!0,configurable:!0,enumerable:!1});for(let t of n)Object.defineProperty(e,t,{get(){throw refuse(`the '${t}' property`,`is not implemented`)},configurable:!0,enumerable:!1})}refuseMembers(GioApplicationBase.prototype,Kt,qt);function withGtkApplication(e){class GtkApplication extends e{get active_window(){return stateOf(this).windows[0]??null}get_active_window(){return this.active_window}get_windows(){return[...stateOf(this).windows]}add_window(e){let t=stateOf(this);t.windows.includes(e)||(t.windows.unshift(e),linkWindow(e,this))}remove_window(e){let t=stateOf(this),n=t.windows.indexOf(e);n!==-1&&(t.windows.splice(n,1),linkWindow(e,null),t.windows.length===0&&this._finish(0))}}return refuseMembers(GtkApplication.prototype,Yt,[]),GtkApplication}withGtkApplication(GioApplicationBase),Math.PI*.35,Math.PI*.015,Math.PI*.9;const Qt=Math.PI*.9,$t=Math.PI*.7,en=Math.PI*1.1,tn=Math.PI*1.35,nn=Qt+en+tn-$t;53*Math.PI*2/nn,en-$t/2,new Set(`ADC.AND.ASL.BCC.BCS.BEQ.BIT.BMI.BNE.BPL.BRK.BVC.BVS.CLC.CLD.CLI.CLV.CMP.CPX.CPY.DEC.DEX.DEY.EOR.INC.INX.INY.JMP.JSR.LDA.LDX.LDY.LSR.NOP.ORA.PHA.PHP.PLA.PLP.ROL.ROR.RTI.RTS.SBC.SEC.SED.SEI.STA.STX.STY.TAX.TAY.TSX.TXA.TXS.TYA`.split(`.`));const rn=new WeakMap,an=new WeakMap;function sourceOf(e){let t=e.constructor.source;if(t===void 0)throw Error(`Adw.StyleManager: this class has no StyleSource; use the Adw.StyleManager of a port.`);return t}var StyleManagerBase=class extends GObjectObject{static{this[Bt]=`Adw.StyleManager`}static get_default(){let e=an.get(this);if(e===void 0){e=new this,an.set(this,e);let t=sourceOf(e);rn.set(e,t.dark()),t.subscribe(()=>{let n=t.dark();rn.get(e)!==n&&(rn.set(e,n),e.notify(`dark`))})}return e}get dark(){return sourceOf(this).dark()}get_dark(){return this.dark}};registerBaseClass(StyleManagerBase,`AdwStyleManager`,{},[It.boolean(`dark`,``,``,J.READABLE,!1)]);const on={system:`Follow system`,light:`Light`,dark:`Dark`},sn={blue:`Blue`,teal:`Teal`,green:`Green`,yellow:`Yellow`,orange:`Orange`,red:`Red`,pink:`Pink`,purple:`Purple`,slate:`Slate`};var StorybookAppearance=class{constructor(){this._provider=null,this._applying=!1,this._styleManager=s.StyleManager.get_default(),this.settings=new StorybookSettings(()=>this._styleManager.get_dark()),this.settings.subscribe(e=>this._apply(e)),this._styleManager.connect(`notify::dark`,()=>this.settings.systemChanged()),this._apply(this.settings.state)}_apply(e){if(!this._applying){this._applying=!0;try{this._styleManager.set_color_scheme(e.colorScheme===`light`?s.ColorScheme.FORCE_LIGHT:e.colorScheme===`dark`?s.ColorScheme.FORCE_DARK:s.ColorScheme.DEFAULT),this._applyAccent(this.settings.resolvedAccent)}finally{this._applying=!1}}}_applyAccent(e){let r=t.Display.get_default();if(!r)return;if(!this._provider){if(!e)return;this._provider=new n.CssProvider,n.StyleContext.add_provider_for_display(r,this._provider,n.STYLE_PROVIDER_PRIORITY_APPLICATION)}if(!e){this._provider.load_from_string(``);return}let i=adwaitaAccentBgColor(e),o=adwaitaAccentColor(e,this.settings.resolvedDark);this._provider.load_from_string(`:root { --accent-bg-color: ${i}; --accent-color: ${o}; }`)}};function buildSwatch(e,t,r){let i=new n.CheckButton({tooltip_text:t,halign:n.Align.CENTER,valign:n.Align.CENTER,focus_on_click:!1});for(let t of e)i.add_css_class(t);return i.update_property([n.AccessibleProperty.LABEL],[t]),r&&i.set_group(r),i}function buildSwatchCard(e=!1){let t=new s.WrapBox({align:.5,child_spacing:8,line_spacing:8,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),n=new s.Bin({child:t,hexpand:!0});return n.add_css_class(`card`),e&&n.add_css_class(`storybook-card-attached`),{card:n,row:t}}function buildAppearanceDialog(e){let t=e.settings,r=new s.PreferencesPage,i=new s.PreferencesGroup({title:`Style`}),{card:o,row:c}=buildSwatchCard(),l=null,u=new Map;for(let e of St){let n=buildSwatch([`storybook-swatch`,`storybook-scheme-swatch`,`storybook-scheme-${e}`],on[e],l);l??=n,n.set_active(t.colorScheme===e),n.connect(`toggled`,()=>{n.get_active()&&(t.colorScheme=e)}),u.set(e,n),c.append(n)}i.add(o),r.add(i);let d=new s.PreferencesGroup({title:`Accent colour`});d.add_css_class(`storybook-attached-group`);let f=new s.SwitchRow({title:`Use a custom accent colour`,subtitle:`Off follows the desktop, which owns the accent`,active:t.accentMode===`custom`});d.add(f);let{card:p,row:m}=buildSwatchCard(!0),h=null,g=new Map;for(let e of Nt){let r=buildSwatch([`storybook-swatch`],sn[e],h);h??=r,r.set_active(t.accent===e);let i=new n.CssProvider;i.load_from_string(`checkbutton { background-color: ${adwaitaAccentBgColor(e)}; }`),r.get_style_context().add_provider(i,n.STYLE_PROVIDER_PRIORITY_APPLICATION),r.connect(`toggled`,()=>{r.get_active()&&(t.accent=e)}),g.set(e,r),m.append(r)}m.set_sensitive(t.accentMode===`custom`),f.connect(`notify::active`,()=>{t.accentMode=f.get_active()?`custom`:`system`}),d.add(p),r.add(d),t.subscribe(e=>{let t=u.get(e.colorScheme);t&&!t.get_active()&&t.set_active(!0);let n=g.get(e.accent);n&&!n.get_active()&&n.set_active(!0);let r=e.accentMode===`custom`;f.get_active()!==r&&f.set_active(r),m.set_sensitive(r)});let _=new s.PreferencesDialog({title:`Appearance`});return _.add(r),_}function adwControlWidgetFactory(){return{text(e,t){let n=new s.EntryRow({title:e});t&&n.set_tooltip_text(t);let r=null;return n.connect(`changed`,()=>r?.(n.get_text())),{node:n,get:()=>n.get_text(),set:e=>n.set_text(e),onChange:e=>{r=e}}},boolean(e,t){let n=new s.SwitchRow({title:e,subtitle:t??``}),r=null;return n.connect(`notify::active`,()=>r?.(n.get_active())),{node:n,get:()=>n.get_active(),set:e=>n.set_active(e),onChange:e=>{r=e}}},number(e){let t=s.SpinRow.new_with_range(e.min??0,e.max??100,e.step??1);t.set_title(e.label||e.name),e.description&&t.set_subtitle(e.description);let n=null;return t.connect(`changed`,()=>n?.(t.get_value())),{node:t,get:()=>t.get_value(),set:e=>t.set_value(e),onChange:e=>{n=e}}},range(e){return buildRangeWidget(e)},select(e){return buildSelectWidget(e)},color(e,t){return buildColorWidget(e,t)}}}function buildRangeWidget(e){let t=e.min??0,r=e.max??100,i=e.step??1,o=typeof e.min==`number`?e.min:0,s=Number.isInteger(i)&&Number.isInteger(o),c=new n.Adjustment({lower:t,upper:r,step_increment:i,value:o});c.step_increment=i;let l=new n.ListBoxRow({selectable:!1,activatable:!1});l.add_css_class(`story-range-row`);let u=new n.Box({orientation:n.Orientation.VERTICAL,spacing:6,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),d=new n.Box({orientation:n.Orientation.HORIZONTAL,spacing:12}),f=new n.Label({label:e.label||e.name,halign:n.Align.START,hexpand:!0,ellipsize:3});f.add_css_class(`heading`);let formatValue=e=>s?String(Math.round(e)):e.toFixed(2),p=new n.Label({label:formatValue(o),halign:n.Align.END});if(p.add_css_class(`numeric`),p.add_css_class(`dim-label`),d.append(f),d.append(p),u.append(d),e.description){let t=new n.Label({label:e.description,halign:n.Align.START,xalign:0,wrap:!0,max_width_chars:32});t.add_css_class(`caption`),t.add_css_class(`dim-label`),u.append(t)}let m=new n.Scale({orientation:n.Orientation.HORIZONTAL,adjustment:c,draw_value:!1,hexpand:!0}),h=null,g=!1;return m.connect(`value-changed`,()=>{if(g)return;let e=m.get_value();if(s){let t=Math.round(e);if(t!==e){m.set_value(t);return}e=t}p.set_label(formatValue(e)),h?.(e)}),u.append(m),l.set_child(u),{node:l,get:()=>m.get_value(),set:e=>{g=!0,m.set_value(e),g=!1,p.set_label(formatValue(e))},onChange:e=>{h=e}}}function buildSelectWidget(e){let t=e.options??[],r=n.StringList.new(t.map(e=>e.label)),i=new s.ComboRow({title:e.label||e.name,subtitle:e.description??``,model:r}),o=null;return i.connect(`notify::selected`,()=>o?.(i.get_selected())),{node:i,get:()=>i.get_selected(),set:e=>i.set_selected(e),onChange:e=>{o=e}}}function buildColorWidget(e,r){let i=new s.ActionRow({title:e,subtitle:r??``}),o=new n.ColorDialogButton({dialog:new n.ColorDialog({title:e}),valign:n.Align.CENTER});i.add_suffix(o),i.set_activatable_widget(o);let channel=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,`0`),rgbaToHex=e=>`#${channel(e.red)}${channel(e.green)}${channel(e.blue)}`,c=null,l=!1;return o.connect(`notify::rgba`,()=>{l||c?.(rgbaToHex(o.get_rgba()))}),{node:i,get:()=>rgbaToHex(o.get_rgba()),set:e=>{let n=new t.RGBA;n.parse(e)&&(l=!0,o.set_rgba(n),l=!1)},onChange:e=>{c=e}}}var cn=class StorybookWindow extends s.ApplicationWindow{static{o.registerClass({GTypeName:`StorybookWindow`,Template:`<?xml version="1.0" encoding="UTF-8"?>
81
+ </node>`}function isWin32(){return e.DIR_SEPARATOR===92}function defaultListenAddress(){return isWin32()?`nonce-tcp:host=127.0.0.1`:`unix:tmpdir=${e.get_tmp_dir()}`}var DevtoolsPeerServerError=class extends Error{constructor(e,t,n,r){super(e),this.address=t,this.reason=n,this.name=`DevtoolsPeerServerError`,this.cause=r}};function isAddressInUse(t){return t instanceof e.Error&&t.matches(r.io_error_quark(),r.IOErrorEnum.ADDRESS_IN_USE)}function unixSocketPath(e){if(!e.startsWith(`unix:`))return null;for(let t of e.slice(5).split(`,`)){let e=t.indexOf(`=`);if(!(e<0||t.slice(0,e)!==`path`))try{return decodeURIComponent(t.slice(e+1))}catch{return null}}return null}function inspectExistingSocket(e){try{if((r.File.new_for_path(e).query_info(`unix::mode`,r.FileQueryInfoFlags.NONE,null).get_attribute_uint32(`unix::mode`)&61440)!=49152)return`not-a-socket`}catch{return`not-a-socket`}let t=new r.SocketClient;t.set_timeout(2);let n;try{n=t.connect(r.UnixSocketAddress.new(e),null)}catch{return`dead`}return n.close(null),`live`}function clearReclaimableSocket(t){let n=unixSocketPath(t);if(!n||!e.file_test(n,e.FileTest.EXISTS))return;let i=inspectExistingSocket(n);if(i===`live`)throw new DevtoolsPeerServerError(`cannot listen on ${t}: another process is already listening there. Stop it, or point ${q} (or options.address) at a different socket — GJSIFY_DEVTOOLS_INSTANCE=<label> lets two devtools-enabled apps run side by side.`,t,`address-in-use`);if(i===`not-a-socket`)throw new DevtoolsPeerServerError(`cannot listen on ${t}: ${n} already exists and is not a socket, so it will NOT be removed. Point ${q} (or options.address) at a free path.`,t,`occupied-by-other-file`);try{r.File.new_for_path(n).delete(null)}catch(e){throw new DevtoolsPeerServerError(`cannot listen on ${t}: ${n} is a socket nothing listens on, but removing it failed (${e}). Delete it by hand, or point ${q} at a free path.`,t,`address-in-use`,e)}v.log(`[gjsify-devtools] reclaimed the stale socket ${n}: nothing was listening on it (an abnormal exit — Ctrl-C, SIGKILL, a crash — leaves the inode behind).`)}function flagsForAddress(e){return e.startsWith(`tcp:`)||e.startsWith(`nonce-tcp:`)?r.DBusServerFlags.NONE:r.DBusServerFlags.AUTHENTICATION_REQUIRE_SAME_USER}function startDevtoolsPeerServer(e,t,n){let i=n&&n!==``?n:defaultListenAddress();clearReclaimableSocket(i);let o;try{o=r.DBusServer.new_sync(i,flagsForAddress(i),r.dbus_generate_guid(),null,null)}catch(e){let t=isAddressInUse(e);throw new DevtoolsPeerServerError(t?`cannot listen on ${i}: the address is already in use (${e}). Stop whatever holds it, or point ${q} (or options.address) at a different address.`:`cannot listen on ${i}: ${e}. Check the address form — \`unix:path=/tmp/app.sock\`, \`unix:tmpdir=/tmp\` or \`nonce-tcp:host=127.0.0.1\`.`,i,t?`address-in-use`:`listen-failed`,e)}let s=new Set;o.connect(`new-connection`,(n,r)=>(s.add(r),r.connect(`closed`,()=>{e.unexport(r),s.delete(r)}),e.export(r,t),!0)),o.start();let c=!1;return{address:o.get_client_address(),objectPath:t,get connectionCount(){return s.size},stop(){if(!c){c=!0,o.stop();for(let t of s)e.unexport(t),!t.is_closed()&&t.close(null,(e,t)=>{try{e.close_finish(t)}catch{}});s.clear()}}}}function writeDevtoolsAddressFile(t,n){try{if(e.mkdir_with_parents(e.path_get_dirname(t),448),!e.file_set_contents(t,`${n}\n`))return null}catch(e){return v.error(`[gjsify-devtools] could not publish the peer address to ${t}: ${e}`),null}try{r.File.new_for_path(t).set_attribute_uint32(`unix::mode`,384,r.FileQueryInfoFlags.NONE,null)}catch(e){v.error(`[gjsify-devtools] could not restrict ${t} to the current user: ${e}`)}return t}function removeDevtoolsAddressFile(e){try{r.File.new_for_path(e).delete(null)}catch{}}function captureWidget(e){let t=e.get_native()?.get_renderer();if(!t)return{png:null,blocker:`no-renderer`};let r=e.get_width(),o=e.get_height();if(r<=0||o<=0)return{png:null,blocker:`zero-size`};let s=n.WidgetPaintable.new(e),c=n.Snapshot.new();s.snapshot(c,r,o);let l=c.to_node();if(!l)return{png:null,blocker:`empty-snapshot`};let u=new i.Rect;u.init(0,0,r,o);let d=t.render_texture(l,u).save_to_png_bytes().get_data();return d?{png:new Uint8Array(d)}:{png:null,blocker:`empty-png`}}function captureWidgetPng(e){return captureWidget(e).png}function dumpGSettings(e){let t=r.SettingsSchemaSource.get_default()?.lookup(e,!0);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`GSettings schema '${e}' is not installed`));let n=new r.Settings({settings_schema:t}),i={};for(let e of t.list_keys())i[e]=n.get_value(e).recursiveUnpack();return i}function parseWidgetPath(e){let t=e.split(`/`).filter(e=>e.length>0);if(t.length===0)return null;let n=t[0].match(/^toplevel:(\d+)$/);if(!n)return null;let r=[];for(let e of t.slice(1)){let t=e.match(/^child:(\d+)$/);if(!t)return null;r.push(Number(t[1]))}return{toplevel:Number(n[1]),children:r}}function buildWidgetPath(e,t){return[`toplevel:${e}`,...t.map(e=>`child:${e}`)].join(`/`)}function widgetType(e){return gtypeName(e)??`GtkWidget`}function gtypeName(e){let t=e;return typeof t?.$typeName==`string`&&t.$typeName.length>0?t.$typeName:t?.constructor?.$gtype?.name??null}function widgetIsA(e,t){let n=gtypeName(e);if(n===null||!t)return!1;if(n===t)return!0;let r=o.type_from_name(n),i=o.type_from_name(t);return!r||!i?!1:o.type_is_a(r,i)}function activateWidget(e){let t=e,n=typeof t.get_parent==`function`?t.get_parent():null,r=!!n&&widgetIsA(n,`GtkListBox`);if(!(r&&widgetIsA(e,`GtkListBoxRow`))&&typeof t.activate==`function`&&t.activate()===!0)return!0;if(r){let t=n,r=!1;return typeof t.select_row==`function`&&(t.select_row(e),r=!0),typeof t.emit==`function`&&(t.emit(`row-activated`,e),r=!0),r}return!1}function sendKeyToWidget(e,t,n){let r=e.observe_controllers(),i=!1;for(let e=0;e<r.get_n_items();e++){let o=r.get_item(e);widgetIsA(o,`GtkEventControllerKey`)&&(o.emit(`key-pressed`,t,0,n),i=!0)}return i}function nthChild(e,t){let n=e.get_first_child(),r=0;for(;n&&r<t;)n=n.get_next_sibling(),r++;return r===t?n:null}function listToplevels(){let e=n.Window.get_toplevels(),t=e.get_n_items(),r=[];for(let n=0;n<t;n++){let t=e.get_item(n);t&&r.push({path:`toplevel:${n}`,type:widgetType(t),title:t.get_title?.()??null,mapped:t.get_mapped(),focused:t.is_active??!1})}return r}function resolveWidgetPath(e){let t=parseWidgetPath(e);if(!t)return null;let r=n.Window.get_toplevels().get_item(t.toplevel);if(!r)return null;for(let e of t.children)if(r=nthChild(r,e),!r)return null;return r}function parseWidgetSelector(e){let t=e.indexOf(`:`),n=(t<0?e:e.slice(0,t)).trim(),r=(t<0?``:e.slice(t+1)).trim();return!n&&!r?null:{type:n,cssClass:r}}function findWidgetPath(e,t,n){let r={path:null};return walkForSelector(e,t,n,r)??r.path}function walkForSelector(e,t,n,r){if(!e.get_visible()||!e.get_mapped())return null;if(!t.cssClass||e.get_css_classes().includes(t.cssClass)){if(!t.type||widgetType(e)===t.type)return n;r.path===null&&widgetIsA(e,t.type)&&(r.path=n)}let i=e.get_first_child(),o=0;for(;i;){let e=walkForSelector(i,t,`${n}/child:${o}`,r);if(e)return e;i=i.get_next_sibling(),o++}return null}function geometryOf(e){if(!e.get_mapped())return;let t=e.get_allocation(),r=t.width+e.get_margin_start()+e.get_margin_end(),i=t.height+e.get_margin_top()+e.get_margin_bottom(),[o,s]=e.measure(n.Orientation.HORIZONTAL,-1),c=r>0?Math.max(r,o):-1,[l,u]=e.measure(n.Orientation.VERTICAL,c),d={width:r,height:i,widthRequest:[o,s],heightRequest:[l,u]};return(r<o||i<l)&&(d.short=!0),d}function dumpTree(e,t,n){let r={path:n,type:widgetType(e),name:e.get_name()||null,cssClasses:e.get_css_classes(),mapped:e.get_mapped(),visible:e.get_visible(),children:[]},i=geometryOf(e);if(i!==void 0&&(r.geometry=i),t<=0)return e.get_first_child()&&(r.truncated=!0),r;let o=e.get_first_child(),s=0;for(;o;)r.children.push(dumpTree(o,t-1,`${n}/child:${s}`)),o=o.get_next_sibling(),s++;return r}function jsonSafe(e){let t=typeof e;return e==null||t===`string`||t===`number`||t===`boolean`?e??null:`[${t}]`}function getWidgetProperty(e,t){let n=e,r=t.replace(/-/g,`_`),i=t.replace(/[-_]([a-z])/g,(e,t)=>t.toUpperCase());for(let e of[t,r,i])if(e in n)return jsonSafe(n[e])}function childIndex(e,t){let n=e.get_first_child(),r=0;for(;n;){if(n===t)return r;n=n.get_next_sibling(),r++}return-1}function pathOfWidget(e){let t=[],r=e,i=r.get_parent();for(;i;){let e=childIndex(i,r);if(e<0)return null;t.unshift(e),r=i,i=r.get_parent()}let o=n.Window.get_toplevels(),s=o.get_n_items();for(let e=0;e<s;e++)if(o.get_item(e)===r)return buildWidgetPath(e,t);return null}function isActiveWindowScope(e){return!e||e===`window`||e===`active`}function frameDelay(t){return new Promise(n=>{e.timeout_add(e.PRIORITY_DEFAULT,t,()=>(n(),e.SOURCE_REMOVE))})}async function captureWidgetWhenRenderable(e,t=12,n=50){let r=null;for(let i=0;i<t;i++){let t=captureWidget(e);if(t.png)return{png:t.png,blocker:null};r=t.blocker,await frameDelay(n)}let i=captureWidget(e);return{png:i.png,blocker:i.png?null:i.blocker??r}}var DevtoolsService=class{constructor(e,t){this._app=e,this._options=t,this._exported=new Map,this._peer=null,this._addressFile=null,this._kinds=new Map,this._extensions=t.extend??[];for(let[e,t]of Object.entries(Et))this._kinds.set(e,t);for(let e of this._extensions){for(let[t,n]of Object.entries(e.methodKinds))this._kinds.set(t,n);for(let[t,n]of Object.entries(e.handlers)){let e=n;this[t]=(...n)=>(this._guard(t),e(...n))}}}export(e,t){if(this._exported.has(e))return;let n=buildDevtoolsIfaceXml(this._extensions.flatMap(e=>e.methodsXml??[])),i=r.DBusExportedObject.wrapJSObject(n,this);i.export(e,t),this._exported.set(e,i)}unexport(e){if(e){this._exported.get(e)?.unexport(),this._exported.delete(e);return}for(let e of this._exported.values())e.unexport();this._exported.clear(),this._peer?.stop(),this._peer=null,this._addressFile&&=(removeDevtoolsAddressFile(this._addressFile),null)}attachPeerServer(e,t){this._peer=e,this._addressFile=t??null}get peerAddress(){return this._peer?.address??null}get addressFile(){return this._addressFile}GetStatus(){let e=this._app.get_active_window(),t={appId:this._app.get_application_id()??`unknown`,instance:this._options.instance??`default`,activeWindow:e?{id:e.get_name()||`window`,title:e.get_title()??``,mapped:e.get_mapped()}:null,toplevelCount:n.Window.get_toplevels().get_n_items(),focusedWidget:null,paused:this._isPaused()};for(let e of this._extensions){let n=e.contributeStatus?.();n&&Object.assign(t,n)}return JSON.stringify(t)}async ScreenshotAsync(t,n){try{let r=typeof t?.[0]==`string`?t[0]:``,i=await this._captureScopePng(r);n.return_value(new e.Variant(`(ay)`,[i]))}catch(e){n.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e){let t=this._resolveRootWidget(e);if(!t){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let r=captureWidget(t.widget);if(r.png)return r.png;let i=t.widget.get_root();i instanceof n.Window&&i.present();let o=await captureWidgetWhenRenderable(t.widget);return o.png?o.png:(v.warn(`[devtools] Screenshot('${e}') has no image: ${o.blocker??`unknown`} after 12 tries. Empty bytes follow.`),new Uint8Array)}ListActions(){let e={app:describeActions(this._actionGroup(`app`)),win:describeActions(this._actionGroup(`win`))};return JSON.stringify(e)}ActivateAction(e,t,n){this._guard(`ActivateAction`);let r=this._scope(e);activateAction(this._requireGroup(r,t),t,this._parseValue(n))}ChangeActionState(e,t,n){this._guard(`ChangeActionState`);let r=this._scope(e);changeActionState(this._requireGroup(r,t),t,this._parseValue(n))}PresentWindow(){this._app.get_active_window()?.present()}ResizeWindow(e,t){this._guard(`ResizeWindow`);let n=this._app.get_active_window();if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no active window to resize`));let r=Math.max(1,Math.round(e)),i=Math.max(1,Math.round(t));return n.is_maximized()&&n.unmaximize(),n.is_fullscreen()&&n.unfullscreen(),n.set_default_size(r,i),[r,i]}ListToplevels(){return JSON.stringify(listToplevels())}DumpTree(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e||`active window`}'`));return JSON.stringify(dumpTree(n.widget,t>0?t:40,n.path))}GetProperty(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));let r=getWidgetProperty(n.widget,t);if(r===void 0)throw Error(formatDbusErrorMessage(`not-found`,`widget has no property '${t}'`));return JSON.stringify(r)}GetFocused(){let e=this._app.get_active_window(),t=e?e.get_focus():null;return JSON.stringify(t?{path:pathOfWidget(t),name:t.get_name()||null,type:widgetType(t)}:null)}ActivateWidget(e){this._guard(`ActivateWidget`);let t=this._resolveRootWidget(e);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));return activateWidget(t.widget)}FindWidget(e){let t=parseWidgetSelector(e);if(!t)throw Error(formatDbusErrorMessage(`invalid-params`,`empty selector '${e}'`));let n=this._resolveRootWidget(``);return n?findWidgetPath(n.widget,t,n.path)??``:``}SendKey(e,t){this._guard(`SendKey`);let[r,i,o]=n.accelerator_parse(e);if(!r)throw Error(formatDbusErrorMessage(`invalid-params`,`cannot parse accelerator '${e}'`));let s;if(s=t?this._resolveRootWidget(t)?.widget??null:this._app.get_active_window()?.get_focus()??null,!s)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${t||`focus`}'`));return sendKeyToWidget(s,i,o??0)}DumpGSettings(e){return JSON.stringify(dumpGSettings(e))}DumpCss(){return JSON.stringify(dumpCss())}SwapCss(e,t){return this._guard(`SwapCss`),swapCss(e,t)}_resolveRootWidget(e){if(isActiveWindowScope(e)){let e=this._app.get_active_window();return e?{widget:e,path:pathOfWidget(e)??`toplevel:0`}:null}let t=resolveWidgetPath(e);return t?{widget:t,path:e}:null}_isPaused(){return this._options.paused?.()??!1}_guard(e){let t=this._kinds.get(e);if(!t)throw Error(formatDbusErrorMessage(`internal`,`unclassified devtools method '${e}'`));if(t===`mutating`&&this._isPaused())throw Error(formatDbusErrorMessage(`paused`,`${e} rejected — external control is paused. Read-only methods keep working.`))}_scope(e){return e===`app`?`app`:`win`}_actionGroup(e){if(e===`app`)return this._app;if(this._options.winActionGroup)return this._options.winActionGroup;let t=this._app.get_active_window();return t instanceof n.ApplicationWindow?t:null}_requireGroup(e,t){let n=this._actionGroup(e);if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no '${e}' action group`));if(!n.has_action(t))throw Error(formatDbusErrorMessage(`not-found`,`unknown action ${e}.${t}`));return n}_parseValue(e){if(!e||e===`null`)return null;try{return JSON.parse(e)}catch{throw Error(formatDbusErrorMessage(`invalid-params`,`value_json is not valid JSON: ${e}`))}}};const Dt=`DBUS_SESSION_BUS_ADDRESS`,Ot=new Set;function envEnabled(){return isDevtoolsEnabledValue(e.getenv(`GJSIFY_DEVTOOLS`))}function envValue(t){let n=e.getenv(t);return n&&n!==``?n:null}function sessionBusUsable(){if(!envValue(Dt))return!1;try{return r.bus_get_sync(r.BusType.SESSION,null),!0}catch{return!1}}function chooseDevtoolsTransport(e){return e.requestedAddress?{kind:`peer`,address:e.requestedAddress,reason:`requested`}:e.hasAppConnection?{kind:`session-bus`}:e.sessionBusUsable?{kind:`unregistered`}:{kind:`peer`,address:null,reason:`no-session-bus`}}function describeMissingConnection(e,t){return e?t?`[gjsify-devtools] the session bus answers but this application is not registered on it yet — call installDevtools() from the GtkApplication "startup" handler (the bus connection and object path exist only after registration).`:`[gjsify-devtools] ${Dt} is set (${e}) but no bus answers there — using the bus-less peer transport instead. On macOS this is the usual state: Homebrew's dbus listens on launchd, so the advertised address only works while that socket is live.`:`[gjsify-devtools] this machine has no session bus (${Dt} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${q} on both the app and \`gjsify debug\` to pin it yourself.`}function installDevtools(e,t={}){if(!(t.enabled??envEnabled()))return null;let n=t.instance??envValue(`GJSIFY_DEVTOOLS_INSTANCE`)??void 0,r=new DevtoolsService(e,{...t,instance:n});try{return exportDevtools(e,r,t,n)}catch(e){return r.unexport(),v.error(`[gjsify-devtools] devtools stayed OFF, the app is unaffected — ${describeInstallFailure(e)}`),null}}function describeInstallFailure(e){return e instanceof DevtoolsPeerServerError||e instanceof Error?e.message:String(e)}function exportDevtools(t,n,r,i){let o=t.get_is_registered(),s=o?t.get_dbus_connection():null,c=o?t.get_dbus_object_path():null,l=envValue(Dt),u=!!(s&&c),d=u||sessionBusUsable(),f=chooseDevtoolsTransport({requestedAddress:r.address??envValue(q),hasAppConnection:u,sessionBusUsable:d}),p=t.get_application_id()??`unknown`,m=`${c??appIdToObjectPath(p)}/devtools`;if((f.kind===`unregistered`||f.kind===`peer`&&f.reason===`no-session-bus`)&&v.error(describeMissingConnection(l,d)),f.kind===`session-bus`&&s)n.export(s,m),v.log(`[gjsify-devtools] exported ${Tt} at ${m} (dest ${p})`);else if(f.kind===`peer`){let r=startDevtoolsPeerServer(n,m,f.address??void 0),o=writeDevtoolsAddressFile(devtoolsAddressFilePath(e.get_user_runtime_dir(),p,i),r.address);n.attachPeerServer(r,o),v.log(`[gjsify-devtools] exported ${Tt} at ${m} (peer address ${r.address}${o?`, published to ${o}`:``})`),o&&t.connect(`shutdown`,()=>removeDevtoolsAddressFile(o))}return Ot.add(n),n}const kt=`&(?![a-zA-Z][a-zA-Z0-9]*;|#\\d+;|#x[0-9a-fA-F]+;)|<(?![a-zA-Z/!?])`;RegExp(kt),RegExp(kt,`g`);const At=[`AdwNavigationSplitView`,`GtkListBox`,`AdwOverlaySplitView`];function probeEnabled(){let t=e.getenv(`GJSIFY_STORYBOOK_PROBE`);if(t==null)return!1;let n=t.toLowerCase();return n!==``&&n!==`0`&&n!==`false`}const jt=5e3;function exitIfNotDrained(){if(typeof process>`u`||typeof process.exit!=`function`)return;let e=setTimeout(()=>{v.error(`STORYBOOK PROBE: host still alive ${jt}ms after quit(), exiting`),process.exit(process.exitCode??0)},jt);typeof e==`object`&&typeof e.unref==`function`&&e.unref()}function collectTypes(e,t){t.add(e.type);for(let n of e.children)collectTypes(n,t)}function installStorybookProbe(t,n,r={}){let i=r.requireChrome??At,o=r.out??e.getenv(`GJSIFY_STORYBOOK_PROBE_OUT`)??void 0,s=r.timeoutMs??8e3,c=r.storyWidget??e.getenv(`GJSIFY_STORYBOOK_PROBE_STORY_WIDGET`)??void 0,l=n.controller.listStories(),u=[...new Set(l.map(e=>e.category))],d=r.story??e.getenv(`GJSIFY_STORYBOOK_PROBE_STORY`)??l[0]?.title,f=d?n.openStoryByTitle(d):!1,p=n.activeStory,m=new Set;collectTypes(dumpTree(n,60,`toplevel:0`),m);let h=i.filter(e=>!m.has(e)),g=new Set;p&&collectTypes(dumpTree(p,60,`story`),g);let _=g.size,y=c?g.has(c):null,finish=n=>{let r=JSON.stringify(n);if(n.ok)v.log(`STORYBOOK PROBE: PASS ${r}`);else{v.error(`STORYBOOK PROBE: FAIL ${r}`);try{typeof process<`u`&&(process.exitCode=1)}catch{}}if(o)try{e.file_set_contents(o,JSON.stringify(n,null,2))}catch{}t.quit(),exitIfNotDrained()},ee=0;e.timeout_add(e.PRIORITY_DEFAULT,100,()=>{ee+=100;let t=captureWidgetPng(n),r=n.get_width()>0&&n.get_height()>0;if(!t&&!(ee>=s))return e.SOURCE_CONTINUE;let o=p?captureWidgetPng(p):null,m=l.length>=1&&u.length>=1&&h.length===0&&f&&p!=null&&_>1,v;return l.length<1?v=`no stories registered`:u.length<1?v=`no categories`:h.length>0?v=`chrome missing: ${h.join(`, `)}`:!f||p==null?v=`could not open story: ${d??`(none)`}`:_<=1&&(v=`opened story rendered an empty subtree`),m&&c&&!g.has(c)&&(m=!1,v=`story widget ${c} not found in the opened story subtree`),m&&r&&(!t||t.length===0)&&(m=!1,v=`window realized (${n.get_width()}x${n.get_height()}) but the GSK capture was empty`),finish({ok:m,reason:v,stories:l.length,categories:u,opened:f,activeStory:p?p.meta.title:null,requiredChrome:i,missingChrome:h,storySubtreeWidgets:_,storyWidgetPresent:y,windowRealized:r,windowPngBytes:t?t.length:0,storyPngBytes:o?o.length:0}),e.SOURCE_REMOVE})}const Mt={UNKNOWN:0,CUSTOM:1,GPL_2_0:2,GPL_3_0:3,LGPL_2_1:4,LGPL_3_0:5,BSD:6,MIT_X11:7,ARTISTIC:8,GPL_2_0_ONLY:9,GPL_3_0_ONLY:10,LGPL_2_1_ONLY:11,LGPL_3_0_ONLY:12,AGPL_3_0:13,AGPL_3_0_ONLY:14,BSD_3:15,APACHE_2_0:16,MPL_2_0:17,"0BSD":18};Mt.GPL_2_0_ONLY,Mt.GPL_3_0_ONLY,Mt.UNKNOWN;const Nt=[`blue`,`teal`,`green`,`yellow`,`orange`,`red`,`pink`,`purple`,`slate`],Pt={blue:`#3584e4`,teal:`#2190a4`,green:`#3a944a`,yellow:`#c88800`,orange:`#ed5b00`,red:`#e62d42`,pink:`#d56199`,purple:`#9141ac`,slate:`#6f8396`};function parseHex(e){let t=/^#([0-9a-f]{6})$/i.exec(e.trim());if(!t)return null;let n=Number.parseInt(t[1],16);return[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255]}function toHex(e,t,n){let channel=e=>Math.round(Math.min(1,Math.max(0,e))*255).toString(16).padStart(2,`0`);return`#${channel(e)}${channel(t)}${channel(n)}`}const toLinear=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,fromLinear=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function linearToOklab(e,t,n){let r=Math.cbrt(.4122214708*e+.5363325363*t+.0514459929*n),i=Math.cbrt(.2119034982*e+.6806995451*t+.1073969566*n),o=Math.cbrt(.0883024619*e+.2817188376*t+.6299787005*n);return[.2104542553*r+.793617785*i-.0040720468*o,1.9779984951*r-2.428592205*i+.4505937099*o,.0259040371*r+.7827717662*i-.808675766*o]}function oklabToLinear(e,t,n){let r=(e+.3963377774*t+.2158037573*n)**3,i=(e-.1055613458*t-.0638541728*n)**3,o=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*i+.2309699292*o,-1.2684380046*r+2.6097574011*i-.3413193965*o,-.0041960863*r-.7034186147*i+1.707614701*o]}function adwaitaStandaloneColor(e,t){let n=parseHex(e);if(!n)return e;let[r,i,o]=linearToOklab(toLinear(n[0]),toLinear(n[1]),toLinear(n[2])),[s,c,l]=oklabToLinear(t?Math.max(r,.85):Math.min(r,.5),i,o);return toHex(fromLinear(s),fromLinear(c),fromLinear(l))}function adwaitaAccentBgColor(e){return Pt[e]}function adwaitaAccentColor(e,t){return adwaitaStandaloneColor(Pt[e],t)}var UnsupportedGObjectError=class extends Error{constructor(e,t){super(t),this.name=`UnsupportedGObjectError`,this.feature=e}};const Ft=new WeakSet;function makeType(e){let t=Object.freeze({name:e});return Ft.add(t),t}makeType(`gchararray`),makeType(`gboolean`),makeType(`gint`),makeType(`guint`),makeType(`gdouble`);const J={READABLE:1,WRITABLE:2,READWRITE:3,CONSTRUCT:4,CONSTRUCT_ONLY:8};var It=class ParamSpec{constructor(e,t,n,r,i,o,s,c){this.kind=e,this.name=t,this.nick=n,this.blurb=r,this.flags=i,this.defaultValue=o,this.minimum=s,this.maximum=c}static boolean(e,t,n,r,i){return new ParamSpec(`boolean`,e,t,n,r,i)}static string(e,t,n,r,i){return new ParamSpec(`string`,e,t,n,r,i)}static int(e,t,n,r,i,o,s){return new ParamSpec(`int`,e,t,n,r,s,i,o)}static uint(e,t,n,r,i,o,s){return new ParamSpec(`uint`,e,t,n,r,s,i,o)}static double(e,t,n,r,i,o,s){return new ParamSpec(`double`,e,t,n,r,s,i,o)}get_default_value(){return this.defaultValue}};const Y={GTypeName:Symbol(`GType name`),GTypeFlags:Symbol(`GType flags`),interfaces:Symbol(`GType interfaces`),properties:Symbol(`GObject properties`),signals:Symbol(`GObject signals`),requires:Symbol(`GObject interface requires`),template:Symbol(`GTK widget template`),cssName:Symbol(`GTK widget CSS name`),children:Symbol(`GTK widget template children`),internalChildren:Symbol(`GTK widget template internal children`)};Y.GTypeName,Y.template,Y.internalChildren,Y.properties,Y.signals,Y.cssName,Y.children,Y.interfaces,Y.requires,Y.GTypeFlags;const Lt=new WeakMap;function chainOf(e){let t=[];for(let n=e;typeof n==`function`;n=Object.getPrototypeOf(n)){let e=Lt.get(n);e&&t.push(e)}return t}function chainOfInstance(e){return chainOf(e.constructor)}function typeNameOf(e,t){return t[0]?.typeName??e.constructor.name}function aliasesOf(e){return[e,e.replace(/-/g,`_`),e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())]}function findProperty(e,t){for(let n of e)for(let e of n.properties)if(aliasesOf(e.name).includes(t))return e}function findSignal(e,t){for(let n of e)if(Object.prototype.hasOwnProperty.call(n.signals,t))return n.signals[t]}const Rt=new WeakMap;let zt=0;function stateOf$1(e){let t=Rt.get(e);return t||(t={values:new Map,handlers:new Map,connections:new Map,emissions:[]},Rt.set(e,t)),t}__name(stateOf$1,`stateOf`);function parseSignal(e){let t=e.indexOf(`::`);return t===-1?{name:e}:{name:e.slice(0,t),detail:e.slice(t+2)}}function addHandler(e,t,n){let r=stateOf$1(e),i=++zt,o=r.handlers.get(t)??[];return o.push({id:i,handler:n}),r.handlers.set(t,o),r.connections.set(i,()=>{o.splice(o.findIndex(e=>e.id===i),1)}),i}function runHandlers(e,t,n){let r=stateOf$1(e),i={key:t,stopped:!1};r.emissions.push(i);try{for(let{id:o,handler:s}of(r.handlers.get(t)??[]).slice()){if(i.stopped)break;r.connections.has(o)&&s(e,...n)}}finally{r.emissions.pop()}}function connectInstance(e,t,n){let r=chainOfInstance(e),i=typeNameOf(e,r),{name:o,detail:s}=parseSignal(t),foreign=()=>{let o=r[0]?.door;if(!o)throw Error(`No signal '${t}' on object '${i}'`);let s=++zt,c=o.listen(e,t,n);return stateOf$1(e).connections.set(s,c),s};if(o===`notify`){if(s===void 0)throw new UnsupportedGObjectError(`connect("notify")`,`connect('notify') without a property is outside the GObject subset; connect 'notify::<property>' on '${i}'.`);let t=findProperty(r,s);return t?addHandler(e,`notify::${t.name}`,n):foreign()}if(findSignal(r,o)){if(s!==void 0)throw Error(`Signal '${o}' on object '${i}' has no detail`);return addHandler(e,o,n)}return foreign()}function disconnectInstance(e,t){let n=stateOf$1(e),r=n.connections.get(t);if(!r)throw Error(`No handler with id ${t} is connected to ${String(e)}`);n.connections.delete(t),r()}function emitInstance(e,t,...n){let r=chainOfInstance(e),i=typeNameOf(e,r),o=findSignal(r,t);if(o){if(n.length!==o.length)throw Error(`Signal '${t}' on ${i} requires ${o.length} args got ${n.length}`);runHandlers(e,t,n);return}let s=r[0]?.door;if(!s)throw Error(`No signal '${t}' on object '${i}'`);s.dispatch(e,t,n)}function notifyInstance(e,t){let n=chainOfInstance(e),r=findProperty(n,t);if(r){runHandlers(e,`notify::${r.name}`,[r]);return}let i=n[0]?.door;if(!i)throw Error(`No property ${t} on ${typeNameOf(e,n)}`);i.dispatch(e,`notify::${t}`,[])}function generateAccessors(e,t){let{name:n,flags:r}=e,i=r&J.READABLE,o=r&J.WRITABLE,s=t??{configurable:!0,enumerable:!0};return i&&o?!s.get&&!s.set?(s.get=function(){let{values:t}=stateOf$1(this);return t.has(n)||t.set(n,e.get_default_value()),t.get(n)},s.set=function(e){let{values:t}=stateOf$1(this);e!==t.get(n)&&(t.set(n,e),this.notify(n))}):s.get?s.set||=function(){throw Error(`getter defined without setter for property ${n}`)}:s.get=function(){throw Error(`setter defined without getter for property ${n}`)}:i&&!s.get?s.get=function(){throw Error(`missing getter for read-only property ${n}`)}:o&&!s.set&&(s.set=function(){throw Error(`missing setter for write-only property ${n}`)}),s}function checkAccessors(e,t){let{name:n,flags:r}=t;if(r&J.CONSTRUCT_ONLY)return;let[,i,o]=aliasesOf(n),own=t=>Object.getOwnPropertyDescriptor(e,t),s=own(n),c=s,l=n.includes(`-`),u,d;l&&(u=own(i),d=own(o),s??=u,s??=d);let f=r&J.READABLE,p=r&J.WRITABLE;(!s||f&&!s.get||p&&!s.set)&&(s=generateAccessors(t,s)),c||Object.defineProperty(e,n,s),l&&(u||Object.defineProperty(e,i,s),d||Object.defineProperty(e,o,s))}function defineConstructOnly(e,t,n){let{values:r}=stateOf$1(e);r.set(t.name,n);for(let n of new Set(aliasesOf(t.name)))Object.defineProperty(e,n,{get:()=>r.get(t.name),enumerable:!0,configurable:!0})}function bindProperties(e,t,n,r,i=[]){let o=i.includes(`invert-boolean`),s=!1,transfer=(e,t,n,r)=>()=>{if(!s){s=!0;try{let i=e[t];n[r]=o?!i:i}finally{s=!1}}},c=transfer(e,t,n,r),l=[[e,e.connect(`notify::${t}`,c)]];if(i.includes(`bidirectional`)){let i=transfer(n,r,e,t);l.push([n,n.connect(`notify::${r}`,i)])}return i.includes(`sync-create`)&&c(),{unbind(){for(let[e,t]of l.splice(0))e.disconnect(t)}}}function createClosure(e,t,n,r){let i=r??e;if(n)throw new UnsupportedGObjectError(`swapped`,`Unsupported template signal flag "swapped"`);let o=e[t];if(o===void 0)throw Error(`A handler called ${t} was not defined on ${String(e)}`);return o.bind(i)}function scopeOf(e){return{instance:e,handler:(t,n)=>createClosure(e,t,n?.flags?.includes(`swapped`)??!1,n?.object),bind:bindProperties}}function constructRegistered(e,t={}){let n=chainOfInstance(e),r={},i=new Map;for(let[e,o]of Object.entries(t)){let t=findProperty(n,e);t?i.set(t,o):r[e]=o}let o=[];for(let t of[...n].reverse())t.template&&o.push([t,t.door.createFromTree(t.template,scopeOf(e),e)]);for(let t of n)for(let n of t.properties)n.flags&J.CONSTRUCT_ONLY&&defineConstructOnly(e,n,i.has(n)?i.get(n):n.get_default_value());for(let[t,n]of i)t.flags&J.CONSTRUCT_ONLY||(e[t.name]=n);for(let[t,n]of o){for(let r of t.internalChildren){let i=n.objects[r];if(i===void 0)throw Error(`Template of ${t.typeName} has no child object '${r}' for InternalChildren`);e[`_${r.replace(/-/g,`_`)}`]=i}t.door.attach(e,n)}return r}const Bt=Symbol(`GIR type`);function registerBaseClass(e,t,n,r=[]){let missing=e=>{throw Error(`No signal '${e}' on object '${t}'`)},i=makeType(t);Object.defineProperty(e,"$gtype",{get:()=>i,enumerable:!1,configurable:!1});for(let t of r)checkAccessors(e.prototype,t);Lt.set(e,{klass:e,typeName:t,gtype:i,properties:r,signals:n,internalChildren:[],door:{name:t,dispatch:(e,t)=>missing(t),listen:(e,t)=>missing(t),createFromTree:()=>missing(`template`),attach(){},register(){}}})}var GObjectObject=class{constructor(e){let t=constructRegistered(this,e),n=Object.keys(t)[0];if(n!==void 0)throw Error(`No property ${n} on ${typeNameOf(this,chainOfInstance(this))}`)}notify(e){notifyInstance(this,e)}connect(e,t){return connectInstance(this,e,t)}disconnect(e){disconnectInstance(this,e)}emit(e,...t){emitInstance(this,e,...t)}};function refuse$1(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}__name(refuse$1,`refuse`);var ActionRegistry=class{constructor(){this._actions=new Map}add(e){this._actions.set(e.name,e)}remove(e){this._actions.delete(e)}lookup_action(e){return this._actions.get(e)??null}has(e){return this._actions.has(e)}list(){return[...this._actions.keys()]}};const Vt=new WeakMap;function actionRegistryOf(e,t=!0){let n=Vt.get(e);return n===void 0&&t&&(n=new ActionRegistry,Vt.set(e,n)),n}function requireAction(e){let t=e;if(typeof t?.name!=`string`||typeof t.activate!=`function`)throw TypeError(`add_action: needs a Gio.Action (a Gio.SimpleAction)`);return t}const Ht={add_action(e){actionRegistryOf(this).add(requireAction(e))},lookup_action(e){return actionRegistryOf(this,!1)?.lookup_action(e)??null},remove_action(e){actionRegistryOf(this,!1)?.remove(e)}},Ut={has_action(e){return actionRegistryOf(this,!1)?.has(e)??!1},list_actions(){return actionRegistryOf(this,!1)?.list()??[]},activate_action(e,t=null){if(t!==null)throw refuse$1(`activate_action with a parameter`,`needs a GLib.Variant`);actionRegistryOf(this,!1)?.lookup_action(e)?.activate(null)},get_action_enabled(e){return actionRegistryOf(this,!1)?.lookup_action(e)?.enabled??!1}};function installActionMap(e,t=!1){let n=t?{...Ht,...Ut}:{...Ht};for(let[t,r]of Object.entries(n))Object.defineProperty(e,t,{value:r,writable:!0,configurable:!0,enumerable:!1})}const Wt=new WeakMap;function linkWindow(e,t){t===null?Wt.delete(e):Wt.set(e,t)}const Gt={NONE:0,FLAGS_NONE:0,DEFAULT_FLAGS:0,IS_SERVICE:1,IS_LAUNCHER:2,HANDLES_OPEN:4,HANDLES_COMMAND_LINE:8,SEND_ENVIRONMENT:16,NON_UNIQUE:32,CAN_OVERRIDE_APP_ID:64,ALLOW_REPLACEMENT:128,REPLACE:256};function isValidApplicationId(e){if(typeof e!=`string`||e.length>255||e===``)return!1;let t=e.split(`.`);return t.length>=2&&t.every(e=>/^[A-Za-z_-][A-Za-z0-9_-]*$/.test(e))}function refuse(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}const Kt=`register.hold.release.mark_busy.unmark_busy.open.set_inactivity_timeout.send_notification.withdraw_notification.register_session.set_option_context_parameter_string.set_option_context_summary.set_option_context_description.add_main_option.add_main_option_entries.add_option_group.set_resource_base_path.get_resource_base_path.set_flags.get_is_remote.get_is_registered.get_dbus_connection.get_dbus_object_path.bind_busy_property.add_action_entries.set_default`.split(`.`),qt=[`is_remote`,`is_registered`,`is_busy`,`resource_base_path`,`inactivity_timeout`,`action_group`],Jt=[`open`,`command-line`,`handle-local-options`,`shutdown`,`name-lost`],Yt=[`set_accels_for_action`,`get_accels_for_action`,`list_action_descriptions`,`get_actions_for_accel`,`set_menubar`,`get_menubar`,`get_menu_by_id`,`set_app_menu`,`get_app_menu`,`get_menu_by_id`,`inhibit`,`uninhibit`],Xt=new WeakMap;let Zt=null;function rememberDefault(e){Zt??=e}function stateOf(e){let t=Xt.get(e);return t===void 0&&(t={id:null,windows:[],running:!1,resolve:()=>{}},Xt.set(e,t)),t}function hostOf(e){let t=e.constructor.host;if(t===void 0)throw Error(`Gio.Application: this class has no ApplicationHost; use the Gtk.Application of a port.`);return t}var GioApplicationBase=class extends GObjectObject{static{this[Bt]=`Gio.Application`}static id_is_valid(e){return isValidApplicationId(e)}static get_default(){return Zt}constructor(e){super(e),rememberDefault(this)}get application_id(){return stateOf(this).id}set application_id(e){let t=e??null;if(t!==null&&!isValidApplicationId(t))throw Error(`Gio.Application: '${String(t)}' is not a valid application id (g_application_id_is_valid)`);let n=stateOf(this);if(n.running)throw Error(`Gio.Application: the application id cannot change while it runs`);n.id!==t&&(n.id=t,this.notify(`application-id`))}get flags(){return 0}set flags(e){if(e!==void 0&&e!==Gt.NONE)throw refuse(`Gio.ApplicationFlags value ${String(e)}`,`is a flag other than the default`)}get_application_id(){return this.application_id}set_application_id(e){this.application_id=e}get_flags(){return 0}vfunc_startup(){}vfunc_activate(){}run(){throw refuse(`Gio.Application.run()`,`blocks, and a page cannot; use runAsync()`)}connect(e,t){let n=e.split(`::`)[0]??e;if(Jt.includes(n))throw refuse(`the '${n}' signal`,`is not emitted`);return super.connect(e,t)}async runAsync(e=[]){let t=stateOf(this);if(t.running)throw Error(`Gio.Application.runAsync(): the application is already running`);let n=hostOf(this);t.running=!0;let r=new Promise(e=>{t.resolve=e}),i,o=!1,body=()=>{try{if(this.vfunc_startup(),this.emit(`startup`),this.emit(`activate`),this.vfunc_activate(),t.running&&t.windows.length===0&&n.requiresWindow)throw Error(`Gio.Application.runAsync(): activate added no window on ${n.name}; a window must be added synchronously by activate (ADR 0098 § 3).`)}catch(e){i=e,o=!0}return t.windows[0]??null};try{await n.start(body)}catch(e){i=e,o=!0}if(o)throw t.running=!1,n.exit(),i;return t.windows.length===0&&this._finish(0),r}quit(){let e=stateOf(this);if(e.running){for(let t of e.windows.splice(0))linkWindow(t,null),hostOf(this).detach(t);this._finish(0)}}_finish(e){let t=stateOf(this);t.running&&(t.running=!1,t.resolve(e),hostOf(this).exit())}};registerBaseClass(GioApplicationBase,`GApplication`,{startup:[],activate:[]},[It.string(`application-id`,``,``,J.READWRITE|J.CONSTRUCT,null),It.uint(`flags`,``,``,J.READWRITE|J.CONSTRUCT,0,4294967295,0)]),installActionMap(GioApplicationBase.prototype,!0);function refuseMembers(e,t,n){for(let n of t)Object.defineProperty(e,n,{value:()=>{throw refuse(`${n}()`,`is not implemented`)},writable:!0,configurable:!0,enumerable:!1});for(let t of n)Object.defineProperty(e,t,{get(){throw refuse(`the '${t}' property`,`is not implemented`)},configurable:!0,enumerable:!1})}refuseMembers(GioApplicationBase.prototype,Kt,qt);function withGtkApplication(e){class GtkApplication extends e{get active_window(){return stateOf(this).windows[0]??null}get_active_window(){return this.active_window}get_windows(){return[...stateOf(this).windows]}add_window(e){let t=stateOf(this);t.windows.includes(e)||(t.windows.unshift(e),linkWindow(e,this))}remove_window(e){let t=stateOf(this),n=t.windows.indexOf(e);n!==-1&&(t.windows.splice(n,1),linkWindow(e,null),t.windows.length===0&&this._finish(0))}}return refuseMembers(GtkApplication.prototype,Yt,[]),GtkApplication}withGtkApplication(GioApplicationBase);var ContentFormats=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}to_string(){return[...this.#e.map(e=>e.name),...this.#t].join(` `)}contain_gtype(e){return this.#e.includes(e)}contain_mime_type(e){return this.#t.includes(e)}};new ContentFormats([],[]),Math.PI*.35,Math.PI*.015,Math.PI*.9;const Qt=Math.PI*.9,$t=Math.PI*.7,en=Math.PI*1.1,tn=Math.PI*1.35,nn=Qt+en+tn-$t;53*Math.PI*2/nn,en-$t/2,new Set(`ADC.AND.ASL.BCC.BCS.BEQ.BIT.BMI.BNE.BPL.BRK.BVC.BVS.CLC.CLD.CLI.CLV.CMP.CPX.CPY.DEC.DEX.DEY.EOR.INC.INX.INY.JMP.JSR.LDA.LDX.LDY.LSR.NOP.ORA.PHA.PHP.PLA.PLP.ROL.ROR.RTI.RTS.SBC.SEC.SED.SEI.STA.STX.STY.TAX.TAY.TSX.TXA.TXS.TYA`.split(`.`));const rn=new WeakMap,an=new WeakMap;function sourceOf(e){let t=e.constructor.source;if(t===void 0)throw Error(`Adw.StyleManager: this class has no StyleSource; use the Adw.StyleManager of a port.`);return t}var StyleManagerBase=class extends GObjectObject{static{this[Bt]=`Adw.StyleManager`}static get_default(){let e=an.get(this);if(e===void 0){e=new this,an.set(this,e);let t=sourceOf(e);rn.set(e,t.dark()),t.subscribe(()=>{let n=t.dark();rn.get(e)!==n&&(rn.set(e,n),e.notify(`dark`))})}return e}get dark(){return sourceOf(this).dark()}get_dark(){return this.dark}};registerBaseClass(StyleManagerBase,`AdwStyleManager`,{},[It.boolean(`dark`,``,``,J.READABLE,!1)]);const on={system:`Follow system`,light:`Light`,dark:`Dark`},sn={blue:`Blue`,teal:`Teal`,green:`Green`,yellow:`Yellow`,orange:`Orange`,red:`Red`,pink:`Pink`,purple:`Purple`,slate:`Slate`};var StorybookAppearance=class{constructor(){this._provider=null,this._applying=!1,this._styleManager=s.StyleManager.get_default(),this.settings=new StorybookSettings(()=>this._styleManager.get_dark()),this.settings.subscribe(e=>this._apply(e)),this._styleManager.connect(`notify::dark`,()=>this.settings.systemChanged()),this._apply(this.settings.state)}_apply(e){if(!this._applying){this._applying=!0;try{this._styleManager.set_color_scheme(e.colorScheme===`light`?s.ColorScheme.FORCE_LIGHT:e.colorScheme===`dark`?s.ColorScheme.FORCE_DARK:s.ColorScheme.DEFAULT),this._applyAccent(this.settings.resolvedAccent)}finally{this._applying=!1}}}_applyAccent(e){let r=t.Display.get_default();if(!r)return;if(!this._provider){if(!e)return;this._provider=new n.CssProvider,n.StyleContext.add_provider_for_display(r,this._provider,n.STYLE_PROVIDER_PRIORITY_APPLICATION)}if(!e){this._provider.load_from_string(``);return}let i=adwaitaAccentBgColor(e),o=adwaitaAccentColor(e,this.settings.resolvedDark);this._provider.load_from_string(`:root { --accent-bg-color: ${i}; --accent-color: ${o}; }`)}};function buildSwatch(e,t,r){let i=new n.CheckButton({tooltip_text:t,halign:n.Align.CENTER,valign:n.Align.CENTER,focus_on_click:!1});for(let t of e)i.add_css_class(t);return i.update_property([n.AccessibleProperty.LABEL],[t]),r&&i.set_group(r),i}function buildSwatchCard(e=!1){let t=new s.WrapBox({align:.5,child_spacing:8,line_spacing:8,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),n=new s.Bin({child:t,hexpand:!0});return n.add_css_class(`card`),e&&n.add_css_class(`storybook-card-attached`),{card:n,row:t}}function buildAppearanceDialog(e){let t=e.settings,r=new s.PreferencesPage,i=new s.PreferencesGroup({title:`Style`}),{card:o,row:c}=buildSwatchCard(),l=null,u=new Map;for(let e of St){let n=buildSwatch([`storybook-swatch`,`storybook-scheme-swatch`,`storybook-scheme-${e}`],on[e],l);l??=n,n.set_active(t.colorScheme===e),n.connect(`toggled`,()=>{n.get_active()&&(t.colorScheme=e)}),u.set(e,n),c.append(n)}i.add(o),r.add(i);let d=new s.PreferencesGroup({title:`Accent colour`});d.add_css_class(`storybook-attached-group`);let f=new s.SwitchRow({title:`Use a custom accent colour`,subtitle:`Off follows the desktop, which owns the accent`,active:t.accentMode===`custom`});d.add(f);let{card:p,row:m}=buildSwatchCard(!0),h=null,g=new Map;for(let e of Nt){let r=buildSwatch([`storybook-swatch`],sn[e],h);h??=r,r.set_active(t.accent===e);let i=new n.CssProvider;i.load_from_string(`checkbutton { background-color: ${adwaitaAccentBgColor(e)}; }`),r.get_style_context().add_provider(i,n.STYLE_PROVIDER_PRIORITY_APPLICATION),r.connect(`toggled`,()=>{r.get_active()&&(t.accent=e)}),g.set(e,r),m.append(r)}m.set_sensitive(t.accentMode===`custom`),f.connect(`notify::active`,()=>{t.accentMode=f.get_active()?`custom`:`system`}),d.add(p),r.add(d),t.subscribe(e=>{let t=u.get(e.colorScheme);t&&!t.get_active()&&t.set_active(!0);let n=g.get(e.accent);n&&!n.get_active()&&n.set_active(!0);let r=e.accentMode===`custom`;f.get_active()!==r&&f.set_active(r),m.set_sensitive(r)});let _=new s.PreferencesDialog({title:`Appearance`});return _.add(r),_}function adwControlWidgetFactory(){return{text(e,t){let n=new s.EntryRow({title:e});t&&n.set_tooltip_text(t);let r=null;return n.connect(`changed`,()=>r?.(n.get_text())),{node:n,get:()=>n.get_text(),set:e=>n.set_text(e),onChange:e=>{r=e}}},boolean(e,t){let n=new s.SwitchRow({title:e,subtitle:t??``}),r=null;return n.connect(`notify::active`,()=>r?.(n.get_active())),{node:n,get:()=>n.get_active(),set:e=>n.set_active(e),onChange:e=>{r=e}}},number(e){let t=s.SpinRow.new_with_range(e.min??0,e.max??100,e.step??1);t.set_title(e.label||e.name),e.description&&t.set_subtitle(e.description);let n=null;return t.connect(`changed`,()=>n?.(t.get_value())),{node:t,get:()=>t.get_value(),set:e=>t.set_value(e),onChange:e=>{n=e}}},range(e){return buildRangeWidget(e)},select(e){return buildSelectWidget(e)},color(e,t){return buildColorWidget(e,t)}}}function buildRangeWidget(e){let t=e.min??0,r=e.max??100,i=e.step??1,o=typeof e.min==`number`?e.min:0,s=Number.isInteger(i)&&Number.isInteger(o),c=new n.Adjustment({lower:t,upper:r,step_increment:i,value:o});c.step_increment=i;let l=new n.ListBoxRow({selectable:!1,activatable:!1});l.add_css_class(`story-range-row`);let u=new n.Box({orientation:n.Orientation.VERTICAL,spacing:6,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),d=new n.Box({orientation:n.Orientation.HORIZONTAL,spacing:12}),f=new n.Label({label:e.label||e.name,halign:n.Align.START,hexpand:!0,ellipsize:3});f.add_css_class(`heading`);let formatValue=e=>s?String(Math.round(e)):e.toFixed(2),p=new n.Label({label:formatValue(o),halign:n.Align.END});if(p.add_css_class(`numeric`),p.add_css_class(`dim-label`),d.append(f),d.append(p),u.append(d),e.description){let t=new n.Label({label:e.description,halign:n.Align.START,xalign:0,wrap:!0,max_width_chars:32});t.add_css_class(`caption`),t.add_css_class(`dim-label`),u.append(t)}let m=new n.Scale({orientation:n.Orientation.HORIZONTAL,adjustment:c,draw_value:!1,hexpand:!0}),h=null,g=!1;return m.connect(`value-changed`,()=>{if(g)return;let e=m.get_value();if(s){let t=Math.round(e);if(t!==e){m.set_value(t);return}e=t}p.set_label(formatValue(e)),h?.(e)}),u.append(m),l.set_child(u),{node:l,get:()=>m.get_value(),set:e=>{g=!0,m.set_value(e),g=!1,p.set_label(formatValue(e))},onChange:e=>{h=e}}}function buildSelectWidget(e){let t=e.options??[],r=n.StringList.new(t.map(e=>e.label)),i=new s.ComboRow({title:e.label||e.name,subtitle:e.description??``,model:r}),o=null;return i.connect(`notify::selected`,()=>o?.(i.get_selected())),{node:i,get:()=>i.get_selected(),set:e=>i.set_selected(e),onChange:e=>{o=e}}}function buildColorWidget(e,r){let i=new s.ActionRow({title:e,subtitle:r??``}),o=new n.ColorDialogButton({dialog:new n.ColorDialog({title:e}),valign:n.Align.CENTER});i.add_suffix(o),i.set_activatable_widget(o);let channel=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,`0`),rgbaToHex=e=>`#${channel(e.red)}${channel(e.green)}${channel(e.blue)}`,c=null,l=!1;return o.connect(`notify::rgba`,()=>{l||c?.(rgbaToHex(o.get_rgba()))}),{node:i,get:()=>rgbaToHex(o.get_rgba()),set:e=>{let n=new t.RGBA;n.parse(e)&&(l=!0,o.set_rgba(n),l=!1)},onChange:e=>{c=e}}}var cn=class StorybookWindow extends s.ApplicationWindow{static{o.registerClass({GTypeName:`StorybookWindow`,Template:`<?xml version="1.0" encoding="UTF-8"?>
82
82
  <!--
83
83
  DO NOT EDIT!
84
84
  This file was @generated by blueprint-compiler. Instead, edit the
package/dist/gjs.node.mjs CHANGED
@@ -70,7 +70,7 @@ import{createRequire as e}from"node:module";import"@gjsify/node-gi/globals";impo
70
70
  </method>${e.length>0?`\n${e.join(`
71
71
  `)}`:``}
72
72
  </interface>
73
- </node>`}const ee=e(import.meta.url);let b;function load$4(){return b===void 0&&(b=ee(`@gjsify/node-gi/gi`).requireGi(`Gio`,`2.0`)),b}__name(load$4,`load`);var x=new Proxy(Object.create(null),{get(e,t){return load$4()[t]},has(e,t){return t in load$4()}});function isWin32(){return l.DIR_SEPARATOR===92}function defaultListenAddress(){return isWin32()?`nonce-tcp:host=127.0.0.1`:`unix:tmpdir=${l.get_tmp_dir()}`}var DevtoolsPeerServerError=class extends Error{constructor(e,t,n,r){super(e),this.address=t,this.reason=n,this.name=`DevtoolsPeerServerError`,this.cause=r}};function isAddressInUse(e){return e instanceof l.Error&&e.matches(x.io_error_quark(),x.IOErrorEnum.ADDRESS_IN_USE)}function unixSocketPath(e){if(!e.startsWith(`unix:`))return null;for(let t of e.slice(5).split(`,`)){let e=t.indexOf(`=`);if(!(e<0||t.slice(0,e)!==`path`))try{return decodeURIComponent(t.slice(e+1))}catch{return null}}return null}function inspectExistingSocket(e){try{if((x.File.new_for_path(e).query_info(`unix::mode`,x.FileQueryInfoFlags.NONE,null).get_attribute_uint32(`unix::mode`)&61440)!=49152)return`not-a-socket`}catch{return`not-a-socket`}let t=new x.SocketClient;t.set_timeout(2);let n;try{n=t.connect(x.UnixSocketAddress.new(e),null)}catch{return`dead`}return n.close(null),`live`}function clearReclaimableSocket(e){let t=unixSocketPath(e);if(!t||!l.file_test(t,l.FileTest.EXISTS))return;let n=inspectExistingSocket(t);if(n===`live`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: another process is already listening there. Stop it, or point ${y} (or options.address) at a different socket — GJSIFY_DEVTOOLS_INSTANCE=<label> lets two devtools-enabled apps run side by side.`,e,`address-in-use`);if(n===`not-a-socket`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} already exists and is not a socket, so it will NOT be removed. Point ${y} (or options.address) at a free path.`,e,`occupied-by-other-file`);try{x.File.new_for_path(t).delete(null)}catch(n){throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} is a socket nothing listens on, but removing it failed (${n}). Delete it by hand, or point ${y} at a free path.`,e,`address-in-use`,n)}console.log(`[gjsify-devtools] reclaimed the stale socket ${t}: nothing was listening on it (an abnormal exit — Ctrl-C, SIGKILL, a crash — leaves the inode behind).`)}function flagsForAddress(e){return e.startsWith(`tcp:`)||e.startsWith(`nonce-tcp:`)?x.DBusServerFlags.NONE:x.DBusServerFlags.AUTHENTICATION_REQUIRE_SAME_USER}function startDevtoolsPeerServer(e,t,n){let r=n&&n!==``?n:defaultListenAddress();clearReclaimableSocket(r);let i;try{i=x.DBusServer.new_sync(r,flagsForAddress(r),x.dbus_generate_guid(),null,null)}catch(e){let t=isAddressInUse(e);throw new DevtoolsPeerServerError(t?`cannot listen on ${r}: the address is already in use (${e}). Stop whatever holds it, or point ${y} (or options.address) at a different address.`:`cannot listen on ${r}: ${e}. Check the address form — \`unix:path=/tmp/app.sock\`, \`unix:tmpdir=/tmp\` or \`nonce-tcp:host=127.0.0.1\`.`,r,t?`address-in-use`:`listen-failed`,e)}let a=new Set;i.connect(`new-connection`,(n,r)=>(a.add(r),r.connect(`closed`,()=>{e.unexport(r),a.delete(r)}),e.export(r,t),!0)),i.start();let o=!1;return{address:i.get_client_address(),objectPath:t,get connectionCount(){return a.size},stop(){if(!o){o=!0,i.stop();for(let t of a)e.unexport(t),!t.is_closed()&&t.close(null,(e,t)=>{try{e.close_finish(t)}catch{}});a.clear()}}}}function writeDevtoolsAddressFile(e,t){try{if(l.mkdir_with_parents(l.path_get_dirname(e),448),!l.file_set_contents(e,`${t}\n`))return null}catch(t){return console.error(`[gjsify-devtools] could not publish the peer address to ${e}: ${t}`),null}try{x.File.new_for_path(e).set_attribute_uint32(`unix::mode`,384,x.FileQueryInfoFlags.NONE,null)}catch(t){console.error(`[gjsify-devtools] could not restrict ${e} to the current user: ${t}`)}return e}function removeDevtoolsAddressFile(e){try{x.File.new_for_path(e).delete(null)}catch{}}const te=e(import.meta.url);let ne;function load$3(){return ne===void 0&&(ne=te(`@gjsify/node-gi/gi`).requireGi(`Graphene`,`1.0`)),ne}__name(load$3,`load`);var re=new Proxy(Object.create(null),{get(e,t){return load$3()[t]},has(e,t){return t in load$3()}});function captureWidget(e){let t=e.get_native()?.get_renderer();if(!t)return{png:null,blocker:`no-renderer`};let n=e.get_width(),r=e.get_height();if(n<=0||r<=0)return{png:null,blocker:`zero-size`};let i=h.WidgetPaintable.new(e),a=h.Snapshot.new();i.snapshot(a,n,r);let o=a.to_node();if(!o)return{png:null,blocker:`empty-snapshot`};let s=new re.Rect;s.init(0,0,n,r);let c=t.render_texture(o,s).save_to_png_bytes().get_data();return c?{png:new Uint8Array(c)}:{png:null,blocker:`empty-png`}}function captureWidgetPng(e){return captureWidget(e).png}function dumpGSettings(e){let t=x.SettingsSchemaSource.get_default()?.lookup(e,!0);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`GSettings schema '${e}' is not installed`));let n=new x.Settings({settings_schema:t}),r={};for(let e of t.list_keys())r[e]=n.get_value(e).recursiveUnpack();return r}const ie=e(import.meta.url);let ae;function load$2(){return ae===void 0&&(ae=ie(`@gjsify/node-gi/gi`).requireGi(`GObject`,`2.0`)),ae}__name(load$2,`load`);var S=new Proxy(Object.create(null),{get(e,t){return load$2()[t]},has(e,t){return t in load$2()}});function parseWidgetPath(e){let t=e.split(`/`).filter(e=>e.length>0);if(t.length===0)return null;let n=t[0].match(/^toplevel:(\d+)$/);if(!n)return null;let r=[];for(let e of t.slice(1)){let t=e.match(/^child:(\d+)$/);if(!t)return null;r.push(Number(t[1]))}return{toplevel:Number(n[1]),children:r}}function buildWidgetPath(e,t){return[`toplevel:${e}`,...t.map(e=>`child:${e}`)].join(`/`)}function widgetType(e){return gtypeName(e)??`GtkWidget`}function gtypeName(e){let t=e;return typeof t?.$typeName==`string`&&t.$typeName.length>0?t.$typeName:t?.constructor?.$gtype?.name??null}function widgetIsA(e,t){let n=gtypeName(e);if(n===null||!t)return!1;if(n===t)return!0;let r=S.type_from_name(n),i=S.type_from_name(t);return!r||!i?!1:S.type_is_a(r,i)}function activateWidget(e){let t=e,n=typeof t.get_parent==`function`?t.get_parent():null,r=!!n&&widgetIsA(n,`GtkListBox`);if(!(r&&widgetIsA(e,`GtkListBoxRow`))&&typeof t.activate==`function`&&t.activate()===!0)return!0;if(r){let t=n,r=!1;return typeof t.select_row==`function`&&(t.select_row(e),r=!0),typeof t.emit==`function`&&(t.emit(`row-activated`,e),r=!0),r}return!1}function sendKeyToWidget(e,t,n){let r=e.observe_controllers(),i=!1;for(let e=0;e<r.get_n_items();e++){let a=r.get_item(e);widgetIsA(a,`GtkEventControllerKey`)&&(a.emit(`key-pressed`,t,0,n),i=!0)}return i}function nthChild(e,t){let n=e.get_first_child(),r=0;for(;n&&r<t;)n=n.get_next_sibling(),r++;return r===t?n:null}function listToplevels(){let e=h.Window.get_toplevels(),t=e.get_n_items(),n=[];for(let r=0;r<t;r++){let t=e.get_item(r);t&&n.push({path:`toplevel:${r}`,type:widgetType(t),title:t.get_title?.()??null,mapped:t.get_mapped(),focused:t.is_active??!1})}return n}function resolveWidgetPath(e){let t=parseWidgetPath(e);if(!t)return null;let n=h.Window.get_toplevels().get_item(t.toplevel);if(!n)return null;for(let e of t.children)if(n=nthChild(n,e),!n)return null;return n}function parseWidgetSelector(e){let t=e.indexOf(`:`),n=(t<0?e:e.slice(0,t)).trim(),r=(t<0?``:e.slice(t+1)).trim();return!n&&!r?null:{type:n,cssClass:r}}function findWidgetPath(e,t,n){let r={path:null};return walkForSelector(e,t,n,r)??r.path}function walkForSelector(e,t,n,r){if(!e.get_visible()||!e.get_mapped())return null;if(!t.cssClass||e.get_css_classes().includes(t.cssClass)){if(!t.type||widgetType(e)===t.type)return n;r.path===null&&widgetIsA(e,t.type)&&(r.path=n)}let i=e.get_first_child(),a=0;for(;i;){let e=walkForSelector(i,t,`${n}/child:${a}`,r);if(e)return e;i=i.get_next_sibling(),a++}return null}function geometryOf(e){if(!e.get_mapped())return;let t=e.get_allocation(),n=t.width+e.get_margin_start()+e.get_margin_end(),r=t.height+e.get_margin_top()+e.get_margin_bottom(),[i,a]=e.measure(h.Orientation.HORIZONTAL,-1),o=n>0?Math.max(n,i):-1,[s,c]=e.measure(h.Orientation.VERTICAL,o),l={width:n,height:r,widthRequest:[i,a],heightRequest:[s,c]};return(n<i||r<s)&&(l.short=!0),l}function dumpTree(e,t,n){let r={path:n,type:widgetType(e),name:e.get_name()||null,cssClasses:e.get_css_classes(),mapped:e.get_mapped(),visible:e.get_visible(),children:[]},i=geometryOf(e);if(i!==void 0&&(r.geometry=i),t<=0)return e.get_first_child()&&(r.truncated=!0),r;let a=e.get_first_child(),o=0;for(;a;)r.children.push(dumpTree(a,t-1,`${n}/child:${o}`)),a=a.get_next_sibling(),o++;return r}function jsonSafe(e){let t=typeof e;return e==null||t===`string`||t===`number`||t===`boolean`?e??null:`[${t}]`}function getWidgetProperty(e,t){let n=e,r=t.replace(/-/g,`_`),i=t.replace(/[-_]([a-z])/g,(e,t)=>t.toUpperCase());for(let e of[t,r,i])if(e in n)return jsonSafe(n[e])}function childIndex(e,t){let n=e.get_first_child(),r=0;for(;n;){if(n===t)return r;n=n.get_next_sibling(),r++}return-1}function pathOfWidget(e){let t=[],n=e,r=n.get_parent();for(;r;){let e=childIndex(r,n);if(e<0)return null;t.unshift(e),n=r,r=n.get_parent()}let i=h.Window.get_toplevels(),a=i.get_n_items();for(let e=0;e<a;e++)if(i.get_item(e)===n)return buildWidgetPath(e,t);return null}function isActiveWindowScope(e){return!e||e===`window`||e===`active`}function frameDelay(e){return new Promise(t=>{l.timeout_add(l.PRIORITY_DEFAULT,e,()=>(t(),l.SOURCE_REMOVE))})}async function captureWidgetWhenRenderable(e,t=12,n=50){let r=null;for(let i=0;i<t;i++){let t=captureWidget(e);if(t.png)return{png:t.png,blocker:null};r=t.blocker,await frameDelay(n)}let i=captureWidget(e);return{png:i.png,blocker:i.png?null:i.blocker??r}}var DevtoolsService=class{constructor(e,t){this._app=e,this._options=t,this._exported=new Map,this._peer=null,this._addressFile=null,this._kinds=new Map,this._extensions=t.extend??[];for(let[e,t]of Object.entries(v))this._kinds.set(e,t);for(let e of this._extensions){for(let[t,n]of Object.entries(e.methodKinds))this._kinds.set(t,n);for(let[t,n]of Object.entries(e.handlers)){let e=n;this[t]=(...n)=>(this._guard(t),e(...n))}}}export(e,t){if(this._exported.has(e))return;let n=buildDevtoolsIfaceXml(this._extensions.flatMap(e=>e.methodsXml??[])),r=x.DBusExportedObject.wrapJSObject(n,this);r.export(e,t),this._exported.set(e,r)}unexport(e){if(e){this._exported.get(e)?.unexport(),this._exported.delete(e);return}for(let e of this._exported.values())e.unexport();this._exported.clear(),this._peer?.stop(),this._peer=null,this._addressFile&&=(removeDevtoolsAddressFile(this._addressFile),null)}attachPeerServer(e,t){this._peer=e,this._addressFile=t??null}get peerAddress(){return this._peer?.address??null}get addressFile(){return this._addressFile}GetStatus(){let e=this._app.get_active_window(),t={appId:this._app.get_application_id()??`unknown`,instance:this._options.instance??`default`,activeWindow:e?{id:e.get_name()||`window`,title:e.get_title()??``,mapped:e.get_mapped()}:null,toplevelCount:h.Window.get_toplevels().get_n_items(),focusedWidget:null,paused:this._isPaused()};for(let e of this._extensions){let n=e.contributeStatus?.();n&&Object.assign(t,n)}return JSON.stringify(t)}async ScreenshotAsync(e,t){try{let n=typeof e?.[0]==`string`?e[0]:``,r=await this._captureScopePng(n);t.return_value(new l.Variant(`(ay)`,[r]))}catch(e){t.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e){let t=this._resolveRootWidget(e);if(!t){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let n=captureWidget(t.widget);if(n.png)return n.png;let r=t.widget.get_root();r instanceof h.Window&&r.present();let i=await captureWidgetWhenRenderable(t.widget);return i.png?i.png:(console.warn(`[devtools] Screenshot('${e}') has no image: ${i.blocker??`unknown`} after 12 tries. Empty bytes follow.`),new Uint8Array)}ListActions(){let e={app:describeActions(this._actionGroup(`app`)),win:describeActions(this._actionGroup(`win`))};return JSON.stringify(e)}ActivateAction(e,t,n){this._guard(`ActivateAction`);let r=this._scope(e);activateAction(this._requireGroup(r,t),t,this._parseValue(n))}ChangeActionState(e,t,n){this._guard(`ChangeActionState`);let r=this._scope(e);changeActionState(this._requireGroup(r,t),t,this._parseValue(n))}PresentWindow(){this._app.get_active_window()?.present()}ResizeWindow(e,t){this._guard(`ResizeWindow`);let n=this._app.get_active_window();if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no active window to resize`));let r=Math.max(1,Math.round(e)),i=Math.max(1,Math.round(t));return n.is_maximized()&&n.unmaximize(),n.is_fullscreen()&&n.unfullscreen(),n.set_default_size(r,i),[r,i]}ListToplevels(){return JSON.stringify(listToplevels())}DumpTree(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e||`active window`}'`));return JSON.stringify(dumpTree(n.widget,t>0?t:40,n.path))}GetProperty(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));let r=getWidgetProperty(n.widget,t);if(r===void 0)throw Error(formatDbusErrorMessage(`not-found`,`widget has no property '${t}'`));return JSON.stringify(r)}GetFocused(){let e=this._app.get_active_window(),t=e?e.get_focus():null;return JSON.stringify(t?{path:pathOfWidget(t),name:t.get_name()||null,type:widgetType(t)}:null)}ActivateWidget(e){this._guard(`ActivateWidget`);let t=this._resolveRootWidget(e);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));return activateWidget(t.widget)}FindWidget(e){let t=parseWidgetSelector(e);if(!t)throw Error(formatDbusErrorMessage(`invalid-params`,`empty selector '${e}'`));let n=this._resolveRootWidget(``);return n?findWidgetPath(n.widget,t,n.path)??``:``}SendKey(e,t){this._guard(`SendKey`);let[n,r,i]=h.accelerator_parse(e);if(!n)throw Error(formatDbusErrorMessage(`invalid-params`,`cannot parse accelerator '${e}'`));let a;if(a=t?this._resolveRootWidget(t)?.widget??null:this._app.get_active_window()?.get_focus()??null,!a)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${t||`focus`}'`));return sendKeyToWidget(a,r,i??0)}DumpGSettings(e){return JSON.stringify(dumpGSettings(e))}DumpCss(){return JSON.stringify(dumpCss())}SwapCss(e,t){return this._guard(`SwapCss`),swapCss(e,t)}_resolveRootWidget(e){if(isActiveWindowScope(e)){let e=this._app.get_active_window();return e?{widget:e,path:pathOfWidget(e)??`toplevel:0`}:null}let t=resolveWidgetPath(e);return t?{widget:t,path:e}:null}_isPaused(){return this._options.paused?.()??!1}_guard(e){let t=this._kinds.get(e);if(!t)throw Error(formatDbusErrorMessage(`internal`,`unclassified devtools method '${e}'`));if(t===`mutating`&&this._isPaused())throw Error(formatDbusErrorMessage(`paused`,`${e} rejected — external control is paused. Read-only methods keep working.`))}_scope(e){return e===`app`?`app`:`win`}_actionGroup(e){if(e===`app`)return this._app;if(this._options.winActionGroup)return this._options.winActionGroup;let t=this._app.get_active_window();return t instanceof h.ApplicationWindow?t:null}_requireGroup(e,t){let n=this._actionGroup(e);if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no '${e}' action group`));if(!n.has_action(t))throw Error(formatDbusErrorMessage(`not-found`,`unknown action ${e}.${t}`));return n}_parseValue(e){if(!e||e===`null`)return null;try{return JSON.parse(e)}catch{throw Error(formatDbusErrorMessage(`invalid-params`,`value_json is not valid JSON: ${e}`))}}};const C=`DBUS_SESSION_BUS_ADDRESS`,oe=new Set;function envEnabled(){return isDevtoolsEnabledValue(l.getenv(`GJSIFY_DEVTOOLS`))}function envValue(e){let t=l.getenv(e);return t&&t!==``?t:null}function sessionBusUsable(){if(!envValue(C))return!1;try{return x.bus_get_sync(x.BusType.SESSION,null),!0}catch{return!1}}function chooseDevtoolsTransport(e){return e.requestedAddress?{kind:`peer`,address:e.requestedAddress,reason:`requested`}:e.hasAppConnection?{kind:`session-bus`}:e.sessionBusUsable?{kind:`unregistered`}:{kind:`peer`,address:null,reason:`no-session-bus`}}function describeMissingConnection(e,t){return e?t?`[gjsify-devtools] the session bus answers but this application is not registered on it yet — call installDevtools() from the GtkApplication "startup" handler (the bus connection and object path exist only after registration).`:`[gjsify-devtools] ${C} is set (${e}) but no bus answers there — using the bus-less peer transport instead. On macOS this is the usual state: Homebrew's dbus listens on launchd, so the advertised address only works while that socket is live.`:`[gjsify-devtools] this machine has no session bus (${C} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${y} on both the app and \`gjsify debug\` to pin it yourself.`}function installDevtools(e,t={}){if(!(t.enabled??envEnabled()))return null;let n=t.instance??envValue(`GJSIFY_DEVTOOLS_INSTANCE`)??void 0,r=new DevtoolsService(e,{...t,instance:n});try{return exportDevtools(e,r,t,n)}catch(e){return r.unexport(),console.error(`[gjsify-devtools] devtools stayed OFF, the app is unaffected — ${describeInstallFailure(e)}`),null}}function describeInstallFailure(e){return e instanceof DevtoolsPeerServerError||e instanceof Error?e.message:String(e)}function exportDevtools(e,t,n,r){let i=e.get_is_registered(),a=i?e.get_dbus_connection():null,o=i?e.get_dbus_object_path():null,s=envValue(C),c=!!(a&&o),u=c||sessionBusUsable(),d=chooseDevtoolsTransport({requestedAddress:n.address??envValue(y),hasAppConnection:c,sessionBusUsable:u}),f=e.get_application_id()??`unknown`,p=`${o??appIdToObjectPath(f)}/devtools`;if((d.kind===`unregistered`||d.kind===`peer`&&d.reason===`no-session-bus`)&&console.error(describeMissingConnection(s,u)),d.kind===`session-bus`&&a)t.export(a,p),console.log(`[gjsify-devtools] exported ${_} at ${p} (dest ${f})`);else if(d.kind===`peer`){let n=startDevtoolsPeerServer(t,p,d.address??void 0),i=writeDevtoolsAddressFile(devtoolsAddressFilePath(l.get_user_runtime_dir(),f,r),n.address);t.attachPeerServer(n,i),console.log(`[gjsify-devtools] exported ${_} at ${p} (peer address ${n.address}${i?`, published to ${i}`:``})`),i&&e.connect(`shutdown`,()=>removeDevtoolsAddressFile(i))}return oe.add(t),t}const se=`&(?![a-zA-Z][a-zA-Z0-9]*;|#\\d+;|#x[0-9a-fA-F]+;)|<(?![a-zA-Z/!?])`;RegExp(se),RegExp(se,`g`);const ce=[`AdwNavigationSplitView`,`GtkListBox`,`AdwOverlaySplitView`];function probeEnabled(){let e=l.getenv(`GJSIFY_STORYBOOK_PROBE`);if(e==null)return!1;let t=e.toLowerCase();return t!==``&&t!==`0`&&t!==`false`}const le=5e3;function exitIfNotDrained(){if(typeof process>`u`||typeof process.exit!=`function`)return;let e=setTimeout(()=>{console.error(`STORYBOOK PROBE: host still alive ${le}ms after quit(), exiting`),process.exit(process.exitCode??0)},le);typeof e==`object`&&typeof e.unref==`function`&&e.unref()}function collectTypes(e,t){t.add(e.type);for(let n of e.children)collectTypes(n,t)}function installStorybookProbe(e,t,n={}){let r=n.requireChrome??ce,i=n.out??l.getenv(`GJSIFY_STORYBOOK_PROBE_OUT`)??void 0,a=n.timeoutMs??8e3,o=n.storyWidget??l.getenv(`GJSIFY_STORYBOOK_PROBE_STORY_WIDGET`)??void 0,s=t.controller.listStories(),c=[...new Set(s.map(e=>e.category))],u=n.story??l.getenv(`GJSIFY_STORYBOOK_PROBE_STORY`)??s[0]?.title,d=u?t.openStoryByTitle(u):!1,f=t.activeStory,p=new Set;collectTypes(dumpTree(t,60,`toplevel:0`),p);let m=r.filter(e=>!p.has(e)),h=new Set;f&&collectTypes(dumpTree(f,60,`story`),h);let g=h.size,_=o?h.has(o):null,finish=t=>{let n=JSON.stringify(t);if(t.ok)console.log(`STORYBOOK PROBE: PASS ${n}`);else{console.error(`STORYBOOK PROBE: FAIL ${n}`);try{typeof process<`u`&&(process.exitCode=1)}catch{}}if(i)try{l.file_set_contents(i,JSON.stringify(t,null,2))}catch{}e.quit(),exitIfNotDrained()},v=0;l.timeout_add(l.PRIORITY_DEFAULT,100,()=>{v+=100;let e=captureWidgetPng(t),n=t.get_width()>0&&t.get_height()>0;if(!e&&!(v>=a))return l.SOURCE_CONTINUE;let i=f?captureWidgetPng(f):null,p=s.length>=1&&c.length>=1&&m.length===0&&d&&f!=null&&g>1,y;return s.length<1?y=`no stories registered`:c.length<1?y=`no categories`:m.length>0?y=`chrome missing: ${m.join(`, `)}`:!d||f==null?y=`could not open story: ${u??`(none)`}`:g<=1&&(y=`opened story rendered an empty subtree`),p&&o&&!h.has(o)&&(p=!1,y=`story widget ${o} not found in the opened story subtree`),p&&n&&(!e||e.length===0)&&(p=!1,y=`window realized (${t.get_width()}x${t.get_height()}) but the GSK capture was empty`),finish({ok:p,reason:y,stories:s.length,categories:c,opened:d,activeStory:f?f.meta.title:null,requiredChrome:r,missingChrome:m,storySubtreeWidgets:g,storyWidgetPresent:_,windowRealized:n,windowPngBytes:e?e.length:0,storyPngBytes:i?i.length:0}),l.SOURCE_REMOVE})}const ue=e(import.meta.url);let de;function load$1(){return de===void 0&&(de=ue(`@gjsify/node-gi/gi`).requireGi(`Adw`,`1`)),de}__name(load$1,`load`);var w=new Proxy(Object.create(null),{get(e,t){return load$1()[t]},has(e,t){return t in load$1()}});const fe={UNKNOWN:0,CUSTOM:1,GPL_2_0:2,GPL_3_0:3,LGPL_2_1:4,LGPL_3_0:5,BSD:6,MIT_X11:7,ARTISTIC:8,GPL_2_0_ONLY:9,GPL_3_0_ONLY:10,LGPL_2_1_ONLY:11,LGPL_3_0_ONLY:12,AGPL_3_0:13,AGPL_3_0_ONLY:14,BSD_3:15,APACHE_2_0:16,MPL_2_0:17,"0BSD":18};fe.GPL_2_0_ONLY,fe.GPL_3_0_ONLY,fe.UNKNOWN;const pe=[`blue`,`teal`,`green`,`yellow`,`orange`,`red`,`pink`,`purple`,`slate`],me={blue:`#3584e4`,teal:`#2190a4`,green:`#3a944a`,yellow:`#c88800`,orange:`#ed5b00`,red:`#e62d42`,pink:`#d56199`,purple:`#9141ac`,slate:`#6f8396`};function parseHex(e){let t=/^#([0-9a-f]{6})$/i.exec(e.trim());if(!t)return null;let n=Number.parseInt(t[1],16);return[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255]}function toHex(e,t,n){let channel=e=>Math.round(Math.min(1,Math.max(0,e))*255).toString(16).padStart(2,`0`);return`#${channel(e)}${channel(t)}${channel(n)}`}const toLinear=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,fromLinear=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function linearToOklab(e,t,n){let r=Math.cbrt(.4122214708*e+.5363325363*t+.0514459929*n),i=Math.cbrt(.2119034982*e+.6806995451*t+.1073969566*n),a=Math.cbrt(.0883024619*e+.2817188376*t+.6299787005*n);return[.2104542553*r+.793617785*i-.0040720468*a,1.9779984951*r-2.428592205*i+.4505937099*a,.0259040371*r+.7827717662*i-.808675766*a]}function oklabToLinear(e,t,n){let r=(e+.3963377774*t+.2158037573*n)**3,i=(e-.1055613458*t-.0638541728*n)**3,a=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*i+.2309699292*a,-1.2684380046*r+2.6097574011*i-.3413193965*a,-.0041960863*r-.7034186147*i+1.707614701*a]}function adwaitaStandaloneColor(e,t){let n=parseHex(e);if(!n)return e;let[r,i,a]=linearToOklab(toLinear(n[0]),toLinear(n[1]),toLinear(n[2])),[o,s,c]=oklabToLinear(t?Math.max(r,.85):Math.min(r,.5),i,a);return toHex(fromLinear(o),fromLinear(s),fromLinear(c))}function adwaitaAccentBgColor(e){return me[e]}function adwaitaAccentColor(e,t){return adwaitaStandaloneColor(me[e],t)}var UnsupportedGObjectError=class extends Error{constructor(e,t){super(t),this.name=`UnsupportedGObjectError`,this.feature=e}};const he=new WeakSet;function makeType(e){let t=Object.freeze({name:e});return he.add(t),t}makeType(`gchararray`),makeType(`gboolean`),makeType(`gint`),makeType(`guint`),makeType(`gdouble`);const T={READABLE:1,WRITABLE:2,READWRITE:3,CONSTRUCT:4,CONSTRUCT_ONLY:8};var E=class ParamSpec{constructor(e,t,n,r,i,a,o,s){this.kind=e,this.name=t,this.nick=n,this.blurb=r,this.flags=i,this.defaultValue=a,this.minimum=o,this.maximum=s}static boolean(e,t,n,r,i){return new ParamSpec(`boolean`,e,t,n,r,i)}static string(e,t,n,r,i){return new ParamSpec(`string`,e,t,n,r,i)}static int(e,t,n,r,i,a,o){return new ParamSpec(`int`,e,t,n,r,o,i,a)}static uint(e,t,n,r,i,a,o){return new ParamSpec(`uint`,e,t,n,r,o,i,a)}static double(e,t,n,r,i,a,o){return new ParamSpec(`double`,e,t,n,r,o,i,a)}get_default_value(){return this.defaultValue}};const D={GTypeName:Symbol(`GType name`),GTypeFlags:Symbol(`GType flags`),interfaces:Symbol(`GType interfaces`),properties:Symbol(`GObject properties`),signals:Symbol(`GObject signals`),requires:Symbol(`GObject interface requires`),template:Symbol(`GTK widget template`),cssName:Symbol(`GTK widget CSS name`),children:Symbol(`GTK widget template children`),internalChildren:Symbol(`GTK widget template internal children`)};D.GTypeName,D.template,D.internalChildren,D.properties,D.signals,D.cssName,D.children,D.interfaces,D.requires,D.GTypeFlags;const ge=new WeakMap;function chainOf(e){let t=[];for(let n=e;typeof n==`function`;n=Object.getPrototypeOf(n)){let e=ge.get(n);e&&t.push(e)}return t}function chainOfInstance(e){return chainOf(e.constructor)}function typeNameOf(e,t){return t[0]?.typeName??e.constructor.name}function aliasesOf(e){return[e,e.replace(/-/g,`_`),e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())]}function findProperty(e,t){for(let n of e)for(let e of n.properties)if(aliasesOf(e.name).includes(t))return e}function findSignal(e,t){for(let n of e)if(Object.prototype.hasOwnProperty.call(n.signals,t))return n.signals[t]}const _e=new WeakMap;let ve=0;function stateOf$1(e){let t=_e.get(e);return t||(t={values:new Map,handlers:new Map,connections:new Map,emissions:[]},_e.set(e,t)),t}__name(stateOf$1,`stateOf`);function parseSignal(e){let t=e.indexOf(`::`);return t===-1?{name:e}:{name:e.slice(0,t),detail:e.slice(t+2)}}function addHandler(e,t,n){let r=stateOf$1(e),i=++ve,a=r.handlers.get(t)??[];return a.push({id:i,handler:n}),r.handlers.set(t,a),r.connections.set(i,()=>{a.splice(a.findIndex(e=>e.id===i),1)}),i}function runHandlers(e,t,n){let r=stateOf$1(e),i={key:t,stopped:!1};r.emissions.push(i);try{for(let{id:a,handler:o}of(r.handlers.get(t)??[]).slice()){if(i.stopped)break;r.connections.has(a)&&o(e,...n)}}finally{r.emissions.pop()}}function connectInstance(e,t,n){let r=chainOfInstance(e),i=typeNameOf(e,r),{name:a,detail:o}=parseSignal(t),foreign=()=>{let a=r[0]?.door;if(!a)throw Error(`No signal '${t}' on object '${i}'`);let o=++ve,s=a.listen(e,t,n);return stateOf$1(e).connections.set(o,s),o};if(a===`notify`){if(o===void 0)throw new UnsupportedGObjectError(`connect("notify")`,`connect('notify') without a property is outside the GObject subset; connect 'notify::<property>' on '${i}'.`);let t=findProperty(r,o);return t?addHandler(e,`notify::${t.name}`,n):foreign()}if(findSignal(r,a)){if(o!==void 0)throw Error(`Signal '${a}' on object '${i}' has no detail`);return addHandler(e,a,n)}return foreign()}function disconnectInstance(e,t){let n=stateOf$1(e),r=n.connections.get(t);if(!r)throw Error(`No handler with id ${t} is connected to ${String(e)}`);n.connections.delete(t),r()}function emitInstance(e,t,...n){let r=chainOfInstance(e),i=typeNameOf(e,r),a=findSignal(r,t);if(a){if(n.length!==a.length)throw Error(`Signal '${t}' on ${i} requires ${a.length} args got ${n.length}`);runHandlers(e,t,n);return}let o=r[0]?.door;if(!o)throw Error(`No signal '${t}' on object '${i}'`);o.dispatch(e,t,n)}function notifyInstance(e,t){let n=chainOfInstance(e),r=findProperty(n,t);if(r){runHandlers(e,`notify::${r.name}`,[r]);return}let i=n[0]?.door;if(!i)throw Error(`No property ${t} on ${typeNameOf(e,n)}`);i.dispatch(e,`notify::${t}`,[])}function generateAccessors(e,t){let{name:n,flags:r}=e,i=r&T.READABLE,a=r&T.WRITABLE,o=t??{configurable:!0,enumerable:!0};return i&&a?!o.get&&!o.set?(o.get=function(){let{values:t}=stateOf$1(this);return t.has(n)||t.set(n,e.get_default_value()),t.get(n)},o.set=function(e){let{values:t}=stateOf$1(this);e!==t.get(n)&&(t.set(n,e),this.notify(n))}):o.get?o.set||=function(){throw Error(`getter defined without setter for property ${n}`)}:o.get=function(){throw Error(`setter defined without getter for property ${n}`)}:i&&!o.get?o.get=function(){throw Error(`missing getter for read-only property ${n}`)}:a&&!o.set&&(o.set=function(){throw Error(`missing setter for write-only property ${n}`)}),o}function checkAccessors(e,t){let{name:n,flags:r}=t;if(r&T.CONSTRUCT_ONLY)return;let[,i,a]=aliasesOf(n),own=t=>Object.getOwnPropertyDescriptor(e,t),o=own(n),s=o,c=n.includes(`-`),l,u;c&&(l=own(i),u=own(a),o??=l,o??=u);let d=r&T.READABLE,f=r&T.WRITABLE;(!o||d&&!o.get||f&&!o.set)&&(o=generateAccessors(t,o)),s||Object.defineProperty(e,n,o),c&&(l||Object.defineProperty(e,i,o),u||Object.defineProperty(e,a,o))}function defineConstructOnly(e,t,n){let{values:r}=stateOf$1(e);r.set(t.name,n);for(let n of new Set(aliasesOf(t.name)))Object.defineProperty(e,n,{get:()=>r.get(t.name),enumerable:!0,configurable:!0})}function bindProperties(e,t,n,r,i=[]){let a=i.includes(`invert-boolean`),o=!1,transfer=(e,t,n,r)=>()=>{if(!o){o=!0;try{let i=e[t];n[r]=a?!i:i}finally{o=!1}}},s=transfer(e,t,n,r),c=[[e,e.connect(`notify::${t}`,s)]];if(i.includes(`bidirectional`)){let i=transfer(n,r,e,t);c.push([n,n.connect(`notify::${r}`,i)])}return i.includes(`sync-create`)&&s(),{unbind(){for(let[e,t]of c.splice(0))e.disconnect(t)}}}function createClosure(e,t,n,r){let i=r??e;if(n)throw new UnsupportedGObjectError(`swapped`,`Unsupported template signal flag "swapped"`);let a=e[t];if(a===void 0)throw Error(`A handler called ${t} was not defined on ${String(e)}`);return a.bind(i)}function scopeOf(e){return{instance:e,handler:(t,n)=>createClosure(e,t,n?.flags?.includes(`swapped`)??!1,n?.object),bind:bindProperties}}function constructRegistered(e,t={}){let n=chainOfInstance(e),r={},i=new Map;for(let[e,a]of Object.entries(t)){let t=findProperty(n,e);t?i.set(t,a):r[e]=a}let a=[];for(let t of[...n].reverse())t.template&&a.push([t,t.door.createFromTree(t.template,scopeOf(e),e)]);for(let t of n)for(let n of t.properties)n.flags&T.CONSTRUCT_ONLY&&defineConstructOnly(e,n,i.has(n)?i.get(n):n.get_default_value());for(let[t,n]of i)t.flags&T.CONSTRUCT_ONLY||(e[t.name]=n);for(let[t,n]of a){for(let r of t.internalChildren){let i=n.objects[r];if(i===void 0)throw Error(`Template of ${t.typeName} has no child object '${r}' for InternalChildren`);e[`_${r.replace(/-/g,`_`)}`]=i}t.door.attach(e,n)}return r}const ye=Symbol(`GIR type`);function registerBaseClass(e,t,n,r=[]){let missing=e=>{throw Error(`No signal '${e}' on object '${t}'`)},i=makeType(t);Object.defineProperty(e,"$gtype",{get:()=>i,enumerable:!1,configurable:!1});for(let t of r)checkAccessors(e.prototype,t);ge.set(e,{klass:e,typeName:t,gtype:i,properties:r,signals:n,internalChildren:[],door:{name:t,dispatch:(e,t)=>missing(t),listen:(e,t)=>missing(t),createFromTree:()=>missing(`template`),attach(){},register(){}}})}var GObjectObject=class{constructor(e){let t=constructRegistered(this,e),n=Object.keys(t)[0];if(n!==void 0)throw Error(`No property ${n} on ${typeNameOf(this,chainOfInstance(this))}`)}notify(e){notifyInstance(this,e)}connect(e,t){return connectInstance(this,e,t)}disconnect(e){disconnectInstance(this,e)}emit(e,...t){emitInstance(this,e,...t)}};function refuse$1(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}__name(refuse$1,`refuse`);var ActionRegistry=class{constructor(){this._actions=new Map}add(e){this._actions.set(e.name,e)}remove(e){this._actions.delete(e)}lookup_action(e){return this._actions.get(e)??null}has(e){return this._actions.has(e)}list(){return[...this._actions.keys()]}};const be=new WeakMap;function actionRegistryOf(e,t=!0){let n=be.get(e);return n===void 0&&t&&(n=new ActionRegistry,be.set(e,n)),n}function requireAction(e){let t=e;if(typeof t?.name!=`string`||typeof t.activate!=`function`)throw TypeError(`add_action: needs a Gio.Action (a Gio.SimpleAction)`);return t}const xe={add_action(e){actionRegistryOf(this).add(requireAction(e))},lookup_action(e){return actionRegistryOf(this,!1)?.lookup_action(e)??null},remove_action(e){actionRegistryOf(this,!1)?.remove(e)}},Se={has_action(e){return actionRegistryOf(this,!1)?.has(e)??!1},list_actions(){return actionRegistryOf(this,!1)?.list()??[]},activate_action(e,t=null){if(t!==null)throw refuse$1(`activate_action with a parameter`,`needs a GLib.Variant`);actionRegistryOf(this,!1)?.lookup_action(e)?.activate(null)},get_action_enabled(e){return actionRegistryOf(this,!1)?.lookup_action(e)?.enabled??!1}};function installActionMap(e,t=!1){let n=t?{...xe,...Se}:{...xe};for(let[t,r]of Object.entries(n))Object.defineProperty(e,t,{value:r,writable:!0,configurable:!0,enumerable:!1})}const Ce=new WeakMap;function linkWindow(e,t){t===null?Ce.delete(e):Ce.set(e,t)}const we={NONE:0,FLAGS_NONE:0,DEFAULT_FLAGS:0,IS_SERVICE:1,IS_LAUNCHER:2,HANDLES_OPEN:4,HANDLES_COMMAND_LINE:8,SEND_ENVIRONMENT:16,NON_UNIQUE:32,CAN_OVERRIDE_APP_ID:64,ALLOW_REPLACEMENT:128,REPLACE:256};function isValidApplicationId(e){if(typeof e!=`string`||e.length>255||e===``)return!1;let t=e.split(`.`);return t.length>=2&&t.every(e=>/^[A-Za-z_-][A-Za-z0-9_-]*$/.test(e))}function refuse(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}const Te=`register.hold.release.mark_busy.unmark_busy.open.set_inactivity_timeout.send_notification.withdraw_notification.register_session.set_option_context_parameter_string.set_option_context_summary.set_option_context_description.add_main_option.add_main_option_entries.add_option_group.set_resource_base_path.get_resource_base_path.set_flags.get_is_remote.get_is_registered.get_dbus_connection.get_dbus_object_path.bind_busy_property.add_action_entries.set_default`.split(`.`),Ee=[`is_remote`,`is_registered`,`is_busy`,`resource_base_path`,`inactivity_timeout`,`action_group`],De=[`open`,`command-line`,`handle-local-options`,`shutdown`,`name-lost`],Oe=[`set_accels_for_action`,`get_accels_for_action`,`list_action_descriptions`,`get_actions_for_accel`,`set_menubar`,`get_menubar`,`get_menu_by_id`,`set_app_menu`,`get_app_menu`,`get_menu_by_id`,`inhibit`,`uninhibit`],ke=new WeakMap;let Ae=null;function rememberDefault(e){Ae??=e}function stateOf(e){let t=ke.get(e);return t===void 0&&(t={id:null,windows:[],running:!1,resolve:()=>{}},ke.set(e,t)),t}function hostOf(e){let t=e.constructor.host;if(t===void 0)throw Error(`Gio.Application: this class has no ApplicationHost; use the Gtk.Application of a port.`);return t}var GioApplicationBase=class extends GObjectObject{static{this[ye]=`Gio.Application`}static id_is_valid(e){return isValidApplicationId(e)}static get_default(){return Ae}constructor(e){super(e),rememberDefault(this)}get application_id(){return stateOf(this).id}set application_id(e){let t=e??null;if(t!==null&&!isValidApplicationId(t))throw Error(`Gio.Application: '${String(t)}' is not a valid application id (g_application_id_is_valid)`);let n=stateOf(this);if(n.running)throw Error(`Gio.Application: the application id cannot change while it runs`);n.id!==t&&(n.id=t,this.notify(`application-id`))}get flags(){return 0}set flags(e){if(e!==void 0&&e!==we.NONE)throw refuse(`Gio.ApplicationFlags value ${String(e)}`,`is a flag other than the default`)}get_application_id(){return this.application_id}set_application_id(e){this.application_id=e}get_flags(){return 0}vfunc_startup(){}vfunc_activate(){}run(){throw refuse(`Gio.Application.run()`,`blocks, and a page cannot; use runAsync()`)}connect(e,t){let n=e.split(`::`)[0]??e;if(De.includes(n))throw refuse(`the '${n}' signal`,`is not emitted`);return super.connect(e,t)}async runAsync(e=[]){let t=stateOf(this);if(t.running)throw Error(`Gio.Application.runAsync(): the application is already running`);let n=hostOf(this);t.running=!0;let r=new Promise(e=>{t.resolve=e}),i,a=!1,body=()=>{try{if(this.vfunc_startup(),this.emit(`startup`),this.emit(`activate`),this.vfunc_activate(),t.running&&t.windows.length===0&&n.requiresWindow)throw Error(`Gio.Application.runAsync(): activate added no window on ${n.name}; a window must be added synchronously by activate (ADR 0098 § 3).`)}catch(e){i=e,a=!0}return t.windows[0]??null};try{await n.start(body)}catch(e){i=e,a=!0}if(a)throw t.running=!1,n.exit(),i;return t.windows.length===0&&this._finish(0),r}quit(){let e=stateOf(this);if(e.running){for(let t of e.windows.splice(0))linkWindow(t,null),hostOf(this).detach(t);this._finish(0)}}_finish(e){let t=stateOf(this);t.running&&(t.running=!1,t.resolve(e),hostOf(this).exit())}};registerBaseClass(GioApplicationBase,`GApplication`,{startup:[],activate:[]},[E.string(`application-id`,``,``,T.READWRITE|T.CONSTRUCT,null),E.uint(`flags`,``,``,T.READWRITE|T.CONSTRUCT,0,4294967295,0)]),installActionMap(GioApplicationBase.prototype,!0);function refuseMembers(e,t,n){for(let n of t)Object.defineProperty(e,n,{value:()=>{throw refuse(`${n}()`,`is not implemented`)},writable:!0,configurable:!0,enumerable:!1});for(let t of n)Object.defineProperty(e,t,{get(){throw refuse(`the '${t}' property`,`is not implemented`)},configurable:!0,enumerable:!1})}refuseMembers(GioApplicationBase.prototype,Te,Ee);function withGtkApplication(e){class GtkApplication extends e{get active_window(){return stateOf(this).windows[0]??null}get_active_window(){return this.active_window}get_windows(){return[...stateOf(this).windows]}add_window(e){let t=stateOf(this);t.windows.includes(e)||(t.windows.unshift(e),linkWindow(e,this))}remove_window(e){let t=stateOf(this),n=t.windows.indexOf(e);n!==-1&&(t.windows.splice(n,1),linkWindow(e,null),t.windows.length===0&&this._finish(0))}}return refuseMembers(GtkApplication.prototype,Oe,[]),GtkApplication}withGtkApplication(GioApplicationBase),Math.PI*.35,Math.PI*.015,Math.PI*.9;const je=Math.PI*.9,Me=Math.PI*.7,Ne=Math.PI*1.1,Pe=Math.PI*1.35,Fe=je+Ne+Pe-Me;53*Math.PI*2/Fe,Ne-Me/2,new Set(`ADC.AND.ASL.BCC.BCS.BEQ.BIT.BMI.BNE.BPL.BRK.BVC.BVS.CLC.CLD.CLI.CLV.CMP.CPX.CPY.DEC.DEX.DEY.EOR.INC.INX.INY.JMP.JSR.LDA.LDX.LDY.LSR.NOP.ORA.PHA.PHP.PLA.PLP.ROL.ROR.RTI.RTS.SBC.SEC.SED.SEI.STA.STX.STY.TAX.TAY.TSX.TXA.TXS.TYA`.split(`.`));const O=new WeakMap,Ie=new WeakMap;function sourceOf(e){let t=e.constructor.source;if(t===void 0)throw Error(`Adw.StyleManager: this class has no StyleSource; use the Adw.StyleManager of a port.`);return t}var StyleManagerBase=class extends GObjectObject{static{this[ye]=`Adw.StyleManager`}static get_default(){let e=Ie.get(this);if(e===void 0){e=new this,Ie.set(this,e);let t=sourceOf(e);O.set(e,t.dark()),t.subscribe(()=>{let n=t.dark();O.get(e)!==n&&(O.set(e,n),e.notify(`dark`))})}return e}get dark(){return sourceOf(this).dark()}get_dark(){return this.dark}};registerBaseClass(StyleManagerBase,`AdwStyleManager`,{},[E.boolean(`dark`,``,``,T.READABLE,!1)]);const Le={system:`Follow system`,light:`Light`,dark:`Dark`},Re={blue:`Blue`,teal:`Teal`,green:`Green`,yellow:`Yellow`,orange:`Orange`,red:`Red`,pink:`Pink`,purple:`Purple`,slate:`Slate`};var StorybookAppearance=class{constructor(){this._provider=null,this._applying=!1,this._styleManager=w.StyleManager.get_default(),this.settings=new StorybookSettings(()=>this._styleManager.get_dark()),this.settings.subscribe(e=>this._apply(e)),this._styleManager.connect(`notify::dark`,()=>this.settings.systemChanged()),this._apply(this.settings.state)}_apply(e){if(!this._applying){this._applying=!0;try{this._styleManager.set_color_scheme(e.colorScheme===`light`?w.ColorScheme.FORCE_LIGHT:e.colorScheme===`dark`?w.ColorScheme.FORCE_DARK:w.ColorScheme.DEFAULT),this._applyAccent(this.settings.resolvedAccent)}finally{this._applying=!1}}}_applyAccent(e){let t=f.Display.get_default();if(!t)return;if(!this._provider){if(!e)return;this._provider=new h.CssProvider,h.StyleContext.add_provider_for_display(t,this._provider,h.STYLE_PROVIDER_PRIORITY_APPLICATION)}if(!e){this._provider.load_from_string(``);return}let n=adwaitaAccentBgColor(e),r=adwaitaAccentColor(e,this.settings.resolvedDark);this._provider.load_from_string(`:root { --accent-bg-color: ${n}; --accent-color: ${r}; }`)}};function buildSwatch(e,t,n){let r=new h.CheckButton({tooltip_text:t,halign:h.Align.CENTER,valign:h.Align.CENTER,focus_on_click:!1});for(let t of e)r.add_css_class(t);return r.update_property([h.AccessibleProperty.LABEL],[t]),n&&r.set_group(n),r}function buildSwatchCard(e=!1){let t=new w.WrapBox({align:.5,child_spacing:8,line_spacing:8,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),n=new w.Bin({child:t,hexpand:!0});return n.add_css_class(`card`),e&&n.add_css_class(`storybook-card-attached`),{card:n,row:t}}function buildAppearanceDialog(e){let t=e.settings,n=new w.PreferencesPage,r=new w.PreferencesGroup({title:`Style`}),{card:i,row:o}=buildSwatchCard(),s=null,c=new Map;for(let e of a){let n=buildSwatch([`storybook-swatch`,`storybook-scheme-swatch`,`storybook-scheme-${e}`],Le[e],s);s??=n,n.set_active(t.colorScheme===e),n.connect(`toggled`,()=>{n.get_active()&&(t.colorScheme=e)}),c.set(e,n),o.append(n)}r.add(i),n.add(r);let l=new w.PreferencesGroup({title:`Accent colour`});l.add_css_class(`storybook-attached-group`);let u=new w.SwitchRow({title:`Use a custom accent colour`,subtitle:`Off follows the desktop, which owns the accent`,active:t.accentMode===`custom`});l.add(u);let{card:d,row:f}=buildSwatchCard(!0),p=null,m=new Map;for(let e of pe){let n=buildSwatch([`storybook-swatch`],Re[e],p);p??=n,n.set_active(t.accent===e);let r=new h.CssProvider;r.load_from_string(`checkbutton { background-color: ${adwaitaAccentBgColor(e)}; }`),n.get_style_context().add_provider(r,h.STYLE_PROVIDER_PRIORITY_APPLICATION),n.connect(`toggled`,()=>{n.get_active()&&(t.accent=e)}),m.set(e,n),f.append(n)}f.set_sensitive(t.accentMode===`custom`),u.connect(`notify::active`,()=>{t.accentMode=u.get_active()?`custom`:`system`}),l.add(d),n.add(l),t.subscribe(e=>{let t=c.get(e.colorScheme);t&&!t.get_active()&&t.set_active(!0);let n=m.get(e.accent);n&&!n.get_active()&&n.set_active(!0);let r=e.accentMode===`custom`;u.get_active()!==r&&u.set_active(r),f.set_sensitive(r)});let g=new w.PreferencesDialog({title:`Appearance`});return g.add(n),g}function adwControlWidgetFactory(){return{text(e,t){let n=new w.EntryRow({title:e});t&&n.set_tooltip_text(t);let r=null;return n.connect(`changed`,()=>r?.(n.get_text())),{node:n,get:()=>n.get_text(),set:e=>n.set_text(e),onChange:e=>{r=e}}},boolean(e,t){let n=new w.SwitchRow({title:e,subtitle:t??``}),r=null;return n.connect(`notify::active`,()=>r?.(n.get_active())),{node:n,get:()=>n.get_active(),set:e=>n.set_active(e),onChange:e=>{r=e}}},number(e){let t=w.SpinRow.new_with_range(e.min??0,e.max??100,e.step??1);t.set_title(e.label||e.name),e.description&&t.set_subtitle(e.description);let n=null;return t.connect(`changed`,()=>n?.(t.get_value())),{node:t,get:()=>t.get_value(),set:e=>t.set_value(e),onChange:e=>{n=e}}},range(e){return buildRangeWidget(e)},select(e){return buildSelectWidget(e)},color(e,t){return buildColorWidget(e,t)}}}function buildRangeWidget(e){let t=e.min??0,n=e.max??100,r=e.step??1,i=typeof e.min==`number`?e.min:0,a=Number.isInteger(r)&&Number.isInteger(i),o=new h.Adjustment({lower:t,upper:n,step_increment:r,value:i});o.step_increment=r;let s=new h.ListBoxRow({selectable:!1,activatable:!1});s.add_css_class(`story-range-row`);let c=new h.Box({orientation:h.Orientation.VERTICAL,spacing:6,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),l=new h.Box({orientation:h.Orientation.HORIZONTAL,spacing:12}),u=new h.Label({label:e.label||e.name,halign:h.Align.START,hexpand:!0,ellipsize:3});u.add_css_class(`heading`);let formatValue=e=>a?String(Math.round(e)):e.toFixed(2),d=new h.Label({label:formatValue(i),halign:h.Align.END});if(d.add_css_class(`numeric`),d.add_css_class(`dim-label`),l.append(u),l.append(d),c.append(l),e.description){let t=new h.Label({label:e.description,halign:h.Align.START,xalign:0,wrap:!0,max_width_chars:32});t.add_css_class(`caption`),t.add_css_class(`dim-label`),c.append(t)}let f=new h.Scale({orientation:h.Orientation.HORIZONTAL,adjustment:o,draw_value:!1,hexpand:!0}),p=null,m=!1;return f.connect(`value-changed`,()=>{if(m)return;let e=f.get_value();if(a){let t=Math.round(e);if(t!==e){f.set_value(t);return}e=t}d.set_label(formatValue(e)),p?.(e)}),c.append(f),s.set_child(c),{node:s,get:()=>f.get_value(),set:e=>{m=!0,f.set_value(e),m=!1,d.set_label(formatValue(e))},onChange:e=>{p=e}}}function buildSelectWidget(e){let t=e.options??[],n=h.StringList.new(t.map(e=>e.label)),r=new w.ComboRow({title:e.label||e.name,subtitle:e.description??``,model:n}),i=null;return r.connect(`notify::selected`,()=>i?.(r.get_selected())),{node:r,get:()=>r.get_selected(),set:e=>r.set_selected(e),onChange:e=>{i=e}}}function buildColorWidget(e,t){let n=new w.ActionRow({title:e,subtitle:t??``}),r=new h.ColorDialogButton({dialog:new h.ColorDialog({title:e}),valign:h.Align.CENTER});n.add_suffix(r),n.set_activatable_widget(r);let channel=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,`0`),rgbaToHex=e=>`#${channel(e.red)}${channel(e.green)}${channel(e.blue)}`,i=null,a=!1;return r.connect(`notify::rgba`,()=>{a||i?.(rgbaToHex(r.get_rgba()))}),{node:n,get:()=>rgbaToHex(r.get_rgba()),set:e=>{let t=new f.RGBA;t.parse(e)&&(a=!0,r.set_rgba(t),a=!1)},onChange:e=>{i=e}}}var ze=class StorybookWindow extends w.ApplicationWindow{static{S.registerClass({GTypeName:`StorybookWindow`,Template:`<?xml version="1.0" encoding="UTF-8"?>
73
+ </node>`}const ee=e(import.meta.url);let b;function load$4(){return b===void 0&&(b=ee(`@gjsify/node-gi/gi`).requireGi(`Gio`,`2.0`)),b}__name(load$4,`load`);var x=new Proxy(Object.create(null),{get(e,t){return load$4()[t]},has(e,t){return t in load$4()}});function isWin32(){return l.DIR_SEPARATOR===92}function defaultListenAddress(){return isWin32()?`nonce-tcp:host=127.0.0.1`:`unix:tmpdir=${l.get_tmp_dir()}`}var DevtoolsPeerServerError=class extends Error{constructor(e,t,n,r){super(e),this.address=t,this.reason=n,this.name=`DevtoolsPeerServerError`,this.cause=r}};function isAddressInUse(e){return e instanceof l.Error&&e.matches(x.io_error_quark(),x.IOErrorEnum.ADDRESS_IN_USE)}function unixSocketPath(e){if(!e.startsWith(`unix:`))return null;for(let t of e.slice(5).split(`,`)){let e=t.indexOf(`=`);if(!(e<0||t.slice(0,e)!==`path`))try{return decodeURIComponent(t.slice(e+1))}catch{return null}}return null}function inspectExistingSocket(e){try{if((x.File.new_for_path(e).query_info(`unix::mode`,x.FileQueryInfoFlags.NONE,null).get_attribute_uint32(`unix::mode`)&61440)!=49152)return`not-a-socket`}catch{return`not-a-socket`}let t=new x.SocketClient;t.set_timeout(2);let n;try{n=t.connect(x.UnixSocketAddress.new(e),null)}catch{return`dead`}return n.close(null),`live`}function clearReclaimableSocket(e){let t=unixSocketPath(e);if(!t||!l.file_test(t,l.FileTest.EXISTS))return;let n=inspectExistingSocket(t);if(n===`live`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: another process is already listening there. Stop it, or point ${y} (or options.address) at a different socket — GJSIFY_DEVTOOLS_INSTANCE=<label> lets two devtools-enabled apps run side by side.`,e,`address-in-use`);if(n===`not-a-socket`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} already exists and is not a socket, so it will NOT be removed. Point ${y} (or options.address) at a free path.`,e,`occupied-by-other-file`);try{x.File.new_for_path(t).delete(null)}catch(n){throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} is a socket nothing listens on, but removing it failed (${n}). Delete it by hand, or point ${y} at a free path.`,e,`address-in-use`,n)}console.log(`[gjsify-devtools] reclaimed the stale socket ${t}: nothing was listening on it (an abnormal exit — Ctrl-C, SIGKILL, a crash — leaves the inode behind).`)}function flagsForAddress(e){return e.startsWith(`tcp:`)||e.startsWith(`nonce-tcp:`)?x.DBusServerFlags.NONE:x.DBusServerFlags.AUTHENTICATION_REQUIRE_SAME_USER}function startDevtoolsPeerServer(e,t,n){let r=n&&n!==``?n:defaultListenAddress();clearReclaimableSocket(r);let i;try{i=x.DBusServer.new_sync(r,flagsForAddress(r),x.dbus_generate_guid(),null,null)}catch(e){let t=isAddressInUse(e);throw new DevtoolsPeerServerError(t?`cannot listen on ${r}: the address is already in use (${e}). Stop whatever holds it, or point ${y} (or options.address) at a different address.`:`cannot listen on ${r}: ${e}. Check the address form — \`unix:path=/tmp/app.sock\`, \`unix:tmpdir=/tmp\` or \`nonce-tcp:host=127.0.0.1\`.`,r,t?`address-in-use`:`listen-failed`,e)}let a=new Set;i.connect(`new-connection`,(n,r)=>(a.add(r),r.connect(`closed`,()=>{e.unexport(r),a.delete(r)}),e.export(r,t),!0)),i.start();let o=!1;return{address:i.get_client_address(),objectPath:t,get connectionCount(){return a.size},stop(){if(!o){o=!0,i.stop();for(let t of a)e.unexport(t),!t.is_closed()&&t.close(null,(e,t)=>{try{e.close_finish(t)}catch{}});a.clear()}}}}function writeDevtoolsAddressFile(e,t){try{if(l.mkdir_with_parents(l.path_get_dirname(e),448),!l.file_set_contents(e,`${t}\n`))return null}catch(t){return console.error(`[gjsify-devtools] could not publish the peer address to ${e}: ${t}`),null}try{x.File.new_for_path(e).set_attribute_uint32(`unix::mode`,384,x.FileQueryInfoFlags.NONE,null)}catch(t){console.error(`[gjsify-devtools] could not restrict ${e} to the current user: ${t}`)}return e}function removeDevtoolsAddressFile(e){try{x.File.new_for_path(e).delete(null)}catch{}}const te=e(import.meta.url);let ne;function load$3(){return ne===void 0&&(ne=te(`@gjsify/node-gi/gi`).requireGi(`Graphene`,`1.0`)),ne}__name(load$3,`load`);var re=new Proxy(Object.create(null),{get(e,t){return load$3()[t]},has(e,t){return t in load$3()}});function captureWidget(e){let t=e.get_native()?.get_renderer();if(!t)return{png:null,blocker:`no-renderer`};let n=e.get_width(),r=e.get_height();if(n<=0||r<=0)return{png:null,blocker:`zero-size`};let i=h.WidgetPaintable.new(e),a=h.Snapshot.new();i.snapshot(a,n,r);let o=a.to_node();if(!o)return{png:null,blocker:`empty-snapshot`};let s=new re.Rect;s.init(0,0,n,r);let c=t.render_texture(o,s).save_to_png_bytes().get_data();return c?{png:new Uint8Array(c)}:{png:null,blocker:`empty-png`}}function captureWidgetPng(e){return captureWidget(e).png}function dumpGSettings(e){let t=x.SettingsSchemaSource.get_default()?.lookup(e,!0);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`GSettings schema '${e}' is not installed`));let n=new x.Settings({settings_schema:t}),r={};for(let e of t.list_keys())r[e]=n.get_value(e).recursiveUnpack();return r}const ie=e(import.meta.url);let ae;function load$2(){return ae===void 0&&(ae=ie(`@gjsify/node-gi/gi`).requireGi(`GObject`,`2.0`)),ae}__name(load$2,`load`);var S=new Proxy(Object.create(null),{get(e,t){return load$2()[t]},has(e,t){return t in load$2()}});function parseWidgetPath(e){let t=e.split(`/`).filter(e=>e.length>0);if(t.length===0)return null;let n=t[0].match(/^toplevel:(\d+)$/);if(!n)return null;let r=[];for(let e of t.slice(1)){let t=e.match(/^child:(\d+)$/);if(!t)return null;r.push(Number(t[1]))}return{toplevel:Number(n[1]),children:r}}function buildWidgetPath(e,t){return[`toplevel:${e}`,...t.map(e=>`child:${e}`)].join(`/`)}function widgetType(e){return gtypeName(e)??`GtkWidget`}function gtypeName(e){let t=e;return typeof t?.$typeName==`string`&&t.$typeName.length>0?t.$typeName:t?.constructor?.$gtype?.name??null}function widgetIsA(e,t){let n=gtypeName(e);if(n===null||!t)return!1;if(n===t)return!0;let r=S.type_from_name(n),i=S.type_from_name(t);return!r||!i?!1:S.type_is_a(r,i)}function activateWidget(e){let t=e,n=typeof t.get_parent==`function`?t.get_parent():null,r=!!n&&widgetIsA(n,`GtkListBox`);if(!(r&&widgetIsA(e,`GtkListBoxRow`))&&typeof t.activate==`function`&&t.activate()===!0)return!0;if(r){let t=n,r=!1;return typeof t.select_row==`function`&&(t.select_row(e),r=!0),typeof t.emit==`function`&&(t.emit(`row-activated`,e),r=!0),r}return!1}function sendKeyToWidget(e,t,n){let r=e.observe_controllers(),i=!1;for(let e=0;e<r.get_n_items();e++){let a=r.get_item(e);widgetIsA(a,`GtkEventControllerKey`)&&(a.emit(`key-pressed`,t,0,n),i=!0)}return i}function nthChild(e,t){let n=e.get_first_child(),r=0;for(;n&&r<t;)n=n.get_next_sibling(),r++;return r===t?n:null}function listToplevels(){let e=h.Window.get_toplevels(),t=e.get_n_items(),n=[];for(let r=0;r<t;r++){let t=e.get_item(r);t&&n.push({path:`toplevel:${r}`,type:widgetType(t),title:t.get_title?.()??null,mapped:t.get_mapped(),focused:t.is_active??!1})}return n}function resolveWidgetPath(e){let t=parseWidgetPath(e);if(!t)return null;let n=h.Window.get_toplevels().get_item(t.toplevel);if(!n)return null;for(let e of t.children)if(n=nthChild(n,e),!n)return null;return n}function parseWidgetSelector(e){let t=e.indexOf(`:`),n=(t<0?e:e.slice(0,t)).trim(),r=(t<0?``:e.slice(t+1)).trim();return!n&&!r?null:{type:n,cssClass:r}}function findWidgetPath(e,t,n){let r={path:null};return walkForSelector(e,t,n,r)??r.path}function walkForSelector(e,t,n,r){if(!e.get_visible()||!e.get_mapped())return null;if(!t.cssClass||e.get_css_classes().includes(t.cssClass)){if(!t.type||widgetType(e)===t.type)return n;r.path===null&&widgetIsA(e,t.type)&&(r.path=n)}let i=e.get_first_child(),a=0;for(;i;){let e=walkForSelector(i,t,`${n}/child:${a}`,r);if(e)return e;i=i.get_next_sibling(),a++}return null}function geometryOf(e){if(!e.get_mapped())return;let t=e.get_allocation(),n=t.width+e.get_margin_start()+e.get_margin_end(),r=t.height+e.get_margin_top()+e.get_margin_bottom(),[i,a]=e.measure(h.Orientation.HORIZONTAL,-1),o=n>0?Math.max(n,i):-1,[s,c]=e.measure(h.Orientation.VERTICAL,o),l={width:n,height:r,widthRequest:[i,a],heightRequest:[s,c]};return(n<i||r<s)&&(l.short=!0),l}function dumpTree(e,t,n){let r={path:n,type:widgetType(e),name:e.get_name()||null,cssClasses:e.get_css_classes(),mapped:e.get_mapped(),visible:e.get_visible(),children:[]},i=geometryOf(e);if(i!==void 0&&(r.geometry=i),t<=0)return e.get_first_child()&&(r.truncated=!0),r;let a=e.get_first_child(),o=0;for(;a;)r.children.push(dumpTree(a,t-1,`${n}/child:${o}`)),a=a.get_next_sibling(),o++;return r}function jsonSafe(e){let t=typeof e;return e==null||t===`string`||t===`number`||t===`boolean`?e??null:`[${t}]`}function getWidgetProperty(e,t){let n=e,r=t.replace(/-/g,`_`),i=t.replace(/[-_]([a-z])/g,(e,t)=>t.toUpperCase());for(let e of[t,r,i])if(e in n)return jsonSafe(n[e])}function childIndex(e,t){let n=e.get_first_child(),r=0;for(;n;){if(n===t)return r;n=n.get_next_sibling(),r++}return-1}function pathOfWidget(e){let t=[],n=e,r=n.get_parent();for(;r;){let e=childIndex(r,n);if(e<0)return null;t.unshift(e),n=r,r=n.get_parent()}let i=h.Window.get_toplevels(),a=i.get_n_items();for(let e=0;e<a;e++)if(i.get_item(e)===n)return buildWidgetPath(e,t);return null}function isActiveWindowScope(e){return!e||e===`window`||e===`active`}function frameDelay(e){return new Promise(t=>{l.timeout_add(l.PRIORITY_DEFAULT,e,()=>(t(),l.SOURCE_REMOVE))})}async function captureWidgetWhenRenderable(e,t=12,n=50){let r=null;for(let i=0;i<t;i++){let t=captureWidget(e);if(t.png)return{png:t.png,blocker:null};r=t.blocker,await frameDelay(n)}let i=captureWidget(e);return{png:i.png,blocker:i.png?null:i.blocker??r}}var DevtoolsService=class{constructor(e,t){this._app=e,this._options=t,this._exported=new Map,this._peer=null,this._addressFile=null,this._kinds=new Map,this._extensions=t.extend??[];for(let[e,t]of Object.entries(v))this._kinds.set(e,t);for(let e of this._extensions){for(let[t,n]of Object.entries(e.methodKinds))this._kinds.set(t,n);for(let[t,n]of Object.entries(e.handlers)){let e=n;this[t]=(...n)=>(this._guard(t),e(...n))}}}export(e,t){if(this._exported.has(e))return;let n=buildDevtoolsIfaceXml(this._extensions.flatMap(e=>e.methodsXml??[])),r=x.DBusExportedObject.wrapJSObject(n,this);r.export(e,t),this._exported.set(e,r)}unexport(e){if(e){this._exported.get(e)?.unexport(),this._exported.delete(e);return}for(let e of this._exported.values())e.unexport();this._exported.clear(),this._peer?.stop(),this._peer=null,this._addressFile&&=(removeDevtoolsAddressFile(this._addressFile),null)}attachPeerServer(e,t){this._peer=e,this._addressFile=t??null}get peerAddress(){return this._peer?.address??null}get addressFile(){return this._addressFile}GetStatus(){let e=this._app.get_active_window(),t={appId:this._app.get_application_id()??`unknown`,instance:this._options.instance??`default`,activeWindow:e?{id:e.get_name()||`window`,title:e.get_title()??``,mapped:e.get_mapped()}:null,toplevelCount:h.Window.get_toplevels().get_n_items(),focusedWidget:null,paused:this._isPaused()};for(let e of this._extensions){let n=e.contributeStatus?.();n&&Object.assign(t,n)}return JSON.stringify(t)}async ScreenshotAsync(e,t){try{let n=typeof e?.[0]==`string`?e[0]:``,r=await this._captureScopePng(n);t.return_value(new l.Variant(`(ay)`,[r]))}catch(e){t.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e){let t=this._resolveRootWidget(e);if(!t){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let n=captureWidget(t.widget);if(n.png)return n.png;let r=t.widget.get_root();r instanceof h.Window&&r.present();let i=await captureWidgetWhenRenderable(t.widget);return i.png?i.png:(console.warn(`[devtools] Screenshot('${e}') has no image: ${i.blocker??`unknown`} after 12 tries. Empty bytes follow.`),new Uint8Array)}ListActions(){let e={app:describeActions(this._actionGroup(`app`)),win:describeActions(this._actionGroup(`win`))};return JSON.stringify(e)}ActivateAction(e,t,n){this._guard(`ActivateAction`);let r=this._scope(e);activateAction(this._requireGroup(r,t),t,this._parseValue(n))}ChangeActionState(e,t,n){this._guard(`ChangeActionState`);let r=this._scope(e);changeActionState(this._requireGroup(r,t),t,this._parseValue(n))}PresentWindow(){this._app.get_active_window()?.present()}ResizeWindow(e,t){this._guard(`ResizeWindow`);let n=this._app.get_active_window();if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no active window to resize`));let r=Math.max(1,Math.round(e)),i=Math.max(1,Math.round(t));return n.is_maximized()&&n.unmaximize(),n.is_fullscreen()&&n.unfullscreen(),n.set_default_size(r,i),[r,i]}ListToplevels(){return JSON.stringify(listToplevels())}DumpTree(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e||`active window`}'`));return JSON.stringify(dumpTree(n.widget,t>0?t:40,n.path))}GetProperty(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));let r=getWidgetProperty(n.widget,t);if(r===void 0)throw Error(formatDbusErrorMessage(`not-found`,`widget has no property '${t}'`));return JSON.stringify(r)}GetFocused(){let e=this._app.get_active_window(),t=e?e.get_focus():null;return JSON.stringify(t?{path:pathOfWidget(t),name:t.get_name()||null,type:widgetType(t)}:null)}ActivateWidget(e){this._guard(`ActivateWidget`);let t=this._resolveRootWidget(e);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));return activateWidget(t.widget)}FindWidget(e){let t=parseWidgetSelector(e);if(!t)throw Error(formatDbusErrorMessage(`invalid-params`,`empty selector '${e}'`));let n=this._resolveRootWidget(``);return n?findWidgetPath(n.widget,t,n.path)??``:``}SendKey(e,t){this._guard(`SendKey`);let[n,r,i]=h.accelerator_parse(e);if(!n)throw Error(formatDbusErrorMessage(`invalid-params`,`cannot parse accelerator '${e}'`));let a;if(a=t?this._resolveRootWidget(t)?.widget??null:this._app.get_active_window()?.get_focus()??null,!a)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${t||`focus`}'`));return sendKeyToWidget(a,r,i??0)}DumpGSettings(e){return JSON.stringify(dumpGSettings(e))}DumpCss(){return JSON.stringify(dumpCss())}SwapCss(e,t){return this._guard(`SwapCss`),swapCss(e,t)}_resolveRootWidget(e){if(isActiveWindowScope(e)){let e=this._app.get_active_window();return e?{widget:e,path:pathOfWidget(e)??`toplevel:0`}:null}let t=resolveWidgetPath(e);return t?{widget:t,path:e}:null}_isPaused(){return this._options.paused?.()??!1}_guard(e){let t=this._kinds.get(e);if(!t)throw Error(formatDbusErrorMessage(`internal`,`unclassified devtools method '${e}'`));if(t===`mutating`&&this._isPaused())throw Error(formatDbusErrorMessage(`paused`,`${e} rejected — external control is paused. Read-only methods keep working.`))}_scope(e){return e===`app`?`app`:`win`}_actionGroup(e){if(e===`app`)return this._app;if(this._options.winActionGroup)return this._options.winActionGroup;let t=this._app.get_active_window();return t instanceof h.ApplicationWindow?t:null}_requireGroup(e,t){let n=this._actionGroup(e);if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no '${e}' action group`));if(!n.has_action(t))throw Error(formatDbusErrorMessage(`not-found`,`unknown action ${e}.${t}`));return n}_parseValue(e){if(!e||e===`null`)return null;try{return JSON.parse(e)}catch{throw Error(formatDbusErrorMessage(`invalid-params`,`value_json is not valid JSON: ${e}`))}}};const C=`DBUS_SESSION_BUS_ADDRESS`,oe=new Set;function envEnabled(){return isDevtoolsEnabledValue(l.getenv(`GJSIFY_DEVTOOLS`))}function envValue(e){let t=l.getenv(e);return t&&t!==``?t:null}function sessionBusUsable(){if(!envValue(C))return!1;try{return x.bus_get_sync(x.BusType.SESSION,null),!0}catch{return!1}}function chooseDevtoolsTransport(e){return e.requestedAddress?{kind:`peer`,address:e.requestedAddress,reason:`requested`}:e.hasAppConnection?{kind:`session-bus`}:e.sessionBusUsable?{kind:`unregistered`}:{kind:`peer`,address:null,reason:`no-session-bus`}}function describeMissingConnection(e,t){return e?t?`[gjsify-devtools] the session bus answers but this application is not registered on it yet — call installDevtools() from the GtkApplication "startup" handler (the bus connection and object path exist only after registration).`:`[gjsify-devtools] ${C} is set (${e}) but no bus answers there — using the bus-less peer transport instead. On macOS this is the usual state: Homebrew's dbus listens on launchd, so the advertised address only works while that socket is live.`:`[gjsify-devtools] this machine has no session bus (${C} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${y} on both the app and \`gjsify debug\` to pin it yourself.`}function installDevtools(e,t={}){if(!(t.enabled??envEnabled()))return null;let n=t.instance??envValue(`GJSIFY_DEVTOOLS_INSTANCE`)??void 0,r=new DevtoolsService(e,{...t,instance:n});try{return exportDevtools(e,r,t,n)}catch(e){return r.unexport(),console.error(`[gjsify-devtools] devtools stayed OFF, the app is unaffected — ${describeInstallFailure(e)}`),null}}function describeInstallFailure(e){return e instanceof DevtoolsPeerServerError||e instanceof Error?e.message:String(e)}function exportDevtools(e,t,n,r){let i=e.get_is_registered(),a=i?e.get_dbus_connection():null,o=i?e.get_dbus_object_path():null,s=envValue(C),c=!!(a&&o),u=c||sessionBusUsable(),d=chooseDevtoolsTransport({requestedAddress:n.address??envValue(y),hasAppConnection:c,sessionBusUsable:u}),f=e.get_application_id()??`unknown`,p=`${o??appIdToObjectPath(f)}/devtools`;if((d.kind===`unregistered`||d.kind===`peer`&&d.reason===`no-session-bus`)&&console.error(describeMissingConnection(s,u)),d.kind===`session-bus`&&a)t.export(a,p),console.log(`[gjsify-devtools] exported ${_} at ${p} (dest ${f})`);else if(d.kind===`peer`){let n=startDevtoolsPeerServer(t,p,d.address??void 0),i=writeDevtoolsAddressFile(devtoolsAddressFilePath(l.get_user_runtime_dir(),f,r),n.address);t.attachPeerServer(n,i),console.log(`[gjsify-devtools] exported ${_} at ${p} (peer address ${n.address}${i?`, published to ${i}`:``})`),i&&e.connect(`shutdown`,()=>removeDevtoolsAddressFile(i))}return oe.add(t),t}const se=`&(?![a-zA-Z][a-zA-Z0-9]*;|#\\d+;|#x[0-9a-fA-F]+;)|<(?![a-zA-Z/!?])`;RegExp(se),RegExp(se,`g`);const ce=[`AdwNavigationSplitView`,`GtkListBox`,`AdwOverlaySplitView`];function probeEnabled(){let e=l.getenv(`GJSIFY_STORYBOOK_PROBE`);if(e==null)return!1;let t=e.toLowerCase();return t!==``&&t!==`0`&&t!==`false`}const le=5e3;function exitIfNotDrained(){if(typeof process>`u`||typeof process.exit!=`function`)return;let e=setTimeout(()=>{console.error(`STORYBOOK PROBE: host still alive ${le}ms after quit(), exiting`),process.exit(process.exitCode??0)},le);typeof e==`object`&&typeof e.unref==`function`&&e.unref()}function collectTypes(e,t){t.add(e.type);for(let n of e.children)collectTypes(n,t)}function installStorybookProbe(e,t,n={}){let r=n.requireChrome??ce,i=n.out??l.getenv(`GJSIFY_STORYBOOK_PROBE_OUT`)??void 0,a=n.timeoutMs??8e3,o=n.storyWidget??l.getenv(`GJSIFY_STORYBOOK_PROBE_STORY_WIDGET`)??void 0,s=t.controller.listStories(),c=[...new Set(s.map(e=>e.category))],u=n.story??l.getenv(`GJSIFY_STORYBOOK_PROBE_STORY`)??s[0]?.title,d=u?t.openStoryByTitle(u):!1,f=t.activeStory,p=new Set;collectTypes(dumpTree(t,60,`toplevel:0`),p);let m=r.filter(e=>!p.has(e)),h=new Set;f&&collectTypes(dumpTree(f,60,`story`),h);let g=h.size,_=o?h.has(o):null,finish=t=>{let n=JSON.stringify(t);if(t.ok)console.log(`STORYBOOK PROBE: PASS ${n}`);else{console.error(`STORYBOOK PROBE: FAIL ${n}`);try{typeof process<`u`&&(process.exitCode=1)}catch{}}if(i)try{l.file_set_contents(i,JSON.stringify(t,null,2))}catch{}e.quit(),exitIfNotDrained()},v=0;l.timeout_add(l.PRIORITY_DEFAULT,100,()=>{v+=100;let e=captureWidgetPng(t),n=t.get_width()>0&&t.get_height()>0;if(!e&&!(v>=a))return l.SOURCE_CONTINUE;let i=f?captureWidgetPng(f):null,p=s.length>=1&&c.length>=1&&m.length===0&&d&&f!=null&&g>1,y;return s.length<1?y=`no stories registered`:c.length<1?y=`no categories`:m.length>0?y=`chrome missing: ${m.join(`, `)}`:!d||f==null?y=`could not open story: ${u??`(none)`}`:g<=1&&(y=`opened story rendered an empty subtree`),p&&o&&!h.has(o)&&(p=!1,y=`story widget ${o} not found in the opened story subtree`),p&&n&&(!e||e.length===0)&&(p=!1,y=`window realized (${t.get_width()}x${t.get_height()}) but the GSK capture was empty`),finish({ok:p,reason:y,stories:s.length,categories:c,opened:d,activeStory:f?f.meta.title:null,requiredChrome:r,missingChrome:m,storySubtreeWidgets:g,storyWidgetPresent:_,windowRealized:n,windowPngBytes:e?e.length:0,storyPngBytes:i?i.length:0}),l.SOURCE_REMOVE})}const ue=e(import.meta.url);let de;function load$1(){return de===void 0&&(de=ue(`@gjsify/node-gi/gi`).requireGi(`Adw`,`1`)),de}__name(load$1,`load`);var w=new Proxy(Object.create(null),{get(e,t){return load$1()[t]},has(e,t){return t in load$1()}});const fe={UNKNOWN:0,CUSTOM:1,GPL_2_0:2,GPL_3_0:3,LGPL_2_1:4,LGPL_3_0:5,BSD:6,MIT_X11:7,ARTISTIC:8,GPL_2_0_ONLY:9,GPL_3_0_ONLY:10,LGPL_2_1_ONLY:11,LGPL_3_0_ONLY:12,AGPL_3_0:13,AGPL_3_0_ONLY:14,BSD_3:15,APACHE_2_0:16,MPL_2_0:17,"0BSD":18};fe.GPL_2_0_ONLY,fe.GPL_3_0_ONLY,fe.UNKNOWN;const pe=[`blue`,`teal`,`green`,`yellow`,`orange`,`red`,`pink`,`purple`,`slate`],me={blue:`#3584e4`,teal:`#2190a4`,green:`#3a944a`,yellow:`#c88800`,orange:`#ed5b00`,red:`#e62d42`,pink:`#d56199`,purple:`#9141ac`,slate:`#6f8396`};function parseHex(e){let t=/^#([0-9a-f]{6})$/i.exec(e.trim());if(!t)return null;let n=Number.parseInt(t[1],16);return[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255]}function toHex(e,t,n){let channel=e=>Math.round(Math.min(1,Math.max(0,e))*255).toString(16).padStart(2,`0`);return`#${channel(e)}${channel(t)}${channel(n)}`}const toLinear=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,fromLinear=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function linearToOklab(e,t,n){let r=Math.cbrt(.4122214708*e+.5363325363*t+.0514459929*n),i=Math.cbrt(.2119034982*e+.6806995451*t+.1073969566*n),a=Math.cbrt(.0883024619*e+.2817188376*t+.6299787005*n);return[.2104542553*r+.793617785*i-.0040720468*a,1.9779984951*r-2.428592205*i+.4505937099*a,.0259040371*r+.7827717662*i-.808675766*a]}function oklabToLinear(e,t,n){let r=(e+.3963377774*t+.2158037573*n)**3,i=(e-.1055613458*t-.0638541728*n)**3,a=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*i+.2309699292*a,-1.2684380046*r+2.6097574011*i-.3413193965*a,-.0041960863*r-.7034186147*i+1.707614701*a]}function adwaitaStandaloneColor(e,t){let n=parseHex(e);if(!n)return e;let[r,i,a]=linearToOklab(toLinear(n[0]),toLinear(n[1]),toLinear(n[2])),[o,s,c]=oklabToLinear(t?Math.max(r,.85):Math.min(r,.5),i,a);return toHex(fromLinear(o),fromLinear(s),fromLinear(c))}function adwaitaAccentBgColor(e){return me[e]}function adwaitaAccentColor(e,t){return adwaitaStandaloneColor(me[e],t)}var UnsupportedGObjectError=class extends Error{constructor(e,t){super(t),this.name=`UnsupportedGObjectError`,this.feature=e}};const he=new WeakSet;function makeType(e){let t=Object.freeze({name:e});return he.add(t),t}makeType(`gchararray`),makeType(`gboolean`),makeType(`gint`),makeType(`guint`),makeType(`gdouble`);const T={READABLE:1,WRITABLE:2,READWRITE:3,CONSTRUCT:4,CONSTRUCT_ONLY:8};var E=class ParamSpec{constructor(e,t,n,r,i,a,o,s){this.kind=e,this.name=t,this.nick=n,this.blurb=r,this.flags=i,this.defaultValue=a,this.minimum=o,this.maximum=s}static boolean(e,t,n,r,i){return new ParamSpec(`boolean`,e,t,n,r,i)}static string(e,t,n,r,i){return new ParamSpec(`string`,e,t,n,r,i)}static int(e,t,n,r,i,a,o){return new ParamSpec(`int`,e,t,n,r,o,i,a)}static uint(e,t,n,r,i,a,o){return new ParamSpec(`uint`,e,t,n,r,o,i,a)}static double(e,t,n,r,i,a,o){return new ParamSpec(`double`,e,t,n,r,o,i,a)}get_default_value(){return this.defaultValue}};const D={GTypeName:Symbol(`GType name`),GTypeFlags:Symbol(`GType flags`),interfaces:Symbol(`GType interfaces`),properties:Symbol(`GObject properties`),signals:Symbol(`GObject signals`),requires:Symbol(`GObject interface requires`),template:Symbol(`GTK widget template`),cssName:Symbol(`GTK widget CSS name`),children:Symbol(`GTK widget template children`),internalChildren:Symbol(`GTK widget template internal children`)};D.GTypeName,D.template,D.internalChildren,D.properties,D.signals,D.cssName,D.children,D.interfaces,D.requires,D.GTypeFlags;const ge=new WeakMap;function chainOf(e){let t=[];for(let n=e;typeof n==`function`;n=Object.getPrototypeOf(n)){let e=ge.get(n);e&&t.push(e)}return t}function chainOfInstance(e){return chainOf(e.constructor)}function typeNameOf(e,t){return t[0]?.typeName??e.constructor.name}function aliasesOf(e){return[e,e.replace(/-/g,`_`),e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())]}function findProperty(e,t){for(let n of e)for(let e of n.properties)if(aliasesOf(e.name).includes(t))return e}function findSignal(e,t){for(let n of e)if(Object.prototype.hasOwnProperty.call(n.signals,t))return n.signals[t]}const _e=new WeakMap;let ve=0;function stateOf$1(e){let t=_e.get(e);return t||(t={values:new Map,handlers:new Map,connections:new Map,emissions:[]},_e.set(e,t)),t}__name(stateOf$1,`stateOf`);function parseSignal(e){let t=e.indexOf(`::`);return t===-1?{name:e}:{name:e.slice(0,t),detail:e.slice(t+2)}}function addHandler(e,t,n){let r=stateOf$1(e),i=++ve,a=r.handlers.get(t)??[];return a.push({id:i,handler:n}),r.handlers.set(t,a),r.connections.set(i,()=>{a.splice(a.findIndex(e=>e.id===i),1)}),i}function runHandlers(e,t,n){let r=stateOf$1(e),i={key:t,stopped:!1};r.emissions.push(i);try{for(let{id:a,handler:o}of(r.handlers.get(t)??[]).slice()){if(i.stopped)break;r.connections.has(a)&&o(e,...n)}}finally{r.emissions.pop()}}function connectInstance(e,t,n){let r=chainOfInstance(e),i=typeNameOf(e,r),{name:a,detail:o}=parseSignal(t),foreign=()=>{let a=r[0]?.door;if(!a)throw Error(`No signal '${t}' on object '${i}'`);let o=++ve,s=a.listen(e,t,n);return stateOf$1(e).connections.set(o,s),o};if(a===`notify`){if(o===void 0)throw new UnsupportedGObjectError(`connect("notify")`,`connect('notify') without a property is outside the GObject subset; connect 'notify::<property>' on '${i}'.`);let t=findProperty(r,o);return t?addHandler(e,`notify::${t.name}`,n):foreign()}if(findSignal(r,a)){if(o!==void 0)throw Error(`Signal '${a}' on object '${i}' has no detail`);return addHandler(e,a,n)}return foreign()}function disconnectInstance(e,t){let n=stateOf$1(e),r=n.connections.get(t);if(!r)throw Error(`No handler with id ${t} is connected to ${String(e)}`);n.connections.delete(t),r()}function emitInstance(e,t,...n){let r=chainOfInstance(e),i=typeNameOf(e,r),a=findSignal(r,t);if(a){if(n.length!==a.length)throw Error(`Signal '${t}' on ${i} requires ${a.length} args got ${n.length}`);runHandlers(e,t,n);return}let o=r[0]?.door;if(!o)throw Error(`No signal '${t}' on object '${i}'`);o.dispatch(e,t,n)}function notifyInstance(e,t){let n=chainOfInstance(e),r=findProperty(n,t);if(r){runHandlers(e,`notify::${r.name}`,[r]);return}let i=n[0]?.door;if(!i)throw Error(`No property ${t} on ${typeNameOf(e,n)}`);i.dispatch(e,`notify::${t}`,[])}function generateAccessors(e,t){let{name:n,flags:r}=e,i=r&T.READABLE,a=r&T.WRITABLE,o=t??{configurable:!0,enumerable:!0};return i&&a?!o.get&&!o.set?(o.get=function(){let{values:t}=stateOf$1(this);return t.has(n)||t.set(n,e.get_default_value()),t.get(n)},o.set=function(e){let{values:t}=stateOf$1(this);e!==t.get(n)&&(t.set(n,e),this.notify(n))}):o.get?o.set||=function(){throw Error(`getter defined without setter for property ${n}`)}:o.get=function(){throw Error(`setter defined without getter for property ${n}`)}:i&&!o.get?o.get=function(){throw Error(`missing getter for read-only property ${n}`)}:a&&!o.set&&(o.set=function(){throw Error(`missing setter for write-only property ${n}`)}),o}function checkAccessors(e,t){let{name:n,flags:r}=t;if(r&T.CONSTRUCT_ONLY)return;let[,i,a]=aliasesOf(n),own=t=>Object.getOwnPropertyDescriptor(e,t),o=own(n),s=o,c=n.includes(`-`),l,u;c&&(l=own(i),u=own(a),o??=l,o??=u);let d=r&T.READABLE,f=r&T.WRITABLE;(!o||d&&!o.get||f&&!o.set)&&(o=generateAccessors(t,o)),s||Object.defineProperty(e,n,o),c&&(l||Object.defineProperty(e,i,o),u||Object.defineProperty(e,a,o))}function defineConstructOnly(e,t,n){let{values:r}=stateOf$1(e);r.set(t.name,n);for(let n of new Set(aliasesOf(t.name)))Object.defineProperty(e,n,{get:()=>r.get(t.name),enumerable:!0,configurable:!0})}function bindProperties(e,t,n,r,i=[]){let a=i.includes(`invert-boolean`),o=!1,transfer=(e,t,n,r)=>()=>{if(!o){o=!0;try{let i=e[t];n[r]=a?!i:i}finally{o=!1}}},s=transfer(e,t,n,r),c=[[e,e.connect(`notify::${t}`,s)]];if(i.includes(`bidirectional`)){let i=transfer(n,r,e,t);c.push([n,n.connect(`notify::${r}`,i)])}return i.includes(`sync-create`)&&s(),{unbind(){for(let[e,t]of c.splice(0))e.disconnect(t)}}}function createClosure(e,t,n,r){let i=r??e;if(n)throw new UnsupportedGObjectError(`swapped`,`Unsupported template signal flag "swapped"`);let a=e[t];if(a===void 0)throw Error(`A handler called ${t} was not defined on ${String(e)}`);return a.bind(i)}function scopeOf(e){return{instance:e,handler:(t,n)=>createClosure(e,t,n?.flags?.includes(`swapped`)??!1,n?.object),bind:bindProperties}}function constructRegistered(e,t={}){let n=chainOfInstance(e),r={},i=new Map;for(let[e,a]of Object.entries(t)){let t=findProperty(n,e);t?i.set(t,a):r[e]=a}let a=[];for(let t of[...n].reverse())t.template&&a.push([t,t.door.createFromTree(t.template,scopeOf(e),e)]);for(let t of n)for(let n of t.properties)n.flags&T.CONSTRUCT_ONLY&&defineConstructOnly(e,n,i.has(n)?i.get(n):n.get_default_value());for(let[t,n]of i)t.flags&T.CONSTRUCT_ONLY||(e[t.name]=n);for(let[t,n]of a){for(let r of t.internalChildren){let i=n.objects[r];if(i===void 0)throw Error(`Template of ${t.typeName} has no child object '${r}' for InternalChildren`);e[`_${r.replace(/-/g,`_`)}`]=i}t.door.attach(e,n)}return r}const ye=Symbol(`GIR type`);function registerBaseClass(e,t,n,r=[]){let missing=e=>{throw Error(`No signal '${e}' on object '${t}'`)},i=makeType(t);Object.defineProperty(e,"$gtype",{get:()=>i,enumerable:!1,configurable:!1});for(let t of r)checkAccessors(e.prototype,t);ge.set(e,{klass:e,typeName:t,gtype:i,properties:r,signals:n,internalChildren:[],door:{name:t,dispatch:(e,t)=>missing(t),listen:(e,t)=>missing(t),createFromTree:()=>missing(`template`),attach(){},register(){}}})}var GObjectObject=class{constructor(e){let t=constructRegistered(this,e),n=Object.keys(t)[0];if(n!==void 0)throw Error(`No property ${n} on ${typeNameOf(this,chainOfInstance(this))}`)}notify(e){notifyInstance(this,e)}connect(e,t){return connectInstance(this,e,t)}disconnect(e){disconnectInstance(this,e)}emit(e,...t){emitInstance(this,e,...t)}};function refuse$1(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}__name(refuse$1,`refuse`);var ActionRegistry=class{constructor(){this._actions=new Map}add(e){this._actions.set(e.name,e)}remove(e){this._actions.delete(e)}lookup_action(e){return this._actions.get(e)??null}has(e){return this._actions.has(e)}list(){return[...this._actions.keys()]}};const be=new WeakMap;function actionRegistryOf(e,t=!0){let n=be.get(e);return n===void 0&&t&&(n=new ActionRegistry,be.set(e,n)),n}function requireAction(e){let t=e;if(typeof t?.name!=`string`||typeof t.activate!=`function`)throw TypeError(`add_action: needs a Gio.Action (a Gio.SimpleAction)`);return t}const xe={add_action(e){actionRegistryOf(this).add(requireAction(e))},lookup_action(e){return actionRegistryOf(this,!1)?.lookup_action(e)??null},remove_action(e){actionRegistryOf(this,!1)?.remove(e)}},Se={has_action(e){return actionRegistryOf(this,!1)?.has(e)??!1},list_actions(){return actionRegistryOf(this,!1)?.list()??[]},activate_action(e,t=null){if(t!==null)throw refuse$1(`activate_action with a parameter`,`needs a GLib.Variant`);actionRegistryOf(this,!1)?.lookup_action(e)?.activate(null)},get_action_enabled(e){return actionRegistryOf(this,!1)?.lookup_action(e)?.enabled??!1}};function installActionMap(e,t=!1){let n=t?{...xe,...Se}:{...xe};for(let[t,r]of Object.entries(n))Object.defineProperty(e,t,{value:r,writable:!0,configurable:!0,enumerable:!1})}const Ce=new WeakMap;function linkWindow(e,t){t===null?Ce.delete(e):Ce.set(e,t)}const we={NONE:0,FLAGS_NONE:0,DEFAULT_FLAGS:0,IS_SERVICE:1,IS_LAUNCHER:2,HANDLES_OPEN:4,HANDLES_COMMAND_LINE:8,SEND_ENVIRONMENT:16,NON_UNIQUE:32,CAN_OVERRIDE_APP_ID:64,ALLOW_REPLACEMENT:128,REPLACE:256};function isValidApplicationId(e){if(typeof e!=`string`||e.length>255||e===``)return!1;let t=e.split(`.`);return t.length>=2&&t.every(e=>/^[A-Za-z_-][A-Za-z0-9_-]*$/.test(e))}function refuse(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}const Te=`register.hold.release.mark_busy.unmark_busy.open.set_inactivity_timeout.send_notification.withdraw_notification.register_session.set_option_context_parameter_string.set_option_context_summary.set_option_context_description.add_main_option.add_main_option_entries.add_option_group.set_resource_base_path.get_resource_base_path.set_flags.get_is_remote.get_is_registered.get_dbus_connection.get_dbus_object_path.bind_busy_property.add_action_entries.set_default`.split(`.`),Ee=[`is_remote`,`is_registered`,`is_busy`,`resource_base_path`,`inactivity_timeout`,`action_group`],De=[`open`,`command-line`,`handle-local-options`,`shutdown`,`name-lost`],Oe=[`set_accels_for_action`,`get_accels_for_action`,`list_action_descriptions`,`get_actions_for_accel`,`set_menubar`,`get_menubar`,`get_menu_by_id`,`set_app_menu`,`get_app_menu`,`get_menu_by_id`,`inhibit`,`uninhibit`],ke=new WeakMap;let Ae=null;function rememberDefault(e){Ae??=e}function stateOf(e){let t=ke.get(e);return t===void 0&&(t={id:null,windows:[],running:!1,resolve:()=>{}},ke.set(e,t)),t}function hostOf(e){let t=e.constructor.host;if(t===void 0)throw Error(`Gio.Application: this class has no ApplicationHost; use the Gtk.Application of a port.`);return t}var GioApplicationBase=class extends GObjectObject{static{this[ye]=`Gio.Application`}static id_is_valid(e){return isValidApplicationId(e)}static get_default(){return Ae}constructor(e){super(e),rememberDefault(this)}get application_id(){return stateOf(this).id}set application_id(e){let t=e??null;if(t!==null&&!isValidApplicationId(t))throw Error(`Gio.Application: '${String(t)}' is not a valid application id (g_application_id_is_valid)`);let n=stateOf(this);if(n.running)throw Error(`Gio.Application: the application id cannot change while it runs`);n.id!==t&&(n.id=t,this.notify(`application-id`))}get flags(){return 0}set flags(e){if(e!==void 0&&e!==we.NONE)throw refuse(`Gio.ApplicationFlags value ${String(e)}`,`is a flag other than the default`)}get_application_id(){return this.application_id}set_application_id(e){this.application_id=e}get_flags(){return 0}vfunc_startup(){}vfunc_activate(){}run(){throw refuse(`Gio.Application.run()`,`blocks, and a page cannot; use runAsync()`)}connect(e,t){let n=e.split(`::`)[0]??e;if(De.includes(n))throw refuse(`the '${n}' signal`,`is not emitted`);return super.connect(e,t)}async runAsync(e=[]){let t=stateOf(this);if(t.running)throw Error(`Gio.Application.runAsync(): the application is already running`);let n=hostOf(this);t.running=!0;let r=new Promise(e=>{t.resolve=e}),i,a=!1,body=()=>{try{if(this.vfunc_startup(),this.emit(`startup`),this.emit(`activate`),this.vfunc_activate(),t.running&&t.windows.length===0&&n.requiresWindow)throw Error(`Gio.Application.runAsync(): activate added no window on ${n.name}; a window must be added synchronously by activate (ADR 0098 § 3).`)}catch(e){i=e,a=!0}return t.windows[0]??null};try{await n.start(body)}catch(e){i=e,a=!0}if(a)throw t.running=!1,n.exit(),i;return t.windows.length===0&&this._finish(0),r}quit(){let e=stateOf(this);if(e.running){for(let t of e.windows.splice(0))linkWindow(t,null),hostOf(this).detach(t);this._finish(0)}}_finish(e){let t=stateOf(this);t.running&&(t.running=!1,t.resolve(e),hostOf(this).exit())}};registerBaseClass(GioApplicationBase,`GApplication`,{startup:[],activate:[]},[E.string(`application-id`,``,``,T.READWRITE|T.CONSTRUCT,null),E.uint(`flags`,``,``,T.READWRITE|T.CONSTRUCT,0,4294967295,0)]),installActionMap(GioApplicationBase.prototype,!0);function refuseMembers(e,t,n){for(let n of t)Object.defineProperty(e,n,{value:()=>{throw refuse(`${n}()`,`is not implemented`)},writable:!0,configurable:!0,enumerable:!1});for(let t of n)Object.defineProperty(e,t,{get(){throw refuse(`the '${t}' property`,`is not implemented`)},configurable:!0,enumerable:!1})}refuseMembers(GioApplicationBase.prototype,Te,Ee);function withGtkApplication(e){class GtkApplication extends e{get active_window(){return stateOf(this).windows[0]??null}get_active_window(){return this.active_window}get_windows(){return[...stateOf(this).windows]}add_window(e){let t=stateOf(this);t.windows.includes(e)||(t.windows.unshift(e),linkWindow(e,this))}remove_window(e){let t=stateOf(this),n=t.windows.indexOf(e);n!==-1&&(t.windows.splice(n,1),linkWindow(e,null),t.windows.length===0&&this._finish(0))}}return refuseMembers(GtkApplication.prototype,Oe,[]),GtkApplication}withGtkApplication(GioApplicationBase);var ContentFormats=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}to_string(){return[...this.#e.map(e=>e.name),...this.#t].join(` `)}contain_gtype(e){return this.#e.includes(e)}contain_mime_type(e){return this.#t.includes(e)}};new ContentFormats([],[]),Math.PI*.35,Math.PI*.015,Math.PI*.9;const je=Math.PI*.9,Me=Math.PI*.7,Ne=Math.PI*1.1,Pe=Math.PI*1.35,Fe=je+Ne+Pe-Me;53*Math.PI*2/Fe,Ne-Me/2,new Set(`ADC.AND.ASL.BCC.BCS.BEQ.BIT.BMI.BNE.BPL.BRK.BVC.BVS.CLC.CLD.CLI.CLV.CMP.CPX.CPY.DEC.DEX.DEY.EOR.INC.INX.INY.JMP.JSR.LDA.LDX.LDY.LSR.NOP.ORA.PHA.PHP.PLA.PLP.ROL.ROR.RTI.RTS.SBC.SEC.SED.SEI.STA.STX.STY.TAX.TAY.TSX.TXA.TXS.TYA`.split(`.`));const O=new WeakMap,Ie=new WeakMap;function sourceOf(e){let t=e.constructor.source;if(t===void 0)throw Error(`Adw.StyleManager: this class has no StyleSource; use the Adw.StyleManager of a port.`);return t}var StyleManagerBase=class extends GObjectObject{static{this[ye]=`Adw.StyleManager`}static get_default(){let e=Ie.get(this);if(e===void 0){e=new this,Ie.set(this,e);let t=sourceOf(e);O.set(e,t.dark()),t.subscribe(()=>{let n=t.dark();O.get(e)!==n&&(O.set(e,n),e.notify(`dark`))})}return e}get dark(){return sourceOf(this).dark()}get_dark(){return this.dark}};registerBaseClass(StyleManagerBase,`AdwStyleManager`,{},[E.boolean(`dark`,``,``,T.READABLE,!1)]);const Le={system:`Follow system`,light:`Light`,dark:`Dark`},Re={blue:`Blue`,teal:`Teal`,green:`Green`,yellow:`Yellow`,orange:`Orange`,red:`Red`,pink:`Pink`,purple:`Purple`,slate:`Slate`};var StorybookAppearance=class{constructor(){this._provider=null,this._applying=!1,this._styleManager=w.StyleManager.get_default(),this.settings=new StorybookSettings(()=>this._styleManager.get_dark()),this.settings.subscribe(e=>this._apply(e)),this._styleManager.connect(`notify::dark`,()=>this.settings.systemChanged()),this._apply(this.settings.state)}_apply(e){if(!this._applying){this._applying=!0;try{this._styleManager.set_color_scheme(e.colorScheme===`light`?w.ColorScheme.FORCE_LIGHT:e.colorScheme===`dark`?w.ColorScheme.FORCE_DARK:w.ColorScheme.DEFAULT),this._applyAccent(this.settings.resolvedAccent)}finally{this._applying=!1}}}_applyAccent(e){let t=f.Display.get_default();if(!t)return;if(!this._provider){if(!e)return;this._provider=new h.CssProvider,h.StyleContext.add_provider_for_display(t,this._provider,h.STYLE_PROVIDER_PRIORITY_APPLICATION)}if(!e){this._provider.load_from_string(``);return}let n=adwaitaAccentBgColor(e),r=adwaitaAccentColor(e,this.settings.resolvedDark);this._provider.load_from_string(`:root { --accent-bg-color: ${n}; --accent-color: ${r}; }`)}};function buildSwatch(e,t,n){let r=new h.CheckButton({tooltip_text:t,halign:h.Align.CENTER,valign:h.Align.CENTER,focus_on_click:!1});for(let t of e)r.add_css_class(t);return r.update_property([h.AccessibleProperty.LABEL],[t]),n&&r.set_group(n),r}function buildSwatchCard(e=!1){let t=new w.WrapBox({align:.5,child_spacing:8,line_spacing:8,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),n=new w.Bin({child:t,hexpand:!0});return n.add_css_class(`card`),e&&n.add_css_class(`storybook-card-attached`),{card:n,row:t}}function buildAppearanceDialog(e){let t=e.settings,n=new w.PreferencesPage,r=new w.PreferencesGroup({title:`Style`}),{card:i,row:o}=buildSwatchCard(),s=null,c=new Map;for(let e of a){let n=buildSwatch([`storybook-swatch`,`storybook-scheme-swatch`,`storybook-scheme-${e}`],Le[e],s);s??=n,n.set_active(t.colorScheme===e),n.connect(`toggled`,()=>{n.get_active()&&(t.colorScheme=e)}),c.set(e,n),o.append(n)}r.add(i),n.add(r);let l=new w.PreferencesGroup({title:`Accent colour`});l.add_css_class(`storybook-attached-group`);let u=new w.SwitchRow({title:`Use a custom accent colour`,subtitle:`Off follows the desktop, which owns the accent`,active:t.accentMode===`custom`});l.add(u);let{card:d,row:f}=buildSwatchCard(!0),p=null,m=new Map;for(let e of pe){let n=buildSwatch([`storybook-swatch`],Re[e],p);p??=n,n.set_active(t.accent===e);let r=new h.CssProvider;r.load_from_string(`checkbutton { background-color: ${adwaitaAccentBgColor(e)}; }`),n.get_style_context().add_provider(r,h.STYLE_PROVIDER_PRIORITY_APPLICATION),n.connect(`toggled`,()=>{n.get_active()&&(t.accent=e)}),m.set(e,n),f.append(n)}f.set_sensitive(t.accentMode===`custom`),u.connect(`notify::active`,()=>{t.accentMode=u.get_active()?`custom`:`system`}),l.add(d),n.add(l),t.subscribe(e=>{let t=c.get(e.colorScheme);t&&!t.get_active()&&t.set_active(!0);let n=m.get(e.accent);n&&!n.get_active()&&n.set_active(!0);let r=e.accentMode===`custom`;u.get_active()!==r&&u.set_active(r),f.set_sensitive(r)});let g=new w.PreferencesDialog({title:`Appearance`});return g.add(n),g}function adwControlWidgetFactory(){return{text(e,t){let n=new w.EntryRow({title:e});t&&n.set_tooltip_text(t);let r=null;return n.connect(`changed`,()=>r?.(n.get_text())),{node:n,get:()=>n.get_text(),set:e=>n.set_text(e),onChange:e=>{r=e}}},boolean(e,t){let n=new w.SwitchRow({title:e,subtitle:t??``}),r=null;return n.connect(`notify::active`,()=>r?.(n.get_active())),{node:n,get:()=>n.get_active(),set:e=>n.set_active(e),onChange:e=>{r=e}}},number(e){let t=w.SpinRow.new_with_range(e.min??0,e.max??100,e.step??1);t.set_title(e.label||e.name),e.description&&t.set_subtitle(e.description);let n=null;return t.connect(`changed`,()=>n?.(t.get_value())),{node:t,get:()=>t.get_value(),set:e=>t.set_value(e),onChange:e=>{n=e}}},range(e){return buildRangeWidget(e)},select(e){return buildSelectWidget(e)},color(e,t){return buildColorWidget(e,t)}}}function buildRangeWidget(e){let t=e.min??0,n=e.max??100,r=e.step??1,i=typeof e.min==`number`?e.min:0,a=Number.isInteger(r)&&Number.isInteger(i),o=new h.Adjustment({lower:t,upper:n,step_increment:r,value:i});o.step_increment=r;let s=new h.ListBoxRow({selectable:!1,activatable:!1});s.add_css_class(`story-range-row`);let c=new h.Box({orientation:h.Orientation.VERTICAL,spacing:6,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),l=new h.Box({orientation:h.Orientation.HORIZONTAL,spacing:12}),u=new h.Label({label:e.label||e.name,halign:h.Align.START,hexpand:!0,ellipsize:3});u.add_css_class(`heading`);let formatValue=e=>a?String(Math.round(e)):e.toFixed(2),d=new h.Label({label:formatValue(i),halign:h.Align.END});if(d.add_css_class(`numeric`),d.add_css_class(`dim-label`),l.append(u),l.append(d),c.append(l),e.description){let t=new h.Label({label:e.description,halign:h.Align.START,xalign:0,wrap:!0,max_width_chars:32});t.add_css_class(`caption`),t.add_css_class(`dim-label`),c.append(t)}let f=new h.Scale({orientation:h.Orientation.HORIZONTAL,adjustment:o,draw_value:!1,hexpand:!0}),p=null,m=!1;return f.connect(`value-changed`,()=>{if(m)return;let e=f.get_value();if(a){let t=Math.round(e);if(t!==e){f.set_value(t);return}e=t}d.set_label(formatValue(e)),p?.(e)}),c.append(f),s.set_child(c),{node:s,get:()=>f.get_value(),set:e=>{m=!0,f.set_value(e),m=!1,d.set_label(formatValue(e))},onChange:e=>{p=e}}}function buildSelectWidget(e){let t=e.options??[],n=h.StringList.new(t.map(e=>e.label)),r=new w.ComboRow({title:e.label||e.name,subtitle:e.description??``,model:n}),i=null;return r.connect(`notify::selected`,()=>i?.(r.get_selected())),{node:r,get:()=>r.get_selected(),set:e=>r.set_selected(e),onChange:e=>{i=e}}}function buildColorWidget(e,t){let n=new w.ActionRow({title:e,subtitle:t??``}),r=new h.ColorDialogButton({dialog:new h.ColorDialog({title:e}),valign:h.Align.CENTER});n.add_suffix(r),n.set_activatable_widget(r);let channel=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,`0`),rgbaToHex=e=>`#${channel(e.red)}${channel(e.green)}${channel(e.blue)}`,i=null,a=!1;return r.connect(`notify::rgba`,()=>{a||i?.(rgbaToHex(r.get_rgba()))}),{node:n,get:()=>rgbaToHex(r.get_rgba()),set:e=>{let t=new f.RGBA;t.parse(e)&&(a=!0,r.set_rgba(t),a=!1)},onChange:e=>{i=e}}}var ze=class StorybookWindow extends w.ApplicationWindow{static{S.registerClass({GTypeName:`StorybookWindow`,Template:`<?xml version="1.0" encoding="UTF-8"?>
74
74
  <!--
75
75
  DO NOT EDIT!
76
76
  This file was @generated by blueprint-compiler. Instead, edit the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/example-gtk-adwaita-storybook",
3
- "version": "0.58.0",
3
+ "version": "0.59.0",
4
4
  "description": "Interactive component browser for Libadwaita widgets — a native Adwaita storybook built on @gjsify/storybook, debuggable over DBus/MCP via @gjsify/devtools",
5
5
  "type": "module",
6
6
  "main": "dist/gjs.js",
@@ -54,11 +54,11 @@
54
54
  "@girs/glib-2.0": "5.4.0",
55
55
  "@girs/gobject-2.0": "5.4.0",
56
56
  "@girs/gtk-4.0": "5.4.0",
57
- "@gjsify/adwaita-web": "^0.58.0",
58
- "@gjsify/cli": "^0.58.0",
57
+ "@gjsify/adwaita-web": "^0.59.0",
58
+ "@gjsify/cli": "^0.59.0",
59
59
  "@gjsify/node-gi": "file:../../../packages/node-gi/node-gi",
60
- "@gjsify/storybook": "^0.58.0",
61
- "@gjsify/adwaita-storybook": "^0.58.0",
60
+ "@gjsify/storybook": "^0.59.0",
61
+ "@gjsify/adwaita-storybook": "^0.59.0",
62
62
  "@types/node": "^25.9.2",
63
63
  "typescript": "^6.0.3"
64
64
  },