@aiquants/markdown-explorer 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +40 -25
  3. package/dist/{EditSurface-Co4Rvfa1.cjs → EditSurface-B1yD7ywF.cjs} +1 -1
  4. package/dist/{EditSurface-Blymamic.js → EditSurface-sUNqYw9o.js} +5 -5
  5. package/dist/{ExplorerSplit-WApgYMPb.cjs → ExplorerSplit-Bn3ZnEMZ.cjs} +1 -1
  6. package/dist/{ExplorerSplit-BZ0PA3z3.js → ExplorerSplit-pClUl3-e.js} +3 -3
  7. package/dist/{MultiLayout-dAW_JCzg.cjs → MultiLayout-0Jh08fxo.cjs} +1 -1
  8. package/dist/{MultiLayout-B5-1N3JD.js → MultiLayout-B-ft4_Vs.js} +4 -4
  9. package/dist/{NativeScrollBar-BraWuZvN.js → NativeScrollBar-ByawerpG.js} +1 -1
  10. package/dist/{NativeScrollBar-ThVMbI0Y.cjs → NativeScrollBar-D9QrjRJa.cjs} +1 -1
  11. package/dist/{TreeLayout-C60lb9hP.cjs → TreeLayout-CXHbKdxy.cjs} +1 -1
  12. package/dist/{TreeLayout-CChoxh9W.js → TreeLayout-DjIVKBG4.js} +3 -3
  13. package/dist/core/config.d.cts +7 -0
  14. package/dist/core/config.d.ts +7 -0
  15. package/dist/core/contracts.d.cts +8 -2
  16. package/dist/core/contracts.d.ts +8 -2
  17. package/dist/core/dataRoute.d.cts +40 -0
  18. package/dist/core/dataRoute.d.ts +40 -0
  19. package/dist/core/labels.d.cts +10 -1
  20. package/dist/core/labels.d.ts +10 -1
  21. package/dist/{dataRoute-BEvesOvN.js → dataRoute-DLhQfdoW.js} +111 -103
  22. package/dist/dataRoute-DwYtgyt6.cjs +1 -0
  23. package/dist/index-BNAkC0g3.js +4800 -0
  24. package/dist/index-DRMNpWDJ.cjs +15 -0
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.d.cts +2 -2
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.js +27 -26
  29. package/dist/{location-DIxIjqs7.js → location-BNFdxzhn.js} +134 -130
  30. package/dist/location-yvU5HUY1.cjs +1 -0
  31. package/dist/{merge-DRWmjC24.cjs → merge-BBU1pDoT.cjs} +1 -1
  32. package/dist/{merge-CgSp-0Dd.js → merge-DhHzRcAI.js} +1 -1
  33. package/dist/{sanitizePolicy-gVKBhabq.js → sanitizePolicy-By0tKOpZ.js} +1 -1
  34. package/dist/{sanitizePolicy-CZwOaJ92.cjs → sanitizePolicy-T5T-3vV5.cjs} +1 -1
  35. package/dist/sanitizeWorker.cjs +1 -1
  36. package/dist/sanitizeWorker.js +1 -1
  37. package/dist/server/ports.d.cts +4 -3
  38. package/dist/server/ports.d.ts +4 -3
  39. package/dist/server.cjs +1 -1
  40. package/dist/server.js +500 -493
  41. package/dist/styles/markdown-explorer.css +1 -1
  42. package/dist/{useSplitPersistence-Df63lnQZ.js → useSplitPersistence-D5EjJwCg.js} +1 -1
  43. package/dist/{useSplitPersistence-D-T75Hlh.cjs → useSplitPersistence-xGOSwpLM.cjs} +1 -1
  44. package/docs/behavior/dom-hooks.md +10 -6
  45. package/docs/behavior/layout.md +8 -3
  46. package/docs/behavior/localization.md +5 -2
  47. package/docs/behavior/security.md +7 -2
  48. package/docs/behavior/url-contract.md +3 -3
  49. package/package.json +5 -5
  50. package/dist/dataRoute-Cv7fgCW7.cjs +0 -1
  51. package/dist/index-B6FkGD-p.cjs +0 -13
  52. package/dist/index-Bd6hgisa.js +0 -4097
  53. package/dist/location-D3DgoELB.cjs +0 -1
@@ -35,6 +35,7 @@ export type ExplorerConfigInput = {
35
35
  readonly legacyTextEncoding?: string;
36
36
  readonly spreadsheets?: {
37
37
  readonly maxBytes?: number;
38
+ readonly maxWorkbookBytes?: number;
38
39
  };
39
40
  };
40
41
  export type ExplorerConfig = {
@@ -60,6 +61,7 @@ export type ExplorerConfig = {
60
61
  readonly legacyTextEncoding: string | null;
61
62
  readonly spreadsheets: {
62
63
  readonly maxBytes: number;
64
+ readonly maxWorkbookBytes: number;
63
65
  };
64
66
  };
65
67
  export declare const DEFAULT_VIEW_SLUGS: ExplorerViewSlugs;
@@ -93,6 +95,11 @@ export declare const SPREADSHEET_BYTE_LIMITS: Readonly<{
93
95
  min: 1;
94
96
  max: number;
95
97
  }>;
98
+ export declare const WORKBOOK_BYTE_LIMITS: Readonly<{
99
+ default: number;
100
+ min: 1;
101
+ max: number;
102
+ }>;
96
103
  export declare const defineExplorerConfig: (input: ExplorerConfigInput) => ExplorerConfig;
97
104
  export declare const revalidateExplorerConfig: (config: ExplorerConfig) => ExplorerConfig;
98
105
  export declare const isExplorerSourceId: (value: unknown) => value is string;
@@ -28,9 +28,15 @@ export declare const EXPLORER_IMAGE_TYPES: readonly [
28
28
  export type ExplorerImageType = (typeof EXPLORER_IMAGE_TYPES)[number];
29
29
  export declare const EXPLORER_SPREADSHEET_FORMATS: readonly [
30
30
  "csv",
31
- "tsv"
31
+ "tsv",
32
+ "workbook"
32
33
  ];
33
34
  export type ExplorerSpreadsheetFormat = (typeof EXPLORER_SPREADSHEET_FORMATS)[number];
35
+ export declare const EXPLORER_SHEET_TEXT_FORMATS: readonly [
36
+ "csv",
37
+ "tsv"
38
+ ];
39
+ export type ExplorerSheetTextFormat = (typeof EXPLORER_SHEET_TEXT_FORMATS)[number];
34
40
  export declare const EXPLORER_NOTICE_TONES: readonly [
35
41
  "info",
36
42
  "warning",
@@ -135,7 +141,7 @@ export type ExplorerSpreadsheetDocument = {
135
141
  readonly name: string;
136
142
  readonly url: string;
137
143
  readonly format: ExplorerSpreadsheetFormat;
138
- readonly firstSheetOnly: boolean;
144
+ readonly firstSheetText: ExplorerSheetTextFormat | null;
139
145
  readonly edit: ExplorerExternalEdit | null;
140
146
  };
141
147
  export type ExplorerDocument = {
@@ -28,9 +28,15 @@ export declare const EXPLORER_IMAGE_TYPES: readonly [
28
28
  export type ExplorerImageType = (typeof EXPLORER_IMAGE_TYPES)[number];
29
29
  export declare const EXPLORER_SPREADSHEET_FORMATS: readonly [
30
30
  "csv",
31
- "tsv"
31
+ "tsv",
32
+ "workbook"
32
33
  ];
33
34
  export type ExplorerSpreadsheetFormat = (typeof EXPLORER_SPREADSHEET_FORMATS)[number];
35
+ export declare const EXPLORER_SHEET_TEXT_FORMATS: readonly [
36
+ "csv",
37
+ "tsv"
38
+ ];
39
+ export type ExplorerSheetTextFormat = (typeof EXPLORER_SHEET_TEXT_FORMATS)[number];
34
40
  export declare const EXPLORER_NOTICE_TONES: readonly [
35
41
  "info",
36
42
  "warning",
@@ -135,7 +141,7 @@ export type ExplorerSpreadsheetDocument = {
135
141
  readonly name: string;
136
142
  readonly url: string;
137
143
  readonly format: ExplorerSpreadsheetFormat;
138
- readonly firstSheetOnly: boolean;
144
+ readonly firstSheetText: ExplorerSheetTextFormat | null;
139
145
  readonly edit: ExplorerExternalEdit | null;
140
146
  };
141
147
  export type ExplorerDocument = {
@@ -0,0 +1,40 @@
1
+ import { ExplorerFailureReason } from "./contracts.cjs";
2
+ export declare const EXPLORER_DATA_OPERATIONS: readonly [
3
+ "tree",
4
+ "children",
5
+ "ancestors",
6
+ "reveal",
7
+ "document",
8
+ "text",
9
+ "edit",
10
+ "save",
11
+ "preview",
12
+ "revisions",
13
+ "revision",
14
+ "refresh",
15
+ "asset",
16
+ "link-card"
17
+ ];
18
+ export type ExplorerDataOperation = (typeof EXPLORER_DATA_OPERATIONS)[number];
19
+ export declare const EXPLORER_DATA_QUERY: Readonly<{
20
+ readonly source: "source";
21
+ readonly path: "path";
22
+ readonly version: "v";
23
+ readonly base: "base";
24
+ readonly revision: "revision";
25
+ readonly display: "as";
26
+ }>;
27
+ export declare const explorerAssetHref: (dataPath: string, path: string, version: string | null) => string;
28
+ export type ExplorerAssetDisplay = "file" | "text" | "workbook";
29
+ export declare const explorerPlainTextHref: (assetHref: string) => string;
30
+ export declare const explorerWorkbookHref: (assetHref: string) => string;
31
+ export declare const readExplorerAssetDisplay: (search: URLSearchParams) => ExplorerAssetDisplay | null;
32
+ export declare const explorerLinkCardEndpoint: (dataPath: string) => string;
33
+ export declare const EXPLORER_SCOPE_HEADER = "X-Markdown-Explorer-Scope";
34
+ export declare const EXPLORER_PROOF_HEADER = "X-Markdown-Explorer";
35
+ export declare const EXPLORER_REFRESH_PROOF = "refresh";
36
+ export declare const EXPLORER_EDIT_PROOF = "edit";
37
+ export declare const EXPLORER_DRAFT_MEDIA_TYPE = "text/markdown";
38
+ export declare const isExplorerDataOperation: (segment: string | undefined) => segment is ExplorerDataOperation;
39
+ export declare const EXPLORER_FAILURE_STATUS: Readonly<Record<ExplorerFailureReason, number>>;
40
+ export declare const failureReasonOfStatus: (status: number) => ExplorerFailureReason;
@@ -0,0 +1,40 @@
1
+ import { ExplorerFailureReason } from "./contracts.js";
2
+ export declare const EXPLORER_DATA_OPERATIONS: readonly [
3
+ "tree",
4
+ "children",
5
+ "ancestors",
6
+ "reveal",
7
+ "document",
8
+ "text",
9
+ "edit",
10
+ "save",
11
+ "preview",
12
+ "revisions",
13
+ "revision",
14
+ "refresh",
15
+ "asset",
16
+ "link-card"
17
+ ];
18
+ export type ExplorerDataOperation = (typeof EXPLORER_DATA_OPERATIONS)[number];
19
+ export declare const EXPLORER_DATA_QUERY: Readonly<{
20
+ readonly source: "source";
21
+ readonly path: "path";
22
+ readonly version: "v";
23
+ readonly base: "base";
24
+ readonly revision: "revision";
25
+ readonly display: "as";
26
+ }>;
27
+ export declare const explorerAssetHref: (dataPath: string, path: string, version: string | null) => string;
28
+ export type ExplorerAssetDisplay = "file" | "text" | "workbook";
29
+ export declare const explorerPlainTextHref: (assetHref: string) => string;
30
+ export declare const explorerWorkbookHref: (assetHref: string) => string;
31
+ export declare const readExplorerAssetDisplay: (search: URLSearchParams) => ExplorerAssetDisplay | null;
32
+ export declare const explorerLinkCardEndpoint: (dataPath: string) => string;
33
+ export declare const EXPLORER_SCOPE_HEADER = "X-Markdown-Explorer-Scope";
34
+ export declare const EXPLORER_PROOF_HEADER = "X-Markdown-Explorer";
35
+ export declare const EXPLORER_REFRESH_PROOF = "refresh";
36
+ export declare const EXPLORER_EDIT_PROOF = "edit";
37
+ export declare const EXPLORER_DRAFT_MEDIA_TYPE = "text/markdown";
38
+ export declare const isExplorerDataOperation: (segment: string | undefined) => segment is ExplorerDataOperation;
39
+ export declare const EXPLORER_FAILURE_STATUS: Readonly<Record<ExplorerFailureReason, number>>;
40
+ export declare const failureReasonOfStatus: (status: number) => ExplorerFailureReason;
@@ -197,7 +197,16 @@ export type MarkdownExplorerLabels = MarkdownExplorerSpreadsheetLabels & {
197
197
  readonly mediaUnsupported: string;
198
198
  readonly fileNotShown: string;
199
199
  readonly pdfNotShown: string;
200
- readonly spreadsheetFirstSheetOnly: string;
200
+ readonly spreadsheetWorkbookFirstSheet: string;
201
+ readonly spreadsheetSheets: (name: string) => string;
202
+ readonly spreadsheetSheetName: (name: string, sheet: string) => string;
203
+ readonly spreadsheetUnshownSheets: (count: number) => string;
204
+ readonly spreadsheetUnlistedSheets: (count: number) => string;
205
+ readonly spreadsheetSheetLoading: string;
206
+ readonly spreadsheetSheetEmpty: string;
207
+ readonly spreadsheetWorkbookEncrypted: string;
208
+ readonly spreadsheetNotWorkbook: string;
209
+ readonly spreadsheetWorkbookTooLarge: string;
201
210
  readonly spreadsheetTruncated: string;
202
211
  readonly spreadsheetUnreadableEncoding: (encodings: readonly string[]) => string;
203
212
  readonly spreadsheetEmpty: string;
@@ -197,7 +197,16 @@ export type MarkdownExplorerLabels = MarkdownExplorerSpreadsheetLabels & {
197
197
  readonly mediaUnsupported: string;
198
198
  readonly fileNotShown: string;
199
199
  readonly pdfNotShown: string;
200
- readonly spreadsheetFirstSheetOnly: string;
200
+ readonly spreadsheetWorkbookFirstSheet: string;
201
+ readonly spreadsheetSheets: (name: string) => string;
202
+ readonly spreadsheetSheetName: (name: string, sheet: string) => string;
203
+ readonly spreadsheetUnshownSheets: (count: number) => string;
204
+ readonly spreadsheetUnlistedSheets: (count: number) => string;
205
+ readonly spreadsheetSheetLoading: string;
206
+ readonly spreadsheetSheetEmpty: string;
207
+ readonly spreadsheetWorkbookEncrypted: string;
208
+ readonly spreadsheetNotWorkbook: string;
209
+ readonly spreadsheetWorkbookTooLarge: string;
201
210
  readonly spreadsheetTruncated: string;
202
211
  readonly spreadsheetUnreadableEncoding: (encodings: readonly string[]) => string;
203
212
  readonly spreadsheetEmpty: string;
@@ -1,5 +1,5 @@
1
- const he = 4096;
2
- const P = Object.freeze([
1
+ const Ae = 4096;
2
+ const N = Object.freeze([
3
3
  ".env*",
4
4
  "*.env",
5
5
  "*.env.*",
@@ -57,21 +57,21 @@ const P = Object.freeze([
57
57
  "*.tfvars.json",
58
58
  ".*_history",
59
59
  "fish_history"
60
- ]), w = /[\u0000-\u001f\u007f]/u, L = /\p{Cs}/u, be = (e) => {
60
+ ]), P = /[\u0000-\u001f\u007f]/u, L = /\p{Cs}/u, _e = (e) => {
61
61
  const t = e.split("/").filter((n) => n !== "").at(-1);
62
62
  return t === void 0 ? e : t;
63
- }, R = (e) => e.length > 0 && e.length <= 4096 && !L.test(e) && !w.test(e) && !e.includes("\\"), h = (e) => e.normalize("NFKC").toUpperCase().toLowerCase(), k = /(?:%[0-9A-Fa-f]{2})+/gu, D = new TextDecoder("utf-8"), j = /[/\\]/u, $ = (e) => e.replace(
64
- k,
65
- (t) => D.decode(
63
+ }, R = (e) => e.length > 0 && e.length <= 4096 && !L.test(e) && !P.test(e) && !e.includes("\\"), h = (e) => e.normalize("NFKC").toUpperCase().toLowerCase(), D = /(?:%[0-9A-Fa-f]{2})+/gu, $ = new TextDecoder("utf-8"), j = /[/\\]/u, I = (e) => e.replace(
64
+ D,
65
+ (t) => $.decode(
66
66
  Uint8Array.from(
67
67
  t.slice(1).split("%").map((n) => Number.parseInt(n, 16))
68
68
  )
69
69
  )
70
- ), I = (e) => {
70
+ ), z = (e) => {
71
71
  const t = [e];
72
72
  let n = e;
73
73
  for (let r = 0; r < 3 && n.includes("%"); r += 1) {
74
- const s = $(n);
74
+ const s = I(n);
75
75
  if (s === n) break;
76
76
  t.push(s), n = s;
77
77
  }
@@ -81,108 +81,112 @@ const P = Object.freeze([
81
81
  throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);
82
82
  const t = h(e).split("*").map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*");
83
83
  return new RegExp(`^${t}$`, "su");
84
- }, y = (e) => {
84
+ }, m = (e) => {
85
85
  if (!Array.isArray(e)) throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");
86
- const t = e.map(C), n = (s) => s !== "" && t.some((i) => i.test(s)), r = (s) => s !== "" && I(s).some((i) => n(i) || i.split(j).some(n));
86
+ const t = e.map(C), n = (s) => s !== "" && t.some((i) => i.test(s)), r = (s) => s !== "" && z(s).some((i) => n(i) || i.split(j).some(n));
87
87
  return {
88
88
  deniesPath: (s) => s.split("/").some(r),
89
89
  deniesName: r
90
90
  };
91
- }, z = y(P), X = Object.freeze({ deniesPath: () => !1, deniesName: () => !1 }), Ae = (e) => e === void 0 ? z : e === !1 ? X : y(e), _e = (e, t) => y(e).deniesPath(t), b = Object.freeze(["unauthorized", "forbidden", "not-found", "not-configured", "invalid", "too-large", "unsupported", "failed"]), U = Object.freeze(["file", "directory"]), H = Object.freeze(["video", "audio", "pdf"]), V = Object.freeze(["raster", "svg"]), F = Object.freeze(["csv", "tsv"]), M = Object.freeze(["info", "warning", "danger"]), K = Object.freeze(["markdown", "text", "image", "media", "spreadsheet", "file", "failure"]), m = Object.freeze({ min: 1, max: 6 }), Oe = 1e4, u = (e) => typeof e == "string" && /^\/(?![/\\])[\x21-\x7E]*$/u.test(e), xe = Object.freeze(["http:", "https:", "mailto:"]), A = 1024, G = /^[a-z0-9-]{1,64}$/u, Y = "https://relative.invalid/", g = 64, c = (e, t) => typeof t == "string" && e.includes(t), o = (e) => typeof e == "string" ? JSON.stringify(e.length > g ? `${e.slice(0, g)}…` : e) : typeof e, W = (e) => c(b, e), J = (e) => c(U, e), q = (e) => c(H, e), B = (e) => c(V, e), Q = (e) => c(F, e), Se = (e) => c(M, e), Z = (e) => c(K, e), _ = (e) => typeof e == "string" && G.test(e), Te = (e, t) => {
91
+ }, X = m(N), U = Object.freeze({ deniesPath: () => !1, deniesName: () => !1 }), Oe = (e) => e === void 0 ? X : e === !1 ? U : m(e), xe = (e, t) => m(e).deniesPath(t), b = Object.freeze(["unauthorized", "forbidden", "not-found", "not-configured", "invalid", "too-large", "unsupported", "failed"]), F = Object.freeze(["file", "directory"]), H = Object.freeze(["video", "audio", "pdf"]), V = Object.freeze(["raster", "svg"]), M = Object.freeze(["csv", "tsv", "workbook"]), K = Object.freeze(["csv", "tsv"]), Y = Object.freeze(["info", "warning", "danger"]), G = Object.freeze(["markdown", "text", "image", "media", "spreadsheet", "file", "failure"]), y = Object.freeze({ min: 1, max: 6 }), Te = 1e4, u = (e) => typeof e == "string" && /^\/(?![/\\])[\x21-\x7E]*$/u.test(e), Se = Object.freeze(["http:", "https:", "mailto:"]), A = 1024, W = /^[a-z0-9-]{1,64}$/u, J = "https://relative.invalid/", g = 64, l = (e, t) => typeof t == "string" && e.includes(t), o = (e) => typeof e == "string" ? JSON.stringify(e.length > g ? `${e.slice(0, g)}…` : e) : typeof e, q = (e) => l(b, e), B = (e) => l(F, e), Q = (e) => l(H, e), Z = (e) => l(V, e), ee = (e) => l(M, e), we = (e) => l(Y, e), te = (e) => l(G, e), _ = (e) => typeof e == "string" && W.test(e), ke = (e, t) => {
92
92
  if (typeof e != "string") return !1;
93
93
  try {
94
- return t.includes(new URL(e, Y).protocol);
94
+ return t.includes(new URL(e, J).protocol);
95
95
  } catch {
96
96
  return !1;
97
97
  }
98
- }, p = (e) => {
98
+ }, E = (e) => {
99
99
  if (e === null || typeof e != "object") return "a failure must be an object";
100
100
  const { reason: t, code: n } = e;
101
- return W(t) ? n !== void 0 && !_(n) ? `a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${o(n)}` : null : `unknown failure reason ${o(t)}`;
102
- }, ee = (e) => {
101
+ return q(t) ? n !== void 0 && !_(n) ? `a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${o(n)}` : null : `unknown failure reason ${o(t)}`;
102
+ }, ne = (e) => {
103
103
  if (e === null || typeof e != "object") return "an entry must be an object";
104
- const { name: t, path: n, type: r, mimeType: s, modifiedAt: i, children: a, lazy: l } = e;
105
- return typeof t != "string" || t === "" ? "an entry needs a non-empty name" : typeof n != "string" || !R(n) ? "an entry needs an acceptable path" : J(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)}` : l !== void 0 && typeof l != "boolean" ? "an entry lazy flag must be a boolean" : a !== void 0 && !Array.isArray(a) ? "entry children must be an array" : r === "file" && (a !== void 0 || l === !0) ? "a file entry cannot have children or be lazy" : l === !0 && Array.isArray(a) && a.length > 0 ? "a lazy directory must not list children" : null : `an entry type must be "file" or "directory"; got ${o(r)}`;
104
+ const { name: t, path: n, type: r, mimeType: s, modifiedAt: i, children: a, lazy: c } = e;
105
+ return typeof t != "string" || t === "" ? "an entry needs a non-empty name" : typeof n != "string" || !R(n) ? "an entry needs an acceptable path" : B(r) ? s !== void 0 && typeof s != "string" ? "an entry mimeType must be a string" : i !== void 0 && !Number.isSafeInteger(i) ? `an entry modifiedAt must be a safe integer of epoch milliseconds; got ${o(i)}` : c !== void 0 && typeof c != "boolean" ? "an entry lazy flag must be a boolean" : a !== void 0 && !Array.isArray(a) ? "entry children must be an array" : r === "file" && (a !== void 0 || c === !0) ? "a file entry cannot have children or be lazy" : c === !0 && Array.isArray(a) && a.length > 0 ? "a lazy directory must not list children" : null : `an entry type must be "file" or "directory"; got ${o(r)}`;
106
106
  }, O = (e) => {
107
- if (ee(e) !== null) return !1;
107
+ if (ne(e) !== null) return !1;
108
108
  const { children: t } = e;
109
109
  return t === void 0 || t.every(O);
110
- }, te = (e) => {
110
+ }, re = (e) => {
111
111
  if (e === null || typeof e != "object") return !1;
112
112
  const { status: t, entries: n, failure: r } = e;
113
- return t === "ok" ? Array.isArray(n) && n.every(O) : t === "error" && p(r) === null;
114
- }, Ne = (e) => {
113
+ return t === "ok" ? Array.isArray(n) && n.every(O) : t === "error" && E(r) === null;
114
+ }, ve = (e) => {
115
115
  if (e === null || typeof e != "object") return !1;
116
116
  const { status: t, ancestors: n, failure: r } = e;
117
- return t === "ok" ? n === null || x(n) : t === "error" && p(r) === null;
118
- }, x = (e) => Array.isArray(e) && e.every((t) => typeof t == "string" && R(t)) && new Set(e).size === e.length, ve = (e) => {
117
+ return t === "ok" ? n === null || x(n) : t === "error" && E(r) === null;
118
+ }, x = (e) => Array.isArray(e) && e.every((t) => typeof t == "string" && R(t)) && new Set(e).size === e.length, Ne = (e) => {
119
119
  if (e === null || typeof e != "object") return !1;
120
120
  const { status: t, source: n, ancestors: r, failure: s } = e;
121
- return t === "ok" ? n === null && r === null || typeof n == "string" && n !== "" && x(r) : t === "error" && p(s) === null;
121
+ return t === "ok" ? n === null && r === null || typeof n == "string" && n !== "" && x(r) : t === "error" && E(s) === null;
122
122
  }, Pe = (e) => {
123
123
  if (e === null || typeof e != "object") return !1;
124
124
  const { status: t, loadedAt: n } = e;
125
- return t === "ok" && !(Number.isSafeInteger(n) && n >= 0) ? !1 : te(e);
126
- }, S = (e) => {
125
+ return t === "ok" && !(Number.isSafeInteger(n) && n >= 0) ? !1 : re(e);
126
+ }, T = (e) => {
127
127
  if (e === null || typeof e != "object") return "a heading must be an object";
128
128
  const { text: t, depth: n, id: r } = e;
129
- return typeof t != "string" || typeof r != "string" ? "a heading needs text and id strings" : typeof n != "number" || !Number.isInteger(n) || n < m.min || n > m.max ? `a heading depth must be an integer in 1..6; got ${String(n)}` : null;
130
- }, ne = (e) => {
129
+ return typeof t != "string" || typeof r != "string" ? "a heading needs text and id strings" : typeof n != "number" || !Number.isInteger(n) || n < y.min || n > y.max ? `a heading depth must be an integer in 1..6; got ${String(n)}` : null;
130
+ }, se = (e) => {
131
131
  if (e === null || typeof e != "object") return "a document must be an object";
132
132
  const t = e, { kind: n } = t;
133
- if (!Z(n)) return `unknown document kind ${o(n)}`;
134
- if (n === "failure") return p(t.failure);
133
+ if (!te(n)) return `unknown document kind ${o(n)}`;
134
+ if (n === "failure") return E(t.failure);
135
135
  if (typeof t.name != "string") return "a document needs a name string";
136
136
  switch (n) {
137
137
  case "markdown": {
138
138
  const { htmlContent: r, headings: s } = t;
139
139
  if (typeof r != "string" || !Array.isArray(s)) return "a markdown document needs htmlContent and headings";
140
140
  for (const i of s) {
141
- const a = S(i);
141
+ const a = T(i);
142
142
  if (a !== null) return a;
143
143
  }
144
- return se(t.edit);
144
+ return ie(t.edit);
145
145
  }
146
146
  case "text":
147
147
  return typeof t.text != "string" || typeof t.truncated != "boolean" ? "a text document needs text and truncated" : u(t.url) ? null : "a text document needs a root-relative url";
148
148
  case "image":
149
- return u(t.url) ? B(t.imageType) ? null : `unknown image type ${o(t.imageType)}` : "an image document needs a root-relative url";
149
+ return u(t.url) ? Z(t.imageType) ? null : `unknown image type ${o(t.imageType)}` : "an image document needs a root-relative url";
150
150
  case "media":
151
- return u(t.url) ? q(t.mediaType) ? null : `unknown media type ${o(t.mediaType)}` : "a media document needs a root-relative url";
151
+ return u(t.url) ? Q(t.mediaType) ? null : `unknown media type ${o(t.mediaType)}` : "a media document needs a root-relative url";
152
152
  case "spreadsheet":
153
- return u(t.url) ? ie(t) : "a spreadsheet document needs a root-relative url";
153
+ return u(t.url) ? le(t) : "a spreadsheet document needs a root-relative url";
154
154
  case "file":
155
155
  return u(t.url) ? null : "a file document needs a root-relative url";
156
156
  }
157
- }, re = (e) => ne(e) === null, we = (e) => re(e) && (e.kind === "text" || e.kind === "failure"), se = (e) => {
157
+ }, oe = (e) => se(e) === null, Le = (e) => oe(e) && (e.kind === "text" || e.kind === "failure"), ie = (e) => {
158
158
  if (e === null) return null;
159
159
  if (typeof e != "object") return "a markdown document's edit must be null or an object";
160
160
  const { kind: t, href: n } = e;
161
- 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)}` : T(n);
162
- }, oe = (e) => {
161
+ 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)}` : S(n);
162
+ }, ae = (e) => {
163
163
  if (e === null) return null;
164
164
  if (typeof e != "object") return "a spreadsheet document's edit must be null or an object";
165
165
  const { kind: t, href: n } = e;
166
- return t !== "external" ? `a spreadsheet document's edit must be external; got ${o(t)}` : T(n);
167
- }, ie = (e) => Q(e.format) ? typeof e.firstSheetOnly != "boolean" ? "a spreadsheet document needs a boolean firstSheetOnly" : oe(e.edit) : `unknown spreadsheet format ${o(e.format)}`, T = (e) => ae(e) ? null : `an external edit needs an absolute https: href; got ${o(e)}`, ae = (e) => {
166
+ return t !== "external" ? `a spreadsheet document's edit must be external; got ${o(t)}` : S(n);
167
+ }, le = (e) => {
168
+ if (!ee(e.format)) return `unknown spreadsheet format ${o(e.format)}`;
169
+ const { firstSheetText: t } = e;
170
+ return t !== null && !l(K, 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" : ae(e.edit);
171
+ }, S = (e) => ce(e) ? null : `an external edit needs an absolute https: href; got ${o(e)}`, ce = (e) => {
168
172
  if (typeof e != "string") return !1;
169
173
  try {
170
174
  return new URL(e).protocol === "https:";
171
175
  } catch {
172
176
  return !1;
173
177
  }
174
- }, d = (e) => typeof e == "string" && e.length > 0 && e.length <= A, le = (e) => u(e.href) ? null : `a grant needs a root-relative href; got ${o(e.href)}`, ce = (e) => {
178
+ }, d = (e) => typeof e == "string" && e.length > 0 && e.length <= A, ue = (e) => u(e.href) ? null : `a grant needs a root-relative href; got ${o(e.href)}`, fe = (e) => {
175
179
  if (e === null || typeof e != "object") return "a revision must be an object";
176
180
  const { id: t, modifiedAt: n, size: r, author: s, kept: i, current: a } = e;
177
181
  return d(t) ? n !== null && (typeof n != "string" || Number.isNaN(Date.parse(n))) ? `a revision's modifiedAt must be a date-time string or null; got ${o(n)}` : typeof r != "number" || !Number.isSafeInteger(r) || r < 0 ? `a revision's size must be a non-negative integer; got ${o(r)}` : s !== null && typeof s != "string" ? `a revision's author must be a string or null; got ${o(s)}` : typeof i != "boolean" || typeof a != "boolean" ? "a revision needs kept and current booleans" : null : `a revision id must be a non-empty string of at most ${A} characters; got ${o(t)}`;
178
182
  }, f = (e, t) => {
179
183
  if (e === null || typeof e != "object") return "an answer must be an object";
180
184
  const n = e, { kind: r } = n;
181
- if (r === "failure") return p(n.failure);
185
+ if (r === "failure") return E(n.failure);
182
186
  if (typeof r != "string" || !t.includes(r)) return `unexpected answer kind ${o(r)}`;
183
187
  switch (r) {
184
188
  case "grant":
185
- return le(n);
189
+ return ue(n);
186
190
  case "edit":
187
191
  return typeof n.text != "string" || typeof n.history != "boolean" ? "an edit source needs text and history" : d(n.version) ? null : `an edit source needs a version; got ${o(n.version)}`;
188
192
  case "draft":
@@ -195,15 +199,15 @@ const P = Object.freeze([
195
199
  const { htmlContent: s, headings: i } = n;
196
200
  if (typeof s != "string" || !Array.isArray(i)) return "a preview needs htmlContent and headings";
197
201
  for (const a of i) {
198
- const l = S(a);
199
- if (l !== null) return l;
202
+ const c = T(a);
203
+ if (c !== null) return c;
200
204
  }
201
205
  return null;
202
206
  }
203
207
  case "revisions": {
204
208
  if (!Array.isArray(n.revisions)) return "revisions need an array";
205
209
  for (const s of n.revisions) {
206
- const i = ce(s);
210
+ const i = fe(s);
207
211
  if (i !== null) return i;
208
212
  }
209
213
  return null;
@@ -213,16 +217,19 @@ const P = Object.freeze([
213
217
  default:
214
218
  return `unexpected answer kind ${o(r)}`;
215
219
  }
216
- }, ue = Object.freeze(["edit", "draft", "grant"]), fe = Object.freeze(["saved", "conflict", "grant"]), N = Object.freeze(["preview"]), de = Object.freeze(["revisions"]), pe = Object.freeze(["revision"]), Le = (e) => f(e, ue) === null, ke = (e) => f(e, fe) === null, De = (e) => f(e, N) === null, je = (e) => f(e, de) === null, $e = (e) => f(e, pe) === null, Ie = (e) => e !== null && typeof e == "object" && e.kind === "unavailable" ? null : f(e, N), Ce = (e, t) => ({ kind: "failure", failure: Ee(e, t) }), Ee = (e, t) => _(t) ? { reason: e, code: t } : { reason: e }, ye = Object.freeze(["tree", "children", "ancestors", "reveal", "document", "text", "edit", "save", "preview", "revisions", "revision", "refresh", "asset", "link-card"]), E = Object.freeze({ source: "source", path: "path", version: "v", base: "base", revision: "revision", display: "as" }), me = "asset", ge = "link-card", ze = (e, t, n) => {
217
- const r = `${e}/${me}?${E.path}=${encodeURIComponent(t)}`;
218
- return n === null ? r : `${r}&${E.version}=${encodeURIComponent(n)}`;
219
- }, v = "text", Xe = (e) => {
220
+ }, de = Object.freeze(["edit", "draft", "grant"]), pe = Object.freeze(["saved", "conflict", "grant"]), w = Object.freeze(["preview"]), Ee = Object.freeze(["revisions"]), me = Object.freeze(["revision"]), De = (e) => f(e, de) === null, $e = (e) => f(e, pe) === null, je = (e) => f(e, w) === null, Ie = (e) => f(e, Ee) === null, ze = (e) => f(e, me) === null, Ce = (e) => e !== null && typeof e == "object" && e.kind === "unavailable" ? null : f(e, w), Xe = (e, t) => ({ kind: "failure", failure: ye(e, t) }), ye = (e, t) => _(t) ? { reason: e, code: t } : { reason: e }, ge = Object.freeze(["tree", "children", "ancestors", "reveal", "document", "text", "edit", "save", "preview", "revisions", "revision", "refresh", "asset", "link-card"]), p = Object.freeze({ source: "source", path: "path", version: "v", base: "base", revision: "revision", display: "as" }), Re = "asset", he = "link-card", Ue = (e, t, n) => {
221
+ const r = `${e}/${Re}?${p.path}=${encodeURIComponent(t)}`;
222
+ return n === null ? r : `${r}&${p.version}=${encodeURIComponent(n)}`;
223
+ }, k = "text", v = "workbook", Fe = (e) => {
224
+ if (!e.includes("?")) throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);
225
+ return `${e}&${p.display}=${k}`;
226
+ }, He = (e) => {
220
227
  if (!e.includes("?")) throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);
221
- return `${e}&${E.display}=${v}`;
222
- }, Ue = (e) => {
223
- const t = e.getAll(E.display);
224
- return t.length === 0 ? "file" : t.length === 1 && t[0] === v ? "text" : null;
225
- }, He = (e) => `${e}/${ge}`, Ve = "X-Markdown-Explorer-Scope", Fe = "X-Markdown-Explorer", Me = "refresh", Ke = "edit", Ge = "text/markdown", Ye = (e) => ye.includes(e), Re = Object.freeze({
228
+ return `${e}&${p.display}=${v}`;
229
+ }, Ve = (e) => {
230
+ const t = e.getAll(p.display);
231
+ return t.length === 0 ? "file" : t.length !== 1 ? null : t[0] === k ? "text" : t[0] === v ? "workbook" : null;
232
+ }, Me = (e) => `${e}/${he}`, Ke = "X-Markdown-Explorer-Scope", Ye = "X-Markdown-Explorer", Ge = "refresh", We = "edit", Je = "text/markdown", qe = (e) => ge.includes(e), be = Object.freeze({
226
233
  invalid: 400,
227
234
  unauthorized: 401,
228
235
  forbidden: 403,
@@ -231,60 +238,61 @@ const P = Object.freeze([
231
238
  "not-configured": 500,
232
239
  unsupported: 500,
233
240
  failed: 500
234
- }), We = (e) => {
235
- const [t, ...n] = b.filter((r) => Re[r] === e);
241
+ }), Be = (e) => {
242
+ const [t, ...n] = b.filter((r) => be[r] === e);
236
243
  return t !== void 0 && n.length === 0 ? t : "failed";
237
244
  };
238
245
  export {
239
- E as A,
240
- Ce as B,
241
- Ue as C,
242
- Ge as D,
243
- Oe as E,
244
- P as F,
245
- _e as G,
246
- be as H,
247
- Xe as I,
248
- We as J,
249
- p as K,
250
- we as L,
251
- he as M,
252
- ve as N,
246
+ p as A,
247
+ Xe as B,
248
+ Ve as C,
249
+ Je as D,
250
+ Te as E,
251
+ N as F,
252
+ xe as G,
253
+ _e as H,
254
+ Fe as I,
255
+ He as J,
256
+ Be as K,
257
+ E as L,
258
+ Ae as M,
259
+ Le as N,
253
260
  Ne as O,
254
- te as P,
255
- Pe as Q,
256
- $e as R,
257
- je as S,
258
- De as T,
259
- ke as U,
260
- Le as V,
261
- re as W,
262
- A as X,
263
- b as Y,
264
- He as a,
265
- W as b,
261
+ ve as P,
262
+ re as Q,
263
+ Pe as R,
264
+ ze as S,
265
+ Ie as T,
266
+ je as U,
267
+ $e as V,
268
+ De as W,
269
+ oe as X,
270
+ A as Y,
271
+ b as Z,
272
+ Me as a,
273
+ q as b,
266
274
  _ as c,
267
- Ie as d,
268
- ze as e,
269
- Ee as f,
270
- Se as g,
271
- Te as h,
275
+ Ce as d,
276
+ Ue as e,
277
+ ye as f,
278
+ we as g,
279
+ ke as h,
272
280
  R as i,
273
- q as j,
274
- B as k,
275
- ne as l,
281
+ Q as j,
282
+ Z as k,
283
+ se as l,
276
284
  d as m,
277
- S as n,
285
+ T as n,
278
286
  u as o,
279
- ee as p,
280
- xe as q,
281
- ce as r,
282
- ie as s,
283
- Ae as t,
284
- Ye as u,
285
- Re as v,
286
- Fe as w,
287
- Me as x,
288
- Ke as y,
289
- Ve as z
287
+ ne as p,
288
+ Se as q,
289
+ fe as r,
290
+ le as s,
291
+ Oe as t,
292
+ qe as u,
293
+ be as v,
294
+ Ye as w,
295
+ Ge as x,
296
+ We as y,
297
+ Ke as z
290
298
  };
@@ -0,0 +1 @@
1
+ "use strict";const b=Object.freeze([".env*","*.env","*.env.*","*.env~*","*.env-*","*.env_*","*.env#*",".git",".git-credentials",".svn",".hg","node_modules","secrets",".secrets","secrets.json","secrets.yml","secrets.yaml","secrets.toml","secrets.ini","secrets.txt",".ssh",".aws",".gnupg",".docker",".kube",".terraform",".npmrc",".yarnrc",".yarnrc.yml",".netrc","_netrc",".pypirc",".pgpass",".my.cnf",".htpasswd",".vault-token","id_rsa*","id_dsa*","id_ecdsa*","id_ed25519*","*.pem","*.key","*.p8","*.p12","*.pfx","*.ppk","*.jks","*.keystore","*.kdbx","*credentials*.json","service-account*.json","*.tfstate","*.tfstate.*","*.tfvars","*.tfvars.json",".*_history","fish_history"]),F=/[\u0000-\u001f\u007f]/u,V=/\p{Cs}/u,M=e=>{const t=e.split("/").filter(r=>r!=="").at(-1);return t===void 0?e:t},R=e=>e.length>0&&e.length<=4096&&!V.test(e)&&!F.test(e)&&!e.includes("\\"),x=e=>e.normalize("NFKC").toUpperCase().toLowerCase(),K=/(?:%[0-9A-Fa-f]{2})+/gu,G=new TextDecoder("utf-8"),Y=/[/\\]/u,W=e=>e.replace(K,t=>G.decode(Uint8Array.from(t.slice(1).split("%").map(r=>Number.parseInt(r,16))))),J=e=>{const t=[e];let r=e;for(let n=0;n<3&&r.includes("%");n+=1){const o=W(r);if(o===r)break;t.push(o),r=o}return t.map(x)},q=e=>{if(typeof e!="string"||e.trim()===""||e.includes("/")||e.includes("\\"))throw new RangeError(`[markdown-explorer] a deny pattern must be one non-blank path segment; got ${JSON.stringify(e)}`);const t=x(e).split("*").map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${t}$`,"su")},m=e=>{if(!Array.isArray(e))throw new RangeError("[markdown-explorer] deny rules must be an array of segment patterns");const t=e.map(q),r=o=>o!==""&&t.some(i=>i.test(o)),n=o=>o!==""&&J(o).some(i=>r(i)||i.split(Y).some(r));return{deniesPath:o=>o.split("/").some(n),deniesName:n}},B=m(b),Q=Object.freeze({deniesPath:()=>!1,deniesName:()=>!1}),Z=e=>e===void 0?B:e===!1?Q:m(e),ee=(e,t)=>m(e).deniesPath(t),y=Object.freeze(["unauthorized","forbidden","not-found","not-configured","invalid","too-large","unsupported","failed"]),te=Object.freeze(["file","directory"]),re=Object.freeze(["video","audio","pdf"]),ne=Object.freeze(["raster","svg"]),oe=Object.freeze(["csv","tsv","workbook"]),se=Object.freeze(["csv","tsv"]),ie=Object.freeze(["info","warning","danger"]),ae=Object.freeze(["markdown","text","image","media","spreadsheet","file","failure"]),O=Object.freeze({min:1,max:6}),le=1e4,u=e=>typeof e=="string"&&/^\/(?![/\\])[\x21-\x7E]*$/u.test(e),ce=Object.freeze(["http:","https:","mailto:"]),_=1024,ue=/^[a-z0-9-]{1,64}$/u,fe="https://relative.invalid/",h=64,l=(e,t)=>typeof t=="string"&&e.includes(t),s=e=>typeof e=="string"?JSON.stringify(e.length>h?`${e.slice(0,h)}…`:e):typeof e,T=e=>l(y,e),de=e=>l(te,e),P=e=>l(re,e),S=e=>l(ne,e),Ee=e=>l(oe,e),pe=e=>l(ie,e),Re=e=>l(ae,e),g=e=>typeof e=="string"&&ue.test(e),me=(e,t)=>{if(typeof e!="string")return!1;try{return t.includes(new URL(e,fe).protocol)}catch{return!1}},E=e=>{if(e===null||typeof e!="object")return"a failure must be an object";const{reason:t,code:r}=e;return T(t)?r!==void 0&&!g(r)?`a failure code must be 1 to 64 lowercase letters, digits or hyphens; got ${s(r)}`:null:`unknown failure reason ${s(t)}`},L=e=>{if(e===null||typeof e!="object")return"an entry must be an object";const{name:t,path:r,type:n,mimeType:o,modifiedAt:i,children:a,lazy:c}=e;return typeof t!="string"||t===""?"an entry needs a non-empty name":typeof r!="string"||!R(r)?"an entry needs an acceptable path":de(n)?o!==void 0&&typeof o!="string"?"an entry mimeType must be a string":i!==void 0&&!Number.isSafeInteger(i)?`an entry modifiedAt must be a safe integer of epoch milliseconds; got ${s(i)}`:c!==void 0&&typeof c!="boolean"?"an entry lazy flag must be a boolean":a!==void 0&&!Array.isArray(a)?"entry children must be an array":n==="file"&&(a!==void 0||c===!0)?"a file entry cannot have children or be lazy":c===!0&&Array.isArray(a)&&a.length>0?"a lazy directory must not list children":null:`an entry type must be "file" or "directory"; got ${s(n)}`},w=e=>{if(L(e)!==null)return!1;const{children:t}=e;return t===void 0||t.every(w)},N=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(w):t==="error"&&E(n)===null},ye=e=>{if(e===null||typeof e!="object")return!1;const{status:t,ancestors:r,failure:n}=e;return t==="ok"?r===null||v(r):t==="error"&&E(n)===null},v=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&R(t))&&new Set(e).size===e.length,_e=e=>{if(e===null||typeof e!="object")return!1;const{status:t,source:r,ancestors:n,failure:o}=e;return t==="ok"?r===null&&n===null||typeof r=="string"&&r!==""&&v(n):t==="error"&&E(o)===null},ge=e=>{if(e===null||typeof e!="object")return!1;const{status:t,loadedAt:r}=e;return t==="ok"&&!(Number.isSafeInteger(r)&&r>=0)?!1:N(e)},A=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<O.min||r>O.max?`a heading depth must be an integer in 1..6; got ${String(r)}`:null},D=e=>{if(e===null||typeof e!="object")return"a document must be an object";const t=e,{kind:r}=t;if(!Re(r))return`unknown document kind ${s(r)}`;if(r==="failure")return E(t.failure);if(typeof t.name!="string")return"a document needs a name string";switch(r){case"markdown":{const{htmlContent:n,headings:o}=t;if(typeof n!="string"||!Array.isArray(o))return"a markdown document needs htmlContent and headings";for(const i of o){const a=A(i);if(a!==null)return a}return Oe(t.edit)}case"text":return typeof t.text!="string"||typeof t.truncated!="boolean"?"a text document needs text and truncated":u(t.url)?null:"a text document needs a root-relative url";case"image":return u(t.url)?S(t.imageType)?null:`unknown image type ${s(t.imageType)}`:"an image document needs a root-relative url";case"media":return u(t.url)?P(t.mediaType)?null:`unknown media type ${s(t.mediaType)}`:"a media document needs a root-relative url";case"spreadsheet":return u(t.url)?I(t):"a spreadsheet document needs a root-relative url";case"file":return u(t.url)?null:"a file document needs a root-relative url"}},k=e=>D(e)===null,Ae=e=>k(e)&&(e.kind==="text"||e.kind==="failure"),Oe=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 ${s(t)}`:$(r)},he=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 ${s(t)}`:$(r)},I=e=>{if(!Ee(e.format))return`unknown spreadsheet format ${s(e.format)}`;const{firstSheetText:t}=e;return t!==null&&!l(se,t)?`a spreadsheet document's firstSheetText must be csv, tsv or null; got ${s(t)}`:t!==null&&e.format!=="workbook"?"only a workbook's spreadsheet document names a firstSheetText":he(e.edit)},$=e=>be(e)?null:`an external edit needs an absolute https: href; got ${s(e)}`,be=e=>{if(typeof e!="string")return!1;try{return new URL(e).protocol==="https:"}catch{return!1}},f=e=>typeof e=="string"&&e.length>0&&e.length<=_,xe=e=>u(e.href)?null:`a grant needs a root-relative href; got ${s(e.href)}`,j=e=>{if(e===null||typeof e!="object")return"a revision must be an object";const{id:t,modifiedAt:r,size:n,author:o,kept:i,current:a}=e;return f(t)?r!==null&&(typeof r!="string"||Number.isNaN(Date.parse(r)))?`a revision's modifiedAt must be a date-time string or null; got ${s(r)}`:typeof n!="number"||!Number.isSafeInteger(n)||n<0?`a revision's size must be a non-negative integer; got ${s(n)}`:o!==null&&typeof o!="string"?`a revision's author must be a string or null; got ${s(o)}`:typeof i!="boolean"||typeof a!="boolean"?"a revision needs kept and current booleans":null:`a revision id must be a non-empty string of at most ${_} characters; got ${s(t)}`},p=(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 E(r.failure);if(typeof n!="string"||!t.includes(n))return`unexpected answer kind ${s(n)}`;switch(n){case"grant":return xe(r);case"edit":return typeof r.text!="string"||typeof r.history!="boolean"?"an edit source needs text and history":f(r.version)?null:`an edit source needs a version; got ${s(r.version)}`;case"draft":return typeof r.text=="string"?null:"a draft source needs text";case"saved":return f(r.version)?null:`a saved answer needs a version; got ${s(r.version)}`;case"conflict":return typeof r.text!="string"?"a conflict needs the current text":f(r.version)?null:`a conflict needs the current version; got ${s(r.version)}`;case"preview":{const{htmlContent:o,headings:i}=r;if(typeof o!="string"||!Array.isArray(i))return"a preview needs htmlContent and headings";for(const a of i){const c=A(a);if(c!==null)return c}return null}case"revisions":{if(!Array.isArray(r.revisions))return"revisions need an array";for(const o of r.revisions){const i=j(o);if(i!==null)return i}return null}case"revision":return typeof r.text!="string"?"a revision answer needs text":f(r.id)?null:`a revision answer needs an id; got ${s(r.id)}`;default:return`unexpected answer kind ${s(n)}`}},Te=Object.freeze(["edit","draft","grant"]),Pe=Object.freeze(["saved","conflict","grant"]),X=Object.freeze(["preview"]),Se=Object.freeze(["revisions"]),Le=Object.freeze(["revision"]),we=e=>p(e,Te)===null,Ne=e=>p(e,Pe)===null,ve=e=>p(e,X)===null,De=e=>p(e,Se)===null,ke=e=>p(e,Le)===null,Ie=e=>e!==null&&typeof e=="object"&&e.kind==="unavailable"?null:p(e,X),$e=(e,t)=>({kind:"failure",failure:C(e,t)}),C=(e,t)=>g(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"]),d=Object.freeze({source:"source",path:"path",version:"v",base:"base",revision:"revision",display:"as"}),Xe="asset",Ce="link-card",Ue=(e,t,r)=>{const n=`${e}/${Xe}?${d.path}=${encodeURIComponent(t)}`;return r===null?n:`${n}&${d.version}=${encodeURIComponent(r)}`},U="text",H="workbook",He=e=>{if(!e.includes("?"))throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);return`${e}&${d.display}=${U}`},ze=e=>{if(!e.includes("?"))throw new RangeError(`[markdown-explorer] an asset URL always carries a query; got ${JSON.stringify(e)}`);return`${e}&${d.display}=${H}`},Fe=e=>{const t=e.getAll(d.display);return t.length===0?"file":t.length!==1?null:t[0]===U?"text":t[0]===H?"workbook":null},Ve=e=>`${e}/${Ce}`,Me="X-Markdown-Explorer-Scope",Ke="X-Markdown-Explorer",Ge="refresh",Ye="edit",We="text/markdown",Je=e=>je.includes(e),z=Object.freeze({invalid:400,unauthorized:401,forbidden:403,"not-found":404,"too-large":413,"not-configured":500,unsupported:500,failed:500}),qe=e=>{const[t,...r]=y.filter(n=>z[n]===e);return t!==void 0&&r.length===0?t:"failed"};exports.DEFAULT_DENIED_PATH_SEGMENTS=b;exports.EXPLORER_DATA_QUERY=d;exports.EXPLORER_DRAFT_MEDIA_TYPE=We;exports.EXPLORER_EDIT_PROOF=Ye;exports.EXPLORER_EDIT_TOKEN_MAX_LENGTH=_;exports.EXPLORER_FAILURE_REASONS=y;exports.EXPLORER_FAILURE_STATUS=z;exports.EXPLORER_LINK_PROTOCOLS=ce;exports.EXPLORER_MAX_HEADINGS=le;exports.EXPLORER_PROOF_HEADER=Ke;exports.EXPLORER_REFRESH_PROOF=Ge;exports.EXPLORER_SCOPE_HEADER=Me;exports.MAX_DOCUMENT_PATH_LENGTH=4096;exports.documentViolation=D;exports.draftAnswerViolation=Ie;exports.entryViolation=L;exports.explorerAssetHref=Ue;exports.explorerLinkCardEndpoint=Ve;exports.explorerPlainTextHref=He;exports.explorerWorkbookHref=ze;exports.failureDocument=$e;exports.failureOf=C;exports.failureReasonOfStatus=qe;exports.failureViolation=E;exports.headingViolation=A;exports.isAcceptableDocumentPath=R;exports.isAcceptableUrl=me;exports.isDeniedPath=ee;exports.isExplorerAncestorsResult=ye;exports.isExplorerChildrenResult=N;exports.isExplorerDataOperation=Je;exports.isExplorerDocument=k;exports.isExplorerEditAnswer=we;exports.isExplorerEditToken=f;exports.isExplorerFailureCode=g;exports.isExplorerFailureReason=T;exports.isExplorerImageType=S;exports.isExplorerMediaType=P;exports.isExplorerNoticeTone=pe;exports.isExplorerPreviewAnswer=ve;exports.isExplorerRevealResult=_e;exports.isExplorerRevisionAnswer=ke;exports.isExplorerRevisionsAnswer=De;exports.isExplorerSaveAnswer=Ne;exports.isExplorerTextAnswer=Ae;exports.isExplorerTreeResult=ge;exports.isRootRelativeUrl=u;exports.lastPathSegment=M;exports.readExplorerAssetDisplay=Fe;exports.resolvePathRules=Z;exports.revisionViolation=j;exports.spreadsheetFieldsViolation=I;