@aiquants/markdown-explorer 0.9.0 → 0.10.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +4 -2
  3. package/dist/{EditSurface-DJ9pJlDd.js → EditSurface-1Jf0CG-f.js} +1 -1
  4. package/dist/{EditSurface-BQ5QAdDd.cjs → EditSurface-B-l3Do_C.cjs} +1 -1
  5. package/dist/{ExplorerSplit-BwUurHbM.js → ExplorerSplit-D0zf7Cr_.js} +2 -2
  6. package/dist/{ExplorerSplit-Brdh9fCW.cjs → ExplorerSplit-WX8afxrQ.cjs} +1 -1
  7. package/dist/{MultiLayout-xWd9nYaD.cjs → MultiLayout-Bq10p3a3.cjs} +1 -1
  8. package/dist/{MultiLayout-DPE2GP2T.js → MultiLayout-Jy9BKofx.js} +4 -4
  9. package/dist/{NativeScrollBar-CwgalDjg.js → NativeScrollBar-CyiyL47o.js} +1 -1
  10. package/dist/{NativeScrollBar-PBnODPEM.cjs → NativeScrollBar-Dt6xH5Mb.cjs} +1 -1
  11. package/dist/{TreeLayout-B3i_63hs.js → TreeLayout-8pRo1ANN.js} +3 -3
  12. package/dist/{TreeLayout-DilrAILF.cjs → TreeLayout-kVWFEKJD.cjs} +1 -1
  13. package/dist/dataRoute-8pyILcjL.cjs +1 -0
  14. package/dist/dataRoute-Csl1WBDz.js +278 -0
  15. package/dist/{index-CPoNWk1T.js → index-CfcJEnrC.js} +384 -384
  16. package/dist/index-sNJrKoGN.cjs +13 -0
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.js +14 -14
  19. package/dist/{location-DmzVAFvo.cjs → location-CRYkEWiC.cjs} +1 -1
  20. package/dist/{location-Q4sgRrUm.js → location-Dc1qNEGm.js} +1 -1
  21. package/dist/{merge-DgAmnpnO.cjs → merge-D0aGvFKC.cjs} +1 -1
  22. package/dist/{merge-D_qmtwWR.js → merge-SRCxtHk2.js} +1 -1
  23. package/dist/sanitizeWorker.cjs +1 -1
  24. package/dist/sanitizeWorker.js +1 -1
  25. package/dist/server.cjs +1 -1
  26. package/dist/server.js +632 -621
  27. package/docs/behavior/dom-hooks.md +1 -1
  28. package/docs/behavior/layout.md +2 -2
  29. package/docs/behavior/security.md +2 -1
  30. package/docs/behavior/url-contract.md +1 -0
  31. package/package.json +1 -1
  32. package/dist/dataRoute-CcZ8PK00.cjs +0 -1
  33. package/dist/dataRoute-D1vE1wFW.js +0 -270
  34. package/dist/index-BBtIYTXJ.cjs +0 -13
@@ -85,7 +85,7 @@ The tree is named by `treeRegion`, apart from the explorer `nav` (`explorerRegio
85
85
  | `data-testid="markdown-explorer-image"` | The image (`img`) | Carries `data-aqmx-image-mode` (`fit` / `level`) |
86
86
  | `data-testid="markdown-explorer-image-level"` | The zoom level (an `output`) | A polite status: assistive technology reads the new level when it changes |
87
87
  | `data-testid="markdown-explorer-media-view"` / `-media-player` | Media viewer and its player | The view carries `data-aqmx-media-type` (`video` / `audio` / `pdf`) |
88
- | `data-testid="markdown-explorer-file-name"` / `-file-open` / `-file-download` | Header of an image, media, text or file view | |
88
+ | `data-testid="markdown-explorer-file-name"` / `-file-open` / `-file-download` | Header of an image, media, text or file view | A text view's `-file-open` leads to the file as plain text (`as=text`); every other link is the asset URL itself. |
89
89
  | `data-testid="markdown-explorer-file-copy"` | Copy the text, in the header of a text read whole (a text file, or a Markdown document shown as written) | Carries `data-aqmx-copy-outcome`: `idle`, then `copied` or `failed` for 2 seconds after a press. Absent when only the file's beginning was read. |
90
90
  | `data-testid="markdown-explorer-file-view"` | The view of a file the explorer cannot show (a `file` document) | Holds the file header and the note below. |
91
91
  | `data-testid="markdown-explorer-file-not-shown"` / `-file-not-shown-download` | The file view's note (`role="note"`, the label `fileNotShown`) and its download link | The link's `href` is the document's `url` and its `download` the file's name. |
@@ -128,7 +128,7 @@ Documents in the multi-panel view sit in `multiView.columns` logical columns (4
128
128
  A Mermaid gantt chart is drawn at the width of its slot (and again, after a short debounce, when a split or the window changes that width), so it keeps its natural height.
129
129
  Where the toolbar covers the inline extent of the document's content — in the tree view and a maximized panel at every width, where the content spans the pane, and in the single view unless its `width` or `maxWidth` leaves room beside the content — the viewer reserves the depth it covers as the top padding and the `scroll-padding-block-start` of its scroll container and publishes it as `--aqmd-toolbar-block-overlap` on `[data-aqmd-scroll-container]`: the first line and every fragment's element start below the buttons. Where the toolbar covers none of the content the band is `0px`.
130
130
  An open, unpinned menu of the toolbar (the table of contents, the style or the alignment menu) closes on Escape while the focus is inside it and returns the focus to its button; the viewer marks that keydown handled (`preventDefault()`). In a panel every part of the document (failure callout, image, media) takes its content height, and an embedded PDF is 1 : √2.
131
- - A file header (the toolbar of an image, a medium or a text: its name, the zoom controls or Copy the text, Open in a new tab and Download) wraps its controls onto more lines instead of letting any of them run out of the pane or the panel at a narrow width or a large text size; the name takes what the controls leave on the first line and is cut with an ellipsis.
131
+ - A file header (the toolbar of an image, a medium or a text: its name, the zoom controls or Copy the text, Open in a new tab — for a text, the whole file as UTF-8 plain text, which a browser shows instead of downloading — and Download) wraps its controls onto more lines instead of letting any of them run out of the pane or the panel at a narrow width or a large text size; the name takes what the controls leave on the first line and is cut with an ellipsis.
132
132
  - An image opens fitted to the pane (Fit pressed). Zoom in and Zoom out step through the levels 1/φ², 1/φ, 1, φ and φ² (≈ 38.2 %, 61.8 %, 100 %, 161.8 % and 261.8 %) of a base size — the image's natural size, or for an image without one the fitted size described below — and the level shown is a percentage of that base; from the fitted size they go to the nearest level above or below it. A zoom button that cannot act stays focusable: before the image is measured, at the ends of the levels, and — while an image with a natural size is fitted — Zoom out when the fitted size is already at or below the smallest level, it is `aria-disabled`, dims its icon and ignores activation. While such an image is fitted, Zoom out's availability follows the pane's size: a pane that grows or shrinks can make it available or unavailable.
133
133
  An image without a natural size (an SVG whose root has no absolute `width` and `height`, such as one with only a `viewBox` or with `width="100%"`) is recognized when the browser reports a natural width or height of 0 for it, or when Fit enlarges it, which Fit never does to an image that has one. Its levels are relative to its fitted size instead: the size it was fitted to when the reader leaves Fit, kept until Fit is pressed again. From Fit, Zoom in goes to φ and Zoom out to 1/φ of that size, and the level shown is a percentage of it.
134
134
  Chromium reports the default object size (300 × 150, fitted to the SVG's aspect ratio) as such an SVG's natural size, so in a pane narrower than that size Fit does not enlarge it, and its levels stay relative to that default size (see the README's known limitations).
@@ -141,7 +141,7 @@ Documents in the multi-panel view sit in `multiView.columns` logical columns (4
141
141
  So does focus in a frame inside the region (a PDF document's frame, an embedded frame of `iframeHosts`), also when it entered the frame straight from outside the region (a click from the tree, Tab), and a press outside the region moves it away from there as well.
142
142
  - **Source of a Markdown document.** While the bar's document is a loaded Markdown document, the bar's button row holds a Source toggle before Refresh document: a toggle button (`aria-pressed`) labelled like its neighbour — visible text beside a page view's pane (`showMarkupLabel`, «Source» / 「ソース」, its accessible name; its tooltip is `showMarkup`), icon-only in a panel and named after the panel's document (`showMarkupNamed`, «Source of a.md» / 「a.md のソース」).
143
143
  An image, media, text or file document and a failure show no toggle, and neither does a document still loading, which gets it once it is there.
144
- Pressing it shows the document as written instead of rendered, in place and without moving the focus from the toggle: the pane reads the document's file through the data route's `text` operation (only once the toggle is pressed) and shows the text the way it shows a text file — the file header with Copy the text, Open and Download, the note `textTruncated` when the server cut the file at its `textMaxBytes`, and the text, which wraps and is never interpreted.
144
+ Pressing it shows the document as written instead of rendered, in place and without moving the focus from the toggle: the pane reads the document's file through the data route's `text` operation (only once the toggle is pressed) and shows the text the way it shows a text file — the file header with Copy the text, Open (the whole file as plain text in a new tab) and Download, the note `textTruncated` when the server cut the file at its `textMaxBytes`, and the text, which wraps and is never interpreted.
145
145
  Copy the text (an icon button, `copyText`) puts the text on the clipboard exactly as read, line endings included, and is offered only for a text read whole, so a cut file is never copied in part (Download fetches it whole). The outcome is announced (`copiedText`, or `copyTextFailed` when the browser has no asynchronous clipboard — an insecure origin — or refuses the write) and shown for 2 seconds by the button's icon and tooltip, while its accessible name stays the same; a second press counts the 2 seconds again. The same button heads every text file.
146
146
  Until the first answer the region shows a skeleton (`markupLoading` for screen readers); a failure shows the failure callout, with Try again for a `failed` read, and is announced once (`documentFailed`), like a document's.
147
147
  Every new answer for the document — Refresh document, Refresh tree, a background revalidation — reads the text again, the previous text staying on screen meanwhile. The next press shows the document rendered again.
@@ -164,6 +164,7 @@ In a tree or children listing, an entry with an empty name, or with a path the b
164
164
  ## What the explorer serves
165
165
 
166
166
  - Any regular file the document admission admits, whatever its kind: the bytes of image and media documents, the whole file behind a text preview, every `file` document (a file the explorer cannot show) and every image embedded in Markdown.
167
- - Inline only for raster images, audio, video and PDF; everything else, SVG and an empty or unknown type included, as an attachment. Both dispositions name the file (`filename*=UTF-8''<name>`, the RFC 8187 encoding of the name with `'`, `(`, `)` and `*` percent-encoded too), so a saved file keeps its name although every asset URL's path ends in `asset`.
167
+ - Inline only for raster images, audio, video and PDF; everything else, SVG and an empty or unknown type included, as an attachment — unless the request asks for the plain-text display (`as=text`, the text viewers' Open in a new tab), which shows any admitted file in place as `text/plain; charset=utf-8` whatever its declared type,
168
+ under the same `nosniff` and sandboxing policy, so an HTML or SVG file opened that way shows its source and runs nothing. Both dispositions name the file (`filename*=UTF-8''<name>`, the RFC 8187 encoding of the name with `'`, `(`, `)` and `*` percent-encoded too), so a saved file keeps its name although every asset URL's path ends in `asset`.
168
169
  - The type is the one the host declares, parsed as a browser parses it, never guessed from the name; `nosniff` stops the browser from guessing either, and the sandboxing policy keeps an SVG or HTML file opened on its own from running script.
169
170
  - For `createFileSystemSource`, files of unknown extensions are downloadable, and so are the whole bytes of every Markdown and text file the source admits: raw Markdown keeps what the rendered view drops (front matter, HTML comments), and a text file is served beyond its preview. Its deny rules — `DEFAULT_DENIED_PATH_SEGMENTS` (environment files, keys and certificates, credential files, Terraform state, shell histories) plus the host's `deny` patterns — are the only filter, so add a pattern for anything else the folder must withhold.
@@ -92,6 +92,7 @@ The explorer serves every file it shows or offers for download through the `asse
92
92
  | Path | `<dataPath>/asset`. GET and HEAD only; any other method answers 405 with `Allow: GET, HEAD`. |
93
93
  | `path` | Required exactly once: the document path exactly as the explorer shows it (workspace-relative, `gcs://bucket/object`, `gdrive://…`), an acceptable document path; otherwise 400. `filePath` is not a parameter (`?filePath=` alone answers 400). |
94
94
  | `v` | Written only on the URL a document carries (image, media, text and file documents), from the version the host reported: a cache-buster the server never reads. The response's ETag is always the file's current version. |
95
+ | `as` | Optional: `text` (exactly once) asks for the file as UTF-8 plain text shown in place (`text/plain; charset=utf-8`, `inline`), whatever type the host declares; any other value, an empty one or the parameter repeated answers 400 before the port is called. `explorerPlainTextHref(assetHref)` adds it to a text document's `url` for the text viewers' Open in a new tab. |
95
96
  | Encoding | `encodeURIComponent` once, decoded once by `URLSearchParams`: exact for `%`, `#`, `?`, `+`, spaces, NFC and NFD names and a trailing `.data`. The request's own path always ends in `asset`, never in `.data`, so no name needs another escape. |
96
97
 
97
98
  Two writers call it: the copy of the host's `document` answer, for the `url` of image, media, text and file documents (with `v`), and the sanitizer, for images marked with `data-asset-src` (without `v`). With `dataPath` `/docs/_data`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiquants/markdown-explorer",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Markdown document explorer for React Router 8 (framework mode): a source tree with a single-document view and a multi-panel reading view, storage-agnostic server ports, golden-ratio layout and an en / ja UI.",
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -1 +0,0 @@
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,X=/\p{Cs}/u,$=e=>{const n=e.split("/").filter(t=>t!=="").at(-1);return n===void 0?e:n},p=e=>e.length>0&&e.length<=4096&&!X.test(e)&&!C.test(e)&&!e.includes("\\"),T=e=>e.normalize("NFKC").toUpperCase().toLowerCase(),U=/(?:%[0-9A-Fa-f]{2})+/gu,H=new TextDecoder("utf-8"),z=/[/\\]/u,F=e=>e.replace(U,n=>H.decode(Uint8Array.from(n.slice(1).split("%").map(t=>Number.parseInt(t,16))))),M=e=>{const n=[e];let t=e;for(let r=0;r<3&&t.includes("%");r+=1){const o=F(t);if(o===t)break;n.push(o),t=o}return n.map(T)},V=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 n=T(e).split("*").map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${n}$`,"su")},R=e=>{if(!Array.isArray(e))throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");const n=e.map(V),t=o=>o!==""&&n.some(s=>s.test(o)),r=o=>o!==""&&M(o).some(s=>t(s)||s.split(z).some(t));return{deniesPath:o=>o.split("/").some(r),deniesName:r}},G=R(b),K=Object.freeze({deniesPath:()=>!1,deniesName:()=>!1}),Y=e=>e===void 0?G:e===!1?K:R(e),W=(e,n)=>R(e).deniesPath(n),y=Object.freeze(["unauthorized","forbidden","not-found","not-configured","invalid","too-large","unsupported","failed"]),J=Object.freeze(["file","directory"]),Q=Object.freeze(["video","audio","pdf"]),B=Object.freeze(["info","warning","danger"]),q=Object.freeze(["markdown","text","image","media","file","failure"]),O=Object.freeze({min:1,max:6}),Z=1e4,l=e=>typeof e=="string"&&/^\/(?![/\\])[\x21-\x7E]*$/u.test(e),ee=Object.freeze(["http:","https:","mailto:"]),_=1024,te=/^[a-z0-9-]{1,64}$/u,ne="https://relative.invalid/",h=64,f=(e,n)=>typeof n=="string"&&e.includes(n),i=e=>typeof e=="string"?JSON.stringify(e.length>h?`${e.slice(0,h)}…`:e):typeof e,x=e=>f(y,e),re=e=>f(J,e),P=e=>f(Q,e),oe=e=>f(B,e),se=e=>f(q,e),m=e=>typeof e=="string"&&te.test(e),ie=(e,n)=>{if(typeof e!="string")return!1;try{return n.includes(new URL(e,ne).protocol)}catch{return!1}},u=e=>{if(e===null||typeof e!="object")return"a failure must be an object";const{reason:n,code:t}=e;return x(n)?t!==void 0&&!m(t)?`a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${i(t)}`:null:`unknown failure reason ${i(n)}`},S=e=>{if(e===null||typeof e!="object")return"an entry must be an object";const{name:n,path:t,type:r,mimeType:o,children:s,lazy:a}=e;return typeof n!="string"||n===""?"an entry needs a non-empty name":typeof t!="string"||!p(t)?"an entry needs an acceptable path":re(r)?o!==void 0&&typeof o!="string"?"an entry mimeType must be a string":a!==void 0&&typeof a!="boolean"?"an entry lazy flag must be a boolean":s!==void 0&&!Array.isArray(s)?"entry children must be an array":r==="file"&&(s!==void 0||a===!0)?"a file entry cannot have children or be lazy":a===!0&&Array.isArray(s)&&s.length>0?"a lazy directory must not list children":null:`an entry type must be "file" or "directory"; got ${i(r)}`},N=e=>{if(S(e)!==null)return!1;const{children:n}=e;return n===void 0||n.every(N)},L=e=>{if(e===null||typeof e!="object")return!1;const{status:n,entries:t,failure:r}=e;return n==="ok"?Array.isArray(t)&&t.every(N):n==="error"&&u(r)===null},ae=e=>{if(e===null||typeof e!="object")return!1;const{status:n,ancestors:t,failure:r}=e;return n==="ok"?t===null||D(t):n==="error"&&u(r)===null},D=e=>Array.isArray(e)&&e.every(n=>typeof n=="string"&&p(n))&&new Set(e).size===e.length,le=e=>{if(e===null||typeof e!="object")return!1;const{status:n,source:t,ancestors:r,failure:o}=e;return n==="ok"?t===null&&r===null||typeof t=="string"&&t!==""&&D(r):n==="error"&&u(o)===null},ce=e=>{if(e===null||typeof e!="object")return!1;const{status:n,loadedAt:t}=e;return n==="ok"&&!(Number.isSafeInteger(t)&&t>=0)?!1:L(e)},A=e=>{if(e===null||typeof e!="object")return"a heading must be an object";const{text:n,depth:t,id:r}=e;return typeof n!="string"||typeof r!="string"?"a heading needs text and id strings":typeof t!="number"||!Number.isInteger(t)||t<O.min||t>O.max?`a heading depth must be an integer in 1..6; got ${String(t)}`:null},v=e=>{if(e===null||typeof e!="object")return"a document must be an object";const n=e,{kind:t}=n;if(!se(t))return`unknown document kind ${i(t)}`;if(t==="failure")return u(n.failure);if(typeof n.name!="string")return"a document needs a name string";switch(t){case"markdown":{const{htmlContent:r,headings:o}=n;if(typeof r!="string"||!Array.isArray(o))return"a markdown document needs htmlContent and headings";for(const s of o){const a=A(s);if(a!==null)return a}return fe(n.edit)}case"text":return typeof n.text!="string"||typeof n.truncated!="boolean"?"a text document needs text and truncated":l(n.url)?null:"a text document needs a root-relative url";case"image":return l(n.url)?null:"an image document needs a root-relative url";case"media":return l(n.url)?P(n.mediaType)?null:`unknown media type ${i(n.mediaType)}`:"a media document needs a root-relative url";case"file":return l(n.url)?null:"a file document needs a root-relative url"}},w=e=>v(e)===null,ue=e=>w(e)&&(e.kind==="text"||e.kind==="failure"),fe=e=>{if(e===null)return null;if(typeof e!="object")return"a markdown document's edit must be null or an object";const{kind:n,href:t}=e;return n==="inline"?t===void 0?null:"an inline edit carries no href":n!=="external"?`unknown edit kind ${i(n)}`:de(t)?null:`an external edit needs an absolute https: href; got ${i(t)}`},de=e=>{if(typeof e!="string")return!1;try{return new URL(e).protocol==="https:"}catch{return!1}},c=e=>typeof e=="string"&&e.length>0&&e.length<=_,Ee=e=>l(e.href)?null:`a grant needs a root-relative href; got ${i(e.href)}`,k=e=>{if(e===null||typeof e!="object")return"a revision must be an object";const{id:n,modifiedAt:t,size:r,author:o,kept:s,current:a}=e;return c(n)?t!==null&&(typeof t!="string"||Number.isNaN(Date.parse(t)))?`a revision's modifiedAt must be a date-time string or null; got ${i(t)}`:typeof r!="number"||!Number.isSafeInteger(r)||r<0?`a revision's size must be a non-negative integer; got ${i(r)}`:o!==null&&typeof o!="string"?`a revision's author must be a string or null; got ${i(o)}`:typeof s!="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 ${i(n)}`},d=(e,n)=>{if(e===null||typeof e!="object")return"an answer must be an object";const t=e,{kind:r}=t;if(r==="failure")return u(t.failure);if(typeof r!="string"||!n.includes(r))return`unexpected answer kind ${i(r)}`;switch(r){case"grant":return Ee(t);case"edit":return typeof t.text!="string"||typeof t.history!="boolean"?"an edit source needs text and history":c(t.version)?null:`an edit source needs a version; got ${i(t.version)}`;case"saved":return c(t.version)?null:`a saved answer needs a version; got ${i(t.version)}`;case"conflict":return typeof t.text!="string"?"a conflict needs the current text":c(t.version)?null:`a conflict needs the current version; got ${i(t.version)}`;case"preview":{const{htmlContent:o,headings:s}=t;if(typeof o!="string"||!Array.isArray(s))return"a preview needs htmlContent and headings";for(const a of s){const g=A(a);if(g!==null)return g}return null}case"revisions":{if(!Array.isArray(t.revisions))return"revisions need an array";for(const o of t.revisions){const s=k(o);if(s!==null)return s}return null}case"revision":return typeof t.text!="string"?"a revision answer needs text":c(t.id)?null:`a revision answer needs an id; got ${i(t.id)}`;default:return`unexpected answer kind ${i(r)}`}},pe=Object.freeze(["edit","grant"]),Re=Object.freeze(["saved","conflict","grant"]),ye=Object.freeze(["preview"]),_e=Object.freeze(["revisions"]),me=Object.freeze(["revision"]),Ae=e=>d(e,pe)===null,ge=e=>d(e,Re)===null,Oe=e=>d(e,ye)===null,he=e=>d(e,_e)===null,be=e=>d(e,me)===null,Te=(e,n)=>({kind:"failure",failure:I(e,n)}),I=(e,n)=>m(n)?{reason:e,code:n}:{reason:e},xe=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"}),Pe="asset",Se="link-card",Ne=(e,n,t)=>{const r=`${e}/${Pe}?${E.path}=${encodeURIComponent(n)}`;return t===null?r:`${r}&${E.version}=${encodeURIComponent(t)}`},Le=e=>`${e}/${Se}`,De="X-Markdown-Explorer-Scope",ve="X-Markdown-Explorer",we="refresh",ke="edit",Ie="text/markdown",je=e=>xe.includes(e),j=Object.freeze({invalid:400,unauthorized:401,forbidden:403,"not-found":404,"too-large":413,"not-configured":500,unsupported:500,failed:500}),Ce=e=>{const[n,...t]=y.filter(r=>j[r]===e);return n!==void 0&&t.length===0?n:"failed"};exports.DEFAULT_DENIED_PATH_SEGMENTS=b;exports.EXPLORER_DATA_QUERY=E;exports.EXPLORER_DRAFT_MEDIA_TYPE=Ie;exports.EXPLORER_EDIT_PROOF=ke;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_;exports.EXPLORER_FAILURE_REASONS=y;exports.EXPLORER_FAILURE_STATUS=j;exports.EXPLORER_LINK_PROTOCOLS=ee;exports.EXPLORER_MAX_HEADINGS=Z;exports.EXPLORER_PROOF_HEADER=ve;exports.EXPLORER_REFRESH_PROOF=we;exports.EXPLORER_SCOPE_HEADER=De;exports.MAX_DOCUMENT_PATH_LENGTH=4096;exports.documentViolation=v;exports.entryViolation=S;exports.explorerAssetHref=Ne;exports.explorerLinkCardEndpoint=Le;exports.failureDocument=Te;exports.failureOf=I;exports.failureReasonOfStatus=Ce;exports.failureViolation=u;exports.headingViolation=A;exports.isAcceptableDocumentPath=p;exports.isAcceptableUrl=ie;exports.isDeniedPath=W;exports.isExplorerAncestorsResult=ae;exports.isExplorerChildrenResult=L;exports.isExplorerDataOperation=je;exports.isExplorerDocument=w;exports.isExplorerEditAnswer=Ae;exports.isExplorerEditToken=c;exports.isExplorerFailureCode=m;exports.isExplorerFailureReason=x;exports.isExplorerMediaType=P;exports.isExplorerNoticeTone=oe;exports.isExplorerPreviewAnswer=Oe;exports.isExplorerRevealResult=le;exports.isExplorerRevisionAnswer=be;exports.isExplorerRevisionsAnswer=he;exports.isExplorerSaveAnswer=ge;exports.isExplorerTextAnswer=ue;exports.isExplorerTreeResult=ce;exports.isRootRelativeUrl=l;exports.lastPathSegment=$;exports.resolvePathRules=Y;exports.revisionViolation=k;
@@ -1,270 +0,0 @@
1
- const fe = 4096;
2
- const S = Object.freeze([
3
- ".env*",
4
- "*.env",
5
- "*.env.*",
6
- "*.env~*",
7
- "*.env-*",
8
- "*.env_*",
9
- "*.env#*",
10
- ".git",
11
- ".git-credentials",
12
- ".svn",
13
- ".hg",
14
- "node_modules",
15
- "secrets",
16
- ".secrets",
17
- "secrets.json",
18
- "secrets.yml",
19
- "secrets.yaml",
20
- "secrets.toml",
21
- "secrets.ini",
22
- "secrets.txt",
23
- ".ssh",
24
- ".aws",
25
- ".gnupg",
26
- ".docker",
27
- ".kube",
28
- ".terraform",
29
- ".npmrc",
30
- ".yarnrc",
31
- ".yarnrc.yml",
32
- ".netrc",
33
- "_netrc",
34
- ".pypirc",
35
- ".pgpass",
36
- ".my.cnf",
37
- ".htpasswd",
38
- ".vault-token",
39
- "id_rsa*",
40
- "id_dsa*",
41
- "id_ecdsa*",
42
- "id_ed25519*",
43
- "*.pem",
44
- "*.key",
45
- "*.p8",
46
- "*.p12",
47
- "*.pfx",
48
- "*.ppk",
49
- "*.jks",
50
- "*.keystore",
51
- "*.kdbx",
52
- "*credentials*.json",
53
- "service-account*.json",
54
- "*.tfstate",
55
- "*.tfstate.*",
56
- "*.tfvars",
57
- "*.tfvars.json",
58
- ".*_history",
59
- "fish_history"
60
- ]), N = /[\u0000-\u001f\u007f]/u, v = /\p{Cs}/u, de = (e) => {
61
- const n = e.split("/").filter((t) => t !== "").at(-1);
62
- return n === void 0 ? e : n;
63
- }, R = (e) => e.length > 0 && e.length <= 4096 && !v.test(e) && !N.test(e) && !e.includes("\\"), _ = (e) => e.normalize("NFKC").toUpperCase().toLowerCase(), P = /(?:%[0-9A-Fa-f]{2})+/gu, w = new TextDecoder("utf-8"), D = /[/\\]/u, L = (e) => e.replace(
64
- P,
65
- (n) => w.decode(
66
- Uint8Array.from(
67
- n.slice(1).split("%").map((t) => Number.parseInt(t, 16))
68
- )
69
- )
70
- ), k = (e) => {
71
- const n = [e];
72
- let t = e;
73
- for (let r = 0; r < 3 && t.includes("%"); r += 1) {
74
- const s = L(t);
75
- if (s === t) break;
76
- n.push(s), t = s;
77
- }
78
- return n.map(_);
79
- }, j = (e) => {
80
- if (typeof e != "string" || e.trim() === "" || e.includes("/") || e.includes("\\"))
81
- throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);
82
- const n = _(e).split("*").map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*");
83
- return new RegExp(`^${n}$`, "su");
84
- }, p = (e) => {
85
- if (!Array.isArray(e)) throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");
86
- const n = e.map(j), t = (s) => s !== "" && n.some((o) => o.test(s)), r = (s) => s !== "" && k(s).some((o) => t(o) || o.split(D).some(t));
87
- return {
88
- deniesPath: (s) => s.split("/").some(r),
89
- deniesName: r
90
- };
91
- }, $ = p(S), I = Object.freeze({ deniesPath: () => !1, deniesName: () => !1 }), pe = (e) => e === void 0 ? $ : e === !1 ? I : p(e), Ee = (e, n) => p(e).deniesPath(n), b = Object.freeze(["unauthorized", "forbidden", "not-found", "not-configured", "invalid", "too-large", "unsupported", "failed"]), C = Object.freeze(["file", "directory"]), z = Object.freeze(["video", "audio", "pdf"]), U = Object.freeze(["info", "warning", "danger"]), X = Object.freeze(["markdown", "text", "image", "media", "file", "failure"]), y = Object.freeze({ min: 1, max: 6 }), ye = 1e4, c = (e) => typeof e == "string" && /^\/(?![/\\])[\x21-\x7E]*$/u.test(e), me = Object.freeze(["http:", "https:", "mailto:"]), h = 1024, H = /^[a-z0-9-]{1,64}$/u, F = "https://relative.invalid/", m = 64, u = (e, n) => typeof n == "string" && e.includes(n), i = (e) => typeof e == "string" ? JSON.stringify(e.length > m ? `${e.slice(0, m)}…` : e) : typeof e, V = (e) => u(b, e), M = (e) => u(C, e), K = (e) => u(z, e), ge = (e) => u(U, e), G = (e) => u(X, e), A = (e) => typeof e == "string" && H.test(e), Re = (e, n) => {
92
- if (typeof e != "string") return !1;
93
- try {
94
- return n.includes(new URL(e, F).protocol);
95
- } catch {
96
- return !1;
97
- }
98
- }, f = (e) => {
99
- if (e === null || typeof e != "object") return "a failure must be an object";
100
- const { reason: n, code: t } = e;
101
- return V(n) ? t !== void 0 && !A(t) ? `a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${i(t)}` : null : `unknown failure reason ${i(n)}`;
102
- }, W = (e) => {
103
- if (e === null || typeof e != "object") return "an entry must be an object";
104
- const { name: n, path: t, type: r, mimeType: s, children: o, lazy: a } = e;
105
- return typeof n != "string" || n === "" ? "an entry needs a non-empty name" : typeof t != "string" || !R(t) ? "an entry needs an acceptable path" : M(r) ? s !== void 0 && typeof s != "string" ? "an entry mimeType must be a string" : a !== void 0 && typeof a != "boolean" ? "an entry lazy flag must be a boolean" : o !== void 0 && !Array.isArray(o) ? "entry children must be an array" : r === "file" && (o !== void 0 || a === !0) ? "a file entry cannot have children or be lazy" : a === !0 && Array.isArray(o) && o.length > 0 ? "a lazy directory must not list children" : null : `an entry type must be "file" or "directory"; got ${i(r)}`;
106
- }, O = (e) => {
107
- if (W(e) !== null) return !1;
108
- const { children: n } = e;
109
- return n === void 0 || n.every(O);
110
- }, Y = (e) => {
111
- if (e === null || typeof e != "object") return !1;
112
- const { status: n, entries: t, failure: r } = e;
113
- return n === "ok" ? Array.isArray(t) && t.every(O) : n === "error" && f(r) === null;
114
- }, _e = (e) => {
115
- if (e === null || typeof e != "object") return !1;
116
- const { status: n, ancestors: t, failure: r } = e;
117
- return n === "ok" ? t === null || x(t) : n === "error" && f(r) === null;
118
- }, x = (e) => Array.isArray(e) && e.every((n) => typeof n == "string" && R(n)) && new Set(e).size === e.length, be = (e) => {
119
- if (e === null || typeof e != "object") return !1;
120
- const { status: n, source: t, ancestors: r, failure: s } = e;
121
- return n === "ok" ? t === null && r === null || typeof t == "string" && t !== "" && x(r) : n === "error" && f(s) === null;
122
- }, he = (e) => {
123
- if (e === null || typeof e != "object") return !1;
124
- const { status: n, loadedAt: t } = e;
125
- return n === "ok" && !(Number.isSafeInteger(t) && t >= 0) ? !1 : Y(e);
126
- }, T = (e) => {
127
- if (e === null || typeof e != "object") return "a heading must be an object";
128
- const { text: n, depth: t, id: r } = e;
129
- return typeof n != "string" || typeof r != "string" ? "a heading needs text and id strings" : typeof t != "number" || !Number.isInteger(t) || t < y.min || t > y.max ? `a heading depth must be an integer in 1..6; got ${String(t)}` : null;
130
- }, J = (e) => {
131
- if (e === null || typeof e != "object") return "a document must be an object";
132
- const n = e, { kind: t } = n;
133
- if (!G(t)) return `unknown document kind ${i(t)}`;
134
- if (t === "failure") return f(n.failure);
135
- if (typeof n.name != "string") return "a document needs a name string";
136
- switch (t) {
137
- case "markdown": {
138
- const { htmlContent: r, headings: s } = n;
139
- if (typeof r != "string" || !Array.isArray(s)) return "a markdown document needs htmlContent and headings";
140
- for (const o of s) {
141
- const a = T(o);
142
- if (a !== null) return a;
143
- }
144
- return Q(n.edit);
145
- }
146
- case "text":
147
- return typeof n.text != "string" || typeof n.truncated != "boolean" ? "a text document needs text and truncated" : c(n.url) ? null : "a text document needs a root-relative url";
148
- case "image":
149
- return c(n.url) ? null : "an image document needs a root-relative url";
150
- case "media":
151
- return c(n.url) ? K(n.mediaType) ? null : `unknown media type ${i(n.mediaType)}` : "a media document needs a root-relative url";
152
- case "file":
153
- return c(n.url) ? null : "a file document needs a root-relative url";
154
- }
155
- }, B = (e) => J(e) === null, Ae = (e) => B(e) && (e.kind === "text" || e.kind === "failure"), Q = (e) => {
156
- if (e === null) return null;
157
- if (typeof e != "object") return "a markdown document's edit must be null or an object";
158
- const { kind: n, href: t } = e;
159
- return n === "inline" ? t === void 0 ? null : "an inline edit carries no href" : n !== "external" ? `unknown edit kind ${i(n)}` : q(t) ? null : `an external edit needs an absolute https: href; got ${i(t)}`;
160
- }, q = (e) => {
161
- if (typeof e != "string") return !1;
162
- try {
163
- return new URL(e).protocol === "https:";
164
- } catch {
165
- return !1;
166
- }
167
- }, l = (e) => typeof e == "string" && e.length > 0 && e.length <= h, Z = (e) => c(e.href) ? null : `a grant needs a root-relative href; got ${i(e.href)}`, ee = (e) => {
168
- if (e === null || typeof e != "object") return "a revision must be an object";
169
- const { id: n, modifiedAt: t, size: r, author: s, kept: o, current: a } = e;
170
- return l(n) ? t !== null && (typeof t != "string" || Number.isNaN(Date.parse(t))) ? `a revision's modifiedAt must be a date-time string or null; got ${i(t)}` : typeof r != "number" || !Number.isSafeInteger(r) || r < 0 ? `a revision's size must be a non-negative integer; got ${i(r)}` : s !== null && typeof s != "string" ? `a revision's author must be a string or null; got ${i(s)}` : typeof o != "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 ${i(n)}`;
171
- }, d = (e, n) => {
172
- if (e === null || typeof e != "object") return "an answer must be an object";
173
- const t = e, { kind: r } = t;
174
- if (r === "failure") return f(t.failure);
175
- if (typeof r != "string" || !n.includes(r)) return `unexpected answer kind ${i(r)}`;
176
- switch (r) {
177
- case "grant":
178
- return Z(t);
179
- case "edit":
180
- return typeof t.text != "string" || typeof t.history != "boolean" ? "an edit source needs text and history" : l(t.version) ? null : `an edit source needs a version; got ${i(t.version)}`;
181
- case "saved":
182
- return l(t.version) ? null : `a saved answer needs a version; got ${i(t.version)}`;
183
- case "conflict":
184
- return typeof t.text != "string" ? "a conflict needs the current text" : l(t.version) ? null : `a conflict needs the current version; got ${i(t.version)}`;
185
- case "preview": {
186
- const { htmlContent: s, headings: o } = t;
187
- if (typeof s != "string" || !Array.isArray(o)) return "a preview needs htmlContent and headings";
188
- for (const a of o) {
189
- const E = T(a);
190
- if (E !== null) return E;
191
- }
192
- return null;
193
- }
194
- case "revisions": {
195
- if (!Array.isArray(t.revisions)) return "revisions need an array";
196
- for (const s of t.revisions) {
197
- const o = ee(s);
198
- if (o !== null) return o;
199
- }
200
- return null;
201
- }
202
- case "revision":
203
- return typeof t.text != "string" ? "a revision answer needs text" : l(t.id) ? null : `a revision answer needs an id; got ${i(t.id)}`;
204
- default:
205
- return `unexpected answer kind ${i(r)}`;
206
- }
207
- }, te = Object.freeze(["edit", "grant"]), ne = Object.freeze(["saved", "conflict", "grant"]), re = Object.freeze(["preview"]), se = Object.freeze(["revisions"]), oe = Object.freeze(["revision"]), Oe = (e) => d(e, te) === null, xe = (e) => d(e, ne) === null, Te = (e) => d(e, re) === null, Se = (e) => d(e, se) === null, Ne = (e) => d(e, oe) === null, ve = (e, n) => ({ kind: "failure", failure: ie(e, n) }), ie = (e, n) => A(n) ? { reason: e, code: n } : { reason: e }, ae = Object.freeze(["tree", "children", "ancestors", "reveal", "document", "text", "edit", "save", "preview", "revisions", "revision", "refresh", "asset", "link-card"]), g = Object.freeze({ source: "source", path: "path", version: "v", base: "base", revision: "revision" }), ce = "asset", le = "link-card", Pe = (e, n, t) => {
208
- const r = `${e}/${ce}?${g.path}=${encodeURIComponent(n)}`;
209
- return t === null ? r : `${r}&${g.version}=${encodeURIComponent(t)}`;
210
- }, we = (e) => `${e}/${le}`, De = "X-Markdown-Explorer-Scope", Le = "X-Markdown-Explorer", ke = "refresh", je = "edit", $e = "text/markdown", Ie = (e) => ae.includes(e), ue = Object.freeze({
211
- invalid: 400,
212
- unauthorized: 401,
213
- forbidden: 403,
214
- "not-found": 404,
215
- "too-large": 413,
216
- "not-configured": 500,
217
- unsupported: 500,
218
- failed: 500
219
- }), Ce = (e) => {
220
- const [n, ...t] = b.filter((r) => ue[r] === e);
221
- return n !== void 0 && t.length === 0 ? n : "failed";
222
- };
223
- export {
224
- Ee as A,
225
- de as B,
226
- Ce as C,
227
- S as D,
228
- ye as E,
229
- Ae as F,
230
- be as G,
231
- _e as H,
232
- Y as I,
233
- f as J,
234
- he as K,
235
- Ne as L,
236
- fe as M,
237
- Se as N,
238
- Te as O,
239
- xe as P,
240
- Oe as Q,
241
- B as R,
242
- h as S,
243
- b as T,
244
- we as a,
245
- V as b,
246
- A as c,
247
- ge as d,
248
- Pe as e,
249
- ie as f,
250
- Re as g,
251
- K as h,
252
- R as i,
253
- J as j,
254
- l as k,
255
- T as l,
256
- c as m,
257
- W as n,
258
- me as o,
259
- pe as p,
260
- Ie as q,
261
- ee as r,
262
- ue as s,
263
- Le as t,
264
- ke as u,
265
- je as v,
266
- De as w,
267
- g as x,
268
- ve as y,
269
- $e as z
270
- };