canofold 0.2.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/LICENSE +21 -0
- package/README.md +33 -0
- package/README.zh-CN.md +33 -0
- package/dist/build-RBMQ6TZ7.js +2 -0
- package/dist/check-FCYLN6KO.js +3 -0
- package/dist/chunk-3TIVCYR7.js +2 -0
- package/dist/chunk-4E7M3CIK.js +6 -0
- package/dist/chunk-4OALGQQB.js +2 -0
- package/dist/chunk-56TT2V3X.js +664 -0
- package/dist/chunk-AYDF3IFZ.js +2 -0
- package/dist/chunk-EAYVCA3Z.js +2 -0
- package/dist/chunk-ENPRUF6E.js +2 -0
- package/dist/chunk-JK7ZNBUA.js +2 -0
- package/dist/chunk-JZIKHPBO.js +45 -0
- package/dist/chunk-M6T5RSNJ.js +2 -0
- package/dist/chunk-OATSOVSV.js +3 -0
- package/dist/chunk-XYJ2OBL3.js +2 -0
- package/dist/clean-74GN2NZC.js +2 -0
- package/dist/cli.js +17 -0
- package/dist/deploy-4YUYRVRO.js +144 -0
- package/dist/dev-WJCFAWYD.js +2 -0
- package/dist/index.js +2 -0
- package/dist/init-6R5SLESH.js +71 -0
- package/dist/load-W4JHZIBF.js +2 -0
- package/dist/playground-client.js +2 -0
- package/dist/preview-ODXGCQZ7.js +2 -0
- package/dist/search-client.js +2 -0
- package/dist/styles.input.css +1739 -0
- package/package.json +73 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as n}from"./chunk-AYDF3IFZ.js";var r=/\.(?:md|mdx)$/i;function e(t){return r.test(t)}n(e,"isMarkdownPath");function i(t){return/\.mdx$/i.test(t)}n(i,"isMdxPath");function o(t){return/^index\.(?:md|mdx)$/i.test(t)}n(o,"isMarkdownIndexName");function s(t){return t.replace(r,"")}n(s,"stripMarkdownExtension");export{e as a,i as b,o as c,s as d};
|
|
2
|
+
//# sourceMappingURL=chunk-EAYVCA3Z.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as y}from"./chunk-XYJ2OBL3.js";import{e as x,h as g}from"./chunk-JK7ZNBUA.js";import{a as o}from"./chunk-AYDF3IFZ.js";function v(t){return t?.replace(/\/+$/,"")}o(v,"normalizeSiteUrl");function k(t,e){let r=v(t.siteUrl);if(r)return`${r}${p(t,e)}`}o(k,"siteUrlFor");function p(t,e){if(/^(?:[a-z][a-z\d+.-]*:|\/\/|#)/i.test(e))return e;let r=e.startsWith("/")?e:`/${e}`;return t.basePath==="/"?r:`${t.basePath.replace(/\/$/,"")}${r}`}o(p,"publicPathFor");function u(t,e){if(t===null||typeof t=="string"||typeof t=="boolean")return!0;if(typeof t=="number")return Number.isFinite(t);if(typeof t!="object"||e.has(t))return!1;let r=Object.getPrototypeOf(t);if(!Array.isArray(t)&&r!==Object.prototype&&r!==null)return!1;e.add(t);try{return Array.isArray(t)?Object.keys(t).length===t.length&&t.every(i=>u(i,e)):Object.values(t).every(i=>u(i,e))}finally{e.delete(t)}}o(u,"validateJsonValue");function C(t,e){if(!u(t,new WeakSet))throw new Error(`${e} must be JSON-serializable`)}o(C,"assertJsonValue");import{mkdir as P,rm as E,writeFile as O}from"fs/promises";import{join as d}from"path";var F=320;function $(t,e,r){let{graph:i,publicPathFor:a}=t,s=new Map,f=i.pages.filter(n=>n.version===e&&n.locale===r&&n.search).map((n,l)=>{let m=Array.isArray(n.frontmatter.tags)?n.frontmatter.tags.filter(c=>typeof c=="string"):[],S=n.codeExamples.map(c=>c.code.slice(0,300)).join(" ").slice(0,2e3),w=`${n.title} ${n.description} ${m.join(" ")} ${n.searchText} ${S}`;for(let c of y(w)){let h=s.get(c);h?h.push(l):s.set(c,[l])}return{title:n.title,description:n.description,routePath:a(n.routePath),excerpt:n.searchText.slice(0,F),tags:m}});return{version:e,locale:r,docs:f,postings:Object.fromEntries([...s.entries()].sort(([n],[l])=>n.localeCompare(l)))}}o($,"createSearchIndex");var b={id:"compact",client:"compact",async write(t){let{graph:e,outputRoot:r}=t,i=d(r,"search");await E(i,{recursive:!0,force:!0}),await P(i,{recursive:!0});for(let a of e.versions)for(let s of e.locales){let f=a.id===e.currentVersion?i:d(i,a.id);await P(f,{recursive:!0}),await O(d(f,`${s}.json`),JSON.stringify($(t,a.id,s),null,2))}await E(d(r,"pagefind"),{recursive:!0,force:!0})}};var N=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;function W(t){if(!N.test(t.id))throw new Error("Search provider id must be a lowercase kebab-case name");if(t.client!=="compact"&&t.client!=="pagefind")throw new Error(`Search provider "${t.id}" client must be "compact" or "pagefind"`);if(t.cacheKey!==void 0&&C(t.cacheKey,`Search provider "${t.id}" cacheKey`),typeof t.write!="function")throw new Error(`Search provider "${t.id}" must define write(context)`);return Object.freeze(t)}o(W,"defineSearchProvider");function X(t){return typeof t=="string"?"compact":t.client}o(X,"searchProviderClient");function j(t){if(typeof t!="string")return t;if(t==="compact")return b;throw new Error("The Pagefind search provider moved to @canofold/plugins. Import pagefind() and set search.provider to pagefind().")}o(j,"searchProviderFor");async function H(t,e,r){if(!e.search.enabled)return;let i=x(t,e.outputDir);await j(e.search.provider).write({cwd:t,config:e,graph:r,outputRoot:i,publicPathFor:o(a=>p(e,a),"publicPathFor"),resolveOutputPath:o((a,s)=>g(i,a,s),"resolveOutputPath")})}o(H,"writeSearchIndexes");var B=1;function Q(t){return t}o(Q,"defineExtension");export{k as a,p as b,W as c,X as d,H as e,B as f,Q as g};
|
|
2
|
+
//# sourceMappingURL=chunk-ENPRUF6E.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as s}from"./chunk-AYDF3IFZ.js";import{access as g,realpath as f}from"fs/promises";import{basename as w,dirname as m,isAbsolute as h,relative as p,resolve as a,sep as l}from"path";async function d(o,r=g){try{return await r(o),!0}catch(t){if(t.code==="ENOENT")return!1;throw t}}s(d,"pathExists");function x(o){return o.normalize("NFC").toLocaleLowerCase("en-US")}s(x,"portablePathKey");function c(o,r){let t=p(a(o),a(r));return t===""||t!==".."&&!t.startsWith(`..${l}`)&&!h(t)}s(c,"isInside");function E(o,r,t){let e=a(o),n=a(e,r),i=p(e,n);if(i===".."||i.startsWith(`..${l}`)||h(i))throw new Error(`${t} must resolve to a path inside the project root`);return n}s(E,"resolveProjectPath");function y(o,r){let t=a(o),e=E(t,r,"outputDir");if(!p(t,e))throw new Error("outputDir must resolve to a directory inside the project root");return e}s(y,"resolveOutputRoot");async function u(o){let r=a(o),t=[];for(;;)try{return a(await f(r),...t)}catch(e){let n=e.code;if(n!=="ENOENT"&&n!=="ENOTDIR")throw e;let i=m(r);if(i===r)throw e;t.unshift(w(r)),r=i}}s(u,"canonicalPath");async function j(o,r,t){let[e,n]=await Promise.all([u(o),u(r)]);if(!c(e,n))throw new Error(`${t} must resolve to a path inside the project root`)}s(j,"assertProjectPath");async function N(o,r,t,e="outputDir"){let[n,i]=await Promise.all([u(o),u(r)]);if(c(n,i)||c(i,n))throw new Error(`${t} must not overlap ${e}`)}s(N,"assertDisjointPaths");function O(o,r,t){let e=a(o,r);if(!c(o,e))throw new Error(`${t} must stay inside outputDir`);return e}s(O,"resolveOutputPath");export{d as a,x as b,c,E as d,y as e,j as f,N as g,O as h};
|
|
2
|
+
//# sourceMappingURL=chunk-JK7ZNBUA.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import{b as N}from"./chunk-M6T5RSNJ.js";import{c as j}from"./chunk-JK7ZNBUA.js";import{a as i}from"./chunk-AYDF3IFZ.js";import{createServer as I}from"http";import{readFile as H,realpath as k}from"fs/promises";import{extname as P,isAbsolute as $,join as v,normalize as O,relative as B,resolve as S,sep as L}from"path";var T={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".js":"text/javascript; charset=utf-8",".mjs":"text/javascript; charset=utf-8",".json":"application/json; charset=utf-8",".txt":"text/plain; charset=utf-8",".md":"text/markdown; charset=utf-8",".svg":"image/svg+xml",".xml":"application/xml; charset=utf-8",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".pagefind":"application/wasm"};function z(e){return T[P(e).toLowerCase()]??"application/octet-stream"}i(z,"contentTypeFor");var J=15e3;function U(e){for(let o of e)o.end();e.clear()}i(U,"closeReloadClients");function w(e,o){for(let n of e)try{n.write(o)}catch{e.delete(n);try{n.end()}catch{}}}i(w,"writeReloadClients");function M(e){w(e,`:keepalive
|
|
2
|
+
|
|
3
|
+
`)}i(M,"heartbeatReloadClients");function R(e,o=""){let n=o.replace(/\r\n?/g,`
|
|
4
|
+
`).split(`
|
|
5
|
+
`);return`event: ${e}
|
|
6
|
+
${n.map(d=>`data: ${d}`).join(`
|
|
7
|
+
`)}
|
|
8
|
+
|
|
9
|
+
`}i(R,"formatServerSentEvent");function A(e,o="/__canofold/events"){let n=`<script type="module">
|
|
10
|
+
const source=new EventSource(${JSON.stringify(o)});
|
|
11
|
+
let connected=false,disconnected=false;
|
|
12
|
+
let overlay=null;
|
|
13
|
+
function showError(msg){
|
|
14
|
+
if(!overlay){overlay=document.createElement('dialog');overlay.style.cssText='all:initial;position:fixed;inset:0;width:100%;height:100%;border:none;background:rgba(15,15,20,.92);color:#f87171;font:14px/1.6 monospace;padding:2rem;box-sizing:border-box;z-index:2147483647;overflow:auto;white-space:pre-wrap;word-break:break-all;';document.documentElement.appendChild(overlay);}
|
|
15
|
+
overlay.textContent='\u26A0\uFE0F Build error:\\n\\n'+msg;
|
|
16
|
+
if(!overlay.open)overlay.showModal();
|
|
17
|
+
}
|
|
18
|
+
function clearError(){if(overlay&&overlay.open){overlay.close();overlay.remove();overlay=null;}}
|
|
19
|
+
function normalizeRoute(value){const path=value.split(/[?#]/,1)[0]||'/';return path.endsWith('/')?path:path+'/';}
|
|
20
|
+
async function applyPageUpdate(update){
|
|
21
|
+
const currentRoute=normalizeRoute(location.pathname);
|
|
22
|
+
if(!update.routes.some((route)=>normalizeRoute(route)===currentRoute))return true;
|
|
23
|
+
const response=await fetch(location.href,{cache:'no-store',headers:{accept:'text/html'}});
|
|
24
|
+
if(!response.ok||!(response.headers.get('content-type')||'').includes('text/html'))return false;
|
|
25
|
+
const nextDocument=new DOMParser().parseFromString(await response.text(),'text/html');
|
|
26
|
+
if(typeof window.__canofoldApplyPageDocument!=='function')return false;
|
|
27
|
+
return window.__canofoldApplyPageDocument(nextDocument,{mode:'update'});
|
|
28
|
+
}
|
|
29
|
+
source.onopen=()=>{if(connected&&disconnected){clearError();location.reload();}connected=true;disconnected=false;};
|
|
30
|
+
source.onerror=()=>{if(connected)disconnected=true;};
|
|
31
|
+
source.onmessage=()=>{clearError();location.reload();};
|
|
32
|
+
source.addEventListener('update',async(event)=>{
|
|
33
|
+
clearError();
|
|
34
|
+
try{
|
|
35
|
+
const update=JSON.parse(event.data);
|
|
36
|
+
if(update.protocol!==1||update.type!=='update'||update.mode!=='page'){location.reload();return;}
|
|
37
|
+
if(!await applyPageUpdate(update))location.reload();
|
|
38
|
+
}catch{location.reload();}
|
|
39
|
+
});
|
|
40
|
+
source.addEventListener('build-error',(e)=>showError(e.data));
|
|
41
|
+
source.addEventListener('build-ok',()=>clearError());
|
|
42
|
+
</script>`;return e.replace("</body>",`${n}</body>`)}i(A,"injectLiveReloadScript");function W(e,o="/"){if(o==="/")return e;let n=o.replace(/\/$/,"");return e===n?"/":e.startsWith(`${n}/`)?e.slice(n.length)||"/":void 0}i(W,"resolveMountedRequestPath");function G(e,o){let n=S(e),d=o.split("/").map(f=>{let t=decodeURIComponent(f);if(t==="."||t===".."||t.includes("/")||t.includes("\\")||/[\u0000-\u001f]/.test(t))throw new Error("Forbidden");return t}),c=O(d.join("/"));if(c.split(/[\\/]/).includes(".."))throw new Error("Forbidden");let s=S(v(n,c)),p=c.endsWith("/")?[v(s,"index.html")]:P(c)===""?[s,v(s,"index.html")]:[s];for(let f of p){let t=B(n,f);if(t===".."||t.startsWith(`..${L}`)||$(t))throw new Error("Forbidden")}return p}i(G,"resolveRequestCandidates");async function _(e,o){let[n,d]=await Promise.all([k(e),k(o)]);if(!j(n,d))throw new Error("Forbidden");return d}i(_,"resolveExistingRequestPath");async function K(e){try{let o=await _(e,v(e,"404.html"));return await H(o)}catch(o){if(o.code==="ENOENT")return;throw o}}i(K,"readGeneratedNotFound");async function ee({root:e,port:o,liveReload:n=!1,basePath:d="/"}){let c=new Set,s=I(async(t,r)=>{if(t.method!=="GET"&&t.method!=="HEAD"){r.writeHead(405,{allow:"GET, HEAD"}),r.end("Method not allowed");return}let l=new URL(t.url??"/","http://127.0.0.1"),h=typeof d=="function"?d():d,y=`${h==="/"?"":h.replace(/\/$/,"")}/__canofold/events`;if(n&&l.pathname===y){r.writeHead(200,{"content-type":"text/event-stream","cache-control":"no-cache",connection:"keep-alive"}),r.write(`:connected
|
|
43
|
+
|
|
44
|
+
`),c.add(r);let a=i(()=>c.delete(r),"removeClient");t.once("close",a),r.once("close",a),r.once("error",a);return}let C=W(l.pathname,h),g,E=i(async()=>{r.statusCode=404;let a=await K(g);if(a){r.setHeader("content-type",T[".html"]??"text/html; charset=utf-8"),n&&(a=Buffer.from(A(a.toString("utf8"),y))),r.end(t.method==="HEAD"?void 0:a);return}r.end(t.method==="HEAD"?void 0:"Not found")},"sendNotFound"),x=i(a=>{N("Static server error:",a),r.statusCode=500,r.end(t.method==="HEAD"?void 0:"Internal server error")},"sendInternalError");if(g=S(typeof e=="function"?e():e),C===void 0){try{await E()}catch(a){x(a)}return}let D;try{D=G(g,C)}catch{r.statusCode=403,r.end("Forbidden");return}try{let a,u;for(let b of D)try{let m=await _(g,b);u=await H(m),a=m;break}catch(m){if(m.message==="Forbidden"){r.statusCode=403,r.end("Forbidden");return}let F=m.code;if(F!=="ENOENT"&&F!=="EISDIR")throw m}if(!a||!u){await E();return}r.setHeader("content-type",z(a)),r.setHeader("cache-control","no-store"),n&&P(a)===".html"&&(u=Buffer.from(A(u.toString("utf8"),y))),r.end(t.method==="HEAD"?void 0:u)}catch(a){let u=a.code;if(u==="ENOENT"||u==="EISDIR")try{await E()}catch(b){x(b)}else x(a)}});await new Promise((t,r)=>{let l=i(h=>r(h),"onError");s.once("error",l),s.listen(o,"127.0.0.1",()=>{s.off("error",l),t()})});let p=s.address();if(!p||typeof p=="string")throw new Error("Failed to start server");let f=n?setInterval(()=>M(c),J):void 0;return f?.unref(),{port:p.port,reload:i((t={protocol:1,type:"update",mode:"full",routes:[]})=>{w(c,R("update",JSON.stringify(t)))},"reload"),sendBuildError:i(t=>{w(c,R("build-error",t))},"sendBuildError"),sendBuildOk:i(()=>{w(c,R("build-ok"))},"sendBuildOk"),close:i(()=>(f&&clearInterval(f),U(c),new Promise((t,r)=>s.close(l=>l?r(l):t()))),"close")}}i(ee,"startStaticServer");export{ee as a};
|
|
45
|
+
//# sourceMappingURL=chunk-JZIKHPBO.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{a as h}from"./chunk-3TIVCYR7.js";import{d as a,e as E,f as d,g as u}from"./chunk-JK7ZNBUA.js";import{a as i}from"./chunk-AYDF3IFZ.js";import{randomUUID as b}from"crypto";import{mkdir as B,open as x,readFile as p,rename as S,rm as f,stat as k,writeFile as M}from"fs/promises";import{hostname as O}from"os";import{dirname as v,join as y}from"path";var w=600*1e3,A=Math.floor(w/3);function l(t){return typeof t=="string"&&t.length>0&&!t.startsWith("/")&&!t.includes("\\")&&t.split("/").every(e=>e!==""&&e!=="."&&e!=="..")}i(l,"isSafeOutputPath");function Q(t){return a(t,".canofold/cache","build cache")}i(Q,"resolveBuildCacheRoot");function Y(t){return a(t,".canofold/tmp","temporary build files")}i(Y,"resolveBuildTemporaryRoot");function P(t){return y(t,"build-manifest.json")}i(P,"manifestPath");function R(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.fingerprint=="string"&&l(e.outputPath)&&l(e.markdownOutputPath)&&Array.isArray(e.assetOutputPaths)&&e.assetOutputPaths.every(l)}i(R,"isPageState");function j(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.fingerprint=="string"&&Number.isSafeInteger(e.size)&&Number(e.size)>=0}i(j,"isOutputState");function C(t){if(!t||typeof t!="object")return!1;let e=t;return e.schemaVersion===3&&e.canofoldVersion===h&&typeof e.buildFingerprint=="string"&&typeof e.sharedFingerprint=="string"&&!!e.pages&&typeof e.pages=="object"&&Object.values(e.pages).every(R)&&!!e.outputs&&typeof e.outputs=="object"&&Object.keys(e.outputs).length>0&&Object.keys(e.outputs).every(l)&&Object.values(e.outputs).every(j)}i(C,"isBuildManifest");async function Z(t){try{let e=JSON.parse(await p(P(t),"utf8"));return C(e)?e:void 0}catch(e){if(e.code==="ENOENT"||e instanceof SyntaxError)return;throw e}}i(Z,"readBuildManifest");async function tt(t,e){await B(t,{recursive:!0});let n=P(t),o=y(t,`.build-manifest.${b()}.tmp`);try{await M(o,`${JSON.stringify(e,null,2)}
|
|
2
|
+
`,{flag:"wx",flush:!0});try{await S(o,n)}catch(r){let s=r.code;if(s!=="EEXIST"&&s!=="EPERM")throw r;await f(n,{force:!0}),await S(o,n)}}finally{await f(o,{force:!0})}}i(tt,"writeBuildManifest");function T(t){try{return process.kill(t,0),!0}catch(e){return e.code!=="ESRCH"}}i(T,"processIsAlive");function D(t,e,n=Date.now()){if(t.hostname===O()&&typeof t.pid=="number"&&Number.isSafeInteger(t.pid)&&t.pid>0&&!T(t.pid))return!0;let o=typeof t.updatedAt=="number"?t.updatedAt:typeof t.createdAt=="number"?t.createdAt:void 0,r=o===void 0?e:Math.max(o,e);return r===void 0||!Number.isFinite(r)||r>n+w||n-r>w}i(D,"lockIsStale");function F(t,e){return JSON.stringify({ownerId:t,pid:process.pid,hostname:O(),createdAt:e})}i(F,"lockContents");async function g(t){try{return JSON.parse(await p(t,"utf8"))}catch(e){if(e.code==="ENOENT")return;throw e}}i(g,"readBuildLock");async function m(t){let e=await x(t,"wx"),n=b(),o=Date.now();try{return await e.writeFile(F(n,o)),{handle:e,path:t,ownerId:n,createdAt:o}}catch(r){throw await e.close(),await f(t,{force:!0}),r}}i(m,"createBuildLock");async function N(t){(await g(t.path))?.ownerId===t.ownerId&&await f(t.path,{force:!0})}i(N,"releaseBuildLock");async function I(t){let e,n;try{let[r,s]=await Promise.all([p(t,"utf8"),k(t)]);e=r,n=s.mtimeMs}catch(r){if(r.code==="ENOENT")return!0;throw r}let o;try{o=D(JSON.parse(e),n)}catch{o=Date.now()-n>w}if(!o)return!1;try{let[r,s]=await Promise.all([p(t,"utf8"),k(t)]);return r!==e||s.mtimeMs!==n?!1:(await f(t),!0)}catch(r){if(r.code==="ENOENT")return!0;throw r}}i(I,"removeStaleLock");async function J(t){try{return await m(t)}catch(e){if(e.code!=="EEXIST")throw e;if(!await I(t))throw new Error("Another Canofold build is already running for this project");try{return await m(t)}catch(n){throw n.code==="EEXIST"?new Error("Another Canofold build is already running for this project"):n}}}i(J,"acquireBuildLock");async function _(t){let e=v(t);await B(e,{recursive:!0});let n=y(e,"build.lock"),o=await J(`${n}.reclaim`);try{try{return await m(n)}catch(r){if(r.code!=="EEXIST")throw r;if(!await I(n))throw new Error("Another Canofold build is already running for this project");return await m(n)}}finally{await o.handle.close(),await N(o)}}i(_,"openBuildLock");async function $(t){if((await g(t.path))?.ownerId!==t.ownerId)return!1;let n=new Date;return await t.handle.utimes(n,n),!0}i($,"refreshBuildLock");async function V(t){if((await g(t.path))?.ownerId!==t.ownerId)throw new Error("Canofold build lock ownership was lost during the build")}i(V,"assertBuildLockOwned");async function et(t,e){let n=await _(t),o,r=setInterval(()=>{$(n).then(s=>{s||(o=new Error("Canofold build lock ownership was lost during the build"))}).catch(s=>{o=s})},A);r.unref();try{let s=i(()=>V(n),"assertOwned"),c=await e(s);if(o)throw o;return await s(),c}finally{clearInterval(r),await n.handle.close(),await N(n)}}i(et,"withBuildLock");async function it(t,e,n){let o=E(t,e.outputDir);await d(t,o,"outputDir"),await d(t,n,"build cache"),await u(o,n,"build cache");for(let r of e.versions.items){let s=a(t,r.docsDir,`versions.items[${r.id}].docsDir`);await d(t,s,`versions.items[${r.id}].docsDir`),await u(o,s,`versions.items[${r.id}].docsDir`),await u(n,s,`versions.items[${r.id}].docsDir`,"build cache")}for(let[r,s]of e.styles.entries()){let c=a(t,s,`styles[${r}]`);await d(t,c,`styles[${r}]`),await u(o,c,`styles[${r}]`),await u(n,c,`styles[${r}]`,"build cache")}return o}i(it,"resolveSafeOutputRoot");export{Q as a,Y as b,Z as c,tt as d,et as e,it as f};
|
|
3
|
+
//# sourceMappingURL=chunk-OATSOVSV.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as e}from"./chunk-AYDF3IFZ.js";function h(a){let r=a.toLowerCase(),i=r.match(/[a-z0-9]+/g)??[],o=[];for(let f of r.matchAll(new RegExp("\\p{Script=Han}+","gu"))){let t=Array.from(f[0]);o.push(...t);for(let n=0;n<t.length-1;n+=1){let s=t[n],c=t[n+1];s&&c&&o.push(s+c)}}return Array.from(new Set([...i,...o]))}e(h,"tokenize");export{h as a};
|
|
2
|
+
//# sourceMappingURL=chunk-XYJ2OBL3.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as s,b as f,e as p,f as l}from"./chunk-OATSOVSV.js";import{j as m}from"./chunk-4OALGQQB.js";import{a as n}from"./chunk-M6T5RSNJ.js";import"./chunk-3TIVCYR7.js";import"./chunk-EAYVCA3Z.js";import"./chunk-JK7ZNBUA.js";import{a as u}from"./chunk-AYDF3IFZ.js";import{readdir as R,rm as o}from"fs/promises";import{basename as h,dirname as g,join as b}from"path";async function x({cwd:t}){let i=await m(t),r=s(t),a=await l(t,i,r);await p(r,async()=>{let c=g(a),d=h(a).replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),w=new RegExp(`^\\.${d}\\.(?:backup|(?:tmp|backup)-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})$`,"i"),v=await R(c,{withFileTypes:!0}).catch(e=>{if(e.code==="ENOENT")return[];throw e});await Promise.all(v.filter(e=>w.test(e.name)).map(e=>o(b(c,e.name),{recursive:!0,force:!0}))),await o(a,{recursive:!0,force:!0}),await o(r,{recursive:!0,force:!0}),await o(f(t),{recursive:!0,force:!0})}),n(`Removed ${i.outputDir}, .canofold/cache, and temporary or interrupted build files`)}u(x,"runClean");export{x as runClean};
|
|
2
|
+
//# sourceMappingURL=clean-74GN2NZC.js.map
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{b as f}from"./chunk-M6T5RSNJ.js";import{a as l}from"./chunk-AYDF3IFZ.js";function u(n){let o=n.slice(1),t=o.flatMap((c,s)=>c==="--port"?[s]:[]);if(t.length>1)throw new Error("--port may only be specified once");let r=t[0];if(r===void 0){if(o.length)throw new Error(`Unknown option: ${o[0]}`);return}if(r!==0)throw new Error(`Unknown option: ${o[0]}`);let i=o[r+1];if(!i||i.startsWith("-"))throw new Error("Missing value for --port");if(o.length>2)throw new Error(`Unknown option: ${o[2]}`);let e=Number(i);if(!Number.isInteger(e)||e<1||e>65535)throw new Error(`Invalid port: ${i}`);return e}l(u,"portFromArgs");function d(n){let o=n.slice(1);if(!o.length)return{noCache:!1};if(o[0]!=="--no-cache")throw new Error(`Unknown option: ${o[0]}`);if(o.length>1)throw new Error(`Unknown option: ${o[1]}`);return{noCache:!0}}l(d,"buildOptionsFromArgs");function w(n){try{let o=Intl.getCanonicalLocales(n)[0];if(!o)throw new Error("Missing canonical locale");return o}catch{throw new Error(`Invalid locale: ${n}`)}}l(w,"canonicalLocale");function h(n){let o={},t=n.slice(1),r=new Set;for(let i=0;i<t.length;i+=1){let e=t[i];if(!e)continue;if(!e.startsWith("-")){if(o.targetDir)throw new Error(`Unknown option: ${e}`);o.targetDir=e;continue}if(e!=="--locale"&&e!=="--locales"&&e!=="--docs-dir")throw new Error(`Unknown option: ${e}`);if(r.has(e))throw new Error(`${e} may only be specified once`);r.add(e);let c=t[i+1];if(!c||c.startsWith("-"))throw new Error(`Missing value for ${e}`);if(i+=1,e==="--locale"&&(o.locale=c),e==="--locales"){let s=c.split(",").map(p=>p.trim());if(s.some(p=>!p))throw new Error("--locales must be a comma-separated list of locale identifiers");o.locales=s}e==="--docs-dir"&&(o.docsDir=c)}if(o.locale&&(o.locale=w(o.locale)),o.locales){if(o.locales=o.locales.map(w),new Set(o.locales).size!==o.locales.length)throw new Error("--locales must not contain duplicate locales");if(o.locale&&!o.locales.includes(o.locale))throw new Error(`--locale ${o.locale} must be included in --locales`);o.locale??=o.locales[0]}return o}l(h,"initOptionsFromArgs");function g(){console.log(`canofold
|
|
3
|
+
|
|
4
|
+
Commands:
|
|
5
|
+
init [dir] [--locale <locale>] [--locales <locale,...>] [--docs-dir <path>]
|
|
6
|
+
Create or adopt documentation
|
|
7
|
+
dev [--port <number>]
|
|
8
|
+
Start local docs server on a custom local port
|
|
9
|
+
build [--no-cache]
|
|
10
|
+
Build static site, optionally ignoring the persistent cache
|
|
11
|
+
clean Remove generated output and the persistent build cache
|
|
12
|
+
preview [--port <number>]
|
|
13
|
+
Preview .canofold/dist on a custom local port
|
|
14
|
+
check Run documentation checks
|
|
15
|
+
deploy Generate deployment guidance
|
|
16
|
+
`)}l(g,"printHelp");function a(n,o){let t=n[o];if(t!==void 0)throw new Error(`Unknown option: ${t}`)}l(a,"assertArgumentCount");async function m(n,o=process.cwd()){let t=n[0]??"help";if(t==="help"||t==="--help"||t==="-h"){a(n,1),g();return}if(t==="init"){let{runInit:r}=await import("./init-6R5SLESH.js");return r({cwd:o,...h(n)})}if(t==="build"){let{runBuild:r}=await import("./build-RBMQ6TZ7.js");return r({cwd:o,...d(n)})}if(t==="clean"){a(n,1);let{runClean:r}=await import("./clean-74GN2NZC.js");return r({cwd:o})}if(t==="dev"){let{runDev:r}=await import("./dev-WJCFAWYD.js");return r({cwd:o,port:u(n)})}if(t==="preview"){let{runPreview:r}=await import("./preview-ODXGCQZ7.js"),i=u(n);return r({cwd:o,port:i})}if(t==="check"){a(n,1);let{runCheck:r}=await import("./check-FCYLN6KO.js");return r({cwd:o})}if(t==="deploy"){a(n,1);let{runDeploy:r}=await import("./deploy-4YUYRVRO.js");return r({cwd:o})}throw new Error(`Unknown command: ${t}`)}l(m,"runCli");m(process.argv.slice(2)).catch(n=>{f(n instanceof Error?n.message:String(n)),process.exitCode=1});
|
|
17
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import{j as g}from"./chunk-4OALGQQB.js";import{a as d}from"./chunk-M6T5RSNJ.js";import"./chunk-EAYVCA3Z.js";import{a as i,e as f}from"./chunk-JK7ZNBUA.js";import{a as r}from"./chunk-AYDF3IFZ.js";import{mkdir as y,readFile as h,writeFile as $}from"fs/promises";import{join as a}from"path";function k(o){return`"${o.replace(/[\\"$]/g,"\\$&")}"`}r(k,"quoteNginxValue");async function b(o){if(await i(a(o,"pnpm-lock.yaml")))return"pnpm";if(await i(a(o,"yarn.lock")))return"yarn";try{let e=JSON.parse(await h(a(o,"package.json"),"utf8"));if(typeof e.packageManager=="string"){if(e.packageManager.startsWith("pnpm@"))return"pnpm";if(e.packageManager.startsWith("yarn@"))return"yarn"}}catch(e){if(e.code!=="ENOENT"&&!(e instanceof SyntaxError))throw e}return"npm"}r(b,"detectPackageManager");function w(o,e,s){let t=o.replaceAll("\\","/"),c=k(`/var/www/canofold/${t.replace(/^\/+/,"")}`),l=e.replace(/\/$/,"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),p=e==="/"?` location / {
|
|
2
|
+
try_files $uri $uri/ =404;
|
|
3
|
+
}`:` location = ${e.replace(/\/$/,"")} {
|
|
4
|
+
return 308 ${e};
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
location ${e} {
|
|
8
|
+
rewrite ^${l}/(.*)$ /$1 break;
|
|
9
|
+
try_files $uri $uri/ =404;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
location / {
|
|
13
|
+
return 404;
|
|
14
|
+
}`,u=JSON.stringify(t),m={npm:"npm exec -- canofold build",pnpm:"pnpm exec canofold build",yarn:"yarn exec canofold build"}[s],n=`Deploy directory:
|
|
15
|
+
|
|
16
|
+
\`\`\`txt
|
|
17
|
+
${t}
|
|
18
|
+
\`\`\`
|
|
19
|
+
|
|
20
|
+
Serve this directory at URL path \`${e}\`.
|
|
21
|
+
|
|
22
|
+
Canofold does not provide hosting, permissions, accounts, analytics, or server runtime.
|
|
23
|
+
`;return{"README.md":`# Canofold Deployment
|
|
24
|
+
|
|
25
|
+
${n}
|
|
26
|
+
|
|
27
|
+
Supported static hosts:
|
|
28
|
+
|
|
29
|
+
- GitHub Pages
|
|
30
|
+
- Cloudflare Pages
|
|
31
|
+
- Vercel
|
|
32
|
+
- Netlify
|
|
33
|
+
- Nginx
|
|
34
|
+
- Object storage
|
|
35
|
+
`,"github-pages.md":`# GitHub Pages
|
|
36
|
+
|
|
37
|
+
${n}
|
|
38
|
+
|
|
39
|
+
Use \`${t}\` as the published static artifact.
|
|
40
|
+
`,"github-pages.yml":`name: Deploy Canofold
|
|
41
|
+
|
|
42
|
+
on:
|
|
43
|
+
push:
|
|
44
|
+
branches: [main]
|
|
45
|
+
workflow_dispatch:
|
|
46
|
+
|
|
47
|
+
permissions:
|
|
48
|
+
contents: read
|
|
49
|
+
pages: write
|
|
50
|
+
id-token: write
|
|
51
|
+
|
|
52
|
+
concurrency:
|
|
53
|
+
group: pages
|
|
54
|
+
cancel-in-progress: false
|
|
55
|
+
|
|
56
|
+
jobs:
|
|
57
|
+
pages:
|
|
58
|
+
runs-on: ubuntu-latest
|
|
59
|
+
environment:
|
|
60
|
+
name: github-pages
|
|
61
|
+
url: \${{ steps.deployment.outputs.page_url }}
|
|
62
|
+
steps:
|
|
63
|
+
- uses: actions/checkout@v4
|
|
64
|
+
- uses: actions/setup-node@v4
|
|
65
|
+
with:
|
|
66
|
+
node-version: 22
|
|
67
|
+
- uses: actions/configure-pages@v5
|
|
68
|
+
- name: Install dependencies
|
|
69
|
+
shell: bash
|
|
70
|
+
run: |
|
|
71
|
+
if [[ -f pnpm-lock.yaml ]]; then
|
|
72
|
+
corepack enable
|
|
73
|
+
pnpm install --frozen-lockfile
|
|
74
|
+
elif [[ -f yarn.lock ]]; then
|
|
75
|
+
corepack enable
|
|
76
|
+
yarn install --immutable
|
|
77
|
+
elif [[ -f package-lock.json ]]; then
|
|
78
|
+
npm ci
|
|
79
|
+
elif [[ -f package.json ]]; then
|
|
80
|
+
npm install
|
|
81
|
+
fi
|
|
82
|
+
- name: Build documentation
|
|
83
|
+
shell: bash
|
|
84
|
+
run: |
|
|
85
|
+
if [[ -f pnpm-lock.yaml ]]; then
|
|
86
|
+
pnpm exec canofold build
|
|
87
|
+
elif [[ -f yarn.lock ]]; then
|
|
88
|
+
yarn exec canofold build
|
|
89
|
+
elif [[ -f package.json ]]; then
|
|
90
|
+
npm exec -- canofold build
|
|
91
|
+
else
|
|
92
|
+
echo "Add canofold to package.json before deploying" >&2
|
|
93
|
+
exit 1
|
|
94
|
+
fi
|
|
95
|
+
- uses: actions/upload-pages-artifact@v3
|
|
96
|
+
with:
|
|
97
|
+
path: ${u}
|
|
98
|
+
- name: Deploy to GitHub Pages
|
|
99
|
+
id: deployment
|
|
100
|
+
uses: actions/deploy-pages@v4
|
|
101
|
+
`,"cloudflare-pages.md":`# Cloudflare Pages
|
|
102
|
+
|
|
103
|
+
${n}
|
|
104
|
+
|
|
105
|
+
Set the output directory to \`${t}\`.
|
|
106
|
+
`,"vercel.md":`# Vercel
|
|
107
|
+
|
|
108
|
+
${n}
|
|
109
|
+
|
|
110
|
+
Use \`${t}\` as the output directory.
|
|
111
|
+
`,"vercel.json":`{
|
|
112
|
+
"outputDirectory": ${u}
|
|
113
|
+
}
|
|
114
|
+
`,"netlify.md":`# Netlify
|
|
115
|
+
|
|
116
|
+
${n}
|
|
117
|
+
|
|
118
|
+
Use \`${t}\` as the publish directory.
|
|
119
|
+
`,"netlify.toml":`[build]
|
|
120
|
+
publish = ${u}
|
|
121
|
+
command = ${JSON.stringify(m)}
|
|
122
|
+
`,"nginx.md":`# Nginx
|
|
123
|
+
|
|
124
|
+
${n}
|
|
125
|
+
|
|
126
|
+
Serve \`${t}\` as a static directory.
|
|
127
|
+
`,"nginx.conf":`# NOTE: Update the 'root' path below to match your server's document root.
|
|
128
|
+
# The default /var/www/canofold/ is a placeholder \u2014 adjust it to where you
|
|
129
|
+
# copied the built output (the contents of the '${t}' directory).
|
|
130
|
+
server {
|
|
131
|
+
listen 80;
|
|
132
|
+
server_name _;
|
|
133
|
+
root ${c};
|
|
134
|
+
index index.html;
|
|
135
|
+
error_page 404 /404.html;
|
|
136
|
+
|
|
137
|
+
location = /404.html {
|
|
138
|
+
internal;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
${p}
|
|
142
|
+
}
|
|
143
|
+
`}}r(w,"createGuides");async function E({cwd:o}){let e=await g(o),s=f(o,e.outputDir);if(!await i(a(s,"index.html")))throw new Error(`Build output not found at ${e.outputDir}. Run canofold build before canofold deploy.`);let t=a(o,".canofold/deploy"),c=await b(o);await y(t,{recursive:!0});for(let[l,p]of Object.entries(w(e.outputDir,e.basePath,c)))await $(a(t,l),p);d(`Wrote deployment guides to ${t}`)}r(E,"runDeploy");export{E as runDeploy};
|
|
144
|
+
//# sourceMappingURL=deploy-4YUYRVRO.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as b}from"./chunk-JZIKHPBO.js";import{b as g}from"./chunk-56TT2V3X.js";import"./chunk-4E7M3CIK.js";import{b as h}from"./chunk-ENPRUF6E.js";import"./chunk-XYJ2OBL3.js";import{a as B}from"./chunk-OATSOVSV.js";import"./chunk-4OALGQQB.js";import{a as v,b as f}from"./chunk-M6T5RSNJ.js";import"./chunk-3TIVCYR7.js";import"./chunk-EAYVCA3Z.js";import{c as p,e as m}from"./chunk-JK7ZNBUA.js";import{a as o}from"./chunk-AYDF3IFZ.js";import w from"chokidar";import{createMarkdownRenderer as S}from"@canofold/markdown/server";import{relative as P,resolve as k,sep as R}from"path";function D({build:n,reload:c,onBuildError:l=o(t=>f(t instanceof Error?t.message:String(t)),"onBuildError"),onBuildOk:i,debounceMs:s=80}){let t,u,e=!1,r=!1,a=o(()=>{if(t=void 0,!r){if(u){e=!0;return}u=(async()=>{try{let d=await n();r||(i?.(),c(d))}catch(d){l(d)}finally{u=void 0,e&&!r&&(e=!1,t=setTimeout(a,0))}})()}},"run");return{schedule(){if(!r){if(u){e=!0;return}t&&clearTimeout(t),t=setTimeout(a,s)}},async close(){r=!0,e=!1,t&&clearTimeout(t),t=void 0,await u}}}o(D,"createBuildScheduler");async function y({cwd:n,port:c}){let l=S(),i=await g({cwd:n,renderer:l}),s=await b({root:o(()=>m(n,i.config.outputDir),"root"),port:c,liveReload:!0,basePath:o(()=>i.config.basePath,"basePath")}),t=w.watch(".",{cwd:n,ignoreInitial:!0,ignored:o(e=>{let r=k(n,e),a=P(n,r).split(R);return a.includes("node_modules")||a.includes(".git")||a.includes(".canofold")||a.some(d=>/^\..+\.(?:tmp|backup)-/.test(d))?!0:p(m(n,i.config.outputDir),r)||p(B(n),r)},"ignored")}),u=D({build:o(async()=>{i=await g({cwd:n,renderer:l});let e=i.changedPages.flatMap(r=>{let a=i.graph.pages.find(d=>d.sourceRelativePath===r);return a?[h(i.config,a.routePath)]:[]});return{protocol:1,type:"update",mode:i.partialReload&&e.length===1?"page":"full",routes:e}},"build"),reload:o(e=>s.reload(e),"reload"),onBuildError:o(e=>{let r=e instanceof Error?e.message:String(e);f("Build error:",r),s.sendBuildError(r)},"onBuildError"),onBuildOk:o(()=>s.sendBuildOk(),"onBuildOk")});return t.on("all",()=>u.schedule()),t.on("error",e=>{let r=e instanceof Error?e.message:String(e);f("File watcher error:",r),s.sendBuildError(r)}),{port:s.port,close:o(async()=>{await t.close(),await u.close(),await s.close()},"close")}}o(y,"startDevServer");async function z({cwd:n,port:c=3333}){let l=await y({cwd:n,port:c});return v(`Dev server running at http://127.0.0.1:${l.port}/`),l}o(z,"runDev");export{z as runDev};
|
|
2
|
+
//# sourceMappingURL=dev-WJCFAWYD.js.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{c as t,f,g as r}from"./chunk-ENPRUF6E.js";import"./chunk-XYJ2OBL3.js";import{a as n}from"./chunk-3TIVCYR7.js";import"./chunk-JK7ZNBUA.js";import{a as o}from"./chunk-AYDF3IFZ.js";function i(e){return e}o(i,"defineConfig");export{f as CANOFOLD_EXTENSION_API_VERSION,n as canofoldVersion,i as defineConfig,r as defineExtension,t as defineSearchProvider};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import{a as d}from"./chunk-M6T5RSNJ.js";import{a as b}from"./chunk-3TIVCYR7.js";import{a as k,d as S}from"./chunk-EAYVCA3Z.js";import{a as T,d as j,f as N}from"./chunk-JK7ZNBUA.js";import{a as l}from"./chunk-AYDF3IFZ.js";import{mkdir as U,readFile as B,readdir as G,rm as V,rmdir as Y,writeFile as _}from"fs/promises";import{dirname as W,isAbsolute as Q,join as E}from"path";import{createInterface as Z}from"readline/promises";import{join as y}from"path";var R=`/**
|
|
2
|
+
* Minimal declarations for trusted project-local TSX components.
|
|
3
|
+
*
|
|
4
|
+
* Canofold intentionally does not publish or emulate a UI component module.
|
|
5
|
+
* Projects that need full React types should install React in the authored project.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare namespace JSX {
|
|
9
|
+
interface Element {}
|
|
10
|
+
interface IntrinsicElements {
|
|
11
|
+
[elementName: string]: Record<string, unknown>
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module 'react/jsx-runtime' {
|
|
16
|
+
export const Fragment: symbol
|
|
17
|
+
export function jsx(type: unknown, props: unknown, key?: unknown): JSX.Element
|
|
18
|
+
export function jsxs(type: unknown, props: unknown, key?: unknown): JSX.Element
|
|
19
|
+
}
|
|
20
|
+
`;var z={zh:{index:`---
|
|
21
|
+
title: \u9996\u9875
|
|
22
|
+
description: Canofold \u4E2D\u6587\u6587\u6863\u9996\u9875
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
# \u6B22\u8FCE\u4F7F\u7528 Canofold
|
|
26
|
+
|
|
27
|
+
\u8FD9\u662F\u4E00\u4E2A\u7531 Canofold \u751F\u6210\u7684\u9759\u6001\u6280\u672F\u6587\u6863\u9879\u76EE\u3002
|
|
28
|
+
`,guide:`---
|
|
29
|
+
title: \u6307\u5357
|
|
30
|
+
description: Canofold \u4F7F\u7528\u6307\u5357
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
# \u6307\u5357
|
|
34
|
+
|
|
35
|
+
\u8FD0\u884C \`canofold dev\` \u5F00\u59CB\u672C\u5730\u9884\u89C8\u3002
|
|
36
|
+
`},en:{index:`---
|
|
37
|
+
title: Home
|
|
38
|
+
description: Canofold English documentation home
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
# Welcome to Canofold
|
|
42
|
+
|
|
43
|
+
This is a static technical documentation project generated by Canofold.
|
|
44
|
+
`,guide:`---
|
|
45
|
+
title: Guide
|
|
46
|
+
description: Canofold guide
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
# Guide
|
|
50
|
+
|
|
51
|
+
Run \`canofold dev\` to preview locally.
|
|
52
|
+
`}},A=`---
|
|
53
|
+
title: Canofold
|
|
54
|
+
description: Technical documentation built with Canofold
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
# Canofold
|
|
58
|
+
`;function q(e){return z[e]??z[e.toLowerCase().split("-")[0]??""]}l(q,"localizedTemplateFor");function H(e,t,n){return`import { defineConfig } from 'canofold'
|
|
59
|
+
|
|
60
|
+
export default defineConfig({
|
|
61
|
+
title: 'Canofold',
|
|
62
|
+
description: 'Technical documentation',
|
|
63
|
+
requiredVersion: '^${b}',
|
|
64
|
+
docsDir: ${JSON.stringify(e)},
|
|
65
|
+
i18n: {
|
|
66
|
+
defaultLocale: '${t}',
|
|
67
|
+
locales: [${n.map(i=>`'${i}'`).join(", ")}]
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
`}l(H,"configTemplate");function O(e){let{docsDir:t,defaultLocale:n,locales:i,includeContent:r,includeConfig:s}=e,c={[y(t,"canofold-env.d.ts")]:R};if(s&&(c["canofold.config.ts"]=H(t,n,i)),!r)return c;for(let g of i){let p=g===n?t:y(t,g),a=q(g);c[y(p,"index.md")]=a?.index??A,a&&(c[y(p,"guide.md")]=a.guide)}return c}l(O,"createInitFiles");async function J(e,t=""){let n;try{n=await G(e,{withFileTypes:!0})}catch(r){if(r.code==="ENOENT")return[];throw r}let i=[];for(let r of n){let s=t?E(t,r.name):r.name;if(r.isFile()&&k(r.name)&&i.push(s),r.isDirectory()&&(t||r.name!=="public"))for(let c of await J(E(e,r.name),s))i.push(c)}return i.sort((r,s)=>r.localeCompare(s))}l(J,"listMarkdownFiles");function ee(e,t){for(let n of t)try{Intl.getCanonicalLocales(n)}catch{throw new Error(`Invalid locale: ${n}`)}if(new Set(t.map(n=>n.toLowerCase())).size!==t.length)throw new Error("Locales must not contain duplicates");if(!t.some(n=>n.toLowerCase()===e.toLowerCase()))throw new Error(`Default locale ${e} must be included in locales`)}l(ee,"validateLocaleSelection");async function te(e=Z({input:process.stdin,output:process.stdout})){try{let n=((await e.question("Existing documents found. Enter their locale, or a comma-separated locale list (default: zh): ")).trim()||"zh").split(",").map(i=>i.trim());if(n.some(i=>!i))throw new Error("Locales must be a comma-separated list of locale identifiers");return n}catch(t){throw t.code==="ABORT_ERR"?new Error("Canofold initialization cancelled"):t}finally{e.close()}}l(te,"promptForLocales");function ne(e,t){return e.length===t.length&&e.every((n,i)=>n.toLowerCase()===t[i]?.toLowerCase())}l(ne,"sameLocales");function oe(e,t){if(e.docsDir&&e.docsDir!==t.docsDir)throw new Error(`--docs-dir ${e.docsDir} conflicts with configured docsDir ${t.docsDir}`);if(e.locale&&e.locale.toLowerCase()!==t.i18n.defaultLocale.toLowerCase())throw new Error(`--locale ${e.locale} conflicts with configured defaultLocale ${t.i18n.defaultLocale}`);if(e.locales&&!ne(e.locales,t.i18n.locales))throw new Error(`--locales ${e.locales.join(",")} conflicts with configured locales ${t.i18n.locales.join(",")}`)}l(oe,"assertOptionsMatchConfig");function $(e){return S(e.replace(/\\/g,"/")).normalize("NFC").toLocaleLowerCase("en-US")}l($,"portablePageKey");function ie(e,t,n){if(!e.length)return[];let i=[],r=e.map(a=>a.replace(/\\/g,"/")),s=l(a=>n==="."?a:`${n.replace(/\\/g,"/")}/${a}`,"displayPath"),c=t.normalize("NFC").toLocaleLowerCase("en-US");r.some(a=>{let h=$(a);return h==="index"||h===`${c}/index`})||i.push(`no default-language index.md or index.mdx was found in ${n}`);let p=new Map;for(let a of r)a.startsWith(`${t}/`)||p.set($(a),a);for(let a of r){if(!a.startsWith(`${t}/`))continue;let h=a.slice(t.length+1),u=p.get($(h));u&&i.push(`${s(u)} and ${s(a)} map to the same default-language page; keep only one source`)}return i}l(ie,"existingContentWarnings");async function re(e,t){let n=[],i=e;for(;!await T(i);){n.push(i);let r=W(i);if(r===i)break;i=r}for(let r of n.reverse())try{await U(r),t.push(r)}catch(s){if(s.code!=="EEXIST")throw s}}l(re,"createMissingDirectoryChain");async function xe(e,t={}){let n=e.targetDir?E(e.cwd,e.targetDir):e.cwd,{findConfigPath:i,loadConfig:r}=await import("./load-W4JHZIBF.js"),s=!!await i(n),c=s?await r(n):void 0;c&&oe(e,c);let g=c?.docsDir??e.docsDir??"docs";if(Q(g))throw new Error("docsDir must be a relative path");let p=j(n,g,"docsDir");await N(n,p,"docsDir");let a=await J(p),h=a.length>0,u=e.locales;if(h&&!s&&!e.locale&&!u){let o=e.localePrompt??(process.stdin.isTTY&&process.stdout.isTTY?te:void 0);if(!o){let f=a[0]??"";throw new Error(`Found ${a.length} existing Markdown file(s) in "${g}" (e.g. "${f}"), but cannot determine their language in a non-interactive environment. Specify the locale explicitly: canofold init --locale <locale> (e.g. --locale zh)`)}u=await o()}let x=c?.i18n.defaultLocale??e.locale??u?.[0]??"zh";u=c?.i18n.locales??u??[x],ee(x,u);let M=O({docsDir:g,defaultLocale:x,locales:u,includeContent:!h,includeConfig:!s}),P=[],F=[],D=ie(a,x,g);for(let[o,f]of Object.entries(M)){let w=E(n,o);try{let C=await B(w,"utf8");F.push(o),C!==f&&D.push(`${o} already exists with different content`)}catch(C){let v=C.code;if(v==="EISDIR")throw new Error(`Cannot create ${o} because a directory exists at that path`);if(v!=="ENOENT")throw C;P.push({relativePath:o,content:f,fullPath:w})}}let m={mode:s?"configured":h?"adopt":"create",createFiles:P,keepFiles:F,warnings:D};if(!m.createFiles.length){for(let o of m.warnings)d(`Warning: ${o}`);d(`Canofold is already initialized in ${n}`);return}let L=[],K=t.writeFile??((o,f,w)=>_(o,f,w)),X=[...new Set(m.createFiles.map(o=>W(o.fullPath)))].sort((o,f)=>o.length-f.length),I=[];try{for(let o of X)await re(o,I);for(let o of m.createFiles)await K(o.fullPath,o.content,{flag:"wx"}),L.push(o.fullPath)}catch(o){await Promise.all(L.map(f=>V(f,{force:!0})));for(let f of I.sort((w,C)=>C.length-w.length))try{await Y(f)}catch{}throw o}for(let o of m.createFiles)d(`Created ${o.relativePath}`);for(let o of m.keepFiles)d(`Kept existing ${o}`);for(let o of m.warnings)d(`Warning: ${o}`);if(m.mode==="adopt"){let o=a.length===1?"document":"documents";d(`Adopted ${a.length} existing ${o} in ${n}`),d(`Kept ${a.length} existing ${o} unchanged`),d("Next: canofold check")}else m.mode==="configured"?(d(`Created missing documentation files in ${n}`),d("Next: canofold dev")):(d(`Created Canofold docs in ${n}`),d("Next: canofold dev"));d("Add .canofold/ to .gitignore if this directory is versioned.")}l(xe,"runInit");export{te as promptForLocales,xe as runInit};
|
|
71
|
+
//# sourceMappingURL=init-6R5SLESH.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a}from"./chunk-AYDF3IFZ.js";import{createElement as k,useEffect as b,useState as H}from"react";import{createRoot as S}from"react-dom/client";import{Markdown as R}from"@canofold/markdown";import{Fragment as C,jsx as P,jsxs as K}from"react/jsx-runtime";function _(t){try{return JSON.parse(t.dataset.canofoldPlaygroundLabels??"{}")}catch{return{}}}a(_,"parseLabels");function x(t){let n=t==="/"?"":t.replace(/\/$/,"");return o=>!n||o===n||o.startsWith(`${n}/`)||!o.startsWith("/")||o.startsWith("//")?o:`${n}${o}`}a(x,"createUrlTransform");function A({source:t,options:n,basePath:o,loadingLabel:i,onReady:c,onFailure:g}){let[d,u]=H();return b(()=>u(void 0),[t]),K(C,{children:[d?P("div",{className:"cf-playground-status cf-playground-error",role:"alert","data-canofold-playground-error":"",children:d instanceof Error?d.message:String(d)}):null,P(R,{as:"article",source:t,options:n,urlTransform:x(o),onError:f=>{u(f),g(f)},onReady:c,retainPrevious:!0,fallback:d?null:P("div",{className:"cf-playground-status",role:"status","aria-live":"polite",children:i})})]})}a(A,"LivePreview");function F(t,n){let o=Math.max(0,t.scrollHeight-t.clientHeight),i=Math.max(0,n.scrollHeight-n.clientHeight);if(t.clientHeight<=0||n.clientHeight<=0)return;let c=o>0?t.scrollTop/o*i:0;Math.abs(n.scrollTop-c)>.5&&(n.scrollTop=c)}a(F,"synchronizeScroll");function q(t,n){let o=t.ownerDocument.defaultView,i=!1,c,g,d,u=a(r=>{r!==void 0&&o?.cancelAnimationFrame(r)},"cancelFrame"),f=a(()=>{i=!0,c=void 0,u(g),u(d),g=void 0,d=void 0},"pause"),p=a(()=>{if(!o){i=!1;return}let r=2,s=a(()=>{if(r-=1,r>0){d=o.requestAnimationFrame(s);return}d=void 0,i=!1},"resume");d=o.requestAnimationFrame(s)},"resumeAfterPaint"),w=a((r,s)=>{if(!(i||c===r)){if(c=s,F(r,s),!o){c=void 0;return}u(g),g=o.requestAnimationFrame(()=>{g=void 0,c=void 0})}},"sync"),y=a(()=>w(t,n),"onSourceScroll"),h=a(()=>w(n,t),"onPreviewScroll"),M=a(r=>{if(r.defaultPrevented||r.button!==0||r.altKey||r.ctrlKey||r.metaKey||r.shiftKey)return;let e=(r.target instanceof Element?r.target:r.target instanceof Node?r.target.parentElement:void 0)?.closest('a[href^="#"]'),l=e?.getAttribute("href");if(!e||!l||l==="#")return;let m;try{m=decodeURIComponent(l.slice(1))}catch{return}let T=[...(e.closest('[data-cf-root="markdown"]')??n).querySelectorAll("[id]")].find(L=>L.id===m);if(!T)return;r.preventDefault(),f();let v=n.scrollTop+T.getBoundingClientRect().top-n.getBoundingClientRect().top;n.scrollTop=Math.max(0,v);try{o?.history.pushState(null,"",l)}catch{}p()},"onPreviewAnchorClick");return t.addEventListener("scroll",y),n.addEventListener("scroll",h),n.addEventListener("click",M),{replacePreview(r){let s=Math.max(0,t.scrollHeight-t.clientHeight),e=s>0?t.scrollTop/s:0;f(),r();let l=Math.max(0,n.scrollHeight-n.clientHeight);t.clientHeight>0&&n.clientHeight>0&&(n.scrollTop=e*l),p()}}}a(q,"setupSynchronizedScrolling");function D(t,n){if(t.dataset.canofoldPlaygroundReady!==void 0)return;let o=t.querySelector("[data-canofold-playground-source]"),i=t.querySelector("[data-canofold-playground-preview]");if(!o||!i)return;let c=_(t),g={...n.markdown,labels:c,locale:document.documentElement.lang||n.markdown.locale},d=`${t.dataset.canofoldPlaygroundPreviewLabel??"Preview"}\u2026`,u,f=0,p,w=!0,y=q(o,i),h=a(e=>{e.dispose?.(),e.root.unmount(),e.element.remove()},"discardStage"),M=a(async(e,l)=>{if(!e.activating){if(e.activating=!0,f!==l){h(e);return}try{e.dispose=await window.__canofoldEnhanceMarkdown?.(e.element)}catch(m){h(e),console.error("[canofold] Playground preview enhancement failed:",m);return}if(f!==l){h(e);return}y.replacePreview(()=>{if(w){e.element.remove(),window.__canofoldMarkdownDispose?.(),window.__canofoldMarkdownDispose=void 0;for(let m of[...i.childNodes])m.remove();w=!1,e.element.hidden=!1,i.append(e.element)}else e.element.hidden=!1,p?.dispose?.(),p?.root.unmount(),p?.element.remove();p=e})}},"activate"),r=a(async e=>{if(await window.__canofoldMarkdownReady,f!==e)return;let l=i.ownerDocument.createElement("div");l.className="cf-playground-live-preview",l.hidden=!0,i.append(l);let m={element:l,root:S(l),activating:!1};m.root.render(k(A,{source:o.value,options:g,basePath:n.basePath,loadingLabel:d,onReady:a(()=>{M(m,e)},"onReady"),onFailure:a(E=>{console.error("[canofold] Playground preview render failed:",E),queueMicrotask(()=>h(m))},"onFailure")}))},"render"),s=a(()=>{let e=++f;u!==void 0&&window.clearTimeout(u),u=window.setTimeout(()=>{r(e)},120)},"scheduleRender");o.addEventListener("input",s),o.addEventListener("keydown",e=>{e.key!=="Tab"||e.altKey||e.ctrlKey||e.metaKey||(e.preventDefault(),o.setRangeText(" ",o.selectionStart,o.selectionEnd,"end"),s())}),t.dataset.canofoldPlaygroundReady=""}a(D,"mountPlayground");function W(t){document.querySelectorAll("[data-canofold-playground]").forEach(n=>D(n,t))}a(W,"mountPlaygrounds");export{W as mountPlaygrounds};
|
|
2
|
+
//# sourceMappingURL=playground-client.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as p}from"./chunk-JZIKHPBO.js";import{j as n}from"./chunk-4OALGQQB.js";import{a}from"./chunk-M6T5RSNJ.js";import"./chunk-EAYVCA3Z.js";import{e as i}from"./chunk-JK7ZNBUA.js";import{a as e}from"./chunk-AYDF3IFZ.js";async function g({cwd:r,port:s=4173}){let t=await n(r),o=await p({root:i(r,t.outputDir),port:s,basePath:t.basePath});return a(`Preview running at http://127.0.0.1:${o.port}${t.basePath}`),o}e(g,"runPreview");export{g as runPreview};
|
|
2
|
+
//# sourceMappingURL=preview-ODXGCQZ7.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as W}from"./chunk-XYJ2OBL3.js";import{a as c}from"./chunk-AYDF3IFZ.js";function $(w,l){let i=c(t=>String(t??"").replace(/<[^>]*>/g," ").replace(/&(?:nbsp|#160);/gi," ").replace(/&(?:amp|#38);/gi,"&").replace(/&(?:lt|#60);/gi,"<").replace(/&(?:gt|#62);/gi,">").replace(/\s+/g," ").trim(),"plainText"),r=i(w).toLowerCase().split(/\s+/).filter(Boolean),a=c((...t)=>{let s=t.map(i).join(" ").toLowerCase();return r.length>0&&r.every(m=>s.includes(m))},"matches"),g=c((t,s)=>!s||!t.toLowerCase().startsWith(s.toLowerCase())?t:t.slice(s.length).replace(/^[\s·::.\-—]+/,"").trim()||t,"withoutRepeatedLead"),b=c((t,s)=>(a(t)?4:0)+(a(s)?2:0)+(a(t,s)?1:0),"score"),d=(l.sub_results??[]).map((t,s)=>{let m=i(t.title),k=i(t.plain_excerpt||t.excerpt);return{fragment:t,title:m,excerpt:k,index:s,score:b(m,k)}}).filter(t=>t.score>0).sort((t,s)=>s.score-t.score||t.index-s.index)[0],p=i(l.meta?.title||l.url);if(d){let t=d.title===p?"":d.title,s=g(d.excerpt,d.title),m=[t,s].filter(Boolean).join(" \xB7 ")||d.title||l.url;return{title:p,description:m,excerpt:s,routePath:d.fragment.url||l.url}}let y=i(l.meta?.description),P=i(l.plain_excerpt||l.excerpt),o=a(p)?y||P||l.url:a(y)?y:a(P)?P:void 0;if(o)return{title:p,description:o,excerpt:P,routePath:l.url}}c($,"createPagefindSearchDocument");function F(w,l){let i=w.trim().toLowerCase();return i?l.map((r,a)=>{let g=r.title.toLowerCase(),b=r.description.toLowerCase(),x=String(r.excerpt??"").toLowerCase(),d=(g===i?200:g.includes(i)?100:0)+(b.includes(i)?24:0)+(x.includes(i)?8:0);return{document:r,index:a,score:d}}).sort((r,a)=>a.score-r.score||r.index-a.index).map(r=>r.document):l}c(F,"rankSearchDocuments");function q(w,l){let i=c(y=>y.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',"""),"escape"),r=String(w),a=l.trim();if(!a)return i(r);let g=r.toLowerCase(),b=a.toLowerCase(),x=0,d="",p=g.indexOf(b);for(;p!==-1;)d+=i(r.slice(x,p)),d+=`<mark>${i(r.slice(p,p+a.length))}</mark>`,x=p+a.length,p=g.indexOf(b,x);return d+i(r.slice(x))}c(q,"highlightSearchText");var N=8,ne=32,re=2;function I(w){return String(w).replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""")}c(I,"escapeHtml");function U(){let w=window;w.__canofoldSearchDispose?.();let l=new AbortController,i=l.signal,r=c((o,t,s,m={})=>o.addEventListener(t,s,{...m,signal:i}),"on"),a,g=!1,b=document.querySelector("[data-canofold-search]");if(b){let R=function(e){return B().then(e).catch(()=>{})},O=function(e){return m==="pagefind"?ee(e):Z(e)},K=function(){return Array.from(o.querySelectorAll('a[href],button:not([disabled]),input:not([disabled]),textarea:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(e=>e.tabIndex>=0&&!e.closest("[hidden]")&&e.getAttribute("aria-hidden")!=="true")},H=function(){_=document.activeElement,o.removeAttribute("hidden"),document.documentElement.classList.add("cf-search-open"),D?.removeAttribute("hidden"),h?.setAttribute("hidden",""),requestAnimationFrame(()=>(A||j)?.focus()),m==="pagefind"&&R(e=>e.init?.())},L=function(){o.setAttribute("hidden",""),document.documentElement.classList.remove("cf-search-open"),A&&(A.value=""),h&&(h.innerHTML=""),D?.removeAttribute("hidden"),h?.setAttribute("hidden",""),_ instanceof HTMLElement&&_.focus({preventScroll:!0})};var x=R,d=O,p=K,y=H,P=L;c(R,"runPagefind"),c(O,"search"),c(K,"focusable"),c(H,"openModal"),c(L,"closeModal");let o=b,t=o.getAttribute("data-locale")||document.documentElement.lang||"en",s=o.getAttribute("data-version")||"current",m=o.getAttribute("data-search-provider")||"compact",k=o.getAttribute("data-search-index-url")||`/search/${t}.json`,X=o.getAttribute("data-search-bundle-url")||"/pagefind/pagefind.js",z=o.getAttribute("data-empty-label")||"No matching documents",G=o.getAttribute("data-error-label")||"Search index is unavailable",A=o.querySelector("input"),D=o.querySelector("[data-canofold-search-default]"),h=o.querySelector("[data-canofold-search-results]"),J=document.querySelectorAll("[data-canofold-search-open]"),Q=o.querySelectorAll("[data-canofold-search-close]"),V=o.querySelectorAll("[data-canofold-search-action]"),j=o.querySelector('[role="dialog"]'),C,M,_;async function Y(){let e=await fetch(k);if(!e.ok)throw new Error("Search index not found");return await e.json()}c(Y,"loadLocalIndex");async function Z(e){C||(C=Y().catch(u=>{throw C=void 0,u}));let n=await C,f=W(e),E=e.toLowerCase(),S=new Map;return f.forEach(u=>{(n.postings[u]||[]).forEach(T=>{S.set(T,(S.get(T)||0)+1)})}),Array.from(S,([u,T])=>{let v=n.docs[u];if(!v)return;let te=[v.title,v.description,...v.tags||[],v.excerpt].join(" ").toLowerCase().includes(E)?re:0;return{doc:v,score:T+te}}).filter(u=>!!u).filter(u=>u.score>0).sort((u,T)=>T.score-u.score).slice(0,N).map(u=>u.doc)}c(Z,"searchCompact");async function B(){return M||(M=import(X).then(e=>e).catch(e=>{throw M=void 0,e})),M}c(B,"loadPagefind");async function ee(e){let f=await(await B()).search(e,{filters:{version:s,locale:t}}),E=await Promise.all(f.results.slice(0,ne).map(async S=>{let u=await S.data();return $(e,u)}));return F(e,E.filter(S=>!!S)).slice(0,N)}c(ee,"searchPagefind"),J.forEach(e=>r(e,"click",H)),Q.forEach(e=>r(e,"click",L)),h&&r(h,"click",e=>{let n=e.target;n instanceof Element&&n.closest("a[href]")&&L()}),V.forEach(e=>r(e,"click",()=>{let n=e.getAttribute("data-canofold-search-action");L(),n==="source"&&document.querySelector("[data-canofold-source-open]")?.click(),n==="theme"&&document.querySelector("[data-canofold-theme-toggle]")?.click()})),r(document,"keydown",e=>{let n=e;if((n.metaKey||n.ctrlKey)&&n.key.toLowerCase()==="k")n.preventDefault(),o.hasAttribute("hidden")?H():L();else if(n.key==="Escape"&&!o.hasAttribute("hidden"))L();else if(n.key==="Tab"&&!o.hasAttribute("hidden")){let f=K();if(!f.length){n.preventDefault(),j?.focus();return}let E=f[0],S=f[f.length-1];n.shiftKey&&document.activeElement===E?(n.preventDefault(),S?.focus()):!n.shiftKey&&document.activeElement===S&&(n.preventDefault(),E?.focus())}}),A&&h&&r(A,"input",()=>{clearTimeout(a),a=setTimeout(async()=>{let e=A.value.trim();if(!e){h.innerHTML="",h.setAttribute("hidden",""),D?.removeAttribute("hidden");return}D?.setAttribute("hidden",""),h.removeAttribute("hidden"),m==="pagefind"&&R(n=>n.preload?.(e,{filters:{version:s,locale:t}}));try{let n=await O(e);if(g||A.value.trim()!==e)return;h.innerHTML=n.length?n.map(f=>'<a class="cf-search-result" href="'+I(f.routePath)+'"><span class="cf-search-result-copy"><strong>'+q(f.title,e)+"</strong><small>"+q(f.description||f.routePath,e)+'</small></span><span class="cf-search-result-arrow" aria-hidden="true">\u2192</span></a>').join(""):`<p class="cf-search-empty">${I(z)}</p>`}catch{if(g||A.value.trim()!==e)return;h.innerHTML=`<p class="cf-search-empty">${I(G)}</p>`}},150)})}w.__canofoldSearchDispose=()=>{g=!0,l.abort(),clearTimeout(a),document.documentElement.classList.remove("cf-search-open")}}c(U,"bootstrapSearch");var oe=window;oe.__canofoldBootstrapSearch=U;U();export{U as bootstrapSearch};
|
|
2
|
+
//# sourceMappingURL=search-client.js.map
|