@aiquants/markdown-explorer 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +795 -0
- package/README.md +119 -55
- package/dist/EditSurface-CLG70Vnn.cjs +6 -0
- package/dist/EditSurface-D2j1kCEE.js +990 -0
- package/dist/ExplorerSplit-CfP1smbT.js +1589 -0
- package/dist/ExplorerSplit-D_0VohOv.cjs +2 -0
- package/dist/{MultiLayout-DYNGlNy0.js → MultiLayout-BeJ5Lubb.js} +291 -290
- package/dist/MultiLayout-CxV5SI7f.cjs +1 -0
- package/dist/NativeScrollBar-BM5NULzg.js +62 -0
- package/dist/NativeScrollBar-RWXpVhbI.cjs +1 -0
- package/dist/TreeLayout-AxLw-36S.js +103 -0
- package/dist/TreeLayout-Bg2YH-EY.cjs +1 -0
- package/dist/client/MarkdownExplorer.d.cts +14 -1
- package/dist/client/MarkdownExplorer.d.ts +14 -1
- package/dist/client/edit/lineEndings.d.cts +4 -0
- package/dist/client/edit/lineEndings.d.ts +4 -0
- package/dist/client/hostContract.d.cts +67 -0
- package/dist/client/hostContract.d.ts +67 -0
- package/dist/core/config.d.cts +7 -0
- package/dist/core/config.d.ts +7 -0
- package/dist/core/contracts.d.cts +10 -4
- package/dist/core/contracts.d.ts +10 -4
- package/dist/core/draftAnswer.d.cts +23 -0
- package/dist/core/draftAnswer.d.ts +23 -0
- package/dist/core/geometry.d.cts +1 -0
- package/dist/core/geometry.d.ts +1 -0
- package/dist/core/labels.d.cts +78 -0
- package/dist/core/labels.d.ts +78 -0
- package/dist/core/location.d.cts +3 -2
- package/dist/core/location.d.ts +3 -2
- package/dist/core/ownUrls.d.cts +15 -0
- package/dist/core/ownUrls.d.ts +15 -0
- package/dist/core/treeSettings.d.cts +3 -2
- package/dist/core/treeSettings.d.ts +3 -2
- package/dist/core/viewSettings.d.cts +5 -1
- package/dist/core/viewSettings.d.ts +5 -1
- package/dist/describeValue-CLlVRO8d.js +17 -0
- package/dist/describeValue-Ccvhbt36.cjs +1 -0
- package/dist/explorerCore-DLpDuSev.js +998 -0
- package/dist/explorerCore-DYrxS9ez.cjs +1 -0
- package/dist/index-C1YMH-yI.js +5816 -0
- package/dist/index-LQWQfpAf.cjs +18 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +47 -42
- package/dist/licenses/@heroicons/react/LICENSE +21 -0
- package/dist/licenses/entities/LICENSE +11 -0
- package/dist/licenses/parse5/LICENSE +19 -0
- package/dist/location--KvTA0Ri.js +726 -0
- package/dist/location-D8DyDkuA.cjs +1 -0
- package/dist/lru-DC8GBmkX.js +39 -0
- package/dist/lru-SGmUyBQU.cjs +1 -0
- package/dist/{merge-D7L_pINl.js → merge-Bb_HpPhe.js} +1 -1
- package/dist/{merge-DZI4pkWI.cjs → merge-DQUYEGCx.cjs} +1 -1
- package/dist/nestingGuardWorker.js +5511 -0
- package/dist/ownUrls-B259RGgd.cjs +1 -0
- package/dist/ownUrls-Dh5g6ZJi.js +370 -0
- package/dist/sanitizeJob-BYRk17nr.js +21 -0
- package/dist/sanitizeJob-Cs9o3Vpl.cjs +1 -0
- package/dist/sanitizePolicy-CEMdaLUB.js +139 -0
- package/dist/sanitizePolicy-CiQfnxyd.cjs +2 -0
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +134 -139
- package/dist/sanitizerService-BY4CPCoA.cjs +1 -0
- package/dist/sanitizerService-KWXv7bPm.js +240 -0
- package/dist/server/assetResponse.d.cts +60 -0
- package/dist/server/assetResponse.d.ts +60 -0
- package/dist/server/browser/browserPlatform.d.cts +12 -0
- package/dist/server/browser/browserPlatform.d.ts +12 -0
- package/dist/server/createMarkdownExplorer.d.cts +0 -10
- package/dist/server/createMarkdownExplorer.d.ts +0 -10
- package/dist/server/explorerCore.d.cts +12 -0
- package/dist/server/explorerCore.d.ts +12 -0
- package/dist/server/fileSystemSource.d.cts +1 -0
- package/dist/server/fileSystemSource.d.ts +1 -0
- package/dist/server/inProcessFetch.d.cts +5 -0
- package/dist/server/inProcessFetch.d.ts +5 -0
- package/dist/server/platform.d.cts +18 -0
- package/dist/server/platform.d.ts +18 -0
- package/dist/server/ports.d.cts +36 -5
- package/dist/server/ports.d.ts +36 -5
- package/dist/server/sanitizeProtocol.d.cts +3 -0
- package/dist/server/sanitizeProtocol.d.ts +3 -0
- package/dist/server/sanitizer.d.cts +5 -40
- package/dist/server/sanitizer.d.ts +5 -40
- package/dist/server/sanitizerOptions.d.cts +24 -0
- package/dist/server/sanitizerOptions.d.ts +24 -0
- package/dist/server/sanitizerService.d.cts +41 -0
- package/dist/server/sanitizerService.d.ts +41 -0
- package/dist/server/{workerPool.d.cts → workerJobs.d.cts} +0 -16
- package/dist/server/{workerPool.d.ts → workerJobs.d.ts} +0 -16
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +3 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.js +270 -1343
- package/dist/serverBrowser.cjs +1 -0
- package/dist/serverBrowser.d.cts +1 -0
- package/dist/serverBrowser.d.ts +1 -0
- package/dist/serverBrowser.js +120 -0
- package/dist/serverCore.cjs +1 -0
- package/dist/serverCore.d.cts +14 -0
- package/dist/serverCore.d.ts +14 -0
- package/dist/serverCore.js +46 -0
- package/dist/storage-BpYsprog.cjs +1 -0
- package/dist/{storage-CmGHg7OA.js → storage-D1uSw-xj.js} +19 -18
- package/dist/storage.cjs +1 -1
- package/dist/storage.js +1 -1
- package/dist/styles/markdown-explorer.css +1 -1
- package/dist/tapScrollCircle-BEydRn0y.js +14 -0
- package/dist/tapScrollCircle-DdX0Wri0.cjs +1 -0
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +6 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.js +4 -0
- package/dist/useSplitPersistence-B2Fj508K.cjs +1 -0
- package/dist/useSplitPersistence-Fkqak8G8.js +44 -0
- package/docs/behavior/dom-hooks.md +14 -3
- package/docs/behavior/hosting.md +123 -0
- package/docs/behavior/layout.md +69 -19
- package/docs/behavior/localization.md +28 -10
- package/docs/behavior/security.md +34 -14
- package/docs/behavior/url-contract.md +13 -6
- package/package.json +54 -16
- package/dist/EditSurface-BPqqykro.cjs +0 -6
- package/dist/EditSurface-CWq35IWQ.js +0 -972
- package/dist/ExplorerSplit-BRY4uy6x.js +0 -1493
- package/dist/ExplorerSplit-CQxr6b0v.cjs +0 -1
- package/dist/MultiLayout-TXbet9k3.cjs +0 -1
- package/dist/NativeScrollBar-BsWdvkHa.js +0 -64
- package/dist/NativeScrollBar-UpjxjLlB.cjs +0 -1
- package/dist/TreeLayout-BQEgZhz9.js +0 -72
- package/dist/TreeLayout-C0O1OGi4.cjs +0 -1
- package/dist/dataRoute-DLhQfdoW.js +0 -298
- package/dist/dataRoute-DwYtgyt6.cjs +0 -1
- package/dist/index-CO-RgTml.js +0 -4912
- package/dist/index-DSkK8iLE.cjs +0 -15
- package/dist/location-BxiJRTyw.cjs +0 -1
- package/dist/location-perTmwct.js +0 -663
- package/dist/sanitizePolicy-By0tKOpZ.js +0 -98
- package/dist/sanitizePolicy-T5T-3vV5.cjs +0 -1
- package/dist/storage-DM0EvkVf.cjs +0 -1
- package/dist/tapScrollCircle-CRKZremf.js +0 -12
- package/dist/tapScrollCircle-Cbf17x8g.cjs +0 -1
- package/dist/useSplitPersistence-Du01PHNg.js +0 -42
- package/dist/useSplitPersistence-pPmE4GTT.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const o=require("./describeValue-Ccvhbt36.cjs"),I=4096,N=3,z=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"]),ae=/[\u0000-\u001f\u007f]/u,le=/\p{Cs}/u,ce=e=>{const t=e.split("/").filter(r=>r!=="").at(-1);return t===void 0?e:t},w=e=>e.length>0&&e.length<=I&&!le.test(e)&&!ae.test(e)&&!e.includes("\\"),C=e=>e.normalize("NFKC").toUpperCase().toLowerCase(),ue=/(?:%[0-9A-Fa-f]{2})+/gu,de=new TextDecoder("utf-8"),fe=/[/\\]/u,U=e=>e.replace(ue,t=>de.decode(Uint8Array.from(t.slice(1).split("%").map(r=>Number.parseInt(r,16))))),pe=e=>{const t=[e];let r=e;for(let n=0;n<N&&r.includes("%");n+=1){const s=U(r);if(s===r)break;t.push(s),r=s}return{levels:t.map(C),stillEncoded:t.length>N&&U(r)!==r}},Ee=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 ${o.describeValue(e)}`);const t=C(e).split("*").map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${t}$`,"su")},x=e=>{if(!Array.isArray(e))throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");const t=e.map(Ee),r=s=>s!==""&&t.some(i=>i.test(s)),n=s=>{if(t.length===0||s==="")return!1;const{levels:i,stillEncoded:l}=pe(s);return l?!0:i.some(u=>r(u)||u.split(fe).some(r))};return{deniesPath:s=>s.split("/").some(n),deniesName:n}},me=x(z),Re=Object.freeze({deniesPath:()=>!1,deniesName:()=>!1}),ge=e=>e===void 0?me:e===!1?Re:x(e),he=(e,t)=>x(e).deniesPath(t),T=Object.freeze(["unauthorized","forbidden","not-found","not-configured","invalid","too-large","unsupported","failed"]),ye=Object.freeze(["file","directory"]),be=Object.freeze(["video","audio","pdf"]),_e=Object.freeze(["raster","svg"]),Oe=Object.freeze(["csv","tsv","workbook"]),Ae=Object.freeze(["csv","tsv"]),we=Object.freeze(["info","warning","danger"]),xe=Object.freeze(["markdown","text","image","media","spreadsheet","file","failure"]),j=Object.freeze({min:1,max:6}),Te=1e4,p=e=>typeof e=="string"&&/^\/(?![/\\])[\x21-\x7E]*$/u.test(e),Se=Object.freeze(["http:","https:","mailto:"]),S=1024,Pe=/^[a-z0-9-]{1,64}$/u,Le="https://relative.invalid/",f=(e,t)=>typeof t=="string"&&e.includes(t),X=e=>f(T,e),ke=e=>f(ye,e),H=e=>f(be,e),F=e=>f(_e,e),$e=e=>f(Oe,e),De=e=>f(we,e),ve=e=>f(xe,e),P=e=>typeof e=="string"&&Pe.test(e),Ne=(e,t)=>{if(typeof e!="string")return!1;try{return t.includes(new URL(e,Le).protocol)}catch{return!1}},R=e=>{if(e===null||typeof e!="object")return"a failure must be an object";const{reason:t,code:r}=e;return X(t)?r!==void 0&&!P(r)?`a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${o.describeValue(r)}`:null:`unknown failure reason ${o.describeValue(t)}`},M=e=>{if(e===null||typeof e!="object")return"an entry must be an object";const{name:t,path:r,type:n,mimeType:s,modifiedAt:i,children:l,lazy:u}=e;return typeof t!="string"||t===""?"an entry needs a non-empty name":typeof r!="string"||!w(r)?"an entry needs an acceptable path":ke(n)?s!==void 0&&typeof s!="string"?"an entry mimeType must be a string":i!==void 0&&!Number.isSafeInteger(i)?`an entry modifiedAt must be a safe integer of epoch milliseconds; got ${o.describeValue(i)}`:u!==void 0&&typeof u!="boolean"?"an entry lazy flag must be a boolean":l!==void 0&&!Array.isArray(l)?"entry children must be an array":n==="file"&&(l!==void 0||u===!0)?"a file entry cannot have children or be lazy":u===!0&&Array.isArray(l)&&l.length>0?"a lazy directory must not list children":null:`an entry type must be "file" or "directory"; got ${o.describeValue(n)}`},K=e=>{if(M(e)!==null)return!1;const{children:t}=e;return t===void 0||t.every(K)},W=e=>{if(e===null||typeof e!="object")return!1;const{status:t,entries:r,failure:n}=e;return t==="ok"?Array.isArray(r)&&r.every(K):t==="error"&&R(n)===null},Ue=e=>{if(e===null||typeof e!="object")return!1;const{status:t,ancestors:r,failure:n}=e;return t==="ok"?r===null||G(r):t==="error"&&R(n)===null},G=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&w(t))&&new Set(e).size===e.length,je=e=>{if(e===null||typeof e!="object")return!1;const{status:t,source:r,ancestors:n,failure:s}=e;return t==="ok"?r===null&&n===null||typeof r=="string"&&r!==""&&G(n):t==="error"&&R(s)===null},Ve=e=>{if(e===null||typeof e!="object")return!1;const{status:t,loadedAt:r}=e;return t==="ok"&&!(Number.isSafeInteger(r)&&r>=0)?!1:W(e)},L=e=>{if(e===null||typeof e!="object")return"a heading must be an object";const{text:t,depth:r,id:n}=e;return typeof t!="string"||typeof n!="string"?"a heading needs text and id strings":typeof r!="number"||!Number.isInteger(r)||r<j.min||r>j.max?`a heading depth must be an integer in 1..6; got ${o.describeValue(r)}`:null},O=e=>{if(typeof e!="string"||e==="")return!1;try{return Intl.getCanonicalLocales(e)[0]===e}catch{return!1}},A=(e,t)=>`a ${e} document needs a lang that is a canonical BCP 47 language tag (such as "ja" or "en-US"); got ${o.describeValue(t)}`,Y=e=>typeof e.text!="string"||typeof e.truncated!="boolean"?"a text document needs text and truncated":p(e.url)?null:"a text document needs a root-relative url",k=e=>{if(e===null||typeof e!="object")return"a document must be an object";const t=e,{kind:r}=t;if(!ve(r))return`unknown document kind ${o.describeValue(r)}`;if(r==="failure")return R(t.failure);if(typeof t.name!="string")return"a document needs a name string";switch(r){case"markdown":{const{htmlContent:n,headings:s}=t;if(typeof n!="string"||!Array.isArray(s))return"a markdown document needs htmlContent and headings";for(const i of s){const l=L(i);if(l!==null)return l}return O(t.lang)?Ce(t.edit):A(r,t.lang)}case"text":{const n=Y(t);return n!==null?n:O(t.lang)?null:A(r,t.lang)}case"image":return p(t.url)?F(t.imageType)?null:`unknown image type ${o.describeValue(t.imageType)}`:"an image document needs a root-relative url";case"media":return p(t.url)?H(t.mediaType)?null:`unknown media type ${o.describeValue(t.mediaType)}`:"a media document needs a root-relative url";case"spreadsheet":return p(t.url)?B(t):"a spreadsheet document needs a root-relative url";case"file":return p(t.url)?null:"a file document needs a root-relative url"}},Ie=e=>k(e)===null,ze=e=>{if(e===null||typeof e!="object")return!1;const t=e;return t.kind==="failure"?k(t)===null:t.kind==="text"&&typeof t.name=="string"&&Y(t)===null},Ce=e=>{if(e===null)return null;if(typeof e!="object")return"a markdown document's edit must be null or an object";const{kind:t,href:r}=e;return t==="inline"?r===void 0?null:"an inline edit carries no href":t==="draft"?r===void 0?null:"a draft edit carries no href":t!=="external"?`unknown edit kind ${o.describeValue(t)}`:q(r)},Xe=e=>{if(e===null)return null;if(typeof e!="object")return"a spreadsheet document's edit must be null or an object";const{kind:t,href:r}=e;return t!=="external"?`a spreadsheet document's edit must be external; got ${o.describeValue(t)}`:q(r)},B=e=>{if(!$e(e.format))return`unknown spreadsheet format ${o.describeValue(e.format)}`;const{firstSheetText:t}=e;return t!==null&&!f(Ae,t)?`a spreadsheet document's firstSheetText must be csv, tsv or null; got ${o.describeValue(t)}`:t!==null&&e.format!=="workbook"?"only a workbook's spreadsheet document names a firstSheetText":Xe(e.edit)},q=e=>He(e)?null:`an external edit needs an absolute https: href; got ${o.describeValue(e)}`,He=e=>{if(typeof e!="string")return!1;try{return new URL(e).protocol==="https:"}catch{return!1}},E=e=>typeof e=="string"&&e.length>0&&e.length<=S,Fe=e=>p(e.href)?null:`a grant needs a root-relative href; got ${o.describeValue(e.href)}`,Q=e=>{if(e===null||typeof e!="object")return"a revision must be an object";const{id:t,modifiedAt:r,size:n,author:s,kept:i,current:l}=e;return E(t)?r!==null&&(typeof r!="string"||Number.isNaN(Date.parse(r)))?`a revision's modifiedAt must be a date-time string or null; got ${o.describeValue(r)}`:typeof n!="number"||!Number.isSafeInteger(n)||n<0?`a revision's size must be a non-negative integer; got ${o.describeValue(n)}`:s!==null&&typeof s!="string"?`a revision's author must be a string or null; got ${o.describeValue(s)}`:typeof i!="boolean"||typeof l!="boolean"?"a revision needs kept and current booleans":null:`a revision id must be a non-empty string of at most ${S} characters; got ${o.describeValue(t)}`},g=(e,t)=>{if(e===null||typeof e!="object")return"an answer must be an object";const r=e,{kind:n}=r;if(n==="failure")return R(r.failure);if(typeof n!="string"||!t.includes(n))return`unexpected answer kind ${o.describeValue(n)}`;switch(n){case"grant":return Fe(r);case"edit":return typeof r.text!="string"||typeof r.history!="boolean"?"an edit source needs text and history":E(r.version)?null:`an edit source needs a version; got ${o.describeValue(r.version)}`;case"draft":return typeof r.text=="string"?null:"a draft source needs text";case"saved":return E(r.version)?null:`a saved answer needs a version; got ${o.describeValue(r.version)}`;case"conflict":return typeof r.text!="string"?"a conflict needs the current text":E(r.version)?null:`a conflict needs the current version; got ${o.describeValue(r.version)}`;case"preview":{const{htmlContent:s,headings:i}=r;if(typeof s!="string"||!Array.isArray(i))return"a preview needs htmlContent and headings";for(const l of i){const u=L(l);if(u!==null)return u}return null}case"revisions":{if(!Array.isArray(r.revisions))return"revisions need an array";for(const s of r.revisions){const i=Q(s);if(i!==null)return i}return null}case"revision":return typeof r.text!="string"?"a revision answer needs text":E(r.id)?null:`a revision answer needs an id; got ${o.describeValue(r.id)}`;default:return`unexpected answer kind ${o.describeValue(n)}`}},Me=Object.freeze(["edit","draft","grant"]),Ke=Object.freeze(["saved","conflict","grant"]),Z=Object.freeze(["preview"]),We=Object.freeze(["revisions"]),Ge=Object.freeze(["revision"]),Ye=e=>g(e,Me)===null,Be=e=>g(e,Ke)===null,qe=e=>g(e,Z)===null,Qe=e=>g(e,We)===null,Ze=e=>g(e,Ge)===null,Je=e=>e!==null&&typeof e=="object"&&e.kind==="unavailable"?null:g(e,Z),et=(e,t)=>({kind:"failure",failure:J(e,t)}),J=(e,t)=>P(t)?{reason:e,code:t}:{reason:e},tt=Object.freeze(["tree","children","ancestors","reveal","document","text","edit","save","preview","revisions","revision","refresh","asset","link-card"]),m=Object.freeze({source:"source",path:"path",version:"v",base:"base",revision:"revision",display:"as"}),rt="asset",nt="link-card",st=(e,t,r)=>{const n=`${e}/${rt}?${m.path}=${encodeURIComponent(t)}`;return r===null?n:`${n}&${m.version}=${encodeURIComponent(r)}`},ee="text",te="workbook",ot=e=>{if(!e.includes("?"))throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${o.describeValue(e)}`);return`${e}&${m.display}=${ee}`},it=e=>{if(!e.includes("?"))throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${o.describeValue(e)}`);return`${e}&${m.display}=${te}`},at=e=>{const t=e.getAll(m.display);return t.length===0?"file":t.length!==1?null:t[0]===ee?"text":t[0]===te?"workbook":null},lt=e=>`${e}/${nt}`,ct="X-Markdown-Explorer-Scope",ut="X-Markdown-Explorer",dt="refresh",ft="edit",pt="text/markdown",Et=e=>tt.includes(e),re=Object.freeze({invalid:400,unauthorized:401,forbidden:403,"not-found":404,"too-large":413,"not-configured":500,unsupported:500,failed:500}),mt=e=>{const[t,...r]=T.filter(n=>re[n]===e);return t!==void 0&&r.length===0?t:"failed"},Rt=/^\/(?:[A-Za-z0-9._~-]+\/)*[A-Za-z0-9._~-]+$/u,gt=/^[\u0000- ]+|[\u0000- ]+$/gu,ht=/[\t\n\r]/gu,yt=/^[a-z][a-z\d+.-]*:/iu,bt=/^(?:\.|%2e){1,2}$/iu,_t=new Set(["ftp:","file:","http:","https:","ws:","wss:"]),Ot=Object.freeze(["http:","https:"]),At="http://path.invalid",V=Object.freeze(["origins","resources","links","media"]),b=e=>Rt.test(e)&&!e.split("/").some(t=>t==="."||t===".."),ne=e=>{if(!URL.canParse(e))return!1;const t=new URL(e);return t.host!==""&&e===`${t.protocol}//${t.host}`},se=e=>{if(!URL.canParse(e))return!1;const t=new URL(e);return(t.protocol==="http:"||t.protocol==="https:")&&e===`${t.origin}${t.pathname}`&&b(t.pathname)},oe=e=>o.isPlainObject(e)&&Object.keys(e).length===V.length&&V.every(t=>{const r=Object.hasOwn(e,t)?e[t]:void 0;return Array.isArray(r)&&Array.from(r).every(n=>typeof n=="string")}),_=e=>`${e.protocol}//${e.hostname.replace(/\.+$/u,"")}${e.port===""?"":`:${e.port}`}`,y=(e,t)=>t.some(r=>e===r||e.startsWith(`${r}/`)),wt=e=>e.slice(0,e.search(/[?#]|$/u)).split("/").some(t=>bt.test(t)),xt=(e,t)=>{switch(t){case"document-link":return!0;case"link":return!wt(e);case"svg-reference":return e.startsWith("#");default:return!1}},ie=e=>{if(!oe(e))throw new TypeError("[markdown-explorer] the HTML sanitizer's ownUrls must be a plain object of exactly origins, resources, links and media, each an array of strings");const t=[["origins",ne,"an origin as the browser writes it (scheme://host[:port])"],["resources",b,'a mount path ("/" and segments of letters, digits and "._~-", without a "." or ".." segment or a trailing "/")'],["links",b,'a mount path ("/" and segments of letters, digits and "._~-", without a "." or ".." segment or a trailing "/")'],["media",se,"an absolute http: or https: URL as the browser writes it, of an origin and a mount path"]];for(const[r,n,s]of t)for(const[i,l]of e[r].entries())if(!n(l))throw new RangeError(`[markdown-explorer] the HTML sanitizer's ownUrls.${r}[${String(i)}] must be ${s}; got ${o.describeValue(l)}`);return Object.freeze({origins:Object.freeze([...e.origins]),resources:Object.freeze([...e.resources]),links:Object.freeze([...e.links]),media:Object.freeze([...e.media])})},Tt=e=>{const t=ie(e),r=t.origins.map(a=>new URL(a)),n=new Set(r.map(_)),s=new Set(r.map(a=>a.protocol).filter(a=>!_t.has(a))),i=t.media.map(a=>{const d=new URL(a);return{key:_(d),path:d.pathname}}),l=new Set(i.map(a=>a.key)),u=r.length===0?Ot:[...new Set(r.map(a=>a.protocol))],$=a=>a==="link"||a==="document-link"?t.links:t.resources,D=(a,d)=>{const c=_(a),h=n.has(c)||s.has(a.protocol);return!(h||l.has(c))||h&&y(a.pathname,$(d))?!0:d==="media"&&i.some(v=>v.key===c&&y(a.pathname,[v.path]))};return(a,d)=>{const c=a.replace(gt,"").replace(ht,"");return c.includes("\\")?!1:yt.test(c)?URL.canParse(c)&&D(new URL(c),d):c.startsWith("//")?u.every(h=>URL.canParse(`${h}${c}`)&&D(new URL(`${h}${c}`),d)):c.startsWith("/")?y(new URL(c,At).pathname,$(d)):xt(c,d)}};exports.DEFAULT_DENIED_PATH_SEGMENTS=z;exports.EXPLORER_DATA_QUERY=m;exports.EXPLORER_DRAFT_MEDIA_TYPE=pt;exports.EXPLORER_EDIT_PROOF=ft;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=S;exports.EXPLORER_FAILURE_REASONS=T;exports.EXPLORER_FAILURE_STATUS=re;exports.EXPLORER_LINK_PROTOCOLS=Se;exports.EXPLORER_MAX_HEADINGS=Te;exports.EXPLORER_PROOF_HEADER=ut;exports.EXPLORER_REFRESH_PROOF=dt;exports.EXPLORER_SCOPE_HEADER=ct;exports.MAX_DOCUMENT_PATH_LENGTH=I;exports.createOwnUrlRule=Tt;exports.documentLangRefusal=A;exports.documentViolation=k;exports.draftAnswerViolation=Je;exports.entryViolation=M;exports.explorerAssetHref=st;exports.explorerLinkCardEndpoint=lt;exports.explorerPlainTextHref=ot;exports.explorerWorkbookHref=it;exports.failureDocument=et;exports.failureOf=J;exports.failureReasonOfStatus=mt;exports.failureViolation=R;exports.headingViolation=L;exports.isAcceptableDocumentPath=w;exports.isAcceptableUrl=Ne;exports.isBrowserOrigin=ne;exports.isDeniedPath=he;exports.isExplorerAncestorsResult=Ue;exports.isExplorerChildrenResult=W;exports.isExplorerDataOperation=Et;exports.isExplorerDocument=Ie;exports.isExplorerDocumentLang=O;exports.isExplorerEditAnswer=Ye;exports.isExplorerEditToken=E;exports.isExplorerFailureCode=P;exports.isExplorerFailureReason=X;exports.isExplorerImageType=F;exports.isExplorerMediaType=H;exports.isExplorerNoticeTone=De;exports.isExplorerOwnUrls=oe;exports.isExplorerPreviewAnswer=qe;exports.isExplorerRevealResult=je;exports.isExplorerRevisionAnswer=Ze;exports.isExplorerRevisionsAnswer=Qe;exports.isExplorerSaveAnswer=Be;exports.isExplorerTextAnswer=ze;exports.isExplorerTreeResult=Ve;exports.isMediaDataUrl=se;exports.isMountPath=b;exports.isRootRelativeUrl=p;exports.isUnder=y;exports.lastPathSegment=ce;exports.readExplorerAssetDisplay=at;exports.readOwnUrls=ie;exports.resolvePathRules=ge;exports.revisionViolation=Q;exports.spreadsheetFieldsViolation=B;
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { d as o, i as W } from "./describeValue-CLlVRO8d.js";
|
|
2
|
+
const G = 4096, S = 3, Y = 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
|
+
]), B = /[\u0000-\u001f\u007f]/u, q = /\p{Cs}/u, Ze = (e) => {
|
|
61
|
+
const t = e.split("/").filter((n) => n !== "").at(-1);
|
|
62
|
+
return t === void 0 ? e : t;
|
|
63
|
+
}, j = (e) => e.length > 0 && e.length <= G && !q.test(e) && !B.test(e) && !e.includes("\\"), v = (e) => e.normalize("NFKC").toUpperCase().toLowerCase(), Z = /(?:%[0-9A-Fa-f]{2})+/gu, Q = new TextDecoder("utf-8"), J = /[/\\]/u, k = (e) => e.replace(
|
|
64
|
+
Z,
|
|
65
|
+
(t) => Q.decode(
|
|
66
|
+
Uint8Array.from(
|
|
67
|
+
t.slice(1).split("%").map((n) => Number.parseInt(n, 16))
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
), ee = (e) => {
|
|
71
|
+
const t = [e];
|
|
72
|
+
let n = e;
|
|
73
|
+
for (let r = 0; r < S && n.includes("%"); r += 1) {
|
|
74
|
+
const s = k(n);
|
|
75
|
+
if (s === n) break;
|
|
76
|
+
t.push(s), n = s;
|
|
77
|
+
}
|
|
78
|
+
return { levels: t.map(v), stillEncoded: t.length > S && k(n) !== n };
|
|
79
|
+
}, te = (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 ${o(e)}`);
|
|
82
|
+
const t = v(e).split("*").map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*");
|
|
83
|
+
return new RegExp(`^${t}$`, "su");
|
|
84
|
+
}, O = (e) => {
|
|
85
|
+
if (!Array.isArray(e)) throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");
|
|
86
|
+
const t = e.map(te), n = (s) => s !== "" && t.some((i) => i.test(s)), r = (s) => {
|
|
87
|
+
if (t.length === 0 || s === "") return !1;
|
|
88
|
+
const { levels: i, stillEncoded: c } = ee(s);
|
|
89
|
+
return c ? !0 : i.some((u) => n(u) || u.split(J).some(n));
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
deniesPath: (s) => s.split("/").some(r),
|
|
93
|
+
deniesName: r
|
|
94
|
+
};
|
|
95
|
+
}, ne = O(Y), re = Object.freeze({ deniesPath: () => !1, deniesName: () => !1 }), Qe = (e) => e === void 0 ? ne : e === !1 ? re : O(e), Je = (e, t) => O(e).deniesPath(t), N = Object.freeze(["unauthorized", "forbidden", "not-found", "not-configured", "invalid", "too-large", "unsupported", "failed"]), se = Object.freeze(["file", "directory"]), oe = Object.freeze(["video", "audio", "pdf"]), ie = Object.freeze(["raster", "svg"]), ae = Object.freeze(["csv", "tsv", "workbook"]), ce = Object.freeze(["csv", "tsv"]), le = Object.freeze(["info", "warning", "danger"]), ue = Object.freeze(["markdown", "text", "image", "media", "spreadsheet", "file", "failure"]), T = Object.freeze({ min: 1, max: 6 }), et = 1e4, p = (e) => typeof e == "string" && /^\/(?![/\\])[\x21-\x7E]*$/u.test(e), tt = Object.freeze(["http:", "https:", "mailto:"]), D = 1024, fe = /^[a-z0-9-]{1,64}$/u, de = "https://relative.invalid/", d = (e, t) => typeof t == "string" && e.includes(t), pe = (e) => d(N, e), me = (e) => d(se, e), Ee = (e) => d(oe, e), ge = (e) => d(ie, e), he = (e) => d(ae, e), nt = (e) => d(le, e), ye = (e) => d(ue, e), U = (e) => typeof e == "string" && fe.test(e), rt = (e, t) => {
|
|
96
|
+
if (typeof e != "string") return !1;
|
|
97
|
+
try {
|
|
98
|
+
return t.includes(new URL(e, de).protocol);
|
|
99
|
+
} catch {
|
|
100
|
+
return !1;
|
|
101
|
+
}
|
|
102
|
+
}, y = (e) => {
|
|
103
|
+
if (e === null || typeof e != "object") return "a failure must be an object";
|
|
104
|
+
const { reason: t, code: n } = e;
|
|
105
|
+
return pe(t) ? n !== void 0 && !U(n) ? `a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${o(n)}` : null : `unknown failure reason ${o(t)}`;
|
|
106
|
+
}, Re = (e) => {
|
|
107
|
+
if (e === null || typeof e != "object") return "an entry must be an object";
|
|
108
|
+
const { name: t, path: n, type: r, mimeType: s, modifiedAt: i, children: c, lazy: u } = e;
|
|
109
|
+
return typeof t != "string" || t === "" ? "an entry needs a non-empty name" : typeof n != "string" || !j(n) ? "an entry needs an acceptable path" : me(r) ? s !== void 0 && typeof s != "string" ? "an entry mimeType must be a string" : i !== void 0 && !Number.isSafeInteger(i) ? `an entry modifiedAt must be a safe integer of epoch milliseconds; got ${o(i)}` : u !== void 0 && typeof u != "boolean" ? "an entry lazy flag must be a boolean" : c !== void 0 && !Array.isArray(c) ? "entry children must be an array" : r === "file" && (c !== void 0 || u === !0) ? "a file entry cannot have children or be lazy" : u === !0 && Array.isArray(c) && c.length > 0 ? "a lazy directory must not list children" : null : `an entry type must be "file" or "directory"; got ${o(r)}`;
|
|
110
|
+
}, I = (e) => {
|
|
111
|
+
if (Re(e) !== null) return !1;
|
|
112
|
+
const { children: t } = e;
|
|
113
|
+
return t === void 0 || t.every(I);
|
|
114
|
+
}, be = (e) => {
|
|
115
|
+
if (e === null || typeof e != "object") return !1;
|
|
116
|
+
const { status: t, entries: n, failure: r } = e;
|
|
117
|
+
return t === "ok" ? Array.isArray(n) && n.every(I) : t === "error" && y(r) === null;
|
|
118
|
+
}, st = (e) => {
|
|
119
|
+
if (e === null || typeof e != "object") return !1;
|
|
120
|
+
const { status: t, ancestors: n, failure: r } = e;
|
|
121
|
+
return t === "ok" ? n === null || z(n) : t === "error" && y(r) === null;
|
|
122
|
+
}, z = (e) => Array.isArray(e) && e.every((t) => typeof t == "string" && j(t)) && new Set(e).size === e.length, ot = (e) => {
|
|
123
|
+
if (e === null || typeof e != "object") return !1;
|
|
124
|
+
const { status: t, source: n, ancestors: r, failure: s } = e;
|
|
125
|
+
return t === "ok" ? n === null && r === null || typeof n == "string" && n !== "" && z(r) : t === "error" && y(s) === null;
|
|
126
|
+
}, it = (e) => {
|
|
127
|
+
if (e === null || typeof e != "object") return !1;
|
|
128
|
+
const { status: t, loadedAt: n } = e;
|
|
129
|
+
return t === "ok" && !(Number.isSafeInteger(n) && n >= 0) ? !1 : be(e);
|
|
130
|
+
}, C = (e) => {
|
|
131
|
+
if (e === null || typeof e != "object") return "a heading must be an object";
|
|
132
|
+
const { text: t, depth: n, id: r } = e;
|
|
133
|
+
return typeof t != "string" || typeof r != "string" ? "a heading needs text and id strings" : typeof n != "number" || !Number.isInteger(n) || n < T.min || n > T.max ? `a heading depth must be an integer in 1..6; got ${o(n)}` : null;
|
|
134
|
+
}, $ = (e) => {
|
|
135
|
+
if (typeof e != "string" || e === "") return !1;
|
|
136
|
+
try {
|
|
137
|
+
return Intl.getCanonicalLocales(e)[0] === e;
|
|
138
|
+
} catch {
|
|
139
|
+
return !1;
|
|
140
|
+
}
|
|
141
|
+
}, L = (e, t) => `a ${e} document needs a lang that is a canonical BCP 47 language tag (such as "ja" or "en-US"); got ${o(t)}`, X = (e) => typeof e.text != "string" || typeof e.truncated != "boolean" ? "a text document needs text and truncated" : p(e.url) ? null : "a text document needs a root-relative url", H = (e) => {
|
|
142
|
+
if (e === null || typeof e != "object") return "a document must be an object";
|
|
143
|
+
const t = e, { kind: n } = t;
|
|
144
|
+
if (!ye(n)) return `unknown document kind ${o(n)}`;
|
|
145
|
+
if (n === "failure") return y(t.failure);
|
|
146
|
+
if (typeof t.name != "string") return "a document needs a name string";
|
|
147
|
+
switch (n) {
|
|
148
|
+
case "markdown": {
|
|
149
|
+
const { htmlContent: r, headings: s } = t;
|
|
150
|
+
if (typeof r != "string" || !Array.isArray(s)) return "a markdown document needs htmlContent and headings";
|
|
151
|
+
for (const i of s) {
|
|
152
|
+
const c = C(i);
|
|
153
|
+
if (c !== null) return c;
|
|
154
|
+
}
|
|
155
|
+
return $(t.lang) ? _e(t.edit) : L(n, t.lang);
|
|
156
|
+
}
|
|
157
|
+
case "text": {
|
|
158
|
+
const r = X(t);
|
|
159
|
+
return r !== null ? r : $(t.lang) ? null : L(n, t.lang);
|
|
160
|
+
}
|
|
161
|
+
case "image":
|
|
162
|
+
return p(t.url) ? ge(t.imageType) ? null : `unknown image type ${o(t.imageType)}` : "an image document needs a root-relative url";
|
|
163
|
+
case "media":
|
|
164
|
+
return p(t.url) ? Ee(t.mediaType) ? null : `unknown media type ${o(t.mediaType)}` : "a media document needs a root-relative url";
|
|
165
|
+
case "spreadsheet":
|
|
166
|
+
return p(t.url) ? Ae(t) : "a spreadsheet document needs a root-relative url";
|
|
167
|
+
case "file":
|
|
168
|
+
return p(t.url) ? null : "a file document needs a root-relative url";
|
|
169
|
+
}
|
|
170
|
+
}, at = (e) => H(e) === null, ct = (e) => {
|
|
171
|
+
if (e === null || typeof e != "object") return !1;
|
|
172
|
+
const t = e;
|
|
173
|
+
return t.kind === "failure" ? H(t) === null : t.kind === "text" && typeof t.name == "string" && X(t) === null;
|
|
174
|
+
}, _e = (e) => {
|
|
175
|
+
if (e === null) return null;
|
|
176
|
+
if (typeof e != "object") return "a markdown document's edit must be null or an object";
|
|
177
|
+
const { kind: t, href: n } = e;
|
|
178
|
+
return t === "inline" ? n === void 0 ? null : "an inline edit carries no href" : t === "draft" ? n === void 0 ? null : "a draft edit carries no href" : t !== "external" ? `unknown edit kind ${o(t)}` : M(n);
|
|
179
|
+
}, Oe = (e) => {
|
|
180
|
+
if (e === null) return null;
|
|
181
|
+
if (typeof e != "object") return "a spreadsheet document's edit must be null or an object";
|
|
182
|
+
const { kind: t, href: n } = e;
|
|
183
|
+
return t !== "external" ? `a spreadsheet document's edit must be external; got ${o(t)}` : M(n);
|
|
184
|
+
}, Ae = (e) => {
|
|
185
|
+
if (!he(e.format)) return `unknown spreadsheet format ${o(e.format)}`;
|
|
186
|
+
const { firstSheetText: t } = e;
|
|
187
|
+
return t !== null && !d(ce, t) ? `a spreadsheet document's firstSheetText must be csv, tsv or null; got ${o(t)}` : t !== null && e.format !== "workbook" ? "only a workbook's spreadsheet document names a firstSheetText" : Oe(e.edit);
|
|
188
|
+
}, M = (e) => we(e) ? null : `an external edit needs an absolute https: href; got ${o(e)}`, we = (e) => {
|
|
189
|
+
if (typeof e != "string") return !1;
|
|
190
|
+
try {
|
|
191
|
+
return new URL(e).protocol === "https:";
|
|
192
|
+
} catch {
|
|
193
|
+
return !1;
|
|
194
|
+
}
|
|
195
|
+
}, g = (e) => typeof e == "string" && e.length > 0 && e.length <= D, xe = (e) => p(e.href) ? null : `a grant needs a root-relative href; got ${o(e.href)}`, Se = (e) => {
|
|
196
|
+
if (e === null || typeof e != "object") return "a revision must be an object";
|
|
197
|
+
const { id: t, modifiedAt: n, size: r, author: s, kept: i, current: c } = e;
|
|
198
|
+
return g(t) ? n !== null && (typeof n != "string" || Number.isNaN(Date.parse(n))) ? `a revision's modifiedAt must be a date-time string or null; got ${o(n)}` : typeof r != "number" || !Number.isSafeInteger(r) || r < 0 ? `a revision's size must be a non-negative integer; got ${o(r)}` : s !== null && typeof s != "string" ? `a revision's author must be a string or null; got ${o(s)}` : typeof i != "boolean" || typeof c != "boolean" ? "a revision needs kept and current booleans" : null : `a revision id must be a non-empty string of at most ${D} characters; got ${o(t)}`;
|
|
199
|
+
}, m = (e, t) => {
|
|
200
|
+
if (e === null || typeof e != "object") return "an answer must be an object";
|
|
201
|
+
const n = e, { kind: r } = n;
|
|
202
|
+
if (r === "failure") return y(n.failure);
|
|
203
|
+
if (typeof r != "string" || !t.includes(r)) return `unexpected answer kind ${o(r)}`;
|
|
204
|
+
switch (r) {
|
|
205
|
+
case "grant":
|
|
206
|
+
return xe(n);
|
|
207
|
+
case "edit":
|
|
208
|
+
return typeof n.text != "string" || typeof n.history != "boolean" ? "an edit source needs text and history" : g(n.version) ? null : `an edit source needs a version; got ${o(n.version)}`;
|
|
209
|
+
case "draft":
|
|
210
|
+
return typeof n.text == "string" ? null : "a draft source needs text";
|
|
211
|
+
case "saved":
|
|
212
|
+
return g(n.version) ? null : `a saved answer needs a version; got ${o(n.version)}`;
|
|
213
|
+
case "conflict":
|
|
214
|
+
return typeof n.text != "string" ? "a conflict needs the current text" : g(n.version) ? null : `a conflict needs the current version; got ${o(n.version)}`;
|
|
215
|
+
case "preview": {
|
|
216
|
+
const { htmlContent: s, headings: i } = n;
|
|
217
|
+
if (typeof s != "string" || !Array.isArray(i)) return "a preview needs htmlContent and headings";
|
|
218
|
+
for (const c of i) {
|
|
219
|
+
const u = C(c);
|
|
220
|
+
if (u !== null) return u;
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
case "revisions": {
|
|
225
|
+
if (!Array.isArray(n.revisions)) return "revisions need an array";
|
|
226
|
+
for (const s of n.revisions) {
|
|
227
|
+
const i = Se(s);
|
|
228
|
+
if (i !== null) return i;
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
case "revision":
|
|
233
|
+
return typeof n.text != "string" ? "a revision answer needs text" : g(n.id) ? null : `a revision answer needs an id; got ${o(n.id)}`;
|
|
234
|
+
default:
|
|
235
|
+
return `unexpected answer kind ${o(r)}`;
|
|
236
|
+
}
|
|
237
|
+
}, ke = Object.freeze(["edit", "draft", "grant"]), Te = Object.freeze(["saved", "conflict", "grant"]), F = Object.freeze(["preview"]), $e = Object.freeze(["revisions"]), Le = Object.freeze(["revision"]), lt = (e) => m(e, ke) === null, ut = (e) => m(e, Te) === null, ft = (e) => m(e, F) === null, dt = (e) => m(e, $e) === null, pt = (e) => m(e, Le) === null, mt = (e) => e !== null && typeof e == "object" && e.kind === "unavailable" ? null : m(e, F), Et = (e, t) => ({ kind: "failure", failure: Pe(e, t) }), Pe = (e, t) => U(t) ? { reason: e, code: t } : { reason: e }, je = Object.freeze(["tree", "children", "ancestors", "reveal", "document", "text", "edit", "save", "preview", "revisions", "revision", "refresh", "asset", "link-card"]), h = Object.freeze({ source: "source", path: "path", version: "v", base: "base", revision: "revision", display: "as" }), ve = "asset", Ne = "link-card", gt = (e, t, n) => {
|
|
238
|
+
const r = `${e}/${ve}?${h.path}=${encodeURIComponent(t)}`;
|
|
239
|
+
return n === null ? r : `${r}&${h.version}=${encodeURIComponent(n)}`;
|
|
240
|
+
}, V = "text", K = "workbook", ht = (e) => {
|
|
241
|
+
if (!e.includes("?")) throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${o(e)}`);
|
|
242
|
+
return `${e}&${h.display}=${V}`;
|
|
243
|
+
}, yt = (e) => {
|
|
244
|
+
if (!e.includes("?")) throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${o(e)}`);
|
|
245
|
+
return `${e}&${h.display}=${K}`;
|
|
246
|
+
}, Rt = (e) => {
|
|
247
|
+
const t = e.getAll(h.display);
|
|
248
|
+
return t.length === 0 ? "file" : t.length !== 1 ? null : t[0] === V ? "text" : t[0] === K ? "workbook" : null;
|
|
249
|
+
}, bt = (e) => `${e}/${Ne}`, _t = "X-Markdown-Explorer-Scope", Ot = "X-Markdown-Explorer", At = "refresh", wt = "edit", xt = "text/markdown", St = (e) => je.includes(e), De = Object.freeze({
|
|
250
|
+
invalid: 400,
|
|
251
|
+
unauthorized: 401,
|
|
252
|
+
forbidden: 403,
|
|
253
|
+
"not-found": 404,
|
|
254
|
+
"too-large": 413,
|
|
255
|
+
"not-configured": 500,
|
|
256
|
+
unsupported: 500,
|
|
257
|
+
failed: 500
|
|
258
|
+
}), kt = (e) => {
|
|
259
|
+
const [t, ...n] = N.filter((r) => De[r] === e);
|
|
260
|
+
return t !== void 0 && n.length === 0 ? t : "failed";
|
|
261
|
+
}, Ue = /^\/(?:[A-Za-z0-9._~-]+\/)*[A-Za-z0-9._~-]+$/u, Ie = /^[\u0000- ]+|[\u0000- ]+$/gu, ze = /[\t\n\r]/gu, Ce = /^[a-z][a-z\d+.-]*:/iu, Xe = /^(?:\.|%2e){1,2}$/iu, He = /* @__PURE__ */ new Set(["ftp:", "file:", "http:", "https:", "ws:", "wss:"]), Me = Object.freeze(["http:", "https:"]), Fe = "http://path.invalid", P = Object.freeze(["origins", "resources", "links", "media"]), _ = (e) => Ue.test(e) && !e.split("/").some((t) => t === "." || t === ".."), Ve = (e) => {
|
|
262
|
+
if (!URL.canParse(e)) return !1;
|
|
263
|
+
const t = new URL(e);
|
|
264
|
+
return t.host !== "" && e === `${t.protocol}//${t.host}`;
|
|
265
|
+
}, Ke = (e) => {
|
|
266
|
+
if (!URL.canParse(e)) return !1;
|
|
267
|
+
const t = new URL(e);
|
|
268
|
+
return (t.protocol === "http:" || t.protocol === "https:") && e === `${t.origin}${t.pathname}` && _(t.pathname);
|
|
269
|
+
}, We = (e) => W(e) && Object.keys(e).length === P.length && P.every((t) => {
|
|
270
|
+
const n = Object.hasOwn(e, t) ? e[t] : void 0;
|
|
271
|
+
return Array.isArray(n) && Array.from(n).every((r) => typeof r == "string");
|
|
272
|
+
}), R = (e) => `${e.protocol}//${e.hostname.replace(/\.+$/u, "")}${e.port === "" ? "" : `:${e.port}`}`, b = (e, t) => t.some((n) => e === n || e.startsWith(`${n}/`)), Ge = (e) => e.slice(0, e.search(/[?#]|$/u)).split("/").some((t) => Xe.test(t)), Ye = (e, t) => {
|
|
273
|
+
switch (t) {
|
|
274
|
+
case "document-link":
|
|
275
|
+
return !0;
|
|
276
|
+
case "link":
|
|
277
|
+
return !Ge(e);
|
|
278
|
+
case "svg-reference":
|
|
279
|
+
return e.startsWith("#");
|
|
280
|
+
default:
|
|
281
|
+
return !1;
|
|
282
|
+
}
|
|
283
|
+
}, Be = (e) => {
|
|
284
|
+
if (!We(e)) throw new TypeError("[markdown-explorer] the HTML sanitizer's ownUrls must be a plain object of exactly origins, resources, links and media, each an array of strings");
|
|
285
|
+
const t = [
|
|
286
|
+
["origins", Ve, "an origin as the browser writes it (scheme://host[:port])"],
|
|
287
|
+
["resources", _, 'a mount path ("/" and segments of letters, digits and "._~-", without a "." or ".." segment or a trailing "/")'],
|
|
288
|
+
["links", _, 'a mount path ("/" and segments of letters, digits and "._~-", without a "." or ".." segment or a trailing "/")'],
|
|
289
|
+
["media", Ke, "an absolute http: or https: URL as the browser writes it, of an origin and a mount path"]
|
|
290
|
+
];
|
|
291
|
+
for (const [n, r, s] of t)
|
|
292
|
+
for (const [i, c] of e[n].entries())
|
|
293
|
+
if (!r(c)) throw new RangeError(`[markdown-explorer] the HTML sanitizer's ownUrls.${n}[${String(i)}] must be ${s}; got ${o(c)}`);
|
|
294
|
+
return Object.freeze({ origins: Object.freeze([...e.origins]), resources: Object.freeze([...e.resources]), links: Object.freeze([...e.links]), media: Object.freeze([...e.media]) });
|
|
295
|
+
}, Tt = (e) => {
|
|
296
|
+
const t = Be(e), n = t.origins.map((a) => new URL(a)), r = new Set(n.map(R)), s = new Set(n.map((a) => a.protocol).filter((a) => !He.has(a))), i = t.media.map((a) => {
|
|
297
|
+
const f = new URL(a);
|
|
298
|
+
return { key: R(f), path: f.pathname };
|
|
299
|
+
}), c = new Set(i.map((a) => a.key)), u = n.length === 0 ? Me : [...new Set(n.map((a) => a.protocol))], A = (a) => a === "link" || a === "document-link" ? t.links : t.resources, w = (a, f) => {
|
|
300
|
+
const l = R(a), E = r.has(l) || s.has(a.protocol);
|
|
301
|
+
return !(E || c.has(l)) || E && b(a.pathname, A(f)) ? !0 : f === "media" && i.some((x) => x.key === l && b(a.pathname, [x.path]));
|
|
302
|
+
};
|
|
303
|
+
return (a, f) => {
|
|
304
|
+
const l = a.replace(Ie, "").replace(ze, "");
|
|
305
|
+
return l.includes("\\") ? !1 : Ce.test(l) ? URL.canParse(l) && w(new URL(l), f) : l.startsWith("//") ? u.every((E) => URL.canParse(`${E}${l}`) && w(new URL(`${E}${l}`), f)) : l.startsWith("/") ? b(new URL(l, Fe).pathname, A(f)) : Ye(l, f);
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
export {
|
|
309
|
+
pt as $,
|
|
310
|
+
St as A,
|
|
311
|
+
De as B,
|
|
312
|
+
Ot as C,
|
|
313
|
+
Y as D,
|
|
314
|
+
et as E,
|
|
315
|
+
At as F,
|
|
316
|
+
wt as G,
|
|
317
|
+
_t as H,
|
|
318
|
+
h as I,
|
|
319
|
+
Rt as J,
|
|
320
|
+
xt as K,
|
|
321
|
+
_ as L,
|
|
322
|
+
G as M,
|
|
323
|
+
Ke as N,
|
|
324
|
+
Ve as O,
|
|
325
|
+
bt as P,
|
|
326
|
+
mt as Q,
|
|
327
|
+
b as R,
|
|
328
|
+
ht as S,
|
|
329
|
+
yt as T,
|
|
330
|
+
kt as U,
|
|
331
|
+
y as V,
|
|
332
|
+
ct as W,
|
|
333
|
+
ot as X,
|
|
334
|
+
st as Y,
|
|
335
|
+
be as Z,
|
|
336
|
+
it as _,
|
|
337
|
+
Je as a,
|
|
338
|
+
dt as a0,
|
|
339
|
+
ft as a1,
|
|
340
|
+
ut as a2,
|
|
341
|
+
lt as a3,
|
|
342
|
+
at as a4,
|
|
343
|
+
D as a5,
|
|
344
|
+
N as a6,
|
|
345
|
+
$ as b,
|
|
346
|
+
Tt as c,
|
|
347
|
+
We as d,
|
|
348
|
+
gt as e,
|
|
349
|
+
Qe as f,
|
|
350
|
+
Et as g,
|
|
351
|
+
pe as h,
|
|
352
|
+
j as i,
|
|
353
|
+
U as j,
|
|
354
|
+
Pe as k,
|
|
355
|
+
Ze as l,
|
|
356
|
+
nt as m,
|
|
357
|
+
rt as n,
|
|
358
|
+
L as o,
|
|
359
|
+
Ee as p,
|
|
360
|
+
ge as q,
|
|
361
|
+
Be as r,
|
|
362
|
+
Ae as s,
|
|
363
|
+
H as t,
|
|
364
|
+
g as u,
|
|
365
|
+
Se as v,
|
|
366
|
+
C as w,
|
|
367
|
+
p as x,
|
|
368
|
+
Re as y,
|
|
369
|
+
tt as z
|
|
370
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { H as l, c as g, M as f } from "./sanitizePolicy-CEMdaLUB.js";
|
|
2
|
+
const d = (s) => s instanceof Error ? `${s.name}: ${s.message}` : String(s), h = (s) => (
|
|
3
|
+
s instanceof l ? { status: "too-large" } : { status: "error", message: d(s) }
|
|
4
|
+
), H = (s) => {
|
|
5
|
+
const r = /* @__PURE__ */ new Map();
|
|
6
|
+
return (t) => {
|
|
7
|
+
try {
|
|
8
|
+
const { origins: e, resources: n, links: c, media: m } = t.ownUrls, o = JSON.stringify([t.iframeHosts, t.dataPath, e, n, c, m]);
|
|
9
|
+
let a = r.get(o);
|
|
10
|
+
a === void 0 && (a = g(s, t.iframeHosts, t.dataPath, f, t.ownUrls), r.set(o, a));
|
|
11
|
+
const i = a(t.html);
|
|
12
|
+
return i.length > t.maxSanitizedChars ? { status: "too-large" } : { status: "sanitized", html: i };
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return h(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
H as c,
|
|
20
|
+
h as s
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const i=require("./sanitizePolicy-CiQfnxyd.cjs"),z=t=>t instanceof Error?`${t.name}: ${t.message}`:String(t),c=t=>t instanceof i.HtmlNestingLimitError?{status:"too-large"}:{status:"error",message:z(t)},f=t=>{const r=new Map;return s=>{try{const{origins:a,resources:l,links:m,media:g}=s.ownUrls,n=JSON.stringify([s.iframeHosts,s.dataPath,a,l,m,g]);let e=r.get(n);e===void 0&&(e=i.createHtmlSanitizer(t,s.iframeHosts,s.dataPath,i.MAX_HTML_NESTING_DEPTH,s.ownUrls),r.set(n,e));const o=e(s.html);return o.length>s.maxSanitizedChars?{status:"too-large"}:{status:"sanitized",html:o}}catch(a){return c(a)}}};exports.createJobSanitizer=f;exports.sanitizeJobFailureOf=c;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { CODE_META_ATTRIBUTE as D } from "@aiquants/markdown/code-blocks";
|
|
2
|
+
import { allowedFrameUrlOf as U, reduceFrameFeatures as z, EMBED_FRAME_REFERRER_POLICIES as C, EMBED_LINK_ATTRIBUTE as E, placeholderLinkOf as M } from "@aiquants/markdown/embeds";
|
|
3
|
+
import { SOURCE_LINES_ATTRIBUTE as h, parseSourceLines as x } from "@aiquants/markdown/source-lines";
|
|
4
|
+
import { c as H, i as j, e as B } from "./ownUrls-Dh5g6ZJi.js";
|
|
5
|
+
import { d as F } from "./describeValue-CLlVRO8d.js";
|
|
6
|
+
const be = 256;
|
|
7
|
+
class G extends RangeError {
|
|
8
|
+
constructor(s) {
|
|
9
|
+
super(`[markdown-explorer] the HTML nests deeper than ${String(s)} levels`), this.name = "HtmlNestingLimitError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const y = ["script", "style", "noscript", "template", "form", "button", "textarea", "select", "option", "object", "embed", "base", "meta", "link", "frame", "frameset"], P = ["srcdoc", "formaction"], V = /^(?:(?:https?|mailto|tel):|[^a-z]|[a-z][a-z\d+.-]*(?:[^a-z\d+.:-]|$))/iu, W = /* @__PURE__ */ new Set(["left", "right", "center", "justify", "start", "end"]), v = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]), T = 1, $ = 3, X = 7, K = 8, Y = "http://www.w3.org/1999/xhtml", Z = "http://www.w3.org/2000/svg", q = Object.freeze(["src", "poster", "background", "href", "xlink:href"]), J = /* @__PURE__ */ new Set(["video", "audio", "source"]), Q = Object.freeze(["clip-path", "color-profile", "cursor", "fill", "filter", "marker-end", "marker-mid", "marker-start", "mask", "stroke"]), ee = Object.freeze(["image-set(", "image(", "src(", "element(", "cross-fade("]), te = /url\([\t\n\f\r ]*["']?(#?)/gu, re = /* @__PURE__ */ new Set([" ", `
|
|
13
|
+
`, "\f", "\r", " "]), w = Object.freeze({
|
|
14
|
+
a: Object.freeze(["target", "data-link-kind", "data-doc-path", "data-doc-exists", "data-footnote-ref", "data-footnote-backref"]),
|
|
15
|
+
area: Object.freeze(["target"]),
|
|
16
|
+
img: Object.freeze(["data-asset-src", "data-asset-exists"]),
|
|
17
|
+
section: Object.freeze(["data-footnotes"]),
|
|
18
|
+
code: Object.freeze([D]),
|
|
19
|
+
iframe: Object.freeze(["allow", "allowfullscreen", "frameborder", "referrerpolicy"])
|
|
20
|
+
}), se = [.../* @__PURE__ */ new Set([...Object.values(w).flatMap((t) => t.filter((s) => s.startsWith("data-"))), h])], oe = /* @__PURE__ */ new Set(["src", "href", "xlink:href"]), ae = /^data:/iu, ne = Object.freeze({
|
|
21
|
+
FORBID_TAGS: y,
|
|
22
|
+
FORBID_ATTR: P,
|
|
23
|
+
ADD_TAGS: ["iframe"],
|
|
24
|
+
ADD_ATTR: (t, s) => t === h || w[s]?.includes(t) === !0,
|
|
25
|
+
ADD_URI_SAFE_ATTR: se,
|
|
26
|
+
ALLOWED_URI_REGEXP: V,
|
|
27
|
+
ALLOW_DATA_ATTR: !1
|
|
28
|
+
}), ie = (t) => {
|
|
29
|
+
let s = null;
|
|
30
|
+
for (const i of t.split(";")) {
|
|
31
|
+
const n = i.indexOf(":");
|
|
32
|
+
if (n < 0 || i.slice(0, n).trim().toLowerCase() !== "text-align") continue;
|
|
33
|
+
const c = i.slice(n + 1).trim().toLowerCase();
|
|
34
|
+
W.has(c) && (s = c);
|
|
35
|
+
}
|
|
36
|
+
return s === null ? null : `text-align: ${s}`;
|
|
37
|
+
}, le = (t) => t.nodeType === $ ? { kind: "text", text: t.nodeValue ?? "" } : t.nodeType === K || t.nodeType === X ? { kind: "ignored" } : t.nodeType === T && t.nodeName.toLowerCase() === "a" ? { kind: "link", href: t.getAttribute("href") } : { kind: "element" }, ce = (t) => {
|
|
38
|
+
const s = t.getAttribute("type");
|
|
39
|
+
return s !== null && s.trim().toLowerCase() === "checkbox" && t.hasAttribute("disabled");
|
|
40
|
+
}, N = (t) => t.replace(/[A-Z]/gu, (s) => s.toLowerCase()), ue = (t) => {
|
|
41
|
+
const s = [], i = (c) => re.has(t.charAt(c));
|
|
42
|
+
let n = 0;
|
|
43
|
+
for (; n < t.length; ) {
|
|
44
|
+
if (i(n) || t.charAt(n) === ",") {
|
|
45
|
+
n += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const c = n;
|
|
49
|
+
for (; n < t.length && !i(n); ) n += 1;
|
|
50
|
+
const d = t.slice(c, n);
|
|
51
|
+
if (s.push(d.replace(/,+$/u, "")), d.endsWith(",")) continue;
|
|
52
|
+
let A = !1;
|
|
53
|
+
for (; n < t.length; ) {
|
|
54
|
+
const u = t.charAt(n);
|
|
55
|
+
if (n += 1, A) A = u !== ")";
|
|
56
|
+
else if (u === "(") A = !0;
|
|
57
|
+
else if (u === ",") break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return s;
|
|
61
|
+
}, fe = (t) => {
|
|
62
|
+
if (t.includes("\\")) return !1;
|
|
63
|
+
const s = N(t);
|
|
64
|
+
return !ee.some((i) => s.includes(i)) && [...s.matchAll(te)].every((i) => i[1] === "#");
|
|
65
|
+
}, de = (t, s, i) => i === "src" ? J.has(s) ? "media" : "resource" : i !== "href" && i !== "xlink:href" ? "resource" : t.namespaceURI === Z ? s === "image" ? "resource" : s === "a" && i === "href" ? "link" : "svg-reference" : i === "xlink:href" ? "resource" : s === "a" && t.namespaceURI === Y && t.getAttribute("data-link-kind") === "doc" ? "document-link" : "link", Ae = (t) => {
|
|
66
|
+
const s = t.getAttribute("preload");
|
|
67
|
+
t.setAttribute("preload", s !== null && N(s) === "none" ? "none" : "metadata");
|
|
68
|
+
}, Se = (t, s, i, n, c) => {
|
|
69
|
+
if (t.isSupported !== !0) throw new Error("[markdown-explorer] the HTML sanitizer cannot run in this environment");
|
|
70
|
+
if (!Number.isSafeInteger(n) || n <= 0) throw new RangeError(`[markdown-explorer] the HTML sanitizer's depth limit must be a positive integer; got ${F(n)}`);
|
|
71
|
+
const d = H(c), A = Object.freeze([...s]);
|
|
72
|
+
let u = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), m;
|
|
73
|
+
const b = (r) => {
|
|
74
|
+
const e = r.parentNode === null ? void 0 : u.get(r.parentNode), o = e === void 0 ? 0 : e + 1;
|
|
75
|
+
if (u.set(r, o), r.nodeType === T && o > n) throw new G(n);
|
|
76
|
+
}, S = (r, e) => {
|
|
77
|
+
if (r.nodeType !== T) return;
|
|
78
|
+
const o = r;
|
|
79
|
+
(e.tagName === "input" && !ce(o) || e.tagName === "iframe" && U(o.getAttribute("src")?.trim(), A) === null) && o.parentNode?.removeChild(o);
|
|
80
|
+
}, k = (r, e) => {
|
|
81
|
+
const o = r.nodeName.toLowerCase();
|
|
82
|
+
if (e.attrName === "style") {
|
|
83
|
+
const a = ie(e.attrValue);
|
|
84
|
+
a === null ? e.keepAttr = !1 : e.attrValue = a;
|
|
85
|
+
} else if (e.attrName === "allow" && o === "iframe") {
|
|
86
|
+
const a = z(e.attrValue);
|
|
87
|
+
a === null ? e.keepAttr = !1 : e.attrValue = a;
|
|
88
|
+
} else if (e.attrName === "referrerpolicy" && o === "iframe") {
|
|
89
|
+
const a = e.attrValue.trim().toLowerCase();
|
|
90
|
+
C.has(a) ? e.attrValue = a : e.keepAttr = !1;
|
|
91
|
+
} else e.attrName === E && o === "p" ? p.set(r, r.getAttribute(E)) : oe.has(e.attrName) && ae.test(e.attrValue) || e.attrName === h && x(e.attrValue) === null ? e.keepAttr = !1 : e.attrName === "id" && v.has(o) && (e.forceKeepAttr = !0);
|
|
92
|
+
}, R = (r) => {
|
|
93
|
+
const e = r.getAttribute("data-asset-src");
|
|
94
|
+
e !== null && (r.getAttribute("data-asset-exists") !== "false" && j(e) ? r.setAttribute("src", B(i, e, null)) : r.removeAttribute("src"));
|
|
95
|
+
}, _ = (r, e, o, a) => {
|
|
96
|
+
if (m === void 0) return;
|
|
97
|
+
const l = r.getAttribute(o);
|
|
98
|
+
if (l === null) return;
|
|
99
|
+
const f = m({ kind: e, path: l });
|
|
100
|
+
f !== void 0 && r.setAttribute(a, String(f));
|
|
101
|
+
}, O = (r) => {
|
|
102
|
+
const e = r.parentNode;
|
|
103
|
+
if (e === null) return;
|
|
104
|
+
const o = p.get(e);
|
|
105
|
+
o != null && M(o, [...e.childNodes].map(le)) !== null && e.setAttribute(E, o);
|
|
106
|
+
}, I = (r, e) => {
|
|
107
|
+
for (const a of q) {
|
|
108
|
+
const l = r.getAttribute(a);
|
|
109
|
+
l !== null && !d(l, de(r, e, a)) && r.removeAttribute(a);
|
|
110
|
+
}
|
|
111
|
+
const o = r.getAttribute("srcset");
|
|
112
|
+
o !== null && !ue(o).every((a) => d(a, "resource")) && r.removeAttribute("srcset");
|
|
113
|
+
for (const a of Q) {
|
|
114
|
+
const l = r.getAttribute(a);
|
|
115
|
+
l !== null && !fe(l) && r.removeAttribute(a);
|
|
116
|
+
}
|
|
117
|
+
}, g = (r) => {
|
|
118
|
+
if (r.nodeType !== T) return;
|
|
119
|
+
const e = r, o = e.nodeName.toLowerCase();
|
|
120
|
+
o === "img" && (_(e, "asset", "data-asset-src", "data-asset-exists"), R(e)), I(e, o), o === "a" ? (_(e, "doc", "data-doc-path", "data-doc-exists"), O(e)) : (o === "video" || o === "audio") && Ae(e);
|
|
121
|
+
const a = e.getAttribute("target");
|
|
122
|
+
if (a === null || a.trim().toLowerCase() === "_self") return;
|
|
123
|
+
const l = e.getAttribute("rel"), f = new Set(l === null ? [] : l.split(/\s+/u).filter((L) => L !== ""));
|
|
124
|
+
f.add("noopener"), f.add("noreferrer"), e.setAttribute("rel", [...f].join(" "));
|
|
125
|
+
};
|
|
126
|
+
return (r, e) => {
|
|
127
|
+
u = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), m = e, t.addHook("beforeSanitizeElements", b), t.addHook("uponSanitizeElement", S), t.addHook("uponSanitizeAttribute", k), t.addHook("afterSanitizeAttributes", g);
|
|
128
|
+
try {
|
|
129
|
+
return t.sanitize(r, ne);
|
|
130
|
+
} finally {
|
|
131
|
+
t.removeHook("beforeSanitizeElements", b), t.removeHook("uponSanitizeElement", S), t.removeHook("uponSanitizeAttribute", k), t.removeHook("afterSanitizeAttributes", g), m = void 0;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
export {
|
|
136
|
+
G as H,
|
|
137
|
+
be as M,
|
|
138
|
+
Se as c
|
|
139
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const z=require("@aiquants/markdown/code-blocks"),f=require("@aiquants/markdown/embeds"),p=require("@aiquants/markdown/source-lines"),_=require("./ownUrls-B259RGgd.cjs"),C=require("./describeValue-Ccvhbt36.cjs"),M=256;class w extends RangeError{constructor(s){super(`[markdown-explorer] the HTML nests deeper than ${String(s)} levels`),this.name="HtmlNestingLimitError"}}const H=["script","style","noscript","template","form","button","textarea","select","option","object","embed","base","meta","link","frame","frameset"],B=["srcdoc","formaction"],x=/^(?:(?:https?|mailto|tel):|[^a-z]|[a-z][a-z\d+.-]*(?:[^a-z\d+.:-]|$))/iu,j=new Set(["left","right","center","justify","start","end"]),F=new Set(["h1","h2","h3","h4","h5","h6"]),m=1,G=3,P=7,y=8,V="http://www.w3.org/1999/xhtml",W="http://www.w3.org/2000/svg",v=Object.freeze(["src","poster","background","href","xlink:href"]),q=new Set(["video","audio","source"]),X=Object.freeze(["clip-path","color-profile","cursor","fill","filter","marker-end","marker-mid","marker-start","mask","stroke"]),$=Object.freeze(["image-set(","image(","src(","element(","cross-fade("]),K=/url\([\t\n\f\r ]*["']?(#?)/gu,Y=new Set([" ",`
|
|
2
|
+
`,"\f","\r"," "]),R=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"]),code:Object.freeze([z.CODE_META_ATTRIBUTE]),iframe:Object.freeze(["allow","allowfullscreen","frameborder","referrerpolicy"])}),Z=[...new Set([...Object.values(R).flatMap(t=>t.filter(s=>s.startsWith("data-"))),p.SOURCE_LINES_ATTRIBUTE])],J=new Set(["src","href","xlink:href"]),Q=/^data:/iu,ee=Object.freeze({FORBID_TAGS:H,FORBID_ATTR:B,ADD_TAGS:["iframe"],ADD_ATTR:(t,s)=>t===p.SOURCE_LINES_ATTRIBUTE||R[s]?.includes(t)===!0,ADD_URI_SAFE_ATTR:Z,ALLOWED_URI_REGEXP:x,ALLOW_DATA_ATTR:!1}),te=t=>{let s=null;for(const i of t.split(";")){const n=i.indexOf(":");if(n<0||i.slice(0,n).trim().toLowerCase()!=="text-align")continue;const c=i.slice(n+1).trim().toLowerCase();j.has(c)&&(s=c)}return s===null?null:`text-align: ${s}`},re=t=>t.nodeType===G?{kind:"text",text:t.nodeValue??""}:t.nodeType===y||t.nodeType===P?{kind:"ignored"}:t.nodeType===m&&t.nodeName.toLowerCase()==="a"?{kind:"link",href:t.getAttribute("href")}:{kind:"element"},se=t=>{const s=t.getAttribute("type");return s!==null&&s.trim().toLowerCase()==="checkbox"&&t.hasAttribute("disabled")},I=t=>t.replace(/[A-Z]/gu,s=>s.toLowerCase()),oe=t=>{const s=[],i=c=>Y.has(t.charAt(c));let n=0;for(;n<t.length;){if(i(n)||t.charAt(n)===","){n+=1;continue}const c=n;for(;n<t.length&&!i(n);)n+=1;const A=t.slice(c,n);if(s.push(A.replace(/,+$/u,"")),A.endsWith(","))continue;let T=!1;for(;n<t.length;){const u=t.charAt(n);if(n+=1,T)T=u!==")";else if(u==="(")T=!0;else if(u===",")break}}return s},ae=t=>{if(t.includes("\\"))return!1;const s=I(t);return!$.some(i=>s.includes(i))&&[...s.matchAll(K)].every(i=>i[1]==="#")},ne=(t,s,i)=>i==="src"?q.has(s)?"media":"resource":i!=="href"&&i!=="xlink:href"?"resource":t.namespaceURI===W?s==="image"?"resource":s==="a"&&i==="href"?"link":"svg-reference":i==="xlink:href"?"resource":s==="a"&&t.namespaceURI===V&&t.getAttribute("data-link-kind")==="doc"?"document-link":"link",ie=t=>{const s=t.getAttribute("preload");t.setAttribute("preload",s!==null&&I(s)==="none"?"none":"metadata")},le=(t,s,i,n,c)=>{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 ${C.describeValue(n)}`);const A=_.createOwnUrlRule(c),T=Object.freeze([...s]);let u=new WeakMap,h=new WeakMap,E;const S=r=>{const e=r.parentNode===null?void 0:u.get(r.parentNode),o=e===void 0?0:e+1;if(u.set(r,o),r.nodeType===m&&o>n)throw new w(n)},b=(r,e)=>{if(r.nodeType!==m)return;const o=r;(e.tagName==="input"&&!se(o)||e.tagName==="iframe"&&f.allowedFrameUrlOf(o.getAttribute("src")?.trim(),T)===null)&&o.parentNode?.removeChild(o)},k=(r,e)=>{const o=r.nodeName.toLowerCase();if(e.attrName==="style"){const a=te(e.attrValue);a===null?e.keepAttr=!1:e.attrValue=a}else if(e.attrName==="allow"&&o==="iframe"){const a=f.reduceFrameFeatures(e.attrValue);a===null?e.keepAttr=!1:e.attrValue=a}else if(e.attrName==="referrerpolicy"&&o==="iframe"){const a=e.attrValue.trim().toLowerCase();f.EMBED_FRAME_REFERRER_POLICIES.has(a)?e.attrValue=a:e.keepAttr=!1}else e.attrName===f.EMBED_LINK_ATTRIBUTE&&o==="p"?h.set(r,r.getAttribute(f.EMBED_LINK_ATTRIBUTE)):J.has(e.attrName)&&Q.test(e.attrValue)||e.attrName===p.SOURCE_LINES_ATTRIBUTE&&p.parseSourceLines(e.attrValue)===null?e.keepAttr=!1:e.attrName==="id"&&F.has(o)&&(e.forceKeepAttr=!0)},L=r=>{const e=r.getAttribute("data-asset-src");e!==null&&(r.getAttribute("data-asset-exists")!=="false"&&_.isAcceptableDocumentPath(e)?r.setAttribute("src",_.explorerAssetHref(i,e,null)):r.removeAttribute("src"))},N=(r,e,o,a)=>{if(E===void 0)return;const l=r.getAttribute(o);if(l===null)return;const d=E({kind:e,path:l});d!==void 0&&r.setAttribute(a,String(d))},O=r=>{const e=r.parentNode;if(e===null)return;const o=h.get(e);o!=null&&f.placeholderLinkOf(o,[...e.childNodes].map(re))!==null&&e.setAttribute(f.EMBED_LINK_ATTRIBUTE,o)},U=(r,e)=>{for(const a of v){const l=r.getAttribute(a);l!==null&&!A(l,ne(r,e,a))&&r.removeAttribute(a)}const o=r.getAttribute("srcset");o!==null&&!oe(o).every(a=>A(a,"resource"))&&r.removeAttribute("srcset");for(const a of X){const l=r.getAttribute(a);l!==null&&!ae(l)&&r.removeAttribute(a)}},g=r=>{if(r.nodeType!==m)return;const e=r,o=e.nodeName.toLowerCase();o==="img"&&(N(e,"asset","data-asset-src","data-asset-exists"),L(e)),U(e,o),o==="a"?(N(e,"doc","data-doc-path","data-doc-exists"),O(e)):(o==="video"||o==="audio")&&ie(e);const a=e.getAttribute("target");if(a===null||a.trim().toLowerCase()==="_self")return;const l=e.getAttribute("rel"),d=new Set(l===null?[]:l.split(/\s+/u).filter(D=>D!==""));d.add("noopener"),d.add("noreferrer"),e.setAttribute("rel",[...d].join(" "))};return(r,e)=>{u=new WeakMap,h=new WeakMap,E=e,t.addHook("beforeSanitizeElements",S),t.addHook("uponSanitizeElement",b),t.addHook("uponSanitizeAttribute",k),t.addHook("afterSanitizeAttributes",g);try{return t.sanitize(r,ee)}finally{t.removeHook("beforeSanitizeElements",S),t.removeHook("uponSanitizeElement",b),t.removeHook("uponSanitizeAttribute",k),t.removeHook("afterSanitizeAttributes",g),E=void 0}}};exports.HtmlNestingLimitError=w;exports.MAX_HTML_NESTING_DEPTH=M;exports.createHtmlSanitizer=le;
|