@stacksjs/docs 0.75.693 → 0.75.694
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/screenshots.js +1 -1
- package/dist/stories.js +1 -1
- package/package.json +8 -8
package/dist/screenshots.js
CHANGED
|
@@ -109,7 +109,7 @@ ${n}::-webkit-search-cancel-button { visibility: hidden !important; }
|
|
|
109
109
|
return true
|
|
110
110
|
})()`,Ce=(e)=>e[0]===137&&e[1]===80?"image/png":"image/jpeg";async function ie(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(Ne(i));let n=[],t,c={width:0,height:0},f=0,p=async(u)=>{let h=JSON.parse(String(await e(`window.__stacksFilm.drain(${u})`)));if(c={width:h.width,height:h.height},h.description)t=new Uint8Array(Buffer.from(h.description,"base64"));for(let[o,s,d]of h.chunks)n.push([o,s,new Uint8Array(Buffer.from(d,"base64"))])};return{frames:()=>f,async add(u,h){if(!Number.isInteger(h)||h<1)return;let o=u?`${JSON.stringify(Buffer.from(u).toString("base64"))}, ${JSON.stringify(Ce(u))}`:"null, null";if(await e(`window.__stacksFilm.add(${o}, ${h})`),f+=h,f%(i.fps*20)<h)await p(!1)},async addVideo(u,h=[]){for(let s of h)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 d=Math.min(i.fps,o.frames-s);await e(`window.__stacksFilm.copy(${s}, ${d}, ${JSON.stringify(h)})`),f+=d,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 Te,h=new Re(u),o=h.addVideoTrack({codec:"h264",width:c.width,height:c.height,frameRate:i.fps,codecDescription:t});for(let[s,d,a]of n)await h.writePacket(o.id,{data:a,timestamp:d/1e6,duration:1/i.fps,isKeyframe:s===1});return await h.finalize(),u.buffer}}}import{createHash as Ae}from"crypto";import{lstat as Ue,mkdir as De,readFile as oe,rename as ne}from"fs/promises";import{dirname as Ve,isAbsolute as Le,join as H,relative as He,resolve as ae}from"path";var ce="<!-- Generated by buddy docs:screenshots. Edit config/screenshots.ts instead. -->",le=(e)=>Ae("sha256").update(e).digest("hex"),B=(e)=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',"""),R=(e)=>B(e).replace(/[\r\n]+/g," ").replace(/([\\`*_[\]#|])/g,"\\$1");function de(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=ae(n,i.page);if(Le(i.page)||He(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,h=Math.max(1,Math.round(p*u)),o=D(c),s=se();try{for(let d of n){if(t.viewports?.length&&!t.viewports.includes(d.name))continue;let a=i.filter((S)=>S.status==="captured"&&S.file&&S.viewport.name===d.name);if(!a.length)continue;let r,l;try{l=await o.view(320,240);let S=l;await S.navigate(s.url);let k=await ie((y)=>S.evaluate(y),{fps:u,width:d.width,height:d.height});for(let y of a)await k.add(new Uint8Array(await oe(H(e,y.file))),h);r=await k.finish()}catch(S){throw Error(`The ${d.name} screens could not be filmed: ${S instanceof Error?S.message.slice(0,400):"the browser failed"}`)}finally{l?.close()}let m=`film-${d.name}.mp4`;await Bun.write(H(e,`${m}.tmp`),r),await ne(H(e,`${m}.tmp`),H(e,m)),f.push({viewport:d.name,file:m,sha256:le(r),screens:a.length,seconds:a.length*h/u})}return f}finally{try{await o.close()}finally{s.stop()}}}function We(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.")}`,"---","",ce,"",`# ${R(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((d)=>d.viewport.name===o.viewport);f.push(`## Walkthrough video (${R(o.viewport)})`,"",`<video controls playsinline preload="none" src="${B(`${n}/${o.file}`)}"${s?` poster="${B(`${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 h=[];for(let[o,s]of[...u].sort(([d],[a])=>d.localeCompare(a))){let d=[];for(let a of s){let r=c.filter((l)=>l.id===a.id);if(!r.length){let l=e.results.find((m)=>m.id===a.id);h.push(`- ${R(a.title)} (\`${a.path}\`): ${a.skip?R(a.skip):l?"the last capture failed.":"not captured yet."}`);continue}d.push(`### ${R(a.title)}`,"",R(r[0].description),"",...r[0].reason?[R(r[0].reason),""]:[],`Address: \`${a.path}\``,"");for(let l of r)d.push("<figure>",` <img src="${B(`${n}/${l.file}`)}" alt="${B(`${l.title}, ${l.viewport.name}`)}" width="${l.viewport.width}" height="${l.viewport.height}" loading="lazy" style="display:block;width:100%;max-width:${l.viewport.width}px;height:auto">`,` <figcaption>${B(l.viewport.name)}, ${l.viewport.width} by ${l.viewport.height}${l.profile==="default"?"":`, signed in as ${B(l.profile)}`}</figcaption>`,"</figure>","")}if(d.length)f.push(`## ${R(o[0].toUpperCase()+o.slice(1).replace(/[-_]+/g," "))}`,"",...d)}if(h.length)f.push("## Not pictured","","These screens are part of the application and have no picture here.","",...h,"");return`${f.join(`
|
|
111
111
|
`).trimEnd()}
|
|
112
|
-
`}async function _(e,i,n){let t=ae(e,n.page);try{if((await Ue(t)).isSymbolicLink()||!(await oe(t,"utf8")).includes(ce))throw Error(`Refusing to replace a hand-written page: ${n.page}`)}catch(f){if(f.code!=="ENOENT")throw f}let c=We(i,n);return await De(Ve(t),{recursive:!0}),await Bun.write(`${t}.tmp`,c),await ne(`${t}.tmp`,t),{path:n.page,sha256:le(c)}}import{createRouter as Je}from"@stacksjs/stx";import{readFileSync as _e}from"fs";import{relative as Ie,resolve as qe}from"path";var fe=(e)=>e.replace(/[-_]+/g," ").replace(/\s+/g," ").trim(),ze=(e)=>e?e[0].toUpperCase()+e.slice(1):e;function Ke(e){try{return _e(e,"utf8")}catch{return""}}function Ge(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 ${fe(c.slice(1,-1).replace(/^\.\.\./,""))}`:fe(c));return t.length?ze(t.join(" / ")):"Home"}function pe(e={}){let i=qe(e.root??process.cwd()),n=[],t=new Set;for(let c of e.directories??["resources/views"])for(let f of Je(i,{pagesDir:c,emit:!1})){let p=f.pattern.replace(/\*(\w*)/g,(d,a)=>`[...${a||"path"}]`).replace(/:(\w+)/g,"[$1]"),u=p.split("/").filter(Boolean).map((d)=>d.replace(/[^a-z0-9]+/gi,"-").replace(/^-|-$/g,"")).filter(Boolean).join("-").toLowerCase()||"index",h=u;for(let d=2;t.has(h);d++)h=`${u}-${d}`;t.add(h);let o=Ke(f.filePath),s=o.match(/@(?:extends|layout)\(\s*['"]([^'"]+)['"]/)?.[1];n.push({id:h,route:p,source:Ie(i,f.filePath).replaceAll("\\","/"),group:p.split("/").filter(Boolean)[0]?.replace(/^\[.*\]$/,"profile")??"home",params:[...f.params],dynamic:f.isDynamic,title:Ge(o,p),...s?{layout:s}:{},text:o})}return n.sort((c,f)=>c.route<f.route?-1:c.route>f.route?1:0)}function Qe(e={}){let i=[],n=new Set;for(let t of pe(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 st}from"@stacksjs/cli/owned-process";import{ChromeLaunchError as it}from"@stacksjs/testing/browser";var C="0.75.
|
|
112
|
+
`}async function _(e,i,n){let t=ae(e,n.page);try{if((await Ue(t)).isSymbolicLink()||!(await oe(t,"utf8")).includes(ce))throw Error(`Refusing to replace a hand-written page: ${n.page}`)}catch(f){if(f.code!=="ENOENT")throw f}let c=We(i,n);return await De(Ve(t),{recursive:!0}),await Bun.write(`${t}.tmp`,c),await ne(`${t}.tmp`,t),{path:n.page,sha256:le(c)}}import{createRouter as Je}from"@stacksjs/stx";import{readFileSync as _e}from"fs";import{relative as Ie,resolve as qe}from"path";var fe=(e)=>e.replace(/[-_]+/g," ").replace(/\s+/g," ").trim(),ze=(e)=>e?e[0].toUpperCase()+e.slice(1):e;function Ke(e){try{return _e(e,"utf8")}catch{return""}}function Ge(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 ${fe(c.slice(1,-1).replace(/^\.\.\./,""))}`:fe(c));return t.length?ze(t.join(" / ")):"Home"}function pe(e={}){let i=qe(e.root??process.cwd()),n=[],t=new Set;for(let c of e.directories??["resources/views"])for(let f of Je(i,{pagesDir:c,emit:!1})){let p=f.pattern.replace(/\*(\w*)/g,(d,a)=>`[...${a||"path"}]`).replace(/:(\w+)/g,"[$1]"),u=p.split("/").filter(Boolean).map((d)=>d.replace(/[^a-z0-9]+/gi,"-").replace(/^-|-$/g,"")).filter(Boolean).join("-").toLowerCase()||"index",h=u;for(let d=2;t.has(h);d++)h=`${u}-${d}`;t.add(h);let o=Ke(f.filePath),s=o.match(/@(?:extends|layout)\(\s*['"]([^'"]+)['"]/)?.[1];n.push({id:h,route:p,source:Ie(i,f.filePath).replaceAll("\\","/"),group:p.split("/").filter(Boolean)[0]?.replace(/^\[.*\]$/,"profile")??"home",params:[...f.params],dynamic:f.isDynamic,title:Ge(o,p),...s?{layout:s}:{},text:o})}return n.sort((c,f)=>c.route<f.route?-1:c.route>f.route?1:0)}function Qe(e={}){let i=[],n=new Set;for(let t of pe(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 st}from"@stacksjs/cli/owned-process";import{ChromeLaunchError as it}from"@stacksjs/testing/browser";var C="0.75.694";var Jt=(e)=>e,he="Screenshot deadline exceeded",j=[{name:"desktop",width:1440,height:900},{name:"mobile",width:390,height:844}],U=(e)=>Ye("sha256").update(e).digest("hex"),q=(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),me=(e)=>{let i=new URL(e);return i.origin+i.pathname};async function ye(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.retries!==void 0&&(!Number.isInteger(e.retries)||e.retries<0||e.retries>3))throw Error("retries must be a whole number from 0 to 3");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)=>!q(o)))throw Error("Profile names must be safe filenames");let c=new Set,f=new Set;for(let o of e.pages){if(!q(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((d)=>!t.includes(d))||o.profiles?.length===0)throw Error(`Unknown or empty profiles for ${o.id}`);for(let d of o.sources??[]){let a=x(i,d);if(T(i,a).startsWith("..")||ge(d))throw Error(`Source must be inside the project: ${d}`);await P(a),f.add(T(i,a).replaceAll("\\","/"))}}let p=new Set;for(let o of e.viewports??j){if(!q(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 P(x(i,o));de(e.film===!0?{}:e.film,e.docs,i,e.viewports??j);let u=[],h=new Set;for(let o of e.coverage?.directories??[]){let s=x(i,o);if(T(i,s).startsWith(".."))throw Error("Coverage directories must be inside the project");if(!(await et(s)).isDirectory())throw Error(`Missing coverage directory: ${o}`);let d=0;for await(let a of new Bun.Glob("**/*.stx").scan({cwd:s,onlyFiles:!0})){d++;let r=T(i,g(s,a)).replaceAll("\\","/");if(h.add(r),!f.has(r)&&!e.coverage?.exclude?.[r]?.trim())u.push(r)}if(!d)throw Error(`No .stx screens found in ${o}`)}for(let[o,s]of Object.entries(e.coverage?.exclude??{}))if(!s.trim()||!h.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(rt(e).href)).default;if(!i||typeof i!=="object")throw Error("Screenshot configuration must have a default export");return i}async function ot(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 be(e,i){let n=e instanceof Error?e.message:"Screenshot capture failed";if(e instanceof it&&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 nt,randomUUID as lt}from"crypto";import{createReadStream as ut}from"fs";import{copyFile as pt,lstat as Y,mkdir as _,open as ht,readFile as P,realpath as at,rename as Z,rm as st,writeFile as F}from"fs/promises";import{basename as ct,dirname as Q,isAbsolute as et,join as u,relative as T,resolve as A,sep as dt}from"path";import{pathToFileURL as wt}from"url";var rt="0.75.
|
|
2
|
+
import{createHash as nt,randomUUID as lt}from"crypto";import{createReadStream as ut}from"fs";import{copyFile as pt,lstat as Y,mkdir as _,open as ht,readFile as P,realpath as at,rename as Z,rm as st,writeFile as F}from"fs/promises";import{basename as ct,dirname as Q,isAbsolute as et,join as u,relative as T,resolve as A,sep as dt}from"path";import{pathToFileURL as wt}from"url";var rt="0.75.694";function $t(t){return t}function Mt(t){return t}var B=`stacks-story-recordings-v1
|
|
3
3
|
`,tt="<!-- Generated by buddy docs:stories. -->",L=(t)=>nt("sha256").update(t).digest("hex"),it=(t)=>typeof t==="string"&&/^[a-z0-9][a-z0-9-]{0,79}$/.test(t);function N(t){return t.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replace(/[\r\n]/g," ").replace(/([\\`*_[\]#|])/g,"\\$1")}async function H(t){try{return await Y(t),!0}catch(s){if(s.code==="ENOENT")return!1;throw s}}async function x(t,s=t){let n=A(t);while(!0){if(await H(n)){if((await Y(n)).isSymbolicLink())throw Error(`Story output cannot traverse a symbolic link: ${n}`)}if(n===A(s))return;let e=Q(n);if(e===n)return;n=e}}async function q(t,s){await x(s,t);let n=await Y(s);if(!n.isFile()||n.size===0)throw Error(`Missing or empty story artifact: ${s}`);let e=nt("sha256"),f=0;for await(let m of ut(s))e.update(m),f+=m.length;return{path:T(t,s).split(dt).join("/"),sha256:e.digest("hex"),bytes:f}}function K(t,s){let n=A(t,s.path);if(!s.path||et(s.path)||T(t,n).startsWith(".."))throw Error("Story artifact escaped its output directory");return n}async function jt(t,s,n=process.cwd()){if(!t.length||!s.endsWith(".mp4"))throw Error("Expected story manifests and an MP4 destination");let e=await Promise.all(t.map(async(o)=>{let b=JSON.parse(await P(o,"utf8")),a=await at(b.mediaDir?A(n,b.mediaDir):Q(A(o)));return{report:b,root:a}})),{configHash:f,inventory:m}=e[0].report;if(!m.length||e.some(({report:o})=>o.version!==1||o.configHash!==f))throw Error("The recordings must share one Stacks story configuration");let{Mp4Demuxer:i,Mp4Muxer:d}=await import("@ts-videos/mp4"),{BufferSource:y,BufferTarget:W,parseMp4Chapters:X}=await import("ts-videos"),G=new W,D=new d(G),h=[],v,r=0;for(let o of m){let b=e.flatMap(({report:l,root:S})=>l.results.filter((U)=>U.id===o.id&&U.status==="passed").map((U)=>({root:S,result:U}))).at(-1),a=b?.result.video;if(!a||b.result.scenes.length!==o.scenes.length||o.scenes.some((l)=>!b.result.scenes.some((S)=>S.id===l.id&&S.status==="passed"&&S.screenshot)))throw Error(`Story ${o.id} has missing or failed recording evidence`);let w=K(b.root,a);if(await x(w,b.root),ct(w)!=="video.mp4"||!(await Y(w)).isFile())throw Error(`Unexpected video path for ${o.id}`);let g=await P(w);if(g.length!==a.bytes||L(g)!==a.sha256)throw Error(`The recording for ${o.id} no longer matches its manifest`);let M=new i(new y(g)),R=await M.getTracks(),C=R.find((l)=>l.type==="video");if(C?.codec!=="h264"||!C.codecDescription?.length||R.some((l)=>l.type==="audio"))throw Error(`Story ${o.id} needs a silent H.264 recording`);let{width:J,height:j,codecDescription:I,frameRate:O}=C;if(!v)v={id:D.addVideoTrack({codec:"h264",width:J,height:j,frameRate:O,codecDescription:I}).id,width:J,height:j,description:I};if(J!==v.width||j!==v.height||!Buffer.from(I).equals(v.description))throw Error(`Story ${o.id} has a different viewport or H.264 configuration`);let z=Math.round(r*1000);D.addChapter(o.title,z);let V,k=0;for await(let l of M.packets(C.id)){if(V===void 0&&!l.isKeyframe)throw Error(`Story ${o.id} has no opening keyframe`);V??=l.timestamp;let S=l.timestamp-V;if(!Number.isFinite(S)||S<0||!l.duration||!Number.isFinite(l.duration)||l.duration<=0)throw Error(`Story ${o.id} has invalid video timing`);await D.writePacket(v.id,{...l,timestamp:r+S}),k=Math.max(k,S+l.duration)}if(!k)throw Error(`Story ${o.id} has no video frames`);r+=k,h.push({title:o.title,start:z,end:Math.round(r*1000)})}await D.finalize();let p=G.buffer,E=X(p).chapters;if(E.length!==h.length||E.some((o,b)=>o.startTime!==h[b]?.start||o.title!==h[b]?.title))throw Error("The MP4 chapters did not match the story inventory");let c=A(s);return await F(c,p,{flag:"wx"}),{output:c,seconds:r,chapters:h}}function ot(t,s){let n=T(t,s);return n&&!n.startsWith("..")&&!et(n)?n.split(dt).join("/"):s}async function mt(t){if(!t||!Array.isArray(t.stories)||!t.stories.length)throw Error("Story configuration needs at least one story");let s=new Set,n=(e,f,m,i)=>{if(!Number.isInteger(e)||e<f||e>m)throw Error(`Invalid story ${i}`)};n(t.fps??12,1,60,"fps (1 to 60)"),n(t.holdMs??700,0,30000,"holdMs (0 to 30000)"),n(t.timeoutMs??120000,100,1800000,"timeoutMs (100 to 1800000)");for(let e of t.stories){if(!it(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 f=new Set;for(let m of e.scenes){if(!it(m.id)||f.has(m.id)||!m.title?.trim()||typeof m.run!=="function")throw Error(`Invalid or duplicate scene in ${e.id}: ${m.id}`);f.add(m.id),n(m.holdMs??t.holdMs??700,0,30000,"scene holdMs"),n(m.timeoutMs??t.timeoutMs??120000,100,1800000,"scene timeoutMs")}}}function gt(t,s){let n=[tt,`# ${N(t.title)}`,"",t.description?N(t.description):"","",`Platform: ${t.platform}. Result: **${t.status}**.`,""];if(t.video)n.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(n.push(`## ${N(e.title)}`,"",`Result: **${e.status}**.${e.startedMs===void 0?"":` Starts at ${(e.startedMs/1000).toFixed(1)}s.`}`,"",e.description?N(e.description):"",""),e.screenshot)n.push(``,"");else n.push("No screenshot was captured for this scene.","");return`${n.join(`
|
|
4
4
|
`).trimEnd()}
|
|
5
5
|
`}async function Pt(t={}){if(t.list&&t.check)throw Error("Choose --list or --check");let s=await at(A(t.root??process.cwd())),n=A(s,t.config??"config/stories.ts"),e=await P(n),f=(await import(`${wt(n).href}?story=${L(e)}`)).default;await mt(f);let m=[rt,L(e),L(JSON.stringify(f,(r,p)=>typeof p==="function"?p.toString():p))];for(let r of[...f.inputs??[]].sort())m.push(`${r}:${L(await P(A(s,r)))}`);let i=A(s,t.outDir??f.outDir??"docs/stories"),d=f.publishDir===!1?void 0:A(s,f.publishDir??u(Q(i),"public",ct(i)));if(d&&(d===i||!T(i,d).startsWith("..")||!T(d,i).startsWith("..")))throw Error("Published media must have a separate directory outside the story output");if(i===s||T(i,s)===""||!T(i,s).startsWith("..")&&!et(T(i,s)))throw Error("Story output must not contain the project root");let y={version:1,configHash:L(m.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.
|
|
5
|
+
"version": "0.75.694",
|
|
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.34",
|
|
61
|
-
"@stacksjs/cli": "0.75.
|
|
62
|
-
"@stacksjs/config": "0.75.
|
|
63
|
-
"@stacksjs/path": "0.75.
|
|
64
|
-
"@stacksjs/orm": "0.75.
|
|
61
|
+
"@stacksjs/cli": "0.75.694",
|
|
62
|
+
"@stacksjs/config": "0.75.694",
|
|
63
|
+
"@stacksjs/path": "0.75.694",
|
|
64
|
+
"@stacksjs/orm": "0.75.694",
|
|
65
65
|
"@stacksjs/stx": "^0.2.938",
|
|
66
|
-
"@stacksjs/testing": "0.75.
|
|
66
|
+
"@stacksjs/testing": "0.75.694",
|
|
67
67
|
"@ts-videos/mp4": "^0.3.1",
|
|
68
68
|
"craft-native": ">=0.0.499",
|
|
69
69
|
"ts-videos": "^0.3.1"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@stacksjs/alias": "0.75.
|
|
73
|
-
"@stacksjs/server": "0.75.
|
|
72
|
+
"@stacksjs/alias": "0.75.694",
|
|
73
|
+
"@stacksjs/server": "0.75.694",
|
|
74
74
|
"better-dx": "^0.2.39"
|
|
75
75
|
}
|
|
76
76
|
}
|