@gjsify/example-gtk-adwaita-storybook 0.41.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-main.js +33 -26
- package/dist/gjs.js +16 -7
- package/dist/gjs.node.mjs +11 -2
- package/package.json +5 -5
- package/src/browser/buttons/toggle-group.web.ts +8 -4
- package/src/browser/layout/toolbar-view.web.ts +1 -1
- package/src/browser/rows/entry-row.web.ts +1 -0
- package/src/browser/view-switching/tab-view.web.ts +6 -3
package/dist/gjs.node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as e}from"node:module";import"@gjsify/node-gi/globals";import t from"@gjsify/node-gi/system";var n=Object.defineProperty,__name=(e,t)=>n(e,`name`,{value:t,configurable:!0}),__exportAll=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r};const r=[`Overview`,`Presentation`,`Boxed Lists`,`Controls`,`Buttons`,`Layout`,`View Switching`,`Navigation`,`Feedback`];function orderCategories(e){let t=new Map(r.map((e,t)=>[e,t])),n=[...e].filter(e=>t.has(e));n.sort((e,n)=>t.get(e)-t.get(n));let i=e.filter(e=>!t.has(e));return[...n,...i]}var StoryRegistry=class{constructor(){this.modules=[]}registerStory(e){if(!e||!Array.isArray(e.stories)){console.warn(`Invalid story module provided to registerStory`);return}this.modules.push(e)}registerStories(e){if(!Array.isArray(e)){console.warn(`Invalid story modules array provided to registerStories`);return}let t=e.filter(e=>e&&Array.isArray(e.stories));this.modules.push(...t)}getStories(){return[...this.modules]}createStoryInstances(){for(let e of this.modules)this.instantiateStoriesForModule(e);return[...this.modules]}instantiateStoriesForModule(e){e.instances=[];let t=e.decorators??[];for(let n of e.stories)try{let r=new n,build=()=>{typeof r.initialize==`function`&&r.initialize()};t.reduceRight((e,t)=>()=>t(e,r),build)(),e.instances.push(r)}catch(e){console.error(`Failed to instantiate story: ${n.name||`Unknown`}`,e)}}},StorybookController=class{constructor(e,t){this._registry=new StoryRegistry,this._activeStory=null,this._unsubArgs=null,this._view=e,this._buildControls=t}mount(e,t=!0){this._registry.registerStories(e);let n=this._registry.createStoryInstances(),r=this._groupByCategory(n);if(this._view.renderSidebar(r,e=>this.select(e)),t){let e=r[0]?.stories[0]?.instance??null;e&&this.select(e)}}select(e){this._view.setPreviewTitle(`${e.meta.title} — ${e.story}`),this._view.showPreview(e),this._view.markSelected(e.meta.title),this._wireControls(e),this._activeStory=e}_wireControls(e){this._unsubArgs&&=(this._unsubArgs(),null);let t=this._buildControls(e),n=t.map(e=>e.refresh);this._view.renderControls(t),this._unsubArgs=e.onArgsChanged(e=>{for(let t of n)t(e)})}_groupByCategory(e){let t=new Map;for(let n of e)for(let e of n.instances??[]){let n=e.meta.title.split(`/`),r=n[0],i=n.length>1?n[1]:e.meta.title;t.has(r)||t.set(r,[]),t.get(r).push({instance:e,name:i||`Unnamed`})}return orderCategories([...t.keys()]).map(e=>({category:e,stories:t.get(e)}))}get activeStory(){return this._activeStory}listStories(){return this._registry.getStories().flatMap(e=>(e.instances??[]).map(e=>({title:e.meta.title,story:e.story,category:e.meta.title.split(`/`)[0],controls:e.meta.controls??[]})))}openStoryByTitle(e){let t=this._findByTitle(e);return t?(this.select(t),!0):!1}getCurrentStory(){let e=this._activeStory;return e?{title:e.meta.title,story:e.story,args:e.args}:null}setActiveArg(e,t){let n=this._activeStory;return n?(n.setArg(e,t),!0):!1}_findByTitle(e){for(let t of this._registry.getStories())for(let n of t.instances??[])if(n.meta.title===e)return n;return null}};let i=function(e){return e.TEXT=`text`,e.NUMBER=`number`,e.BOOLEAN=`boolean`,e.SELECT=`select`,e.RANGE=`range`,e.COLOR=`color`,e}({});function isStoryModule(e){return typeof e==`object`&&!!e&&Array.isArray(e.stories)}function argsFromControls(e=[]){let t={};for(let n of e)t[n.name]=defaultFor(n);return t}function defaultFor(e){if(e.defaultValue!==void 0)return e.defaultValue;switch(e.type){case`text`:return``;case`color`:return`#000000`;case`boolean`:return!1;case`number`:case`range`:return e.min??0;case`select`:return e.options[0]?.value??null;default:return null}}function controlLabel(e){return e.label||e.name}function bindControl(e,t,n){let r=t.name,a=t.description;switch(t.type){case i.TEXT:{let i=n.text(controlLabel(t),a),o=e.args[r];return i.set(typeof o==`string`?o:``),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=typeof e[r]==`string`?e[r]:``;i.get()!==t&&i.set(t)}}}case i.COLOR:{let i=n.color(controlLabel(t),a),o=e.args[r];return i.set(typeof o==`string`?o:`#000000`),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=typeof e[r]==`string`?e[r]:`#000000`;i.get()!==t&&i.set(t)}}}case i.BOOLEAN:{let i=n.boolean(controlLabel(t),a);return i.set(!!e.args[r]),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=!!e[r];i.get()!==t&&i.set(t)}}}case i.NUMBER:{let i=n.number(t),a=e.args[r];return i.set(typeof a==`number`?a:t.min??0),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=typeof e[r]==`number`?e[r]:0;i.get()!==t&&i.set(t)}}}case i.RANGE:{let i=n.range(t),a=e.args[r],o=typeof a==`number`?a:t.min??0;return i.set(o),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=typeof e[r]==`number`?e[r]:o;i.get()!==t&&i.set(t)}}}case i.SELECT:{let i=t.options;if(!i?.length)return console.warn(`SELECT control "${r}" has no options`),null;let a=n.select(t),o=e.args[r],s=Math.max(0,i.findIndex(e=>e.value===o));return a.set(s),a.onChange(t=>{t>=0&&t<i.length&&e.setArg(r,i[t].value)}),{view:a.node,refresh:e=>{let t=e[r],n=i.findIndex(e=>e.value===t);n>=0&&a.get()!==n&&a.set(n)}}}default:return console.warn(`Unsupported control type: ${t.type}`),null}}function buildStorybookDevtoolsExtension(e){let currentStory=()=>e.getCurrentStory();return{methods:[{name:`ListStories`,kind:`read-only`,handler:(()=>JSON.stringify(e.listStories(),null,2))},{name:`GetCurrentStory`,kind:`read-only`,handler:(()=>JSON.stringify(currentStory(),null,2))},{name:`OpenStory`,kind:`mutating`,handler:(t=>e.openStoryByTitle(t))},{name:`SetStoryArg`,kind:`mutating`,handler:((t,n)=>e.setActiveArg(t,n?JSON.parse(n):null))},{name:`GetStoryArgs`,kind:`read-only`,handler:(()=>JSON.stringify(currentStory()?.args??{},null,2))}],contributeStatus:()=>{let t=currentStory(),n=e.listStories();return{storybook:{currentStory:t?{title:t.title,story:t.story}:null,storyCount:n.length}}}}}function collectStoryModules$1(e){let t=[];for(let n of e)if(!(!n||typeof n!=`object`))for(let e of Object.values(n))isStoryModule(e)&&t.push(e);return t}__name(collectStoryModules$1,`collectStoryModules`);var StoryViewBase=class{constructor(){this._listeners=new Set}initBase(e,t,n){this._meta=e,this._story=t,this._args=argsFromControls(e.controls),this._chrome=this.createChrome(e,n),this.refreshChromeText()}get meta(){return this._meta}get story(){return this._story}get args(){return this._args}get root(){return this._chrome.root}set args(e){this._args!==e&&(this._args=e,this.updateArgs(e),this.emitArgs(e))}emitArgs(e){for(let t of this._listeners)t(e)}onArgsChanged(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}setArg(e,t){this.args={...this._args,[e]:t}}initialize(){}updateArgs(e){}teardown(){}addContent(e){this._chrome.hasStage&&this._chrome.setStageContent(e)}refreshChromeText(){let e=this._story?`${this._meta.title} — ${this._story}`:this._meta.title;this._chrome.setChromeText(e,this._meta.description??``)}};const a=[`system`,`light`,`dark`];var StorybookSettings=class{constructor(e=()=>!1){this._colorScheme=`system`,this._accentMode=`system`,this._accent=`blue`,this._listeners=new Set,this._systemDark=e}get colorScheme(){return this._colorScheme}set colorScheme(e){!a.includes(e)||e===this._colorScheme||(this._colorScheme=e,this._notify())}get accentMode(){return this._accentMode}set accentMode(e){e!==this._accentMode&&(this._accentMode=e,this._notify())}get accent(){return this._accent}set accent(e){e!==this._accent&&(this._accent=e,this._notify())}get resolvedAccent(){return this._accentMode===`custom`?this._accent:null}get resolvedDark(){return this._colorScheme===`dark`?!0:this._colorScheme===`light`?!1:this._systemDark()}get state(){return{colorScheme:this._colorScheme,accentMode:this._accentMode,accent:this._accent}}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}systemChanged(){this._colorScheme===`system`&&this._notify()}_notify(){let e=this.state;for(let t of[...this._listeners])try{t(e)}catch{}}};const o={ListStories:`<method name="ListStories"><arg type="s" direction="out" name="stories_json"/></method>`,GetCurrentStory:`<method name="GetCurrentStory"><arg type="s" direction="out" name="story_json"/></method>`,OpenStory:`<method name="OpenStory"><arg type="s" direction="in" name="title"/><arg type="b" direction="out" name="opened"/></method>`,SetStoryArg:`<method name="SetStoryArg"><arg type="s" direction="in" name="name"/><arg type="s" direction="in" name="value_json"/><arg type="b" direction="out" name="applied"/></method>`,GetStoryArgs:`<method name="GetStoryArgs"><arg type="s" direction="out" name="args_json"/></method>`};function storybookDevtoolsExtension(e){let t=buildStorybookDevtoolsExtension(e.controller),n=[],r={},i={};for(let e of t.methods){let t=o[e.name];t&&n.push(t),r[e.name]=e.handler,i[e.name]=e.kind}return{methodsXml:n,handlers:r,methodKinds:i,contributeStatus:t.contributeStatus}}const s=e(import.meta.url);let c;function load$6(){return c===void 0&&(c=s(`@gjsify/node-gi/gi`).requireGi(`GLib`,`2.0`)),c}__name(load$6,`load`);var l=new Proxy(Object.create(null),{get(e,t){return load$6()[t]},has(e,t){return t in load$6()}});function variantKindFor(e,t){switch(e){case`s`:case`b`:case`i`:case`u`:case`d`:return e}if(typeof t==`string`)return`s`;if(typeof t==`boolean`)return`b`;if(typeof t==`number`)return Number.isInteger(t)?`i`:`d`;throw Error(`Cannot build a GLib.Variant from ${typeof t}`)}function buildVariant(e,t){switch(variantKindFor(e?.dup_string()??null,t)){case`s`:return l.Variant.new_string(String(t));case`b`:return l.Variant.new_boolean(!!t);case`i`:return l.Variant.new_int32(Number(t));case`u`:return l.Variant.new_uint32(Number(t));case`d`:return l.Variant.new_double(Number(t))}}function describeActions(e){return e?e.list_actions().sort((e,t)=>e.localeCompare(t)).map(t=>({name:t,enabled:e.get_action_enabled(t),parameterType:e.get_action_parameter_type(t)?.dup_string()??null,stateType:e.get_action_state_type(t)?.dup_string()??null})):[]}function activateAction(e,t,n){let r=e.get_action_parameter_type(t),i=n==null?null:buildVariant(r,n);e.activate_action(t,i)}function changeActionState(e,t,n){e.change_action_state(t,buildVariant(e.get_action_state_type(t),n))}const u=e(import.meta.url);let d;function load$5(){return d===void 0&&(d=u(`@gjsify/node-gi/gi`).requireGi(`Gdk`,`4.0`)),d}__name(load$5,`load`);var f=new Proxy(Object.create(null),{get(e,t){return load$5()[t]},has(e,t){return t in load$5()}});const p=e(import.meta.url);let m;function load$4(){return m===void 0&&(m=p(`@gjsify/node-gi/gi`).requireGi(`Gtk`,`4.0`)),m}__name(load$4,`load`);var h=new Proxy(Object.create(null),{get(e,t){return load$4()[t]},has(e,t){return t in load$4()}});const g=new Map;function swapCss(e,t){let n=f.Display.get_default();if(!n)return!1;let r=g.get(e);return r||(r=new h.CssProvider,h.StyleContext.add_provider_for_display(n,r,h.STYLE_PROVIDER_PRIORITY_USER+1),g.set(e,r)),r.load_from_string(t),!0}function dumpCss(){return{providers:[...g.keys()]}}const _=`org.gjsify.Devtools`;function formatDbusErrorMessage(e,t){return`${e}: ${t}`}const v={GetStatus:`read-only`,Screenshot:`read-only`,ListActions:`read-only`,ActivateAction:`mutating`,ChangeActionState:`mutating`,PresentWindow:`read-only`,ResizeWindow:`mutating`,ListToplevels:`read-only`,DumpTree:`read-only`,GetProperty:`read-only`,GetFocused:`read-only`,ActivateWidget:`mutating`,DumpGSettings:`read-only`,DumpCss:`read-only`,SwapCss:`mutating`};function sanitizeInstanceId(e){let t=e.toLowerCase().replace(/[^a-z0-9]/g,``);return/^[a-z]/.test(t)?t:`i${t||`0`}`}function appIdToObjectPath(e){return`/${e.replace(/\./g,`/`).replace(/-/g,`_`)}`}function resolveBusAddress(e,t){let n=appIdToObjectPath(e),r=t&&t!=="default"?sanitizeInstanceId(t):`default`;return r==="default"?{busName:e,objectPath:`${n}/devtools`,instance:`default`}:{busName:`${e}.${r}`,objectPath:`${n}/${r}/devtools`,instance:r}}const y=`GJSIFY_DEVTOOLS_ADDRESS`;function isDevtoolsEnabledValue(e){if(e==null)return!1;let t=e.toLowerCase();return t!==``&&t!==`0`&&t!==`false`}function devtoolsAddressFilePath(e,t,n){let{busName:r}=resolveBusAddress(t,n);return`${e}/gjsify-devtools/${r}.address`}function buildDevtoolsIfaceXml(e=[]){return`<node>
|
|
1
|
+
import{createRequire as e}from"node:module";import"@gjsify/node-gi/globals";import t from"@gjsify/node-gi/system";var n=Object.defineProperty,__name=(e,t)=>n(e,`name`,{value:t,configurable:!0}),__exportAll=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r};const r=[`Overview`,`Presentation`,`Boxed Lists`,`Controls`,`Buttons`,`Layout`,`View Switching`,`Navigation`,`Feedback`];function orderCategories(e){let t=new Map(r.map((e,t)=>[e,t])),n=[...e].filter(e=>t.has(e));n.sort((e,n)=>t.get(e)-t.get(n));let i=e.filter(e=>!t.has(e));return[...n,...i]}var StoryRegistry=class{constructor(){this.modules=[]}registerStory(e){if(!e||!Array.isArray(e.stories)){console.warn(`Invalid story module provided to registerStory`);return}this.modules.push(e)}registerStories(e){if(!Array.isArray(e)){console.warn(`Invalid story modules array provided to registerStories`);return}let t=e.filter(e=>e&&Array.isArray(e.stories));this.modules.push(...t)}getStories(){return[...this.modules]}createStoryInstances(){for(let e of this.modules)this.instantiateStoriesForModule(e);return[...this.modules]}instantiateStoriesForModule(e){e.instances=[];let t=e.decorators??[];for(let n of e.stories)try{let r=new n,build=()=>{typeof r.initialize==`function`&&r.initialize()};t.reduceRight((e,t)=>()=>t(e,r),build)(),e.instances.push(r)}catch(e){console.error(`Failed to instantiate story: ${n.name||`Unknown`}`,e)}}},StorybookController=class{constructor(e,t){this._registry=new StoryRegistry,this._activeStory=null,this._unsubArgs=null,this._view=e,this._buildControls=t}mount(e,t=!0){this._registry.registerStories(e);let n=this._registry.createStoryInstances(),r=this._groupByCategory(n);if(this._view.renderSidebar(r,e=>this.select(e)),t){let e=r[0]?.stories[0]?.instance??null;e&&this.select(e)}}select(e){this._view.setPreviewTitle(`${e.meta.title} — ${e.story}`),this._view.showPreview(e),this._view.markSelected(e.meta.title),this._wireControls(e),this._activeStory=e}_wireControls(e){this._unsubArgs&&=(this._unsubArgs(),null);let t=this._buildControls(e),n=t.map(e=>e.refresh);this._view.renderControls(t),this._unsubArgs=e.onArgsChanged(e=>{for(let t of n)t(e)})}_groupByCategory(e){let t=new Map;for(let n of e)for(let e of n.instances??[]){let n=e.meta.title.split(`/`),r=n[0],i=n.length>1?n[1]:e.meta.title;t.has(r)||t.set(r,[]),t.get(r).push({instance:e,name:i||`Unnamed`})}return orderCategories([...t.keys()]).map(e=>({category:e,stories:t.get(e)}))}get activeStory(){return this._activeStory}listStories(){return this._registry.getStories().flatMap(e=>(e.instances??[]).map(e=>({title:e.meta.title,story:e.story,category:e.meta.title.split(`/`)[0],controls:e.meta.controls??[]})))}openStoryByTitle(e){let t=this._findByTitle(e);return t?(this.select(t),!0):!1}getCurrentStory(){let e=this._activeStory;return e?{title:e.meta.title,story:e.story,args:e.args}:null}setActiveArg(e,t){let n=this._activeStory;return n?(n.setArg(e,t),!0):!1}_findByTitle(e){for(let t of this._registry.getStories())for(let n of t.instances??[])if(n.meta.title===e)return n;return null}};let i=function(e){return e.TEXT=`text`,e.NUMBER=`number`,e.BOOLEAN=`boolean`,e.SELECT=`select`,e.RANGE=`range`,e.COLOR=`color`,e}({});function isStoryModule(e){return typeof e==`object`&&!!e&&Array.isArray(e.stories)}function argsFromControls(e=[]){let t={};for(let n of e)t[n.name]=defaultFor(n);return t}function defaultFor(e){if(e.defaultValue!==void 0)return e.defaultValue;switch(e.type){case`text`:return``;case`color`:return`#000000`;case`boolean`:return!1;case`number`:case`range`:return e.min??0;case`select`:return e.options[0]?.value??null;default:return null}}function controlLabel(e){return e.label||e.name}function bindControl(e,t,n){let r=t.name,a=t.description;switch(t.type){case i.TEXT:{let i=n.text(controlLabel(t),a),o=e.args[r];return i.set(typeof o==`string`?o:``),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=typeof e[r]==`string`?e[r]:``;i.get()!==t&&i.set(t)}}}case i.COLOR:{let i=n.color(controlLabel(t),a),o=e.args[r];return i.set(typeof o==`string`?o:`#000000`),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=typeof e[r]==`string`?e[r]:`#000000`;i.get()!==t&&i.set(t)}}}case i.BOOLEAN:{let i=n.boolean(controlLabel(t),a);return i.set(!!e.args[r]),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=!!e[r];i.get()!==t&&i.set(t)}}}case i.NUMBER:{let i=n.number(t),a=e.args[r];return i.set(typeof a==`number`?a:t.min??0),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=typeof e[r]==`number`?e[r]:0;i.get()!==t&&i.set(t)}}}case i.RANGE:{let i=n.range(t),a=e.args[r],o=typeof a==`number`?a:t.min??0;return i.set(o),i.onChange(t=>e.setArg(r,t)),{view:i.node,refresh:e=>{let t=typeof e[r]==`number`?e[r]:o;i.get()!==t&&i.set(t)}}}case i.SELECT:{let i=t.options;if(!i?.length)return console.warn(`SELECT control "${r}" has no options`),null;let a=n.select(t),o=e.args[r],s=Math.max(0,i.findIndex(e=>e.value===o));return a.set(s),a.onChange(t=>{t>=0&&t<i.length&&e.setArg(r,i[t].value)}),{view:a.node,refresh:e=>{let t=e[r],n=i.findIndex(e=>e.value===t);n>=0&&a.get()!==n&&a.set(n)}}}default:return console.warn(`Unsupported control type: ${t.type}`),null}}function buildStorybookDevtoolsExtension(e){let currentStory=()=>e.getCurrentStory();return{methods:[{name:`ListStories`,kind:`read-only`,handler:(()=>JSON.stringify(e.listStories(),null,2))},{name:`GetCurrentStory`,kind:`read-only`,handler:(()=>JSON.stringify(currentStory(),null,2))},{name:`OpenStory`,kind:`mutating`,handler:(t=>e.openStoryByTitle(t))},{name:`SetStoryArg`,kind:`mutating`,handler:((t,n)=>e.setActiveArg(t,n?JSON.parse(n):null))},{name:`GetStoryArgs`,kind:`read-only`,handler:(()=>JSON.stringify(currentStory()?.args??{},null,2))}],contributeStatus:()=>{let t=currentStory(),n=e.listStories();return{storybook:{currentStory:t?{title:t.title,story:t.story}:null,storyCount:n.length}}}}}function collectStoryModules$1(e){let t=[];for(let n of e)if(!(!n||typeof n!=`object`))for(let e of Object.values(n))isStoryModule(e)&&t.push(e);return t}__name(collectStoryModules$1,`collectStoryModules`);var StoryViewBase=class{constructor(){this._listeners=new Set}initBase(e,t,n){this._meta=e,this._story=t,this._args=argsFromControls(e.controls),this._chrome=this.createChrome(e,n),this.refreshChromeText()}get meta(){return this._meta}get story(){return this._story}get args(){return this._args}get root(){return this._chrome.root}set args(e){this._args!==e&&(this._args=e,this.updateArgs(e),this.emitArgs(e))}emitArgs(e){for(let t of this._listeners)t(e)}onArgsChanged(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}setArg(e,t){this.args={...this._args,[e]:t}}initialize(){}updateArgs(e){}teardown(){}addContent(e){this._chrome.hasStage&&this._chrome.setStageContent(e)}refreshChromeText(){let e=this._story?`${this._meta.title} — ${this._story}`:this._meta.title;this._chrome.setChromeText(e,this._meta.description??``)}};const a=[`system`,`light`,`dark`];var StorybookSettings=class{constructor(e=()=>!1){this._colorScheme=`system`,this._accentMode=`system`,this._accent=`blue`,this._listeners=new Set,this._systemDark=e}get colorScheme(){return this._colorScheme}set colorScheme(e){!a.includes(e)||e===this._colorScheme||(this._colorScheme=e,this._notify())}get accentMode(){return this._accentMode}set accentMode(e){e!==this._accentMode&&(this._accentMode=e,this._notify())}get accent(){return this._accent}set accent(e){e!==this._accent&&(this._accent=e,this._notify())}get resolvedAccent(){return this._accentMode===`custom`?this._accent:null}get resolvedDark(){return this._colorScheme===`dark`?!0:this._colorScheme===`light`?!1:this._systemDark()}get state(){return{colorScheme:this._colorScheme,accentMode:this._accentMode,accent:this._accent}}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}systemChanged(){this._colorScheme===`system`&&this._notify()}_notify(){let e=this.state;for(let t of[...this._listeners])try{t(e)}catch{}}};const o={ListStories:`<method name="ListStories"><arg type="s" direction="out" name="stories_json"/></method>`,GetCurrentStory:`<method name="GetCurrentStory"><arg type="s" direction="out" name="story_json"/></method>`,OpenStory:`<method name="OpenStory"><arg type="s" direction="in" name="title"/><arg type="b" direction="out" name="opened"/></method>`,SetStoryArg:`<method name="SetStoryArg"><arg type="s" direction="in" name="name"/><arg type="s" direction="in" name="value_json"/><arg type="b" direction="out" name="applied"/></method>`,GetStoryArgs:`<method name="GetStoryArgs"><arg type="s" direction="out" name="args_json"/></method>`};function storybookDevtoolsExtension(e){let t=buildStorybookDevtoolsExtension(e.controller),n=[],r={},i={};for(let e of t.methods){let t=o[e.name];t&&n.push(t),r[e.name]=e.handler,i[e.name]=e.kind}return{methodsXml:n,handlers:r,methodKinds:i,contributeStatus:t.contributeStatus}}const s=e(import.meta.url);let c;function load$6(){return c===void 0&&(c=s(`@gjsify/node-gi/gi`).requireGi(`GLib`,`2.0`)),c}__name(load$6,`load`);var l=new Proxy(Object.create(null),{get(e,t){return load$6()[t]},has(e,t){return t in load$6()}});function variantKindFor(e,t){switch(e){case`s`:case`b`:case`i`:case`u`:case`d`:return e}if(typeof t==`string`)return`s`;if(typeof t==`boolean`)return`b`;if(typeof t==`number`)return Number.isInteger(t)?`i`:`d`;throw Error(`Cannot build a GLib.Variant from ${typeof t}`)}function buildVariant(e,t){switch(variantKindFor(e?.dup_string()??null,t)){case`s`:return l.Variant.new_string(String(t));case`b`:return l.Variant.new_boolean(!!t);case`i`:return l.Variant.new_int32(Number(t));case`u`:return l.Variant.new_uint32(Number(t));case`d`:return l.Variant.new_double(Number(t))}}function describeActions(e){return e?e.list_actions().sort((e,t)=>e.localeCompare(t)).map(t=>({name:t,enabled:e.get_action_enabled(t),parameterType:e.get_action_parameter_type(t)?.dup_string()??null,stateType:e.get_action_state_type(t)?.dup_string()??null})):[]}function activateAction(e,t,n){let r=e.get_action_parameter_type(t),i=n==null?null:buildVariant(r,n);e.activate_action(t,i)}function changeActionState(e,t,n){e.change_action_state(t,buildVariant(e.get_action_state_type(t),n))}const u=e(import.meta.url);let d;function load$5(){return d===void 0&&(d=u(`@gjsify/node-gi/gi`).requireGi(`Gdk`,`4.0`)),d}__name(load$5,`load`);var f=new Proxy(Object.create(null),{get(e,t){return load$5()[t]},has(e,t){return t in load$5()}});const p=e(import.meta.url);let m;function load$4(){return m===void 0&&(m=p(`@gjsify/node-gi/gi`).requireGi(`Gtk`,`4.0`)),m}__name(load$4,`load`);var h=new Proxy(Object.create(null),{get(e,t){return load$4()[t]},has(e,t){return t in load$4()}});const g=new Map;function swapCss(e,t){let n=f.Display.get_default();if(!n)return!1;let r=g.get(e);return r||(r=new h.CssProvider,h.StyleContext.add_provider_for_display(n,r,h.STYLE_PROVIDER_PRIORITY_USER+1),g.set(e,r)),r.load_from_string(t),!0}function dumpCss(){return{providers:[...g.keys()]}}const _=`org.gjsify.Devtools`;function formatDbusErrorMessage(e,t){return`${e}: ${t}`}const v={GetStatus:`read-only`,Screenshot:`read-only`,ListActions:`read-only`,ActivateAction:`mutating`,ChangeActionState:`mutating`,PresentWindow:`read-only`,ResizeWindow:`mutating`,ListToplevels:`read-only`,DumpTree:`read-only`,GetProperty:`read-only`,GetFocused:`read-only`,FindWidget:`read-only`,SendKey:`mutating`,ActivateWidget:`mutating`,DumpGSettings:`read-only`,DumpCss:`read-only`,SwapCss:`mutating`};function sanitizeInstanceId(e){let t=e.toLowerCase().replace(/[^a-z0-9]/g,``);return/^[a-z]/.test(t)?t:`i${t||`0`}`}function appIdToObjectPath(e){return`/${e.replace(/\./g,`/`).replace(/-/g,`_`)}`}function resolveBusAddress(e,t){let n=appIdToObjectPath(e),r=t&&t!=="default"?sanitizeInstanceId(t):`default`;return r==="default"?{busName:e,objectPath:`${n}/devtools`,instance:`default`}:{busName:`${e}.${r}`,objectPath:`${n}/${r}/devtools`,instance:r}}const y=`GJSIFY_DEVTOOLS_ADDRESS`;function isDevtoolsEnabledValue(e){if(e==null)return!1;let t=e.toLowerCase();return t!==``&&t!==`0`&&t!==`false`}function devtoolsAddressFilePath(e,t,n){let{busName:r}=resolveBusAddress(t,n);return`${e}/gjsify-devtools/${r}.address`}function buildDevtoolsIfaceXml(e=[]){return`<node>
|
|
2
2
|
<interface name="${_}">
|
|
3
3
|
<method name="GetStatus">
|
|
4
4
|
<arg type="s" direction="out" name="status_json"/>
|
|
@@ -47,6 +47,15 @@ import{createRequire as e}from"node:module";import"@gjsify/node-gi/globals";impo
|
|
|
47
47
|
<arg type="s" direction="in" name="path"/>
|
|
48
48
|
<arg type="b" direction="out" name="activated"/>
|
|
49
49
|
</method>
|
|
50
|
+
<method name="FindWidget">
|
|
51
|
+
<arg type="s" direction="in" name="selector"/>
|
|
52
|
+
<arg type="s" direction="out" name="path"/>
|
|
53
|
+
</method>
|
|
54
|
+
<method name="SendKey">
|
|
55
|
+
<arg type="s" direction="in" name="accelerator"/>
|
|
56
|
+
<arg type="s" direction="in" name="path"/>
|
|
57
|
+
<arg type="b" direction="out" name="delivered"/>
|
|
58
|
+
</method>
|
|
50
59
|
<method name="DumpGSettings">
|
|
51
60
|
<arg type="s" direction="in" name="schema_id"/>
|
|
52
61
|
<arg type="s" direction="out" name="settings_json"/>
|
|
@@ -61,7 +70,7 @@ import{createRequire as e}from"node:module";import"@gjsify/node-gi/globals";impo
|
|
|
61
70
|
</method>${e.length>0?`\n${e.join(`
|
|
62
71
|
`)}`:``}
|
|
63
72
|
</interface>
|
|
64
|
-
</node>`}const ee=e(import.meta.url);let b;function load$3(){return b===void 0&&(b=ee(`@gjsify/node-gi/gi`).requireGi(`Gio`,`2.0`)),b}__name(load$3,`load`);var x=new Proxy(Object.create(null),{get(e,t){return load$3()[t]},has(e,t){return t in load$3()}});function isWin32(){return l.DIR_SEPARATOR===92}function defaultListenAddress(){return isWin32()?`nonce-tcp:host=127.0.0.1`:`unix:tmpdir=${l.get_tmp_dir()}`}var DevtoolsPeerServerError=class extends Error{constructor(e,t,n,r){super(e),this.address=t,this.reason=n,this.name=`DevtoolsPeerServerError`,this.cause=r}};function isAddressInUse(e){return e instanceof l.Error&&e.matches(x.io_error_quark(),x.IOErrorEnum.ADDRESS_IN_USE)}function unixSocketPath(e){if(!e.startsWith(`unix:`))return null;for(let t of e.slice(5).split(`,`)){let e=t.indexOf(`=`);if(!(e<0||t.slice(0,e)!==`path`))try{return decodeURIComponent(t.slice(e+1))}catch{return null}}return null}function inspectExistingSocket(e){try{if((x.File.new_for_path(e).query_info(`unix::mode`,x.FileQueryInfoFlags.NONE,null).get_attribute_uint32(`unix::mode`)&61440)!=49152)return`not-a-socket`}catch{return`not-a-socket`}let t=new x.SocketClient;t.set_timeout(2);let n;try{n=t.connect(x.UnixSocketAddress.new(e),null)}catch{return`dead`}return n.close(null),`live`}function clearReclaimableSocket(e){let t=unixSocketPath(e);if(!t||!l.file_test(t,l.FileTest.EXISTS))return;let n=inspectExistingSocket(t);if(n===`live`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: another process is already listening there. Stop it, or point ${y} (or options.address) at a different socket — GJSIFY_DEVTOOLS_INSTANCE=<label> lets two devtools-enabled apps run side by side.`,e,`address-in-use`);if(n===`not-a-socket`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} already exists and is not a socket, so it will NOT be removed. Point ${y} (or options.address) at a free path.`,e,`occupied-by-other-file`);try{x.File.new_for_path(t).delete(null)}catch(n){throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} is a socket nothing listens on, but removing it failed (${n}). Delete it by hand, or point ${y} at a free path.`,e,`address-in-use`,n)}console.log(`[gjsify-devtools] reclaimed the stale socket ${t}: nothing was listening on it (an abnormal exit — Ctrl-C, SIGKILL, a crash — leaves the inode behind).`)}function flagsForAddress(e){return e.startsWith(`tcp:`)||e.startsWith(`nonce-tcp:`)?x.DBusServerFlags.NONE:x.DBusServerFlags.AUTHENTICATION_REQUIRE_SAME_USER}function startDevtoolsPeerServer(e,t,n){let r=n&&n!==``?n:defaultListenAddress();clearReclaimableSocket(r);let i;try{i=x.DBusServer.new_sync(r,flagsForAddress(r),x.dbus_generate_guid(),null,null)}catch(e){let t=isAddressInUse(e);throw new DevtoolsPeerServerError(t?`cannot listen on ${r}: the address is already in use (${e}). Stop whatever holds it, or point ${y} (or options.address) at a different address.`:`cannot listen on ${r}: ${e}. Check the address form — \`unix:path=/tmp/app.sock\`, \`unix:tmpdir=/tmp\` or \`nonce-tcp:host=127.0.0.1\`.`,r,t?`address-in-use`:`listen-failed`,e)}let a=new Set;i.connect(`new-connection`,(n,r)=>(a.add(r),r.connect(`closed`,()=>{e.unexport(r),a.delete(r)}),e.export(r,t),!0)),i.start();let o=!1;return{address:i.get_client_address(),objectPath:t,get connectionCount(){return a.size},stop(){if(!o){o=!0,i.stop();for(let t of a)e.unexport(t),!t.is_closed()&&t.close(null,(e,t)=>{try{e.close_finish(t)}catch{}});a.clear()}}}}function writeDevtoolsAddressFile(e,t){try{if(l.mkdir_with_parents(l.path_get_dirname(e),448),!l.file_set_contents(e,`${t}\n`))return null}catch(t){return console.error(`[gjsify-devtools] could not publish the peer address to ${e}: ${t}`),null}try{x.File.new_for_path(e).set_attribute_uint32(`unix::mode`,384,x.FileQueryInfoFlags.NONE,null)}catch(t){console.error(`[gjsify-devtools] could not restrict ${e} to the current user: ${t}`)}return e}function removeDevtoolsAddressFile(e){try{x.File.new_for_path(e).delete(null)}catch{}}const te=e(import.meta.url);let S;function load$2(){return S===void 0&&(S=te(`@gjsify/node-gi/gi`).requireGi(`Graphene`,`1.0`)),S}__name(load$2,`load`);var ne=new Proxy(Object.create(null),{get(e,t){return load$2()[t]},has(e,t){return t in load$2()}});function captureWidgetPng(e){let t=e.get_native()?.get_renderer();if(!t)return null;let n=e.get_width(),r=e.get_height();if(n<=0||r<=0)return null;let i=h.WidgetPaintable.new(e),a=h.Snapshot.new();i.snapshot(a,n,r);let o=a.to_node();if(!o)return null;let s=new ne.Rect;s.init(0,0,n,r);let c=t.render_texture(o,s).save_to_png_bytes().get_data();return c?new Uint8Array(c):null}function dumpGSettings(e){let t=x.SettingsSchemaSource.get_default()?.lookup(e,!0);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`GSettings schema '${e}' is not installed`));let n=new x.Settings({settings_schema:t}),r={};for(let e of t.list_keys())r[e]=n.get_value(e).recursiveUnpack();return r}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){let t=e;return typeof t.$typeName==`string`&&t.$typeName.length>0?t.$typeName:t.constructor?.$gtype?.name??`GtkWidget`}function activateWidget(e){let t=e;if(typeof t.activate==`function`&&t.activate()===!0)return!0;let n=typeof t.get_parent==`function`?t.get_parent():null;if(n&&widgetType(n)===`GtkListBox`){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 nthChild(e,t){let n=e.get_first_child(),r=0;for(;n&&r<t;)n=n.get_next_sibling(),r++;return r===t?n:null}function listToplevels(){let e=h.Window.get_toplevels(),t=e.get_n_items(),n=[];for(let r=0;r<t;r++){let t=e.get_item(r);t&&n.push({path:`toplevel:${r}`,type:widgetType(t),title:t.get_title?.()??null,mapped:t.get_mapped(),focused:t.is_active??!1})}return n}function resolveWidgetPath(e){let t=parseWidgetPath(e);if(!t)return null;let n=h.Window.get_toplevels().get_item(t.toplevel);if(!n)return null;for(let e of t.children)if(n=nthChild(n,e),!n)return null;return n}function 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:[]};if(t<=0)return r;let i=e.get_first_child(),a=0;for(;i;)r.children.push(dumpTree(i,t-1,`${n}/child:${a}`)),i=i.get_next_sibling(),a++;return r}function jsonSafe(e){let t=typeof e;return e==null||t===`string`||t===`number`||t===`boolean`?e??null:`[${t}]`}function getWidgetProperty(e,t){let n=e,r=t.replace(/-/g,`_`),i=t.replace(/[-_]([a-z])/g,(e,t)=>t.toUpperCase());for(let e of[t,r,i])if(e in n)return jsonSafe(n[e])}function childIndex(e,t){let n=e.get_first_child(),r=0;for(;n;){if(n===t)return r;n=n.get_next_sibling(),r++}return-1}function pathOfWidget(e){let t=[],n=e,r=n.get_parent();for(;r;){let e=childIndex(r,n);if(e<0)return null;t.unshift(e),n=r,r=n.get_parent()}let i=h.Window.get_toplevels(),a=i.get_n_items();for(let e=0;e<a;e++)if(i.get_item(e)===n)return buildWidgetPath(e,t);return null}function isActiveWindowScope(e){return!e||e===`window`||e===`active`}function frameDelay(e){return new Promise(t=>{l.timeout_add(l.PRIORITY_DEFAULT,e,()=>(t(),l.SOURCE_REMOVE))})}async function captureWidgetWhenRenderable(e,t=12,n=50){for(let r=0;r<t;r++){let t=captureWidgetPng(e);if(t)return t;await frameDelay(n)}return captureWidgetPng(e)}var DevtoolsService=class{constructor(e,t){this._app=e,this._options=t,this._exported=new Map,this._peer=null,this._addressFile=null,this._kinds=new Map,this._extensions=t.extend??[];for(let[e,t]of Object.entries(v))this._kinds.set(e,t);for(let e of this._extensions){for(let[t,n]of Object.entries(e.methodKinds))this._kinds.set(t,n);for(let[t,n]of Object.entries(e.handlers)){let e=n;this[t]=(...n)=>(this._guard(t),e(...n))}}}export(e,t){if(this._exported.has(e))return;let n=buildDevtoolsIfaceXml(this._extensions.flatMap(e=>e.methodsXml??[])),r=x.DBusExportedObject.wrapJSObject(n,this);r.export(e,t),this._exported.set(e,r)}unexport(e){if(e){this._exported.get(e)?.unexport(),this._exported.delete(e);return}for(let e of this._exported.values())e.unexport();this._exported.clear(),this._peer?.stop(),this._peer=null,this._addressFile&&=(removeDevtoolsAddressFile(this._addressFile),null)}attachPeerServer(e,t){this._peer=e,this._addressFile=t??null}get peerAddress(){return this._peer?.address??null}get addressFile(){return this._addressFile}GetStatus(){let e=this._app.get_active_window(),t={appId:this._app.get_application_id()??`unknown`,instance:this._options.instance??`default`,activeWindow:e?{id:e.get_name()||`window`,title:e.get_title()??``,mapped:e.get_mapped()}:null,toplevelCount:h.Window.get_toplevels().get_n_items(),focusedWidget:null,paused:this._isPaused()};for(let e of this._extensions){let n=e.contributeStatus?.();n&&Object.assign(t,n)}return JSON.stringify(t)}async ScreenshotAsync(e,t){try{let n=typeof e?.[0]==`string`?e[0]:``,r=await this._captureScopePng(n);t.return_value(new l.Variant(`(ay)`,[r]))}catch(e){t.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e){let t=this._resolveRootWidget(e);if(!t){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let n=captureWidgetPng(t.widget);if(!n){let e=t.widget.get_root();e instanceof h.Window&&e.present(),n=await captureWidgetWhenRenderable(t.widget)}return n??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:8,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)}DumpGSettings(e){return JSON.stringify(dumpGSettings(e))}DumpCss(){return JSON.stringify(dumpCss())}SwapCss(e,t){return this._guard(`SwapCss`),swapCss(e,t)}_resolveRootWidget(e){if(isActiveWindowScope(e)){let e=this._app.get_active_window();return e?{widget:e,path:pathOfWidget(e)??`toplevel:0`}:null}let t=resolveWidgetPath(e);return t?{widget:t,path:e}:null}_isPaused(){return this._options.paused?.()??!1}_guard(e){let t=this._kinds.get(e);if(!t)throw Error(formatDbusErrorMessage(`internal`,`unclassified devtools method '${e}'`));if(t===`mutating`&&this._isPaused())throw Error(formatDbusErrorMessage(`paused`,`${e} rejected — external control is paused. Read-only methods keep working.`))}_scope(e){return e===`app`?`app`:`win`}_actionGroup(e){if(e===`app`)return this._app;if(this._options.winActionGroup)return this._options.winActionGroup;let t=this._app.get_active_window();return t instanceof h.ApplicationWindow?t:null}_requireGroup(e,t){let n=this._actionGroup(e);if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no '${e}' action group`));if(!n.has_action(t))throw Error(formatDbusErrorMessage(`not-found`,`unknown action ${e}.${t}`));return n}_parseValue(e){if(!e||e===`null`)return null;try{return JSON.parse(e)}catch{throw Error(formatDbusErrorMessage(`invalid-params`,`value_json is not valid JSON: ${e}`))}}};const C=`DBUS_SESSION_BUS_ADDRESS`,re=new Set;function envEnabled(){return isDevtoolsEnabledValue(l.getenv(`GJSIFY_DEVTOOLS`))}function envValue(e){let t=l.getenv(e);return t&&t!==``?t:null}function sessionBusUsable(){if(!envValue(C))return!1;try{return x.bus_get_sync(x.BusType.SESSION,null),!0}catch{return!1}}function chooseDevtoolsTransport(e){return e.requestedAddress?{kind:`peer`,address:e.requestedAddress,reason:`requested`}:e.hasAppConnection?{kind:`session-bus`}:e.sessionBusUsable?{kind:`unregistered`}:{kind:`peer`,address:null,reason:`no-session-bus`}}function describeMissingConnection(e,t){return e?t?`[gjsify-devtools] the session bus answers but this application is not registered on it yet — call installDevtools() from the GtkApplication "startup" handler (the bus connection and object path exist only after registration).`:`[gjsify-devtools] ${C} is set (${e}) but no bus answers there — using the bus-less peer transport instead. On macOS this is the usual state: Homebrew's dbus listens on launchd, so the advertised address only works while that socket is live.`:`[gjsify-devtools] this machine has no session bus (${C} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${y} on both the app and \`gjsify debug\` to pin it yourself.`}function installDevtools(e,t={}){if(!(t.enabled??envEnabled()))return null;let n=t.instance??envValue(`GJSIFY_DEVTOOLS_INSTANCE`)??void 0,r=new DevtoolsService(e,{...t,instance:n});try{return exportDevtools(e,r,t,n)}catch(e){return r.unexport(),console.error(`[gjsify-devtools] devtools stayed OFF, the app is unaffected — ${describeInstallFailure(e)}`),null}}function describeInstallFailure(e){return e instanceof DevtoolsPeerServerError||e instanceof Error?e.message:String(e)}function exportDevtools(e,t,n,r){let i=e.get_is_registered(),a=i?e.get_dbus_connection():null,o=i?e.get_dbus_object_path():null,s=envValue(C),c=!!(a&&o),u=c||sessionBusUsable(),d=chooseDevtoolsTransport({requestedAddress:n.address??envValue(y),hasAppConnection:c,sessionBusUsable:u}),f=e.get_application_id()??`unknown`,p=`${o??appIdToObjectPath(f)}/devtools`;if((d.kind===`unregistered`||d.kind===`peer`&&d.reason===`no-session-bus`)&&console.error(describeMissingConnection(s,u)),d.kind===`session-bus`&&a)t.export(a,p),console.log(`[gjsify-devtools] exported ${_} at ${p} (dest ${f})`);else if(d.kind===`peer`){let n=startDevtoolsPeerServer(t,p,d.address??void 0),i=writeDevtoolsAddressFile(devtoolsAddressFilePath(l.get_user_runtime_dir(),f,r),n.address);t.attachPeerServer(n,i),console.log(`[gjsify-devtools] exported ${_} at ${p} (peer address ${n.address}${i?`, published to ${i}`:``})`),i&&e.connect(`shutdown`,()=>removeDevtoolsAddressFile(i))}return re.add(t),t}const ie=[`AdwNavigationSplitView`,`GtkListBox`,`AdwOverlaySplitView`];function probeEnabled(){let e=l.getenv(`GJSIFY_STORYBOOK_PROBE`);if(e==null)return!1;let t=e.toLowerCase();return t!==``&&t!==`0`&&t!==`false`}function collectTypes(e,t){t.add(e.type);for(let n of e.children)collectTypes(n,t)}function installStorybookProbe(e,t,n={}){let r=n.requireChrome??ie,i=n.out??l.getenv(`GJSIFY_STORYBOOK_PROBE_OUT`)??void 0,a=n.timeoutMs??8e3,o=n.storyWidget??l.getenv(`GJSIFY_STORYBOOK_PROBE_STORY_WIDGET`)??void 0,s=t.controller.listStories(),c=[...new Set(s.map(e=>e.category))],u=n.story??l.getenv(`GJSIFY_STORYBOOK_PROBE_STORY`)??s[0]?.title,d=u?t.openStoryByTitle(u):!1,f=t.activeStory,p=new Set;collectTypes(dumpTree(t,60,`toplevel:0`),p);let m=r.filter(e=>!p.has(e)),h=new Set;f&&collectTypes(dumpTree(f,60,`story`),h);let g=h.size,_=o?h.has(o):null,finish=t=>{let n=JSON.stringify(t);if(t.ok)console.log(`STORYBOOK PROBE: PASS ${n}`);else{console.error(`STORYBOOK PROBE: FAIL ${n}`);try{typeof process<`u`&&(process.exitCode=1)}catch{}}if(i)try{l.file_set_contents(i,JSON.stringify(t,null,2))}catch{}e.quit()},v=0;l.timeout_add(l.PRIORITY_DEFAULT,100,()=>{v+=100;let e=captureWidgetPng(t),n=t.get_width()>0&&t.get_height()>0;if(!e&&!(v>=a))return l.SOURCE_CONTINUE;let i=f?captureWidgetPng(f):null,p=s.length>=1&&c.length>=1&&m.length===0&&d&&f!=null&&g>1,y;return s.length<1?y=`no stories registered`:c.length<1?y=`no categories`:m.length>0?y=`chrome missing: ${m.join(`, `)}`:!d||f==null?y=`could not open story: ${u??`(none)`}`:g<=1&&(y=`opened story rendered an empty subtree`),p&&o&&!h.has(o)&&(p=!1,y=`story widget ${o} not found in the opened story subtree`),p&&n&&(!e||e.length===0)&&(p=!1,y=`window realized (${t.get_width()}x${t.get_height()}) but the GSK capture was empty`),finish({ok:p,reason:y,stories:s.length,categories:c,opened:d,activeStory:f?f.meta.title:null,requiredChrome:r,missingChrome:m,storySubtreeWidgets:g,storyWidgetPresent:_,windowRealized:n,windowPngBytes:e?e.length:0,storyPngBytes:i?i.length:0}),l.SOURCE_REMOVE})}const ae=e(import.meta.url);let oe;function load$1(){return oe===void 0&&(oe=ae(`@gjsify/node-gi/gi`).requireGi(`Adw`,`1`)),oe}__name(load$1,`load`);var w=new Proxy(Object.create(null),{get(e,t){return load$1()[t]},has(e,t){return t in load$1()}});const T={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};T.GPL_2_0_ONLY,T.GPL_3_0_ONLY,T.UNKNOWN;const se=[`blue`,`teal`,`green`,`yellow`,`orange`,`red`,`pink`,`purple`,`slate`],ce={blue:`#3584e4`,teal:`#2190a4`,green:`#3a944a`,yellow:`#c88800`,orange:`#ed5b00`,red:`#e62d42`,pink:`#d56199`,purple:`#9141ac`,slate:`#6f8396`};function parseHex(e){let t=/^#([0-9a-f]{6})$/i.exec(e.trim());if(!t)return null;let n=Number.parseInt(t[1],16);return[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255]}function toHex(e,t,n){let channel=e=>Math.round(Math.min(1,Math.max(0,e))*255).toString(16).padStart(2,`0`);return`#${channel(e)}${channel(t)}${channel(n)}`}const toLinear=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,fromLinear=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function linearToOklab(e,t,n){let r=Math.cbrt(.4122214708*e+.5363325363*t+.0514459929*n),i=Math.cbrt(.2119034982*e+.6806995451*t+.1073969566*n),a=Math.cbrt(.0883024619*e+.2817188376*t+.6299787005*n);return[.2104542553*r+.793617785*i-.0040720468*a,1.9779984951*r-2.428592205*i+.4505937099*a,.0259040371*r+.7827717662*i-.808675766*a]}function oklabToLinear(e,t,n){let r=(e+.3963377774*t+.2158037573*n)**3,i=(e-.1055613458*t-.0638541728*n)**3,a=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*i+.2309699292*a,-1.2684380046*r+2.6097574011*i-.3413193965*a,-.0041960863*r-.7034186147*i+1.707614701*a]}function adwaitaStandaloneColor(e,t){let n=parseHex(e);if(!n)return e;let[r,i,a]=linearToOklab(toLinear(n[0]),toLinear(n[1]),toLinear(n[2])),[o,s,c]=oklabToLinear(t?Math.max(r,.85):Math.min(r,.5),i,a);return toHex(fromLinear(o),fromLinear(s),fromLinear(c))}function adwaitaAccentBgColor(e){return ce[e]}function adwaitaAccentColor(e,t){return adwaitaStandaloneColor(ce[e],t)}Math.PI*.35,Math.PI*.015,Math.PI*.9;const le=Math.PI*.9,ue=Math.PI*.7,de=Math.PI*1.1,fe=Math.PI*1.35,pe=le+de+fe-ue;53*Math.PI*2/pe,de-ue/2;const me={system:`Follow system`,light:`Light`,dark:`Dark`},he={blue:`Blue`,teal:`Teal`,green:`Green`,yellow:`Yellow`,orange:`Orange`,red:`Red`,pink:`Pink`,purple:`Purple`,slate:`Slate`};var StorybookAppearance=class{constructor(){this._provider=null,this._applying=!1,this._styleManager=w.StyleManager.get_default(),this.settings=new StorybookSettings(()=>this._styleManager.get_dark()),this.settings.subscribe(e=>this._apply(e)),this._styleManager.connect(`notify::dark`,()=>this.settings.systemChanged()),this._apply(this.settings.state)}_apply(e){if(!this._applying){this._applying=!0;try{this._styleManager.set_color_scheme(e.colorScheme===`light`?w.ColorScheme.FORCE_LIGHT:e.colorScheme===`dark`?w.ColorScheme.FORCE_DARK:w.ColorScheme.DEFAULT),this._applyAccent(this.settings.resolvedAccent)}finally{this._applying=!1}}}_applyAccent(e){let t=f.Display.get_default();if(!t)return;if(!this._provider){if(!e)return;this._provider=new h.CssProvider,h.StyleContext.add_provider_for_display(t,this._provider,h.STYLE_PROVIDER_PRIORITY_APPLICATION)}if(!e){this._provider.load_from_string(``);return}let n=adwaitaAccentBgColor(e),r=adwaitaAccentColor(e,this.settings.resolvedDark);this._provider.load_from_string(`:root { --accent-bg-color: ${n}; --accent-color: ${r}; }`)}};function buildSwatch(e,t,n){let r=new h.CheckButton({tooltip_text:t,halign:h.Align.CENTER,valign:h.Align.CENTER,focus_on_click:!1});for(let t of e)r.add_css_class(t);return r.update_property([h.AccessibleProperty.LABEL],[t]),n&&r.set_group(n),r}function buildSwatchCard(e=!1){let t=new w.WrapBox({align:.5,child_spacing:8,line_spacing:8,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),n=new w.Bin({child:t,hexpand:!0});return n.add_css_class(`card`),e&&n.add_css_class(`storybook-card-attached`),{card:n,row:t}}function buildAppearanceDialog(e){let t=e.settings,n=new w.PreferencesPage,r=new w.PreferencesGroup({title:`Style`}),{card:i,row:o}=buildSwatchCard(),s=null,c=new Map;for(let e of a){let n=buildSwatch([`storybook-swatch`,`storybook-scheme-swatch`,`storybook-scheme-${e}`],me[e],s);s??=n,n.set_active(t.colorScheme===e),n.connect(`toggled`,()=>{n.get_active()&&(t.colorScheme=e)}),c.set(e,n),o.append(n)}r.add(i),n.add(r);let l=new w.PreferencesGroup({title:`Accent colour`});l.add_css_class(`storybook-attached-group`);let u=new w.SwitchRow({title:`Use a custom accent colour`,subtitle:`Off follows the desktop, which owns the accent`,active:t.accentMode===`custom`});l.add(u);let{card:d,row:f}=buildSwatchCard(!0),p=null,m=new Map;for(let e of se){let n=buildSwatch([`storybook-swatch`],he[e],p);p??=n,n.set_active(t.accent===e);let r=new h.CssProvider;r.load_from_string(`checkbutton { background-color: ${adwaitaAccentBgColor(e)}; }`),n.get_style_context().add_provider(r,h.STYLE_PROVIDER_PRIORITY_APPLICATION),n.connect(`toggled`,()=>{n.get_active()&&(t.accent=e)}),m.set(e,n),f.append(n)}f.set_sensitive(t.accentMode===`custom`),u.connect(`notify::active`,()=>{t.accentMode=u.get_active()?`custom`:`system`}),l.add(d),n.add(l),t.subscribe(e=>{let t=c.get(e.colorScheme);t&&!t.get_active()&&t.set_active(!0);let n=m.get(e.accent);n&&!n.get_active()&&n.set_active(!0);let r=e.accentMode===`custom`;u.get_active()!==r&&u.set_active(r),f.set_sensitive(r)});let g=new w.PreferencesDialog({title:`Appearance`});return g.add(n),g}const ge=e(import.meta.url);let E;function load(){return E===void 0&&(E=ge("@gjsify/node-gi/gi").requireGi(`GObject`,`2.0`)),E}var D=new Proxy(Object.create(null),{get(e,t){return load()[t]},has(e,t){return t in load()}});function adwControlWidgetFactory(){return{text(e,t){let n=new w.EntryRow({title:e});t&&n.set_tooltip_text(t);let r=null;return n.connect(`changed`,()=>r?.(n.get_text())),{node:n,get:()=>n.get_text(),set:e=>n.set_text(e),onChange:e=>{r=e}}},boolean(e,t){let n=new w.SwitchRow({title:e,subtitle:t??``}),r=null;return n.connect(`notify::active`,()=>r?.(n.get_active())),{node:n,get:()=>n.get_active(),set:e=>n.set_active(e),onChange:e=>{r=e}}},number(e){let t=w.SpinRow.new_with_range(e.min??0,e.max??100,e.step??1);t.set_title(e.label||e.name),e.description&&t.set_subtitle(e.description);let n=null;return t.connect(`changed`,()=>n?.(t.get_value())),{node:t,get:()=>t.get_value(),set:e=>t.set_value(e),onChange:e=>{n=e}}},range(e){return buildRangeWidget(e)},select(e){return buildSelectWidget(e)},color(e,t){return buildColorWidget(e,t)}}}function buildRangeWidget(e){let t=e.min??0,n=e.max??100,r=e.step??1,i=typeof e.min==`number`?e.min:0,a=Number.isInteger(r)&&Number.isInteger(i),o=new h.Adjustment({lower:t,upper:n,step_increment:r,value:i});o.step_increment=r;let s=new h.ListBoxRow({selectable:!1,activatable:!1});s.add_css_class(`story-range-row`);let c=new h.Box({orientation:h.Orientation.VERTICAL,spacing:6,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),l=new h.Box({orientation:h.Orientation.HORIZONTAL,spacing:12}),u=new h.Label({label:e.label||e.name,halign:h.Align.START,hexpand:!0,ellipsize:3});u.add_css_class(`heading`);let formatValue=e=>a?String(Math.round(e)):e.toFixed(2),d=new h.Label({label:formatValue(i),halign:h.Align.END});if(d.add_css_class(`numeric`),d.add_css_class(`dim-label`),l.append(u),l.append(d),c.append(l),e.description){let t=new h.Label({label:e.description,halign:h.Align.START,xalign:0,wrap:!0,max_width_chars:32});t.add_css_class(`caption`),t.add_css_class(`dim-label`),c.append(t)}let f=new h.Scale({orientation:h.Orientation.HORIZONTAL,adjustment:o,draw_value:!1,hexpand:!0}),p=null,m=!1;return f.connect(`value-changed`,()=>{if(m)return;let e=f.get_value();if(a){let t=Math.round(e);if(t!==e){f.set_value(t);return}e=t}d.set_label(formatValue(e)),p?.(e)}),c.append(f),s.set_child(c),{node:s,get:()=>f.get_value(),set:e=>{m=!0,f.set_value(e),m=!1,d.set_label(formatValue(e))},onChange:e=>{p=e}}}function buildSelectWidget(e){let t=e.options??[],n=h.StringList.new(t.map(e=>e.label)),r=new w.ComboRow({title:e.label||e.name,subtitle:e.description??``,model:n}),i=null;return r.connect(`notify::selected`,()=>i?.(r.get_selected())),{node:r,get:()=>r.get_selected(),set:e=>r.set_selected(e),onChange:e=>{i=e}}}function buildColorWidget(e,t){let n=new w.ActionRow({title:e,subtitle:t??``}),r=new h.ColorDialogButton({dialog:new h.ColorDialog({title:e}),valign:h.Align.CENTER});n.add_suffix(r),n.set_activatable_widget(r);let channel=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,`0`),rgbaToHex=e=>`#${channel(e.red)}${channel(e.green)}${channel(e.blue)}`,i=null,a=!1;return r.connect(`notify::rgba`,()=>{a||i?.(rgbaToHex(r.get_rgba()))}),{node:n,get:()=>rgbaToHex(r.get_rgba()),set:e=>{let t=new f.RGBA;t.parse(e)&&(a=!0,r.set_rgba(t),a=!1)},onChange:e=>{i=e}}}var _e=class StorybookWindow extends w.ApplicationWindow{static{D.registerClass({GTypeName:`StorybookWindow`},StorybookWindow)}constructor(e){super(e),this._appearance=new StorybookAppearance,this._controlRows=[],this._rowByTitle=new Map,this._onSelect=null,this._suppressSelect=!1,this.set_default_size(1200,800),this.set_size_request(360,320),this.set_title(`Storybook`),this._buildUI(),this._controller=new StorybookController(this,e=>this._buildControls(e)),this._sidebar_list.connect(`row-selected`,this._onRowSelected.bind(this)),this._show_controls_button.connect(`toggled`,this._onToggleControls.bind(this)),this._controls_split_view.set_show_sidebar(!0)}_onRowSelected(e,t){if(this._suppressSelect||!t)return;let n=t;n.storyWidget&&this._onSelect?.(n.storyWidget)}get controller(){return this._controller}_buildControls(e){let t=e.meta.controls;if(!Array.isArray(t))return[];let n=adwControlWidgetFactory(),r=[];for(let i of t){if(!i?.name||!i?.type){console.warn(`Invalid control configuration:`,i);continue}let t=bindControl(e,i,n);t&&r.push(t)}return r}_buildUI(){this._sidebar_list=new h.ListBox({selection_mode:h.SelectionMode.SINGLE}),this._sidebar_list.add_css_class(`navigation-sidebar`);let e=new h.ScrolledWindow({hexpand:!0,vexpand:!0,child:this._sidebar_list}),t=new w.HeaderBar({title_widget:new w.WindowTitle({title:`Stories`}),show_end_title_buttons:!1}),n=new w.ToolbarView({content:e,top_bar_style:w.ToolbarStyle.FLAT});n.add_top_bar(t);let r=new w.NavigationPage({title:`Stories`,tag:`stories`,child:n});this._content_area=new w.Bin({hexpand:!0,vexpand:!0});let i=new h.ScrolledWindow({hexpand:!0,vexpand:!0,child:this._content_area});i.add_css_class(`sb-preview-area`),this._control_panel=new w.PreferencesGroup({title:`Controls`});let a=new w.PreferencesPage;a.add(this._control_panel);let o=new h.ScrolledWindow({vexpand:!0,child:a});this._controls_split_view=new w.OverlaySplitView({show_sidebar:!0,sidebar_position:h.PackType.END,min_sidebar_width:280,max_sidebar_width:360,content:i,sidebar:o,css_classes:[`storybook-controls`]}),this._preview_title=new w.WindowTitle({title:`Preview`}),this._show_controls_button=new h.ToggleButton({icon_name:`sidebar-show-right-symbolic`,tooltip_text:`Toggle Controls`,active:!0});let s=new w.HeaderBar({title_widget:this._preview_title});s.pack_end(this._show_controls_button);let c=new h.Button({icon_name:`applications-graphics-symbolic`,tooltip_text:`Appearance`});c.connect(`clicked`,()=>buildAppearanceDialog(this._appearance).present(this)),s.pack_end(c);let l=new w.ToolbarView({content:this._controls_split_view,top_bar_style:w.ToolbarStyle.FLAT});l.add_top_bar(s);let u=new w.NavigationPage({title:`Preview`,tag:`preview`,child:l});this._main_split_view=new w.NavigationSplitView({min_sidebar_width:220,max_sidebar_width:320,sidebar:r,content:u}),this.set_content(this._main_split_view);let d=w.BreakpointCondition.parse(`max-width: 720sp`);if(d){let e=new w.Breakpoint({condition:d});e.connect(`apply`,()=>{this._main_split_view.collapsed=!0,this._controls_split_view.collapsed=!0}),e.connect(`unapply`,()=>{this._main_split_view.collapsed=!1,this._controls_split_view.collapsed=!1}),this.add_breakpoint(e)}}_onToggleControls(e){this._controls_split_view.set_show_sidebar(e.get_active())}populateSidebar(e){this._controller.mount(e,!0)}renderSidebar(e,t){this._onSelect=t,this._suppressSelect=!0,this._clearSidebar(),this._rowByTitle.clear();for(let t of e){this._addCategoryToSidebar(t.category);for(let{instance:e,name:n}of t.stories)this._addStoryToSidebar(e,n)}this._suppressSelect=!1}markSelected(e){let t=this._rowByTitle.get(e);t&&this._sidebar_list.get_selected_row()!==t&&(this._suppressSelect=!0,this._sidebar_list.select_row(t),this._suppressSelect=!1)}setPreviewTitle(e){this._preview_title.set_title(e)}showPreview(e){this._content_area.set_child(e),this._main_split_view.get_collapsed()&&this._main_split_view.set_show_content(!0)}renderControls(e){this._clearControlPanel();for(let t of e){let e=t.view;e instanceof w.PreferencesRow&&e.set_use_markup(!1),this._control_panel.add(e),this._controlRows.push(e)}this._show_controls_button.set_active(!0)}_clearSidebar(){let e=this._sidebar_list.get_first_child();for(;e;){let t=e.get_next_sibling();e.unparent(),e=t}}_addCategoryToSidebar(e){let t=new h.ListBoxRow({selectable:!1}),n=new h.Label({label:e,halign:h.Align.START,margin_top:10,margin_bottom:4,margin_start:12,margin_end:12});n.add_css_class(`heading`),n.add_css_class(`dim-label`),t.set_child(n),this._sidebar_list.append(t)}_addStoryToSidebar(e,t){let n=new h.ListBoxRow,r=new h.Label({label:t||`Unnamed Story`,halign:h.Align.START,margin_start:20,margin_top:6,margin_bottom:6});n.set_child(r),this._sidebar_list.append(n),n.storyWidget=e,this._rowByTitle.set(e.meta.title,n)}_clearControlPanel(){for(let e of this._controlRows)this._control_panel.remove(e);this._controlRows=[]}get activeStory(){return this._controller.activeStory}openStoryByTitle(e){return this._controller.openStoryByTitle(e)}setActiveArg(e,t){return this._controller.setActiveArg(e,t)}};D.type_ensure(_e.$gtype);var ve=class StorybookApplication extends w.Application{static{D.registerClass({GTypeName:`StorybookApplication`},StorybookApplication)}constructor(e){super({application_id:e.applicationId,flags:x.ApplicationFlags.DEFAULT_FLAGS}),this._window=null,this._options=e,this.connect(`startup`,()=>this._initStyles()),this.connect(`activate`,()=>this._onActivate())}_initStyles(){let e=new h.CssProvider;e.load_from_string(`
|
|
73
|
+
</node>`}const ee=e(import.meta.url);let b;function load$3(){return b===void 0&&(b=ee(`@gjsify/node-gi/gi`).requireGi(`Gio`,`2.0`)),b}__name(load$3,`load`);var x=new Proxy(Object.create(null),{get(e,t){return load$3()[t]},has(e,t){return t in load$3()}});function isWin32(){return l.DIR_SEPARATOR===92}function defaultListenAddress(){return isWin32()?`nonce-tcp:host=127.0.0.1`:`unix:tmpdir=${l.get_tmp_dir()}`}var DevtoolsPeerServerError=class extends Error{constructor(e,t,n,r){super(e),this.address=t,this.reason=n,this.name=`DevtoolsPeerServerError`,this.cause=r}};function isAddressInUse(e){return e instanceof l.Error&&e.matches(x.io_error_quark(),x.IOErrorEnum.ADDRESS_IN_USE)}function unixSocketPath(e){if(!e.startsWith(`unix:`))return null;for(let t of e.slice(5).split(`,`)){let e=t.indexOf(`=`);if(!(e<0||t.slice(0,e)!==`path`))try{return decodeURIComponent(t.slice(e+1))}catch{return null}}return null}function inspectExistingSocket(e){try{if((x.File.new_for_path(e).query_info(`unix::mode`,x.FileQueryInfoFlags.NONE,null).get_attribute_uint32(`unix::mode`)&61440)!=49152)return`not-a-socket`}catch{return`not-a-socket`}let t=new x.SocketClient;t.set_timeout(2);let n;try{n=t.connect(x.UnixSocketAddress.new(e),null)}catch{return`dead`}return n.close(null),`live`}function clearReclaimableSocket(e){let t=unixSocketPath(e);if(!t||!l.file_test(t,l.FileTest.EXISTS))return;let n=inspectExistingSocket(t);if(n===`live`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: another process is already listening there. Stop it, or point ${y} (or options.address) at a different socket — GJSIFY_DEVTOOLS_INSTANCE=<label> lets two devtools-enabled apps run side by side.`,e,`address-in-use`);if(n===`not-a-socket`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} already exists and is not a socket, so it will NOT be removed. Point ${y} (or options.address) at a free path.`,e,`occupied-by-other-file`);try{x.File.new_for_path(t).delete(null)}catch(n){throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} is a socket nothing listens on, but removing it failed (${n}). Delete it by hand, or point ${y} at a free path.`,e,`address-in-use`,n)}console.log(`[gjsify-devtools] reclaimed the stale socket ${t}: nothing was listening on it (an abnormal exit — Ctrl-C, SIGKILL, a crash — leaves the inode behind).`)}function flagsForAddress(e){return e.startsWith(`tcp:`)||e.startsWith(`nonce-tcp:`)?x.DBusServerFlags.NONE:x.DBusServerFlags.AUTHENTICATION_REQUIRE_SAME_USER}function startDevtoolsPeerServer(e,t,n){let r=n&&n!==``?n:defaultListenAddress();clearReclaimableSocket(r);let i;try{i=x.DBusServer.new_sync(r,flagsForAddress(r),x.dbus_generate_guid(),null,null)}catch(e){let t=isAddressInUse(e);throw new DevtoolsPeerServerError(t?`cannot listen on ${r}: the address is already in use (${e}). Stop whatever holds it, or point ${y} (or options.address) at a different address.`:`cannot listen on ${r}: ${e}. Check the address form — \`unix:path=/tmp/app.sock\`, \`unix:tmpdir=/tmp\` or \`nonce-tcp:host=127.0.0.1\`.`,r,t?`address-in-use`:`listen-failed`,e)}let a=new Set;i.connect(`new-connection`,(n,r)=>(a.add(r),r.connect(`closed`,()=>{e.unexport(r),a.delete(r)}),e.export(r,t),!0)),i.start();let o=!1;return{address:i.get_client_address(),objectPath:t,get connectionCount(){return a.size},stop(){if(!o){o=!0,i.stop();for(let t of a)e.unexport(t),!t.is_closed()&&t.close(null,(e,t)=>{try{e.close_finish(t)}catch{}});a.clear()}}}}function writeDevtoolsAddressFile(e,t){try{if(l.mkdir_with_parents(l.path_get_dirname(e),448),!l.file_set_contents(e,`${t}\n`))return null}catch(t){return console.error(`[gjsify-devtools] could not publish the peer address to ${e}: ${t}`),null}try{x.File.new_for_path(e).set_attribute_uint32(`unix::mode`,384,x.FileQueryInfoFlags.NONE,null)}catch(t){console.error(`[gjsify-devtools] could not restrict ${e} to the current user: ${t}`)}return e}function removeDevtoolsAddressFile(e){try{x.File.new_for_path(e).delete(null)}catch{}}const te=e(import.meta.url);let S;function load$2(){return S===void 0&&(S=te(`@gjsify/node-gi/gi`).requireGi(`Graphene`,`1.0`)),S}__name(load$2,`load`);var ne=new Proxy(Object.create(null),{get(e,t){return load$2()[t]},has(e,t){return t in load$2()}});function captureWidgetPng(e){let t=e.get_native()?.get_renderer();if(!t)return null;let n=e.get_width(),r=e.get_height();if(n<=0||r<=0)return null;let i=h.WidgetPaintable.new(e),a=h.Snapshot.new();i.snapshot(a,n,r);let o=a.to_node();if(!o)return null;let s=new ne.Rect;s.init(0,0,n,r);let c=t.render_texture(o,s).save_to_png_bytes().get_data();return c?new Uint8Array(c):null}function dumpGSettings(e){let t=x.SettingsSchemaSource.get_default()?.lookup(e,!0);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`GSettings schema '${e}' is not installed`));let n=new x.Settings({settings_schema:t}),r={};for(let e of t.list_keys())r[e]=n.get_value(e).recursiveUnpack();return r}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 activateWidget(e){let t=e;if(typeof t.activate==`function`&&t.activate()===!0)return!0;let n=typeof t.get_parent==`function`?t.get_parent():null;if(n&&widgetType(n)===`GtkListBox`){let t=n,r=!1;return typeof t.select_row==`function`&&(t.select_row(e),r=!0),typeof t.emit==`function`&&(t.emit(`row-activated`,e),r=!0),r}return!1}function sendKeyToWidget(e,t,n){let r=e.observe_controllers(),i=!1;for(let e=0;e<r.get_n_items();e++){let a=r.get_item(e);gtypeName(a)===`GtkEventControllerKey`&&(a.emit(`key-pressed`,t,0,n),i=!0)}return i}function nthChild(e,t){let n=e.get_first_child(),r=0;for(;n&&r<t;)n=n.get_next_sibling(),r++;return r===t?n:null}function listToplevels(){let e=h.Window.get_toplevels(),t=e.get_n_items(),n=[];for(let r=0;r<t;r++){let t=e.get_item(r);t&&n.push({path:`toplevel:${r}`,type:widgetType(t),title:t.get_title?.()??null,mapped:t.get_mapped(),focused:t.is_active??!1})}return n}function resolveWidgetPath(e){let t=parseWidgetPath(e);if(!t)return null;let n=h.Window.get_toplevels().get_item(t.toplevel);if(!n)return null;for(let e of t.children)if(n=nthChild(n,e),!n)return null;return n}function parseWidgetSelector(e){let t=e.indexOf(`:`),n=(t<0?e:e.slice(0,t)).trim(),r=(t<0?``:e.slice(t+1)).trim();return!n&&!r?null:{type:n,cssClass:r}}function findWidgetPath(e,t,n){if(!e.get_visible()||!e.get_mapped())return null;let r=!t.type||widgetType(e)===t.type,i=!t.cssClass||e.get_css_classes().includes(t.cssClass);if(r&&i)return n;let a=e.get_first_child(),o=0;for(;a;){let e=findWidgetPath(a,t,`${n}/child:${o}`);if(e)return e;a=a.get_next_sibling(),o++}return null}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:[]};if(t<=0)return r;let i=e.get_first_child(),a=0;for(;i;)r.children.push(dumpTree(i,t-1,`${n}/child:${a}`)),i=i.get_next_sibling(),a++;return r}function jsonSafe(e){let t=typeof e;return e==null||t===`string`||t===`number`||t===`boolean`?e??null:`[${t}]`}function getWidgetProperty(e,t){let n=e,r=t.replace(/-/g,`_`),i=t.replace(/[-_]([a-z])/g,(e,t)=>t.toUpperCase());for(let e of[t,r,i])if(e in n)return jsonSafe(n[e])}function childIndex(e,t){let n=e.get_first_child(),r=0;for(;n;){if(n===t)return r;n=n.get_next_sibling(),r++}return-1}function pathOfWidget(e){let t=[],n=e,r=n.get_parent();for(;r;){let e=childIndex(r,n);if(e<0)return null;t.unshift(e),n=r,r=n.get_parent()}let i=h.Window.get_toplevels(),a=i.get_n_items();for(let e=0;e<a;e++)if(i.get_item(e)===n)return buildWidgetPath(e,t);return null}function isActiveWindowScope(e){return!e||e===`window`||e===`active`}function frameDelay(e){return new Promise(t=>{l.timeout_add(l.PRIORITY_DEFAULT,e,()=>(t(),l.SOURCE_REMOVE))})}async function captureWidgetWhenRenderable(e,t=12,n=50){for(let r=0;r<t;r++){let t=captureWidgetPng(e);if(t)return t;await frameDelay(n)}return captureWidgetPng(e)}var DevtoolsService=class{constructor(e,t){this._app=e,this._options=t,this._exported=new Map,this._peer=null,this._addressFile=null,this._kinds=new Map,this._extensions=t.extend??[];for(let[e,t]of Object.entries(v))this._kinds.set(e,t);for(let e of this._extensions){for(let[t,n]of Object.entries(e.methodKinds))this._kinds.set(t,n);for(let[t,n]of Object.entries(e.handlers)){let e=n;this[t]=(...n)=>(this._guard(t),e(...n))}}}export(e,t){if(this._exported.has(e))return;let n=buildDevtoolsIfaceXml(this._extensions.flatMap(e=>e.methodsXml??[])),r=x.DBusExportedObject.wrapJSObject(n,this);r.export(e,t),this._exported.set(e,r)}unexport(e){if(e){this._exported.get(e)?.unexport(),this._exported.delete(e);return}for(let e of this._exported.values())e.unexport();this._exported.clear(),this._peer?.stop(),this._peer=null,this._addressFile&&=(removeDevtoolsAddressFile(this._addressFile),null)}attachPeerServer(e,t){this._peer=e,this._addressFile=t??null}get peerAddress(){return this._peer?.address??null}get addressFile(){return this._addressFile}GetStatus(){let e=this._app.get_active_window(),t={appId:this._app.get_application_id()??`unknown`,instance:this._options.instance??`default`,activeWindow:e?{id:e.get_name()||`window`,title:e.get_title()??``,mapped:e.get_mapped()}:null,toplevelCount:h.Window.get_toplevels().get_n_items(),focusedWidget:null,paused:this._isPaused()};for(let e of this._extensions){let n=e.contributeStatus?.();n&&Object.assign(t,n)}return JSON.stringify(t)}async ScreenshotAsync(e,t){try{let n=typeof e?.[0]==`string`?e[0]:``,r=await this._captureScopePng(n);t.return_value(new l.Variant(`(ay)`,[r]))}catch(e){t.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e){let t=this._resolveRootWidget(e);if(!t){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let n=captureWidgetPng(t.widget);if(!n){let e=t.widget.get_root();e instanceof h.Window&&e.present(),n=await captureWidgetWhenRenderable(t.widget)}return n??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:8,n.path))}GetProperty(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));let r=getWidgetProperty(n.widget,t);if(r===void 0)throw Error(formatDbusErrorMessage(`not-found`,`widget has no property '${t}'`));return JSON.stringify(r)}GetFocused(){let e=this._app.get_active_window(),t=e?e.get_focus():null;return JSON.stringify(t?{path:pathOfWidget(t),name:t.get_name()||null,type:widgetType(t)}:null)}ActivateWidget(e){this._guard(`ActivateWidget`);let t=this._resolveRootWidget(e);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));return activateWidget(t.widget)}FindWidget(e){let t=parseWidgetSelector(e);if(!t)throw Error(formatDbusErrorMessage(`invalid-params`,`empty selector '${e}'`));let n=this._resolveRootWidget(``);return n?findWidgetPath(n.widget,t,n.path)??``:``}SendKey(e,t){this._guard(`SendKey`);let[n,r,i]=h.accelerator_parse(e);if(!n)throw Error(formatDbusErrorMessage(`invalid-params`,`cannot parse accelerator '${e}'`));let a;if(a=t?this._resolveRootWidget(t)?.widget??null:this._app.get_active_window()?.get_focus()??null,!a)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${t||`focus`}'`));return sendKeyToWidget(a,r,i??0)}DumpGSettings(e){return JSON.stringify(dumpGSettings(e))}DumpCss(){return JSON.stringify(dumpCss())}SwapCss(e,t){return this._guard(`SwapCss`),swapCss(e,t)}_resolveRootWidget(e){if(isActiveWindowScope(e)){let e=this._app.get_active_window();return e?{widget:e,path:pathOfWidget(e)??`toplevel:0`}:null}let t=resolveWidgetPath(e);return t?{widget:t,path:e}:null}_isPaused(){return this._options.paused?.()??!1}_guard(e){let t=this._kinds.get(e);if(!t)throw Error(formatDbusErrorMessage(`internal`,`unclassified devtools method '${e}'`));if(t===`mutating`&&this._isPaused())throw Error(formatDbusErrorMessage(`paused`,`${e} rejected — external control is paused. Read-only methods keep working.`))}_scope(e){return e===`app`?`app`:`win`}_actionGroup(e){if(e===`app`)return this._app;if(this._options.winActionGroup)return this._options.winActionGroup;let t=this._app.get_active_window();return t instanceof h.ApplicationWindow?t:null}_requireGroup(e,t){let n=this._actionGroup(e);if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no '${e}' action group`));if(!n.has_action(t))throw Error(formatDbusErrorMessage(`not-found`,`unknown action ${e}.${t}`));return n}_parseValue(e){if(!e||e===`null`)return null;try{return JSON.parse(e)}catch{throw Error(formatDbusErrorMessage(`invalid-params`,`value_json is not valid JSON: ${e}`))}}};const C=`DBUS_SESSION_BUS_ADDRESS`,re=new Set;function envEnabled(){return isDevtoolsEnabledValue(l.getenv(`GJSIFY_DEVTOOLS`))}function envValue(e){let t=l.getenv(e);return t&&t!==``?t:null}function sessionBusUsable(){if(!envValue(C))return!1;try{return x.bus_get_sync(x.BusType.SESSION,null),!0}catch{return!1}}function chooseDevtoolsTransport(e){return e.requestedAddress?{kind:`peer`,address:e.requestedAddress,reason:`requested`}:e.hasAppConnection?{kind:`session-bus`}:e.sessionBusUsable?{kind:`unregistered`}:{kind:`peer`,address:null,reason:`no-session-bus`}}function describeMissingConnection(e,t){return e?t?`[gjsify-devtools] the session bus answers but this application is not registered on it yet — call installDevtools() from the GtkApplication "startup" handler (the bus connection and object path exist only after registration).`:`[gjsify-devtools] ${C} is set (${e}) but no bus answers there — using the bus-less peer transport instead. On macOS this is the usual state: Homebrew's dbus listens on launchd, so the advertised address only works while that socket is live.`:`[gjsify-devtools] this machine has no session bus (${C} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${y} on both the app and \`gjsify debug\` to pin it yourself.`}function installDevtools(e,t={}){if(!(t.enabled??envEnabled()))return null;let n=t.instance??envValue(`GJSIFY_DEVTOOLS_INSTANCE`)??void 0,r=new DevtoolsService(e,{...t,instance:n});try{return exportDevtools(e,r,t,n)}catch(e){return r.unexport(),console.error(`[gjsify-devtools] devtools stayed OFF, the app is unaffected — ${describeInstallFailure(e)}`),null}}function describeInstallFailure(e){return e instanceof DevtoolsPeerServerError||e instanceof Error?e.message:String(e)}function exportDevtools(e,t,n,r){let i=e.get_is_registered(),a=i?e.get_dbus_connection():null,o=i?e.get_dbus_object_path():null,s=envValue(C),c=!!(a&&o),u=c||sessionBusUsable(),d=chooseDevtoolsTransport({requestedAddress:n.address??envValue(y),hasAppConnection:c,sessionBusUsable:u}),f=e.get_application_id()??`unknown`,p=`${o??appIdToObjectPath(f)}/devtools`;if((d.kind===`unregistered`||d.kind===`peer`&&d.reason===`no-session-bus`)&&console.error(describeMissingConnection(s,u)),d.kind===`session-bus`&&a)t.export(a,p),console.log(`[gjsify-devtools] exported ${_} at ${p} (dest ${f})`);else if(d.kind===`peer`){let n=startDevtoolsPeerServer(t,p,d.address??void 0),i=writeDevtoolsAddressFile(devtoolsAddressFilePath(l.get_user_runtime_dir(),f,r),n.address);t.attachPeerServer(n,i),console.log(`[gjsify-devtools] exported ${_} at ${p} (peer address ${n.address}${i?`, published to ${i}`:``})`),i&&e.connect(`shutdown`,()=>removeDevtoolsAddressFile(i))}return re.add(t),t}const ie=[`AdwNavigationSplitView`,`GtkListBox`,`AdwOverlaySplitView`];function probeEnabled(){let e=l.getenv(`GJSIFY_STORYBOOK_PROBE`);if(e==null)return!1;let t=e.toLowerCase();return t!==``&&t!==`0`&&t!==`false`}function collectTypes(e,t){t.add(e.type);for(let n of e.children)collectTypes(n,t)}function installStorybookProbe(e,t,n={}){let r=n.requireChrome??ie,i=n.out??l.getenv(`GJSIFY_STORYBOOK_PROBE_OUT`)??void 0,a=n.timeoutMs??8e3,o=n.storyWidget??l.getenv(`GJSIFY_STORYBOOK_PROBE_STORY_WIDGET`)??void 0,s=t.controller.listStories(),c=[...new Set(s.map(e=>e.category))],u=n.story??l.getenv(`GJSIFY_STORYBOOK_PROBE_STORY`)??s[0]?.title,d=u?t.openStoryByTitle(u):!1,f=t.activeStory,p=new Set;collectTypes(dumpTree(t,60,`toplevel:0`),p);let m=r.filter(e=>!p.has(e)),h=new Set;f&&collectTypes(dumpTree(f,60,`story`),h);let g=h.size,_=o?h.has(o):null,finish=t=>{let n=JSON.stringify(t);if(t.ok)console.log(`STORYBOOK PROBE: PASS ${n}`);else{console.error(`STORYBOOK PROBE: FAIL ${n}`);try{typeof process<`u`&&(process.exitCode=1)}catch{}}if(i)try{l.file_set_contents(i,JSON.stringify(t,null,2))}catch{}e.quit()},v=0;l.timeout_add(l.PRIORITY_DEFAULT,100,()=>{v+=100;let e=captureWidgetPng(t),n=t.get_width()>0&&t.get_height()>0;if(!e&&!(v>=a))return l.SOURCE_CONTINUE;let i=f?captureWidgetPng(f):null,p=s.length>=1&&c.length>=1&&m.length===0&&d&&f!=null&&g>1,y;return s.length<1?y=`no stories registered`:c.length<1?y=`no categories`:m.length>0?y=`chrome missing: ${m.join(`, `)}`:!d||f==null?y=`could not open story: ${u??`(none)`}`:g<=1&&(y=`opened story rendered an empty subtree`),p&&o&&!h.has(o)&&(p=!1,y=`story widget ${o} not found in the opened story subtree`),p&&n&&(!e||e.length===0)&&(p=!1,y=`window realized (${t.get_width()}x${t.get_height()}) but the GSK capture was empty`),finish({ok:p,reason:y,stories:s.length,categories:c,opened:d,activeStory:f?f.meta.title:null,requiredChrome:r,missingChrome:m,storySubtreeWidgets:g,storyWidgetPresent:_,windowRealized:n,windowPngBytes:e?e.length:0,storyPngBytes:i?i.length:0}),l.SOURCE_REMOVE})}const ae=e(import.meta.url);let oe;function load$1(){return oe===void 0&&(oe=ae(`@gjsify/node-gi/gi`).requireGi(`Adw`,`1`)),oe}__name(load$1,`load`);var w=new Proxy(Object.create(null),{get(e,t){return load$1()[t]},has(e,t){return t in load$1()}});const T={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};T.GPL_2_0_ONLY,T.GPL_3_0_ONLY,T.UNKNOWN;const se=[`blue`,`teal`,`green`,`yellow`,`orange`,`red`,`pink`,`purple`,`slate`],ce={blue:`#3584e4`,teal:`#2190a4`,green:`#3a944a`,yellow:`#c88800`,orange:`#ed5b00`,red:`#e62d42`,pink:`#d56199`,purple:`#9141ac`,slate:`#6f8396`};function parseHex(e){let t=/^#([0-9a-f]{6})$/i.exec(e.trim());if(!t)return null;let n=Number.parseInt(t[1],16);return[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255]}function toHex(e,t,n){let channel=e=>Math.round(Math.min(1,Math.max(0,e))*255).toString(16).padStart(2,`0`);return`#${channel(e)}${channel(t)}${channel(n)}`}const toLinear=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,fromLinear=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function linearToOklab(e,t,n){let r=Math.cbrt(.4122214708*e+.5363325363*t+.0514459929*n),i=Math.cbrt(.2119034982*e+.6806995451*t+.1073969566*n),a=Math.cbrt(.0883024619*e+.2817188376*t+.6299787005*n);return[.2104542553*r+.793617785*i-.0040720468*a,1.9779984951*r-2.428592205*i+.4505937099*a,.0259040371*r+.7827717662*i-.808675766*a]}function oklabToLinear(e,t,n){let r=(e+.3963377774*t+.2158037573*n)**3,i=(e-.1055613458*t-.0638541728*n)**3,a=(e-.0894841775*t-1.291485548*n)**3;return[4.0767416621*r-3.3077115913*i+.2309699292*a,-1.2684380046*r+2.6097574011*i-.3413193965*a,-.0041960863*r-.7034186147*i+1.707614701*a]}function adwaitaStandaloneColor(e,t){let n=parseHex(e);if(!n)return e;let[r,i,a]=linearToOklab(toLinear(n[0]),toLinear(n[1]),toLinear(n[2])),[o,s,c]=oklabToLinear(t?Math.max(r,.85):Math.min(r,.5),i,a);return toHex(fromLinear(o),fromLinear(s),fromLinear(c))}function adwaitaAccentBgColor(e){return ce[e]}function adwaitaAccentColor(e,t){return adwaitaStandaloneColor(ce[e],t)}Math.PI*.35,Math.PI*.015,Math.PI*.9;const le=Math.PI*.9,ue=Math.PI*.7,de=Math.PI*1.1,fe=Math.PI*1.35,pe=le+de+fe-ue;53*Math.PI*2/pe,de-ue/2;const me={system:`Follow system`,light:`Light`,dark:`Dark`},he={blue:`Blue`,teal:`Teal`,green:`Green`,yellow:`Yellow`,orange:`Orange`,red:`Red`,pink:`Pink`,purple:`Purple`,slate:`Slate`};var StorybookAppearance=class{constructor(){this._provider=null,this._applying=!1,this._styleManager=w.StyleManager.get_default(),this.settings=new StorybookSettings(()=>this._styleManager.get_dark()),this.settings.subscribe(e=>this._apply(e)),this._styleManager.connect(`notify::dark`,()=>this.settings.systemChanged()),this._apply(this.settings.state)}_apply(e){if(!this._applying){this._applying=!0;try{this._styleManager.set_color_scheme(e.colorScheme===`light`?w.ColorScheme.FORCE_LIGHT:e.colorScheme===`dark`?w.ColorScheme.FORCE_DARK:w.ColorScheme.DEFAULT),this._applyAccent(this.settings.resolvedAccent)}finally{this._applying=!1}}}_applyAccent(e){let t=f.Display.get_default();if(!t)return;if(!this._provider){if(!e)return;this._provider=new h.CssProvider,h.StyleContext.add_provider_for_display(t,this._provider,h.STYLE_PROVIDER_PRIORITY_APPLICATION)}if(!e){this._provider.load_from_string(``);return}let n=adwaitaAccentBgColor(e),r=adwaitaAccentColor(e,this.settings.resolvedDark);this._provider.load_from_string(`:root { --accent-bg-color: ${n}; --accent-color: ${r}; }`)}};function buildSwatch(e,t,n){let r=new h.CheckButton({tooltip_text:t,halign:h.Align.CENTER,valign:h.Align.CENTER,focus_on_click:!1});for(let t of e)r.add_css_class(t);return r.update_property([h.AccessibleProperty.LABEL],[t]),n&&r.set_group(n),r}function buildSwatchCard(e=!1){let t=new w.WrapBox({align:.5,child_spacing:8,line_spacing:8,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),n=new w.Bin({child:t,hexpand:!0});return n.add_css_class(`card`),e&&n.add_css_class(`storybook-card-attached`),{card:n,row:t}}function buildAppearanceDialog(e){let t=e.settings,n=new w.PreferencesPage,r=new w.PreferencesGroup({title:`Style`}),{card:i,row:o}=buildSwatchCard(),s=null,c=new Map;for(let e of a){let n=buildSwatch([`storybook-swatch`,`storybook-scheme-swatch`,`storybook-scheme-${e}`],me[e],s);s??=n,n.set_active(t.colorScheme===e),n.connect(`toggled`,()=>{n.get_active()&&(t.colorScheme=e)}),c.set(e,n),o.append(n)}r.add(i),n.add(r);let l=new w.PreferencesGroup({title:`Accent colour`});l.add_css_class(`storybook-attached-group`);let u=new w.SwitchRow({title:`Use a custom accent colour`,subtitle:`Off follows the desktop, which owns the accent`,active:t.accentMode===`custom`});l.add(u);let{card:d,row:f}=buildSwatchCard(!0),p=null,m=new Map;for(let e of se){let n=buildSwatch([`storybook-swatch`],he[e],p);p??=n,n.set_active(t.accent===e);let r=new h.CssProvider;r.load_from_string(`checkbutton { background-color: ${adwaitaAccentBgColor(e)}; }`),n.get_style_context().add_provider(r,h.STYLE_PROVIDER_PRIORITY_APPLICATION),n.connect(`toggled`,()=>{n.get_active()&&(t.accent=e)}),m.set(e,n),f.append(n)}f.set_sensitive(t.accentMode===`custom`),u.connect(`notify::active`,()=>{t.accentMode=u.get_active()?`custom`:`system`}),l.add(d),n.add(l),t.subscribe(e=>{let t=c.get(e.colorScheme);t&&!t.get_active()&&t.set_active(!0);let n=m.get(e.accent);n&&!n.get_active()&&n.set_active(!0);let r=e.accentMode===`custom`;u.get_active()!==r&&u.set_active(r),f.set_sensitive(r)});let g=new w.PreferencesDialog({title:`Appearance`});return g.add(n),g}const ge=e(import.meta.url);let E;function load(){return E===void 0&&(E=ge("@gjsify/node-gi/gi").requireGi(`GObject`,`2.0`)),E}var D=new Proxy(Object.create(null),{get(e,t){return load()[t]},has(e,t){return t in load()}});function adwControlWidgetFactory(){return{text(e,t){let n=new w.EntryRow({title:e});t&&n.set_tooltip_text(t);let r=null;return n.connect(`changed`,()=>r?.(n.get_text())),{node:n,get:()=>n.get_text(),set:e=>n.set_text(e),onChange:e=>{r=e}}},boolean(e,t){let n=new w.SwitchRow({title:e,subtitle:t??``}),r=null;return n.connect(`notify::active`,()=>r?.(n.get_active())),{node:n,get:()=>n.get_active(),set:e=>n.set_active(e),onChange:e=>{r=e}}},number(e){let t=w.SpinRow.new_with_range(e.min??0,e.max??100,e.step??1);t.set_title(e.label||e.name),e.description&&t.set_subtitle(e.description);let n=null;return t.connect(`changed`,()=>n?.(t.get_value())),{node:t,get:()=>t.get_value(),set:e=>t.set_value(e),onChange:e=>{n=e}}},range(e){return buildRangeWidget(e)},select(e){return buildSelectWidget(e)},color(e,t){return buildColorWidget(e,t)}}}function buildRangeWidget(e){let t=e.min??0,n=e.max??100,r=e.step??1,i=typeof e.min==`number`?e.min:0,a=Number.isInteger(r)&&Number.isInteger(i),o=new h.Adjustment({lower:t,upper:n,step_increment:r,value:i});o.step_increment=r;let s=new h.ListBoxRow({selectable:!1,activatable:!1});s.add_css_class(`story-range-row`);let c=new h.Box({orientation:h.Orientation.VERTICAL,spacing:6,margin_top:12,margin_bottom:12,margin_start:12,margin_end:12}),l=new h.Box({orientation:h.Orientation.HORIZONTAL,spacing:12}),u=new h.Label({label:e.label||e.name,halign:h.Align.START,hexpand:!0,ellipsize:3});u.add_css_class(`heading`);let formatValue=e=>a?String(Math.round(e)):e.toFixed(2),d=new h.Label({label:formatValue(i),halign:h.Align.END});if(d.add_css_class(`numeric`),d.add_css_class(`dim-label`),l.append(u),l.append(d),c.append(l),e.description){let t=new h.Label({label:e.description,halign:h.Align.START,xalign:0,wrap:!0,max_width_chars:32});t.add_css_class(`caption`),t.add_css_class(`dim-label`),c.append(t)}let f=new h.Scale({orientation:h.Orientation.HORIZONTAL,adjustment:o,draw_value:!1,hexpand:!0}),p=null,m=!1;return f.connect(`value-changed`,()=>{if(m)return;let e=f.get_value();if(a){let t=Math.round(e);if(t!==e){f.set_value(t);return}e=t}d.set_label(formatValue(e)),p?.(e)}),c.append(f),s.set_child(c),{node:s,get:()=>f.get_value(),set:e=>{m=!0,f.set_value(e),m=!1,d.set_label(formatValue(e))},onChange:e=>{p=e}}}function buildSelectWidget(e){let t=e.options??[],n=h.StringList.new(t.map(e=>e.label)),r=new w.ComboRow({title:e.label||e.name,subtitle:e.description??``,model:n}),i=null;return r.connect(`notify::selected`,()=>i?.(r.get_selected())),{node:r,get:()=>r.get_selected(),set:e=>r.set_selected(e),onChange:e=>{i=e}}}function buildColorWidget(e,t){let n=new w.ActionRow({title:e,subtitle:t??``}),r=new h.ColorDialogButton({dialog:new h.ColorDialog({title:e}),valign:h.Align.CENTER});n.add_suffix(r),n.set_activatable_widget(r);let channel=e=>Math.round(Math.max(0,Math.min(1,e))*255).toString(16).padStart(2,`0`),rgbaToHex=e=>`#${channel(e.red)}${channel(e.green)}${channel(e.blue)}`,i=null,a=!1;return r.connect(`notify::rgba`,()=>{a||i?.(rgbaToHex(r.get_rgba()))}),{node:n,get:()=>rgbaToHex(r.get_rgba()),set:e=>{let t=new f.RGBA;t.parse(e)&&(a=!0,r.set_rgba(t),a=!1)},onChange:e=>{i=e}}}var _e=class StorybookWindow extends w.ApplicationWindow{static{D.registerClass({GTypeName:`StorybookWindow`},StorybookWindow)}constructor(e){super(e),this._appearance=new StorybookAppearance,this._controlRows=[],this._rowByTitle=new Map,this._onSelect=null,this._suppressSelect=!1,this.set_default_size(1200,800),this.set_size_request(360,320),this.set_title(`Storybook`),this._buildUI(),this._controller=new StorybookController(this,e=>this._buildControls(e)),this._sidebar_list.connect(`row-selected`,this._onRowSelected.bind(this)),this._show_controls_button.connect(`toggled`,this._onToggleControls.bind(this)),this._controls_split_view.set_show_sidebar(!0)}_onRowSelected(e,t){if(this._suppressSelect||!t)return;let n=t;n.storyWidget&&this._onSelect?.(n.storyWidget)}get controller(){return this._controller}_buildControls(e){let t=e.meta.controls;if(!Array.isArray(t))return[];let n=adwControlWidgetFactory(),r=[];for(let i of t){if(!i?.name||!i?.type){console.warn(`Invalid control configuration:`,i);continue}let t=bindControl(e,i,n);t&&r.push(t)}return r}_buildUI(){this._sidebar_list=new h.ListBox({selection_mode:h.SelectionMode.SINGLE}),this._sidebar_list.add_css_class(`navigation-sidebar`);let e=new h.ScrolledWindow({hexpand:!0,vexpand:!0,child:this._sidebar_list}),t=new w.HeaderBar({title_widget:new w.WindowTitle({title:`Stories`}),show_end_title_buttons:!1}),n=new w.ToolbarView({content:e,top_bar_style:w.ToolbarStyle.FLAT});n.add_top_bar(t);let r=new w.NavigationPage({title:`Stories`,tag:`stories`,child:n});this._content_area=new w.Bin({hexpand:!0,vexpand:!0});let i=new h.ScrolledWindow({hexpand:!0,vexpand:!0,child:this._content_area});i.add_css_class(`sb-preview-area`),this._control_panel=new w.PreferencesGroup({title:`Controls`});let a=new w.PreferencesPage;a.add(this._control_panel);let o=new h.ScrolledWindow({vexpand:!0,child:a});this._controls_split_view=new w.OverlaySplitView({show_sidebar:!0,sidebar_position:h.PackType.END,min_sidebar_width:280,max_sidebar_width:360,content:i,sidebar:o,css_classes:[`storybook-controls`]}),this._preview_title=new w.WindowTitle({title:`Preview`}),this._show_controls_button=new h.ToggleButton({icon_name:`sidebar-show-right-symbolic`,tooltip_text:`Toggle Controls`,active:!0});let s=new w.HeaderBar({title_widget:this._preview_title});s.pack_end(this._show_controls_button);let c=new h.Button({icon_name:`applications-graphics-symbolic`,tooltip_text:`Appearance`});c.connect(`clicked`,()=>buildAppearanceDialog(this._appearance).present(this)),s.pack_end(c);let l=new w.ToolbarView({content:this._controls_split_view,top_bar_style:w.ToolbarStyle.FLAT});l.add_top_bar(s);let u=new w.NavigationPage({title:`Preview`,tag:`preview`,child:l});this._main_split_view=new w.NavigationSplitView({min_sidebar_width:220,max_sidebar_width:320,sidebar:r,content:u}),this.set_content(this._main_split_view);let d=w.BreakpointCondition.parse(`max-width: 720sp`);if(d){let e=new w.Breakpoint({condition:d});e.connect(`apply`,()=>{this._main_split_view.collapsed=!0,this._controls_split_view.collapsed=!0}),e.connect(`unapply`,()=>{this._main_split_view.collapsed=!1,this._controls_split_view.collapsed=!1}),this.add_breakpoint(e)}}_onToggleControls(e){this._controls_split_view.set_show_sidebar(e.get_active())}populateSidebar(e){this._controller.mount(e,!0)}renderSidebar(e,t){this._onSelect=t,this._suppressSelect=!0,this._clearSidebar(),this._rowByTitle.clear();for(let t of e){this._addCategoryToSidebar(t.category);for(let{instance:e,name:n}of t.stories)this._addStoryToSidebar(e,n)}this._suppressSelect=!1}markSelected(e){let t=this._rowByTitle.get(e);t&&this._sidebar_list.get_selected_row()!==t&&(this._suppressSelect=!0,this._sidebar_list.select_row(t),this._suppressSelect=!1)}setPreviewTitle(e){this._preview_title.set_title(e)}showPreview(e){this._content_area.set_child(e),this._main_split_view.get_collapsed()&&this._main_split_view.set_show_content(!0)}renderControls(e){this._clearControlPanel();for(let t of e){let e=t.view;e instanceof w.PreferencesRow&&e.set_use_markup(!1),this._control_panel.add(e),this._controlRows.push(e)}this._show_controls_button.set_active(!0)}_clearSidebar(){let e=this._sidebar_list.get_first_child();for(;e;){let t=e.get_next_sibling();e.unparent(),e=t}}_addCategoryToSidebar(e){let t=new h.ListBoxRow({selectable:!1}),n=new h.Label({label:e,halign:h.Align.START,margin_top:10,margin_bottom:4,margin_start:12,margin_end:12});n.add_css_class(`heading`),n.add_css_class(`dim-label`),t.set_child(n),this._sidebar_list.append(t)}_addStoryToSidebar(e,t){let n=new h.ListBoxRow,r=new h.Label({label:t||`Unnamed Story`,halign:h.Align.START,margin_start:20,margin_top:6,margin_bottom:6});n.set_child(r),this._sidebar_list.append(n),n.storyWidget=e,this._rowByTitle.set(e.meta.title,n)}_clearControlPanel(){for(let e of this._controlRows)this._control_panel.remove(e);this._controlRows=[]}get activeStory(){return this._controller.activeStory}openStoryByTitle(e){return this._controller.openStoryByTitle(e)}setActiveArg(e,t){return this._controller.setActiveArg(e,t)}};D.type_ensure(_e.$gtype);var ve=class StorybookApplication extends w.Application{static{D.registerClass({GTypeName:`StorybookApplication`},StorybookApplication)}constructor(e){super({application_id:e.applicationId,flags:x.ApplicationFlags.DEFAULT_FLAGS}),this._window=null,this._options=e,this.connect(`startup`,()=>this._initStyles()),this.connect(`activate`,()=>this._onActivate())}_initStyles(){let e=new h.CssProvider;e.load_from_string(`
|
|
65
74
|
/* Appearance dialog — round swatches with a selection ring, the shape GNOME's own
|
|
66
75
|
appearance switcher uses. Adapted from Learn6502's theme-mode-selector.css and
|
|
67
76
|
accent-color-selector.css (JumpLink/easy6502, MIT).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/example-gtk-adwaita-storybook",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "Interactive component browser for Libadwaita widgets — a native Adwaita storybook built on @gjsify/storybook, debuggable over DBus/MCP via @gjsify/devtools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/gjs.js",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"@girs/glib-2.0": "^4.1.0",
|
|
55
55
|
"@girs/gobject-2.0": "^4.1.0",
|
|
56
56
|
"@girs/gtk-4.0": "^4.1.0",
|
|
57
|
-
"@gjsify/adwaita-web": "^0.
|
|
58
|
-
"@gjsify/cli": "^0.
|
|
57
|
+
"@gjsify/adwaita-web": "^0.42.0",
|
|
58
|
+
"@gjsify/cli": "^0.42.0",
|
|
59
59
|
"@gjsify/node-gi": "file:../../../packages/node-gi/node-gi",
|
|
60
|
-
"@gjsify/storybook": "^0.
|
|
61
|
-
"@gjsify/adwaita-storybook": "^0.
|
|
60
|
+
"@gjsify/storybook": "^0.42.0",
|
|
61
|
+
"@gjsify/adwaita-storybook": "^0.42.0",
|
|
62
62
|
"@types/node": "^25.9.2",
|
|
63
63
|
"typescript": "^6.0.3"
|
|
64
64
|
},
|
|
@@ -7,10 +7,14 @@ import { toggleGroupMeta } from '../../buttons/toggle-group.meta.js';
|
|
|
7
7
|
|
|
8
8
|
const STYLE_CLASSES = ['flat', 'round'] as const;
|
|
9
9
|
|
|
10
|
-
// The three toggles, mirroring the native demo. `view-
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// `view-
|
|
10
|
+
// The three toggles, mirroring the native demo. The previous `view-dual` name had no
|
|
11
|
+
// `.adw-icon--*` rule and rendered blank.
|
|
12
|
+
//
|
|
13
|
+
// `view-columns` DIVERGES, and this pane is the better-off half: the name is in no icon
|
|
14
|
+
// theme at all, so the GTK story beside it draws the broken-image paintable while
|
|
15
|
+
// build-scss.mjs hand-draws a 3-column glyph for the web. Ledgered under that name in
|
|
16
|
+
// status/adwaita-web-icon-masks.json, which the third arm of
|
|
17
|
+
// scripts/check-adwaita-icon-masks.mjs holds.
|
|
14
18
|
const TOGGLES: ReadonlyArray<{ label: string; icon: string }> = [
|
|
15
19
|
{ label: 'List', icon: 'view-list' },
|
|
16
20
|
{ label: 'Grid', icon: 'view-grid' },
|
|
@@ -33,7 +33,7 @@ export class ToolbarViewWebStory extends StoryElement {
|
|
|
33
33
|
|
|
34
34
|
// Scrollable content — a status page sits between the toolbars.
|
|
35
35
|
const content = document.createElement('adw-status-page');
|
|
36
|
-
content.setAttribute('icon', 'folder');
|
|
36
|
+
content.setAttribute('icon', 'folder-documents');
|
|
37
37
|
content.setAttribute('title', 'Your library');
|
|
38
38
|
content.setAttribute('description', 'Content sits between the toolbars and scrolls independently of them.');
|
|
39
39
|
view.appendChild(content);
|
|
@@ -36,6 +36,7 @@ export class EntryRowWebStory extends StoryElement {
|
|
|
36
36
|
if (!this._row) return;
|
|
37
37
|
this._row.setAttribute('title', this.args.title as string);
|
|
38
38
|
this._row.setAttribute('text', this.args.text as string);
|
|
39
|
+
this._row.toggleAttribute('show-apply-button', this.args.showApplyButton as boolean);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -44,11 +44,14 @@ export class TabViewWebStory extends StoryElement {
|
|
|
44
44
|
this._applyAutohide(this.args.autohide as boolean);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//
|
|
48
|
-
//
|
|
47
|
+
// The SAME name the GTK twin uses. It stood in as `view-grid` under a comment
|
|
48
|
+
// blaming @gjsify/adwaita-icons for not having the glyph — which exports it at
|
|
49
|
+
// actions.ts:981; what was missing was a `.adw-icon--view-paged` mask class, so
|
|
50
|
+
// the right name drew a solid square and a different glyph was substituted.
|
|
51
|
+
// `scripts/check-adwaita-icon-masks.mjs` now fails that state instead.
|
|
49
52
|
private _buildPageBody(title: string, body: string): HTMLElement {
|
|
50
53
|
const status = document.createElement('adw-status-page');
|
|
51
|
-
status.setAttribute('icon', 'view-
|
|
54
|
+
status.setAttribute('icon', 'view-paged');
|
|
52
55
|
status.setAttribute('title', title);
|
|
53
56
|
status.setAttribute('description', body);
|
|
54
57
|
return status;
|