@stacksjs/stx 0.2.832 → 0.2.834
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/builtins/image-worker.js +6 -1
- package/dist/{chunk-vb4xzz5c.js → chunk-0a36jnq4.js} +1 -1
- package/dist/chunk-0c8fqfan.js +3 -0
- package/dist/{chunk-k58rsprz.js → chunk-0mb3jch4.js} +3 -3
- package/dist/{chunk-cnf9r95x.js → chunk-0mrzdsh5.js} +4 -4
- package/dist/chunk-0rnfywsx.js +2 -0
- package/dist/chunk-0z7w8e0s.js +2 -0
- package/dist/{chunk-hr4rd0rr.js → chunk-1qgzexkc.js} +42 -40
- package/dist/{chunk-mxvevxb8.js → chunk-29f6vmyz.js} +4 -4
- package/dist/{chunk-jp6sbk05.js → chunk-2nxxhcyy.js} +1 -1
- package/dist/{chunk-xdwnbr9b.js → chunk-33czswpt.js} +2 -2
- package/dist/{chunk-ekh3mxyp.js → chunk-3bjnrmha.js} +2 -2
- package/dist/chunk-3f1ks1ah.js +2 -0
- package/dist/{chunk-fgreefqz.js → chunk-3tn9tb9w.js} +5 -5
- package/dist/{chunk-v856z21j.js → chunk-3w8kt53x.js} +7 -7
- package/dist/chunk-4f2zy3y6.js +2 -0
- package/dist/{chunk-7zzz8r0d.js → chunk-4g6v5qsp.js} +2 -2
- package/dist/{chunk-04z1xyrb.js → chunk-4ntm3dtk.js} +2 -2
- package/dist/chunk-523s4p08.js +2 -0
- package/dist/{chunk-mypygxdm.js → chunk-52g026sc.js} +2 -2
- package/dist/{chunk-716jrdcg.js → chunk-52t0qpx6.js} +1 -1
- package/dist/{chunk-b5rxc6p1.js → chunk-5379q74v.js} +1 -1
- package/dist/{chunk-4a3r1kh1.js → chunk-55e46spy.js} +2 -2
- package/dist/{chunk-5hm3aq74.js → chunk-55k7m9cp.js} +2 -2
- package/dist/chunk-5gqjhq31.js +2 -0
- package/dist/chunk-6j2aea05.js +2 -0
- package/dist/{chunk-yrw5ensv.js → chunk-7bvvv74e.js} +2 -2
- package/dist/chunk-7efkc3gk.js +2 -0
- package/dist/{chunk-9pjmza44.js → chunk-7h5rt22w.js} +4 -4
- package/dist/{chunk-5201w0f1.js → chunk-84nw3921.js} +3 -3
- package/dist/chunk-913grzaj.js +2 -0
- package/dist/chunk-99ddfv0b.js +2 -0
- package/dist/{chunk-9vvvp4g3.js → chunk-9n14m2gn.js} +5 -5
- package/dist/chunk-9w3r1ch2.js +3 -0
- package/dist/chunk-a1hxz8q4.js +2 -0
- package/dist/{chunk-wt7qhv5b.js → chunk-a579jdwb.js} +1 -1
- package/dist/{chunk-7p8m82pj.js → chunk-amg6kr1p.js} +2 -2
- package/dist/{chunk-27r7e2pv.js → chunk-b0z85f8h.js} +1 -1
- package/dist/chunk-b3s8tb18.js +2 -0
- package/dist/{chunk-67nq6csk.js → chunk-bc4x45vx.js} +1 -1
- package/dist/{chunk-3p7r3ajd.js → chunk-bky02g7k.js} +2 -2
- package/dist/chunk-brk1pk8w.js +2 -0
- package/dist/{chunk-hd378dgy.js → chunk-c3dg8qdn.js} +2 -2
- package/dist/{chunk-cca18z35.js → chunk-c9vxm8yq.js} +8 -8
- package/dist/{chunk-xwjsbewa.js → chunk-cddzcckm.js} +7 -7
- package/dist/chunk-cy3c4yxg.js +2 -0
- package/dist/chunk-db7p6bc4.js +2 -0
- package/dist/{chunk-qm2t1ftx.js → chunk-ddtk57fy.js} +4 -4
- package/dist/{chunk-npk6j7a9.js → chunk-dgqp0pjn.js} +2 -2
- package/dist/{chunk-gcf97wgx.js → chunk-dv11h4f0.js} +1 -1
- package/dist/{chunk-5jkx1t6c.js → chunk-dvyysszs.js} +6 -6
- package/dist/chunk-e7ssdryq.js +2 -0
- package/dist/{chunk-eaeyemgp.js → chunk-ecmvq302.js} +8 -8
- package/dist/chunk-ee147ezb.js +2 -0
- package/dist/chunk-f6vzn90z.js +2 -0
- package/dist/chunk-fc5zj6qg.js +2 -0
- package/dist/{chunk-wr7bmkne.js → chunk-fvgk1w9s.js} +2 -2
- package/dist/{chunk-ke0w29sz.js → chunk-g3xbwz51.js} +1 -1
- package/dist/chunk-g5jfb1ms.js +2 -0
- package/dist/{chunk-hn3qmkx2.js → chunk-ga2k1rga.js} +11 -11
- package/dist/{chunk-cv1zc9dg.js → chunk-gh62p9mx.js} +2 -2
- package/dist/{chunk-6m58mesb.js → chunk-gnt1v0kc.js} +6 -6
- package/dist/chunk-gtj8wy95.js +2 -0
- package/dist/{chunk-wb6w807m.js → chunk-h4tbpr7p.js} +1 -1
- package/dist/chunk-j0w048sj.js +2 -0
- package/dist/chunk-jmk1ze6r.js +2 -0
- package/dist/{chunk-t59bc7na.js → chunk-jr0r5pzw.js} +2 -2
- package/dist/{chunk-44wcgf44.js → chunk-k46pfdmn.js} +1 -1
- package/dist/chunk-k4hjqfx1.js +2 -0
- package/dist/chunk-k761q7s7.js +2 -0
- package/dist/{chunk-1vzncfka.js → chunk-kw5gra2z.js} +2 -2
- package/dist/chunk-kzvt88tk.js +2 -0
- package/dist/chunk-mdtysd2d.js +2 -0
- package/dist/{chunk-rkdsgfhd.js → chunk-ms3v5nat.js} +6 -6
- package/dist/{chunk-7qgegnxh.js → chunk-mya2g8sn.js} +1 -1
- package/dist/{chunk-f6b7av6b.js → chunk-n4qznmkm.js} +5 -5
- package/dist/{chunk-m9bbhg46.js → chunk-nmtya57z.js} +2 -2
- package/dist/chunk-npn692c4.js +42 -0
- package/dist/{chunk-02zvytqx.js → chunk-nxfyjw59.js} +1 -1
- package/dist/{chunk-xn9jg1q5.js → chunk-nyg0nbjj.js} +1 -1
- package/dist/chunk-pt8nft3k.js +2 -0
- package/dist/chunk-pwv77cyb.js +2 -0
- package/dist/chunk-q1cfc2fp.js +2 -0
- package/dist/{chunk-qy6dtm1a.js → chunk-q46ay7aq.js} +4 -4
- package/dist/{chunk-zgf3nss0.js → chunk-qbvy23qa.js} +95 -95
- package/dist/{chunk-tdq1bq8x.js → chunk-qdagsy5b.js} +2 -2
- package/dist/{chunk-zx85qm3n.js → chunk-qfcabz87.js} +4 -4
- package/dist/{chunk-9fw647px.js → chunk-rfdwn0k3.js} +32 -32
- package/dist/{chunk-wvds0s9m.js → chunk-rnm8ejpz.js} +2 -2
- package/dist/{chunk-gj33636j.js → chunk-rtj900pa.js} +1 -1
- package/dist/{chunk-c84pxd2k.js → chunk-s33andzg.js} +2 -2
- package/dist/{chunk-4z0jpzdq.js → chunk-s3j5vxy9.js} +2 -2
- package/dist/{chunk-8y8kgw9s.js → chunk-s6r54dyf.js} +2 -2
- package/dist/{chunk-hdedvppk.js → chunk-srb0qmgx.js} +1 -1
- package/dist/{chunk-7kzmfpcf.js → chunk-srqk1nxc.js} +2 -2
- package/dist/{chunk-8ew4a7vy.js → chunk-t33fttx9.js} +1 -1
- package/dist/chunk-t612xpa4.js +2 -0
- package/dist/{chunk-g4qzy5hv.js → chunk-tesbhpbp.js} +1 -1
- package/dist/{chunk-m9dj8pgb.js → chunk-tvw571ab.js} +1 -1
- package/dist/{chunk-6k26n0sj.js → chunk-tx8wk6h7.js} +2 -2
- package/dist/{chunk-c9mdvpf5.js → chunk-txd2js5v.js} +10 -10
- package/dist/chunk-v1wgp7ep.js +2 -0
- package/dist/{chunk-qnrgfm9v.js → chunk-v3xyb3ws.js} +2 -2
- package/dist/{chunk-v88bnrwx.js → chunk-v4kenb7z.js} +5 -5
- package/dist/chunk-v53kdjz6.js +2 -0
- package/dist/{chunk-2qngyyaz.js → chunk-vfj9wp11.js} +2 -2
- package/dist/{chunk-nfpsaaqm.js → chunk-vfxkn1pe.js} +3 -3
- package/dist/{chunk-8nf8244n.js → chunk-vnk6gt0t.js} +1 -1
- package/dist/chunk-vqpypnys.js +2 -0
- package/dist/{chunk-any1jha4.js → chunk-x57x0yq7.js} +5 -5
- package/dist/{chunk-6cayjtgq.js → chunk-xd9t20sx.js} +1 -1
- package/dist/{chunk-dnx152fg.js → chunk-xqy8y5dc.js} +1 -1
- package/dist/{chunk-6tjm38e4.js → chunk-xtqapjz3.js} +1 -1
- package/dist/{chunk-ec45m14s.js → chunk-xvmn976f.js} +1 -1
- package/dist/chunk-xxyhzsqx.js +2 -0
- package/dist/{chunk-nd7z3syn.js → chunk-y47n1j5x.js} +6 -6
- package/dist/{chunk-qadce16v.js → chunk-ya6bp08c.js} +1 -1
- package/dist/{chunk-zvvv6x8c.js → chunk-yw1s8kyj.js} +3 -3
- package/dist/{chunk-rmygv0n0.js → chunk-z0ynyz62.js} +4 -4
- package/dist/chunk-z2e06633.js +2 -0
- package/dist/{chunk-d6qkykt6.js → chunk-zb7kfwac.js} +3 -3
- package/dist/chunk-zsdqsky6.js +2 -0
- package/dist/cli.js +13 -13
- package/dist/component-processing.js +1 -1
- package/dist/component-renderer.js +1 -1
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/document-styles.d.ts +7 -0
- package/dist/document-styles.js +40 -0
- package/dist/html-masking.js +6 -3
- package/dist/process.js +3 -0
- package/dist/pwa.js +3 -3
- package/dist/ssg.js +4 -4
- package/package.json +5 -5
- package/dist/chunk-0cwn420q.js +0 -2
- package/dist/chunk-17zrprh0.js +0 -2
- package/dist/chunk-32xv3q66.js +0 -2
- package/dist/chunk-39k5bfmk.js +0 -2
- package/dist/chunk-42c92rp3.js +0 -2
- package/dist/chunk-6r4teng3.js +0 -2
- package/dist/chunk-7b3wjek8.js +0 -2
- package/dist/chunk-7jazxycb.js +0 -2
- package/dist/chunk-8hhkqfb7.js +0 -3
- package/dist/chunk-8n8vj099.js +0 -2
- package/dist/chunk-8q6qp36z.js +0 -2
- package/dist/chunk-8z2g630g.js +0 -2
- package/dist/chunk-9maxchrj.js +0 -2
- package/dist/chunk-a5kd0r75.js +0 -2
- package/dist/chunk-asf2d722.js +0 -2
- package/dist/chunk-asqznjzg.js +0 -2
- package/dist/chunk-atbzg7vw.js +0 -2
- package/dist/chunk-bkf2z7zt.js +0 -2
- package/dist/chunk-dafwt7tk.js +0 -2
- package/dist/chunk-egmxf96v.js +0 -2
- package/dist/chunk-f9yqvq9t.js +0 -2
- package/dist/chunk-fb90n0by.js +0 -2
- package/dist/chunk-hmnzsdc9.js +0 -2
- package/dist/chunk-jxjmbwb9.js +0 -2
- package/dist/chunk-k6ye0159.js +0 -3
- package/dist/chunk-kgn911k7.js +0 -2
- package/dist/chunk-kmss70d5.js +0 -2
- package/dist/chunk-kqhq31nh.js +0 -2
- package/dist/chunk-kshem79d.js +0 -2
- package/dist/chunk-kts0wcxn.js +0 -42
- package/dist/chunk-q1nbsj9p.js +0 -2
- package/dist/chunk-q2zsy8vk.js +0 -2
- package/dist/chunk-qez22va2.js +0 -2
- package/dist/chunk-qg2tpvdw.js +0 -2
- package/dist/chunk-v1mwhvf8.js +0 -2
- package/dist/chunk-wbmh106x.js +0 -2
- package/dist/chunk-wpyhavjy.js +0 -2
- package/dist/chunk-yw9g1ag1.js +0 -2
- package/dist/chunk-zt74q4c8.js +0 -2
- package/dist/chunk-zty254tw.js +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{kn,M}from"./chunk-vfj9wp11.js";import m from"fs";import e from"path";async function Sn(r,o,i){if(r.__stx_runtime_config)return;let n=kn();if(n||i){r.__stx_runtime_config=n??M(i);return}let t=e.dirname(e.resolve(o));while(!0){if(["stx.config.ts","stx.config.js",".config/stx.config.ts",".config/stx.config.js"].some((f)=>m.existsSync(e.join(t,f)))){let{loadStxConfig:f}=await import("./chunk-e7ssdryq.js"),c=await f(t);if(c.runtimeConfig)r.__stx_runtime_config=M(c.runtimeConfig);return}let s=e.dirname(t);if(s===t)return;t=s}}async function Si(r,o){function i(n){if(n===null)return"null";if(Array.isArray(n))return`Array<${n.length?[...new Set(n.map(i))].join(" | "):"unknown"}>`;if(typeof n==="object")return`{ ${Object.entries(n).map(([t,s])=>`readonly ${JSON.stringify(t)}: ${i(s)}`).join("; ")} }`;return typeof n}await Bun.write(e.join(r,".stx/runtime-config.d.ts"),`import '@stacksjs/stx/runtime-config'
|
|
3
3
|
declare module '@stacksjs/stx/runtime-config' { interface PublicRuntimeConfig ${i(o.public??{})} }
|
|
4
4
|
`),await Bun.write(e.join(r,".stx/runtime-config-server.d.ts"),`import '@stacksjs/stx/runtime-config-server'
|
|
5
5
|
declare module '@stacksjs/stx/runtime-config-server' { interface PrivateRuntimeConfig ${i(o.private??{})} }
|
|
6
6
|
`)}
|
|
7
|
-
export{
|
|
7
|
+
export{Sn,Si};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ut,dt,pt}from"./chunk-ema1c29k.js";import"./chunk-
|
|
2
|
+
import{ut,dt,pt}from"./chunk-ema1c29k.js";import"./chunk-4ntm3dtk.js";import"./chunk-s6r54dyf.js";import"./chunk-txd2js5v.js";import{m}from"./chunk-qbvy23qa.js";import"./chunk-vfj9wp11.js";import"./chunk-qdagsy5b.js";import{Ut,ro,Wt,Wi,lt,qi,so,qt,Xi,Kt}from"./chunk-v3xyb3ws.js";import M from"fs";import x from"path";function E(t,e){let r=[x.join(t.root,"stx.config.ts"),x.join(t.root,"stx.config.js"),x.join(t.root,"stx.config.mjs")],s=e.debounceMs??300,o=null,a=[];for(let c of r)try{if(!M.existsSync(c))continue;let n=M.watch(c,(d)=>{if(d==="change"){if(o)clearTimeout(o);o=setTimeout(async()=>{qi("Config file changed, restarting...");try{await e.onChange()}catch(p){lt(`Failed to restart: ${p}`)}},s)}});a.push(n)}catch{}return{stop(){if(o)clearTimeout(o);for(let c of a)c.close()}}}import w from"fs";import j from"path";var nt=".stx/story/analytics.json",st=1,A=1e4;class k{storage;storagePath;currentSession=null;dirty=!1;viewStartTimes=new Map;constructor(t){this.storagePath=j.join(t,nt),this.storage=this.loadStorage(),this.startSession()}loadStorage(){try{let t=w.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:st,events:[],sessions:[]}}}async save(){if(!this.dirty)return;let t=j.dirname(this.storagePath);if(await w.promises.mkdir(t,{recursive:!0}),this.storage.events.length>A)this.storage.events=this.storage.events.slice(-A);await w.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}startSession(){this.endSession(),this.currentSession={id:at(),startTime:Date.now(),componentViews:[]},this.storage.sessions.push(this.currentSession),this.dirty=!0}endSession(){if(this.currentSession)this.currentSession.endTime=Date.now(),this.currentSession=null}track(t){this.storage.events.push({...t,timestamp:Date.now()}),this.dirty=!0}trackView(t,e){if(this.endViewTiming(t),this.viewStartTimes.set(t,Date.now()),this.track({type:"view",componentId:t,variantId:e}),this.currentSession&&!this.currentSession.componentViews.includes(t))this.currentSession.componentViews.push(t)}endViewTiming(t){let e=this.viewStartTimes.get(t);if(e){let r=Date.now()-e;this.track({type:"view",componentId:t,metadata:{duration:r,endView:!0}}),this.viewStartTimes.delete(t)}}trackPropChange(t,e,r){this.track({type:"prop_change",componentId:t,propName:e,metadata:{value:r}})}trackVariantSwitch(t,e){this.track({type:"variant_switch",componentId:t,variantId:e})}trackSearch(t,e){this.track({type:"search",query:t,metadata:{resultCount:e}})}getComponentAnalytics(t,e){let r=this.storage.events.filter((i)=>i.componentId===t),s=r.filter((i)=>i.type==="view"&&!i.metadata?.endView),o=r.filter((i)=>i.type==="prop_change"),a=r.filter((i)=>i.type==="variant_switch"),c={};for(let i of o)if(i.propName)c[i.propName]=(c[i.propName]||0)+1;let n={};for(let i of a)if(i.variantId)n[i.variantId]=(n[i.variantId]||0)+1;let d=new Set(this.storage.sessions.filter((i)=>i.componentViews.includes(t)).map((i)=>i.id)),p=r.filter((i)=>i.metadata?.duration).map((i)=>i.metadata.duration),g=p.length>0?p.reduce((i,l)=>i+l,0)/p.length:0,y=Object.entries(c).sort((i,l)=>l[1]-i[1]).slice(0,5).map(([i])=>i);return{componentId:t,componentName:e,viewCount:s.length,uniqueViews:d.size,lastViewed:s[s.length-1]?.timestamp,propChanges:c,topChangedProps:y,variantViews:n,avgTimeSpent:g}}getMostViewedComponents(t=10){let e=new Map;for(let r of this.storage.events)if(r.type==="view"&&r.componentId&&!r.metadata?.endView)e.set(r.componentId,(e.get(r.componentId)||0)+1);return Array.from(e.entries()).map(([r,s])=>({componentId:r,viewCount:s})).sort((r,s)=>s.viewCount-r.viewCount).slice(0,t)}getMostChangedProps(t=10){let e=new Map;for(let r of this.storage.events)if(r.type==="prop_change"&&r.propName)e.set(r.propName,(e.get(r.propName)||0)+1);return Array.from(e.entries()).map(([r,s])=>({propName:r,changeCount:s})).sort((r,s)=>s.changeCount-r.changeCount).slice(0,t)}getSearchAnalytics(){let t=this.storage.events.filter((o)=>o.type==="search"),e=new Map,r=0;for(let o of t){if(o.query)e.set(o.query,(e.get(o.query)||0)+1);if(o.metadata?.resultCount!==void 0)r+=o.metadata.resultCount}let s=Array.from(e.entries()).map(([o,a])=>({query:o,count:a})).sort((o,a)=>a.count-o.count).slice(0,10);return{totalSearches:t.length,topQueries:s,avgResultCount:t.length>0?r/t.length:0}}clear(){this.storage.events=[],this.storage.sessions=[],this.dirty=!0,this.startSession()}exportAnalytics(){return JSON.stringify({exportedAt:Date.now(),...this.storage},null,2)}}function at(){return`session-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import S from"fs";import B from"path";var it=".stx/story/bookmarks.json",ct=1;class P{storage;storagePath;dirty=!1;constructor(t){this.storagePath=B.join(t,it),this.storage=this.loadStorage()}loadStorage(){try{let t=S.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:ct,bookmarks:[]}}}async save(){if(!this.dirty)return;let t=B.dirname(this.storagePath);await S.promises.mkdir(t,{recursive:!0}),await S.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}addBookmark(t,e,r,s={}){let o={id:mt(),name:s.name||`${t}/${e}`,storyId:t,variantId:e,props:r,created:Date.now(),notes:s.notes,color:s.color};return this.storage.bookmarks.push(o),this.dirty=!0,o}getAllBookmarks(){return[...this.storage.bookmarks]}getBookmarksForStory(t){return this.storage.bookmarks.filter((e)=>e.storyId===t)}getBookmark(t){return this.storage.bookmarks.find((e)=>e.id===t)}isBookmarked(t,e){return this.storage.bookmarks.some((r)=>r.storyId===t&&r.variantId===e)}updateBookmark(t,e){let r=this.getBookmark(t);if(!r)return;return Object.assign(r,e),this.dirty=!0,r}deleteBookmark(t){let e=this.storage.bookmarks.findIndex((r)=>r.id===t);if(e===-1)return!1;return this.storage.bookmarks.splice(e,1),this.dirty=!0,!0}toggleBookmark(t,e,r){let s=this.storage.bookmarks.find((a)=>a.storyId===t&&a.variantId===e);if(s)return this.deleteBookmark(s.id),{added:!1};return{added:!0,bookmark:this.addBookmark(t,e,r)}}exportBookmarks(){return JSON.stringify(this.storage,null,2)}importBookmarks(t,e=!0){let r=JSON.parse(t),s=0;for(let o of r.bookmarks){if(e){let a=this.storage.bookmarks.find((c)=>c.id===o.id);if(a)Object.assign(a,o);else this.storage.bookmarks.push(o)}else this.storage.bookmarks.push(o);s++}if(s>0)this.dirty=!0;return s}}function mt(){return`bm-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}var v=new Set;function N(){return{open(t){v.add(t),t.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close(t){v.delete(t)},message(t,e){}}}function C(t){let e=JSON.stringify({...t,timestamp:t.timestamp||Date.now()});for(let r of v)try{r.send(e)}catch{v.delete(r)}}function V(t,e){C({type:"story-update",data:{storyId:t,...e}})}function H(t,e){C({type:"story-add",data:{storyId:t,...e}})}function O(t){C({type:"story-remove",data:{storyId:t}})}function F(t){return`
|
|
3
3
|
<script>
|
|
4
4
|
(function() {
|
|
5
5
|
const ws = new WebSocket('${t}');
|
|
@@ -556,7 +556,7 @@ window.__stxPerformance = {
|
|
|
556
556
|
|
|
557
557
|
window.clearPerformanceMetrics = () => window.__stxPerformance.clear();
|
|
558
558
|
</script>
|
|
559
|
-
`}import T from"fs";import K from"path";var ft=".stx/story/presets.json",R=1,yt=10;class I{storage;storagePath;dirty=!1;constructor(t){this.storagePath=K.join(t,ft),this.storage=this.loadStorage()}loadStorage(){try{let t=T.readFileSync(this.storagePath,"utf-8"),e=JSON.parse(t);if(e.version!==R)return this.migrateStorage(e);return e}catch{return{version:R,presets:[],recentIds:[]}}}migrateStorage(t){return{version:R,presets:t.presets||[],recentIds:t.recentIds||[]}}async save(){if(!this.dirty)return;let t=K.dirname(this.storagePath);await T.promises.mkdir(t,{recursive:!0}),await T.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}createPreset(t,e,r={}){let s={id:ht(),name:t,description:r.description,props:e,componentId:r.componentId,created:Date.now(),usageCount:0,tags:r.tags};return this.storage.presets.push(s),this.dirty=!0,s}getPreset(t){return this.storage.presets.find((e)=>e.id===t)}getAllPresets(){return[...this.storage.presets]}getPresetsForComponent(t){return this.storage.presets.filter((e)=>!e.componentId||e.componentId===t)}getRecentPresets(){return this.storage.recentIds.map((t)=>this.getPreset(t)).filter((t)=>t!==void 0)}usePreset(t){let e=this.getPreset(t);if(!e)return;return e.lastUsed=Date.now(),e.usageCount++,this.storage.recentIds=[t,...this.storage.recentIds.filter((r)=>r!==t)].slice(0,yt),this.dirty=!0,e}updatePreset(t,e){let r=this.getPreset(t);if(!r)return;return Object.assign(r,e),this.dirty=!0,r}deletePreset(t){let e=this.storage.presets.findIndex((r)=>r.id===t);if(e===-1)return!1;return this.storage.presets.splice(e,1),this.storage.recentIds=this.storage.recentIds.filter((r)=>r!==t),this.dirty=!0,!0}searchPresets(t){let e=t.toLowerCase();return this.storage.presets.filter((r)=>{if(r.name.toLowerCase().includes(e))return!0;if(r.description?.toLowerCase().includes(e))return!0;if(r.tags?.some((s)=>s.toLowerCase().includes(e)))return!0;return!1})}getMostUsedPresets(t=5){return[...this.storage.presets].sort((e,r)=>r.usageCount-e.usageCount).slice(0,t)}exportPresets(t){let e=t?this.storage.presets.filter((r)=>t.includes(r.id)):this.storage.presets;return JSON.stringify({presets:e},null,2)}importPresets(t,e=!1){let r=JSON.parse(t),s=0;for(let o of r.presets){let a=this.storage.presets.find((c)=>c.id===o.id);if(a&&!e)continue;if(a)Object.assign(a,o);else this.storage.presets.push(o);s++}if(s>0)this.dirty=!0;return s}}function ht(){return`preset-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import _ from"fs";var q=new Map;async function b(t,e,r={}){let s=performance.now(),o=[];try{let a=await _.promises.stat(e),c=q.get(e),n;if(c&&c.mtime===a.mtimeMs)n=c.content;else n=await _.promises.readFile(e,"utf-8"),q.set(e,{content:n,mtime:a.mtimeMs,analyzed:null});let{processDirectives:d}=await import("./chunk-
|
|
559
|
+
`}import T from"fs";import K from"path";var ft=".stx/story/presets.json",R=1,yt=10;class I{storage;storagePath;dirty=!1;constructor(t){this.storagePath=K.join(t,ft),this.storage=this.loadStorage()}loadStorage(){try{let t=T.readFileSync(this.storagePath,"utf-8"),e=JSON.parse(t);if(e.version!==R)return this.migrateStorage(e);return e}catch{return{version:R,presets:[],recentIds:[]}}}migrateStorage(t){return{version:R,presets:t.presets||[],recentIds:t.recentIds||[]}}async save(){if(!this.dirty)return;let t=K.dirname(this.storagePath);await T.promises.mkdir(t,{recursive:!0}),await T.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}createPreset(t,e,r={}){let s={id:ht(),name:t,description:r.description,props:e,componentId:r.componentId,created:Date.now(),usageCount:0,tags:r.tags};return this.storage.presets.push(s),this.dirty=!0,s}getPreset(t){return this.storage.presets.find((e)=>e.id===t)}getAllPresets(){return[...this.storage.presets]}getPresetsForComponent(t){return this.storage.presets.filter((e)=>!e.componentId||e.componentId===t)}getRecentPresets(){return this.storage.recentIds.map((t)=>this.getPreset(t)).filter((t)=>t!==void 0)}usePreset(t){let e=this.getPreset(t);if(!e)return;return e.lastUsed=Date.now(),e.usageCount++,this.storage.recentIds=[t,...this.storage.recentIds.filter((r)=>r!==t)].slice(0,yt),this.dirty=!0,e}updatePreset(t,e){let r=this.getPreset(t);if(!r)return;return Object.assign(r,e),this.dirty=!0,r}deletePreset(t){let e=this.storage.presets.findIndex((r)=>r.id===t);if(e===-1)return!1;return this.storage.presets.splice(e,1),this.storage.recentIds=this.storage.recentIds.filter((r)=>r!==t),this.dirty=!0,!0}searchPresets(t){let e=t.toLowerCase();return this.storage.presets.filter((r)=>{if(r.name.toLowerCase().includes(e))return!0;if(r.description?.toLowerCase().includes(e))return!0;if(r.tags?.some((s)=>s.toLowerCase().includes(e)))return!0;return!1})}getMostUsedPresets(t=5){return[...this.storage.presets].sort((e,r)=>r.usageCount-e.usageCount).slice(0,t)}exportPresets(t){let e=t?this.storage.presets.filter((r)=>t.includes(r.id)):this.storage.presets;return JSON.stringify({presets:e},null,2)}importPresets(t,e=!1){let r=JSON.parse(t),s=0;for(let o of r.presets){let a=this.storage.presets.find((c)=>c.id===o.id);if(a&&!e)continue;if(a)Object.assign(a,o);else this.storage.presets.push(o);s++}if(s>0)this.dirty=!0;return s}}function ht(){return`preset-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import _ from"fs";var q=new Map;async function b(t,e,r={}){let s=performance.now(),o=[];try{let a=await _.promises.stat(e),c=q.get(e),n;if(c&&c.mtime===a.mtimeMs)n=c.content;else n=await _.promises.readFile(e,"utf-8"),q.set(e,{content:n,mtime:a.mtimeMs,analyzed:null});let{processDirectives:d}=await import("./chunk-brk1pk8w.js"),p={},g=h(n);if(g)try{await m(g,p,e)}catch(f){o.push(`Warning: Could not extract script variables: ${f instanceof Error?f.message:String(f)}`)}if(r.props)Object.assign(p,r.props);let i=await d(n,p,e,{},new Set),l=Z(n),u=h(n);return i=Q(i),i=tt(i,p),{html:i,css:l,js:u,errors:o,duration:performance.now()-s}}catch(a){return o.push(a instanceof Error?a.message:String(a)),{html:`<div class="stx-render-error">${et(o[0])}</div>`,css:"",js:"",errors:o,duration:performance.now()-s}}}async function vt(t){try{let e=await _.promises.readFile(t,"utf-8"),r=h(e);if(!r)return null;let s={};if(await m(r,s,t),Array.isArray(s.variants))return s.variants;return null}catch{return null}}async function Y(t,e,r,s){let o=e.story?.variants;if(!o){let n=await vt(e.path);if(n)o=n}if(!o&&r==="default")return b(t,e.path,{props:s||{}});if(!o)return b(t,e.path,{props:s||{}});let a=o.find((n)=>n.id===r);if(!a&&r==="default")return b(t,e.path,{props:s||{}});if(!a)return{html:'<div class="stx-render-error">Variant not found</div>',css:"",js:"",errors:[`Variant '${r}' not found`],duration:0};let c={...a.state,...s};if(a.source)return bt(t,a.source,c);return b(t,e.path,{props:c})}async function bt(t,e,r={}){let s=performance.now(),o=[];try{let{processDirectives:a}=await import("./chunk-brk1pk8w.js"),c={...r},n=h(e);if(n)try{await m(n,c,"inline-template.stx")}catch{}let p=await a(e,c,"inline-template.stx",{},new Set);return p=Q(p),p=tt(p,c),{html:p,css:Z(e),js:h(e),errors:o,duration:performance.now()-s}}catch(a){return o.push(a instanceof Error?a.message:String(a)),{html:`<div class="stx-render-error">${et(o[0])}</div>`,css:"",js:"",errors:o,duration:performance.now()-s}}}function Z(t){let e=[],r=/<style\b[^>]*>([\s\S]*?)<\/style>/gi,s=r.exec(t);while(s!==null)e.push(s[1].trim()),s=r.exec(t);return e.join(`
|
|
560
560
|
`)}function Q(t){return t.replace(/<!--[\s\S]*?-->/g,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/^\s*\n/gm,"").trim()}function h(t){let e=[],r=/<script\b[^>]*>([\s\S]*?)<\/script>/gi,s=r.exec(t);while(s!==null)e.push(s[1].trim()),s=r.exec(t);return e.join(`
|
|
561
561
|
`)}function tt(t,e){let r=`<script>window.__stxProps = ${JSON.stringify(e)};</script>`;return t+r}function et(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function rt(t,e){let r=await qt(t);dt(t,r);let s=Kt(t.config,r);pt(t,s),console.log(` Found ${r.length} story files`);let o=typeof e.host==="string"?e.host:e.host===!0?"0.0.0.0":"localhost",a=new I(t.root),c=new P(t.root),n=new k(t.root),d=N(),p=Bun.serve({port:e.port,hostname:o,fetch:async(i,l)=>{let f=new URL(i.url).pathname;if(f==="/__hmr"){if(l.upgrade(i,{data:{isHmr:!0}}))return;return new Response("WebSocket upgrade failed",{status:400})}if(f.startsWith("/api/"))return xt(t,f,i,{presetsManager:a,bookmarksManager:c,analyticsTracker:n});return wt(t,f,e.port)},websocket:{open(i){d.open(i)},close(i){d.close(i)},message(i,l){d.message(i,l)}}}),g=`http://${o}:${e.port}`,y=Xi(t,async(i,l)=>{console.log(` [${i}] ${l.relativePath}`);let u=await qt(t);dt(t,u);let f=Kt(t.config,u);if(pt(t,f),i==="add")H(l.id,{fileName:l.fileName});else if(i==="unlink")O(l.id);else V(l.id,{fileName:l.fileName})});if(e.open){let i=g;try{let{exec:l}=await import("child_process"),u=process.platform;l(`${u==="darwin"?"open":u==="win32"?"start":"xdg-open"} ${i}`)}catch{}}return{server:p,url:g,close:async()=>{y(),p.stop()}}}async function xt(t,e,r,s){let{presetsManager:o,bookmarksManager:a,analyticsTracker:c}=s;if(e==="/api/stories")return Response.json({files:t.storyFiles.map((n)=>({id:n.id,fileName:n.fileName,relativePath:n.relativePath,treePath:n.treePath})),tree:t.tree});if(e.startsWith("/api/story/")){let n=e.slice(11),d=t.storyFiles.find((p)=>p.id===n);if(!d)return new Response("Story not found",{status:404});try{let p=await Bun.file(d.path).text();return Response.json({id:d.id,fileName:d.fileName,relativePath:d.relativePath,content:p})}catch{return new Response("Error reading story",{status:500})}}if(e==="/api/config")return Response.json({theme:t.config.theme,responsivePresets:t.config.responsivePresets,backgroundPresets:t.config.backgroundPresets});if(e.startsWith("/api/render/")){let n=new URL(r.url),d=e.slice(12).split("/"),p=d[0],g=d[1]||"default",y,i=n.searchParams.get("props");if(i)try{y=JSON.parse(i)}catch{}let l=t.storyFiles.find((u)=>u.id===p);if(!l)return new Response("Story not found",{status:404});try{let u=await Y(t,l,g,y);return Response.json({html:u.html,css:u.css,js:u.js,errors:u.errors,duration:u.duration})}catch(u){return Response.json({html:"",css:"",js:"",errors:[u instanceof Error?u.message:String(u)],duration:0},{status:500})}}if(e==="/api/presets"&&r.method==="GET")return Response.json({presets:o.getAllPresets()});if(e==="/api/presets"&&r.method==="POST")try{let n=await r.json(),d=o.createPreset(n.name,n.props,{componentId:n.componentId,description:n.description});return await o.save(),Response.json(d)}catch(n){return Response.json({error:String(n)},{status:400})}if(e.startsWith("/api/presets/")&&!e.includes("/use")&&r.method==="GET"){let n=e.slice(13),d=o.getPreset(n);if(!d)return new Response("Preset not found",{status:404});return Response.json(d)}if(e.endsWith("/use")&&r.method==="POST"){let n=e.slice(13,-4),d=o.usePreset(n);if(!d)return new Response("Preset not found",{status:404});return await o.save(),Response.json(d)}if(e.startsWith("/api/presets/")&&r.method==="DELETE"){let n=e.slice(13);if(!o.deletePreset(n))return new Response("Preset not found",{status:404});return await o.save(),Response.json({success:!0})}if(e==="/api/bookmarks"&&r.method==="GET")return Response.json({bookmarks:a.getAllBookmarks()});if(e==="/api/bookmarks"&&r.method==="POST")try{let n=await r.json(),d=a.addBookmark(n.storyId,n.variantId,n.props,{name:n.name,notes:n.notes,color:n.color});return await a.save(),Response.json(d)}catch(n){return Response.json({error:String(n)},{status:400})}if(e==="/api/bookmarks/toggle"&&r.method==="POST")try{let n=await r.json(),d=a.toggleBookmark(n.storyId,n.variantId,n.props);return await a.save(),Response.json(d)}catch(n){return Response.json({error:String(n)},{status:400})}if(e.startsWith("/api/bookmarks/")&&e!=="/api/bookmarks/toggle"&&r.method==="GET"){let n=e.slice(15),d=a.getBookmark(n);if(!d)return new Response("Bookmark not found",{status:404});return Response.json(d)}if(e.startsWith("/api/bookmarks/")&&r.method==="DELETE"){let n=e.slice(15);if(!a.deleteBookmark(n))return new Response("Bookmark not found",{status:404});return await a.save(),Response.json({success:!0})}if(e==="/api/analytics/track"&&r.method==="POST")try{let n=await r.json();if(n.type==="view"&&n.componentId)c.trackView(n.componentId,n.variantId);else if(n.type==="prop_change"&&n.componentId&&n.propName)c.trackPropChange(n.componentId,n.propName,null);else if(n.type==="variant_switch"&&n.componentId&&n.variantId)c.trackVariantSwitch(n.componentId,n.variantId);else if(n.type==="search"&&n.query)c.trackSearch(n.query,0);return await c.save(),Response.json({success:!0})}catch(n){return Response.json({error:String(n)},{status:400})}if(e==="/api/analytics/summary"&&r.method==="GET")return Response.json({mostViewed:c.getMostViewedComponents(10),mostChangedProps:c.getMostChangedProps(10),searchAnalytics:c.getSearchAnalytics()});if(e.startsWith("/api/analytics/component/")&&r.method==="GET"){let n=e.slice(25),d=t.storyFiles.find((g)=>g.id===n),p=c.getComponentAnalytics(n,d?.fileName||n);return Response.json(p)}return new Response("Not found",{status:404})}function wt(t,e,r){let s=kt(t,r);return new Response(s,{headers:{"Content-Type":"text/html; charset=utf-8"}})}function kt(t,e){let{theme:r}=t.config,s=r.title||"STX Story",o=`ws://localhost:${e}/__hmr`,a=F(o);return`<!DOCTYPE html>
|
|
562
562
|
<html lang="en" class="${r.darkClass||"dark"}">
|
|
@@ -1276,5 +1276,5 @@ else {
|
|
|
1276
1276
|
<style>${W()}</style>
|
|
1277
1277
|
${D()}
|
|
1278
1278
|
</body>
|
|
1279
|
-
</html>`}import St from"fs";import Pt from"path";var Ct=new Map,Tt=[],Rt=[],It=new Map;async function ot(t){let e=t.config.setupFile;if(!e)return;let r=Pt.resolve(t.root,e);try{await St.promises.access(r)}catch{return}let s={storyContext:t,registerComponent:(o,a)=>{Ct.set(o,a)},addCSS:(o)=>{Tt.push(o)},addScript:(o)=>{Rt.push(o)},setState:(o,a)=>{It.set(o,a)}};try{let o=await import(r);if(typeof o.default==="function")await o.default(s);else if(typeof o.setupStory==="function")await o.setupStory(s)}catch(o){console.warn(`Warning: Failed to load setup file: ${o}`)}}async function we(t={}){Ut();let e=await ut({mode:"dev"});if(!e.config.enabled){lt("Story feature is disabled in config.");return}await ot(e);let r=t.port??e.config.port,s,o=async()=>{s=await rt(e,{port:r,open:t.open,host:t.host}),Wt(e.storyFiles.length),
|
|
1280
|
-
`),a.stop(),await s.close(),process.exit(0)};if(process.on("SIGINT",c),process.on("SIGTERM",c),process.stdin.isTTY)process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.on("data",async(n)=>{switch(n.toString()){case"h":
|
|
1279
|
+
</html>`}import St from"fs";import Pt from"path";var Ct=new Map,Tt=[],Rt=[],It=new Map;async function ot(t){let e=t.config.setupFile;if(!e)return;let r=Pt.resolve(t.root,e);try{await St.promises.access(r)}catch{return}let s={storyContext:t,registerComponent:(o,a)=>{Ct.set(o,a)},addCSS:(o)=>{Tt.push(o)},addScript:(o)=>{Rt.push(o)},setState:(o,a)=>{It.set(o,a)}};try{let o=await import(r);if(typeof o.default==="function")await o.default(s);else if(typeof o.setupStory==="function")await o.setupStory(s)}catch(o){console.warn(`Warning: Failed to load setup file: ${o}`)}}async function we(t={}){Ut();let e=await ut({mode:"dev"});if(!e.config.enabled){lt("Story feature is disabled in config.");return}await ot(e);let r=t.port??e.config.port,s,o=async()=>{s=await rt(e,{port:r,open:t.open,host:t.host}),Wt(e.storyFiles.length),ro(s.url),so()};await o();let a=E(e,{onChange:async()=>{await s.close();let n=await ut({mode:"dev"});Object.assign(e,n),await o()}}),c=async()=>{console.log(`
|
|
1280
|
+
`),a.stop(),await s.close(),process.exit(0)};if(process.on("SIGINT",c),process.on("SIGTERM",c),process.stdin.isTTY)process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.on("data",async(n)=>{switch(n.toString()){case"h":so();break;case"o":try{let{exec:p}=await import("child_process"),g=process.platform==="darwin"?"open":process.platform==="win32"?"start":"xdg-open";p(`${g} ${s.url}`)}catch{Wi("Failed to open browser")}break;case"r":await s.close(),await o();break;case"c":console.clear(),Ut(),Wt(e.storyFiles.length),ro(s.url);break;case"q":case"\x03":await c();break}});await new Promise(()=>{})}export{we as devCommand};
|