@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.
- package/CHANGELOG.md +27 -1
- package/README.md +65 -6
- package/dist/EditSurface-By6NPcD7.js +633 -0
- package/dist/EditSurface-BztcpQPW.cjs +2 -0
- package/dist/{ExplorerSplit-DwlWWfRv.js → ExplorerSplit-BjjqNRtj.js} +52 -52
- package/dist/{ExplorerSplit-51frK8xf.cjs → ExplorerSplit-CqmbUSZ7.cjs} +1 -1
- package/dist/{MultiLayout-CeR_l6Rb.js → MultiLayout-BYXoD1aS.js} +4 -4
- package/dist/{MultiLayout-B4PtS45V.cjs → MultiLayout-BZbEl73E.cjs} +1 -1
- package/dist/{NativeScrollBar-Dp4YWBp7.cjs → NativeScrollBar-B7jTbQmn.cjs} +1 -1
- package/dist/{NativeScrollBar-CVWeTlHC.js → NativeScrollBar-RP37nwmY.js} +1 -1
- package/dist/{TreeLayout-D-NyhuVM.cjs → TreeLayout-CEp5oKly.cjs} +1 -1
- package/dist/{TreeLayout-min5AOhr.js → TreeLayout-Uo6RG7lq.js} +3 -3
- package/dist/client/MarkdownExplorer.d.cts +3 -2
- package/dist/client/MarkdownExplorer.d.ts +3 -2
- package/dist/core/contracts.d.cts +16 -0
- package/dist/core/contracts.d.ts +16 -0
- package/dist/dataRoute-CH3yOKR0.cjs +1 -0
- package/dist/{dataRoute-CU9CKP44.js → dataRoute-Pm_0ue_4.js} +93 -92
- package/dist/{index-DJ_FUtYM.cjs → index-CGBl3fYT.cjs} +8 -8
- package/dist/{index-BPj19kIo.js → index-CjCr8czx.js} +962 -908
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/{location-LNl0QOXI.cjs → location-BUNWJ4eB.cjs} +1 -1
- package/dist/{location-BT23fKeh.js → location-DWd6SQhN.js} +1 -1
- package/dist/{merge-AnqxGn__.cjs → merge-DRGBbLuR.cjs} +1 -1
- package/dist/{merge-hyUGPGbJ.js → merge-q-5i8qsn.js} +1 -1
- package/dist/sanitizePolicy-BfUlXI5E.cjs +1 -0
- package/dist/sanitizePolicy-djLC3fRN.js +96 -0
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +143 -226
- package/dist/server.cjs +1 -1
- package/dist/server.js +3 -3
- package/dist/styles/markdown-explorer.css +1 -1
- package/docs/behavior/dom-hooks.md +1 -1
- package/docs/behavior/layout.md +4 -1
- package/docs/behavior/security.md +2 -0
- package/package.json +3 -3
- package/dist/EditSurface-BK_Pz_LF.js +0 -371
- package/dist/EditSurface-CfbYYXrc.cjs +0 -2
- package/dist/dataRoute-CIFFX5bd.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./index-CGBl3fYT.cjs"),e=require("./storage-Dgi4JXaB.cjs"),E=require("./location-BUNWJ4eB.cjs"),_=require("./dataRoute-CH3yOKR0.cjs");exports.DEFAULT_MARKDOWN_EXPLORER_LOCALE=L.DEFAULT_MARKDOWN_EXPLORER_LOCALE;exports.EXPLORER_THEMES=L.EXPLORER_THEMES;exports.MARKDOWN_EXPLORER_LABEL_CATALOGS=L.MARKDOWN_EXPLORER_LABEL_CATALOGS;exports.MARKDOWN_EXPLORER_LABEL_KEYS=L.MARKDOWN_EXPLORER_LABEL_KEYS;exports.MARKDOWN_EXPLORER_LABEL_TEMPLATES=L.MARKDOWN_EXPLORER_LABEL_TEMPLATES;exports.MARKDOWN_EXPLORER_LOCALES=L.MARKDOWN_EXPLORER_LOCALES;exports.MarkdownExplorer=L.MarkdownExplorer;exports.resolveMarkdownExplorerLabels=L.resolveMarkdownExplorerLabels;exports.shouldRevalidateExplorer=L.shouldRevalidateExplorer;exports.clearExplorerStorage=e.clearExplorerStorage;exports.COLUMN_MIN_MEASURE=E.COLUMN_MIN_MEASURE;exports.DEFAULT_TREE_SETTINGS=E.DEFAULT_TREE_SETTINGS;exports.DEFAULT_VIEW_SLUGS=E.DEFAULT_VIEW_SLUGS;exports.EXPAND_ALL_DEPTH_LIMITS=E.EXPAND_ALL_DEPTH_LIMITS;exports.EXPAND_ALL_FOLDER_LIMITS=E.EXPAND_ALL_FOLDER_LIMITS;exports.EXPLORER_DEFAULT_PERCENT=E.EXPLORER_DEFAULT_PERCENT;exports.EXPLORER_MAX_PERCENT=E.EXPLORER_MAX_PERCENT;exports.EXPLORER_MIN_REM=E.EXPLORER_MIN_REM;exports.EXPLORER_MULTI_DEFAULT_PERCENT=E.EXPLORER_MULTI_DEFAULT_PERCENT;exports.GOLDEN_RATIO=E.GOLDEN_RATIO;exports.MULTI_VIEW_COLUMN_LIMITS=E.MULTI_VIEW_COLUMN_LIMITS;exports.MULTI_VIEW_PANEL_LIMITS=E.MULTI_VIEW_PANEL_LIMITS;exports.REVEAL_DOCUMENT_DEPTH_LIMITS=E.REVEAL_DOCUMENT_DEPTH_LIMITS;exports.defineExplorerConfig=E.defineExplorerConfig;exports.explorerHref=E.explorerHref;exports.isExplorerSourceId=E.isExplorerSourceId;exports.resolveExplorerLocation=E.resolveExplorerLocation;exports.withExplorerSources=E.withExplorerSources;exports.DEFAULT_DENIED_PATH_SEGMENTS=_.DEFAULT_DENIED_PATH_SEGMENTS;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_.EXPLORER_EDIT_TOKEN_MAX_LENGTH;exports.EXPLORER_FAILURE_REASONS=_.EXPLORER_FAILURE_REASONS;exports.EXPLORER_MAX_HEADINGS=_.EXPLORER_MAX_HEADINGS;exports.MAX_DOCUMENT_PATH_LENGTH=_.MAX_DOCUMENT_PATH_LENGTH;exports.failureDocument=_.failureDocument;exports.failureOf=_.failureOf;exports.isAcceptableDocumentPath=_.isAcceptableDocumentPath;exports.isDeniedPath=_.isDeniedPath;exports.isExplorerChildrenResult=_.isExplorerChildrenResult;exports.isExplorerFailureCode=_.isExplorerFailureCode;exports.isExplorerFailureReason=_.isExplorerFailureReason;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { type ExplorerFrameRenderer, MarkdownExplorer, type MarkdownExplorerProps } from "./client/MarkdownExplorer.cjs";
|
|
2
2
|
export { clearExplorerStorage } from "./client/storage.cjs";
|
|
3
3
|
export { DEFAULT_VIEW_SLUGS, defineExplorerConfig, EXPAND_ALL_DEPTH_LIMITS, EXPAND_ALL_FOLDER_LIMITS, type ExplorerConfig, type ExplorerConfigInput, type ExplorerDocumentStyle, type ExplorerLocationConfig, type ExplorerView, type ExplorerViewSlugs, isExplorerSourceId, MULTI_VIEW_COLUMN_LIMITS, MULTI_VIEW_PANEL_LIMITS, REVEAL_DOCUMENT_DEPTH_LIMITS, withExplorerSources, } from "./core/config.cjs";
|
|
4
|
-
export { EXPLORER_EDIT_TOKEN_MAX_LENGTH, EXPLORER_FAILURE_REASONS, EXPLORER_MAX_HEADINGS, type ExplorerChildrenResult, type ExplorerDocument, type ExplorerDocumentEdit, type ExplorerEntry, type ExplorerFailure, type ExplorerFailureDocument, type ExplorerFailureReason, type ExplorerGrantRequired, type ExplorerHeading, type ExplorerMediaType, type ExplorerNotice, type ExplorerPageData, type ExplorerRevision, type ExplorerSeededDocument, type ExplorerSourceSummary, type ExplorerTreeResult, failureDocument, failureOf, isExplorerChildrenResult, isExplorerFailureCode, isExplorerFailureReason, } from "./core/contracts.cjs";
|
|
4
|
+
export { EXPLORER_EDIT_TOKEN_MAX_LENGTH, EXPLORER_FAILURE_REASONS, EXPLORER_MAX_HEADINGS, type ExplorerChildrenResult, type ExplorerDocument, type ExplorerDocumentEdit, type ExplorerDraft, type ExplorerDraftAnswer, type ExplorerDraftConverter, type ExplorerEntry, type ExplorerFailure, type ExplorerFailureDocument, type ExplorerFailureReason, type ExplorerGrantRequired, type ExplorerHeading, type ExplorerMediaType, type ExplorerNotice, type ExplorerPageData, type ExplorerRevision, type ExplorerSeededDocument, type ExplorerSourceSummary, type ExplorerTreeResult, failureDocument, failureOf, isExplorerChildrenResult, isExplorerFailureCode, isExplorerFailureReason, } from "./core/contracts.cjs";
|
|
5
5
|
export { COLUMN_MIN_MEASURE, EXPLORER_DEFAULT_PERCENT, EXPLORER_MAX_PERCENT, EXPLORER_MIN_REM, EXPLORER_MULTI_DEFAULT_PERCENT, GOLDEN_RATIO } from "./core/geometry.cjs";
|
|
6
6
|
export { DEFAULT_MARKDOWN_EXPLORER_LOCALE, MARKDOWN_EXPLORER_LABEL_CATALOGS, MARKDOWN_EXPLORER_LABEL_KEYS, MARKDOWN_EXPLORER_LABEL_TEMPLATES, MARKDOWN_EXPLORER_LOCALES, type MarkdownExplorerLabelKey, type MarkdownExplorerLabelOverrides, type MarkdownExplorerLabels, type MarkdownExplorerLocale, resolveMarkdownExplorerLabels, } from "./core/labels.cjs";
|
|
7
7
|
export { type ExplorerEmbedOptions, type ExplorerHrefTarget, type ExplorerLocation, type ExplorerLocationResult, type ExplorerOverrides, type ExplorerSourcelessHrefTarget, explorerHref, resolveExplorerLocation, } from "./core/location.cjs";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { type ExplorerFrameRenderer, MarkdownExplorer, type MarkdownExplorerProps } from "./client/MarkdownExplorer.js";
|
|
2
2
|
export { clearExplorerStorage } from "./client/storage.js";
|
|
3
3
|
export { DEFAULT_VIEW_SLUGS, defineExplorerConfig, EXPAND_ALL_DEPTH_LIMITS, EXPAND_ALL_FOLDER_LIMITS, type ExplorerConfig, type ExplorerConfigInput, type ExplorerDocumentStyle, type ExplorerLocationConfig, type ExplorerView, type ExplorerViewSlugs, isExplorerSourceId, MULTI_VIEW_COLUMN_LIMITS, MULTI_VIEW_PANEL_LIMITS, REVEAL_DOCUMENT_DEPTH_LIMITS, withExplorerSources, } from "./core/config.js";
|
|
4
|
-
export { EXPLORER_EDIT_TOKEN_MAX_LENGTH, EXPLORER_FAILURE_REASONS, EXPLORER_MAX_HEADINGS, type ExplorerChildrenResult, type ExplorerDocument, type ExplorerDocumentEdit, type ExplorerEntry, type ExplorerFailure, type ExplorerFailureDocument, type ExplorerFailureReason, type ExplorerGrantRequired, type ExplorerHeading, type ExplorerMediaType, type ExplorerNotice, type ExplorerPageData, type ExplorerRevision, type ExplorerSeededDocument, type ExplorerSourceSummary, type ExplorerTreeResult, failureDocument, failureOf, isExplorerChildrenResult, isExplorerFailureCode, isExplorerFailureReason, } from "./core/contracts.js";
|
|
4
|
+
export { EXPLORER_EDIT_TOKEN_MAX_LENGTH, EXPLORER_FAILURE_REASONS, EXPLORER_MAX_HEADINGS, type ExplorerChildrenResult, type ExplorerDocument, type ExplorerDocumentEdit, type ExplorerDraft, type ExplorerDraftAnswer, type ExplorerDraftConverter, type ExplorerEntry, type ExplorerFailure, type ExplorerFailureDocument, type ExplorerFailureReason, type ExplorerGrantRequired, type ExplorerHeading, type ExplorerMediaType, type ExplorerNotice, type ExplorerPageData, type ExplorerRevision, type ExplorerSeededDocument, type ExplorerSourceSummary, type ExplorerTreeResult, failureDocument, failureOf, isExplorerChildrenResult, isExplorerFailureCode, isExplorerFailureReason, } from "./core/contracts.js";
|
|
5
5
|
export { COLUMN_MIN_MEASURE, EXPLORER_DEFAULT_PERCENT, EXPLORER_MAX_PERCENT, EXPLORER_MIN_REM, EXPLORER_MULTI_DEFAULT_PERCENT, GOLDEN_RATIO } from "./core/geometry.js";
|
|
6
6
|
export { DEFAULT_MARKDOWN_EXPLORER_LOCALE, MARKDOWN_EXPLORER_LABEL_CATALOGS, MARKDOWN_EXPLORER_LABEL_KEYS, MARKDOWN_EXPLORER_LABEL_TEMPLATES, MARKDOWN_EXPLORER_LOCALES, type MarkdownExplorerLabelKey, type MarkdownExplorerLabelOverrides, type MarkdownExplorerLabels, type MarkdownExplorerLocale, resolveMarkdownExplorerLabels, } from "./core/labels.js";
|
|
7
7
|
export { type ExplorerEmbedOptions, type ExplorerHrefTarget, type ExplorerLocation, type ExplorerLocationResult, type ExplorerOverrides, type ExplorerSourcelessHrefTarget, explorerHref, resolveExplorerLocation, } from "./core/location.js";
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { y as a, z as L, M as s, B as e, G as r, H as R, J as A, K as T, N as o } from "./index-CjCr8czx.js";
|
|
2
2
|
import { c as O } from "./storage-BSthKLSG.js";
|
|
3
|
-
import { J as N, K as P, L as l, M as I, O as S, q as i, o as X, Q as
|
|
4
|
-
import { D as
|
|
3
|
+
import { J as N, K as P, L as l, M as I, O as S, q as i, o as X, Q as p, s as U, G as x, R as t, T as C, U as f, V as c, e as n, i as u, a as F, w as G } from "./location-DWd6SQhN.js";
|
|
4
|
+
import { D as d, V as K, W, E as m, M as V, z as h, f as w, i as B, C as b, L as v, c as g, b as k } from "./dataRoute-Pm_0ue_4.js";
|
|
5
5
|
export {
|
|
6
6
|
N as COLUMN_MIN_MEASURE,
|
|
7
|
-
|
|
7
|
+
d as DEFAULT_DENIED_PATH_SEGMENTS,
|
|
8
8
|
a as DEFAULT_MARKDOWN_EXPLORER_LOCALE,
|
|
9
9
|
P as DEFAULT_TREE_SETTINGS,
|
|
10
10
|
l as DEFAULT_VIEW_SLUGS,
|
|
11
11
|
I as EXPAND_ALL_DEPTH_LIMITS,
|
|
12
12
|
S as EXPAND_ALL_FOLDER_LIMITS,
|
|
13
13
|
i as EXPLORER_DEFAULT_PERCENT,
|
|
14
|
-
|
|
14
|
+
K as EXPLORER_EDIT_TOKEN_MAX_LENGTH,
|
|
15
15
|
W as EXPLORER_FAILURE_REASONS,
|
|
16
16
|
m as EXPLORER_MAX_HEADINGS,
|
|
17
17
|
X as EXPLORER_MAX_PERCENT,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
p as EXPLORER_MIN_REM,
|
|
19
|
+
U as EXPLORER_MULTI_DEFAULT_PERCENT,
|
|
20
20
|
L as EXPLORER_THEMES,
|
|
21
21
|
x as GOLDEN_RATIO,
|
|
22
22
|
s as MARKDOWN_EXPLORER_LABEL_CATALOGS,
|
|
@@ -32,8 +32,8 @@ export {
|
|
|
32
32
|
c as defineExplorerConfig,
|
|
33
33
|
n as explorerHref,
|
|
34
34
|
h as failureDocument,
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
w as failureOf,
|
|
36
|
+
B as isAcceptableDocumentPath,
|
|
37
37
|
b as isDeniedPath,
|
|
38
38
|
v as isExplorerChildrenResult,
|
|
39
39
|
g as isExplorerFailureCode,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const O=require("@aiquants/markdown/embeds"),b=require("@aiquants/markdown/viewer-settings"),N=require("./dataRoute-CIFFX5bd.cjs"),k=e=>{if(e===null||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},D=new Intl.Collator("en",{numeric:!0,sensitivity:"variant"}),z=Object.freeze({sortMode:"native",folderPlacement:"mixed",selectionMode:"single",doubleClickAction:"recursive",expandIconSize:8,alwaysExpanded:!1,revealDocument:!1,removeRootIndent:!1,lines:!0,expandIcons:!0,directoryIcons:!0,fileIcons:!0}),we=[!0,!1],pe=(e,t)=>t?e.settingOn:e.settingOff,E=(e,t)=>({key:e,labelKey:t,values:we,formatValue:pe,requiresItemSelection:!1}),Se=Object.freeze({native:e=>e.sortNative,asc:e=>e.sortAscending,desc:e=>e.sortDescending,oldest:e=>e.sortOldest,newest:e=>e.sortNewest}),S=Object.freeze([{key:"sortMode",labelKey:"settingSortMode",values:["native","asc","desc","oldest","newest"],formatValue:(e,t)=>Se[t](e),requiresItemSelection:!1},{key:"folderPlacement",labelKey:"settingFolderPlacement",values:["mixed","first","last"],formatValue:(e,t)=>t==="mixed"?e.folderPlacementMixed:t==="first"?e.folderPlacementFirst:e.folderPlacementLast,requiresItemSelection:!1},{key:"selectionMode",labelKey:"settingSelectionMode",values:["single","multiple","none"],formatValue:(e,t)=>t==="single"?e.selectionSingle:t==="multiple"?e.selectionMultiple:e.selectionNone,requiresItemSelection:!0},{key:"doubleClickAction",labelKey:"settingDoubleClick",values:["recursive","toggle"],formatValue:(e,t)=>t==="recursive"?e.doubleClickRecursive:e.doubleClickToggle,requiresItemSelection:!1},{key:"expandIconSize",labelKey:"settingExpandIconSize",values:[8,13,5],formatValue:(e,t)=>e.expandIconSizeValue(t),requiresItemSelection:!1},E("alwaysExpanded","settingAlwaysExpanded"),E("revealDocument","settingRevealDocument"),E("removeRootIndent","settingRemoveRootIndent"),E("lines","settingTreeLines"),E("expandIcons","settingExpandIcons"),E("directoryIcons","settingDirectoryIcons"),E("fileIcons","settingFileIcons")]),he=e=>e?S:S.filter(t=>!t.requiresItemSelection),B=e=>{const t=S.find(r=>r.key===e);if(t===void 0)throw new RangeError(`[markdown-explorer] no tree setting descriptor for ${e}`);return t},_e=(e,t)=>{const r=B(t).values,n=r[(r.indexOf(e[t])+1)%r.length];return{...e,[t]:n}},Oe=(e,t,r)=>B(r).formatValue(e,t[r]),K=2,j=Object.freeze({}),U=(e,t)=>Object.freeze(Object.fromEntries(S.filter(r=>t(r,e[r.key])).map(r=>[r.key,e[r.key]]))),G="directoriesFirst",xe=e=>{if(!Object.hasOwn(e,G))return e;const{[G]:t,...r}=e;return Object.hasOwn(r,"folderPlacement")||typeof t!="boolean"?r:{...r,folderPlacement:t?"first":"mixed"}},be=e=>{if(e===null||typeof e!="object"||Array.isArray(e))return j;const t=e;return t.version!==K||t.settings===null||typeof t.settings!="object"||Array.isArray(t.settings)?j:U(xe(t.settings),(r,n)=>r.values.includes(n))},ye=(e,t)=>{const r=U(t,(n,o)=>o!==void 0&&o!==e[n.key]);return Object.keys(r).length===0?e:Object.freeze({...e,...r})},Te=(e,t,r,n)=>U({...e,[t]:r},(o,i)=>i!==void 0&&!(o.key===t&&i===n[t])),Re=e=>JSON.stringify({version:K,settings:e}),Ie=(e,t,r)=>e===void 0||t===void 0?e===t?0:e===void 0?1:-1:r*(e-t),Ne=e=>{const{sortMode:t,folderPlacement:r}=e;if(t==="native"&&r==="mixed")return;const n=(o,i)=>{const a=D.compare(o.name,i.name);return a!==0?a:D.compare(o.path,i.path)};return(o,i)=>{if(r!=="mixed"&&o.type!==i.type)return o.type==="directory"==(r==="first")?-1:1;if(t==="native")return 0;if(t==="asc")return n(o,i);if(t==="desc")return-n(o,i);const a=Ie(o.modifiedAt,i.modifiedAt,t==="oldest"?1:-1);return a!==0?a:n(o,i)}},f=(1+Math.sqrt(5))/2,ke=100/f**3,Ae=100/f**4,X=100/f**2,Z=13,Le=16,Pe=Object.freeze({gripThickness:5,gripLength:34,barThickness:2,barLength:21}),Ce=Object.freeze([89,144,233,377]),ve=34,Me=44,$e=24,De=1/f,ze=1/f**3,je="40ch",Ve=e=>{if(!Number.isFinite(e)||e<=0)throw new RangeError(`[markdown-explorer] rootFontPixels must be a finite number > 0; got ${String(e)}`)},Y=e=>(Ve(e),Z*e),Fe=e=>Y(e)*f**2,Ue=233,Xe=Ce[0],W=(e,t)=>{if(!Number.isFinite(t)||t<0)throw new RangeError(`[markdown-explorer] ${e} must be a finite number >= 0; got ${String(t)}`)},Ge=({trackInlineSize:e,gap:t,minColumnInlineSize:r,logicalColumns:n})=>{if(W("trackInlineSize",e),W("gap",t),!Number.isFinite(r)||r<=0)throw new RangeError(`[markdown-explorer] minColumnInlineSize must be a finite number > 0; got ${String(r)}`);if(!Number.isInteger(n)||n<1)throw new RangeError(`[markdown-explorer] logicalColumns must be a positive integer; got ${String(n)}`);const o=Math.floor((e+t)/(r+t));return Math.min(n,Math.max(1,o))},We=(e,t)=>{const{trackInlineSize:r,gap:n,minColumnInlineSize:o,logicalColumns:i}=t;if(!([r,n,o].every(Number.isFinite)&&r>0&&n>=0&&o>0))return e;const c=Ge(t);if(e===null||c===e)return c;const s=Math.min(i,Math.max(1,e));if(c>s){const A=(s+1)*o+s*n+n/f;return r>=A?c:s}return r>=s*o+(s-1)*n?s:c},He=(e,t)=>{if(!(Number.isInteger(e)&&Number.isInteger(t))||t<1||t>e)throw new RangeError(`[markdown-explorer] visible columns must be an integer in 1..${String(e)}; got ${String(t)}`);return Array.from({length:t},(r,n)=>[Math.floor(n*e/t),Math.floor((n+1)*e/t)])},Je=31536e3,qe=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u,Be=e=>{if(typeof e!="string"||!qe.test(e))throw new RangeError(`[markdown-explorer] settingsCookie must be a cookie-name token; got ${JSON.stringify(e)}`)},H=e=>typeof e=="number"&&Number.isFinite(e)&&e>0&&e<=X,Ke=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))return{};const r=e,{treeExplorer:n,multiExplorer:o,style:i,align:a}=r;return{...H(n)?{treeExplorer:n}:{},...H(o)?{multiExplorer:o}:{},...typeof i=="string"&&t.includes(i)?{style:i}:{},...typeof a=="string"&&b.CONTENT_ALIGNS.includes(a)?{align:a}:{}}},Ze=(e,t)=>{if(e!==null)for(const r of e.split(";")){const n=r.indexOf("=");if(!(n<0)&&r.slice(0,n).trim()===t)return r.slice(n+1).trim()}},Ye=(e,t)=>{if(e===void 0||e==="")return{};try{return Ke(JSON.parse(decodeURIComponent(e)),t)}catch{return{}}},I=100,Qe=Math.floor(X*I)/I,et=e=>{const t=r=>Math.min(Qe,Math.max(1,Math.round(r*I))/I);return encodeURIComponent(JSON.stringify({...e.treeExplorer===void 0?{}:{treeExplorer:t(e.treeExplorer)},...e.multiExplorer===void 0?{}:{multiExplorer:t(e.multiExplorer)},...e.style===void 0?{}:{style:e.style},...e.align===void 0?{}:{align:e.align}}))},tt=(e,t,r)=>`${e}=${et(t)}; Path=/; Max-Age=${String(Je)}; SameSite=Lax${r?"; Secure":""}`,V=Object.freeze({tree:"tree",multi:"multi",single:"single"}),Q=Object.freeze({default:12,min:1,max:64}),ee=Object.freeze({default:4,min:1,max:6}),te=Object.freeze({default:500,min:1,max:1e4}),re=Object.freeze({default:16,min:1,max:64}),ne=Object.freeze({default:16,min:1,max:64}),rt=/^\/(?:[A-Za-z0-9._~-]+\/)*[A-Za-z0-9._~-]+$/u,nt=/^[A-Za-z0-9][A-Za-z0-9_-]*$/u,ot=/^[a-z0-9][a-z0-9-]*$/u,it=/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/u,J=(e,t)=>{if(typeof t!="string")throw new TypeError(`[markdown-explorer] ${e} must be a string; got ${typeof t}`);if(!rt.test(t)||t.split("/").some(r=>r==="."||r===".."))throw new RangeError(`[markdown-explorer] ${e} must start with "/", have no trailing "/", and use only letters, digits and "._~-" in each segment; got ${JSON.stringify(t)}`)},d=e=>typeof e=="string"?JSON.stringify(e):typeof e=="bigint"?`${String(e)}n`:Object.is(e,-0)?"-0":typeof e=="function"?"a function":Array.isArray(e)?"an array":e!==null&&typeof e=="object"?k(e)?"a plain object":`a non-plain object (${Object.prototype.toString.call(e)})`:String(e),p=(e,t,r)=>{if(t===void 0)return[];if(!k(t))throw new TypeError(`[markdown-explorer] ${e} must be a plain object; got ${d(t)}`);const n=Object.entries(t);for(const[o]of n)if(!r.includes(o))throw new RangeError(`[markdown-explorer] ${e}.${o} is not an option; expected ${r.join(", ")}`);return n.filter(([,o])=>o!==void 0)},st=e=>{const t={...V};for(const[r,n]of p("views",e,Object.keys(V)))t[r]=n;for(const[r,n]of Object.entries(t))if(typeof n!="string"||!nt.test(n))throw new RangeError(`[markdown-explorer] views.${r} must start with a letter or digit and use only letters, digits, "_" and "-"; got ${JSON.stringify(n)}`);return Object.freeze(t)},x=(e,t,r)=>{if(t===void 0)return r.default;if(typeof t!="number"||!Number.isInteger(t)||t<r.min||t>r.max)throw new RangeError(`[markdown-explorer] ${e} must be an integer in ${String(r.min)}..${String(r.max)}; got ${d(t)}`);return t},at=(e,t)=>{const r=new Map(p("embeds",e,["providers","linkCards","linkCardSize"]));if(r.size===0)return O.NO_EMBEDS;const n=r.has("providers")?r.get("providers"):[];if(!Array.isArray(n))throw new RangeError(`[markdown-explorer] embeds.providers must be an array of provider ids; got ${d(n)}`);for(const c of n)if(!O.isEmbedProviderId(c))throw new RangeError(`[markdown-explorer] embeds.providers must hold only ${O.EMBED_PROVIDER_IDS.join(", ")}; got ${d(c)}`);const o=r.has("linkCards")?r.get("linkCards"):!1;if(typeof o!="boolean")throw new RangeError(`[markdown-explorer] embeds.linkCards must be a boolean; got ${d(o)}`);const i={providers:Object.freeze([...new Set(n)]),linkCardEndpoint:o?N.explorerLinkCardEndpoint(t):null};if(!r.has("linkCardSize"))return Object.freeze(i);const a=r.get("linkCardSize");if(!O.isLinkCardSize(a))throw new RangeError(`[markdown-explorer] embeds.linkCardSize must be one of ${O.LINK_CARD_SIZES.join(", ")}; got ${d(a)}`);if(!o)throw new RangeError(`[markdown-explorer] embeds.linkCardSize needs embeds.linkCards: true; got linkCardSize ${d(a)} with linkCards ${d(o)}`);return Object.freeze({...i,linkCardSize:a})},lt=e=>{const t=new Map(p("defaultTreeSettings",e,S.map(n=>n.key)));if(t.size===0)return z;const r={...z};for(const n of S){if(!t.has(n.key))continue;const o=t.get(n.key),i=n.values;if(!i.includes(o))throw new RangeError(`[markdown-explorer] defaultTreeSettings.${n.key} must be one of ${i.map(d).join(", ")}; got ${d(o)}`);r[n.key]=o}return Object.freeze(r)},oe=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] the explorer configuration must be an object");J("basePath",e.basePath),J("dataPath",e.dataPath);const t=st(e.views);if(new Set([t.tree,t.multi,t.single]).size!==3)throw new RangeError(`[markdown-explorer] the view slugs must differ; got ${JSON.stringify(t)}`);if(e.dataPath===e.basePath)throw new RangeError("[markdown-explorer] dataPath must differ from basePath");if(e.dataPath.startsWith(`${e.basePath}/`)){const s=e.dataPath.slice(e.basePath.length+1).split("/")[0];if(s===t.tree||s===t.multi||s===t.single)throw new RangeError(`[markdown-explorer] dataPath must not start with a view slug under basePath; got ${JSON.stringify(e.dataPath)}`)}Be(e.settingsCookie);const r=e.iframeHosts??[];if(!Array.isArray(r)||r.some(s=>typeof s!="string"||!it.test(s)))throw new RangeError(`[markdown-explorer] iframeHosts must be lowercase host names without scheme, port or path; got ${JSON.stringify(r)}`);const n=Object.fromEntries(p("multiView",e.multiView,["maxPanels","columns"])),o=Object.fromEntries(p("expandAll",e.expandAll,["maxFolders","maxDepth"])),i=Object.fromEntries(p("revealDocument",e.revealDocument,["maxDepth"])),a=e.documentStyles??b.DEFAULT_MARKDOWN_STYLES;if(!Array.isArray(a)||a.length===0)throw new RangeError("[markdown-explorer] documentStyles must be a non-empty array");const c=new Set;for(const s of a){if(s===null||typeof s!="object"||typeof s.name!="string"||s.name.trim()===""||typeof s.className!="string")throw new RangeError("[markdown-explorer] each document style needs a non-blank name and a className string");if(c.has(s.name))throw new RangeError(`[markdown-explorer] document style names must be unique; ${JSON.stringify(s.name)} repeats`);c.add(s.name)}return Object.freeze({basePath:e.basePath,dataPath:e.dataPath,settingsCookie:e.settingsCookie,views:t,multiView:Object.freeze({maxPanels:x("multiView.maxPanels",n.maxPanels,Q),columns:x("multiView.columns",n.columns,ee)}),expandAll:Object.freeze({maxFolders:x("expandAll.maxFolders",o.maxFolders,te),maxDepth:x("expandAll.maxDepth",o.maxDepth,re)}),revealDocument:Object.freeze({maxDepth:x("revealDocument.maxDepth",i.maxDepth,ne)}),documentStyles:Object.freeze(a.map(s=>Object.freeze({name:s.name,className:s.className}))),iframeHosts:Object.freeze([...new Set(r)]),embeds:at(e.embeds,e.dataPath),defaultTreeSettings:lt(e.defaultTreeSettings)})},ct=e=>{const t=e.embeds;if(!k(t))throw new TypeError(`[markdown-explorer] config.embeds must be the embeds defineExplorerConfig resolved; got ${d(t)}`);if(Object.hasOwn(t,"linkCards"))throw new RangeError(`[markdown-explorer] config.embeds.linkCards is an option of defineExplorerConfig, not a key of the embeds it resolves; pass the option to defineExplorerConfig (got linkCards ${d(t.linkCards)})`);const{linkCardEndpoint:r,...n}=t,o=oe({...e,embeds:{...n,linkCards:r!==null}});if(o.embeds.linkCardEndpoint!==r)throw new RangeError(`[markdown-explorer] config.embeds.linkCardEndpoint must be ${d(o.embeds.linkCardEndpoint)} (the data route's link-card path) or null; got ${d(r)}`);return o},ie=e=>typeof e=="string"&&ot.test(e),dt=(e,t)=>{if(e===null||typeof e!="object")throw new TypeError(`[markdown-explorer] withExplorerSources needs the configuration of defineExplorerConfig; got ${d(e)}`);if(!Array.isArray(t)||t.length===0)throw new RangeError(`[markdown-explorer] sourceIds must be a non-empty array; got ${d(t)}`);for(const r of t)if(!ie(r))throw new RangeError(`[markdown-explorer] each source id must use lowercase letters, digits and "-" and start with a letter or digit; got ${d(r)}`);if(new Set(t).size!==t.length)throw new RangeError(`[markdown-explorer] source ids must be unique; got ${JSON.stringify(t)}`);return Object.freeze({...e,sourceIds:Object.freeze([...t])})},mt=e=>e.documentStyles.map(t=>t.name),l=Object.freeze({source:"source",doc:"doc",maximized:"maximized",style:"style",align:"align",showToc:"showToc",showStyle:"showStyle",showAlign:"showAlign",padding:"padding",width:"width",maxWidth:"maxWidth",markup:"markup"}),se="true",q=".data",ae=256,le=/^\d+(?:\.\d+)?$/u,F=/^\d+(?:\.\d+)?(?:px|rem|em|ch|vw|%)$/u,ce=Object.freeze(["showToc","showStyle","showAlign"]),ut=e=>{const t=encodeURIComponent(e.replaceAll("%","%25"));return t.endsWith(q)?`${t.slice(0,-q.length)}%2Edata`:t},ft=e=>e.replaceAll("%25","%"),de=e=>{const{sourceIds:t}=e;if(t===void 0)throw new TypeError("[markdown-explorer] the configuration has no source ids; join the server's sources with withExplorerSources(config, sourceIds)");return t},gt=(e,t,r)=>{const n=r.getAll(l.source);if(n.length===0)return t;const[o]=n;return n.length>1||o===void 0||o===t||!e.includes(o)?null:o},Et=(e,t)=>{const r=t.get(l.style),n=t.get(l.align);return{...r!==null&&e.documentStyles.some(o=>o.name===r)?{style:r}:{},...n!==null&&b.CONTENT_ALIGNS.includes(n)?{align:n}:{}}},me=e=>Number.isFinite(e)&&e>=0&&e<=ae&&le.test(String(e)),wt=e=>{const t=e.get(l.padding),r=t!==null&&le.test(t)?Number(t):Number.NaN,n=e.get(l.width),o=e.get(l.maxWidth);return{...e.get(l.showToc)==="false"?{showToc:!1}:{},...e.get(l.showStyle)==="false"?{showStyle:!1}:{},...e.get(l.showAlign)==="false"?{showAlign:!1}:{},...me(r)?{padding:r}:{},...n!==null&&F.test(n)?{width:n}:{},...o!==null&&F.test(o)?{maxWidth:o}:{}}},ue=(e,t)=>[...new Set(t.filter(N.isAcceptableDocumentPath))].slice(0,e.multiView.maxPanels),pt=(e,t,r,n)=>{for(const i of t)fe(i);if(new Set(t).size!==t.length)throw new RangeError(`[markdown-explorer] multi-view documents must each appear once; got ${String(t.length)} with repeats`);if(t.length>e.multiView.maxPanels)throw new RangeError(`[markdown-explorer] the multi view opens at most ${String(e.multiView.maxPanels)} documents; got ${String(t.length)}`);if(r!==null&&!t.includes(r))throw new RangeError(`[markdown-explorer] the maximized document must be one of the open documents; got ${JSON.stringify(r.slice(0,80))}`);if(new Set(n).size!==n.length)throw new RangeError(`[markdown-explorer] the documents shown as written must each appear once; got ${String(n.length)} with repeats`);const o=n.find(i=>!t.includes(i));if(o!==void 0)throw new RangeError(`[markdown-explorer] a document shown as written must be one of the open documents; got ${JSON.stringify(o.slice(0,80))}`)},fe=e=>{if(!N.isAcceptableDocumentPath(e))throw new RangeError(`[markdown-explorer] not an acceptable document path: ${JSON.stringify(String(e).slice(0,80))}`);return e},St=(e,t)=>{if(t.style!==void 0&&!e.documentStyles.some(r=>r.name===t.style))throw new RangeError(`[markdown-explorer] overrides.style must name a configured document style (${e.documentStyles.map(r=>JSON.stringify(r.name)).join(", ")}); got ${JSON.stringify(t.style)}`);if(t.align!==void 0&&!b.CONTENT_ALIGNS.includes(t.align))throw new RangeError(`[markdown-explorer] overrides.align must be one of ${b.CONTENT_ALIGNS.join(", ")}; got ${JSON.stringify(t.align)}`)},ht=e=>{for(const t of ce)if(e[t]!==void 0&&typeof e[t]!="boolean")throw new RangeError(`[markdown-explorer] embed.${t} must be a boolean; got ${JSON.stringify(e[t])}`);if(e.padding!==void 0&&!me(e.padding))throw new RangeError(`[markdown-explorer] embed.padding must be 0..${String(ae)} px in plain decimal digits; got ${String(e.padding)}`);for(const t of["width","maxWidth"]){const r=e[t];if(r!==void 0&&!F.test(r))throw new RangeError(`[markdown-explorer] embed.${t} must be a CSS length in px, rem, em, ch, vw or %; got ${JSON.stringify(r)}`)}},ge=(e,t)=>{const r=new URLSearchParams;let n=`${e.basePath}/${e.views[t.view]}`;if(t.view==="multi"){const i=t.docs??[],a=t.maximized??null,c=t.markup??[];pt(e,i,a,c);for(const s of i)r.append(l.doc,s);a!==null&&r.set(l.maximized,a);for(const s of i)c.includes(s)&&r.append(l.markup,s)}else t.doc!==void 0&&t.doc!==null&&(n+=`/${ut(fe(t.doc))}`);if(t.source!==void 0){const i=de(e);if(!i.includes(t.source))throw new RangeError(`[markdown-explorer] unknown source ${JSON.stringify(t.source)}; expected one of ${i.join(", ")}`);t.source!==i[0]&&r.set(l.source,t.source)}if(t.view!=="multi"&&t.overrides!==void 0&&(St(e,t.overrides),t.overrides.style!==void 0&&r.set(l.style,t.overrides.style),t.overrides.align!==void 0&&r.set(l.align,t.overrides.align)),t.view!=="multi"&&t.markup===!0){if(t.doc===void 0||t.doc===null)throw new RangeError("[markdown-explorer] a tree view without a document has nothing to show as written");r.set(l.markup,se)}if(t.view==="single"&&t.embed!==void 0){const{embed:i}=t;ht(i);for(const a of ce)i[a]===!1&&r.set(l[a],"false");i.padding!==void 0&&r.set(l.padding,String(i.padding)),i.width!==void 0&&r.set(l.width,i.width),i.maxWidth!==void 0&&r.set(l.maxWidth,i.maxWidth)}const o=r.toString();return o===""?n:`${n}?${o}`},_t=(e,t)=>Object.keys(e.views).find(r=>e.views[r]===t),Ot=(e,t,r)=>{const n=de(e),[o]=n;if(o===void 0)throw new RangeError("[markdown-explorer] the configuration has no source");const i=gt(n,o,r),a=i===null?o:i,c=m=>({kind:"redirect",href:ge(e,m),location:m}),s=()=>c({view:"tree",source:a,doc:null,overrides:{},markup:!1});if(t===void 0||t==="")return s();const h=t.indexOf("/"),A=h<0?t:t.slice(0,h),L=h<0?null:t.slice(h+1),g=_t(e,A);if(g===void 0)return s();if(g==="multi"){const m=r.getAll(l.doc),w=ue(e,m),P=r.getAll(l.maximized),[C]=P,v=P.length===1&&C!==void 0&&w.includes(C)?C:null,M=r.getAll(l.markup),R=w.filter(_=>M.includes(_)),Ee=R.length===M.length&&R.every((_,$)=>_===M[$]);return L===null&&i!==null&&w.length===m.length&&w.every((_,$)=>_===m[$])&&(P.length===0||v!==null)&&Ee?{kind:"location",location:{view:"multi",source:a,docs:w,maximized:v,markup:R}}:c({view:"multi",source:a,docs:w,maximized:v,markup:R})}const u=L===null?null:ft(L);if(u!==null&&!N.isAcceptableDocumentPath(u))return s();const y=Et(e,r),T=u!==null&&r.get(l.markup)===se;if(g==="single"){if(u===null)return s();const m=wt(r);return i===null?c({view:g,source:a,doc:u,overrides:y,embed:m,markup:T}):{kind:"location",location:{view:g,source:a,doc:u,overrides:y,embed:m,markup:T}}}return i===null?c({view:g,source:a,doc:u,overrides:y,markup:T}):{kind:"location",location:{view:g,source:a,doc:u,overrides:y,markup:T}}};exports.ASSUMED_ROOT_FONT_PIXELS=Le;exports.COARSE_TARGET_PIXELS=Me;exports.COLUMN_MIN_MEASURE=je;exports.CONTROL_BLOCK_PIXELS=ve;exports.DEFAULT_TREE_SETTINGS=z;exports.DEFAULT_VIEW_SLUGS=V;exports.EXPAND_ALL_DEPTH_LIMITS=re;exports.EXPAND_ALL_FOLDER_LIMITS=te;exports.EXPLORER_DEFAULT_PERCENT=ke;exports.EXPLORER_MAX_PERCENT=X;exports.EXPLORER_MIN_REM=Z;exports.EXPLORER_MULTI_DEFAULT_PERCENT=Ae;exports.EXPLORER_WIDTH_PERSIST_DELAY_MS=Ue;exports.FINE_TARGET_PIXELS=$e;exports.GOLDEN_RATIO=f;exports.MULTI_VIEW_COLUMN_LIMITS=ee;exports.MULTI_VIEW_PANEL_LIMITS=Q;exports.NAME_COLLATOR=D;exports.NO_TREE_SETTING_CHANGES=j;exports.PANEL_MAX_BLOCK_RATIO=De;exports.PANEL_MIN_BLOCK_RATIO=ze;exports.PREFETCH_DWELL_MS=Xe;exports.REVEAL_DOCUMENT_DEPTH_LIMITS=ne;exports.SPLIT_HANDLE_PIXELS=Pe;exports.advanceTreeSetting=_e;exports.applyTreeSettingChanges=ye;exports.canonicalMultiDocuments=ue;exports.columnGroups=He;exports.createEntryComparator=Ne;exports.defineExplorerConfig=oe;exports.documentStyleNames=mt;exports.explorerHref=ge;exports.explorerMinPixels=Y;exports.explorerSheetBelowPixels=Fe;exports.formatTreeSettingValue=Oe;exports.isExplorerSourceId=ie;exports.isPlainObject=k;exports.parseViewSettings=Ye;exports.readCookieValue=Ze;exports.readTreeSettingChanges=be;exports.recordTreeSettingChange=Te;exports.replanVisibleColumns=We;exports.resolveExplorerLocation=Ot;exports.revalidateExplorerConfig=ct;exports.serializeTreeSettingChanges=Re;exports.viewSettingsCookieString=tt;exports.visibleTreeSettingDescriptors=he;exports.withExplorerSources=dt;
|
|
1
|
+
"use strict";const O=require("@aiquants/markdown/embeds"),b=require("@aiquants/markdown/viewer-settings"),N=require("./dataRoute-CH3yOKR0.cjs"),k=e=>{if(e===null||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},D=new Intl.Collator("en",{numeric:!0,sensitivity:"variant"}),z=Object.freeze({sortMode:"native",folderPlacement:"mixed",selectionMode:"single",doubleClickAction:"recursive",expandIconSize:8,alwaysExpanded:!1,revealDocument:!1,removeRootIndent:!1,lines:!0,expandIcons:!0,directoryIcons:!0,fileIcons:!0}),we=[!0,!1],pe=(e,t)=>t?e.settingOn:e.settingOff,E=(e,t)=>({key:e,labelKey:t,values:we,formatValue:pe,requiresItemSelection:!1}),Se=Object.freeze({native:e=>e.sortNative,asc:e=>e.sortAscending,desc:e=>e.sortDescending,oldest:e=>e.sortOldest,newest:e=>e.sortNewest}),S=Object.freeze([{key:"sortMode",labelKey:"settingSortMode",values:["native","asc","desc","oldest","newest"],formatValue:(e,t)=>Se[t](e),requiresItemSelection:!1},{key:"folderPlacement",labelKey:"settingFolderPlacement",values:["mixed","first","last"],formatValue:(e,t)=>t==="mixed"?e.folderPlacementMixed:t==="first"?e.folderPlacementFirst:e.folderPlacementLast,requiresItemSelection:!1},{key:"selectionMode",labelKey:"settingSelectionMode",values:["single","multiple","none"],formatValue:(e,t)=>t==="single"?e.selectionSingle:t==="multiple"?e.selectionMultiple:e.selectionNone,requiresItemSelection:!0},{key:"doubleClickAction",labelKey:"settingDoubleClick",values:["recursive","toggle"],formatValue:(e,t)=>t==="recursive"?e.doubleClickRecursive:e.doubleClickToggle,requiresItemSelection:!1},{key:"expandIconSize",labelKey:"settingExpandIconSize",values:[8,13,5],formatValue:(e,t)=>e.expandIconSizeValue(t),requiresItemSelection:!1},E("alwaysExpanded","settingAlwaysExpanded"),E("revealDocument","settingRevealDocument"),E("removeRootIndent","settingRemoveRootIndent"),E("lines","settingTreeLines"),E("expandIcons","settingExpandIcons"),E("directoryIcons","settingDirectoryIcons"),E("fileIcons","settingFileIcons")]),he=e=>e?S:S.filter(t=>!t.requiresItemSelection),B=e=>{const t=S.find(r=>r.key===e);if(t===void 0)throw new RangeError(`[markdown-explorer] no tree setting descriptor for ${e}`);return t},_e=(e,t)=>{const r=B(t).values,n=r[(r.indexOf(e[t])+1)%r.length];return{...e,[t]:n}},Oe=(e,t,r)=>B(r).formatValue(e,t[r]),K=2,j=Object.freeze({}),U=(e,t)=>Object.freeze(Object.fromEntries(S.filter(r=>t(r,e[r.key])).map(r=>[r.key,e[r.key]]))),G="directoriesFirst",xe=e=>{if(!Object.hasOwn(e,G))return e;const{[G]:t,...r}=e;return Object.hasOwn(r,"folderPlacement")||typeof t!="boolean"?r:{...r,folderPlacement:t?"first":"mixed"}},be=e=>{if(e===null||typeof e!="object"||Array.isArray(e))return j;const t=e;return t.version!==K||t.settings===null||typeof t.settings!="object"||Array.isArray(t.settings)?j:U(xe(t.settings),(r,n)=>r.values.includes(n))},ye=(e,t)=>{const r=U(t,(n,o)=>o!==void 0&&o!==e[n.key]);return Object.keys(r).length===0?e:Object.freeze({...e,...r})},Te=(e,t,r,n)=>U({...e,[t]:r},(o,i)=>i!==void 0&&!(o.key===t&&i===n[t])),Re=e=>JSON.stringify({version:K,settings:e}),Ie=(e,t,r)=>e===void 0||t===void 0?e===t?0:e===void 0?1:-1:r*(e-t),Ne=e=>{const{sortMode:t,folderPlacement:r}=e;if(t==="native"&&r==="mixed")return;const n=(o,i)=>{const a=D.compare(o.name,i.name);return a!==0?a:D.compare(o.path,i.path)};return(o,i)=>{if(r!=="mixed"&&o.type!==i.type)return o.type==="directory"==(r==="first")?-1:1;if(t==="native")return 0;if(t==="asc")return n(o,i);if(t==="desc")return-n(o,i);const a=Ie(o.modifiedAt,i.modifiedAt,t==="oldest"?1:-1);return a!==0?a:n(o,i)}},f=(1+Math.sqrt(5))/2,ke=100/f**3,Ae=100/f**4,X=100/f**2,Z=13,Le=16,Pe=Object.freeze({gripThickness:5,gripLength:34,barThickness:2,barLength:21}),Ce=Object.freeze([89,144,233,377]),ve=34,Me=44,$e=24,De=1/f,ze=1/f**3,je="40ch",Ve=e=>{if(!Number.isFinite(e)||e<=0)throw new RangeError(`[markdown-explorer] rootFontPixels must be a finite number > 0; got ${String(e)}`)},Y=e=>(Ve(e),Z*e),Fe=e=>Y(e)*f**2,Ue=233,Xe=Ce[0],W=(e,t)=>{if(!Number.isFinite(t)||t<0)throw new RangeError(`[markdown-explorer] ${e} must be a finite number >= 0; got ${String(t)}`)},Ge=({trackInlineSize:e,gap:t,minColumnInlineSize:r,logicalColumns:n})=>{if(W("trackInlineSize",e),W("gap",t),!Number.isFinite(r)||r<=0)throw new RangeError(`[markdown-explorer] minColumnInlineSize must be a finite number > 0; got ${String(r)}`);if(!Number.isInteger(n)||n<1)throw new RangeError(`[markdown-explorer] logicalColumns must be a positive integer; got ${String(n)}`);const o=Math.floor((e+t)/(r+t));return Math.min(n,Math.max(1,o))},We=(e,t)=>{const{trackInlineSize:r,gap:n,minColumnInlineSize:o,logicalColumns:i}=t;if(!([r,n,o].every(Number.isFinite)&&r>0&&n>=0&&o>0))return e;const c=Ge(t);if(e===null||c===e)return c;const s=Math.min(i,Math.max(1,e));if(c>s){const A=(s+1)*o+s*n+n/f;return r>=A?c:s}return r>=s*o+(s-1)*n?s:c},He=(e,t)=>{if(!(Number.isInteger(e)&&Number.isInteger(t))||t<1||t>e)throw new RangeError(`[markdown-explorer] visible columns must be an integer in 1..${String(e)}; got ${String(t)}`);return Array.from({length:t},(r,n)=>[Math.floor(n*e/t),Math.floor((n+1)*e/t)])},Je=31536e3,qe=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u,Be=e=>{if(typeof e!="string"||!qe.test(e))throw new RangeError(`[markdown-explorer] settingsCookie must be a cookie-name token; got ${JSON.stringify(e)}`)},H=e=>typeof e=="number"&&Number.isFinite(e)&&e>0&&e<=X,Ke=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))return{};const r=e,{treeExplorer:n,multiExplorer:o,style:i,align:a}=r;return{...H(n)?{treeExplorer:n}:{},...H(o)?{multiExplorer:o}:{},...typeof i=="string"&&t.includes(i)?{style:i}:{},...typeof a=="string"&&b.CONTENT_ALIGNS.includes(a)?{align:a}:{}}},Ze=(e,t)=>{if(e!==null)for(const r of e.split(";")){const n=r.indexOf("=");if(!(n<0)&&r.slice(0,n).trim()===t)return r.slice(n+1).trim()}},Ye=(e,t)=>{if(e===void 0||e==="")return{};try{return Ke(JSON.parse(decodeURIComponent(e)),t)}catch{return{}}},I=100,Qe=Math.floor(X*I)/I,et=e=>{const t=r=>Math.min(Qe,Math.max(1,Math.round(r*I))/I);return encodeURIComponent(JSON.stringify({...e.treeExplorer===void 0?{}:{treeExplorer:t(e.treeExplorer)},...e.multiExplorer===void 0?{}:{multiExplorer:t(e.multiExplorer)},...e.style===void 0?{}:{style:e.style},...e.align===void 0?{}:{align:e.align}}))},tt=(e,t,r)=>`${e}=${et(t)}; Path=/; Max-Age=${String(Je)}; SameSite=Lax${r?"; Secure":""}`,V=Object.freeze({tree:"tree",multi:"multi",single:"single"}),Q=Object.freeze({default:12,min:1,max:64}),ee=Object.freeze({default:4,min:1,max:6}),te=Object.freeze({default:500,min:1,max:1e4}),re=Object.freeze({default:16,min:1,max:64}),ne=Object.freeze({default:16,min:1,max:64}),rt=/^\/(?:[A-Za-z0-9._~-]+\/)*[A-Za-z0-9._~-]+$/u,nt=/^[A-Za-z0-9][A-Za-z0-9_-]*$/u,ot=/^[a-z0-9][a-z0-9-]*$/u,it=/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/u,J=(e,t)=>{if(typeof t!="string")throw new TypeError(`[markdown-explorer] ${e} must be a string; got ${typeof t}`);if(!rt.test(t)||t.split("/").some(r=>r==="."||r===".."))throw new RangeError(`[markdown-explorer] ${e} must start with "/", have no trailing "/", and use only letters, digits and "._~-" in each segment; got ${JSON.stringify(t)}`)},d=e=>typeof e=="string"?JSON.stringify(e):typeof e=="bigint"?`${String(e)}n`:Object.is(e,-0)?"-0":typeof e=="function"?"a function":Array.isArray(e)?"an array":e!==null&&typeof e=="object"?k(e)?"a plain object":`a non-plain object (${Object.prototype.toString.call(e)})`:String(e),p=(e,t,r)=>{if(t===void 0)return[];if(!k(t))throw new TypeError(`[markdown-explorer] ${e} must be a plain object; got ${d(t)}`);const n=Object.entries(t);for(const[o]of n)if(!r.includes(o))throw new RangeError(`[markdown-explorer] ${e}.${o} is not an option; expected ${r.join(", ")}`);return n.filter(([,o])=>o!==void 0)},st=e=>{const t={...V};for(const[r,n]of p("views",e,Object.keys(V)))t[r]=n;for(const[r,n]of Object.entries(t))if(typeof n!="string"||!nt.test(n))throw new RangeError(`[markdown-explorer] views.${r} must start with a letter or digit and use only letters, digits, "_" and "-"; got ${JSON.stringify(n)}`);return Object.freeze(t)},x=(e,t,r)=>{if(t===void 0)return r.default;if(typeof t!="number"||!Number.isInteger(t)||t<r.min||t>r.max)throw new RangeError(`[markdown-explorer] ${e} must be an integer in ${String(r.min)}..${String(r.max)}; got ${d(t)}`);return t},at=(e,t)=>{const r=new Map(p("embeds",e,["providers","linkCards","linkCardSize"]));if(r.size===0)return O.NO_EMBEDS;const n=r.has("providers")?r.get("providers"):[];if(!Array.isArray(n))throw new RangeError(`[markdown-explorer] embeds.providers must be an array of provider ids; got ${d(n)}`);for(const c of n)if(!O.isEmbedProviderId(c))throw new RangeError(`[markdown-explorer] embeds.providers must hold only ${O.EMBED_PROVIDER_IDS.join(", ")}; got ${d(c)}`);const o=r.has("linkCards")?r.get("linkCards"):!1;if(typeof o!="boolean")throw new RangeError(`[markdown-explorer] embeds.linkCards must be a boolean; got ${d(o)}`);const i={providers:Object.freeze([...new Set(n)]),linkCardEndpoint:o?N.explorerLinkCardEndpoint(t):null};if(!r.has("linkCardSize"))return Object.freeze(i);const a=r.get("linkCardSize");if(!O.isLinkCardSize(a))throw new RangeError(`[markdown-explorer] embeds.linkCardSize must be one of ${O.LINK_CARD_SIZES.join(", ")}; got ${d(a)}`);if(!o)throw new RangeError(`[markdown-explorer] embeds.linkCardSize needs embeds.linkCards: true; got linkCardSize ${d(a)} with linkCards ${d(o)}`);return Object.freeze({...i,linkCardSize:a})},lt=e=>{const t=new Map(p("defaultTreeSettings",e,S.map(n=>n.key)));if(t.size===0)return z;const r={...z};for(const n of S){if(!t.has(n.key))continue;const o=t.get(n.key),i=n.values;if(!i.includes(o))throw new RangeError(`[markdown-explorer] defaultTreeSettings.${n.key} must be one of ${i.map(d).join(", ")}; got ${d(o)}`);r[n.key]=o}return Object.freeze(r)},oe=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] the explorer configuration must be an object");J("basePath",e.basePath),J("dataPath",e.dataPath);const t=st(e.views);if(new Set([t.tree,t.multi,t.single]).size!==3)throw new RangeError(`[markdown-explorer] the view slugs must differ; got ${JSON.stringify(t)}`);if(e.dataPath===e.basePath)throw new RangeError("[markdown-explorer] dataPath must differ from basePath");if(e.dataPath.startsWith(`${e.basePath}/`)){const s=e.dataPath.slice(e.basePath.length+1).split("/")[0];if(s===t.tree||s===t.multi||s===t.single)throw new RangeError(`[markdown-explorer] dataPath must not start with a view slug under basePath; got ${JSON.stringify(e.dataPath)}`)}Be(e.settingsCookie);const r=e.iframeHosts??[];if(!Array.isArray(r)||r.some(s=>typeof s!="string"||!it.test(s)))throw new RangeError(`[markdown-explorer] iframeHosts must be lowercase host names without scheme, port or path; got ${JSON.stringify(r)}`);const n=Object.fromEntries(p("multiView",e.multiView,["maxPanels","columns"])),o=Object.fromEntries(p("expandAll",e.expandAll,["maxFolders","maxDepth"])),i=Object.fromEntries(p("revealDocument",e.revealDocument,["maxDepth"])),a=e.documentStyles??b.DEFAULT_MARKDOWN_STYLES;if(!Array.isArray(a)||a.length===0)throw new RangeError("[markdown-explorer] documentStyles must be a non-empty array");const c=new Set;for(const s of a){if(s===null||typeof s!="object"||typeof s.name!="string"||s.name.trim()===""||typeof s.className!="string")throw new RangeError("[markdown-explorer] each document style needs a non-blank name and a className string");if(c.has(s.name))throw new RangeError(`[markdown-explorer] document style names must be unique; ${JSON.stringify(s.name)} repeats`);c.add(s.name)}return Object.freeze({basePath:e.basePath,dataPath:e.dataPath,settingsCookie:e.settingsCookie,views:t,multiView:Object.freeze({maxPanels:x("multiView.maxPanels",n.maxPanels,Q),columns:x("multiView.columns",n.columns,ee)}),expandAll:Object.freeze({maxFolders:x("expandAll.maxFolders",o.maxFolders,te),maxDepth:x("expandAll.maxDepth",o.maxDepth,re)}),revealDocument:Object.freeze({maxDepth:x("revealDocument.maxDepth",i.maxDepth,ne)}),documentStyles:Object.freeze(a.map(s=>Object.freeze({name:s.name,className:s.className}))),iframeHosts:Object.freeze([...new Set(r)]),embeds:at(e.embeds,e.dataPath),defaultTreeSettings:lt(e.defaultTreeSettings)})},ct=e=>{const t=e.embeds;if(!k(t))throw new TypeError(`[markdown-explorer] config.embeds must be the embeds defineExplorerConfig resolved; got ${d(t)}`);if(Object.hasOwn(t,"linkCards"))throw new RangeError(`[markdown-explorer] config.embeds.linkCards is an option of defineExplorerConfig, not a key of the embeds it resolves; pass the option to defineExplorerConfig (got linkCards ${d(t.linkCards)})`);const{linkCardEndpoint:r,...n}=t,o=oe({...e,embeds:{...n,linkCards:r!==null}});if(o.embeds.linkCardEndpoint!==r)throw new RangeError(`[markdown-explorer] config.embeds.linkCardEndpoint must be ${d(o.embeds.linkCardEndpoint)} (the data route's link-card path) or null; got ${d(r)}`);return o},ie=e=>typeof e=="string"&&ot.test(e),dt=(e,t)=>{if(e===null||typeof e!="object")throw new TypeError(`[markdown-explorer] withExplorerSources needs the configuration of defineExplorerConfig; got ${d(e)}`);if(!Array.isArray(t)||t.length===0)throw new RangeError(`[markdown-explorer] sourceIds must be a non-empty array; got ${d(t)}`);for(const r of t)if(!ie(r))throw new RangeError(`[markdown-explorer] each source id must use lowercase letters, digits and "-" and start with a letter or digit; got ${d(r)}`);if(new Set(t).size!==t.length)throw new RangeError(`[markdown-explorer] source ids must be unique; got ${JSON.stringify(t)}`);return Object.freeze({...e,sourceIds:Object.freeze([...t])})},mt=e=>e.documentStyles.map(t=>t.name),l=Object.freeze({source:"source",doc:"doc",maximized:"maximized",style:"style",align:"align",showToc:"showToc",showStyle:"showStyle",showAlign:"showAlign",padding:"padding",width:"width",maxWidth:"maxWidth",markup:"markup"}),se="true",q=".data",ae=256,le=/^\d+(?:\.\d+)?$/u,F=/^\d+(?:\.\d+)?(?:px|rem|em|ch|vw|%)$/u,ce=Object.freeze(["showToc","showStyle","showAlign"]),ut=e=>{const t=encodeURIComponent(e.replaceAll("%","%25"));return t.endsWith(q)?`${t.slice(0,-q.length)}%2Edata`:t},ft=e=>e.replaceAll("%25","%"),de=e=>{const{sourceIds:t}=e;if(t===void 0)throw new TypeError("[markdown-explorer] the configuration has no source ids; join the server's sources with withExplorerSources(config, sourceIds)");return t},gt=(e,t,r)=>{const n=r.getAll(l.source);if(n.length===0)return t;const[o]=n;return n.length>1||o===void 0||o===t||!e.includes(o)?null:o},Et=(e,t)=>{const r=t.get(l.style),n=t.get(l.align);return{...r!==null&&e.documentStyles.some(o=>o.name===r)?{style:r}:{},...n!==null&&b.CONTENT_ALIGNS.includes(n)?{align:n}:{}}},me=e=>Number.isFinite(e)&&e>=0&&e<=ae&&le.test(String(e)),wt=e=>{const t=e.get(l.padding),r=t!==null&&le.test(t)?Number(t):Number.NaN,n=e.get(l.width),o=e.get(l.maxWidth);return{...e.get(l.showToc)==="false"?{showToc:!1}:{},...e.get(l.showStyle)==="false"?{showStyle:!1}:{},...e.get(l.showAlign)==="false"?{showAlign:!1}:{},...me(r)?{padding:r}:{},...n!==null&&F.test(n)?{width:n}:{},...o!==null&&F.test(o)?{maxWidth:o}:{}}},ue=(e,t)=>[...new Set(t.filter(N.isAcceptableDocumentPath))].slice(0,e.multiView.maxPanels),pt=(e,t,r,n)=>{for(const i of t)fe(i);if(new Set(t).size!==t.length)throw new RangeError(`[markdown-explorer] multi-view documents must each appear once; got ${String(t.length)} with repeats`);if(t.length>e.multiView.maxPanels)throw new RangeError(`[markdown-explorer] the multi view opens at most ${String(e.multiView.maxPanels)} documents; got ${String(t.length)}`);if(r!==null&&!t.includes(r))throw new RangeError(`[markdown-explorer] the maximized document must be one of the open documents; got ${JSON.stringify(r.slice(0,80))}`);if(new Set(n).size!==n.length)throw new RangeError(`[markdown-explorer] the documents shown as written must each appear once; got ${String(n.length)} with repeats`);const o=n.find(i=>!t.includes(i));if(o!==void 0)throw new RangeError(`[markdown-explorer] a document shown as written must be one of the open documents; got ${JSON.stringify(o.slice(0,80))}`)},fe=e=>{if(!N.isAcceptableDocumentPath(e))throw new RangeError(`[markdown-explorer] not an acceptable document path: ${JSON.stringify(String(e).slice(0,80))}`);return e},St=(e,t)=>{if(t.style!==void 0&&!e.documentStyles.some(r=>r.name===t.style))throw new RangeError(`[markdown-explorer] overrides.style must name a configured document style (${e.documentStyles.map(r=>JSON.stringify(r.name)).join(", ")}); got ${JSON.stringify(t.style)}`);if(t.align!==void 0&&!b.CONTENT_ALIGNS.includes(t.align))throw new RangeError(`[markdown-explorer] overrides.align must be one of ${b.CONTENT_ALIGNS.join(", ")}; got ${JSON.stringify(t.align)}`)},ht=e=>{for(const t of ce)if(e[t]!==void 0&&typeof e[t]!="boolean")throw new RangeError(`[markdown-explorer] embed.${t} must be a boolean; got ${JSON.stringify(e[t])}`);if(e.padding!==void 0&&!me(e.padding))throw new RangeError(`[markdown-explorer] embed.padding must be 0..${String(ae)} px in plain decimal digits; got ${String(e.padding)}`);for(const t of["width","maxWidth"]){const r=e[t];if(r!==void 0&&!F.test(r))throw new RangeError(`[markdown-explorer] embed.${t} must be a CSS length in px, rem, em, ch, vw or %; got ${JSON.stringify(r)}`)}},ge=(e,t)=>{const r=new URLSearchParams;let n=`${e.basePath}/${e.views[t.view]}`;if(t.view==="multi"){const i=t.docs??[],a=t.maximized??null,c=t.markup??[];pt(e,i,a,c);for(const s of i)r.append(l.doc,s);a!==null&&r.set(l.maximized,a);for(const s of i)c.includes(s)&&r.append(l.markup,s)}else t.doc!==void 0&&t.doc!==null&&(n+=`/${ut(fe(t.doc))}`);if(t.source!==void 0){const i=de(e);if(!i.includes(t.source))throw new RangeError(`[markdown-explorer] unknown source ${JSON.stringify(t.source)}; expected one of ${i.join(", ")}`);t.source!==i[0]&&r.set(l.source,t.source)}if(t.view!=="multi"&&t.overrides!==void 0&&(St(e,t.overrides),t.overrides.style!==void 0&&r.set(l.style,t.overrides.style),t.overrides.align!==void 0&&r.set(l.align,t.overrides.align)),t.view!=="multi"&&t.markup===!0){if(t.doc===void 0||t.doc===null)throw new RangeError("[markdown-explorer] a tree view without a document has nothing to show as written");r.set(l.markup,se)}if(t.view==="single"&&t.embed!==void 0){const{embed:i}=t;ht(i);for(const a of ce)i[a]===!1&&r.set(l[a],"false");i.padding!==void 0&&r.set(l.padding,String(i.padding)),i.width!==void 0&&r.set(l.width,i.width),i.maxWidth!==void 0&&r.set(l.maxWidth,i.maxWidth)}const o=r.toString();return o===""?n:`${n}?${o}`},_t=(e,t)=>Object.keys(e.views).find(r=>e.views[r]===t),Ot=(e,t,r)=>{const n=de(e),[o]=n;if(o===void 0)throw new RangeError("[markdown-explorer] the configuration has no source");const i=gt(n,o,r),a=i===null?o:i,c=m=>({kind:"redirect",href:ge(e,m),location:m}),s=()=>c({view:"tree",source:a,doc:null,overrides:{},markup:!1});if(t===void 0||t==="")return s();const h=t.indexOf("/"),A=h<0?t:t.slice(0,h),L=h<0?null:t.slice(h+1),g=_t(e,A);if(g===void 0)return s();if(g==="multi"){const m=r.getAll(l.doc),w=ue(e,m),P=r.getAll(l.maximized),[C]=P,v=P.length===1&&C!==void 0&&w.includes(C)?C:null,M=r.getAll(l.markup),R=w.filter(_=>M.includes(_)),Ee=R.length===M.length&&R.every((_,$)=>_===M[$]);return L===null&&i!==null&&w.length===m.length&&w.every((_,$)=>_===m[$])&&(P.length===0||v!==null)&&Ee?{kind:"location",location:{view:"multi",source:a,docs:w,maximized:v,markup:R}}:c({view:"multi",source:a,docs:w,maximized:v,markup:R})}const u=L===null?null:ft(L);if(u!==null&&!N.isAcceptableDocumentPath(u))return s();const y=Et(e,r),T=u!==null&&r.get(l.markup)===se;if(g==="single"){if(u===null)return s();const m=wt(r);return i===null?c({view:g,source:a,doc:u,overrides:y,embed:m,markup:T}):{kind:"location",location:{view:g,source:a,doc:u,overrides:y,embed:m,markup:T}}}return i===null?c({view:g,source:a,doc:u,overrides:y,markup:T}):{kind:"location",location:{view:g,source:a,doc:u,overrides:y,markup:T}}};exports.ASSUMED_ROOT_FONT_PIXELS=Le;exports.COARSE_TARGET_PIXELS=Me;exports.COLUMN_MIN_MEASURE=je;exports.CONTROL_BLOCK_PIXELS=ve;exports.DEFAULT_TREE_SETTINGS=z;exports.DEFAULT_VIEW_SLUGS=V;exports.EXPAND_ALL_DEPTH_LIMITS=re;exports.EXPAND_ALL_FOLDER_LIMITS=te;exports.EXPLORER_DEFAULT_PERCENT=ke;exports.EXPLORER_MAX_PERCENT=X;exports.EXPLORER_MIN_REM=Z;exports.EXPLORER_MULTI_DEFAULT_PERCENT=Ae;exports.EXPLORER_WIDTH_PERSIST_DELAY_MS=Ue;exports.FINE_TARGET_PIXELS=$e;exports.GOLDEN_RATIO=f;exports.MULTI_VIEW_COLUMN_LIMITS=ee;exports.MULTI_VIEW_PANEL_LIMITS=Q;exports.NAME_COLLATOR=D;exports.NO_TREE_SETTING_CHANGES=j;exports.PANEL_MAX_BLOCK_RATIO=De;exports.PANEL_MIN_BLOCK_RATIO=ze;exports.PREFETCH_DWELL_MS=Xe;exports.REVEAL_DOCUMENT_DEPTH_LIMITS=ne;exports.SPLIT_HANDLE_PIXELS=Pe;exports.advanceTreeSetting=_e;exports.applyTreeSettingChanges=ye;exports.canonicalMultiDocuments=ue;exports.columnGroups=He;exports.createEntryComparator=Ne;exports.defineExplorerConfig=oe;exports.documentStyleNames=mt;exports.explorerHref=ge;exports.explorerMinPixels=Y;exports.explorerSheetBelowPixels=Fe;exports.formatTreeSettingValue=Oe;exports.isExplorerSourceId=ie;exports.isPlainObject=k;exports.parseViewSettings=Ye;exports.readCookieValue=Ze;exports.readTreeSettingChanges=be;exports.recordTreeSettingChange=Te;exports.replanVisibleColumns=We;exports.resolveExplorerLocation=Ot;exports.revalidateExplorerConfig=ct;exports.serializeTreeSettingChanges=Re;exports.viewSettingsCookieString=tt;exports.visibleTreeSettingDescriptors=he;exports.withExplorerSources=dt;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NO_EMBEDS as oe, isEmbedProviderId as se, EMBED_PROVIDER_IDS as ie, isLinkCardSize as ae, LINK_CARD_SIZES as le } from "@aiquants/markdown/embeds";
|
|
2
2
|
import { CONTENT_ALIGNS as R, DEFAULT_MARKDOWN_STYLES as ce } from "@aiquants/markdown/viewer-settings";
|
|
3
|
-
import { a as de, i as z } from "./dataRoute-
|
|
3
|
+
import { a as de, i as z } from "./dataRoute-Pm_0ue_4.js";
|
|
4
4
|
const j = (e) => {
|
|
5
5
|
if (e === null || typeof e != "object") return !1;
|
|
6
6
|
const t = Object.getPrototypeOf(e);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("node-diff3"),r=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("node-diff3"),r=require("./index-CGBl3fYT.cjs"),R=(n,t,i,l)=>{if(t===n||t===i)return{kind:"clean",text:i};if(i===n)return{kind:"clean",text:t};const d=g.diff3Merge(t.split(`
|
|
2
2
|
`),n.split(`
|
|
3
3
|
`),i.split(`
|
|
4
4
|
`),{excludeFalseConflicts:!0}),o=[];let c=0;const u=s(l.ours),a=s(l.theirs);for(const e of d)e.ok!==void 0?o.push(...e.ok):e.conflict!==void 0&&(c+=1,o.push(`${r.CONFLICT_OURS_MARKER} ${u}`,...e.conflict.a,r.CONFLICT_SEPARATOR,...e.conflict.b,`${r.CONFLICT_THEIRS_MARKER} ${a}`));const f=o.join(`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { diff3Merge as p } from "node-diff3";
|
|
2
|
-
import { C, d as R, e as u } from "./index-
|
|
2
|
+
import { C, d as R, e as u } from "./index-CjCr8czx.js";
|
|
3
3
|
const g = (n, o, e, l) => {
|
|
4
4
|
if (o === n || o === e) return { kind: "clean", text: e };
|
|
5
5
|
if (e === n) return { kind: "clean", text: o };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const i=require("@aiquants/markdown/embeds"),A=require("@aiquants/markdown/source-lines"),h=require("./dataRoute-CH3yOKR0.cjs"),w=512;class R extends RangeError{constructor(s){super(`[markdown-explorer] the HTML nests deeper than ${String(s)} levels`),this.name="HtmlNestingLimitError"}}const O=["script","style","noscript","template","form","button","textarea","select","option","object","embed","base","meta","link","frame","frameset"],D=["srcdoc","formaction"],z=/^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu,H=new Set(["left","right","center","justify","start","end"]),M=new Set(["h1","h2","h3","h4","h5","h6"]),T=1,U=3,B=7,C=8,k=Object.freeze({a:Object.freeze(["target","data-link-kind","data-doc-path","data-doc-exists","data-footnote-ref","data-footnote-backref"]),area:Object.freeze(["target"]),img:Object.freeze(["data-asset-src","data-asset-exists"]),section:Object.freeze(["data-footnotes"]),iframe:Object.freeze(["allow","allowfullscreen","frameborder","referrerpolicy"])}),x=[...new Set([...Object.values(k).flatMap(t=>t.filter(s=>s.startsWith("data-"))),A.SOURCE_LINES_ATTRIBUTE])],j=new Set(["src","href","xlink:href"]),F=/^data:/iu,G=Object.freeze({FORBID_TAGS:O,FORBID_ATTR:D,ADD_TAGS:["iframe"],ADD_ATTR:(t,s)=>t===A.SOURCE_LINES_ATTRIBUTE||k[s]?.includes(t)===!0,ADD_URI_SAFE_ATTR:x,ALLOWED_URI_REGEXP:z,ALLOW_DATA_ATTR:!1}),y=t=>{let s=null;for(const c of t.split(";")){const n=c.indexOf(":");if(n<0||c.slice(0,n).trim().toLowerCase()!=="text-align")continue;const d=c.slice(n+1).trim().toLowerCase();H.has(d)&&(s=d)}return s===null?null:`text-align: ${s}`},V=t=>t.nodeType===U?{kind:"text",text:t.nodeValue??""}:t.nodeType===C||t.nodeType===B?{kind:"ignored"}:t.nodeType===T&&t.nodeName.toLowerCase()==="a"?{kind:"link",href:t.getAttribute("href")}:{kind:"element"},P=t=>{const s=t.getAttribute("type");return s!==null&&s.trim().toLowerCase()==="checkbox"&&t.hasAttribute("disabled")},W=(t,s,c,n)=>{if(t.isSupported!==!0)throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");if(!Number.isSafeInteger(n)||n<=0)throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${String(n)}`);const d=Object.freeze([...s]);let E=new WeakMap,m=new WeakMap,f;const p=r=>{const e=r.parentNode===null?void 0:E.get(r.parentNode),a=e===void 0?0:e+1;if(E.set(r,a),r.nodeType===T&&a>n)throw new R(n)},_=(r,e)=>{if(r.nodeType!==T)return;const a=r;(e.tagName==="input"&&!P(a)||e.tagName==="iframe"&&i.allowedFrameUrlOf(a.getAttribute("src")?.trim(),d)===null)&&a.parentNode?.removeChild(a)},N=(r,e)=>{const a=r.nodeName.toLowerCase();if(e.attrName==="style"){const o=y(e.attrValue);o===null?e.keepAttr=!1:e.attrValue=o}else if(e.attrName==="allow"&&a==="iframe"){const o=i.reduceFrameFeatures(e.attrValue);o===null?e.keepAttr=!1:e.attrValue=o}else if(e.attrName==="referrerpolicy"&&a==="iframe"){const o=e.attrValue.trim().toLowerCase();i.EMBED_FRAME_REFERRER_POLICIES.has(o)?e.attrValue=o:e.keepAttr=!1}else e.attrName===i.EMBED_LINK_ATTRIBUTE&&a==="p"?m.set(r,r.getAttribute(i.EMBED_LINK_ATTRIBUTE)):j.has(e.attrName)&&F.test(e.attrValue)||e.attrName===A.SOURCE_LINES_ATTRIBUTE&&A.parseSourceLines(e.attrValue)===null?e.keepAttr=!1:e.attrName==="id"&&M.has(a)&&(e.forceKeepAttr=!0)},g=r=>{const e=r.getAttribute("data-asset-src");e!==null&&(r.getAttribute("data-asset-exists")!=="false"&&h.isAcceptableDocumentPath(e)?r.setAttribute("src",h.explorerAssetHref(c,e,null)):r.removeAttribute("src"))},S=(r,e,a,o)=>{if(f===void 0)return;const u=r.getAttribute(a);if(u===null)return;const l=f({kind:e,path:u});l!==void 0&&r.setAttribute(o,String(l))},L=r=>{const e=r.parentNode;if(e===null)return;const a=m.get(e);a!=null&&i.placeholderLinkOf(a,[...e.childNodes].map(V))!==null&&e.setAttribute(i.EMBED_LINK_ATTRIBUTE,a)},b=r=>{if(r.nodeType!==T)return;const e=r,a=e.nodeName.toLowerCase();a==="img"?(S(e,"asset","data-asset-src","data-asset-exists"),g(e)):a==="a"&&(S(e,"doc","data-doc-path","data-doc-exists"),L(e));const o=e.getAttribute("target");if(o===null||o.trim().toLowerCase()==="_self")return;const u=e.getAttribute("rel"),l=new Set(u===null?[]:u.split(/\s+/u).filter(I=>I!==""));l.add("noopener"),l.add("noreferrer"),e.setAttribute("rel",[...l].join(" "))};return(r,e)=>{E=new WeakMap,m=new WeakMap,f=e,t.addHook("beforeSanitizeElements",p),t.addHook("uponSanitizeElement",_),t.addHook("uponSanitizeAttribute",N),t.addHook("afterSanitizeAttributes",b);try{return t.sanitize(r,G)}finally{t.removeHook("beforeSanitizeElements",p),t.removeHook("uponSanitizeElement",_),t.removeHook("uponSanitizeAttribute",N),t.removeHook("afterSanitizeAttributes",b),f=void 0}}};exports.HtmlNestingLimitError=R;exports.MAX_HTML_NESTING_DEPTH=w;exports.createHtmlSanitizer=W;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { allowedFrameUrlOf as w, reduceFrameFeatures as L, EMBED_FRAME_REFERRER_POLICIES as O, EMBED_LINK_ATTRIBUTE as T, placeholderLinkOf as D } from "@aiquants/markdown/embeds";
|
|
2
|
+
import { SOURCE_LINES_ATTRIBUTE as p, parseSourceLines as I } from "@aiquants/markdown/source-lines";
|
|
3
|
+
import { i as z, e as x } from "./dataRoute-Pm_0ue_4.js";
|
|
4
|
+
const Z = 512;
|
|
5
|
+
class H extends RangeError {
|
|
6
|
+
constructor(s) {
|
|
7
|
+
super(`[markdown-explorer] the HTML nests deeper than ${String(s)} levels`), this.name = "HtmlNestingLimitError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const M = ["script", "style", "noscript", "template", "form", "button", "textarea", "select", "option", "object", "embed", "base", "meta", "link", "frame", "frameset"], C = ["srcdoc", "formaction"], U = /^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu, j = /* @__PURE__ */ new Set(["left", "right", "center", "justify", "start", "end"]), B = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]), u = 1, F = 3, G = 7, y = 8, S = Object.freeze({
|
|
11
|
+
a: Object.freeze(["target", "data-link-kind", "data-doc-path", "data-doc-exists", "data-footnote-ref", "data-footnote-backref"]),
|
|
12
|
+
area: Object.freeze(["target"]),
|
|
13
|
+
img: Object.freeze(["data-asset-src", "data-asset-exists"]),
|
|
14
|
+
section: Object.freeze(["data-footnotes"]),
|
|
15
|
+
iframe: Object.freeze(["allow", "allowfullscreen", "frameborder", "referrerpolicy"])
|
|
16
|
+
}), V = [.../* @__PURE__ */ new Set([...Object.values(S).flatMap((t) => t.filter((s) => s.startsWith("data-"))), p])], P = /* @__PURE__ */ new Set(["src", "href", "xlink:href"]), W = /^data:/iu, X = Object.freeze({
|
|
17
|
+
FORBID_TAGS: M,
|
|
18
|
+
FORBID_ATTR: C,
|
|
19
|
+
ADD_TAGS: ["iframe"],
|
|
20
|
+
ADD_ATTR: (t, s) => t === p || S[s]?.includes(t) === !0,
|
|
21
|
+
ADD_URI_SAFE_ATTR: V,
|
|
22
|
+
ALLOWED_URI_REGEXP: U,
|
|
23
|
+
ALLOW_DATA_ATTR: !1
|
|
24
|
+
}), $ = (t) => {
|
|
25
|
+
let s = null;
|
|
26
|
+
for (const l of t.split(";")) {
|
|
27
|
+
const n = l.indexOf(":");
|
|
28
|
+
if (n < 0 || l.slice(0, n).trim().toLowerCase() !== "text-align") continue;
|
|
29
|
+
const f = l.slice(n + 1).trim().toLowerCase();
|
|
30
|
+
j.has(f) && (s = f);
|
|
31
|
+
}
|
|
32
|
+
return s === null ? null : `text-align: ${s}`;
|
|
33
|
+
}, K = (t) => t.nodeType === F ? { kind: "text", text: t.nodeValue ?? "" } : t.nodeType === y || t.nodeType === G ? { kind: "ignored" } : t.nodeType === u && t.nodeName.toLowerCase() === "a" ? { kind: "link", href: t.getAttribute("href") } : { kind: "element" }, Y = (t) => {
|
|
34
|
+
const s = t.getAttribute("type");
|
|
35
|
+
return s !== null && s.trim().toLowerCase() === "checkbox" && t.hasAttribute("disabled");
|
|
36
|
+
}, v = (t, s, l, n) => {
|
|
37
|
+
if (t.isSupported !== !0) throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");
|
|
38
|
+
if (!Number.isSafeInteger(n) || n <= 0) throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${String(n)}`);
|
|
39
|
+
const f = Object.freeze([...s]);
|
|
40
|
+
let m = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), d;
|
|
41
|
+
const E = (r) => {
|
|
42
|
+
const e = r.parentNode === null ? void 0 : m.get(r.parentNode), a = e === void 0 ? 0 : e + 1;
|
|
43
|
+
if (m.set(r, a), r.nodeType === u && a > n) throw new H(n);
|
|
44
|
+
}, b = (r, e) => {
|
|
45
|
+
if (r.nodeType !== u) return;
|
|
46
|
+
const a = r;
|
|
47
|
+
(e.tagName === "input" && !Y(a) || e.tagName === "iframe" && w(a.getAttribute("src")?.trim(), f) === null) && a.parentNode?.removeChild(a);
|
|
48
|
+
}, h = (r, e) => {
|
|
49
|
+
const a = r.nodeName.toLowerCase();
|
|
50
|
+
if (e.attrName === "style") {
|
|
51
|
+
const o = $(e.attrValue);
|
|
52
|
+
o === null ? e.keepAttr = !1 : e.attrValue = o;
|
|
53
|
+
} else if (e.attrName === "allow" && a === "iframe") {
|
|
54
|
+
const o = L(e.attrValue);
|
|
55
|
+
o === null ? e.keepAttr = !1 : e.attrValue = o;
|
|
56
|
+
} else if (e.attrName === "referrerpolicy" && a === "iframe") {
|
|
57
|
+
const o = e.attrValue.trim().toLowerCase();
|
|
58
|
+
O.has(o) ? e.attrValue = o : e.keepAttr = !1;
|
|
59
|
+
} else e.attrName === T && a === "p" ? A.set(r, r.getAttribute(T)) : P.has(e.attrName) && W.test(e.attrValue) || e.attrName === p && I(e.attrValue) === null ? e.keepAttr = !1 : e.attrName === "id" && B.has(a) && (e.forceKeepAttr = !0);
|
|
60
|
+
}, k = (r) => {
|
|
61
|
+
const e = r.getAttribute("data-asset-src");
|
|
62
|
+
e !== null && (r.getAttribute("data-asset-exists") !== "false" && z(e) ? r.setAttribute("src", x(l, e, null)) : r.removeAttribute("src"));
|
|
63
|
+
}, N = (r, e, a, o) => {
|
|
64
|
+
if (d === void 0) return;
|
|
65
|
+
const c = r.getAttribute(a);
|
|
66
|
+
if (c === null) return;
|
|
67
|
+
const i = d({ kind: e, path: c });
|
|
68
|
+
i !== void 0 && r.setAttribute(o, String(i));
|
|
69
|
+
}, g = (r) => {
|
|
70
|
+
const e = r.parentNode;
|
|
71
|
+
if (e === null) return;
|
|
72
|
+
const a = A.get(e);
|
|
73
|
+
a != null && D(a, [...e.childNodes].map(K)) !== null && e.setAttribute(T, a);
|
|
74
|
+
}, _ = (r) => {
|
|
75
|
+
if (r.nodeType !== u) return;
|
|
76
|
+
const e = r, a = e.nodeName.toLowerCase();
|
|
77
|
+
a === "img" ? (N(e, "asset", "data-asset-src", "data-asset-exists"), k(e)) : a === "a" && (N(e, "doc", "data-doc-path", "data-doc-exists"), g(e));
|
|
78
|
+
const o = e.getAttribute("target");
|
|
79
|
+
if (o === null || o.trim().toLowerCase() === "_self") return;
|
|
80
|
+
const c = e.getAttribute("rel"), i = new Set(c === null ? [] : c.split(/\s+/u).filter((R) => R !== ""));
|
|
81
|
+
i.add("noopener"), i.add("noreferrer"), e.setAttribute("rel", [...i].join(" "));
|
|
82
|
+
};
|
|
83
|
+
return (r, e) => {
|
|
84
|
+
m = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), d = e, t.addHook("beforeSanitizeElements", E), t.addHook("uponSanitizeElement", b), t.addHook("uponSanitizeAttribute", h), t.addHook("afterSanitizeAttributes", _);
|
|
85
|
+
try {
|
|
86
|
+
return t.sanitize(r, X);
|
|
87
|
+
} finally {
|
|
88
|
+
t.removeHook("beforeSanitizeElements", E), t.removeHook("uponSanitizeElement", b), t.removeHook("uponSanitizeAttribute", h), t.removeHook("afterSanitizeAttributes", _), d = void 0;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export {
|
|
93
|
+
H,
|
|
94
|
+
Z as M,
|
|
95
|
+
v as c
|
|
96
|
+
};
|
package/dist/sanitizeWorker.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const re=require("node:worker_threads"),_=require("parse5"),L=require("@aiquants/markdown/embeds"),H=require("@aiquants/markdown/source-lines"),S=require("isomorphic-dompurify"),G=require("./dataRoute-CIFFX5bd.cjs"),j=512,ne=4096,V=1024,$=Symbol("placement"),W=2,se=3,oe=new Set(["html","head","body"]),N=0,D=1,M=2,Q=3,z=4,O=5,R=6,b=7,q=8,U=9,X=10,w=-1,ae=0,ie=1,le=2,ce=3,ue=4,fe=5,Y=6,de=7,Ee=r=>{switch(r){case 9:case 10:case 12:case 13:case 32:return ae;case 47:return ie;case 62:return le;case 61:return ce;case 34:return ue;case 39:return fe;default:return Y}},Te=Uint8Array.from({length:128},(r,i)=>Ee(i)),P=60,K=47,pe=/[\t\n\f\r />="'<]/g,Ae=/["<]/g,he=/['<]/g,m=-1-M,me=Int8Array.from([[D,U,w,N,N,N,N],[D,U,w,m,m,m,m],[Q,U,w,z,M,M,M],[Q,U,w,z,m,m,m],[z,b,w,b,O,R,b],[O,O,O,O,q,O,O],[R,R,R,R,R,q,R],[D,b,w,b,b,b,b],[D,U,w,m,m,m,m],[D,U,w,m,m,m,m]].flat()),J=r=>r>=65&&r<=90||r>=97&&r<=122,ge=(r,i)=>{let u=new Int32Array(X),f=new Int32Array(X),l=0,A=0,n=0;for(;n<r.length;){if(l===0){const E=r.indexOf("<",n);if(E<0)return!1;n=E+1,r.charCodeAt(n)===K&&(n+=1),J(r.charCodeAt(n))&&(u[N]=0,l=1<<N,n+=1);continue}if((l&-230)===0&&n>=A){const E=l===1<<O?Ae:l===1<<R?he:pe;E.lastIndex=n;const a=E.exec(r);if(a===null)return!1;n=a.index,r.charCodeAt(n)===P&&(A=n+3)}const p=r.charCodeAt(n),g=p<128?Te[p]:Y;let h=0;for(let E=l;E!==0;E&=E-1){const a=31-Math.clz32(E&-E);let e=me[a*de+g],s=u[a];if(e<w&&(e=-1-e,s+=1,s>i))return!0;if(e===w)continue;const T=1<<e;((h&T)===0||s>f[e])&&(f[e]=s),h|=T}J(p)&&(r.charCodeAt(n-1)===P||r.charCodeAt(n-1)===K&&r.charCodeAt(n-2)===P)&&(h&1<<N)===0&&(f[N]=0,h|=1<<N);const I=u;u=f,f=I,l=h,n+=1}return!1};class k extends Error{status;constructor(i){super(`[markdown-explorer] the nesting guard stopped the parse: ${i}`),this.name="ParseStop",this.status=i}}const _e=(r,i,u,f)=>{if(!Number.isSafeInteger(i)||i<=0)throw new RangeError(`[markdown-explorer] the nesting guard's depth limit must be a positive safe integer; got ${String(i)}`);if(!Number.isSafeInteger(u)||u<=0)throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${String(u)}`);if(!Number.isSafeInteger(f)||f<=0)throw new RangeError(`[markdown-explorer] the nesting guard's attribute character budget must be a positive safe integer; got ${String(f)}`);if(ge(r,V))return{status:"too-many-attributes"};const l=i+W,A=r.length+se;let n=null,p=0,g=0,h=0,I=0;const E=t=>{if(g+=t,g>u)throw new k("too-many-nodes")},a=t=>{for(const o of t)I+=o.name.length+o.value.length;if(I>f)throw new k("too-many-attribute-characters")},e=(t,o,c,d)=>{const F={node:t,above:null,levels:o,height:0,keepsChildren:c,attributes:d,first:null,next:null,previous:null},te=t;return te[$]=F,F},s=t=>{const c=t[$];if(c===void 0)throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");return c},T=(t,o)=>{let c=o;for(let d=t;d!==null&&c>d.height;d=d.above)d.height=c,c+=d.levels;if(n!==null&&n.height>l)throw new k("too-deep")},y=t=>{const o=t.above;o?.keepsChildren&&(t.previous===null?o.first=t.next:t.previous.next=t.next,t.next!==null&&(t.next.previous=t.previous)),t.above=null,t.next=null,t.previous=null},C=(t,o)=>{if(!_.defaultTreeAdapter.isElementNode(o))return;const c=s(o),d=s(t);y(c),c.above=d,d.keepsChildren&&(c.next=d.first,d.first!==null&&(d.first.previous=c),d.first=c),o.parentNode=t,T(d,c.height+c.levels)},B={..._.defaultTreeAdapter,createDocument:()=>{const t=_.defaultTreeAdapter.createDocument();return n=e(t,0,!1,0),t},createDocumentFragment:()=>{const t=_.defaultTreeAdapter.createDocumentFragment();return e(t,0,!1,0),t},createElement:(t,o,c)=>{if(p+=1,p>A)throw new k("too-many-elements");E(1+c.length),a(c);const d=_.defaultTreeAdapter.createElement(t,o,c);return e(d,1,!(o===_.html.NS.HTML&&oe.has(t)),c.length),d},createCommentNode:t=>{if(h+=1,h>ne)throw new k("too-many-comments");return E(1),_.defaultTreeAdapter.createCommentNode(t)},setTemplateContent:(t,o)=>{_.defaultTreeAdapter.setTemplateContent(t,o);const c=s(o);c.above=s(t),T(c.above,c.height)},appendChild:C,insertBefore:(t,o)=>C(t,o),detachNode:t=>{_.defaultTreeAdapter.isElementNode(t)&&(y(s(t)),t.parentNode=null)},getFirstChild:t=>{const o=s(t);if(!o.keepsChildren)throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");return o.first===null?null:o.first.node},getChildNodes:()=>{throw new Error("[markdown-explorer] the nesting guard keeps no child lists for source locations")},onItemPop:t=>{const o=s(t);o.keepsChildren=!1,o.first=null},insertText:()=>{},insertTextBefore:()=>{},adoptAttributes:(t,o)=>{E(o.length),a(o);const c=s(t);if(c.attributes+=o.length,c.attributes>V)throw new k("too-many-attributes")}};let v;try{v=_.parse(r,{scriptingEnabled:!1,treeAdapter:B})}catch(t){if(t instanceof k)return{status:t.status};throw t}return{status:"within",depth:s(v).height-W,elements:p,nodes:g}};class Z extends RangeError{constructor(i){super(`[markdown-explorer] the HTML nests deeper than ${String(i)} levels`),this.name="HtmlNestingLimitError"}}const Se=["script","style","noscript","template","form","button","textarea","select","option","object","embed","base","meta","link","frame","frameset"],we=["srcdoc","formaction"],Ne=/^(?:(?:https?|mailto|tel):|[^a-z]|[a-z+.-]+(?:[^a-z+.:-]|$))/iu,be=new Set(["left","right","center","justify","start","end"]),Oe=new Set(["h1","h2","h3","h4","h5","h6"]),x=1,Re=3,Le=7,ke=8,ee=Object.freeze({a:Object.freeze(["target","data-link-kind","data-doc-path","data-doc-exists","data-footnote-ref","data-footnote-backref"]),area:Object.freeze(["target"]),img:Object.freeze(["data-asset-src","data-asset-exists"]),section:Object.freeze(["data-footnotes"]),iframe:Object.freeze(["allow","allowfullscreen","frameborder","referrerpolicy"])}),Ie=[...new Set([...Object.values(ee).flatMap(r=>r.filter(i=>i.startsWith("data-"))),H.SOURCE_LINES_ATTRIBUTE])],Ce=new Set(["src","href","xlink:href"]),Ue=/^data:/iu,ye=Object.freeze({FORBID_TAGS:Se,FORBID_ATTR:we,ADD_TAGS:["iframe"],ADD_ATTR:(r,i)=>r===H.SOURCE_LINES_ATTRIBUTE||ee[i]?.includes(r)===!0,ADD_URI_SAFE_ATTR:Ie,ALLOWED_URI_REGEXP:Ne,ALLOW_DATA_ATTR:!1}),De=r=>{let i=null;for(const u of r.split(";")){const f=u.indexOf(":");if(f<0||u.slice(0,f).trim().toLowerCase()!=="text-align")continue;const l=u.slice(f+1).trim().toLowerCase();be.has(l)&&(i=l)}return i===null?null:`text-align: ${i}`},Me=r=>r.nodeType===Re?{kind:"text",text:r.nodeValue??""}:r.nodeType===ke||r.nodeType===Le?{kind:"ignored"}:r.nodeType===x&&r.nodeName.toLowerCase()==="a"?{kind:"link",href:r.getAttribute("href")}:{kind:"element"},xe=r=>{const i=r.getAttribute("type");return i!==null&&i.trim().toLowerCase()==="checkbox"&&r.hasAttribute("disabled")},He=(r,i,u)=>{if(S.isSupported!==!0)throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");if(!Number.isSafeInteger(u)||u<=0)throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${String(u)}`);const f=Object.freeze([...r]);let l=new WeakMap,A=new WeakMap;const n=a=>{const e=a.parentNode===null?void 0:l.get(a.parentNode),s=e===void 0?0:e+1;if(l.set(a,s),a.nodeType===x&&s>u)throw new Z(u)},p=(a,e)=>{if(a.nodeType!==x)return;const s=a;(e.tagName==="input"&&!xe(s)||e.tagName==="iframe"&&L.allowedFrameUrlOf(s.getAttribute("src")?.trim(),f)===null)&&s.parentNode?.removeChild(s)},g=(a,e)=>{const s=a.nodeName.toLowerCase();if(e.attrName==="style"){const T=De(e.attrValue);T===null?e.keepAttr=!1:e.attrValue=T}else if(e.attrName==="allow"&&s==="iframe"){const T=L.reduceFrameFeatures(e.attrValue);T===null?e.keepAttr=!1:e.attrValue=T}else if(e.attrName==="referrerpolicy"&&s==="iframe"){const T=e.attrValue.trim().toLowerCase();L.EMBED_FRAME_REFERRER_POLICIES.has(T)?e.attrValue=T:e.keepAttr=!1}else e.attrName===L.EMBED_LINK_ATTRIBUTE&&s==="p"?A.set(a,a.getAttribute(L.EMBED_LINK_ATTRIBUTE)):Ce.has(e.attrName)&&Ue.test(e.attrValue)||e.attrName===H.SOURCE_LINES_ATTRIBUTE&&H.parseSourceLines(e.attrValue)===null?e.keepAttr=!1:e.attrName==="id"&&Oe.has(s)&&(e.forceKeepAttr=!0)},h=a=>{const e=a.getAttribute("data-asset-src");e!==null&&(a.getAttribute("data-asset-exists")!=="false"&&G.isAcceptableDocumentPath(e)?a.setAttribute("src",G.explorerAssetHref(i,e,null)):a.removeAttribute("src"))},I=a=>{const e=a.parentNode;if(e===null)return;const s=A.get(e);s!=null&&L.placeholderLinkOf(s,[...e.childNodes].map(Me))!==null&&e.setAttribute(L.EMBED_LINK_ATTRIBUTE,s)},E=a=>{if(a.nodeType!==x)return;const e=a,s=e.nodeName.toLowerCase();s==="img"?h(e):s==="a"&&I(e);const T=e.getAttribute("target");if(T===null||T.trim().toLowerCase()==="_self")return;const y=e.getAttribute("rel"),C=new Set(y===null?[]:y.split(/\s+/u).filter(B=>B!==""));C.add("noopener"),C.add("noreferrer"),e.setAttribute("rel",[...C].join(" "))};return a=>{l=new WeakMap,A=new WeakMap,S.addHook("beforeSanitizeElements",n),S.addHook("uponSanitizeElement",p),S.addHook("uponSanitizeAttribute",g),S.addHook("afterSanitizeAttributes",E);try{return S.sanitize(a,ye)}finally{S.removeHook("beforeSanitizeElements",n),S.removeHook("uponSanitizeElement",p),S.removeHook("uponSanitizeAttribute",g),S.removeHook("afterSanitizeAttributes",E)}}},Be=r=>{if(r===null||typeof r!="object")return!1;const{id:i,input:u}=r;if(typeof i!="number"||u===null||typeof u!="object")return!1;const{html:f,iframeHosts:l,dataPath:A,maxNodes:n,maxAttributeChars:p,maxSanitizedChars:g}=u;return typeof f=="string"&&Array.isArray(l)&&l.every(h=>typeof h=="string")&&typeof A=="string"&&A!==""&&[n,p,g].every(h=>Number.isSafeInteger(h)&&h>0)},ze=()=>{const r=re.parentPort;if(r===null)throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");const i=new Map;r.on("message",u=>{if(!Be(u))throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");const{id:f,input:l}=u;let A;try{if(_e(l.html,j,l.maxNodes,l.maxAttributeChars).status!=="within"){r.postMessage({id:f,output:{status:"too-large"}});return}const n=JSON.stringify([l.iframeHosts,l.dataPath]);let p=i.get(n);p===void 0&&(p=He(l.iframeHosts,l.dataPath,j),i.set(n,p));const g=p(l.html);A=g.length>l.maxSanitizedChars?{status:"too-large"}:{status:"sanitized",html:g}}catch(n){A=n instanceof Z?{status:"too-large"}:{status:"error",message:n instanceof Error?`${n.name}: ${n.message}`:String(n)}}r.postMessage({id:f,output:A})}),r.postMessage({ready:!0})};ze();
|
|
1
|
+
"use strict";const J=require("node:worker_threads"),W=require("isomorphic-dompurify"),M=require("./sanitizePolicy-BfUlXI5E.cjs"),A=require("parse5"),K=4096,P=1024,B=Symbol("placement"),G=2,Y=3,Z=new Set(["html","head","body"]),S=0,v=1,I=2,z=3,U=4,C=5,N=6,w=7,F=8,b=9,Q=10,m=-1,ee=0,te=1,re=2,ne=3,se=4,oe=5,q=6,ae=7,ie=t=>{switch(t){case 9:case 10:case 12:case 13:case 32:return ee;case 47:return te;case 62:return re;case 61:return ne;case 34:return se;case 39:return oe;default:return q}},ce=Uint8Array.from({length:128},(t,i)=>ie(i)),x=60,V=47,le=/[\t\n\f\r />="'<]/g,ue=/["<]/g,fe=/['<]/g,f=-1-I,de=Int8Array.from([[v,b,m,S,S,S,S],[v,b,m,f,f,f,f],[z,b,m,U,I,I,I],[z,b,m,U,f,f,f],[U,w,m,w,C,N,w],[C,C,C,C,F,C,C],[N,N,N,N,N,F,N],[v,w,m,w,w,w,w],[v,b,m,f,f,f,f],[v,b,m,f,f,f,f]].flat()),$=t=>t>=65&&t<=90||t>=97&&t<=122,Ee=(t,i)=>{let c=new Int32Array(Q),l=new Int32Array(Q),o=0,p=0,n=0;for(;n<t.length;){if(o===0){const u=t.indexOf("<",n);if(u<0)return!1;n=u+1,t.charCodeAt(n)===V&&(n+=1),$(t.charCodeAt(n))&&(c[S]=0,o=1<<S,n+=1);continue}if((o&-230)===0&&n>=p){const u=o===1<<C?ue:o===1<<N?fe:le;u.lastIndex=n;const _=u.exec(t);if(_===null)return!1;n=_.index,t.charCodeAt(n)===x&&(p=n+3)}const d=t.charCodeAt(n),g=d<128?ce[d]:q;let h=0;for(let u=o;u!==0;u&=u-1){const _=31-Math.clz32(u&-u);let T=de[_*ae+g],E=c[_];if(T<m&&(T=-1-T,E+=1,E>i))return!0;if(T===m)continue;const L=1<<T;((h&L)===0||E>l[T])&&(l[T]=E),h|=L}$(d)&&(t.charCodeAt(n-1)===x||t.charCodeAt(n-1)===V&&t.charCodeAt(n-2)===x)&&(h&1<<S)===0&&(l[S]=0,h|=1<<S);const y=c;c=l,l=y,o=h,n+=1}return!1};class O extends Error{status;constructor(i){super(`[markdown-explorer] the nesting guard stopped the parse: ${i}`),this.name="ParseStop",this.status=i}}const he=(t,i,c,l)=>{if(!Number.isSafeInteger(i)||i<=0)throw new RangeError(`[markdown-explorer] the nesting guard's depth limit must be a positive safe integer; got ${String(i)}`);if(!Number.isSafeInteger(c)||c<=0)throw new RangeError(`[markdown-explorer] the nesting guard's node budget must be a positive safe integer; got ${String(c)}`);if(!Number.isSafeInteger(l)||l<=0)throw new RangeError(`[markdown-explorer] the nesting guard's attribute character budget must be a positive safe integer; got ${String(l)}`);if(Ee(t,P))return{status:"too-many-attributes"};const o=i+G,p=t.length+Y;let n=null,d=0,g=0,h=0,y=0;const u=e=>{if(g+=e,g>c)throw new O("too-many-nodes")},_=e=>{for(const r of e)y+=r.name.length+r.value.length;if(y>l)throw new O("too-many-attribute-characters")},T=(e,r,s,a)=>{const D={node:e,above:null,levels:r,height:0,keepsChildren:s,attributes:a,first:null,next:null,previous:null},j=e;return j[B]=D,D},E=e=>{const s=e[B];if(s===void 0)throw new Error("[markdown-explorer] the nesting guard was handed a node it did not create");return s},L=(e,r)=>{let s=r;for(let a=e;a!==null&&s>a.height;a=a.above)a.height=s,s+=a.levels;if(n!==null&&n.height>o)throw new O("too-deep")},k=e=>{const r=e.above;r?.keepsChildren&&(e.previous===null?r.first=e.next:e.previous.next=e.next,e.next!==null&&(e.next.previous=e.previous)),e.above=null,e.next=null,e.previous=null},R=(e,r)=>{if(!A.defaultTreeAdapter.isElementNode(r))return;const s=E(r),a=E(e);k(s),s.above=a,a.keepsChildren&&(s.next=a.first,a.first!==null&&(a.first.previous=s),a.first=s),r.parentNode=e,L(a,s.height+s.levels)},X={...A.defaultTreeAdapter,createDocument:()=>{const e=A.defaultTreeAdapter.createDocument();return n=T(e,0,!1,0),e},createDocumentFragment:()=>{const e=A.defaultTreeAdapter.createDocumentFragment();return T(e,0,!1,0),e},createElement:(e,r,s)=>{if(d+=1,d>p)throw new O("too-many-elements");u(1+s.length),_(s);const a=A.defaultTreeAdapter.createElement(e,r,s);return T(a,1,!(r===A.html.NS.HTML&&Z.has(e)),s.length),a},createCommentNode:e=>{if(h+=1,h>K)throw new O("too-many-comments");return u(1),A.defaultTreeAdapter.createCommentNode(e)},setTemplateContent:(e,r)=>{A.defaultTreeAdapter.setTemplateContent(e,r);const s=E(r);s.above=E(e),L(s.above,s.height)},appendChild:R,insertBefore:(e,r)=>R(e,r),detachNode:e=>{A.defaultTreeAdapter.isElementNode(e)&&(k(E(e)),e.parentNode=null)},getFirstChild:e=>{const r=E(e);if(!r.keepsChildren)throw new Error("[markdown-explorer] the nesting guard was asked for the children of a node whose children it does not keep");return r.first===null?null:r.first.node},getChildNodes:()=>{throw new Error("[markdown-explorer] the nesting guard keeps no child lists for source locations")},onItemPop:e=>{const r=E(e);r.keepsChildren=!1,r.first=null},insertText:()=>{},insertTextBefore:()=>{},adoptAttributes:(e,r)=>{u(r.length),_(r);const s=E(e);if(s.attributes+=r.length,s.attributes>P)throw new O("too-many-attributes")}};let H;try{H=A.parse(t,{scriptingEnabled:!1,treeAdapter:X})}catch(e){if(e instanceof O)return{status:e.status};throw e}return{status:"within",depth:E(H).height-G,elements:d,nodes:g}},pe=t=>{if(t===null||typeof t!="object")return!1;const{id:i,input:c}=t;if(typeof i!="number"||c===null||typeof c!="object")return!1;const{html:l,iframeHosts:o,dataPath:p,maxNodes:n,maxAttributeChars:d,maxSanitizedChars:g}=c;return typeof l=="string"&&Array.isArray(o)&&o.every(h=>typeof h=="string")&&typeof p=="string"&&p!==""&&[n,d,g].every(h=>Number.isSafeInteger(h)&&h>0)},Te=()=>{const t=J.parentPort;if(t===null)throw new Error("[markdown-explorer] the sanitizer worker must run in a worker thread");const i=new Map;t.on("message",c=>{if(!pe(c))throw new TypeError("[markdown-explorer] the sanitizer worker received a message that is not a job");const{id:l,input:o}=c;let p;try{if(he(o.html,M.MAX_HTML_NESTING_DEPTH,o.maxNodes,o.maxAttributeChars).status!=="within"){t.postMessage({id:l,output:{status:"too-large"}});return}const n=JSON.stringify([o.iframeHosts,o.dataPath]);let d=i.get(n);d===void 0&&(d=M.createHtmlSanitizer(W,o.iframeHosts,o.dataPath,M.MAX_HTML_NESTING_DEPTH),i.set(n,d));const g=d(o.html);p=g.length>o.maxSanitizedChars?{status:"too-large"}:{status:"sanitized",html:g}}catch(n){p=n instanceof M.HtmlNestingLimitError?{status:"too-large"}:{status:"error",message:n instanceof Error?`${n.name}: ${n.message}`:String(n)}}t.postMessage({id:l,output:p})}),t.postMessage({ready:!0})};Te();
|