@aiquants/markdown-explorer 0.11.0 → 0.12.1

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +65 -6
  3. package/dist/EditSurface-By6NPcD7.js +633 -0
  4. package/dist/EditSurface-BztcpQPW.cjs +2 -0
  5. package/dist/{ExplorerSplit-DwlWWfRv.js → ExplorerSplit-BjjqNRtj.js} +52 -52
  6. package/dist/{ExplorerSplit-51frK8xf.cjs → ExplorerSplit-CqmbUSZ7.cjs} +1 -1
  7. package/dist/{MultiLayout-CeR_l6Rb.js → MultiLayout-BYXoD1aS.js} +4 -4
  8. package/dist/{MultiLayout-B4PtS45V.cjs → MultiLayout-BZbEl73E.cjs} +1 -1
  9. package/dist/{NativeScrollBar-Dp4YWBp7.cjs → NativeScrollBar-B7jTbQmn.cjs} +1 -1
  10. package/dist/{NativeScrollBar-CVWeTlHC.js → NativeScrollBar-RP37nwmY.js} +1 -1
  11. package/dist/{TreeLayout-D-NyhuVM.cjs → TreeLayout-CEp5oKly.cjs} +1 -1
  12. package/dist/{TreeLayout-min5AOhr.js → TreeLayout-Uo6RG7lq.js} +3 -3
  13. package/dist/client/MarkdownExplorer.d.cts +3 -2
  14. package/dist/client/MarkdownExplorer.d.ts +3 -2
  15. package/dist/core/contracts.d.cts +16 -0
  16. package/dist/core/contracts.d.ts +16 -0
  17. package/dist/dataRoute-CH3yOKR0.cjs +1 -0
  18. package/dist/{dataRoute-CU9CKP44.js → dataRoute-Pm_0ue_4.js} +93 -92
  19. package/dist/{index-DJ_FUtYM.cjs → index-CGBl3fYT.cjs} +8 -8
  20. package/dist/{index-BPj19kIo.js → index-CjCr8czx.js} +962 -908
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.cts +1 -1
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +9 -9
  25. package/dist/{location-LNl0QOXI.cjs → location-BUNWJ4eB.cjs} +1 -1
  26. package/dist/{location-BT23fKeh.js → location-DWd6SQhN.js} +1 -1
  27. package/dist/{merge-AnqxGn__.cjs → merge-DRGBbLuR.cjs} +1 -1
  28. package/dist/{merge-hyUGPGbJ.js → merge-q-5i8qsn.js} +1 -1
  29. package/dist/sanitizePolicy-BfUlXI5E.cjs +1 -0
  30. package/dist/sanitizePolicy-djLC3fRN.js +96 -0
  31. package/dist/sanitizeWorker.cjs +1 -1
  32. package/dist/sanitizeWorker.js +143 -226
  33. package/dist/server.cjs +1 -1
  34. package/dist/server.js +3 -3
  35. package/dist/styles/markdown-explorer.css +1 -1
  36. package/docs/behavior/dom-hooks.md +1 -1
  37. package/docs/behavior/layout.md +4 -1
  38. package/docs/behavior/security.md +2 -0
  39. package/package.json +3 -3
  40. package/dist/EditSurface-BK_Pz_LF.js +0 -371
  41. package/dist/EditSurface-CfbYYXrc.cjs +0 -2
  42. package/dist/dataRoute-CIFFX5bd.cjs +0 -1
@@ -161,6 +161,21 @@ export type ExplorerPreviewAnswer = {
161
161
  readonly htmlContent: string;
162
162
  readonly headings: readonly ExplorerHeading[];
163
163
  } | ExplorerFailureDocument;
164
+ export type ExplorerDraft = {
165
+ readonly path: string;
166
+ readonly text: string;
167
+ };
168
+ export type ExplorerDraftAnswer = {
169
+ readonly kind: "preview";
170
+ readonly htmlContent: string;
171
+ readonly headings: readonly ExplorerHeading[];
172
+ } | ExplorerFailureDocument | {
173
+ readonly kind: "unavailable";
174
+ };
175
+ export type ExplorerDraftConverter = {
176
+ readonly convert: (draft: ExplorerDraft, signal: AbortSignal) => Promise<ExplorerDraftAnswer>;
177
+ readonly prepare?: () => void;
178
+ };
164
179
  export type ExplorerRevision = {
165
180
  readonly id: string;
166
181
  readonly modifiedAt: string | null;
@@ -219,6 +234,7 @@ export declare const isExplorerSaveAnswer: (value: unknown) => value is Explorer
219
234
  export declare const isExplorerPreviewAnswer: (value: unknown) => value is ExplorerPreviewAnswer;
220
235
  export declare const isExplorerRevisionsAnswer: (value: unknown) => value is ExplorerRevisionsAnswer;
221
236
  export declare const isExplorerRevisionAnswer: (value: unknown) => value is ExplorerRevisionAnswer;
237
+ export declare const draftAnswerViolation: (value: unknown) => string | null;
222
238
  export declare const failureDocument: (reason: ExplorerFailureReason, code?: string) => ExplorerFailureDocument;
223
239
  export declare const failureOf: (reason: ExplorerFailureReason, code?: string) => ExplorerFailure;
224
240
  export type ExplorerSeededDocument = {
@@ -161,6 +161,21 @@ export type ExplorerPreviewAnswer = {
161
161
  readonly htmlContent: string;
162
162
  readonly headings: readonly ExplorerHeading[];
163
163
  } | ExplorerFailureDocument;
164
+ export type ExplorerDraft = {
165
+ readonly path: string;
166
+ readonly text: string;
167
+ };
168
+ export type ExplorerDraftAnswer = {
169
+ readonly kind: "preview";
170
+ readonly htmlContent: string;
171
+ readonly headings: readonly ExplorerHeading[];
172
+ } | ExplorerFailureDocument | {
173
+ readonly kind: "unavailable";
174
+ };
175
+ export type ExplorerDraftConverter = {
176
+ readonly convert: (draft: ExplorerDraft, signal: AbortSignal) => Promise<ExplorerDraftAnswer>;
177
+ readonly prepare?: () => void;
178
+ };
164
179
  export type ExplorerRevision = {
165
180
  readonly id: string;
166
181
  readonly modifiedAt: string | null;
@@ -219,6 +234,7 @@ export declare const isExplorerSaveAnswer: (value: unknown) => value is Explorer
219
234
  export declare const isExplorerPreviewAnswer: (value: unknown) => value is ExplorerPreviewAnswer;
220
235
  export declare const isExplorerRevisionsAnswer: (value: unknown) => value is ExplorerRevisionsAnswer;
221
236
  export declare const isExplorerRevisionAnswer: (value: unknown) => value is ExplorerRevisionAnswer;
237
+ export declare const draftAnswerViolation: (value: unknown) => string | null;
222
238
  export declare const failureDocument: (reason: ExplorerFailureReason, code?: string) => ExplorerFailureDocument;
223
239
  export declare const failureOf: (reason: ExplorerFailureReason, code?: string) => ExplorerFailure;
224
240
  export type ExplorerSeededDocument = {
@@ -0,0 +1 @@
1
+ "use strict";const b=Object.freeze([".env*","*.env","*.env.*","*.env~*","*.env-*","*.env_*","*.env#*",".git",".git-credentials",".svn",".hg","node_modules","secrets",".secrets","secrets.json","secrets.yml","secrets.yaml","secrets.toml","secrets.ini","secrets.txt",".ssh",".aws",".gnupg",".docker",".kube",".terraform",".npmrc",".yarnrc",".yarnrc.yml",".netrc","_netrc",".pypirc",".pgpass",".my.cnf",".htpasswd",".vault-token","id_rsa*","id_dsa*","id_ecdsa*","id_ed25519*","*.pem","*.key","*.p8","*.p12","*.pfx","*.ppk","*.jks","*.keystore","*.kdbx","*credentials*.json","service-account*.json","*.tfstate","*.tfstate.*","*.tfvars","*.tfvars.json",".*_history","fish_history"]),C=/[\u0000-\u001f\u007f]/u,U=/\p{Cs}/u,H=e=>{const t=e.split("/").filter(n=>n!=="").at(-1);return t===void 0?e:t},R=e=>e.length>0&&e.length<=4096&&!U.test(e)&&!C.test(e)&&!e.includes("\\"),x=e=>e.normalize("NFKC").toUpperCase().toLowerCase(),z=/(?:%[0-9A-Fa-f]{2})+/gu,F=new TextDecoder("utf-8"),V=/[/\\]/u,M=e=>e.replace(z,t=>F.decode(Uint8Array.from(t.slice(1).split("%").map(n=>Number.parseInt(n,16))))),G=e=>{const t=[e];let n=e;for(let r=0;r<3&&n.includes("%");r+=1){const o=M(n);if(o===n)break;t.push(o),n=o}return t.map(x)},K=e=>{if(typeof e!="string"||e.trim()===""||e.includes("/")||e.includes("\\"))throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);const t=x(e).split("*").map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${t}$`,"su")},y=e=>{if(!Array.isArray(e))throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");const t=e.map(K),n=o=>o!==""&&t.some(i=>i.test(o)),r=o=>o!==""&&G(o).some(i=>n(i)||i.split(V).some(n));return{deniesPath:o=>o.split("/").some(r),deniesName:r}},Y=y(b),W=Object.freeze({deniesPath:()=>!1,deniesName:()=>!1}),J=e=>e===void 0?Y:e===!1?W:y(e),Q=(e,t)=>y(e).deniesPath(t),m=Object.freeze(["unauthorized","forbidden","not-found","not-configured","invalid","too-large","unsupported","failed"]),q=Object.freeze(["file","directory"]),B=Object.freeze(["video","audio","pdf"]),Z=Object.freeze(["info","warning","danger"]),ee=Object.freeze(["markdown","text","image","media","file","failure"]),O=Object.freeze({min:1,max:6}),te=1e4,c=e=>typeof e=="string"&&/^\/(?![/\\])[\x21-\x7E]*$/u.test(e),ne=Object.freeze(["http:","https:","mailto:"]),_=1024,re=/^[a-z0-9-]{1,64}$/u,oe="https://relative.invalid/",h=64,p=(e,t)=>typeof t=="string"&&e.includes(t),s=e=>typeof e=="string"?JSON.stringify(e.length>h?`${e.slice(0,h)}…`:e):typeof e,T=e=>p(m,e),se=e=>p(q,e),P=e=>p(B,e),ie=e=>p(Z,e),ae=e=>p(ee,e),A=e=>typeof e=="string"&&re.test(e),le=(e,t)=>{if(typeof e!="string")return!1;try{return t.includes(new URL(e,oe).protocol)}catch{return!1}},f=e=>{if(e===null||typeof e!="object")return"a failure must be an object";const{reason:t,code:n}=e;return T(t)?n!==void 0&&!A(n)?`a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${s(n)}`:null:`unknown failure reason ${s(t)}`},S=e=>{if(e===null||typeof e!="object")return"an entry must be an object";const{name:t,path:n,type:r,mimeType:o,modifiedAt:i,children:a,lazy:l}=e;return typeof t!="string"||t===""?"an entry needs a non-empty name":typeof n!="string"||!R(n)?"an entry needs an acceptable path":se(r)?o!==void 0&&typeof o!="string"?"an entry mimeType must be a string":i!==void 0&&!Number.isSafeInteger(i)?`an entry modifiedAt must be a safe integer of epoch milliseconds; got ${s(i)}`:l!==void 0&&typeof l!="boolean"?"an entry lazy flag must be a boolean":a!==void 0&&!Array.isArray(a)?"entry children must be an array":r==="file"&&(a!==void 0||l===!0)?"a file entry cannot have children or be lazy":l===!0&&Array.isArray(a)&&a.length>0?"a lazy directory must not list children":null:`an entry type must be "file" or "directory"; got ${s(r)}`},N=e=>{if(S(e)!==null)return!1;const{children:t}=e;return t===void 0||t.every(N)},L=e=>{if(e===null||typeof e!="object")return!1;const{status:t,entries:n,failure:r}=e;return t==="ok"?Array.isArray(n)&&n.every(N):t==="error"&&f(r)===null},ce=e=>{if(e===null||typeof e!="object")return!1;const{status:t,ancestors:n,failure:r}=e;return t==="ok"?n===null||D(n):t==="error"&&f(r)===null},D=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&R(t))&&new Set(e).size===e.length,ue=e=>{if(e===null||typeof e!="object")return!1;const{status:t,source:n,ancestors:r,failure:o}=e;return t==="ok"?n===null&&r===null||typeof n=="string"&&n!==""&&D(r):t==="error"&&f(o)===null},fe=e=>{if(e===null||typeof e!="object")return!1;const{status:t,loadedAt:n}=e;return t==="ok"&&!(Number.isSafeInteger(n)&&n>=0)?!1:L(e)},g=e=>{if(e===null||typeof e!="object")return"a heading must be an object";const{text:t,depth:n,id:r}=e;return typeof t!="string"||typeof r!="string"?"a heading needs text and id strings":typeof n!="number"||!Number.isInteger(n)||n<O.min||n>O.max?`a heading depth must be an integer in 1..6; got ${String(n)}`:null},v=e=>{if(e===null||typeof e!="object")return"a document must be an object";const t=e,{kind:n}=t;if(!ae(n))return`unknown document kind ${s(n)}`;if(n==="failure")return f(t.failure);if(typeof t.name!="string")return"a document needs a name string";switch(n){case"markdown":{const{htmlContent:r,headings:o}=t;if(typeof r!="string"||!Array.isArray(o))return"a markdown document needs htmlContent and headings";for(const i of o){const a=g(i);if(a!==null)return a}return Ee(t.edit)}case"text":return typeof t.text!="string"||typeof t.truncated!="boolean"?"a text document needs text and truncated":c(t.url)?null:"a text document needs a root-relative url";case"image":return c(t.url)?null:"an image document needs a root-relative url";case"media":return c(t.url)?P(t.mediaType)?null:`unknown media type ${s(t.mediaType)}`:"a media document needs a root-relative url";case"file":return c(t.url)?null:"a file document needs a root-relative url"}},w=e=>v(e)===null,de=e=>w(e)&&(e.kind==="text"||e.kind==="failure"),Ee=e=>{if(e===null)return null;if(typeof e!="object")return"a markdown document's edit must be null or an object";const{kind:t,href:n}=e;return t==="inline"?n===void 0?null:"an inline edit carries no href":t!=="external"?`unknown edit kind ${s(t)}`:pe(n)?null:`an external edit needs an absolute https: href; got ${s(n)}`},pe=e=>{if(typeof e!="string")return!1;try{return new URL(e).protocol==="https:"}catch{return!1}},u=e=>typeof e=="string"&&e.length>0&&e.length<=_,Re=e=>c(e.href)?null:`a grant needs a root-relative href; got ${s(e.href)}`,k=e=>{if(e===null||typeof e!="object")return"a revision must be an object";const{id:t,modifiedAt:n,size:r,author:o,kept:i,current:a}=e;return u(t)?n!==null&&(typeof n!="string"||Number.isNaN(Date.parse(n)))?`a revision's modifiedAt must be a date-time string or null; got ${s(n)}`:typeof r!="number"||!Number.isSafeInteger(r)||r<0?`a revision's size must be a non-negative integer; got ${s(r)}`:o!==null&&typeof o!="string"?`a revision's author must be a string or null; got ${s(o)}`:typeof i!="boolean"||typeof a!="boolean"?"a revision needs kept and current booleans":null:`a revision id must be a non-empty string of at most ${_} characters; got ${s(t)}`},d=(e,t)=>{if(e===null||typeof e!="object")return"an answer must be an object";const n=e,{kind:r}=n;if(r==="failure")return f(n.failure);if(typeof r!="string"||!t.includes(r))return`unexpected answer kind ${s(r)}`;switch(r){case"grant":return Re(n);case"edit":return typeof n.text!="string"||typeof n.history!="boolean"?"an edit source needs text and history":u(n.version)?null:`an edit source needs a version; got ${s(n.version)}`;case"saved":return u(n.version)?null:`a saved answer needs a version; got ${s(n.version)}`;case"conflict":return typeof n.text!="string"?"a conflict needs the current text":u(n.version)?null:`a conflict needs the current version; got ${s(n.version)}`;case"preview":{const{htmlContent:o,headings:i}=n;if(typeof o!="string"||!Array.isArray(i))return"a preview needs htmlContent and headings";for(const a of i){const l=g(a);if(l!==null)return l}return null}case"revisions":{if(!Array.isArray(n.revisions))return"revisions need an array";for(const o of n.revisions){const i=k(o);if(i!==null)return i}return null}case"revision":return typeof n.text!="string"?"a revision answer needs text":u(n.id)?null:`a revision answer needs an id; got ${s(n.id)}`;default:return`unexpected answer kind ${s(r)}`}},ye=Object.freeze(["edit","grant"]),me=Object.freeze(["saved","conflict","grant"]),I=Object.freeze(["preview"]),_e=Object.freeze(["revisions"]),Ae=Object.freeze(["revision"]),ge=e=>d(e,ye)===null,Oe=e=>d(e,me)===null,he=e=>d(e,I)===null,be=e=>d(e,_e)===null,xe=e=>d(e,Ae)===null,Te=e=>e!==null&&typeof e=="object"&&e.kind==="unavailable"?null:d(e,I),Pe=(e,t)=>({kind:"failure",failure:j(e,t)}),j=(e,t)=>A(t)?{reason:e,code:t}:{reason:e},Se=Object.freeze(["tree","children","ancestors","reveal","document","text","edit","save","preview","revisions","revision","refresh","asset","link-card"]),E=Object.freeze({source:"source",path:"path",version:"v",base:"base",revision:"revision",display:"as"}),Ne="asset",Le="link-card",De=(e,t,n)=>{const r=`${e}/${Ne}?${E.path}=${encodeURIComponent(t)}`;return n===null?r:`${r}&${E.version}=${encodeURIComponent(n)}`},$="text",ve=e=>{if(!e.includes("?"))throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);return`${e}&${E.display}=${$}`},we=e=>{const t=e.getAll(E.display);return t.length===0?"file":t.length===1&&t[0]===$?"text":null},ke=e=>`${e}/${Le}`,Ie="X-Markdown-Explorer-Scope",je="X-Markdown-Explorer",$e="refresh",Xe="edit",Ce="text/markdown",Ue=e=>Se.includes(e),X=Object.freeze({invalid:400,unauthorized:401,forbidden:403,"not-found":404,"too-large":413,"not-configured":500,unsupported:500,failed:500}),He=e=>{const[t,...n]=m.filter(r=>X[r]===e);return t!==void 0&&n.length===0?t:"failed"};exports.DEFAULT_DENIED_PATH_SEGMENTS=b;exports.EXPLORER_DATA_QUERY=E;exports.EXPLORER_DRAFT_MEDIA_TYPE=Ce;exports.EXPLORER_EDIT_PROOF=Xe;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_;exports.EXPLORER_FAILURE_REASONS=m;exports.EXPLORER_FAILURE_STATUS=X;exports.EXPLORER_LINK_PROTOCOLS=ne;exports.EXPLORER_MAX_HEADINGS=te;exports.EXPLORER_PROOF_HEADER=je;exports.EXPLORER_REFRESH_PROOF=$e;exports.EXPLORER_SCOPE_HEADER=Ie;exports.MAX_DOCUMENT_PATH_LENGTH=4096;exports.documentViolation=v;exports.draftAnswerViolation=Te;exports.entryViolation=S;exports.explorerAssetHref=De;exports.explorerLinkCardEndpoint=ke;exports.explorerPlainTextHref=ve;exports.failureDocument=Pe;exports.failureOf=j;exports.failureReasonOfStatus=He;exports.failureViolation=f;exports.headingViolation=g;exports.isAcceptableDocumentPath=R;exports.isAcceptableUrl=le;exports.isDeniedPath=Q;exports.isExplorerAncestorsResult=ce;exports.isExplorerChildrenResult=L;exports.isExplorerDataOperation=Ue;exports.isExplorerDocument=w;exports.isExplorerEditAnswer=ge;exports.isExplorerEditToken=u;exports.isExplorerFailureCode=A;exports.isExplorerFailureReason=T;exports.isExplorerMediaType=P;exports.isExplorerNoticeTone=ie;exports.isExplorerPreviewAnswer=he;exports.isExplorerRevealResult=ue;exports.isExplorerRevisionAnswer=xe;exports.isExplorerRevisionsAnswer=be;exports.isExplorerSaveAnswer=Oe;exports.isExplorerTextAnswer=de;exports.isExplorerTreeResult=fe;exports.isRootRelativeUrl=c;exports.lastPathSegment=H;exports.readExplorerAssetDisplay=we;exports.resolvePathRules=J;exports.revisionViolation=k;
@@ -1,5 +1,5 @@
1
1
  const de = 4096;
2
- const N = Object.freeze([
2
+ const v = Object.freeze([
3
3
  ".env*",
4
4
  "*.env",
5
5
  "*.env.*",
@@ -57,81 +57,81 @@ const N = Object.freeze([
57
57
  "*.tfvars.json",
58
58
  ".*_history",
59
59
  "fish_history"
60
- ]), v = /[\u0000-\u001f\u007f]/u, w = /\p{Cs}/u, pe = (e) => {
60
+ ]), w = /[\u0000-\u001f\u007f]/u, P = /\p{Cs}/u, pe = (e) => {
61
61
  const t = e.split("/").filter((n) => n !== "").at(-1);
62
62
  return t === void 0 ? e : t;
63
- }, R = (e) => e.length > 0 && e.length <= 4096 && !w.test(e) && !v.test(e) && !e.includes("\\"), A = (e) => e.normalize("NFKC").toUpperCase().toLowerCase(), P = /(?:%[0-9A-Fa-f]{2})+/gu, L = new TextDecoder("utf-8"), D = /[/\\]/u, k = (e) => e.replace(
64
- P,
65
- (t) => L.decode(
63
+ }, R = (e) => e.length > 0 && e.length <= 4096 && !P.test(e) && !w.test(e) && !e.includes("\\"), A = (e) => e.normalize("NFKC").toUpperCase().toLowerCase(), L = /(?:%[0-9A-Fa-f]{2})+/gu, D = new TextDecoder("utf-8"), k = /[/\\]/u, j = (e) => e.replace(
64
+ L,
65
+ (t) => D.decode(
66
66
  Uint8Array.from(
67
67
  t.slice(1).split("%").map((n) => Number.parseInt(n, 16))
68
68
  )
69
69
  )
70
- ), j = (e) => {
70
+ ), $ = (e) => {
71
71
  const t = [e];
72
72
  let n = e;
73
73
  for (let r = 0; r < 3 && n.includes("%"); r += 1) {
74
- const s = k(n);
74
+ const s = j(n);
75
75
  if (s === n) break;
76
76
  t.push(s), n = s;
77
77
  }
78
78
  return t.map(A);
79
- }, $ = (e) => {
79
+ }, I = (e) => {
80
80
  if (typeof e != "string" || e.trim() === "" || e.includes("/") || e.includes("\\"))
81
81
  throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);
82
82
  const t = A(e).split("*").map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*");
83
83
  return new RegExp(`^${t}$`, "su");
84
84
  }, y = (e) => {
85
85
  if (!Array.isArray(e)) throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");
86
- const t = e.map($), n = (s) => s !== "" && t.some((i) => i.test(s)), r = (s) => s !== "" && j(s).some((i) => n(i) || i.split(D).some(n));
86
+ const t = e.map(I), n = (s) => s !== "" && t.some((i) => i.test(s)), r = (s) => s !== "" && $(s).some((i) => n(i) || i.split(k).some(n));
87
87
  return {
88
88
  deniesPath: (s) => s.split("/").some(r),
89
89
  deniesName: r
90
90
  };
91
- }, I = y(N), C = Object.freeze({ deniesPath: () => !1, deniesName: () => !1 }), Ee = (e) => e === void 0 ? I : e === !1 ? C : y(e), ye = (e, t) => y(e).deniesPath(t), h = Object.freeze(["unauthorized", "forbidden", "not-found", "not-configured", "invalid", "too-large", "unsupported", "failed"]), z = Object.freeze(["file", "directory"]), U = Object.freeze(["video", "audio", "pdf"]), X = Object.freeze(["info", "warning", "danger"]), H = Object.freeze(["markdown", "text", "image", "media", "file", "failure"]), m = Object.freeze({ min: 1, max: 6 }), me = 1e4, l = (e) => typeof e == "string" && /^\/(?![/\\])[\x21-\x7E]*$/u.test(e), ge = Object.freeze(["http:", "https:", "mailto:"]), _ = 1024, F = /^[a-z0-9-]{1,64}$/u, V = "https://relative.invalid/", g = 64, f = (e, t) => typeof t == "string" && e.includes(t), o = (e) => typeof e == "string" ? JSON.stringify(e.length > g ? `${e.slice(0, g)}…` : e) : typeof e, M = (e) => f(h, e), K = (e) => f(z, e), G = (e) => f(U, e), Re = (e) => f(X, e), Y = (e) => f(H, e), b = (e) => typeof e == "string" && F.test(e), Ae = (e, t) => {
91
+ }, C = y(v), z = Object.freeze({ deniesPath: () => !1, deniesName: () => !1 }), Ee = (e) => e === void 0 ? C : e === !1 ? z : y(e), ye = (e, t) => y(e).deniesPath(t), b = Object.freeze(["unauthorized", "forbidden", "not-found", "not-configured", "invalid", "too-large", "unsupported", "failed"]), U = Object.freeze(["file", "directory"]), X = Object.freeze(["video", "audio", "pdf"]), H = Object.freeze(["info", "warning", "danger"]), V = Object.freeze(["markdown", "text", "image", "media", "file", "failure"]), m = Object.freeze({ min: 1, max: 6 }), me = 1e4, u = (e) => typeof e == "string" && /^\/(?![/\\])[\x21-\x7E]*$/u.test(e), ge = Object.freeze(["http:", "https:", "mailto:"]), h = 1024, F = /^[a-z0-9-]{1,64}$/u, M = "https://relative.invalid/", g = 64, d = (e, t) => typeof t == "string" && e.includes(t), o = (e) => typeof e == "string" ? JSON.stringify(e.length > g ? `${e.slice(0, g)}…` : e) : typeof e, K = (e) => d(b, e), G = (e) => d(U, e), W = (e) => d(X, e), Re = (e) => d(H, e), Y = (e) => d(V, e), _ = (e) => typeof e == "string" && F.test(e), Ae = (e, t) => {
92
92
  if (typeof e != "string") return !1;
93
93
  try {
94
- return t.includes(new URL(e, V).protocol);
94
+ return t.includes(new URL(e, M).protocol);
95
95
  } catch {
96
96
  return !1;
97
97
  }
98
- }, d = (e) => {
98
+ }, p = (e) => {
99
99
  if (e === null || typeof e != "object") return "a failure must be an object";
100
100
  const { reason: t, code: n } = e;
101
- return M(t) ? n !== void 0 && !b(n) ? `a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${o(n)}` : null : `unknown failure reason ${o(t)}`;
102
- }, W = (e) => {
101
+ return K(t) ? n !== void 0 && !_(n) ? `a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${o(n)}` : null : `unknown failure reason ${o(t)}`;
102
+ }, J = (e) => {
103
103
  if (e === null || typeof e != "object") return "an entry must be an object";
104
104
  const { name: t, path: n, type: r, mimeType: s, modifiedAt: i, children: a, lazy: c } = e;
105
- return typeof t != "string" || t === "" ? "an entry needs a non-empty name" : typeof n != "string" || !R(n) ? "an entry needs an acceptable path" : K(r) ? s !== void 0 && typeof s != "string" ? "an entry mimeType must be a string" : i !== void 0 && !Number.isSafeInteger(i) ? `an entry modifiedAt must be a safe integer of epoch milliseconds; got ${o(i)}` : c !== void 0 && typeof c != "boolean" ? "an entry lazy flag must be a boolean" : a !== void 0 && !Array.isArray(a) ? "entry children must be an array" : r === "file" && (a !== void 0 || c === !0) ? "a file entry cannot have children or be lazy" : c === !0 && Array.isArray(a) && a.length > 0 ? "a lazy directory must not list children" : null : `an entry type must be "file" or "directory"; got ${o(r)}`;
105
+ return typeof t != "string" || t === "" ? "an entry needs a non-empty name" : typeof n != "string" || !R(n) ? "an entry needs an acceptable path" : G(r) ? s !== void 0 && typeof s != "string" ? "an entry mimeType must be a string" : i !== void 0 && !Number.isSafeInteger(i) ? `an entry modifiedAt must be a safe integer of epoch milliseconds; got ${o(i)}` : c !== void 0 && typeof c != "boolean" ? "an entry lazy flag must be a boolean" : a !== void 0 && !Array.isArray(a) ? "entry children must be an array" : r === "file" && (a !== void 0 || c === !0) ? "a file entry cannot have children or be lazy" : c === !0 && Array.isArray(a) && a.length > 0 ? "a lazy directory must not list children" : null : `an entry type must be "file" or "directory"; got ${o(r)}`;
106
106
  }, O = (e) => {
107
- if (W(e) !== null) return !1;
107
+ if (J(e) !== null) return !1;
108
108
  const { children: t } = e;
109
109
  return t === void 0 || t.every(O);
110
- }, J = (e) => {
110
+ }, q = (e) => {
111
111
  if (e === null || typeof e != "object") return !1;
112
112
  const { status: t, entries: n, failure: r } = e;
113
- return t === "ok" ? Array.isArray(n) && n.every(O) : t === "error" && d(r) === null;
114
- }, he = (e) => {
113
+ return t === "ok" ? Array.isArray(n) && n.every(O) : t === "error" && p(r) === null;
114
+ }, be = (e) => {
115
115
  if (e === null || typeof e != "object") return !1;
116
116
  const { status: t, ancestors: n, failure: r } = e;
117
- return t === "ok" ? n === null || x(n) : t === "error" && d(r) === null;
118
- }, x = (e) => Array.isArray(e) && e.every((t) => typeof t == "string" && R(t)) && new Set(e).size === e.length, _e = (e) => {
117
+ return t === "ok" ? n === null || x(n) : t === "error" && p(r) === null;
118
+ }, x = (e) => Array.isArray(e) && e.every((t) => typeof t == "string" && R(t)) && new Set(e).size === e.length, he = (e) => {
119
119
  if (e === null || typeof e != "object") return !1;
120
120
  const { status: t, source: n, ancestors: r, failure: s } = e;
121
- return t === "ok" ? n === null && r === null || typeof n == "string" && n !== "" && x(r) : t === "error" && d(s) === null;
122
- }, be = (e) => {
121
+ return t === "ok" ? n === null && r === null || typeof n == "string" && n !== "" && x(r) : t === "error" && p(s) === null;
122
+ }, _e = (e) => {
123
123
  if (e === null || typeof e != "object") return !1;
124
124
  const { status: t, loadedAt: n } = e;
125
- return t === "ok" && !(Number.isSafeInteger(n) && n >= 0) ? !1 : J(e);
125
+ return t === "ok" && !(Number.isSafeInteger(n) && n >= 0) ? !1 : q(e);
126
126
  }, T = (e) => {
127
127
  if (e === null || typeof e != "object") return "a heading must be an object";
128
128
  const { text: t, depth: n, id: r } = e;
129
129
  return typeof t != "string" || typeof r != "string" ? "a heading needs text and id strings" : typeof n != "number" || !Number.isInteger(n) || n < m.min || n > m.max ? `a heading depth must be an integer in 1..6; got ${String(n)}` : null;
130
- }, q = (e) => {
130
+ }, B = (e) => {
131
131
  if (e === null || typeof e != "object") return "a document must be an object";
132
132
  const t = e, { kind: n } = t;
133
133
  if (!Y(n)) return `unknown document kind ${o(n)}`;
134
- if (n === "failure") return d(t.failure);
134
+ if (n === "failure") return p(t.failure);
135
135
  if (typeof t.name != "string") return "a document needs a name string";
136
136
  switch (n) {
137
137
  case "markdown": {
@@ -141,47 +141,47 @@ const N = Object.freeze([
141
141
  const a = T(i);
142
142
  if (a !== null) return a;
143
143
  }
144
- return Q(t.edit);
144
+ return Z(t.edit);
145
145
  }
146
146
  case "text":
147
- return typeof t.text != "string" || typeof t.truncated != "boolean" ? "a text document needs text and truncated" : l(t.url) ? null : "a text document needs a root-relative url";
147
+ return typeof t.text != "string" || typeof t.truncated != "boolean" ? "a text document needs text and truncated" : u(t.url) ? null : "a text document needs a root-relative url";
148
148
  case "image":
149
- return l(t.url) ? null : "an image document needs a root-relative url";
149
+ return u(t.url) ? null : "an image document needs a root-relative url";
150
150
  case "media":
151
- return l(t.url) ? G(t.mediaType) ? null : `unknown media type ${o(t.mediaType)}` : "a media document needs a root-relative url";
151
+ return u(t.url) ? W(t.mediaType) ? null : `unknown media type ${o(t.mediaType)}` : "a media document needs a root-relative url";
152
152
  case "file":
153
- return l(t.url) ? null : "a file document needs a root-relative url";
153
+ return u(t.url) ? null : "a file document needs a root-relative url";
154
154
  }
155
- }, B = (e) => q(e) === null, Oe = (e) => B(e) && (e.kind === "text" || e.kind === "failure"), Q = (e) => {
155
+ }, Q = (e) => B(e) === null, Oe = (e) => Q(e) && (e.kind === "text" || e.kind === "failure"), Z = (e) => {
156
156
  if (e === null) return null;
157
157
  if (typeof e != "object") return "a markdown document's edit must be null or an object";
158
158
  const { kind: t, href: n } = e;
159
- return t === "inline" ? n === void 0 ? null : "an inline edit carries no href" : t !== "external" ? `unknown edit kind ${o(t)}` : Z(n) ? null : `an external edit needs an absolute https: href; got ${o(n)}`;
160
- }, Z = (e) => {
159
+ return t === "inline" ? n === void 0 ? null : "an inline edit carries no href" : t !== "external" ? `unknown edit kind ${o(t)}` : ee(n) ? null : `an external edit needs an absolute https: href; got ${o(n)}`;
160
+ }, ee = (e) => {
161
161
  if (typeof e != "string") return !1;
162
162
  try {
163
163
  return new URL(e).protocol === "https:";
164
164
  } catch {
165
165
  return !1;
166
166
  }
167
- }, u = (e) => typeof e == "string" && e.length > 0 && e.length <= _, ee = (e) => l(e.href) ? null : `a grant needs a root-relative href; got ${o(e.href)}`, te = (e) => {
167
+ }, f = (e) => typeof e == "string" && e.length > 0 && e.length <= h, te = (e) => u(e.href) ? null : `a grant needs a root-relative href; got ${o(e.href)}`, ne = (e) => {
168
168
  if (e === null || typeof e != "object") return "a revision must be an object";
169
169
  const { id: t, modifiedAt: n, size: r, author: s, kept: i, current: a } = e;
170
- return u(t) ? n !== null && (typeof n != "string" || Number.isNaN(Date.parse(n))) ? `a revision's modifiedAt must be a date-time string or null; got ${o(n)}` : typeof r != "number" || !Number.isSafeInteger(r) || r < 0 ? `a revision's size must be a non-negative integer; got ${o(r)}` : s !== null && typeof s != "string" ? `a revision's author must be a string or null; got ${o(s)}` : typeof i != "boolean" || typeof a != "boolean" ? "a revision needs kept and current booleans" : null : `a revision id must be a non-empty string of at most ${_} characters; got ${o(t)}`;
171
- }, p = (e, t) => {
170
+ return f(t) ? n !== null && (typeof n != "string" || Number.isNaN(Date.parse(n))) ? `a revision's modifiedAt must be a date-time string or null; got ${o(n)}` : typeof r != "number" || !Number.isSafeInteger(r) || r < 0 ? `a revision's size must be a non-negative integer; got ${o(r)}` : s !== null && typeof s != "string" ? `a revision's author must be a string or null; got ${o(s)}` : typeof i != "boolean" || typeof a != "boolean" ? "a revision needs kept and current booleans" : null : `a revision id must be a non-empty string of at most ${h} characters; got ${o(t)}`;
171
+ }, l = (e, t) => {
172
172
  if (e === null || typeof e != "object") return "an answer must be an object";
173
173
  const n = e, { kind: r } = n;
174
- if (r === "failure") return d(n.failure);
174
+ if (r === "failure") return p(n.failure);
175
175
  if (typeof r != "string" || !t.includes(r)) return `unexpected answer kind ${o(r)}`;
176
176
  switch (r) {
177
177
  case "grant":
178
- return ee(n);
178
+ return te(n);
179
179
  case "edit":
180
- return typeof n.text != "string" || typeof n.history != "boolean" ? "an edit source needs text and history" : u(n.version) ? null : `an edit source needs a version; got ${o(n.version)}`;
180
+ return typeof n.text != "string" || typeof n.history != "boolean" ? "an edit source needs text and history" : f(n.version) ? null : `an edit source needs a version; got ${o(n.version)}`;
181
181
  case "saved":
182
- return u(n.version) ? null : `a saved answer needs a version; got ${o(n.version)}`;
182
+ return f(n.version) ? null : `a saved answer needs a version; got ${o(n.version)}`;
183
183
  case "conflict":
184
- return typeof n.text != "string" ? "a conflict needs the current text" : u(n.version) ? null : `a conflict needs the current version; got ${o(n.version)}`;
184
+ return typeof n.text != "string" ? "a conflict needs the current text" : f(n.version) ? null : `a conflict needs the current version; got ${o(n.version)}`;
185
185
  case "preview": {
186
186
  const { htmlContent: s, headings: i } = n;
187
187
  if (typeof s != "string" || !Array.isArray(i)) return "a preview needs htmlContent and headings";
@@ -194,26 +194,26 @@ const N = Object.freeze([
194
194
  case "revisions": {
195
195
  if (!Array.isArray(n.revisions)) return "revisions need an array";
196
196
  for (const s of n.revisions) {
197
- const i = te(s);
197
+ const i = ne(s);
198
198
  if (i !== null) return i;
199
199
  }
200
200
  return null;
201
201
  }
202
202
  case "revision":
203
- return typeof n.text != "string" ? "a revision answer needs text" : u(n.id) ? null : `a revision answer needs an id; got ${o(n.id)}`;
203
+ return typeof n.text != "string" ? "a revision answer needs text" : f(n.id) ? null : `a revision answer needs an id; got ${o(n.id)}`;
204
204
  default:
205
205
  return `unexpected answer kind ${o(r)}`;
206
206
  }
207
- }, ne = Object.freeze(["edit", "grant"]), re = Object.freeze(["saved", "conflict", "grant"]), se = Object.freeze(["preview"]), oe = Object.freeze(["revisions"]), ie = Object.freeze(["revision"]), xe = (e) => p(e, ne) === null, Te = (e) => p(e, re) === null, Se = (e) => p(e, se) === null, Ne = (e) => p(e, oe) === null, ve = (e) => p(e, ie) === null, we = (e, t) => ({ kind: "failure", failure: ae(e, t) }), ae = (e, t) => b(t) ? { reason: e, code: t } : { reason: e }, ce = Object.freeze(["tree", "children", "ancestors", "reveal", "document", "text", "edit", "save", "preview", "revisions", "revision", "refresh", "asset", "link-card"]), E = Object.freeze({ source: "source", path: "path", version: "v", base: "base", revision: "revision", display: "as" }), le = "asset", ue = "link-card", Pe = (e, t, n) => {
207
+ }, re = Object.freeze(["edit", "grant"]), se = Object.freeze(["saved", "conflict", "grant"]), S = Object.freeze(["preview"]), oe = Object.freeze(["revisions"]), ie = Object.freeze(["revision"]), xe = (e) => l(e, re) === null, Te = (e) => l(e, se) === null, Se = (e) => l(e, S) === null, Ne = (e) => l(e, oe) === null, ve = (e) => l(e, ie) === null, we = (e) => e !== null && typeof e == "object" && e.kind === "unavailable" ? null : l(e, S), Pe = (e, t) => ({ kind: "failure", failure: ae(e, t) }), ae = (e, t) => _(t) ? { reason: e, code: t } : { reason: e }, ce = Object.freeze(["tree", "children", "ancestors", "reveal", "document", "text", "edit", "save", "preview", "revisions", "revision", "refresh", "asset", "link-card"]), E = Object.freeze({ source: "source", path: "path", version: "v", base: "base", revision: "revision", display: "as" }), le = "asset", ue = "link-card", Le = (e, t, n) => {
208
208
  const r = `${e}/${le}?${E.path}=${encodeURIComponent(t)}`;
209
209
  return n === null ? r : `${r}&${E.version}=${encodeURIComponent(n)}`;
210
- }, S = "text", Le = (e) => {
210
+ }, N = "text", De = (e) => {
211
211
  if (!e.includes("?")) throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);
212
- return `${e}&${E.display}=${S}`;
213
- }, De = (e) => {
212
+ return `${e}&${E.display}=${N}`;
213
+ }, ke = (e) => {
214
214
  const t = e.getAll(E.display);
215
- return t.length === 0 ? "file" : t.length === 1 && t[0] === S ? "text" : null;
216
- }, ke = (e) => `${e}/${ue}`, je = "X-Markdown-Explorer-Scope", $e = "X-Markdown-Explorer", Ie = "refresh", Ce = "edit", ze = "text/markdown", Ue = (e) => ce.includes(e), fe = Object.freeze({
215
+ return t.length === 0 ? "file" : t.length === 1 && t[0] === N ? "text" : null;
216
+ }, je = (e) => `${e}/${ue}`, $e = "X-Markdown-Explorer-Scope", Ie = "X-Markdown-Explorer", Ce = "refresh", ze = "edit", Ue = "text/markdown", Xe = (e) => ce.includes(e), fe = Object.freeze({
217
217
  invalid: 400,
218
218
  unauthorized: 401,
219
219
  forbidden: 403,
@@ -222,57 +222,58 @@ const N = Object.freeze([
222
222
  "not-configured": 500,
223
223
  unsupported: 500,
224
224
  failed: 500
225
- }), Xe = (e) => {
226
- const [t, ...n] = h.filter((r) => fe[r] === e);
225
+ }), He = (e) => {
226
+ const [t, ...n] = b.filter((r) => fe[r] === e);
227
227
  return t !== void 0 && n.length === 0 ? t : "failed";
228
228
  };
229
229
  export {
230
- ze as A,
231
- ye as B,
232
- pe as C,
233
- N as D,
230
+ ke as A,
231
+ Ue as B,
232
+ ye as C,
233
+ v as D,
234
234
  me as E,
235
- Le as F,
236
- Xe as G,
237
- Oe as H,
238
- _e as I,
235
+ pe as F,
236
+ De as G,
237
+ He as H,
238
+ Oe as I,
239
239
  he as J,
240
- J as K,
241
- d as L,
240
+ be as K,
241
+ q as L,
242
242
  de as M,
243
- be as N,
244
- ve as O,
245
- Ne as P,
246
- Se as Q,
247
- Te as R,
248
- xe as S,
249
- B as T,
250
- _ as U,
243
+ p as N,
244
+ _e as O,
245
+ ve as P,
246
+ Ne as Q,
247
+ Se as R,
248
+ Te as S,
249
+ xe as T,
250
+ Q as U,
251
251
  h as V,
252
- ke as a,
253
- M as b,
254
- b as c,
255
- Re as d,
256
- Pe as e,
252
+ b as W,
253
+ je as a,
254
+ K as b,
255
+ _ as c,
256
+ we as d,
257
+ Le as e,
257
258
  ae as f,
258
- Ae as g,
259
- G as h,
259
+ Re as g,
260
+ Ae as h,
260
261
  R as i,
261
- q as j,
262
- u as k,
263
- T as l,
264
- l as m,
265
- W as n,
266
- ge as o,
267
- Ee as p,
268
- Ue as q,
269
- te as r,
270
- fe as s,
271
- $e as t,
262
+ W as j,
263
+ B as k,
264
+ f as l,
265
+ T as m,
266
+ u as n,
267
+ J as o,
268
+ ge as p,
269
+ Ee as q,
270
+ ne as r,
271
+ Xe as s,
272
+ fe as t,
272
273
  Ie as u,
273
274
  Ce as v,
274
- je as w,
275
- E as x,
276
- we as y,
277
- De as z
275
+ ze as w,
276
+ $e as x,
277
+ E as y,
278
+ Pe as z
278
279
  };