@stacksjs/docs 0.75.667 → 0.75.668

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.
@@ -109,7 +109,7 @@ ${n}::-webkit-search-cancel-button { visibility: hidden !important; }
109
109
  return true
110
110
  })()`,Re=(e)=>e[0]===137&&e[1]===80?"image/png":"image/jpeg";async function te(e,i){if(!Number.isInteger(i.fps)||i.fps<1||i.fps>60)throw Error("Film frames per second must be an integer from 1 to 60");await e(Fe(i));let n=[],t,c={width:0,height:0},f=0,p=async(u)=>{let m=JSON.parse(String(await e(`window.__stacksFilm.drain(${u})`)));if(c={width:m.width,height:m.height},m.description)t=new Uint8Array(Buffer.from(m.description,"base64"));for(let[o,s,l]of m.chunks)n.push([o,s,new Uint8Array(Buffer.from(l,"base64"))])};return{frames:()=>f,async add(u,m){if(!Number.isInteger(m)||m<1)return;let o=u?`${JSON.stringify(Buffer.from(u).toString("base64"))}, ${JSON.stringify(Re(u))}`:"null, null";if(await e(`window.__stacksFilm.add(${o}, ${m})`),f+=m,f%(i.fps*20)<m)await p(!1)},async addVideo(u,m=[]){for(let s of m)if(![s.x,s.y,s.size,s.start,s.end].every(Number.isFinite)||!/^#[0-9a-f]{6}$/i.test(s.color))throw Error("Invalid film mark");let o=JSON.parse(String(await e(`window.__stacksFilm.open(${JSON.stringify(u)})`)));for(let s=0;s<o.frames;s+=i.fps){let l=Math.min(i.fps,o.frames-s);await e(`window.__stacksFilm.copy(${s}, ${l}, ${JSON.stringify(m)})`),f+=l,await p(!1)}return o.seconds},async finish(){if(await p(!0),!n.length||!t)throw Error("The browser encoded no video");let u=new Oe,m=new Me(u),o=m.addVideoTrack({codec:"h264",width:c.width,height:c.height,frameRate:i.fps,codecDescription:t});for(let[s,l,r]of n)await m.writePacket(o.id,{data:r,timestamp:l/1e6,duration:1/i.fps,isKeyframe:s===1});return await m.finalize(),u.buffer}}}import{createHash as Te}from"crypto";import{lstat as Be,mkdir as Ne,readFile as re,rename as se}from"fs/promises";import{dirname as Ce,isAbsolute as Ue,join as L,relative as Ae,resolve as ie}from"path";var oe="<!-- Generated by buddy docs:screenshots. Edit config/screenshots.ts instead. -->",ne=(e)=>Te("sha256").update(e).digest("hex"),N=(e)=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;"),T=(e)=>N(e).replace(/[\r\n]+/g," ").replace(/([\\`*_[\]#|])/g,"\\$1");function ae(e,i,n,t){if(e){let c=e.secondsPerScreen??2;if(!Number.isFinite(c)||c<0.2||c>30)throw Error("film.secondsPerScreen must be between 0.2 and 30");if(!Number.isInteger(e.fps??12)||(e.fps??12)<1||(e.fps??12)>60)throw Error("film.fps must be an integer from 1 to 60");for(let f of e.viewports??[])if(!t.some((p)=>p.name===f))throw Error(`Unknown film viewport: ${f}`)}if(i){let c=ie(n,i.page);if(Ue(i.page)||Ae(n,c).startsWith("..")||!i.page.endsWith(".md"))throw Error("docs.page must be a Markdown file inside the project");if(!/^\/[\w./-]*$/.test(i.base)||i.base.includes(".."))throw Error("docs.base must be a site path such as /screens")}}async function J(e,i,n,t,c=process.platform==="darwin"?"webkit":"chrome"){let f=[],p=t.secondsPerScreen??2,u=t.fps??12,m=Math.max(1,Math.round(p*u)),o=D(c),s=ee();try{for(let l of n){if(t.viewports?.length&&!t.viewports.includes(l.name))continue;let r=i.filter((y)=>y.status==="captured"&&y.file&&y.viewport.name===l.name);if(!r.length)continue;let a,d;try{d=await o.view(320,240);let y=d;await y.navigate(s.url);let x=await te((b)=>y.evaluate(b),{fps:u,width:l.width,height:l.height});for(let b of r)await x.add(new Uint8Array(await re(L(e,b.file))),m);a=await x.finish()}catch(y){throw Error(`The ${l.name} screens could not be filmed: ${y instanceof Error?y.message.slice(0,400):"the browser failed"}`)}finally{d?.close()}let h=`film-${l.name}.mp4`;await Bun.write(L(e,`${h}.tmp`),a),await se(L(e,`${h}.tmp`),L(e,h)),f.push({viewport:l.name,file:h,sha256:ne(a),screens:r.length,seconds:r.length*m/u})}return f}finally{try{await o.close()}finally{s.stop()}}}function De(e,i){let n=i.base.replace(/\/+$/,""),t=i.title??"Screens",c=e.results.filter((o)=>o.status==="captured"&&o.file),f=["---",`title: ${JSON.stringify(t)}`,`description: ${JSON.stringify(i.description??"Every screen of the application, captured automatically from its views.")}`,"---","",oe,"",`# ${T(t)}`,"",`${new Set(c.map((o)=>o.id)).size} of ${e.inventory.length} screens, captured automatically from the application's views with @stacksjs/docs ${e.generatorVersion}. A new view appears here after the next capture.`,""];for(let o of e.films??[]){let s=c.find((l)=>l.viewport.name===o.viewport);f.push(`## Walkthrough video (${T(o.viewport)})`,"",`<video controls playsinline preload="none" src="${N(`${n}/${o.file}`)}"${s?` poster="${N(`${n}/${s.file}`)}"`:""} style="width:100%;max-width:${s&&s.viewport.width<600?s.viewport.width:1100}px;height:auto"></video>`,"",`${o.screens} screens in ${Math.round(o.seconds)} seconds. [Download the video](${n}/${o.file}).`,"")}let p=(o)=>o.split("/").filter(Boolean)[0]?.replace(/^[[:].*/,"profiles")??"home",u=new Map;for(let o of e.inventory)u.set(p(o.path),[...u.get(p(o.path))??[],o]);let m=[];for(let[o,s]of[...u].sort(([l],[r])=>l.localeCompare(r))){let l=[];for(let r of s){let a=c.filter((d)=>d.id===r.id);if(!a.length){let d=e.results.find((h)=>h.id===r.id);m.push(`- ${T(r.title)} (\`${r.path}\`): ${r.skip?T(r.skip):d?"the last capture failed.":"not captured yet."}`);continue}l.push(`### ${T(r.title)}`,"",T(a[0].description),"",...a[0].reason?[T(a[0].reason),""]:[],`Address: \`${r.path}\``,"");for(let d of a)l.push("<figure>",` <img src="${N(`${n}/${d.file}`)}" alt="${N(`${d.title}, ${d.viewport.name}`)}" width="${d.viewport.width}" height="${d.viewport.height}" loading="lazy" style="display:block;width:100%;max-width:${d.viewport.width}px;height:auto">`,` <figcaption>${N(d.viewport.name)}, ${d.viewport.width} by ${d.viewport.height}${d.profile==="default"?"":`, signed in as ${N(d.profile)}`}</figcaption>`,"</figure>","")}if(l.length)f.push(`## ${T(o[0].toUpperCase()+o.slice(1).replace(/[-_]+/g," "))}`,"",...l)}if(m.length)f.push("## Not pictured","","These screens are part of the application and have no picture here.","",...m,"");return`${f.join(`
111
111
  `).trimEnd()}
112
- `}async function _(e,i,n){let t=ie(e,n.page);try{if((await Be(t)).isSymbolicLink()||!(await re(t,"utf8")).includes(oe))throw Error(`Refusing to replace a hand-written page: ${n.page}`)}catch(f){if(f.code!=="ENOENT")throw f}let c=De(i,n);return await Ne(Ce(t),{recursive:!0}),await Bun.write(`${t}.tmp`,c),await se(`${t}.tmp`,t),{path:n.page,sha256:ne(c)}}import{createRouter as Ve}from"@stacksjs/stx";import{readFileSync as He}from"fs";import{relative as Le,resolve as We}from"path";var ce=(e)=>e.replace(/[-_]+/g," ").replace(/\s+/g," ").trim(),Je=(e)=>e?e[0].toUpperCase()+e.slice(1):e;function _e(e){try{return He(e,"utf8")}catch{return""}}function qe(e,i){let n=e.match(/<title>([^<{@]+)<\/title>/i)?.[1]?.trim();if(n)return n;let t=i.split("/").filter(Boolean).map((c)=>c.startsWith("[")?`by ${ce(c.slice(1,-1).replace(/^\.\.\./,""))}`:ce(c));return t.length?Je(t.join(" / ")):"Home"}function le(e={}){let i=We(e.root??process.cwd()),n=[],t=new Set;for(let c of e.directories??["resources/views"])for(let f of Ve(i,{pagesDir:c,emit:!1})){let p=f.pattern.replace(/\*(\w*)/g,(l,r)=>`[...${r||"path"}]`).replace(/:(\w+)/g,"[$1]"),u=p.split("/").filter(Boolean).map((l)=>l.replace(/[^a-z0-9]+/gi,"-").replace(/^-|-$/g,"")).filter(Boolean).join("-").toLowerCase()||"index",m=u;for(let l=2;t.has(m);l++)m=`${u}-${l}`;t.add(m);let o=_e(f.filePath),s=o.match(/@(?:extends|layout)\(\s*['"]([^'"]+)['"]/)?.[1];n.push({id:m,route:p,source:Le(i,f.filePath).replaceAll("\\","/"),group:p.split("/").filter(Boolean)[0]?.replace(/^\[.*\]$/,"profile")??"home",params:[...f.params],dynamic:f.isDynamic,title:qe(o,p),...s?{layout:s}:{},text:o})}return n.sort((c,f)=>c.route<f.route?-1:c.route>f.route?1:0)}function Ie(e={}){let i=[],n=new Set;for(let t of le(e)){n.add(t.route);let c=[e.each?.(t),e.routes?.[t.route]],f={id:t.id,title:t.title,path:t.route,description:`The ${t.title} screen, served at ${t.route}.`,waitFor:"body",...e.defaults,sources:[t.source]};for(let p of c){if(p===void 0)continue;if(p===!1||typeof p==="string"){f.skip=p||"Left out of the screen documentation on purpose.";continue}Object.assign(f,p)}if(t.dynamic&&typeof f.path==="string"&&f.path===t.route&&!f.model&&!f.skip){if(e.strict)throw Error(`Dynamic view needs a concrete path or model: ${t.route} (${t.source})`);f.skip=`Needs a seeded example: give ${t.route} a concrete path, fixture resolver or model.`}if(typeof f.path==="function"&&!f.route)f.route=t.route;i.push(f)}for(let t of Object.keys(e.routes??{}))if(!n.has(t))throw Error(`Screenshot rule for a view that does not exist: ${t}`);return[...i,...e.extra??[]]}import{spawnOwnedProcess as Ze}from"@stacksjs/cli/owned-process";import{ChromeLaunchError as et}from"@stacksjs/testing/browser";var C="0.75.667";var Vt=(e)=>e,F=[{name:"desktop",width:1440,height:900},{name:"mobile",width:390,height:844}],A=(e)=>Ke("sha256").update(e).digest("hex"),I=(e)=>/^[a-z0-9][a-z0-9._-]*$/i.test(e)&&!e.endsWith(".")&&!/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(e),de=(e)=>{let i=new URL(e);return i.origin+i.pathname};async function he(e,i=process.cwd()){let n=new URL(e.baseUrl);if(!["http:","https:"].includes(n.protocol)||n.username||n.password||n.search||n.hash)throw Error("baseUrl must be an http(s) URL without credentials, query or fragment");if(!e.outDir||!e.pages.length)throw Error("outDir and at least one page are required");if(e.timeoutMs!==void 0&&(!Number.isFinite(e.timeoutMs)||e.timeoutMs<100||e.timeoutMs>120000))throw Error("timeoutMs must be between 100 and 120000");if(e.backend&&!["webkit","chrome"].includes(e.backend))throw Error("backend must be webkit or chrome");if(e.requireHttpStatus!==void 0&&typeof e.requireHttpStatus!=="boolean")throw Error("requireHttpStatus must be a boolean");let t=Object.keys(e.profiles??{default:{}});if(!t.length||t.some((o)=>!I(o)))throw Error("Profile names must be safe filenames");let c=new Set,f=new Set;for(let o of e.pages){if(!I(o.id)||c.has(o.id))throw Error(`Duplicate or invalid screen id: ${o.id}`);if(c.add(o.id),o.expectedStatus!==void 0&&(!Number.isInteger(o.expectedStatus)||o.expectedStatus<100||o.expectedStatus>599))throw Error(`Invalid expected HTTP status for ${o.id}`);if(!o.title.trim()||!o.description.trim()||!o.waitFor.trim())throw Error(`Screen ${o.id} needs title, description and waitFor`);if(typeof o.path!=="string"&&(typeof o.path!=="function"||!o.route))throw Error(`Screen ${o.id} needs a route pattern for its path resolver`);let s=new URL(typeof o.path==="string"?o.path:o.route,n);if(s.origin!==n.origin||s.username||s.password)throw Error(`Screen ${o.id} must stay on baseUrl's origin`);if(o.profiles?.some((l)=>!t.includes(l))||o.profiles?.length===0)throw Error(`Unknown or empty profiles for ${o.id}`);for(let l of o.sources??[]){let r=v(i,l);if(B(i,r).startsWith("..")||ue(l))throw Error(`Source must be inside the project: ${l}`);await M(r),f.add(B(i,r).replaceAll("\\","/"))}}let p=new Set;for(let o of e.viewports??F){if(!I(o.name)||p.has(o.name)||![o.width,o.height].every((s)=>Number.isInteger(s)&&s>=200&&s<=7680))throw Error("Viewports need unique safe names and integer dimensions from 200 to 7680");p.add(o.name)}if(!p.size)throw Error("At least one viewport is required");for(let o of e.pages)if(o.viewports!==void 0&&(!o.viewports.length||o.viewports.some((s)=>!p.has(s))))throw Error(`Unknown or empty viewports for ${o.id}`);for(let o of e.inputs??[])await M(v(i,o));ae(e.film===!0?{}:e.film,e.docs,i,e.viewports??F);let u=[],m=new Set;for(let o of e.coverage?.directories??[]){let s=v(i,o);if(B(i,s).startsWith(".."))throw Error("Coverage directories must be inside the project");if(!(await Qe(s)).isDirectory())throw Error(`Missing coverage directory: ${o}`);let l=0;for await(let r of new Bun.Glob("**/*.stx").scan({cwd:s,onlyFiles:!0})){l++;let a=B(i,g(s,r)).replaceAll("\\","/");if(m.add(a),!f.has(a)&&!e.coverage?.exclude?.[a]?.trim())u.push(a)}if(!l)throw Error(`No .stx screens found in ${o}`)}for(let[o,s]of Object.entries(e.coverage?.exclude??{}))if(!s.trim()||!m.has(o))throw Error(`Stale or unexplained coverage exclusion: ${o}`);if(u.length)throw Error(`Undocumented screens:
112
+ `}async function _(e,i,n){let t=ie(e,n.page);try{if((await Be(t)).isSymbolicLink()||!(await re(t,"utf8")).includes(oe))throw Error(`Refusing to replace a hand-written page: ${n.page}`)}catch(f){if(f.code!=="ENOENT")throw f}let c=De(i,n);return await Ne(Ce(t),{recursive:!0}),await Bun.write(`${t}.tmp`,c),await se(`${t}.tmp`,t),{path:n.page,sha256:ne(c)}}import{createRouter as Ve}from"@stacksjs/stx";import{readFileSync as He}from"fs";import{relative as Le,resolve as We}from"path";var ce=(e)=>e.replace(/[-_]+/g," ").replace(/\s+/g," ").trim(),Je=(e)=>e?e[0].toUpperCase()+e.slice(1):e;function _e(e){try{return He(e,"utf8")}catch{return""}}function qe(e,i){let n=e.match(/<title>([^<{@]+)<\/title>/i)?.[1]?.trim();if(n)return n;let t=i.split("/").filter(Boolean).map((c)=>c.startsWith("[")?`by ${ce(c.slice(1,-1).replace(/^\.\.\./,""))}`:ce(c));return t.length?Je(t.join(" / ")):"Home"}function le(e={}){let i=We(e.root??process.cwd()),n=[],t=new Set;for(let c of e.directories??["resources/views"])for(let f of Ve(i,{pagesDir:c,emit:!1})){let p=f.pattern.replace(/\*(\w*)/g,(l,r)=>`[...${r||"path"}]`).replace(/:(\w+)/g,"[$1]"),u=p.split("/").filter(Boolean).map((l)=>l.replace(/[^a-z0-9]+/gi,"-").replace(/^-|-$/g,"")).filter(Boolean).join("-").toLowerCase()||"index",m=u;for(let l=2;t.has(m);l++)m=`${u}-${l}`;t.add(m);let o=_e(f.filePath),s=o.match(/@(?:extends|layout)\(\s*['"]([^'"]+)['"]/)?.[1];n.push({id:m,route:p,source:Le(i,f.filePath).replaceAll("\\","/"),group:p.split("/").filter(Boolean)[0]?.replace(/^\[.*\]$/,"profile")??"home",params:[...f.params],dynamic:f.isDynamic,title:qe(o,p),...s?{layout:s}:{},text:o})}return n.sort((c,f)=>c.route<f.route?-1:c.route>f.route?1:0)}function Ie(e={}){let i=[],n=new Set;for(let t of le(e)){n.add(t.route);let c=[e.each?.(t),e.routes?.[t.route]],f={id:t.id,title:t.title,path:t.route,description:`The ${t.title} screen, served at ${t.route}.`,waitFor:"body",...e.defaults,sources:[t.source]};for(let p of c){if(p===void 0)continue;if(p===!1||typeof p==="string"){f.skip=p||"Left out of the screen documentation on purpose.";continue}Object.assign(f,p)}if(t.dynamic&&typeof f.path==="string"&&f.path===t.route&&!f.model&&!f.skip){if(e.strict)throw Error(`Dynamic view needs a concrete path or model: ${t.route} (${t.source})`);f.skip=`Needs a seeded example: give ${t.route} a concrete path, fixture resolver or model.`}if(typeof f.path==="function"&&!f.route)f.route=t.route;i.push(f)}for(let t of Object.keys(e.routes??{}))if(!n.has(t))throw Error(`Screenshot rule for a view that does not exist: ${t}`);return[...i,...e.extra??[]]}import{spawnOwnedProcess as Ze}from"@stacksjs/cli/owned-process";import{ChromeLaunchError as et}from"@stacksjs/testing/browser";var C="0.75.668";var Vt=(e)=>e,F=[{name:"desktop",width:1440,height:900},{name:"mobile",width:390,height:844}],A=(e)=>Ke("sha256").update(e).digest("hex"),I=(e)=>/^[a-z0-9][a-z0-9._-]*$/i.test(e)&&!e.endsWith(".")&&!/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(e),de=(e)=>{let i=new URL(e);return i.origin+i.pathname};async function he(e,i=process.cwd()){let n=new URL(e.baseUrl);if(!["http:","https:"].includes(n.protocol)||n.username||n.password||n.search||n.hash)throw Error("baseUrl must be an http(s) URL without credentials, query or fragment");if(!e.outDir||!e.pages.length)throw Error("outDir and at least one page are required");if(e.timeoutMs!==void 0&&(!Number.isFinite(e.timeoutMs)||e.timeoutMs<100||e.timeoutMs>120000))throw Error("timeoutMs must be between 100 and 120000");if(e.backend&&!["webkit","chrome"].includes(e.backend))throw Error("backend must be webkit or chrome");if(e.requireHttpStatus!==void 0&&typeof e.requireHttpStatus!=="boolean")throw Error("requireHttpStatus must be a boolean");let t=Object.keys(e.profiles??{default:{}});if(!t.length||t.some((o)=>!I(o)))throw Error("Profile names must be safe filenames");let c=new Set,f=new Set;for(let o of e.pages){if(!I(o.id)||c.has(o.id))throw Error(`Duplicate or invalid screen id: ${o.id}`);if(c.add(o.id),o.expectedStatus!==void 0&&(!Number.isInteger(o.expectedStatus)||o.expectedStatus<100||o.expectedStatus>599))throw Error(`Invalid expected HTTP status for ${o.id}`);if(!o.title.trim()||!o.description.trim()||!o.waitFor.trim())throw Error(`Screen ${o.id} needs title, description and waitFor`);if(typeof o.path!=="string"&&(typeof o.path!=="function"||!o.route))throw Error(`Screen ${o.id} needs a route pattern for its path resolver`);let s=new URL(typeof o.path==="string"?o.path:o.route,n);if(s.origin!==n.origin||s.username||s.password)throw Error(`Screen ${o.id} must stay on baseUrl's origin`);if(o.profiles?.some((l)=>!t.includes(l))||o.profiles?.length===0)throw Error(`Unknown or empty profiles for ${o.id}`);for(let l of o.sources??[]){let r=v(i,l);if(B(i,r).startsWith("..")||ue(l))throw Error(`Source must be inside the project: ${l}`);await M(r),f.add(B(i,r).replaceAll("\\","/"))}}let p=new Set;for(let o of e.viewports??F){if(!I(o.name)||p.has(o.name)||![o.width,o.height].every((s)=>Number.isInteger(s)&&s>=200&&s<=7680))throw Error("Viewports need unique safe names and integer dimensions from 200 to 7680");p.add(o.name)}if(!p.size)throw Error("At least one viewport is required");for(let o of e.pages)if(o.viewports!==void 0&&(!o.viewports.length||o.viewports.some((s)=>!p.has(s))))throw Error(`Unknown or empty viewports for ${o.id}`);for(let o of e.inputs??[])await M(v(i,o));ae(e.film===!0?{}:e.film,e.docs,i,e.viewports??F);let u=[],m=new Set;for(let o of e.coverage?.directories??[]){let s=v(i,o);if(B(i,s).startsWith(".."))throw Error("Coverage directories must be inside the project");if(!(await Qe(s)).isDirectory())throw Error(`Missing coverage directory: ${o}`);let l=0;for await(let r of new Bun.Glob("**/*.stx").scan({cwd:s,onlyFiles:!0})){l++;let a=B(i,g(s,r)).replaceAll("\\","/");if(m.add(a),!f.has(a)&&!e.coverage?.exclude?.[a]?.trim())u.push(a)}if(!l)throw Error(`No .stx screens found in ${o}`)}for(let[o,s]of Object.entries(e.coverage?.exclude??{}))if(!s.trim()||!m.has(o))throw Error(`Stale or unexplained coverage exclusion: ${o}`);if(u.length)throw Error(`Undocumented screens:
113
113
  ${u.sort().join(`
114
114
  `)}`)}async function G(e){let i=(await import(Ye(e).href)).default;if(!i||typeof i!=="object")throw Error("Screenshot configuration must have a default export");return i}async function tt(e,i){let n=Date.now()+i;while(!await e()){if(Date.now()>=n)throw Error("The screen did not become ready before its deadline");await Bun.sleep(100)}}function me(e,i){let n=e instanceof Error?e.message:"Screenshot capture failed";if(e instanceof et&&e.diagnostics.stderrTail.trim()){let t=e.diagnostics.stderrTail.trim(),c=t.split(`
115
115
  `).filter((f)=>/FATAL|Check failed/.test(f)).at(-1)??t.slice(-750);n=`${n.split(`
package/dist/stories.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{createHash as it,randomUUID as dt}from"crypto";import{createReadStream as lt}from"fs";import{copyFile as ft,lstat as X,mkdir as U,open as ut,readFile as b,realpath as pt,rename as z,rm as et,writeFile as C}from"fs/promises";import{basename as ht,dirname as V,isAbsolute as q,join as n,relative as k,resolve as x,sep as ot}from"path";import{pathToFileURL as wt}from"url";var tt="0.75.667";function $t(t){return t}function jt(t){return t}var I=`stacks-story-recordings-v1
2
+ import{createHash as it,randomUUID as dt}from"crypto";import{createReadStream as lt}from"fs";import{copyFile as ft,lstat as X,mkdir as U,open as ut,readFile as b,realpath as pt,rename as z,rm as et,writeFile as C}from"fs/promises";import{basename as ht,dirname as V,isAbsolute as q,join as n,relative as k,resolve as x,sep as ot}from"path";import{pathToFileURL as wt}from"url";var tt="0.75.668";function $t(t){return t}function jt(t){return t}var I=`stacks-story-recordings-v1
3
3
  `,_="<!-- Generated by buddy docs:stories. -->",N=(t)=>it("sha256").update(t).digest("hex"),rt=(t)=>typeof t==="string"&&/^[a-z0-9][a-z0-9-]{0,79}$/.test(t);function E(t){return t.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replace(/[\r\n]/g," ").replace(/([\\`*_[\]#|])/g,"\\$1")}async function O(t){try{return await X(t),!0}catch(s){if(s.code==="ENOENT")return!1;throw s}}async function y(t,s=t){let o=x(t);while(!0){if(await O(o)){if((await X(o)).isSymbolicLink())throw Error(`Story output cannot traverse a symbolic link: ${o}`)}if(o===x(s))return;let e=V(o);if(e===o)return;o=e}}async function F(t,s){await y(s,t);let o=await X(s);if(!o.isFile()||o.size===0)throw Error(`Missing or empty story artifact: ${s}`);let e=it("sha256"),l=0;for await(let u of lt(s))e.update(u),l+=u.length;return{path:k(t,s).split(ot).join("/"),sha256:e.digest("hex"),bytes:l}}function G(t,s){let o=x(t,s.path);if(!s.path||q(s.path)||k(t,o).startsWith(".."))throw Error("Story artifact escaped its output directory");return o}function st(t,s){let o=k(t,s);return o&&!o.startsWith("..")&&!q(o)?o.split(ot).join("/"):s}async function gt(t){if(!t||!Array.isArray(t.stories)||!t.stories.length)throw Error("Story configuration needs at least one story");let s=new Set,o=(e,l,u,r)=>{if(!Number.isInteger(e)||e<l||e>u)throw Error(`Invalid story ${r}`)};o(t.fps??12,1,60,"fps (1 to 60)"),o(t.holdMs??700,0,30000,"holdMs (0 to 30000)"),o(t.timeoutMs??120000,100,1800000,"timeoutMs (100 to 1800000)");for(let e of t.stories){if(!rt(e.id)||s.has(e.id)||!e.title?.trim())throw Error(`Invalid or duplicate story id/title: ${e.id}`);if(s.add(e.id),!["browser","ios","android"].includes(e.driver?.platform)||typeof e.driver.open!=="function")throw Error(`Invalid driver for story ${e.id}`);if(!Array.isArray(e.scenes)||!e.scenes.length)throw Error(`Story ${e.id} has no scenes`);let l=new Set;for(let u of e.scenes){if(!rt(u.id)||l.has(u.id)||!u.title?.trim()||typeof u.run!=="function")throw Error(`Invalid or duplicate scene in ${e.id}: ${u.id}`);l.add(u.id),o(u.holdMs??t.holdMs??700,0,30000,"scene holdMs"),o(u.timeoutMs??t.timeoutMs??120000,100,1800000,"scene timeoutMs")}}}function mt(t,s){let o=[_,`# ${E(t.title)}`,"",t.description?E(t.description):"","",`Platform: ${t.platform}. Result: **${t.status}**.`,""];if(t.video)o.push(`<video controls playsinline preload="metadata" src="${s}${t.video.path}" poster="${t.scenes.find((e)=>e.screenshot)?.screenshot?s+t.scenes.find((e)=>e.screenshot).screenshot.path:""}"></video>`,"",`[Download video](${s}${t.video.path})`,"");for(let e of t.scenes)if(o.push(`## ${E(e.title)}`,"",`Result: **${e.status}**.${e.startedMs===void 0?"":` Starts at ${(e.startedMs/1000).toFixed(1)}s.`}`,"",e.description?E(e.description):"",""),e.screenshot)o.push(`![${E(e.title)}](${s}${e.screenshot.path})`,"");else o.push("No screenshot was captured for this scene.","");return`${o.join(`
4
4
  `).trimEnd()}
5
5
  `}async function Mt(t={}){if(t.list&&t.check)throw Error("Choose --list or --check");let s=await pt(x(t.root??process.cwd())),o=x(s,t.config??"config/stories.ts"),e=await b(o),l=(await import(`${wt(o).href}?story=${N(e)}`)).default;await gt(l);let u=[tt,N(e),N(JSON.stringify(l,(i,f)=>typeof f==="function"?f.toString():f))];for(let i of[...l.inputs??[]].sort())u.push(`${i}:${N(await b(x(s,i)))}`);let r=x(s,t.outDir??l.outDir??"docs/stories"),a=l.publishDir===!1?void 0:x(s,l.publishDir??n(V(r),"public",ht(r)));if(a&&(a===r||!k(r,a).startsWith("..")||!k(a,r).startsWith("..")))throw Error("Published media must have a separate directory outside the story output");if(r===s||k(r,s)===""||!k(r,s).startsWith("..")&&!q(k(r,s)))throw Error("Story output must not contain the project root");let p={version:1,configHash:N(u.join(`
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/docs",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.667",
5
+ "version": "0.75.668",
6
6
  "description": "The Stacks way to document.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -58,19 +58,19 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@stacksjs/bunpress": "^0.2.33",
61
- "@stacksjs/cli": "0.75.667",
62
- "@stacksjs/config": "0.75.667",
63
- "@stacksjs/path": "0.75.667",
64
- "@stacksjs/orm": "0.75.667",
61
+ "@stacksjs/cli": "0.75.668",
62
+ "@stacksjs/config": "0.75.668",
63
+ "@stacksjs/path": "0.75.668",
64
+ "@stacksjs/orm": "0.75.668",
65
65
  "@stacksjs/stx": "^0.2.930",
66
- "@stacksjs/testing": "0.75.667",
66
+ "@stacksjs/testing": "0.75.668",
67
67
  "@ts-videos/mp4": "^0.1.2",
68
68
  "craft-native": ">=0.0.499",
69
69
  "ts-videos": "^0.1.2"
70
70
  },
71
71
  "devDependencies": {
72
- "@stacksjs/alias": "0.75.667",
73
- "@stacksjs/server": "0.75.667",
72
+ "@stacksjs/alias": "0.75.668",
73
+ "@stacksjs/server": "0.75.668",
74
74
  "better-dx": "^0.2.39"
75
75
  }
76
76
  }