@gjsify/example-gtk-adwaita-storybook 0.64.0 → 0.64.1-next.241

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
@@ -83,7 +83,7 @@ if(globalThis.__gjsifyBundleUrl??=import.meta.url,Symbol.dispose||(Symbol.dispos
83
83
  </method>${e.length>0?`\n${e.join(`
84
84
  `)}`:``}
85
85
  </interface>
86
- </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 ${U} (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 ${U} (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 ${U} 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 ${U} (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 defaultCaptureScale(e){let t=e.get_scale_factor?.();return typeof t==`number`&&t>0?t:1}function captureWidget(e,t={}){let r=e.get_native()?.get_renderer();if(!r)return{png:null,blocker:`no-renderer`};let o=e.get_width(),s=e.get_height();if(o<=0||s<=0)return{png:null,blocker:`zero-size`};let c=t.scale&&t.scale>0?t.scale:defaultCaptureScale(e),l=n.WidgetPaintable.new(e),u=n.Snapshot.new();c!==1&&u.scale(c,c),l.snapshot(u,o,s);let d=u.to_node();if(!d)return{png:null,blocker:`empty-snapshot`};let f=new i.Rect;f.init(0,0,o*c,s*c);let p=r.render_texture(d,f).save_to_png_bytes().get_data();return p?{png:new Uint8Array(p)}:{png:null,blocker:`empty-png`}}function captureWidgetPng(e,t={}){return captureWidget(e,t).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={},n=12,r=50){let i=null;for(let o=0;o<n;o++){let n=captureWidget(e,t);if(n.png)return{png:n.png,blocker:null};i=n.blocker,await frameDelay(r)}let o=captureWidget(e,t);return{png:o.png,blocker:o.png?null:o.blocker??i}}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(At))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 ScreenshotScaledAsync(t,n){try{let r=typeof t?.[0]==`string`?t[0]:``,i=typeof t?.[1]==`number`?t[1]:0,o=await this._captureScopePng(r,i>0?{scale:i}:{});n.return_value(new e.Variant(`(ay)`,[o]))}catch(e){n.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e,t={}){let r=this._resolveRootWidget(e);if(!r){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let i=captureWidget(r.widget,t);if(i.png)return i.png;let o=r.widget.get_root();o instanceof n.Window&&o.present();let s=await captureWidgetWhenRenderable(r.widget,t);return s.png?s.png:(v.warn(`[devtools] Screenshot('${e}') has no image: ${s.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 jt=`DBUS_SESSION_BUS_ADDRESS`,Mt=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(jt))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] ${jt} 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 (${jt} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${U} 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(jt),u=!!(s&&c),d=u||sessionBusUsable(),f=chooseDevtoolsTransport({requestedAddress:r.address??envValue(U),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 ${kt} 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 ${kt} at ${m} (peer address ${r.address}${o?`, published to ${o}`:``})`),o&&t.connect(`shutdown`,()=>removeDevtoolsAddressFile(o))}return Mt.add(n),n}const Nt=`&(?![a-zA-Z][a-zA-Z0-9]*;|#\\d+;|#x[0-9a-fA-F]+;)|<(?![a-zA-Z/!?])`;RegExp(Nt),RegExp(Nt,`g`);const Pt=[`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 Ft=5e3;function exitIfNotDrained(){if(typeof process>`u`||typeof process.exit!=`function`)return;let e=setTimeout(()=>{v.error(`STORYBOOK PROBE: host still alive ${Ft}ms after quit(), exiting`),process.exit(process.exitCode??0)},Ft);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??Pt,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,ee=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()},te=0;e.timeout_add(e.PRIORITY_DEFAULT,100,()=>{te+=100;let t=captureWidgetPng(n),r=n.get_width()>0&&n.get_height()>0;if(!t&&!(te>=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:ee,windowRealized:r,windowPngBytes:t?t.length:0,storyPngBytes:o?o.length:0}),e.SOURCE_REMOVE})}const It={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};It.GPL_2_0_ONLY,It.GPL_3_0_ONLY,It.UNKNOWN;var UnsupportedGObjectError=class extends Error{constructor(e,t){super(t),this.name=`UnsupportedGObjectError`,this.feature=e}};const Lt=new WeakSet;function makeType(e){let t=Object.freeze({name:e});return Lt.add(t),t}makeType(`gchararray`),makeType(`gboolean`),makeType(`gint`),makeType(`guint`),makeType(`gdouble`);const W={READABLE:1,WRITABLE:2,READWRITE:3,CONSTRUCT:4,CONSTRUCT_ONLY:8};var Rt=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 G={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`)};G.GTypeName,G.template,G.internalChildren,G.properties,G.signals,G.cssName,G.children,G.interfaces,G.requires,G.GTypeFlags;const zt=new WeakMap;function chainOf(e){let t=[];for(let n=e;typeof n==`function`;n=Object.getPrototypeOf(n)){let e=zt.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]}function parseSignal(e){let t=e.indexOf(`::`);return t===-1?{name:e}:{name:e.slice(0,t),detail:e.slice(t+2)}}const Bt=new WeakMap;function stateOf$1(e){let t=Bt.get(e);return t||(t={values:new Map,handlers:new Map,connections:new Map,emissions:[]},Bt.set(e,t)),t}__name(stateOf$1,`stateOf`);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()}}const Vt={name:`pure-js`,register(){},getValue(e,t){let{values:n}=stateOf$1(e);return n.has(t.name)||n.set(t.name,t.get_default_value()),n.get(t.name)},setValue(e,t,n){let{values:r}=stateOf$1(e),i=n!==r.get(t.name);return r.set(t.name,n),i},addHandler(e,t,n,r){let i=stateOf$1(e),o=i.handlers.get(n)??[];o.push({id:t,handler:r}),i.handlers.set(n,o),i.connections.set(t,()=>{o.splice(o.findIndex(e=>e.id===t),1)})},removeHandler(e,t){let n=stateOf$1(e),r=n.connections.get(t);return r?(n.connections.delete(t),r(),!0):!1},emit(e,t,n){runHandlers(e,t,n)},notify(e,t){runHandlers(e,`notify::${t.name}`,[t])},stopEmission(e,t){let{emissions:n}=stateOf$1(e);for(let e=n.length-1;e>=0;e--){let r=n[e];if(r.key===t&&!r.stopped)return r.stopped=!0,!0}return!1},bind(e,t,n,r,i){return bindProperties(e,t,n,r,i)}},Ht=new WeakMap;function engineOf(e){let t=Ht.get(e);return t||(t=chainOfInstance(e)[0]?.engine??Vt,Ht.set(e,t)),t}let Ut=0;const Wt=new WeakMap;function connectInstance(e,t,n){let r=chainOfInstance(e),i=typeNameOf(e,r),{name:o,detail:s}=parseSignal(t),own=t=>{let r=++Ut;return engineOf(e).addHandler(e,r,t,n),r},foreign=()=>{let o=r[0]?.door;if(!o)throw Error(`No signal '${t}' on object '${i}'`);let s=++Ut,c=o.listen(e,t,n),l=Wt.get(e);return l||Wt.set(e,l=new Map),l.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 e=findProperty(r,s);return e?own(`notify::${e.name}`):foreign()}if(findSignal(r,o)){if(s!==void 0)throw Error(`Signal '${o}' on object '${i}' has no detail`);return own(o)}return foreign()}function disconnectInstance(e,t){let n=Wt.get(e)?.get(t);if(n){Wt.get(e).delete(t),n();return}if(!engineOf(e).removeHandler(e,t))throw Error(`No handler with id ${t} is connected to ${String(e)}`)}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}`);engineOf(e).emit(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){engineOf(e).notify(e,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&W.READABLE,o=r&W.WRITABLE,s=t??{configurable:!0,enumerable:!0};return i&&o?!s.get&&!s.set?(s.get=function(){return engineOf(this).getValue(this,e)},s.set=function(t){engineOf(this).setValue(this,e,t)&&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&W.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&W.READABLE,p=r&W.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 r=engineOf(e);r.setValue(e,t,n);for(let n of new Set(aliasesOf(t.name)))Object.defineProperty(e,n,{get:()=>r.getValue(e,t),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){let t=engineOf(e);return{instance:e,handler:(t,n)=>createClosure(e,t,n?.flags?.includes(`swapped`)??!1,n?.object),bind:(e,n,r,i,o)=>t.bind(e,n,r,i,o??[])}}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&W.CONSTRUCT_ONLY&&defineConstructOnly(e,n,i.has(n)?i.get(n):n.get_default_value());for(let[t,n]of i)t.flags&W.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 Gt=Symbol(`GIR type`);function registerBaseClass(e,t,n,r=[],i=Vt){let missing=e=>{throw Error(`No signal '${e}' on object '${t}'`)},o=makeType(t);Object.defineProperty(e,"$gtype",{get:()=>o,enumerable:!1,configurable:!1});for(let t of r)checkAccessors(e.prototype,t);let s={klass:e,typeName:t,gtype:o,properties:r,signals:n,internalChildren:[],engine:i,door:{name:t,dispatch:(e,t)=>missing(t),listen:(e,t)=>missing(t),createFromTree:()=>missing(`template`),attach(){},register(){}}};zt.set(e,s),i.register(s)}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)}};const K=Object.freeze({SHIFT:1,CONTROL:4,ALT:8,SUPER:1<<26,HYPER:1<<27,META:1<<28}),Kt=K.SHIFT|K.CONTROL|K.ALT|K.SUPER|K.HYPER|K.META,qt={primary:K.CONTROL,control:K.CONTROL,ctrl:K.CONTROL,ctl:K.CONTROL,shift:K.SHIFT,shft:K.SHIFT,alt:K.ALT,mod1:K.ALT,meta:K.META,super:K.SUPER,hyper:K.HYPER},Jt=[[K.SHIFT,`<Shift>`],[K.CONTROL,`<Control>`],[K.ALT,`<Alt>`],[K.META,`<Meta>`],[K.SUPER,`<Super>`],[K.HYPER,`<Hyper>`]],Yt=Object.freeze({space:32,exclam:33,quotedbl:34,numbersign:35,dollar:36,percent:37,ampersand:38,apostrophe:39,parenleft:40,parenright:41,asterisk:42,plus:43,comma:44,minus:45,period:46,slash:47,colon:58,semicolon:59,less:60,equal:61,greater:62,question:63,at:64,bracketleft:91,backslash:92,bracketright:93,asciicircum:94,underscore:95,grave:96,braceleft:123,bar:124,braceright:125,asciitilde:126,BackSpace:65288,Tab:65289,Return:65293,Escape:65307,Home:65360,Left:65361,Up:65362,Right:65363,Down:65364,Page_Up:65365,Page_Down:65366,End:65367,Insert:65379,KP_Enter:65421,KP_Multiply:65450,KP_Add:65451,KP_Subtract:65453,KP_Divide:65455,ISO_Left_Tab:65056,Delete:65535,F1:65470,F2:65471,F3:65472,F4:65473,F5:65474,F6:65475,F7:65476,F8:65477,F9:65478,F10:65479,F11:65480,F12:65481}),Xt=new Map(Object.entries(Yt).map(([e,t])=>[t,e]));function keyvalFromName(e){return/^[A-Za-z0-9]$/.test(e)?e.toLowerCase().charCodeAt(0):Yt[e]??null}function keyvalName(e){return e===0?``:e>=48&&e<=57||e>=97&&e<=122?String.fromCharCode(e):Xt.get(e)??``}function parseAcceleratorKeyval(e){let t=0,n=e.trim();for(;n.startsWith(`<`);){let e=n.indexOf(`>`);if(e===-1)return null;let r=qt[n.slice(1,e).toLowerCase()];if(r===void 0)return null;t|=r,n=n.slice(e+1)}if(n===``)return{keyval:0,modifiers:t};let r=keyvalFromName(n);if(r===null)throw new UnsupportedGObjectError(`accelerator key '${n}'`,`The key name '${n}' is outside the keysym subset of the Gtk.Application accelerators (ADR 0098 § 1).`);return{keyval:r,modifiers:t}}function acceleratorName({keyval:e,modifiers:t}){let n=``;for(let[e,r]of Jt)t&e&&(n+=r);return n+keyvalName(e)}function consumesShift(e){return e>=32&&e<=126&&!(e>=97&&e<=122)}function significant({keyval:e,modifiers:t}){let n=t&Kt;return{keyval:e,modifiers:consumesShift(e)?n&~K.SHIFT:n}}function canonicalDetailedName(e){let t=e.indexOf(`::`);if(t<=0)return e;let n=e.slice(t+2).replace(/\\/g,`\\\\`).replace(/'/g,`\\'`);return`${e.slice(0,t)}('${n}')`}var AcceleratorMap=class{#e=new Map;setAccels(e,t){let n=canonicalDetailedName(e),r=[];for(let e of t){let t=parseAcceleratorKeyval(e);if(t===null){v.error(`Gtk-CRITICAL **: Unable to parse accelerator '${e}': ignored request to install accelerators`);return}r.push(t)}r.length===0?this.#e.delete(n):this.#e.set(n,{names:r.map(acceleratorName),parsed:r})}getAccels(e){return[...this.#e.get(canonicalDetailedName(e))?.names??[]]}listActions(){return[...this.#e.keys()]}actionsFor(e){let t=parseAcceleratorKeyval(e);return t===null?(v.error(`Gtk-CRITICAL **: Unable to parse accelerator '${e}'`),[]):this.#t(t)}matching(e,t){return this.#t({keyval:e,modifiers:t})}#t(e){let t=significant(e),n=[];for(let[e,{parsed:r}]of this.#e)r.some(e=>e.keyval===t.keyval&&significant(e).modifiers===t.modifiers)&&n.push(e);return n}};const Zt=[`blue`,`teal`,`green`,`yellow`,`orange`,`red`,`pink`,`purple`,`slate`],Qt={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 Qt[e]}function adwaitaAccentColor(e,t){return adwaitaStandaloneColor(Qt[e],t)}function refuse$4(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}__name(refuse$4,`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 $t=new WeakMap;function actionRegistryOf(e,t=!0){let n=$t.get(e);return n===void 0&&t&&(n=new ActionRegistry,$t.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 en={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)}},tn={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$4(`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?{...en,...tn}:{...en};for(let[t,r]of Object.entries(n))Object.defineProperty(e,t,{value:r,writable:!0,configurable:!0,enumerable:!1})}const nn=new WeakMap;function linkWindow(e,t){t===null?nn.delete(e):nn.set(e,t)}const q=Object.freeze({KEY_space:32,KEY_a:97,KEY_d:100,KEY_e:101,KEY_q:113,KEY_s:115,KEY_w:119,KEY_Return:65293,KEY_Escape:65307,KEY_Left:65361,KEY_Up:65362,KEY_Right:65363,KEY_Down:65364});q.KEY_space,q.KEY_Return,q.KEY_Escape,q.KEY_Left,q.KEY_Up,q.KEY_Right,q.KEY_Down;const rn={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$3(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}__name(refuse$3,`refuse`);const an=`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(`.`),on=[`is_remote`,`is_registered`,`is_busy`,`resource_base_path`,`inactivity_timeout`,`action_group`],sn=[`open`,`command-line`,`handle-local-options`,`shutdown`,`name-lost`],cn=[`set_menubar`,`get_menubar`,`get_menu_by_id`,`set_app_menu`,`get_app_menu`,`get_menu_by_id`,`inhibit`,`uninhibit`],ln=new WeakMap;let un=null;function rememberDefault(e){un??=e}function stateOf(e){let t=ln.get(e);return t===void 0&&(t={id:null,windows:[],running:!1,resolve:()=>{}},ln.set(e,t)),t}const dn=new WeakMap;function acceleratorsOf(e){let t=dn.get(e);return t===void 0&&(t=new AcceleratorMap,dn.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[Gt]=`Gio.Application`}static id_is_valid(e){return isValidApplicationId(e)}static get_default(){return un}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!==rn.NONE)throw refuse$3(`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$3(`Gio.Application.run()`,`blocks, and a page cannot; use runAsync()`)}connect(e,t){let n=e.split(`::`)[0]??e;if(sn.includes(n))throw refuse$3(`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:[]},[Rt.string(`application-id`,``,``,W.READWRITE|W.CONSTRUCT,null),Rt.uint(`flags`,``,``,W.READWRITE|W.CONSTRUCT,0,4294967295,0)]),installActionMap(GioApplicationBase.prototype,!0);function refuseMembers$1(e,t,n){for(let n of t)Object.defineProperty(e,n,{value:()=>{throw refuse$3(`${n}()`,`is not implemented`)},writable:!0,configurable:!0,enumerable:!1});for(let t of n)Object.defineProperty(e,t,{get(){throw refuse$3(`the '${t}' property`,`is not implemented`)},configurable:!0,enumerable:!1})}__name(refuseMembers$1,`refuseMembers`),refuseMembers$1(GioApplicationBase.prototype,an,on);function withGtkApplication(e){class GtkApplication extends e{get active_window(){return stateOf(this).windows[0]??null}get_active_window(){return this.active_window}set_accels_for_action(e,t){acceleratorsOf(this).setAccels(e,t)}get_accels_for_action(e){return acceleratorsOf(this).getAccels(e)}get_actions_for_accel(e){return acceleratorsOf(this).actionsFor(e)}list_action_descriptions(){return acceleratorsOf(this).listActions()}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$1(GtkApplication.prototype,cn,[]),GtkApplication}withGtkApplication(GioApplicationBase);function refuse$2(e){return new UnsupportedGObjectError(e,`${e} is outside the GLib.Bytes subset (ADR 0100 § 3).`)}__name(refuse$2,`refuse`);const fn=[`slice`,`hash`,`compare`,`equal`,`unref_to_data`,`unref_to_array`,`get_region`,`toArray`];var J=class Bytes{#e;constructor(e){if(!(e instanceof Uint8Array))throw refuse$2(`new GLib.Bytes(${typeof e})`);this.#e=e.slice()}static new(e){return new Bytes(e)}static new_take(){throw refuse$2(`GLib.Bytes.new_take()`)}static new_static(){throw refuse$2(`GLib.Bytes.new_static()`)}get_size(){return this.#e.length}get_data(){return this.#e.slice()}static view(e){return e.#e}};for(let e of fn)Object.defineProperty(J.prototype,e,{value:()=>{throw refuse$2(`GLib.Bytes.${e}()`)},writable:!0,configurable:!0,enumerable:!1});function refuse$1(e){return new UnsupportedGObjectError(e,`${e} is outside the GLib.Error subset (ADR 0100 § 5).`)}__name(refuse$1,`refuse`);const pn=new WeakMap,mn=new Map;function errorDomain(e,t,n){let r=Object.freeze({...n}),i={quark:t,name:e};return pn.set(r,i),mn.set(t,i),r}const hn=errorDomain(`Gtk.DialogError`,1001,{FAILED:0,CANCELLED:1,DISMISSED:2}),Y=errorDomain(`Gio.IOErrorEnum`,1002,{FAILED:0,NOT_FOUND:1,NOT_SUPPORTED:15,CLOSED:18,CANCELLED:19,PENDING:20});function domainOf(e){let t=typeof e==`number`?mn.get(e):typeof e==`object`&&e?pn.get(e):void 0;if(!t)throw refuse$1(`GLib.Error domain ${String(e)}`);return t}var GLibError=class{constructor(e,t,n){this.domain=domainOf(e).quark,this.code=t,this.message=String(n),this.stack=Error(this.message).stack??``}matches(e,t){return domainOf(e).quark===this.domain&&t===this.code}toString(){return`${domainOf(this.domain).name}: ${this.message}`}static new_literal(){throw refuse$1(`GLib.Error.new_literal()`)}copy(){throw refuse$1(`GLib.Error.copy()`)}};function asGLibError(e,t,n){return e instanceof GLibError?e:new GLibError(t,n,e instanceof Error?`${e.name}: ${e.message}`:String(e))}function refuse(e,t=`is outside the file-chooser subset`){return new UnsupportedGObjectError(e,`${e} ${t} (ADR 0100).`)}function refuseMembers(e,t,n){for(let r of n)Object.defineProperty(e,r,{value:()=>{throw refuse(`${t}.${r}()`)},writable:!0,configurable:!0,enumerable:!1})}function dialogFailedError(e){return new GLibError(hn,hn.FAILED,e)}var X=class AsyncResult{#e;#t;#n;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}get_source_object(){return this.#e}static take(e,t,n){if(!(e instanceof AsyncResult)||e.#e!==t||e.#t!==n)throw TypeError(`${n}_finish: the result is not one of ${n}`);if(!e.#n.ok)throw e.#n.error;return e.#n.value}};function requireArgs(e,t,n){if(n<t)throw TypeError(`method ${e}: At least ${t} arguments required, but only ${n} passed`)}function isCancelled(e){let t=e;return typeof t?.is_cancelled==`function`&&t.is_cancelled()===!0}function cancelledError(){return new GLibError(Y,Y.CANCELLED,`Operation was cancelled`)}function runAsync(e,t,n,r,i,o){(isCancelled(n)?Promise.reject(cancelledError()):Promise.resolve().then(i)).then(e=>({ok:!0,value:e}),e=>({ok:!1,error:o(e)})).then(n=>{typeof r==`function`&&r(e,new X(e,t,n))})}const ioError=e=>asGLibError(e,Y,Y.FAILED),dialogError=e=>asGLibError(e,hn,hn.FAILED),gn=/[*?[\]]/,_n=new WeakMap;function filterState(e){let t=typeof e==`object`&&e?_n.get(e):void 0;if(!t)throw refuse(`a ${typeof e} where a Gtk.FileFilter is expected`,`is not a Gtk.FileFilter`);return t}var vn=class FileFilter{constructor(e={}){_n.set(this,{name:null,patterns:[],suffixes:[],mimeTypes:[],acceptAll:!1});for(let[t,n]of Object.entries(e))if(t===`name`)this.set_name(n);else throw refuse(`the Gtk.FileFilter '${t}' property`)}static new(){return new FileFilter}get name(){return filterState(this).name}set name(e){this.set_name(e)}get_name(){return this.name}set_name(e){filterState(this).name=e==null?null:String(e)}add_pattern(e){let t=filterState(this);if(e===`*`){t.acceptAll=!0;return}let n=e.startsWith(`*.`)?e.slice(2):null;if(n===null||n===``||gn.test(n))throw refuse(`Gtk.FileFilter.add_pattern('${e}')`,`is a glob other than '*' or '*.ext'`);t.patterns.push(n)}add_suffix(e){if(typeof e!=`string`||e===``||gn.test(e))throw refuse(`Gtk.FileFilter.add_suffix('${String(e)}')`,`is not a plain suffix`);filterState(this).suffixes.push(e)}add_mime_type(e){let t=filterState(this);if(e===`*/*`){t.acceptAll=!0;return}if(typeof e!=`string`||!/^[\w.+-]+\/(\*|[\w.+-]+)$/.test(e))throw refuse(`Gtk.FileFilter.add_mime_type('${String(e)}')`,`is not a MIME type`);t.mimeTypes.push(e)}};refuseMembers(vn.prototype,`Gtk.FileFilter`,[`add_pixbuf_formats`,`get_attributes`,`to_gvariant`,`match`,`get_strictness`,`changed`]),registerBaseClass(vn,`GtkFileFilter`,{});function fileFilterSpec(e){let{name:t,patterns:n,suffixes:r,mimeTypes:i,acceptAll:o}=filterState(e);return{name:t,patterns:[...n],suffixes:[...r],mimeTypes:[...i],acceptAll:o}}var GioListStore=class{#e=[];#t;constructor(e={}){let t=e.item_type??e.itemType;if(t!==vn.$gtype)throw refuse(`Gio.ListStore of ${String(t?.name??t)}`,`holds no Gtk.FileFilter`);this.#t=t}get item_type(){return this.#t}get n_items(){return this.#e.length}append(e){filterState(e),this.#e.push(e)}get_n_items(){return this.#e.length}get_item(e){return this.#e[e]??null}get_item_type(){return this.#t}};refuseMembers(GioListStore.prototype,`Gio.ListStore`,[`insert`,`insert_sorted`,`remove`,`remove_all`,`splice`,`sort`,`find`,`find_with_equal_func`,`items_changed`]);const yn=Object.freeze({NONE:0,PRIVATE:1,REPLACE_DESTINATION:2}),bn=new WeakMap;function streamState(e){let t=bn.get(e);if(!t)throw refuse(`Gio.OutputStream`,`is only made by Gio.File.replace_async`);return t}function streamOp(e,t,n){return async()=>{let r=streamState(e);if(r.closed)throw new GLibError(Y,Y.CLOSED,`Stream is already closed`);if(r.pending)throw new GLibError(Y,Y.PENDING,`Stream has outstanding operation`);r.pending=!0;try{let e=await n(r.writer);return t&&(r.closed=!0),e}finally{r.pending=!1}}}var OutputStream=class{constructor(e){bn.set(this,{writer:e,closed:!1,pending:!1})}write_bytes_async(e,t,n,r){if(requireArgs(`Gio.OutputStream.write_bytes_async`,4,arguments.length),!(e instanceof J))throw refuse(`write_bytes_async of a non-GLib.Bytes`,`is not a GLib.Bytes`);let i=J.view(e),o=streamOp(this,!1,async e=>(await e.write(i),i.length));runAsync(this,`write_bytes`,n,r,o,ioError)}write_bytes_finish(e){return X.take(e,this,`write_bytes`)}close_async(e,t,n){requireArgs(`Gio.OutputStream.close_async`,3,arguments.length);let r=streamOp(this,!0,async e=>(await e.close(),!0));runAsync(this,`close`,t,n,r,ioError)}close_finish(e){return X.take(e,this,`close`)}is_closed(){return streamState(this).closed}},FileOutputStream=class extends OutputStream{};refuseMembers(OutputStream.prototype,`Gio.OutputStream`,[`write`,`write_all`,`write_bytes`,`write_async`,`write_all_async`,`writev`,`splice`,`splice_async`,`flush`,`flush_async`,`close`,`printf`]),refuseMembers(FileOutputStream.prototype,`Gio.FileOutputStream`,[`seek`,`truncate`,`query_info`,`get_etag`]);const xn=new WeakMap;function handleOf(e){let t=xn.get(e);if(!t)throw refuse(`Gio.File`,`is only made by Gtk.FileDialog`);return t}function checkReplaceArgs(e,t,n,r){if(t!=null)throw refuse(`${e} with an etag`);if(n!==!1)throw refuse(`${e} with make_backup`);if(r!==yn.NONE)throw refuse(`${e} with flags ${String(r)}`)}var GioFile=class{constructor(e){xn.set(this,e)}static new_for_path(){throw refuse(`Gio.File.new_for_path()`,`names a path, and a page or an Android app has none`)}static new_for_uri(){throw refuse(`Gio.File.new_for_uri()`,`names a URI the platform cannot open`)}static new_for_commandline_arg(){throw refuse(`Gio.File.new_for_commandline_arg()`)}get_basename(){return handleOf(this).basename}get_path(){return handleOf(this),null}get_uri(){let{uri:e}=handleOf(this);if(e===void 0)throw refuse(`Gio.File.get_uri()`,`has no URI to give on this platform`);return e}load_contents_async(e,t){requireArgs(`Gio.File.load_contents_async`,2,arguments.length);let n=handleOf(this);runAsync(this,`load_contents`,e,t,()=>n.read(),ioError)}load_contents_finish(e){return[!0,X.take(e,this,`load_contents`),null]}replace_contents_async(e,t,n,r,i,o){requireArgs(`Gio.File.replace_contents_async`,6,arguments.length),checkReplaceArgs(`Gio.File.replace_contents_async`,t,n,r);let s=e instanceof J?J.view(e):e;if(!(s instanceof Uint8Array))throw refuse(`replace_contents_async of a non-Uint8Array`);let c=s.slice(),l=handleOf(this),work=async()=>{let e=await l.openWriter();await e.write(c),await e.close()};runAsync(this,`replace_contents`,i,o,work,ioError)}replace_contents_finish(e){return X.take(e,this,`replace_contents`),[!0,null]}replace_async(e,t,n,r,i,o){requireArgs(`Gio.File.replace_async`,6,arguments.length),checkReplaceArgs(`Gio.File.replace_async`,e,t,n);let s=handleOf(this),work=async()=>new FileOutputStream(await s.openWriter());runAsync(this,`replace`,i,o,work,ioError)}replace_finish(e){return X.take(e,this,`replace`)}};refuseMembers(GioFile.prototype,`Gio.File`,`read.read_async.load_contents.load_bytes.load_bytes_async.replace.replace_contents.create.create_async.append_to.append_to_async.query_info.query_info_async.query_exists.query_file_type.delete.delete_async.trash.move.move_async.copy.copy_async.get_parent.get_child.resolve_relative_path.enumerate_children.enumerate_children_async.make_directory.monitor.monitor_file.monitor_directory.equal.hash.dup`.split(`.`));const Sn=new Set([`title`,`modal`,`filters`,`initial_name`,`default_filter`]),Cn=[`initial_folder`,`initial_file`,`accept_label`],snake=e=>e.replace(/-/g,`_`).replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`);var wn=class FileDialog{#e=null;#t=!0;#n=null;#r=null;#i=null;constructor(e={}){for(let[t,n]of Object.entries(e)){let e=snake(t);if(!Sn.has(e))throw refuse(`the Gtk.FileDialog '${e}' property`);this[e]=n}}static new(){return new FileDialog}get title(){return this.#e}set title(e){this.#e=e==null?null:String(e)}get_title(){return this.#e}set_title(e){this.title=e}get modal(){return this.#t}set modal(e){if(e!==!0)throw refuse(`Gtk.FileDialog modal: false`,`cannot open non-modally on this platform`);this.#t=!0}get_modal(){return this.#t}set_modal(e){this.modal=e}get filters(){return this.#n}set filters(e){if(e!==null&&!(e instanceof GioListStore))throw refuse(`Gtk.FileDialog filters of another type`);this.#n=e}get_filters(){return this.#n}set_filters(e){this.filters=e}get initial_name(){return this.#r}set initial_name(e){this.#r=e==null?null:String(e)}get initialName(){return this.initial_name}set initialName(e){this.initial_name=e}get_initial_name(){return this.#r}set_initial_name(e){this.initial_name=e}get default_filter(){return this.#i}set default_filter(e){e!==null&&filterState(e),this.#i=e}get defaultFilter(){return this.default_filter}set defaultFilter(e){this.default_filter=e}get_default_filter(){return this.#i}set_default_filter(e){this.default_filter=e}open(e,t,n){requireArgs(`Gtk.FileDialog.open`,3,arguments.length),this.#a(`open`,e,t,n)}open_finish(e){return X.take(e,this,`open`)}save(e,t,n){requireArgs(`Gtk.FileDialog.save`,3,arguments.length),this.#a(`save`,e,t,n)}save_finish(e){return X.take(e,this,`save`)}#a(e,t,n,r){this.#o(t);let work=async()=>{throw dialogFailedError(`No file chooser driver is registered on this platform`)};runAsync(this,e,n,r,work,dialogError)}#o(e){let t=[],n=this.#n;for(let e=0;n&&e<n.get_n_items();e++)t.push(fileFilterSpec(n.get_item(e)));return{title:this.#e,filters:t,defaultFilter:this.#i?fileFilterSpec(this.#i):null,initialName:this.#r,parent:e}}};refuseMembers(wn.prototype,`Gtk.FileDialog`,[`open_multiple`,`open_multiple_finish`,`open_multiple_text_files`,`open_multiple_text_files_finish`,`open_text_file`,`open_text_file_finish`,`save_text_file`,`save_text_file_finish`,`select_folder`,`select_folder_finish`,`select_multiple_folders`,`select_multiple_folders_finish`,`set_initial_folder`,`get_initial_folder`,`set_initial_file`,`get_initial_file`,`set_accept_label`,`get_accept_label`]);for(let e of Cn)Object.defineProperty(wn.prototype,e,{get(){throw refuse(`the Gtk.FileDialog '${e}' property`,`names a folder or label the platform does not take`)},set(){throw refuse(`the Gtk.FileDialog '${e}' property`,`names a folder or label the platform does not take`)},configurable:!0,enumerable:!1});registerBaseClass(wn,`GtkFileDialog`,{});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 Tn=Math.PI*.9,En=Math.PI*.7,Dn=Math.PI*1.1,On=Math.PI*1.35,kn=Tn+Dn+On-En;53*Math.PI*2/kn,Dn-En/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 An={DEFAULT:0,FORCE_LIGHT:1,PREFER_LIGHT:2,PREFER_DARK:3,FORCE_DARK:4},jn=new WeakMap,Mn=new WeakMap,Nn=new WeakMap;function refresh(e){if(!jn.has(e))return;let t=sourceOf(e).dark();jn.get(e)!==t&&(jn.set(e,t),e.notify(`dark`))}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[Gt]=`Adw.StyleManager`}static get_default(){let e=Mn.get(this);if(e===void 0){e=new this,Mn.set(this,e);let t=sourceOf(e);jn.set(e,t.dark()),t.subscribe(()=>refresh(e))}return e}get dark(){return sourceOf(this).dark()}get_dark(){return this.dark}get color_scheme(){return Nn.get(this)??An.DEFAULT}set color_scheme(e){if(!Object.values(An).includes(e))throw Error(`Adw.StyleManager: ${e} is not an Adw.ColorScheme`);if(e===this.color_scheme)return;Nn.set(this,e);let t=e===An.FORCE_DARK?!0:e===An.FORCE_LIGHT?!1:null;sourceOf(this).force?.(t),this.notify(`color-scheme`),refresh(this)}get_color_scheme(){return this.color_scheme}set_color_scheme(e){this.color_scheme=e}};registerBaseClass(StyleManagerBase,`AdwStyleManager`,{},[Rt.boolean(`dark`,``,``,W.READABLE,!1),Rt.int(`color-scheme`,``,``,W.READWRITE,0,4,0)]);const Pn={system:`Follow system`,light:`Light`,dark:`Dark`},Fn={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 Et){let n=buildSwatch([`storybook-swatch`,`storybook-scheme-swatch`,`storybook-scheme-${e}`],Pn[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 Zt){let r=buildSwatch([`storybook-swatch`],Fn[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 In=class StorybookWindow extends s.ApplicationWindow{static{o.registerClass({GTypeName:`StorybookWindow`,Template:`<?xml version="1.0" encoding="UTF-8"?>
86
+ </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 ${U} (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 ${U} (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 ${U} 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 ${U} (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 defaultCaptureScale(e){let t=e.get_scale_factor?.();return typeof t==`number`&&t>0?t:1}function captureWidget(e,t={}){let r=e.get_native()?.get_renderer();if(!r)return{png:null,blocker:`no-renderer`};let o=e.get_width(),s=e.get_height();if(o<=0||s<=0)return{png:null,blocker:`zero-size`};let c=t.scale&&t.scale>0?t.scale:defaultCaptureScale(e),l=n.WidgetPaintable.new(e),u=n.Snapshot.new();c!==1&&u.scale(c,c),l.snapshot(u,o,s);let d=u.to_node();if(!d)return{png:null,blocker:`empty-snapshot`};let f=new i.Rect;f.init(0,0,o*c,s*c);let p=r.render_texture(d,f).save_to_png_bytes().get_data();return p?{png:new Uint8Array(p)}:{png:null,blocker:`empty-png`}}function captureWidgetPng(e,t={}){return captureWidget(e,t).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={},n=12,r=50){let i=null;for(let o=0;o<n;o++){let n=captureWidget(e,t);if(n.png)return{png:n.png,blocker:null};i=n.blocker,await frameDelay(r)}let o=captureWidget(e,t);return{png:o.png,blocker:o.png?null:o.blocker??i}}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(At))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 ScreenshotScaledAsync(t,n){try{let r=typeof t?.[0]==`string`?t[0]:``,i=typeof t?.[1]==`number`?t[1]:0,o=await this._captureScopePng(r,i>0?{scale:i}:{});n.return_value(new e.Variant(`(ay)`,[o]))}catch(e){n.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e,t={}){let r=this._resolveRootWidget(e);if(!r){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let i=captureWidget(r.widget,t);if(i.png)return i.png;let o=r.widget.get_root();o instanceof n.Window&&o.present();let s=await captureWidgetWhenRenderable(r.widget,t);return s.png?s.png:(v.warn(`[devtools] Screenshot('${e}') has no image: ${s.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 jt=`DBUS_SESSION_BUS_ADDRESS`,Mt=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(jt))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] ${jt} 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 (${jt} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${U} 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(jt),u=!!(s&&c),d=u||sessionBusUsable(),f=chooseDevtoolsTransport({requestedAddress:r.address??envValue(U),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 ${kt} 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 ${kt} at ${m} (peer address ${r.address}${o?`, published to ${o}`:``})`),o&&t.connect(`shutdown`,()=>removeDevtoolsAddressFile(o))}return Mt.add(n),n}const Nt=`&(?![a-zA-Z][a-zA-Z0-9]*;|#\\d+;|#x[0-9a-fA-F]+;)|<(?![a-zA-Z/!?])`;RegExp(Nt),RegExp(Nt,`g`);const Pt=[`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 Ft=5e3;function exitIfNotDrained(){if(typeof process>`u`||typeof process.exit!=`function`)return;let e=setTimeout(()=>{v.error(`STORYBOOK PROBE: host still alive ${Ft}ms after quit(), exiting`),process.exit(process.exitCode??0)},Ft);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??Pt,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,ee=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()},te=0;e.timeout_add(e.PRIORITY_DEFAULT,100,()=>{te+=100;let t=captureWidgetPng(n),r=n.get_width()>0&&n.get_height()>0;if(!t&&!(te>=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:ee,windowRealized:r,windowPngBytes:t?t.length:0,storyPngBytes:o?o.length:0}),e.SOURCE_REMOVE})}const It={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};It.GPL_2_0_ONLY,It.GPL_3_0_ONLY,It.UNKNOWN;var UnsupportedGObjectError=class extends Error{constructor(e,t){super(t),this.name=`UnsupportedGObjectError`,this.feature=e}};const Lt=new WeakSet;function makeType(e){let t=Object.freeze({name:e});return Lt.add(t),t}makeType(`gchararray`),makeType(`gboolean`),makeType(`gint`),makeType(`guint`),makeType(`gdouble`);const W={READABLE:1,WRITABLE:2,READWRITE:3,CONSTRUCT:4,CONSTRUCT_ONLY:8};var Rt=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 G={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`)};G.GTypeName,G.template,G.internalChildren,G.properties,G.signals,G.cssName,G.children,G.interfaces,G.requires,G.GTypeFlags;const zt=new WeakMap;function chainOf(e){let t=[];for(let n=e;typeof n==`function`;n=Object.getPrototypeOf(n)){let e=zt.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]}function parseSignal(e){let t=e.indexOf(`::`);return t===-1?{name:e}:{name:e.slice(0,t),detail:e.slice(t+2)}}const Bt=new WeakMap;function stateOf$1(e){let t=Bt.get(e);return t||(t={values:new Map,handlers:new Map,connections:new Map,emissions:[]},Bt.set(e,t)),t}__name(stateOf$1,`stateOf`);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()}}const Vt={name:`pure-js`,register(){},getValue(e,t){let{values:n}=stateOf$1(e);return n.has(t.name)||n.set(t.name,t.get_default_value()),n.get(t.name)},setValue(e,t,n){let{values:r}=stateOf$1(e),i=n!==r.get(t.name);return r.set(t.name,n),i},addHandler(e,t,n,r){let i=stateOf$1(e),o=i.handlers.get(n)??[];o.push({id:t,handler:r}),i.handlers.set(n,o),i.connections.set(t,()=>{o.splice(o.findIndex(e=>e.id===t),1)})},removeHandler(e,t){let n=stateOf$1(e),r=n.connections.get(t);return r?(n.connections.delete(t),r(),!0):!1},emit(e,t,n){runHandlers(e,t,n)},notify(e,t){runHandlers(e,`notify::${t.name}`,[t])},stopEmission(e,t){let{emissions:n}=stateOf$1(e);for(let e=n.length-1;e>=0;e--){let r=n[e];if(r.key===t&&!r.stopped)return r.stopped=!0,!0}return!1},bind(e,t,n,r,i){return bindProperties(e,t,n,r,i)}},Ht=new WeakMap;function engineOf(e){let t=Ht.get(e);return t||(t=chainOfInstance(e)[0]?.engine??Vt,Ht.set(e,t)),t}let Ut=0;const Wt=new WeakMap;function connectInstance(e,t,n){let r=chainOfInstance(e),i=typeNameOf(e,r),{name:o,detail:s}=parseSignal(t),own=t=>{let r=++Ut;return engineOf(e).addHandler(e,r,t,n),r},foreign=()=>{let o=r[0]?.door;if(!o)throw Error(`No signal '${t}' on object '${i}'`);let s=++Ut,c=o.listen(e,t,n),l=Wt.get(e);return l||Wt.set(e,l=new Map),l.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 e=findProperty(r,s);return e?own(`notify::${e.name}`):foreign()}if(findSignal(r,o)){if(s!==void 0)throw Error(`Signal '${o}' on object '${i}' has no detail`);return own(o)}return foreign()}function disconnectInstance(e,t){let n=Wt.get(e)?.get(t);if(n){Wt.get(e).delete(t),n();return}if(!engineOf(e).removeHandler(e,t))throw Error(`No handler with id ${t} is connected to ${String(e)}`)}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}`);engineOf(e).emit(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){engineOf(e).notify(e,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&W.READABLE,o=r&W.WRITABLE,s=t??{configurable:!0,enumerable:!0};return i&&o?!s.get&&!s.set?(s.get=function(){return engineOf(this).getValue(this,e)},s.set=function(t){engineOf(this).setValue(this,e,t)&&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&W.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&W.READABLE,p=r&W.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 r=engineOf(e);r.setValue(e,t,n);for(let n of new Set(aliasesOf(t.name)))Object.defineProperty(e,n,{get:()=>r.getValue(e,t),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){let t=engineOf(e);return{instance:e,handler:(t,n)=>createClosure(e,t,n?.flags?.includes(`swapped`)??!1,n?.object),bind:(e,n,r,i,o)=>t.bind(e,n,r,i,o??[])}}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&W.CONSTRUCT_ONLY&&defineConstructOnly(e,n,i.has(n)?i.get(n):n.get_default_value());for(let t of[...n].reverse())for(let n of t.properties)n.flags&W.CONSTRUCT&&!(n.flags&W.CONSTRUCT_ONLY)&&(e[n.name]=i.has(n)?i.get(n):n.get_default_value());for(let[t,n]of i)t.flags&(W.CONSTRUCT|W.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 Gt=Symbol(`GIR type`);function registerBaseClass(e,t,n,r=[],i=Vt){let missing=e=>{throw Error(`No signal '${e}' on object '${t}'`)},o=makeType(t);Object.defineProperty(e,"$gtype",{get:()=>o,enumerable:!1,configurable:!1});for(let t of r)checkAccessors(e.prototype,t);let s={klass:e,typeName:t,gtype:o,properties:r,signals:n,internalChildren:[],engine:i,door:{name:t,dispatch:(e,t)=>missing(t),listen:(e,t)=>missing(t),createFromTree:()=>missing(`template`),attach(){},register(){}}};zt.set(e,s),i.register(s)}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)}};const K=Object.freeze({SHIFT:1,CONTROL:4,ALT:8,SUPER:1<<26,HYPER:1<<27,META:1<<28}),Kt=K.SHIFT|K.CONTROL|K.ALT|K.SUPER|K.HYPER|K.META,qt={primary:K.CONTROL,control:K.CONTROL,ctrl:K.CONTROL,ctl:K.CONTROL,shift:K.SHIFT,shft:K.SHIFT,alt:K.ALT,mod1:K.ALT,meta:K.META,super:K.SUPER,hyper:K.HYPER},Jt=[[K.SHIFT,`<Shift>`],[K.CONTROL,`<Control>`],[K.ALT,`<Alt>`],[K.META,`<Meta>`],[K.SUPER,`<Super>`],[K.HYPER,`<Hyper>`]],Yt=Object.freeze({space:32,exclam:33,quotedbl:34,numbersign:35,dollar:36,percent:37,ampersand:38,apostrophe:39,parenleft:40,parenright:41,asterisk:42,plus:43,comma:44,minus:45,period:46,slash:47,colon:58,semicolon:59,less:60,equal:61,greater:62,question:63,at:64,bracketleft:91,backslash:92,bracketright:93,asciicircum:94,underscore:95,grave:96,braceleft:123,bar:124,braceright:125,asciitilde:126,BackSpace:65288,Tab:65289,Return:65293,Escape:65307,Home:65360,Left:65361,Up:65362,Right:65363,Down:65364,Page_Up:65365,Page_Down:65366,End:65367,Insert:65379,KP_Enter:65421,KP_Multiply:65450,KP_Add:65451,KP_Subtract:65453,KP_Divide:65455,ISO_Left_Tab:65056,Delete:65535,F1:65470,F2:65471,F3:65472,F4:65473,F5:65474,F6:65475,F7:65476,F8:65477,F9:65478,F10:65479,F11:65480,F12:65481}),Xt=new Map(Object.entries(Yt).map(([e,t])=>[t,e]));function keyvalFromName(e){return/^[A-Za-z0-9]$/.test(e)?e.toLowerCase().charCodeAt(0):Yt[e]??null}function keyvalName(e){return e===0?``:e>=48&&e<=57||e>=97&&e<=122?String.fromCharCode(e):Xt.get(e)??``}function parseAcceleratorKeyval(e){let t=0,n=e.trim();for(;n.startsWith(`<`);){let e=n.indexOf(`>`);if(e===-1)return null;let r=qt[n.slice(1,e).toLowerCase()];if(r===void 0)return null;t|=r,n=n.slice(e+1)}if(n===``)return{keyval:0,modifiers:t};let r=keyvalFromName(n);if(r===null)throw new UnsupportedGObjectError(`accelerator key '${n}'`,`The key name '${n}' is outside the keysym subset of the Gtk.Application accelerators (ADR 0098 § 1).`);return{keyval:r,modifiers:t}}function acceleratorName({keyval:e,modifiers:t}){let n=``;for(let[e,r]of Jt)t&e&&(n+=r);return n+keyvalName(e)}function consumesShift(e){return e>=32&&e<=126&&!(e>=97&&e<=122)}function significant({keyval:e,modifiers:t}){let n=t&Kt;return{keyval:e,modifiers:consumesShift(e)?n&~K.SHIFT:n}}function canonicalDetailedName(e){let t=e.indexOf(`::`);if(t<=0)return e;let n=e.slice(t+2).replace(/\\/g,`\\\\`).replace(/'/g,`\\'`);return`${e.slice(0,t)}('${n}')`}var AcceleratorMap=class{#e=new Map;setAccels(e,t){let n=canonicalDetailedName(e),r=[];for(let e of t){let t=parseAcceleratorKeyval(e);if(t===null){v.error(`Gtk-CRITICAL **: Unable to parse accelerator '${e}': ignored request to install accelerators`);return}r.push(t)}r.length===0?this.#e.delete(n):this.#e.set(n,{names:r.map(acceleratorName),parsed:r})}getAccels(e){return[...this.#e.get(canonicalDetailedName(e))?.names??[]]}listActions(){return[...this.#e.keys()]}actionsFor(e){let t=parseAcceleratorKeyval(e);return t===null?(v.error(`Gtk-CRITICAL **: Unable to parse accelerator '${e}'`),[]):this.#t(t)}matching(e,t){return this.#t({keyval:e,modifiers:t})}#t(e){let t=significant(e),n=[];for(let[e,{parsed:r}]of this.#e)r.some(e=>e.keyval===t.keyval&&significant(e).modifiers===t.modifiers)&&n.push(e);return n}};const Zt=[`blue`,`teal`,`green`,`yellow`,`orange`,`red`,`pink`,`purple`,`slate`],Qt={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 Qt[e]}function adwaitaAccentColor(e,t){return adwaitaStandaloneColor(Qt[e],t)}function refuse$4(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}__name(refuse$4,`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 $t=new WeakMap;function actionRegistryOf(e,t=!0){let n=$t.get(e);return n===void 0&&t&&(n=new ActionRegistry,$t.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 en={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)}},tn={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$4(`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?{...en,...tn}:{...en};for(let[t,r]of Object.entries(n))Object.defineProperty(e,t,{value:r,writable:!0,configurable:!0,enumerable:!1})}const nn=new WeakMap;function linkWindow(e,t){t===null?nn.delete(e):nn.set(e,t)}const q=Object.freeze({KEY_space:32,KEY_a:97,KEY_d:100,KEY_e:101,KEY_q:113,KEY_s:115,KEY_w:119,KEY_Return:65293,KEY_Escape:65307,KEY_Left:65361,KEY_Up:65362,KEY_Right:65363,KEY_Down:65364});q.KEY_space,q.KEY_Return,q.KEY_Escape,q.KEY_Left,q.KEY_Up,q.KEY_Right,q.KEY_Down;const rn={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$3(e,t){return new UnsupportedGObjectError(e,`${e} ${t}, which is outside the Gio subset (ADR 0098 § 1).`)}__name(refuse$3,`refuse`);const an=`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(`.`),on=[`is_remote`,`is_registered`,`is_busy`,`resource_base_path`,`inactivity_timeout`,`action_group`],sn=[`open`,`command-line`,`handle-local-options`,`shutdown`,`name-lost`],cn=[`set_menubar`,`get_menubar`,`get_menu_by_id`,`set_app_menu`,`get_app_menu`,`get_menu_by_id`,`inhibit`,`uninhibit`],ln=new WeakMap;let un=null;function rememberDefault(e){un??=e}function stateOf(e){let t=ln.get(e);return t===void 0&&(t={id:null,windows:[],running:!1,resolve:()=>{}},ln.set(e,t)),t}const dn=new WeakMap;function acceleratorsOf(e){let t=dn.get(e);return t===void 0&&(t=new AcceleratorMap,dn.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[Gt]=`Gio.Application`}static id_is_valid(e){return isValidApplicationId(e)}static get_default(){return un}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!==rn.NONE)throw refuse$3(`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$3(`Gio.Application.run()`,`blocks, and a page cannot; use runAsync()`)}connect(e,t){let n=e.split(`::`)[0]??e;if(sn.includes(n))throw refuse$3(`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:[]},[Rt.string(`application-id`,``,``,W.READWRITE|W.CONSTRUCT,null),Rt.uint(`flags`,``,``,W.READWRITE|W.CONSTRUCT,0,4294967295,0)]),installActionMap(GioApplicationBase.prototype,!0);function refuseMembers$1(e,t,n){for(let n of t)Object.defineProperty(e,n,{value:()=>{throw refuse$3(`${n}()`,`is not implemented`)},writable:!0,configurable:!0,enumerable:!1});for(let t of n)Object.defineProperty(e,t,{get(){throw refuse$3(`the '${t}' property`,`is not implemented`)},configurable:!0,enumerable:!1})}__name(refuseMembers$1,`refuseMembers`),refuseMembers$1(GioApplicationBase.prototype,an,on);function withGtkApplication(e){class GtkApplication extends e{get active_window(){return stateOf(this).windows[0]??null}get_active_window(){return this.active_window}set_accels_for_action(e,t){acceleratorsOf(this).setAccels(e,t)}get_accels_for_action(e){return acceleratorsOf(this).getAccels(e)}get_actions_for_accel(e){return acceleratorsOf(this).actionsFor(e)}list_action_descriptions(){return acceleratorsOf(this).listActions()}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$1(GtkApplication.prototype,cn,[]),GtkApplication}withGtkApplication(GioApplicationBase);function refuse$2(e){return new UnsupportedGObjectError(e,`${e} is outside the GLib.Bytes subset (ADR 0100 § 3).`)}__name(refuse$2,`refuse`);const fn=[`slice`,`hash`,`compare`,`equal`,`unref_to_data`,`unref_to_array`,`get_region`,`toArray`];var J=class Bytes{#e;constructor(e){if(!(e instanceof Uint8Array))throw refuse$2(`new GLib.Bytes(${typeof e})`);this.#e=e.slice()}static new(e){return new Bytes(e)}static new_take(){throw refuse$2(`GLib.Bytes.new_take()`)}static new_static(){throw refuse$2(`GLib.Bytes.new_static()`)}get_size(){return this.#e.length}get_data(){return this.#e.slice()}static view(e){return e.#e}};for(let e of fn)Object.defineProperty(J.prototype,e,{value:()=>{throw refuse$2(`GLib.Bytes.${e}()`)},writable:!0,configurable:!0,enumerable:!1});function refuse$1(e){return new UnsupportedGObjectError(e,`${e} is outside the GLib.Error subset (ADR 0100 § 5).`)}__name(refuse$1,`refuse`);const pn=new WeakMap,mn=new Map;function errorDomain(e,t,n){let r=Object.freeze({...n}),i={quark:t,name:e};return pn.set(r,i),mn.set(t,i),r}const hn=errorDomain(`Gtk.DialogError`,1001,{FAILED:0,CANCELLED:1,DISMISSED:2}),Y=errorDomain(`Gio.IOErrorEnum`,1002,{FAILED:0,NOT_FOUND:1,NOT_SUPPORTED:15,CLOSED:18,CANCELLED:19,PENDING:20});function domainOf(e){let t=typeof e==`number`?mn.get(e):typeof e==`object`&&e?pn.get(e):void 0;if(!t)throw refuse$1(`GLib.Error domain ${String(e)}`);return t}var GLibError=class{constructor(e,t,n){this.domain=domainOf(e).quark,this.code=t,this.message=String(n),this.stack=Error(this.message).stack??``}matches(e,t){return domainOf(e).quark===this.domain&&t===this.code}toString(){return`${domainOf(this.domain).name}: ${this.message}`}static new_literal(){throw refuse$1(`GLib.Error.new_literal()`)}copy(){throw refuse$1(`GLib.Error.copy()`)}};function asGLibError(e,t,n){return e instanceof GLibError?e:new GLibError(t,n,e instanceof Error?`${e.name}: ${e.message}`:String(e))}function refuse(e,t=`is outside the file-chooser subset`){return new UnsupportedGObjectError(e,`${e} ${t} (ADR 0100).`)}function refuseMembers(e,t,n){for(let r of n)Object.defineProperty(e,r,{value:()=>{throw refuse(`${t}.${r}()`)},writable:!0,configurable:!0,enumerable:!1})}function dialogFailedError(e){return new GLibError(hn,hn.FAILED,e)}var X=class AsyncResult{#e;#t;#n;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}get_source_object(){return this.#e}static take(e,t,n){if(!(e instanceof AsyncResult)||e.#e!==t||e.#t!==n)throw TypeError(`${n}_finish: the result is not one of ${n}`);if(!e.#n.ok)throw e.#n.error;return e.#n.value}};function requireArgs(e,t,n){if(n<t)throw TypeError(`method ${e}: At least ${t} arguments required, but only ${n} passed`)}function isCancelled(e){let t=e;return typeof t?.is_cancelled==`function`&&t.is_cancelled()===!0}function cancelledError(){return new GLibError(Y,Y.CANCELLED,`Operation was cancelled`)}function runAsync(e,t,n,r,i,o){(isCancelled(n)?Promise.reject(cancelledError()):Promise.resolve().then(i)).then(e=>({ok:!0,value:e}),e=>({ok:!1,error:o(e)})).then(n=>{typeof r==`function`&&r(e,new X(e,t,n))})}const ioError=e=>asGLibError(e,Y,Y.FAILED),dialogError=e=>asGLibError(e,hn,hn.FAILED),gn=/[*?[\]]/,_n=new WeakMap;function filterState(e){let t=typeof e==`object`&&e?_n.get(e):void 0;if(!t)throw refuse(`a ${typeof e} where a Gtk.FileFilter is expected`,`is not a Gtk.FileFilter`);return t}var vn=class FileFilter{constructor(e={}){_n.set(this,{name:null,patterns:[],suffixes:[],mimeTypes:[],acceptAll:!1});for(let[t,n]of Object.entries(e))if(t===`name`)this.set_name(n);else throw refuse(`the Gtk.FileFilter '${t}' property`)}static new(){return new FileFilter}get name(){return filterState(this).name}set name(e){this.set_name(e)}get_name(){return this.name}set_name(e){filterState(this).name=e==null?null:String(e)}add_pattern(e){let t=filterState(this);if(e===`*`){t.acceptAll=!0;return}let n=e.startsWith(`*.`)?e.slice(2):null;if(n===null||n===``||gn.test(n))throw refuse(`Gtk.FileFilter.add_pattern('${e}')`,`is a glob other than '*' or '*.ext'`);t.patterns.push(n)}add_suffix(e){if(typeof e!=`string`||e===``||gn.test(e))throw refuse(`Gtk.FileFilter.add_suffix('${String(e)}')`,`is not a plain suffix`);filterState(this).suffixes.push(e)}add_mime_type(e){let t=filterState(this);if(e===`*/*`){t.acceptAll=!0;return}if(typeof e!=`string`||!/^[\w.+-]+\/(\*|[\w.+-]+)$/.test(e))throw refuse(`Gtk.FileFilter.add_mime_type('${String(e)}')`,`is not a MIME type`);t.mimeTypes.push(e)}};refuseMembers(vn.prototype,`Gtk.FileFilter`,[`add_pixbuf_formats`,`get_attributes`,`to_gvariant`,`match`,`get_strictness`,`changed`]),registerBaseClass(vn,`GtkFileFilter`,{});function fileFilterSpec(e){let{name:t,patterns:n,suffixes:r,mimeTypes:i,acceptAll:o}=filterState(e);return{name:t,patterns:[...n],suffixes:[...r],mimeTypes:[...i],acceptAll:o}}var GioListStore=class{#e=[];#t;constructor(e={}){let t=e.item_type??e.itemType;if(t!==vn.$gtype)throw refuse(`Gio.ListStore of ${String(t?.name??t)}`,`holds no Gtk.FileFilter`);this.#t=t}get item_type(){return this.#t}get n_items(){return this.#e.length}append(e){filterState(e),this.#e.push(e)}get_n_items(){return this.#e.length}get_item(e){return this.#e[e]??null}get_item_type(){return this.#t}};refuseMembers(GioListStore.prototype,`Gio.ListStore`,[`insert`,`insert_sorted`,`remove`,`remove_all`,`splice`,`sort`,`find`,`find_with_equal_func`,`items_changed`]);const yn=Object.freeze({NONE:0,PRIVATE:1,REPLACE_DESTINATION:2}),bn=new WeakMap;function streamState(e){let t=bn.get(e);if(!t)throw refuse(`Gio.OutputStream`,`is only made by Gio.File.replace_async`);return t}function streamOp(e,t,n){return async()=>{let r=streamState(e);if(r.closed)throw new GLibError(Y,Y.CLOSED,`Stream is already closed`);if(r.pending)throw new GLibError(Y,Y.PENDING,`Stream has outstanding operation`);r.pending=!0;try{let e=await n(r.writer);return t&&(r.closed=!0),e}finally{r.pending=!1}}}var OutputStream=class{constructor(e){bn.set(this,{writer:e,closed:!1,pending:!1})}write_bytes_async(e,t,n,r){if(requireArgs(`Gio.OutputStream.write_bytes_async`,4,arguments.length),!(e instanceof J))throw refuse(`write_bytes_async of a non-GLib.Bytes`,`is not a GLib.Bytes`);let i=J.view(e),o=streamOp(this,!1,async e=>(await e.write(i),i.length));runAsync(this,`write_bytes`,n,r,o,ioError)}write_bytes_finish(e){return X.take(e,this,`write_bytes`)}close_async(e,t,n){requireArgs(`Gio.OutputStream.close_async`,3,arguments.length);let r=streamOp(this,!0,async e=>(await e.close(),!0));runAsync(this,`close`,t,n,r,ioError)}close_finish(e){return X.take(e,this,`close`)}is_closed(){return streamState(this).closed}},FileOutputStream=class extends OutputStream{};refuseMembers(OutputStream.prototype,`Gio.OutputStream`,[`write`,`write_all`,`write_bytes`,`write_async`,`write_all_async`,`writev`,`splice`,`splice_async`,`flush`,`flush_async`,`close`,`printf`]),refuseMembers(FileOutputStream.prototype,`Gio.FileOutputStream`,[`seek`,`truncate`,`query_info`,`get_etag`]);const xn=new WeakMap;function handleOf(e){let t=xn.get(e);if(!t)throw refuse(`Gio.File`,`is only made by Gtk.FileDialog`);return t}function checkReplaceArgs(e,t,n,r){if(t!=null)throw refuse(`${e} with an etag`);if(n!==!1)throw refuse(`${e} with make_backup`);if(r!==yn.NONE)throw refuse(`${e} with flags ${String(r)}`)}var GioFile=class{constructor(e){xn.set(this,e)}static new_for_path(){throw refuse(`Gio.File.new_for_path()`,`names a path, and a page or an Android app has none`)}static new_for_uri(){throw refuse(`Gio.File.new_for_uri()`,`names a URI the platform cannot open`)}static new_for_commandline_arg(){throw refuse(`Gio.File.new_for_commandline_arg()`)}get_basename(){return handleOf(this).basename}get_path(){return handleOf(this),null}get_uri(){let{uri:e}=handleOf(this);if(e===void 0)throw refuse(`Gio.File.get_uri()`,`has no URI to give on this platform`);return e}load_contents_async(e,t){requireArgs(`Gio.File.load_contents_async`,2,arguments.length);let n=handleOf(this);runAsync(this,`load_contents`,e,t,()=>n.read(),ioError)}load_contents_finish(e){return[!0,X.take(e,this,`load_contents`),null]}replace_contents_async(e,t,n,r,i,o){requireArgs(`Gio.File.replace_contents_async`,6,arguments.length),checkReplaceArgs(`Gio.File.replace_contents_async`,t,n,r);let s=e instanceof J?J.view(e):e;if(!(s instanceof Uint8Array))throw refuse(`replace_contents_async of a non-Uint8Array`);let c=s.slice(),l=handleOf(this),work=async()=>{let e=await l.openWriter();await e.write(c),await e.close()};runAsync(this,`replace_contents`,i,o,work,ioError)}replace_contents_finish(e){return X.take(e,this,`replace_contents`),[!0,null]}replace_async(e,t,n,r,i,o){requireArgs(`Gio.File.replace_async`,6,arguments.length),checkReplaceArgs(`Gio.File.replace_async`,e,t,n);let s=handleOf(this),work=async()=>new FileOutputStream(await s.openWriter());runAsync(this,`replace`,i,o,work,ioError)}replace_finish(e){return X.take(e,this,`replace`)}};refuseMembers(GioFile.prototype,`Gio.File`,`read.read_async.load_contents.load_bytes.load_bytes_async.replace.replace_contents.create.create_async.append_to.append_to_async.query_info.query_info_async.query_exists.query_file_type.delete.delete_async.trash.move.move_async.copy.copy_async.get_parent.get_child.resolve_relative_path.enumerate_children.enumerate_children_async.make_directory.monitor.monitor_file.monitor_directory.equal.hash.dup`.split(`.`));const Sn=new Set([`title`,`modal`,`filters`,`initial_name`,`default_filter`]),Cn=[`initial_folder`,`initial_file`,`accept_label`],snake=e=>e.replace(/-/g,`_`).replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`);var wn=class FileDialog{#e=null;#t=!0;#n=null;#r=null;#i=null;constructor(e={}){for(let[t,n]of Object.entries(e)){let e=snake(t);if(!Sn.has(e))throw refuse(`the Gtk.FileDialog '${e}' property`);this[e]=n}}static new(){return new FileDialog}get title(){return this.#e}set title(e){this.#e=e==null?null:String(e)}get_title(){return this.#e}set_title(e){this.title=e}get modal(){return this.#t}set modal(e){if(e!==!0)throw refuse(`Gtk.FileDialog modal: false`,`cannot open non-modally on this platform`);this.#t=!0}get_modal(){return this.#t}set_modal(e){this.modal=e}get filters(){return this.#n}set filters(e){if(e!==null&&!(e instanceof GioListStore))throw refuse(`Gtk.FileDialog filters of another type`);this.#n=e}get_filters(){return this.#n}set_filters(e){this.filters=e}get initial_name(){return this.#r}set initial_name(e){this.#r=e==null?null:String(e)}get initialName(){return this.initial_name}set initialName(e){this.initial_name=e}get_initial_name(){return this.#r}set_initial_name(e){this.initial_name=e}get default_filter(){return this.#i}set default_filter(e){e!==null&&filterState(e),this.#i=e}get defaultFilter(){return this.default_filter}set defaultFilter(e){this.default_filter=e}get_default_filter(){return this.#i}set_default_filter(e){this.default_filter=e}open(e,t,n){requireArgs(`Gtk.FileDialog.open`,3,arguments.length),this.#a(`open`,e,t,n)}open_finish(e){return X.take(e,this,`open`)}save(e,t,n){requireArgs(`Gtk.FileDialog.save`,3,arguments.length),this.#a(`save`,e,t,n)}save_finish(e){return X.take(e,this,`save`)}#a(e,t,n,r){this.#o(t);let work=async()=>{throw dialogFailedError(`No file chooser driver is registered on this platform`)};runAsync(this,e,n,r,work,dialogError)}#o(e){let t=[],n=this.#n;for(let e=0;n&&e<n.get_n_items();e++)t.push(fileFilterSpec(n.get_item(e)));return{title:this.#e,filters:t,defaultFilter:this.#i?fileFilterSpec(this.#i):null,initialName:this.#r,parent:e}}};refuseMembers(wn.prototype,`Gtk.FileDialog`,[`open_multiple`,`open_multiple_finish`,`open_multiple_text_files`,`open_multiple_text_files_finish`,`open_text_file`,`open_text_file_finish`,`save_text_file`,`save_text_file_finish`,`select_folder`,`select_folder_finish`,`select_multiple_folders`,`select_multiple_folders_finish`,`set_initial_folder`,`get_initial_folder`,`set_initial_file`,`get_initial_file`,`set_accept_label`,`get_accept_label`]);for(let e of Cn)Object.defineProperty(wn.prototype,e,{get(){throw refuse(`the Gtk.FileDialog '${e}' property`,`names a folder or label the platform does not take`)},set(){throw refuse(`the Gtk.FileDialog '${e}' property`,`names a folder or label the platform does not take`)},configurable:!0,enumerable:!1});registerBaseClass(wn,`GtkFileDialog`,{});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 Tn=Math.PI*.9,En=Math.PI*.7,Dn=Math.PI*1.1,On=Math.PI*1.35,kn=Tn+Dn+On-En;53*Math.PI*2/kn,Dn-En/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 An={DEFAULT:0,FORCE_LIGHT:1,PREFER_LIGHT:2,PREFER_DARK:3,FORCE_DARK:4},jn=new WeakMap,Mn=new WeakMap,Nn=new WeakMap;function refresh(e){if(!jn.has(e))return;let t=sourceOf(e).dark();jn.get(e)!==t&&(jn.set(e,t),e.notify(`dark`))}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[Gt]=`Adw.StyleManager`}static get_default(){let e=Mn.get(this);if(e===void 0){e=new this,Mn.set(this,e);let t=sourceOf(e);jn.set(e,t.dark()),t.subscribe(()=>refresh(e))}return e}get dark(){return sourceOf(this).dark()}get_dark(){return this.dark}get color_scheme(){return Nn.get(this)??An.DEFAULT}set color_scheme(e){if(!Object.values(An).includes(e))throw Error(`Adw.StyleManager: ${e} is not an Adw.ColorScheme`);if(e===this.color_scheme)return;Nn.set(this,e);let t=e===An.FORCE_DARK?!0:e===An.FORCE_LIGHT?!1:null;sourceOf(this).force?.(t),this.notify(`color-scheme`),refresh(this)}get_color_scheme(){return this.color_scheme}set_color_scheme(e){this.color_scheme=e}};registerBaseClass(StyleManagerBase,`AdwStyleManager`,{},[Rt.boolean(`dark`,``,``,W.READABLE,!1),Rt.int(`color-scheme`,``,``,W.READWRITE,0,4,0)]);const Pn={system:`Follow system`,light:`Light`,dark:`Dark`},Fn={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 Et){let n=buildSwatch([`storybook-swatch`,`storybook-scheme-swatch`,`storybook-scheme-${e}`],Pn[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 Zt){let r=buildSwatch([`storybook-swatch`],Fn[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 In=class StorybookWindow extends s.ApplicationWindow{static{o.registerClass({GTypeName:`StorybookWindow`,Template:`<?xml version="1.0" encoding="UTF-8"?>
87
87
  <!--
88
88
  DO NOT EDIT!
89
89
  This file was @generated by blueprint-compiler. Instead, edit the