@aiquants/markdown-explorer 0.35.0 → 0.37.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 +165 -0
- package/README.md +105 -13
- package/dist/{EditSurface-D2j1kCEE.js → EditSurface-BQgwRUrR.js} +250 -245
- package/dist/EditSurface-Xvk5wZu7.cjs +6 -0
- package/dist/ExplorerSplit-C_3FChSt.cjs +2 -0
- package/dist/ExplorerSplit-C_kaEnyM.js +1619 -0
- package/dist/{MultiLayout-CxV5SI7f.cjs → MultiLayout-BZNj1GYo.cjs} +1 -1
- package/dist/{MultiLayout-BeJ5Lubb.js → MultiLayout-DROxkTdD.js} +24 -24
- package/dist/{NativeScrollBar-RWXpVhbI.cjs → NativeScrollBar-BDF9A1sc.cjs} +1 -1
- package/dist/{NativeScrollBar-BM5NULzg.js → NativeScrollBar-DvdOpwIW.js} +2 -2
- package/dist/TreeLayout-Cc-ykewY.js +103 -0
- package/dist/TreeLayout-D_DYV64_.cjs +1 -0
- package/dist/client/MarkdownExplorer.d.cts +4 -5
- package/dist/client/MarkdownExplorer.d.ts +4 -5
- package/dist/client/hostContract.d.cts +1 -8
- package/dist/client/hostContract.d.ts +1 -8
- package/dist/core/config.d.cts +6 -0
- package/dist/core/config.d.ts +6 -0
- package/dist/core/contracts.d.cts +21 -0
- package/dist/core/contracts.d.ts +21 -0
- package/dist/core/dataRoute.d.cts +5 -1
- package/dist/core/dataRoute.d.ts +5 -1
- package/dist/core/documentId.d.cts +6 -0
- package/dist/core/documentId.d.ts +6 -0
- package/dist/core/labels.d.cts +10 -9
- package/dist/core/labels.d.ts +10 -9
- package/dist/core/location.d.cts +21 -0
- package/dist/core/location.d.ts +21 -0
- package/dist/explorerCore-DivWkFQF.cjs +1 -0
- package/dist/explorerCore-EkU0mwdW.js +1085 -0
- package/dist/index-BmOU3xcK.cjs +18 -0
- package/dist/{index-C1YMH-yI.js → index-dtjghDWY.js} +2647 -2466
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +49 -45
- package/dist/location-Dh6K-y7w.js +761 -0
- package/dist/location-DrOP6t1F.cjs +1 -0
- package/dist/{merge-DQUYEGCx.cjs → merge-BCFCL1cF.cjs} +1 -1
- package/dist/{merge-Bb_HpPhe.js → merge-DC_h-t31.js} +1 -1
- package/dist/ownUrls-BTPGNhBt.cjs +1 -0
- package/dist/ownUrls-DD0cSCsF.js +409 -0
- package/dist/{sanitizeJob-BYRk17nr.js → sanitizeJob-BYqzjFJC.js} +1 -1
- package/dist/{sanitizeJob-Cs9o3Vpl.cjs → sanitizeJob-CudE1RUP.cjs} +1 -1
- package/dist/{sanitizePolicy-CiQfnxyd.cjs → sanitizePolicy-C-ehd0J_.cjs} +1 -1
- package/dist/{sanitizePolicy-CEMdaLUB.js → sanitizePolicy-DAPnUUVm.js} +1 -1
- package/dist/sanitizeWorker.cjs +1 -1
- package/dist/sanitizeWorker.js +3 -3
- package/dist/{sanitizerService-KWXv7bPm.js → sanitizerService-B8v4ap9t.js} +1 -1
- package/dist/{sanitizerService-BY4CPCoA.cjs → sanitizerService-DomN7lwC.cjs} +1 -1
- package/dist/server/anonymous.d.cts +2 -2
- package/dist/server/anonymous.d.ts +2 -2
- package/dist/server/errors.d.cts +1 -1
- package/dist/server/errors.d.ts +1 -1
- package/dist/server/ports.d.cts +24 -2
- package/dist/server/ports.d.ts +24 -2
- package/dist/server.cjs +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +16 -16
- package/dist/serverBrowser.cjs +1 -1
- package/dist/serverBrowser.js +3 -3
- package/dist/serverCore.cjs +1 -1
- package/dist/serverCore.d.cts +1 -1
- package/dist/serverCore.d.ts +1 -1
- package/dist/serverCore.js +4 -4
- package/dist/styles/markdown-explorer.css +1 -1
- package/dist/{tapScrollCircle-BEydRn0y.js → tapScrollCircle-CqMZzWjo.js} +1 -1
- package/dist/{tapScrollCircle-DdX0Wri0.cjs → tapScrollCircle-DVNlszeF.cjs} +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +5 -0
- package/dist/testing.d.ts +5 -0
- package/dist/testing.js +80 -2
- package/dist/{useSplitPersistence-B2Fj508K.cjs → useSplitPersistence-BUa_KMsV.cjs} +1 -1
- package/dist/{useSplitPersistence-Fkqak8G8.js → useSplitPersistence-pnb21dsr.js} +1 -1
- package/docs/behavior/dom-hooks.md +11 -2
- package/docs/behavior/hosting.md +1 -1
- package/docs/behavior/localization.md +2 -2
- package/docs/behavior/security.md +24 -3
- package/docs/behavior/url-contract.md +26 -0
- package/package.json +6 -4
- package/dist/EditSurface-CLG70Vnn.cjs +0 -6
- package/dist/ExplorerSplit-CfP1smbT.js +0 -1589
- package/dist/ExplorerSplit-D_0VohOv.cjs +0 -2
- package/dist/TreeLayout-AxLw-36S.js +0 -103
- package/dist/TreeLayout-Bg2YH-EY.cjs +0 -1
- package/dist/explorerCore-DLpDuSev.js +0 -998
- package/dist/explorerCore-DYrxS9ez.cjs +0 -1
- package/dist/index-LQWQfpAf.cjs +0 -18
- package/dist/location--KvTA0Ri.js +0 -726
- package/dist/location-D8DyDkuA.cjs +0 -1
- package/dist/ownUrls-B259RGgd.cjs +0 -1
- package/dist/ownUrls-Dh5g6ZJi.js +0 -370
package/dist/core/config.d.cts
CHANGED
|
@@ -14,6 +14,9 @@ export type ExplorerConfigInput = {
|
|
|
14
14
|
readonly dataPath: string;
|
|
15
15
|
readonly settingsCookie: string;
|
|
16
16
|
readonly views?: Partial<ExplorerViewSlugs>;
|
|
17
|
+
readonly documentIds?: {
|
|
18
|
+
readonly slug: string;
|
|
19
|
+
};
|
|
17
20
|
readonly multiView?: {
|
|
18
21
|
readonly maxPanels?: number;
|
|
19
22
|
readonly columns?: number;
|
|
@@ -47,6 +50,9 @@ export type ExplorerConfig = {
|
|
|
47
50
|
readonly dataPath: string;
|
|
48
51
|
readonly settingsCookie: string;
|
|
49
52
|
readonly views: ExplorerViewSlugs;
|
|
53
|
+
readonly documentIds: {
|
|
54
|
+
readonly slug: string;
|
|
55
|
+
} | null;
|
|
50
56
|
readonly multiView: {
|
|
51
57
|
readonly maxPanels: number;
|
|
52
58
|
readonly columns: number;
|
package/dist/core/config.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ export type ExplorerConfigInput = {
|
|
|
14
14
|
readonly dataPath: string;
|
|
15
15
|
readonly settingsCookie: string;
|
|
16
16
|
readonly views?: Partial<ExplorerViewSlugs>;
|
|
17
|
+
readonly documentIds?: {
|
|
18
|
+
readonly slug: string;
|
|
19
|
+
};
|
|
17
20
|
readonly multiView?: {
|
|
18
21
|
readonly maxPanels?: number;
|
|
19
22
|
readonly columns?: number;
|
|
@@ -47,6 +50,9 @@ export type ExplorerConfig = {
|
|
|
47
50
|
readonly dataPath: string;
|
|
48
51
|
readonly settingsCookie: string;
|
|
49
52
|
readonly views: ExplorerViewSlugs;
|
|
53
|
+
readonly documentIds: {
|
|
54
|
+
readonly slug: string;
|
|
55
|
+
} | null;
|
|
50
56
|
readonly multiView: {
|
|
51
57
|
readonly maxPanels: number;
|
|
52
58
|
readonly columns: number;
|
|
@@ -111,6 +111,21 @@ export type ExplorerRevealResult = {
|
|
|
111
111
|
readonly status: "error";
|
|
112
112
|
readonly failure: ExplorerFailure;
|
|
113
113
|
};
|
|
114
|
+
export type ExplorerIssuedDocumentId = {
|
|
115
|
+
readonly status: "ok";
|
|
116
|
+
readonly id: string;
|
|
117
|
+
} | {
|
|
118
|
+
readonly status: "error";
|
|
119
|
+
readonly failure: ExplorerFailure;
|
|
120
|
+
};
|
|
121
|
+
export type ExplorerResolvedDocumentId = {
|
|
122
|
+
readonly status: "ok";
|
|
123
|
+
readonly path: string;
|
|
124
|
+
readonly source: string;
|
|
125
|
+
} | {
|
|
126
|
+
readonly status: "error";
|
|
127
|
+
readonly failure: ExplorerFailure;
|
|
128
|
+
};
|
|
114
129
|
export type ExplorerHeading = {
|
|
115
130
|
readonly text: string;
|
|
116
131
|
readonly depth: number;
|
|
@@ -259,6 +274,8 @@ export declare const entryViolation: (value: unknown) => string | null;
|
|
|
259
274
|
export declare const isExplorerChildrenResult: (value: unknown) => value is ExplorerChildrenResult;
|
|
260
275
|
export declare const isExplorerAncestorsResult: (value: unknown) => value is ExplorerAncestorsResult;
|
|
261
276
|
export declare const isExplorerRevealResult: (value: unknown) => value is ExplorerRevealResult;
|
|
277
|
+
export declare const isExplorerIssuedDocumentId: (value: unknown) => value is ExplorerIssuedDocumentId;
|
|
278
|
+
export declare const isExplorerResolvedDocumentId: (value: unknown) => value is ExplorerResolvedDocumentId;
|
|
262
279
|
export declare const isExplorerTreeResult: (value: unknown) => value is ExplorerTreeResult;
|
|
263
280
|
export declare const headingViolation: (value: unknown) => string | null;
|
|
264
281
|
export declare const isExplorerDocumentLang: (value: unknown) => value is string;
|
|
@@ -294,4 +311,8 @@ export type ExplorerPageData = {
|
|
|
294
311
|
} | null;
|
|
295
312
|
readonly documents: readonly ExplorerSeededDocument[];
|
|
296
313
|
readonly notices: Promise<readonly ExplorerNotice[]>;
|
|
314
|
+
readonly documentId: {
|
|
315
|
+
readonly id: string | null;
|
|
316
|
+
readonly failure: ExplorerFailure;
|
|
317
|
+
} | null;
|
|
297
318
|
};
|
package/dist/core/contracts.d.ts
CHANGED
|
@@ -111,6 +111,21 @@ export type ExplorerRevealResult = {
|
|
|
111
111
|
readonly status: "error";
|
|
112
112
|
readonly failure: ExplorerFailure;
|
|
113
113
|
};
|
|
114
|
+
export type ExplorerIssuedDocumentId = {
|
|
115
|
+
readonly status: "ok";
|
|
116
|
+
readonly id: string;
|
|
117
|
+
} | {
|
|
118
|
+
readonly status: "error";
|
|
119
|
+
readonly failure: ExplorerFailure;
|
|
120
|
+
};
|
|
121
|
+
export type ExplorerResolvedDocumentId = {
|
|
122
|
+
readonly status: "ok";
|
|
123
|
+
readonly path: string;
|
|
124
|
+
readonly source: string;
|
|
125
|
+
} | {
|
|
126
|
+
readonly status: "error";
|
|
127
|
+
readonly failure: ExplorerFailure;
|
|
128
|
+
};
|
|
114
129
|
export type ExplorerHeading = {
|
|
115
130
|
readonly text: string;
|
|
116
131
|
readonly depth: number;
|
|
@@ -259,6 +274,8 @@ export declare const entryViolation: (value: unknown) => string | null;
|
|
|
259
274
|
export declare const isExplorerChildrenResult: (value: unknown) => value is ExplorerChildrenResult;
|
|
260
275
|
export declare const isExplorerAncestorsResult: (value: unknown) => value is ExplorerAncestorsResult;
|
|
261
276
|
export declare const isExplorerRevealResult: (value: unknown) => value is ExplorerRevealResult;
|
|
277
|
+
export declare const isExplorerIssuedDocumentId: (value: unknown) => value is ExplorerIssuedDocumentId;
|
|
278
|
+
export declare const isExplorerResolvedDocumentId: (value: unknown) => value is ExplorerResolvedDocumentId;
|
|
262
279
|
export declare const isExplorerTreeResult: (value: unknown) => value is ExplorerTreeResult;
|
|
263
280
|
export declare const headingViolation: (value: unknown) => string | null;
|
|
264
281
|
export declare const isExplorerDocumentLang: (value: unknown) => value is string;
|
|
@@ -294,4 +311,8 @@ export type ExplorerPageData = {
|
|
|
294
311
|
} | null;
|
|
295
312
|
readonly documents: readonly ExplorerSeededDocument[];
|
|
296
313
|
readonly notices: Promise<readonly ExplorerNotice[]>;
|
|
314
|
+
readonly documentId: {
|
|
315
|
+
readonly id: string | null;
|
|
316
|
+
readonly failure: ExplorerFailure;
|
|
317
|
+
} | null;
|
|
297
318
|
};
|
|
@@ -13,7 +13,9 @@ export declare const EXPLORER_DATA_OPERATIONS: readonly [
|
|
|
13
13
|
"revision",
|
|
14
14
|
"refresh",
|
|
15
15
|
"asset",
|
|
16
|
-
"link-card"
|
|
16
|
+
"link-card",
|
|
17
|
+
"issue-id",
|
|
18
|
+
"resolve-id"
|
|
17
19
|
];
|
|
18
20
|
export type ExplorerDataOperation = (typeof EXPLORER_DATA_OPERATIONS)[number];
|
|
19
21
|
export declare const EXPLORER_DATA_QUERY: Readonly<{
|
|
@@ -23,6 +25,7 @@ export declare const EXPLORER_DATA_QUERY: Readonly<{
|
|
|
23
25
|
readonly base: "base";
|
|
24
26
|
readonly revision: "revision";
|
|
25
27
|
readonly display: "as";
|
|
28
|
+
readonly id: "id";
|
|
26
29
|
}>;
|
|
27
30
|
export declare const explorerAssetHref: (dataPath: string, path: string, version: string | null) => string;
|
|
28
31
|
export type ExplorerAssetDisplay = "file" | "text" | "workbook";
|
|
@@ -34,6 +37,7 @@ export declare const EXPLORER_SCOPE_HEADER = "X-Markdown-Explorer-Scope";
|
|
|
34
37
|
export declare const EXPLORER_PROOF_HEADER = "X-Markdown-Explorer";
|
|
35
38
|
export declare const EXPLORER_REFRESH_PROOF = "refresh";
|
|
36
39
|
export declare const EXPLORER_EDIT_PROOF = "edit";
|
|
40
|
+
export declare const EXPLORER_DOCUMENT_ID_PROOF = "document-id";
|
|
37
41
|
export declare const EXPLORER_DRAFT_MEDIA_TYPE = "text/markdown";
|
|
38
42
|
export declare const isExplorerDataOperation: (segment: string | undefined) => segment is ExplorerDataOperation;
|
|
39
43
|
export declare const EXPLORER_FAILURE_STATUS: Readonly<Record<ExplorerFailureReason, number>>;
|
package/dist/core/dataRoute.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export declare const EXPLORER_DATA_OPERATIONS: readonly [
|
|
|
13
13
|
"revision",
|
|
14
14
|
"refresh",
|
|
15
15
|
"asset",
|
|
16
|
-
"link-card"
|
|
16
|
+
"link-card",
|
|
17
|
+
"issue-id",
|
|
18
|
+
"resolve-id"
|
|
17
19
|
];
|
|
18
20
|
export type ExplorerDataOperation = (typeof EXPLORER_DATA_OPERATIONS)[number];
|
|
19
21
|
export declare const EXPLORER_DATA_QUERY: Readonly<{
|
|
@@ -23,6 +25,7 @@ export declare const EXPLORER_DATA_QUERY: Readonly<{
|
|
|
23
25
|
readonly base: "base";
|
|
24
26
|
readonly revision: "revision";
|
|
25
27
|
readonly display: "as";
|
|
28
|
+
readonly id: "id";
|
|
26
29
|
}>;
|
|
27
30
|
export declare const explorerAssetHref: (dataPath: string, path: string, version: string | null) => string;
|
|
28
31
|
export type ExplorerAssetDisplay = "file" | "text" | "workbook";
|
|
@@ -34,6 +37,7 @@ export declare const EXPLORER_SCOPE_HEADER = "X-Markdown-Explorer-Scope";
|
|
|
34
37
|
export declare const EXPLORER_PROOF_HEADER = "X-Markdown-Explorer";
|
|
35
38
|
export declare const EXPLORER_REFRESH_PROOF = "refresh";
|
|
36
39
|
export declare const EXPLORER_EDIT_PROOF = "edit";
|
|
40
|
+
export declare const EXPLORER_DOCUMENT_ID_PROOF = "document-id";
|
|
37
41
|
export declare const EXPLORER_DRAFT_MEDIA_TYPE = "text/markdown";
|
|
38
42
|
export declare const isExplorerDataOperation: (segment: string | undefined) => segment is ExplorerDataOperation;
|
|
39
43
|
export declare const EXPLORER_FAILURE_STATUS: Readonly<Record<ExplorerFailureReason, number>>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const DOCUMENT_ID_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
2
|
+
export declare const DOCUMENT_ID_LENGTH = 12;
|
|
3
|
+
export declare const isCanonicalDocumentId: (value: unknown) => value is string;
|
|
4
|
+
export declare const parseDocumentId: (written: string) => string | null;
|
|
5
|
+
export declare const createDocumentId: (fillRandom: (bytes: Uint8Array<ArrayBuffer>) => void) => string;
|
|
6
|
+
export declare const groupDocumentId: (id: string) => string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const DOCUMENT_ID_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
2
|
+
export declare const DOCUMENT_ID_LENGTH = 12;
|
|
3
|
+
export declare const isCanonicalDocumentId: (value: unknown) => value is string;
|
|
4
|
+
export declare const parseDocumentId: (written: string) => string | null;
|
|
5
|
+
export declare const createDocumentId: (fillRandom: (bytes: Uint8Array<ArrayBuffer>) => void) => string;
|
|
6
|
+
export declare const groupDocumentId: (id: string) => string;
|
package/dist/core/labels.d.cts
CHANGED
|
@@ -181,12 +181,6 @@ export type MarkdownExplorerLabels = MarkdownExplorerSpreadsheetLabels & {
|
|
|
181
181
|
readonly announcementSequence: (messages: readonly string[]) => string;
|
|
182
182
|
readonly textTruncated: string;
|
|
183
183
|
readonly inertLink: string;
|
|
184
|
-
readonly failureUnauthorizedTitle: string;
|
|
185
|
-
readonly failureUnauthorizedBody: string;
|
|
186
|
-
readonly failureUnauthorizedSignInBody: string;
|
|
187
|
-
readonly failureUnauthorizedSignedOutBody: string;
|
|
188
|
-
readonly failureForbiddenTitle: string;
|
|
189
|
-
readonly failureForbiddenBody: string;
|
|
190
184
|
readonly failureNotFoundTitle: string;
|
|
191
185
|
readonly failureNotFoundBody: string;
|
|
192
186
|
readonly failureNotConfiguredTitle: string;
|
|
@@ -200,9 +194,6 @@ export type MarkdownExplorerLabels = MarkdownExplorerSpreadsheetLabels & {
|
|
|
200
194
|
readonly failureFailedTitle: string;
|
|
201
195
|
readonly failureFailedBody: string;
|
|
202
196
|
readonly retry: string;
|
|
203
|
-
readonly reloadPage: string;
|
|
204
|
-
readonly signInAgain: string;
|
|
205
|
-
readonly signIn: string;
|
|
206
197
|
readonly imageZoomIn: string;
|
|
207
198
|
readonly imageZoomOut: string;
|
|
208
199
|
readonly imageFit: string;
|
|
@@ -213,6 +204,16 @@ export type MarkdownExplorerLabels = MarkdownExplorerSpreadsheetLabels & {
|
|
|
213
204
|
readonly copyText: string;
|
|
214
205
|
readonly copiedText: string;
|
|
215
206
|
readonly copyTextFailed: string;
|
|
207
|
+
readonly copyPermalinkLabel: string;
|
|
208
|
+
readonly copyPermalink: string;
|
|
209
|
+
readonly copyPermalinkNamed: (name: string) => string;
|
|
210
|
+
readonly permalinkCopied: (groupedId: string) => string;
|
|
211
|
+
readonly permalinkCopyFailed: (reason: string) => string;
|
|
212
|
+
readonly permalinkClipboardRefused: string;
|
|
213
|
+
readonly documentIdFailedTitle: string;
|
|
214
|
+
readonly documentIdInvalid: string;
|
|
215
|
+
readonly documentIdNotFound: string;
|
|
216
|
+
readonly documentIdForbidden: string;
|
|
216
217
|
readonly mediaUnsupported: string;
|
|
217
218
|
readonly fileNotShown: string;
|
|
218
219
|
readonly pdfNotShown: string;
|
package/dist/core/labels.d.ts
CHANGED
|
@@ -181,12 +181,6 @@ export type MarkdownExplorerLabels = MarkdownExplorerSpreadsheetLabels & {
|
|
|
181
181
|
readonly announcementSequence: (messages: readonly string[]) => string;
|
|
182
182
|
readonly textTruncated: string;
|
|
183
183
|
readonly inertLink: string;
|
|
184
|
-
readonly failureUnauthorizedTitle: string;
|
|
185
|
-
readonly failureUnauthorizedBody: string;
|
|
186
|
-
readonly failureUnauthorizedSignInBody: string;
|
|
187
|
-
readonly failureUnauthorizedSignedOutBody: string;
|
|
188
|
-
readonly failureForbiddenTitle: string;
|
|
189
|
-
readonly failureForbiddenBody: string;
|
|
190
184
|
readonly failureNotFoundTitle: string;
|
|
191
185
|
readonly failureNotFoundBody: string;
|
|
192
186
|
readonly failureNotConfiguredTitle: string;
|
|
@@ -200,9 +194,6 @@ export type MarkdownExplorerLabels = MarkdownExplorerSpreadsheetLabels & {
|
|
|
200
194
|
readonly failureFailedTitle: string;
|
|
201
195
|
readonly failureFailedBody: string;
|
|
202
196
|
readonly retry: string;
|
|
203
|
-
readonly reloadPage: string;
|
|
204
|
-
readonly signInAgain: string;
|
|
205
|
-
readonly signIn: string;
|
|
206
197
|
readonly imageZoomIn: string;
|
|
207
198
|
readonly imageZoomOut: string;
|
|
208
199
|
readonly imageFit: string;
|
|
@@ -213,6 +204,16 @@ export type MarkdownExplorerLabels = MarkdownExplorerSpreadsheetLabels & {
|
|
|
213
204
|
readonly copyText: string;
|
|
214
205
|
readonly copiedText: string;
|
|
215
206
|
readonly copyTextFailed: string;
|
|
207
|
+
readonly copyPermalinkLabel: string;
|
|
208
|
+
readonly copyPermalink: string;
|
|
209
|
+
readonly copyPermalinkNamed: (name: string) => string;
|
|
210
|
+
readonly permalinkCopied: (groupedId: string) => string;
|
|
211
|
+
readonly permalinkCopyFailed: (reason: string) => string;
|
|
212
|
+
readonly permalinkClipboardRefused: string;
|
|
213
|
+
readonly documentIdFailedTitle: string;
|
|
214
|
+
readonly documentIdInvalid: string;
|
|
215
|
+
readonly documentIdNotFound: string;
|
|
216
|
+
readonly documentIdForbidden: string;
|
|
216
217
|
readonly mediaUnsupported: string;
|
|
217
218
|
readonly fileNotShown: string;
|
|
218
219
|
readonly pdfNotShown: string;
|
package/dist/core/location.d.cts
CHANGED
|
@@ -34,6 +34,14 @@ export type ExplorerLocation = {
|
|
|
34
34
|
readonly embed: ExplorerEmbedOptions;
|
|
35
35
|
readonly markup: boolean;
|
|
36
36
|
};
|
|
37
|
+
export type ExplorerDocumentIdOpening = {
|
|
38
|
+
readonly view: "tree";
|
|
39
|
+
readonly overrides: ExplorerOverrides;
|
|
40
|
+
} | {
|
|
41
|
+
readonly view: "single";
|
|
42
|
+
readonly overrides: ExplorerOverrides;
|
|
43
|
+
readonly embed: ExplorerEmbedOptions;
|
|
44
|
+
};
|
|
37
45
|
export type ExplorerLocationResult = {
|
|
38
46
|
readonly kind: "location";
|
|
39
47
|
readonly location: ExplorerLocation;
|
|
@@ -41,6 +49,11 @@ export type ExplorerLocationResult = {
|
|
|
41
49
|
readonly kind: "redirect";
|
|
42
50
|
readonly href: string;
|
|
43
51
|
readonly location: ExplorerLocation;
|
|
52
|
+
} | {
|
|
53
|
+
readonly kind: "document-id";
|
|
54
|
+
readonly id: string | null;
|
|
55
|
+
readonly opens: ExplorerDocumentIdOpening;
|
|
56
|
+
readonly location: ExplorerLocation;
|
|
44
57
|
};
|
|
45
58
|
export type ExplorerHrefTarget = {
|
|
46
59
|
readonly view: "tree";
|
|
@@ -63,6 +76,12 @@ export type ExplorerHrefTarget = {
|
|
|
63
76
|
readonly overrides?: ExplorerOverrides;
|
|
64
77
|
readonly embed?: ExplorerEmbedOptions;
|
|
65
78
|
readonly markup?: boolean;
|
|
79
|
+
} | {
|
|
80
|
+
readonly view: "document-id";
|
|
81
|
+
readonly id: string;
|
|
82
|
+
readonly opens?: "single";
|
|
83
|
+
readonly overrides?: ExplorerOverrides;
|
|
84
|
+
readonly embed?: ExplorerEmbedOptions;
|
|
66
85
|
};
|
|
67
86
|
export type ExplorerSourcelessHrefTarget = ExplorerHrefTarget & {
|
|
68
87
|
readonly source?: undefined;
|
|
@@ -89,5 +108,7 @@ export declare const FOLDER_SEGMENT_MARK = "/";
|
|
|
89
108
|
export declare const encodeDocumentSegment: (path: string) => string;
|
|
90
109
|
export declare const decodeDocumentSegment: (segment: string) => string;
|
|
91
110
|
export declare const canonicalMultiDocuments: (config: ExplorerConfig, docs: readonly string[]) => readonly string[];
|
|
111
|
+
export declare const hasDocumentUrl: (path: string) => boolean;
|
|
92
112
|
export declare const explorerHref: ExplorerHrefWriter;
|
|
93
113
|
export declare const resolveExplorerLocation: (config: ExplorerLocationConfig, splat: string | undefined, search: URLSearchParams) => ExplorerLocationResult;
|
|
114
|
+
export declare const documentIdOpeningTarget: (opens: ExplorerDocumentIdOpening, path: string, source: string) => ExplorerHrefTarget;
|
package/dist/core/location.d.ts
CHANGED
|
@@ -34,6 +34,14 @@ export type ExplorerLocation = {
|
|
|
34
34
|
readonly embed: ExplorerEmbedOptions;
|
|
35
35
|
readonly markup: boolean;
|
|
36
36
|
};
|
|
37
|
+
export type ExplorerDocumentIdOpening = {
|
|
38
|
+
readonly view: "tree";
|
|
39
|
+
readonly overrides: ExplorerOverrides;
|
|
40
|
+
} | {
|
|
41
|
+
readonly view: "single";
|
|
42
|
+
readonly overrides: ExplorerOverrides;
|
|
43
|
+
readonly embed: ExplorerEmbedOptions;
|
|
44
|
+
};
|
|
37
45
|
export type ExplorerLocationResult = {
|
|
38
46
|
readonly kind: "location";
|
|
39
47
|
readonly location: ExplorerLocation;
|
|
@@ -41,6 +49,11 @@ export type ExplorerLocationResult = {
|
|
|
41
49
|
readonly kind: "redirect";
|
|
42
50
|
readonly href: string;
|
|
43
51
|
readonly location: ExplorerLocation;
|
|
52
|
+
} | {
|
|
53
|
+
readonly kind: "document-id";
|
|
54
|
+
readonly id: string | null;
|
|
55
|
+
readonly opens: ExplorerDocumentIdOpening;
|
|
56
|
+
readonly location: ExplorerLocation;
|
|
44
57
|
};
|
|
45
58
|
export type ExplorerHrefTarget = {
|
|
46
59
|
readonly view: "tree";
|
|
@@ -63,6 +76,12 @@ export type ExplorerHrefTarget = {
|
|
|
63
76
|
readonly overrides?: ExplorerOverrides;
|
|
64
77
|
readonly embed?: ExplorerEmbedOptions;
|
|
65
78
|
readonly markup?: boolean;
|
|
79
|
+
} | {
|
|
80
|
+
readonly view: "document-id";
|
|
81
|
+
readonly id: string;
|
|
82
|
+
readonly opens?: "single";
|
|
83
|
+
readonly overrides?: ExplorerOverrides;
|
|
84
|
+
readonly embed?: ExplorerEmbedOptions;
|
|
66
85
|
};
|
|
67
86
|
export type ExplorerSourcelessHrefTarget = ExplorerHrefTarget & {
|
|
68
87
|
readonly source?: undefined;
|
|
@@ -89,5 +108,7 @@ export declare const FOLDER_SEGMENT_MARK = "/";
|
|
|
89
108
|
export declare const encodeDocumentSegment: (path: string) => string;
|
|
90
109
|
export declare const decodeDocumentSegment: (segment: string) => string;
|
|
91
110
|
export declare const canonicalMultiDocuments: (config: ExplorerConfig, docs: readonly string[]) => readonly string[];
|
|
111
|
+
export declare const hasDocumentUrl: (path: string) => boolean;
|
|
92
112
|
export declare const explorerHref: ExplorerHrefWriter;
|
|
93
113
|
export declare const resolveExplorerLocation: (config: ExplorerLocationConfig, splat: string | undefined, search: URLSearchParams) => ExplorerLocationResult;
|
|
114
|
+
export declare const documentIdOpeningTarget: (opens: ExplorerDocumentIdOpening, path: string, source: string) => ExplorerHrefTarget;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const Xr=require("@aiquants/auth-core"),J=require("@aiquants/request-isolation"),ee=require("react-router"),$=require("./location-DrOP6t1F.cjs"),m=require("./ownUrls-BTPGNhBt.cjs"),x=require("./describeValue-Ccvhbt36.cjs"),Ee=require("./lru-SGmUyBQU.cjs"),tr="application/octet-stream",nr="application/pdf",Hr=new Set(["image/png","image/apng","image/jpeg","image/gif","image/webp","image/avif","image/bmp","image/x-icon","image/vnd.microsoft.icon","audio/mpeg","audio/mp4","audio/aac","audio/ogg","audio/opus","audio/wav","audio/wave","audio/x-wav","audio/webm","audio/flac","audio/x-flac","audio/x-m4a","video/mp4","video/webm","video/ogg","video/quicktime",nr]),Ce="default-src 'none'; media-src 'self'; style-src 'unsafe-inline'",se=Object.freeze({sandboxed:`${Ce}; sandbox`,mediaDocument:`${Ce}; sandbox allow-same-origin`}),Me=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/u,Br=/^[\t\n\r ]+|[\t\n\r ]+$/gu,me=/^[\t ]+|[\t ]+$/gu,Yr=e=>{const r=[];let t="",o=0;for(;;){for(;o<e.length&&e[o]!=='"'&&e[o]!==",";)t+=e[o],o+=1;if(o<e.length&&e[o]==='"'){const c=o;for(o+=1;o<e.length&&e[o]!=='"';)o+=e[o]==="\\"?2:1;if(o=Math.min(o+1,e.length),t+=e.slice(c,o),o<e.length)continue}if(r.push(t.replace(me,"")),t="",o>=e.length)return r;o+=1}},Gr=e=>{const r=e.replace(Br,""),t=r.indexOf("/");if(t<0)return null;const o=r.slice(0,t),c=r.indexOf(";",t+1),d=r.slice(t+1,c<0?r.length:c).replace(/[\t\n\r ]+$/u,"");return Me.test(o)&&Me.test(d)?`${o}/${d}`.toLowerCase():null},Wr=e=>{let r=null;for(const t of Yr(e)){const o=Gr(t);o!==null&&o!=="*/*"&&(r=o)}return r},Jr=/['()*]/gu,sr=e=>encodeURIComponent(e).replace(Jr,r=>`%${r.charCodeAt(0).toString(16).toUpperCase()}`),be=Object.freeze({"Cache-Control":"private, max-age=60, stale-while-revalidate=600, no-transform",Vary:"Cookie"}),or=(e,r)=>{const t=Wr(e),o=t!==null&&Hr.has(t),c=o&&(t.startsWith("audio/")||t.startsWith("video/"));return{contentType:t===null?tr:t,inline:o,headers:{"X-Content-Type-Options":"nosniff","Content-Disposition":`${o?"inline":"attachment"}; filename*=UTF-8''${sr(r)}`,...t===nr?{}:{"Content-Security-Policy":c?se.mediaDocument:se.sandboxed},"Cross-Origin-Resource-Policy":"same-origin"}}},ne=64*1024,ar=e=>`text/plain; charset=${e}`,Kr=e=>({"X-Content-Type-Options":"nosniff","Content-Disposition":`inline; filename*=UTF-8''${sr(e)}`,"Content-Security-Policy":se.sandboxed,"Cross-Origin-Resource-Policy":"same-origin"}),Qr=(e,r)=>`${r===null?"":r};${e}`,Zr=/^bytes=(?:(\d+)-(\d*)|-(\d+))$/iu,re=Object.freeze({kind:"whole"}),ze=Object.freeze({kind:"unsatisfiable"}),ir=(e,r,t,o)=>{const c=e.get("Range");if(c===null)return re;const d=e.get("If-Range");if(d!==null&&d!==t)return re;const f=Zr.exec(c);if(f===null)return re;const[,p,h,k]=f;if(k!==void 0){const T=Number(k);if(T===0)return ze;const A=Math.max(0,r-T);return Ue(A,r-A,o)}const y=Number(p),b=h===""?Number.POSITIVE_INFINITY:Number(h);return b<y?re:y>=r?ze:Ue(y,Math.min(b,r-1)-y+1,o)},Ue=(e,r,t)=>({kind:"partial",range:{offset:e,length:t===null?r:Math.min(r,t)}}),Ve="W/",qr=e=>{const r=[];let t=0,o=!1;for(let c=0;c<e.length;c+=1)e[c]==='"'?o=!o:e[c]===","&&!o&&(r.push(e.slice(t,c).replace(me,"")),t=c+1);return r.push(e.slice(t).replace(me,"")),r},Fe=e=>e.startsWith(Ve)?e.slice(Ve.length):e,Te=(e,r)=>{if(e===null)return!1;const t=qr(e);if(t.length===1&&t[0]==="*")return!0;const o=Fe(r);return t.some(c=>Fe(c)===o)},et=(e,r)=>{let t=r;return e.pipeThrough(new TransformStream({transform:(o,c)=>{const d=o.byteLength>t?o.subarray(0,t):o;t-=d.byteLength,c.enqueue(d),t===0&&c.terminate()},flush:o=>{t>0&&o.error(new RangeError("[markdown-explorer] the asset ended before its declared length"))}}))},Y=(e,r,t,o,c)=>(c!==null&&t.set("Content-Length",String(c)),{head:e.method.toUpperCase()==="HEAD",status:r,headers:t,range:o,length:c}),q=({head:e,status:r,headers:t,range:o,length:c})=>e?{kind:"respond",response:new Response(null,{status:r,headers:t})}:{kind:"stream",status:r,headers:t,range:o,length:c},oe=async(e,r)=>{if(e.kind==="respond")return e.response;const t=await r(e.range);return new Response(e.length===null?t:et(t,e.length),{status:e.status,headers:e.headers})},cr=(e,r)=>{const t=new Headers(e);for(const[o,c]of Object.entries({"Accept-Ranges":"bytes","Content-Range":`bytes */${r}`,"Cache-Control":"private, no-store","X-Content-Type-Options":"nosniff"}))t.set(o,c);return new Response(null,{status:416,headers:t})},ur=(e,r,t,o)=>{const c=`"${r.version}"`,d=or(r.contentType,r.name),f=new Headers(t);for(const[k,y]of Object.entries({...d.headers,...be,ETag:c}))f.set(k,y);if(Te(e.headers.get("If-None-Match"),c))return{kind:"respond",response:new Response(null,{status:304,headers:f})};if(f.set("Content-Type",d.contentType),r.size===null)return q(Y(e,200,f,null,null));if(r.size===0)return f.set("Content-Length","0"),{kind:"respond",response:new Response(null,{status:200,headers:f})};f.set("Accept-Ranges","bytes");const p=ir(e.headers,r.size,c,o);if(p.kind==="unsatisfiable")return{kind:"respond",response:cr(t,r.size)};if(p.kind==="whole")return q(Y(e,200,f,null,r.size));const{range:h}=p;return f.set("Content-Range",`bytes ${h.offset}-${h.offset+h.length-1}/${r.size}`),q(Y(e,206,f,h,h.length))},rt=async(e,r,t,o)=>oe(ur(e,r,t,o),c=>r.open(c)),tt=(e,r)=>{const t=new Uint8Array(r);let o=0;for(const c of e){if(o===r)break;const d=c.subarray(0,r-o);t.set(d,o),o+=d.byteLength}return t},nt=(e,r,t)=>new ReadableStream({start:o=>{for(const c of e)o.enqueue(c);r&&o.close()},pull:async o=>{const{done:c,value:d}=await t.read();c?o.close():o.enqueue(d)},cancel:o=>t.cancel(o)},{highWaterMark:0}),dr=async(e,r,t)=>{const o=e.getReader(),c=r===null?ne:Math.min(r,ne),d=r===null?c+1:c,f=[];let p=0,h=!1;try{for(;p<d;){const{done:b,value:T}=await o.read();if(b){h=!0;break}f.push(T),p+=T.byteLength}if(h&&r!==null&&p<c)throw new RangeError("[markdown-explorer] the asset ended before its declared length");const k=r===null?h:r<=ne;return{encoding:$.textEncodingOf(tt(f,Math.min(p,c)),k,t),body:nt(f,h,o)}}catch(k){throw o.cancel(k).catch(()=>{}),k}},lr=async(e,r)=>{const t=await dr(await e.open(e.size===null?null:{offset:0,length:Math.min(e.size,ne)}),e.size,r);return t.body.cancel().catch(()=>{}),t.encoding},fr=(e,r,t,o,c)=>{const d=`"${Qr(r.version,o)}"`,f=new Headers(t);for(const[k,y]of Object.entries({...Kr(r.name),...be,ETag:d}))f.set(k,y);if(Te(e.headers.get("If-None-Match"),d))return{kind:"respond",response:new Response(null,{status:304,headers:f})};if(r.size===0)return f.set("Content-Type",ar($.textEncodingOf(new Uint8Array(0),!0,o))),f.set("Content-Length","0"),{kind:"respond",response:new Response(null,{status:200,headers:f})};if(r.size===null)return{kind:"needs-encoding",selection:Y(e,200,f,null,null)};f.set("Accept-Ranges","bytes");const p=ir(e.headers,r.size,d,c);if(p.kind==="unsatisfiable")return{kind:"respond",response:cr(t,r.size)};if(p.kind==="whole")return{kind:"needs-encoding",selection:Y(e,200,f,null,r.size)};const{range:h}=p;return f.set("Content-Range",`bytes ${h.offset}-${h.offset+h.length-1}/${r.size}`),{kind:"needs-encoding",selection:Y(e,206,f,h,h.length)}},ye=(e,r)=>{const t=new Headers(e.headers);return t.set("Content-Type",ar(r)),q({...e,headers:t})},st=async(e,r,t,o,c)=>{const d=fr(e,r,t,o,c);if(d.kind==="respond")return d.response;const{selection:f}=d;if(f.head||f.range!==null)return oe(ye(f,await lr(r,o)),h=>r.open(h));const p=await dr(await r.open(null),r.size,o);return oe(ye(f,p.encoding),async()=>p.body)},ot=e=>`workbook;${e}`,at=async(e,r,t)=>{const o=`"${ot(r.version)}"`,c=or(tr,r.name),d=new Headers(t);for(const[f,p]of Object.entries({...c.headers,...be,ETag:o}))d.set(f,p);return Te(e.headers.get("If-None-Match"),o)?new Response(null,{status:304,headers:d}):(d.set("Content-Type",c.contentType),oe(q(Y(e,200,d,null,r.size)),f=>r.open(f)))},it=Object.freeze({"Cache-Control":"private, no-store","Referrer-Policy":"no-referrer"}),ct=(e,r)=>{const t=new Headers(r);for(const[o,c]of Object.entries(it))t.set(o,c);return t.set("Location",e),new Response(null,{status:302,headers:t})},fe=(e,r)=>{const t=new AbortController,o=r(AbortSignal.any([e.signal,t.signal]));return new Promise(c=>{let d;const f=setTimeout(()=>{c(e.late),d=setTimeout(()=>t.abort(),e.handOverMs)},e.timeoutMs),p=()=>{clearTimeout(f),clearTimeout(d)};o.then(h=>{p(),c(h)},()=>{p(),c(e.late)})})},ut=Object.freeze({error:(e,r)=>{console.error(e,r)}}),pr=Symbol.for("@aiquants/markdown-explorer:ExplorerError");class dt extends Error{reason;code;constructor(r,t={}){if(!m.isExplorerFailureReason(r))throw new RangeError(`[markdown-explorer] ExplorerError needs a failure reason; got ${x.describeValue(r)}`);if(t.code!==void 0&&!m.isExplorerFailureCode(t.code))throw new RangeError(`[markdown-explorer] an ExplorerError code must be 1 to 64 lowercase letters, digits or hyphens; got ${x.describeValue(t.code)}`);super(`[markdown-explorer] ${r}`,t.cause===void 0?void 0:{cause:t.cause}),this.name="ExplorerError",this.reason=r,this.code=t.code,Object.defineProperty(this,pr,{value:!0})}}const lt=e=>e instanceof Error&&Object.hasOwn(e,pr)&&m.isExplorerFailureReason(e.reason),ft=e=>typeof e=="object"&&e!==null&&e.name==="AbortError",Re=(e,r,t)=>{try{e.error(r,t)}catch(o){console.error("[markdown-explorer] the logger threw while reporting a failure",{operation:t.operation,error:o})}},N=(e,r)=>Re(e,`[markdown-explorer] ${r.operation} failed`,r),pt=(e,r)=>Re(e,`[markdown-explorer] ${r.operation} left out an entry`,r),Z=(e,r)=>Re(e,`[markdown-explorer] ${r.operation} refused a path the deny rules match`,{...r,error:new RangeError("[markdown-explorer] the path matches a deny rule")}),Xe=(e,r)=>{e===null||typeof e!="object"&&typeof e!="function"||Promise.resolve(e).then(void 0,r)},v=(e,r,t,o)=>lt(e)?m.failureOf(e.reason,e.code):(ft(e)||t.aborted||N(o,{...r,error:e}),{reason:"failed"}),He=2*1024*1024,Be=256*1024*1024,ht=async(e,r)=>{const t=e.getReader(),o=new Uint8Array(r);let c=0;for(;c<r;){const{done:d,value:f}=await t.read();if(d)return o.subarray(0,c);const p=f.subarray(0,r-c);o.set(p,c),c+=p.byteLength}return t.cancel().catch(()=>{}),o},wt=async(e,r,t)=>{if(e.size===0)return{text:"",truncated:!1};const o=e.size!==null&&e.size>r,c=e.size===null?r+1:Math.min(e.size,r),d=await ht(await e.open(o?{offset:0,length:r}:null),c);if(e.size!==null&&d.byteLength<c)throw new RangeError("[markdown-explorer] the file ended before the length its asset port reported");const f=o||d.byteLength>r,p=f?d.subarray(0,r):d,h=$.decodeTextLeniently(p,!f,t);return h.includes("\0")?null:{text:h,truncated:f}},ae=e=>({result:e,json:JSON.stringify(e)}),pe=Object.freeze(ae(Object.freeze({status:"error",failure:Object.freeze({reason:"failed"})}))),mt=e=>e.status==="ok"&&e.entries.length>0,yt=({ttlMs:e,maxEntries:r,maxBytes:t,now:o})=>{const c=Ee.createLruCache(r,{max:t,of:(y,b)=>2*b.tree.json.length}),d=new Map,f=new Map,p=(y,b)=>{const T=new AbortController,A={waiters:0,superseded:!1,started:!1,loadTree:b},I=f.get(y),V=(M,ce)=>{const K=ae(M);return!(A.superseded||T.signal.aborted)&&mt(M)&&c.set(y,{tree:K,loadedAt:ce}),K},U=(async()=>{if(I!==void 0&&await I,T.signal.aborted)return pe;const M=o();return A.started=!0,V(await A.loadTree(T.signal,M),M)})().finally(()=>{d.get(y)===X&&d.delete(y)}),X={promise:U,controller:T,state:A};d.set(y,X);const j=U.then(()=>{},()=>{});return f.set(y,j),j.then(()=>{f.get(y)===j&&f.delete(y)}),X},h=(y,b,T)=>{b.state.waiters+=1;const A=()=>{b.state.waiters-=1,!(b.state.waiters>0)&&(d.get(y)===b&&d.delete(y),b.controller.abort())};return T.addEventListener("abort",A,{once:!0}),b.promise.finally(()=>{T.removeEventListener("abort",A)})},k=y=>{c.delete(y);const b=d.get(y);b?.state.started&&(b.state.superseded=!0,d.delete(y))};return{load:(y,b,T)=>{if(b.aborted)return Promise.resolve(pe);const A=c.get(y);if(A!==void 0){if(o()-A.loadedAt<e)return Promise.resolve(A.tree);c.delete(y)}const I=d.get(y);return h(y,I===void 0?p(y,T):I,b)},refresh:(y,b,T)=>{if(b.aborted)return Promise.resolve(pe);k(y);const A=d.get(y);return A===void 0?h(y,p(y,T),b):(A.state.loadTree=T,h(y,A,b))},forget:k}},gt=e=>({load:(r,t,o)=>o(t,e()).then(ae),refresh:(r,t,o)=>o(t,e()).then(ae),forget:()=>{}}),E=e=>{throw new TypeError(`[markdown-explorer] ${e}`)},Et=e=>{if(e===null||typeof e!="object")return null;const{name:r,path:t}=e;return typeof r!="string"||typeof t!="string"?null:r===""?{path:t,reason:"an empty name"}:m.isAcceptableDocumentPath(t)?null:{path:t,reason:"a path the browser cannot address (empty, too long, a lone surrogate, a control character or a backslash)"}},bt=(e,r,t,o)=>{if(e===null)return null;if(!Array.isArray(e))throw new TypeError(`[markdown-explorer] a source's ancestors must be null or an array of folder paths; got ${x.describeValue(e)}`);const c=new Set;for(const d of e){if(typeof d!="string"||!m.isAcceptableDocumentPath(d))throw new TypeError("[markdown-explorer] a source's ancestors held a path the explorer does not accept");if(t.deniesPath(d))throw new TypeError("[markdown-explorer] a source's ancestors held a denied path");if(!o(d))throw new TypeError("[markdown-explorer] a source's ancestors held a path outside the source's boundary");if(d===r)throw new TypeError("[markdown-explorer] a source's ancestors held the document itself");if(c.has(d))throw new TypeError("[markdown-explorer] a source's ancestors held a path twice");c.add(d)}return Object.freeze([...c])},Tt=(e,r,t,o,c)=>{const d=new Set,f=h=>{if(!Array.isArray(h))return E("a source returned entries that are not an array");const k=[];for(const y of h){const b=p(y);b!==null&&k.push(b)}return k},p=h=>{const k=Et(h);if(k!==null)return o(k),null;const y=m.entryViolation(h);if(y!==null)return E(y);const b=h;if(d.has(b))return E("a source returned entries that contain themselves");const{name:T,path:A,type:I,mimeType:V,modifiedAt:F,children:U,lazy:X}=b;if(r.deniesName(T)||r.deniesPath(A))return null;if(!c(A))return o({path:A,reason:"a path outside the source's boundary"}),null;const j={name:T,path:A,...V===void 0?{}:{mimeType:V},...F===void 0?{}:{modifiedAt:F}};if(I==="file")return{...j,type:I};if(X===!0)return t?{...j,type:I,lazy:!0,children:[]}:E("a lazy directory came from a source without a children function");if(U===void 0)return{...j,type:I};d.add(b);const M=f(U);return d.delete(b),{...j,type:I,children:M}};return f(e)},Rt=/^[\x21\x23-\x7E]{1,256}$/u,hr=e=>typeof e=="string"&&Rt.test(e),kt=new Set(["text","image","media","spreadsheet","file"]),Ot=e=>typeof e=="string"&&kt.has(e),At=(e,r,t)=>{if(e!==null&&typeof e=="object"){const d=e,{kind:f}=d;if(Ot(f)){if(Object.hasOwn(d,"url"))return E(`a ${f} document carries its version, not a url`);if(typeof d.name!="string")return E("a document needs a name string");if(!hr(d.version))return E(`a ${f} document needs a version of 1 to 256 visible ASCII characters other than '"'`);const p=r(d.version);switch(f){case"image":{const{imageType:h}=d;return m.isExplorerImageType(h)?{kind:f,name:d.name,url:p,imageType:h}:E(`unknown image type ${x.describeValue(h)}`)}case"file":return{kind:f,name:d.name,url:p};case"media":{const{mediaType:h}=d;return m.isExplorerMediaType(h)?{kind:f,name:d.name,url:p,mediaType:h}:E(`unknown media type ${x.describeValue(h)}`)}case"text":{const{text:h,truncated:k,lang:y}=d;return typeof h!="string"||typeof k!="boolean"?E("a text document needs text and truncated"):m.isExplorerDocumentLang(y)?{kind:f,name:d.name,text:h,truncated:k,lang:y,url:p}:E(m.documentLangRefusal(f,y))}case"spreadsheet":{const h=m.spreadsheetFieldsViolation(d);if(h!==null)return E(h);const{format:k,firstSheetText:y,edit:b}=d;return{kind:f,name:d.name,url:p,format:k,firstSheetText:y,edit:vt(b)}}}}}const o=m.documentViolation(e);if(o!==null)return E(o);const c=e;switch(c.kind){case"failure":{const{reason:d,code:f}=c.failure;return{kind:"failure",failure:m.failureOf(d,f)}}case"markdown":return c.headings.length>m.EXPLORER_MAX_HEADINGS?{kind:"failure",failure:m.failureOf("too-large")}:(c.edit?.kind==="inline"||c.edit?.kind==="draft")&&!t?E(`a markdown document offers ${c.edit.kind} editing, but the server has no edit ports`):{kind:"unsanitized-markdown",name:c.name,html:c.htmlContent,headings:c.headings.map(({text:d,depth:f,id:p})=>({text:d,depth:f,id:p})),lang:c.lang,edit:xt(c.edit)}}},xt=e=>{if(e===null)return null;switch(e.kind){case"inline":return{kind:"inline"};case"draft":return{kind:"draft"};case"external":return{kind:"external",href:e.href}}},vt=e=>e===null?null:{kind:"external",href:e.href},ie=(e,r,t)=>typeof e!="string"?E(`${t} needs a text string`):e.includes("\0")?E(`${t} holds NUL, which no text editor can keep`):new TextEncoder().encode(e).byteLength>r?E(`${t} is over editMaxBytes (${r} bytes); refuse a longer source with ExplorerError "too-large"`):e,wr=e=>m.isRootRelativeUrl(e.href)?{kind:"grant",href:e.href}:E("a grant needs a root-relative href"),_t=(e,r)=>{if(e===null||typeof e!="object")return E("an edit source must be an object");const t=e;return t.kind==="grant"?wr(t):t.kind==="draft"?{kind:"draft",text:ie(t.text,r,"a draft source")}:t.kind!=="edit"?E(`an edit source's kind must be "edit", "draft" or "grant"`):m.isExplorerEditToken(t.version)?typeof t.history!="boolean"?E("an edit source needs history"):{kind:"edit",text:ie(t.text,r,"an edit source"),version:t.version,history:t.history}:E("an edit source needs a version of 1 to 1024 characters")},St=(e,r)=>{if(e===null||typeof e!="object")return E("a save result must be an object");const t=e;switch(t.kind){case"grant":return wr(t);case"saved":return m.isExplorerEditToken(t.version)?{kind:"saved",version:t.version}:E("a saved result needs a version of 1 to 1024 characters");case"conflict":return m.isExplorerEditToken(t.version)?{kind:"conflict",version:t.version,text:ie(t.text,r,"a conflict's current text")}:E("a conflict needs the current version of 1 to 1024 characters");default:return E(`a save result's kind must be "saved", "conflict" or "grant"`)}},Pt=e=>{if(e===null||typeof e!="object")return E("a preview must be an object");const{htmlContent:r,headings:t}=e;if(typeof r!="string"||!Array.isArray(t))return E("a preview needs htmlContent and headings");if(t.length>m.EXPLORER_MAX_HEADINGS)return{kind:"failure",failure:m.failureOf("too-large")};for(const o of t){const c=m.headingViolation(o);if(c!==null)return E(c)}return{html:r,headings:t.map(({text:o,depth:c,id:d})=>({text:o,depth:c,id:d}))}},It=e=>{if(!Array.isArray(e))return E("revisions must be an array");const r=new Set;return e.map(t=>{const o=m.revisionViolation(t);if(o!==null)return E(o);const{id:c,modifiedAt:d,size:f,author:p,kept:h,current:k}=t;return r.has(c)?E(`two revisions share the id ${x.describeValue(c)}`):(r.add(c),{id:c,modifiedAt:d,size:f,author:p,kept:h,current:k})})},Dt=(e,r)=>ie(e,r,"a revision"),ge=e=>{if(e===null||typeof e!="object")return E("an asset file must be an object");const{name:r,contentType:t,size:o,version:c,open:d,kind:f,bridge:p}=e;if(f!==void 0)return E(f==="redirect"?"an asset redirect answers only a request for the stored file (options.delivery file), never one that reads the bytes":'an asset file has no kind (the only kind is "redirect")');if(typeof r!="string"||r==="")return E("an asset file needs a non-empty name");if(typeof t!="string")return E("an asset file needs a contentType string ('' when unknown)");if(o!==null&&!(typeof o=="number"&&Number.isSafeInteger(o)&&o>=0))return E("an asset file's size must be null or a non-negative safe integer");if(!hr(c))return E(`an asset file needs a version of 1 to 256 visible ASCII characters other than '"'`);if(typeof d!="function")return E("an asset file needs an open function");const h={name:r,contentType:t,size:o,version:c,open:d};return Object.freeze(p===void 0?h:{...h,bridge:Lt(p)})},Lt=e=>{if(e===null||typeof e!="object")return E("an asset file's bridge must be an object when present");const{uri:r,storageVersion:t,readFailure:o}=e;return typeof r!="string"||r===""?E("an asset file's bridge needs a non-empty uri"):t!==null&&(typeof t!="string"||t==="")?E("an asset file's bridge needs a storageVersion that is a non-empty string, or null when the storage keeps none"):typeof o!="function"?E("an asset file's bridge needs a readFailure function"):Object.freeze({uri:r,storageVersion:t,readFailure:o})},Ye=e=>{if(e===null||typeof e!="object"||e.kind!=="redirect")return ge(e);const{url:r}=e;if(typeof r!="string"||!URL.canParse(r))return E("an asset redirect needs an absolute https URL");const t=new URL(r);return t.protocol!=="https:"||t.username!==""||t.password!==""?E("an asset redirect's URL must be https and carry no credentials"):Object.freeze({kind:"redirect",url:t.href})},Nt=e=>Array.isArray(e)?e.map(r=>{if(r===null||typeof r!="object")return E("a notice must be an object");const{id:t,tone:o,title:c,body:d,action:f}=r;if(typeof t!="string"||t===""||typeof c!="string")return E("a notice needs an id and a title");if(!m.isExplorerNoticeTone(o))return E(`unknown notice tone ${x.describeValue(o)}`);if(d!==void 0&&typeof d!="string")return E("a notice body must be a string");const h={id:t,tone:o,title:c,...d===void 0?{}:{body:d}};if(f===void 0)return h;if(f===null||typeof f!="object")return E("a notice action must be an object");const{label:k,href:y}=f;return typeof k!="string"||!m.isAcceptableUrl(y,m.EXPLORER_LINK_PROTOCOLS)?E("a notice action needs a label and an http(s), mailto or relative href"):{...h,action:{label:k,href:y}}}):E("notices must be an array"),$t=4e3,te=Object.freeze({ttlMs:3e5,maxEntries:64,maxBytes:64*1024*1024}),mr="private, no-store",jt=Object.freeze({"Content-Type":"application/json; charset=utf-8","Cache-Control":mr,"X-Content-Type-Options":"nosniff","Content-Security-Policy":"default-src 'none'; frame-ancestors 'none'; sandbox","Cross-Origin-Resource-Policy":"same-origin"}),he=Object.freeze([]),Ct=Object.freeze({status:"ok",source:null,ancestors:null}),Ge=Object.freeze(["contains","confirm"]),We=Object.freeze({readOnly:!1}),Mt=Object.freeze({readOnly:!0}),zt=new Set(["file","text","workbook"]),Ut=new Set(["file","text"]),Vt=Object.freeze({status:"error",failure:Object.freeze({reason:"invalid"})}),P=(e,r,t)=>{if(!(t&&r===void 0)&&typeof r!="function")throw new TypeError(`[markdown-explorer] ${e} must be a function; got ${x.describeValue(r)}`)},B=(e,r,t)=>{if(typeof r!="number")throw new TypeError(`[markdown-explorer] ${e} must be a number; got ${x.describeValue(r)}`);if(!Number.isSafeInteger(r)||r<=0||r>t)throw new RangeError(`[markdown-explorer] ${e} must be an integer in 1..${String(t)}; got ${x.describeValue(r)}`);return r},Ft=e=>{if(e===null||typeof e!="object"||!Object.isFrozen(e))throw new TypeError("[markdown-explorer] config must be the value returned by defineExplorerConfig");return $.revalidateExplorerConfig(e)},we=e=>{try{return new Headers(e)}catch{throw new TypeError("[markdown-explorer] authenticate returned headers that are not a valid headers init (their values are not logged)")}},Je=e=>e instanceof Response?new TypeError(`[markdown-explorer] authenticate threw a Response (status ${String(e.status)}), which a data request does not follow`):e,Xt=(e,r)=>{if(!x.isPlainObject(r))throw new TypeError(`[markdown-explorer] ${e}.boundary must be a plain object { contains, confirm? }`);for(const t of Object.keys(r))if(!Ge.includes(t))throw new RangeError(`[markdown-explorer] ${e}.boundary.${t} is not an option; expected ${Ge.join(", ")}`);P(`${e}.boundary.contains`,r.contains,!1),P(`${e}.boundary.confirm`,r.confirm,!0)},Ht=e=>{if(!Array.isArray(e))throw new TypeError("[markdown-explorer] sources must be an array");const r=e;if(r.length===0)throw new RangeError("[markdown-explorer] sources must hold at least one source");const t=new Set;for(const[o,c]of r.entries()){if(c===null||typeof c!="object")throw new TypeError(`[markdown-explorer] sources[${String(o)}] must be an object`);const{id:d,label:f,boundary:p,tree:h,children:k,ancestors:y,cacheScope:b}=c;if(!$.isExplorerSourceId(d))throw new RangeError(`[markdown-explorer] sources[${String(o)}].id must use lowercase letters, digits and "-" and start with a letter or digit; got ${x.describeValue(d)}`);const T=`source ${x.describeValue(d)}`;if(t.has(d))throw new RangeError(`[markdown-explorer] source ids must be unique; ${x.describeValue(d)} repeats at sources[${String(o)}]`);if(t.add(d),typeof f!="string"&&typeof f!="function")throw new TypeError(`[markdown-explorer] ${T}.label must be a string or a function`);if(typeof f=="string"&&f.trim()==="")throw new RangeError(`[markdown-explorer] ${T}.label must not be blank`);if(Xt(T,p),P(`${T}.tree`,h,!1),P(`${T}.children`,k,!0),P(`${T}.ancestors`,y,!0),b!==void 0&&b!=="principal"&&b!=="shared")throw new RangeError(`[markdown-explorer] ${T}.cacheScope must be "principal" or "shared"; got ${x.describeValue(b)}`)}return r},Bt=e=>{if(e===!1)return!1;if(e===void 0)return te;if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] treeCache must be { ttlMs, maxEntries, maxBytes } or false");const{ttlMs:r,maxEntries:t,maxBytes:o}=e;return{ttlMs:r===void 0?te.ttlMs:B("treeCache.ttlMs",r,Number.MAX_SAFE_INTEGER),maxEntries:t===void 0?te.maxEntries:B("treeCache.maxEntries",t,Number.MAX_SAFE_INTEGER),maxBytes:o===void 0?te.maxBytes:B("treeCache.maxBytes",o,Number.MAX_SAFE_INTEGER)}},Ke=e=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] authenticate must resolve to { status, ... }");const{status:r}=e;if(r!=="signed-in"&&r!=="signed-out"&&r!=="forbidden")throw new TypeError(`[markdown-explorer] authenticate resolved to an unknown status ${x.describeValue(r)}`);return e},Yt=(e,r)=>{if(!(r instanceof Response))throw new TypeError(`[markdown-explorer] ${e} must return a Response`);return r},Qe=(e,r)=>{if(typeof r!="string"||r==="")throw new TypeError("[markdown-explorer] principalKey must return a non-empty string");const t=e(r);if(!Ee.isExplorerScope(t))throw new TypeError("[markdown-explorer] the platform's scope must be 22 base64url characters");return t},Gt=(e,r)=>{try{return e(r)}catch(t){return t}},Wt=(e,r)=>{const t=e(r);if(t!==void 0&&typeof t!="string")throw new TypeError(`[markdown-explorer] readSettings must return a string or undefined; got ${t===null?"null":typeof t}`);return t},Jt=e=>e.view==="multi"?e.docs:e.doc===null?[]:[e.doc],z=(e,r)=>{const t=e.getAll(r),[o]=t;return t.length===1&&o!==void 0&&o!==""?o:null},S=(e,r,t,o={})=>{const c=new Headers(t);for(const[d,f]of Object.entries({...jt,...o}))c.set(d,f);return new Response(r,{status:e,headers:c})},O=(e,r,t)=>S(m.EXPLORER_FAILURE_STATUS[e.reason],JSON.stringify({failure:e}),r,t),Kt=new Set(["refresh","save","preview","issue-id"]),Qt=new Set(["issue-id","resolve-id"]),Ze=4,Zt=new Set(["edit","save","preview","revisions","revision"]),qe=(e,r)=>{const t=Kt.has(r)?["POST"]:["GET","HEAD"];return t.includes(e.method.toUpperCase())?null:S(405,JSON.stringify({failure:{reason:"invalid"}}),void 0,{Allow:t.join(", ")})},er=e=>e.headers.get(m.EXPLORER_PROOF_HEADER)===m.EXPLORER_REFRESH_PROOF&&J.crossOriginRefusal(e,J.NO_CROSS_ORIGIN_NAVIGATION)===void 0,qt=e=>e.headers.get(m.EXPLORER_PROOF_HEADER)===m.EXPLORER_EDIT_PROOF&&J.crossOriginRefusal(e,J.NO_CROSS_ORIGIN_NAVIGATION)===void 0,en=e=>e.headers.get(m.EXPLORER_PROOF_HEADER)===m.EXPLORER_DOCUMENT_ID_PROOF&&J.crossOriginRefusal(e,J.NO_CROSS_ORIGIN_NAVIGATION)===void 0,rn=async(e,r)=>{const[t,...o]=(e.headers.get("Content-Type")??"").split(";").map(T=>T.trim().toLowerCase()),c=o.find(T=>T.startsWith("charset="));if(t!==m.EXPLORER_DRAFT_MEDIA_TYPE||c!==void 0&&c!=="charset=utf-8")return{status:"error",failure:{reason:"invalid"}};const d=Number(e.headers.get("Content-Length")??"0");if(Number.isFinite(d)&&d>r)return{status:"error",failure:{reason:"too-large"}};if(e.body===null)return{status:"ok",text:""};const f=e.body.getReader(),p=[];let h=0;for(;;){const{done:T,value:A}=await f.read();if(T)break;if(h+=A.byteLength,h>r)return await f.cancel(),{status:"error",failure:{reason:"too-large"}};p.push(A)}const k=new Uint8Array(h);let y=0;for(const T of p)k.set(T,y),y+=T.byteLength;let b;try{b=new TextDecoder("utf-8",{fatal:!0}).decode(k)}catch{return{status:"error",failure:{reason:"invalid"}}}return b.includes("\0")?{status:"error",failure:{reason:"invalid"}}:{status:"ok",text:b}},tn=e=>{if(e===void 0)return;if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] edit must be an object of the editor's ports");const r=e;for(const t of["source","save","preview","revisions","revision"])P(`edit.${t}`,r[t],!1);return e},nn=(e,r)=>{if(e.documentIds===null!=(r===void 0))throw new TypeError("[markdown-explorer] documentIds in defineExplorerConfig and the server's documentIds ports go together; give both or neither");if(r===void 0)return;if(r===null||typeof r!="object")throw new TypeError("[markdown-explorer] documentIds must be an object of the registry's ports");const t=r;for(const o of["issue","resolve"])P(`documentIds.${o}`,t[o],!1);return r},sn=e=>{if(e===null||typeof e!="object")return null;const{kind:r,id:t}=e;return r==="issued"||r==="taken"?{kind:r}:r==="existing"&&m.isCanonicalDocumentId(t)?{kind:r,id:t}:null},on=e=>{if(e===null||typeof e!="object")return;const{kind:r,path:t}=e;return r==="unbound"?null:r==="bound"&&typeof t=="string"&&$.hasDocumentUrl(t)?t:void 0},rr=(e,r)=>e.status==="ok"?S(200,JSON.stringify(e),r):O(e.failure,r),an=({parentHeaders:e,loaderHeaders:r,errorHeaders:t})=>{const o=new Headers,c=t===void 0?[e,r]:[e,r,t];for(const d of c)for(const[f,p]of d)f!=="set-cookie"&&o.set(f,p);return o},cn=(e,r)=>{if(e===null||typeof e!="object")throw new TypeError("[markdown-explorer] the server configuration must be an object");const t=Ft(e.config),o=r.prepareScope();P("authenticate",e.authenticate,!1),P("principalKey",e.principalKey,!1),P("document",e.document,!1),P("asset",e.asset,!1),P("signedOutPage",e.signedOutPage,!1),P("notices",e.notices,!0),P("onTreeRefreshed",e.onTreeRefreshed,!0),P("readSettings",e.readSettings,!1);const c=Ht(e.sources),d=$.withExplorerSources(t,c.map(n=>n.id)),f=e.logger;if(f!==void 0&&(f===null||typeof f!="object"||typeof f.error!="function"))throw new TypeError("[markdown-explorer] logger must be an object with an error function");const p=e.logger===void 0?ut:e.logger,h=m.resolvePathRules(e.deny),k=e.deferredTimeoutMs===void 0?$t:B("deferredTimeoutMs",e.deferredTimeoutMs,Ee.MAX_TIMER_MILLISECONDS),y=e.textMaxBytes===void 0?He:B("textMaxBytes",e.textMaxBytes,Be),b=tn(e.edit);if(b===void 0&&e.editMaxBytes!==void 0)throw new TypeError("[markdown-explorer] editMaxBytes needs the edit ports");const T=e.editMaxBytes===void 0?He:B("editMaxBytes",e.editMaxBytes,Be),A=nn(t,e.documentIds),I=Bt(e.treeCache),V=()=>Date.now(),F=I===!1?gt(V):yt({...I,now:V}),U=r.createSanitizer({options:e.sanitizer,maxPanels:t.multiView.maxPanels,iframeHosts:t.iframeHosts,dataPath:t.dataPath,ownUrls:$.ownUrlsOf(t)}),X=e.readSettings,j=e.assetMaxRangeBytes===null?null:B("assetMaxRangeBytes",e.assetMaxRangeBytes,Number.MAX_SAFE_INTEGER),M=new Map(c.map(n=>[n.id,n])),ce=$.documentStyleNames(t),{authenticate:K,principalKey:ke,signedOutPage:yr,onTreeRefreshed:Oe}=e,gr=(n,a)=>{if(typeof n.label=="string")return n.label;const s=n.label(a);if(typeof s!="string"||s.trim()==="")throw new TypeError(`[markdown-explorer] the label of source ${x.describeValue(n.id)} must be a non-blank string`);return s},ue=(n,a)=>n.cacheScope==="shared"?n.id:`${n.id}\0${a}`,G=(n,a)=>{const s=u=>N(p,{operation:"boundary",sourceId:n.id,path:a,error:u});let i;try{i=n.boundary.contains(a)}catch(u){return s(u),!1}return typeof i=="boolean"?i:(Xe(i,s),s(new TypeError(`[markdown-explorer] boundary.contains of source ${x.describeValue(n.id)} must return a boolean; got ${x.describeValue(i)}`)),!1)},de=async(n,a,s)=>{const{confirm:i}=n.boundary;if(i===void 0)return{status:"inside",readPath:s};let u;try{u=await i(a,s)}catch(R){return{status:"error",failure:v(R,{operation:"boundary",sourceId:n.id,path:s},a.signal,p)}}const l=R=>(N(p,{operation:"boundary",sourceId:n.id,path:s,error:new TypeError(`[markdown-explorer] boundary.confirm of source ${x.describeValue(n.id)} ${R}`)}),{status:"outside"});if(u===null||typeof u!="object")return l(`must resolve to { inside, readPath? }; got ${u===null?"null":typeof u}`);const{inside:w,readPath:g}=u;return w===!1?{status:"outside"}:w!==!0||typeof g!="string"?l("must resolve to { inside: false } or { inside: true, readPath: string }"):!m.isAcceptableDocumentPath(g)||h.deniesPath(g)?(N(p,{operation:"boundary",sourceId:n.id,path:s,error:new RangeError(`[markdown-explorer] boundary.confirm of source ${x.describeValue(n.id)} answered a readPath the explorer does not serve (unacceptable or denied)`)}),{status:"error",failure:{reason:"failed"}}):{status:"inside",readPath:g}},W=async(n,a)=>{const s=c.filter(l=>G(l,a));if(s.length===0)return{status:"error",failure:{reason:"forbidden"}};const i=s.find(l=>l.boundary.confirm===void 0);if(i!==void 0)return{status:"inside",readPath:a,sourceId:i.id};let u=null;for(const l of s){const w=await de(l,n,a);if(w.status==="inside")return{status:"inside",readPath:w.readPath,sourceId:l.id};w.status==="error"&&u===null&&(u=w.failure)}return{status:"error",failure:u===null?{reason:"forbidden"}:u}},Ae=async(n,a,s)=>{try{return Ye(await e.asset(n,a,s,{delivery:"file"})),null}catch(i){return v(i,{operation:"asset",path:a},n.signal,p)}},xe=async(n,a,s)=>{let i;try{i=await n.resolve(a,s)}catch(g){return{status:"error",failure:v(g,{operation:"resolve-id"},a.signal,p)}}const u=on(i);if(u===void 0)return N(p,{operation:"resolve-id",error:new TypeError('[markdown-explorer] documentIds.resolve must resolve to { kind: "unbound" } or { kind: "bound", path } with a document path that has a URL')}),{status:"error",failure:{reason:"failed"}};if(u===null)return{status:"error",failure:{reason:"not-found"}};if(h.deniesPath(u))return Z(p,{operation:"resolve-id",path:u}),{status:"error",failure:{reason:"forbidden"}};const l=await W(a,u);if(l.status==="error")return l;const w=await Ae(a,u,l.readPath);return w!==null?{status:"error",failure:w}:{status:"resolved",path:u,sourceId:l.sourceId}},Er=async(n,a,s)=>{if(h.deniesPath(s))return Z(p,{operation:"issue-id",path:s}),{status:"error",failure:{reason:"forbidden"}};const i=await W(a,s);if(i.status==="error")return i;const u=await Ae(a,s,i.readPath);if(u!==null)return{status:"error",failure:u};for(let l=0;l<Ze;l+=1){const w=m.createDocumentId(D=>crypto.getRandomValues(D));let g;try{g=await n.issue(a,s,w)}catch(D){return{status:"error",failure:v(D,{operation:"issue-id",path:s},a.signal,p)}}const R=sn(g);if(R===null)return N(p,{operation:"issue-id",path:s,error:new TypeError('[markdown-explorer] documentIds.issue must resolve to { kind: "issued" }, { kind: "existing", id } with an ID in its canonical form, or { kind: "taken" }')}),{status:"error",failure:{reason:"failed"}};if(R.kind==="issued")return{status:"ok",id:w};if(R.kind==="existing")return{status:"ok",id:R.id}}return N(p,{operation:"issue-id",path:s,error:new Error(`[markdown-explorer] documentIds.issue answered taken for ${String(Ze)} candidates in a row`)}),{status:"error",failure:{reason:"failed"}}},ve=(n,a,s)=>{const i=({path:u,reason:l})=>pt(p,{operation:s.operation,sourceId:s.sourceId,path:u,error:new TypeError(`[markdown-explorer] an entry with ${l} was left out`)});try{return{status:"ok",entries:Tt(n,h,a.children!==void 0,i,u=>G(a,u))}}catch(u){return N(p,{...s,error:u}),{status:"error",failure:{reason:"failed"}}}},br=async(n,a,s)=>{let i;try{i=await n.tree(a)}catch(l){return{status:"error",failure:v(l,{operation:"tree",sourceId:n.id},a.signal,p)}}const u=ve(i,n,{operation:"tree",sourceId:n.id});return u.status==="ok"?{status:"ok",entries:u.entries,loadedAt:s}:u},_e=(n,a,s,i)=>(u,l)=>br(n,{principal:a,request:s,signal:u,refresh:i},l),Se=(n,a,s,i,u)=>F.load(ue(n,s),u,_e(n,a,i,!1)),Tr=(n,a,s,i)=>F.refresh(ue(n,s),i.signal,_e(n,a,i,!0)),Rr=(n,a)=>{if(Oe===void 0)return;const s=i=>N(p,{operation:"refresh",sourceId:n.id,error:i});try{Xe(Oe(a),s)}catch(i){s(i)}},kr=async(n,a,s,i)=>{if(h.deniesPath(i)||!G(n,i))return{status:"error",failure:{reason:"forbidden"}};const u=await de(n,s,i);if(u.status==="outside")return{status:"error",failure:{reason:"forbidden"}};if(u.status==="error")return{status:"error",failure:u.failure};let l;try{l=await a(s,i,u.readPath)}catch(w){return{status:"error",failure:v(w,{operation:"children",sourceId:n.id,path:i},s.signal,p)}}return ve(l,n,{operation:"children",sourceId:n.id,path:i})},Pe=async(n,a,s,i)=>{const u=await de(n,s,i);if(u.status==="outside")return{status:"ok",ancestors:null};if(u.status==="error")return{status:"error",failure:u.failure};let l;try{l=await a(s,i,u.readPath,{maxDepth:t.revealDocument.maxDepth})}catch(w){return{status:"error",failure:v(w,{operation:"ancestors",sourceId:n.id,path:i},s.signal,p)}}if(Array.isArray(l)&&l.length>t.revealDocument.maxDepth)return{status:"ok",ancestors:null};try{return{status:"ok",ancestors:bt(l,i,h,w=>G(n,w))}}catch(w){return N(p,{operation:"ancestors",sourceId:n.id,path:i,error:w}),{status:"error",failure:{reason:"failed"}}}},Or=async(n,a,s,i)=>h.deniesPath(i)?{status:"error",failure:{reason:"forbidden"}}:G(n,i)?Pe(n,a,s,i):{status:"ok",ancestors:null},Ar=async(n,a,s)=>{if(h.deniesPath(s))return{status:"error",failure:{reason:"forbidden"}};for(const i of[n,...c.filter(u=>u!==n)]){if(a.signal.aborted)break;const u=i.ancestors;if(u===void 0||!G(i,s))continue;const l=await Pe(i,u,a,s);if(l.status==="ok"&&l.ancestors!==null)return{status:"ok",source:i.id,ancestors:l.ancestors}}return Ct},Ie=async(n,a,s)=>{if(h.deniesPath(s))return m.failureDocument("forbidden");const i=await W(n,s);if(i.status==="error")return{kind:"failure",failure:i.failure};let u;try{u=await e.document(n,s,i.readPath)}catch(g){return{kind:"failure",failure:v(g,{operation:"document",path:s},n.signal,p)}}let l;try{l=At(u,g=>m.explorerAssetHref(t.dataPath,s,g),b!==void 0)}catch(g){return N(p,{operation:"document",path:s,error:g}),m.failureDocument("failed")}if(l.kind!=="unsanitized-markdown")return l;const w=await U(l.html,{scope:a,signal:n.signal});return w.status==="sanitized"?{kind:"markdown",name:l.name,htmlContent:w.html,headings:l.headings,lang:l.lang,edit:l.edit}:(w.cause!==null&&N(p,{operation:"document",path:s,error:w.cause}),m.failureDocument(w.reason))},xr=async n=>{if(e.notices===void 0)return he;try{return Nt(await e.notices(n))}catch(a){return v(a,{operation:"notices"},n.signal,p),he}},De=async(n,a,s,i)=>{const u=z(a,m.EXPLORER_DATA_QUERY.path);if(u===null||!m.isAcceptableDocumentPath(u))return{status:"answered",response:O({reason:"invalid"},s)};const l=m.readExplorerAssetDisplay(a);if(l===null||!i.has(l))return{status:"answered",response:O({reason:"invalid"},s)};if(h.deniesPath(u))return Z(p,{operation:"asset",path:u}),{status:"answered",response:O({reason:"forbidden"},s)};const w=await W(n,u);if(w.status==="error")return{status:"answered",response:O(w.failure,s)};try{const g=await e.asset(n,u,w.readPath,{delivery:l}),R=l==="file"?Ye(g):ge(g);return"kind"in R?{status:"answered",response:ct(R.url,s)}:{status:"admitted",path:u,display:l,file:R}}catch(g){return{status:"answered",response:O(v(g,{operation:"asset",path:u},n.signal,p),s)}}},vr=async(n,a,s)=>{const i=await De(n,a,s,zt);if(i.status==="answered")return i.response;const{path:u,display:l,file:w}=i;try{return l==="text"?await st(n.request,w,s,t.legacyTextEncoding,j):l==="workbook"?await at(n.request,w,s):await rt(n.request,w,s,j)}catch(g){return O(v(g,{operation:"asset",path:u},n.signal,p),s)}},_r=async(n,a,s)=>{const i=fr(n,a,s,t.legacyTextEncoding,j);return i.kind==="respond"?i:ye(i.selection,await lr(a,t.legacyTextEncoding))},Sr=async(n,a,s)=>{const i=await De(n,a,s,Ut);if(i.status==="answered")return{kind:"response",response:i.response};const{path:u,display:l,file:w}=i,g=L=>O(v(L,{operation:"asset",path:u},n.signal,p),s);let R;try{R=l==="text"?await _r(n.request,w,s):ur(n.request,w,s,j)}catch(L){return{kind:"response",response:g(L)}}if(R.kind==="respond")return{kind:"response",response:R.response};const{bridge:D}=w;return D===void 0?(N(p,{operation:"asset",path:u,error:new TypeError("[markdown-explorer] the asset port must attach a bridge to a file the host streams itself")}),{kind:"response",response:O({reason:"failed"},s)}):{kind:"file",status:R.status,headers:R.headers,bridge:{uri:D.uri,storageVersion:D.storageVersion},range:R.range,length:R.length,fail:L=>g(Gt(D.readFailure,L))}},Pr=async(n,a)=>{if(h.deniesPath(a))return Z(p,{operation:"text",path:a}),m.failureDocument("forbidden");const s=await W(n,a);if(s.status==="error")return{kind:"failure",failure:s.failure};try{const i=ge(await e.asset(n,a,s.readPath,{delivery:"text"})),u=await wt(i,y,t.legacyTextEncoding);return u===null?m.failureDocument("unsupported"):{kind:"text",name:i.name,text:u.text,truncated:u.truncated,url:m.explorerAssetHref(t.dataPath,a,i.version)}}catch(i){return{kind:"failure",failure:v(i,{operation:"text",path:a},n.signal,p)}}},Q=async(n,a,s)=>h.deniesPath(s)?(Z(p,{operation:a,path:s}),{status:"error",failure:{reason:"forbidden"}}):W(n,s),Ir=async(n,a,s)=>{const i=await Q(a,"edit",s);if(i.status==="error")return{kind:"failure",failure:i.failure};try{return _t(await n.source(a,s,i.readPath),T)}catch(u){return{kind:"failure",failure:v(u,{operation:"edit",path:s},a.signal,p)}}},Dr=async(n,a,s,i,u)=>{const l=await Q(a,"save",s);if(l.status==="error")return{kind:"failure",failure:l.failure};try{return St(await n.save(a,s,l.readPath,{text:u,baseVersion:i}),T)}catch(w){return{kind:"failure",failure:v(w,{operation:"save",path:s},a.signal,p)}}},Lr=async(n,a,s,i,u)=>{const l=await Q(a,"preview",i);if(l.status==="error")return{kind:"failure",failure:l.failure};let w;try{w=Pt(await n.preview(a,i,l.readPath,u))}catch(R){return{kind:"failure",failure:v(R,{operation:"preview",path:i},a.signal,p)}}if("kind"in w)return w.kind==="failure"?w:m.failureDocument("failed");const g=await U(w.html,{scope:s,signal:a.signal});return g.status==="sanitized"?{kind:"preview",htmlContent:g.html,headings:w.headings}:(g.cause!==null&&N(p,{operation:"preview",path:i,error:g.cause}),m.failureDocument(g.reason))},Nr=async(n,a,s)=>{const i=await Q(a,"revisions",s);if(i.status==="error")return{kind:"failure",failure:i.failure};try{return{kind:"revisions",revisions:It(await n.revisions(a,s,i.readPath))}}catch(u){return{kind:"failure",failure:v(u,{operation:"revisions",path:s},a.signal,p)}}},$r=async(n,a,s,i)=>{const u=await Q(a,"revision",s);if(u.status==="error")return{kind:"failure",failure:u.failure};try{return{kind:"revision",id:i,text:Dt(await n.revision(a,s,u.readPath,i),T)}}catch(l){return{kind:"failure",failure:v(l,{operation:"revision",path:s},a.signal,p)}}},jr=async(n,a,s,i,u,l)=>{const w=z(u,m.EXPLORER_DATA_QUERY.path);if(w===null||!m.isAcceptableDocumentPath(w))return O({reason:"invalid"},l);if(a==="edit")return S(200,JSON.stringify(await Ir(n,s,w)),l);if(a==="revisions")return S(200,JSON.stringify(await Nr(n,s,w)),l);if(a==="revision"){const D=z(u,m.EXPLORER_DATA_QUERY.revision);return m.isExplorerEditToken(D)?S(200,JSON.stringify(await $r(n,s,w,D)),l):O({reason:"invalid"},l)}const g=z(u,m.EXPLORER_DATA_QUERY.base);if(a==="save"&&!m.isExplorerEditToken(g))return O({reason:"invalid"},l);const R=await rn(s.request,T);return R.status==="error"?O(R.failure,l):a==="preview"?S(200,JSON.stringify(await Lr(n,s,i,w,R.text)),l):S(200,JSON.stringify(await Dr(n,s,w,g,R.text)),l)},Cr=async({request:n,url:a,params:s})=>{const i=Ke(await K(n,We));if(i.status==="forbidden")throw Xr.accessFailureResponse("forbidden",{headers:we(i.headers)});const u=we(i.headers);if(u.set("Cache-Control",mr),i.status==="signed-out")throw Yt("signedOutPage",yr({request:n,url:a},u));const l=$.resolveExplorerLocation(d,s["*"],a.searchParams);if(l.kind==="redirect")throw ee.redirect(l.href,{headers:u});const{principal:w}=i,g=Qe(o,ke(w));if(l.kind==="document-id"){if(A===void 0)throw new TypeError("[markdown-explorer] an ID URL was resolved without the documentIds ports");const R=l.id===null?Vt:await xe(A,{principal:w,request:n,signal:n.signal,refresh:!1},l.id);if(R.status==="resolved")throw ee.redirect(Mr(l.opens,R),{headers:u});return ee.data(Le(w,g,n,l.location,{id:l.id,failure:R.failure}),{status:m.EXPLORER_FAILURE_STATUS[R.failure.reason],headers:u})}return ee.data(Le(w,g,n,l.location,null),{headers:u})},Mr=(n,a)=>$.explorerHref(d,$.documentIdOpeningTarget(n,a.path,a.sourceId)),Le=(n,a,s,i,u)=>{const l=M.get(i.source);if(l===void 0)throw new RangeError(`[markdown-explorer] no source for ${x.describeValue(i.source)}`);const w={signal:s.signal,timeoutMs:k,late:null,handOverMs:k};return{scope:a,sources:c.map(g=>({id:g.id,label:gr(g,n)})),settings:$.parseViewSettings(Wt(X,s),ce),tree:i.view==="single"?null:{sourceId:i.source,result:fe(w,g=>Se(l,n,a,s,g).then(R=>R.result))},documents:Jt(i).map(g=>({path:g,document:fe(w,R=>Ie({principal:n,request:s,signal:R,refresh:!1},a,g))})),notices:fe({signal:s.signal,timeoutMs:k,late:he,handOverMs:0},g=>xr({principal:n,request:s,signal:g,refresh:!1})),documentId:u}},Ne=async(n,a)=>{const s=Ke(await K(n,a));return{authentication:s,headers:we(s.headers)}},$e=async n=>{let a;try{a=await Ne(n,We)}catch(u){return{status:"answered",response:O(v(Je(u),{operation:"authenticate"},n.signal,p))}}const{authentication:s,headers:i}=a;return s.status==="signed-out"?{status:"answered",response:O({reason:"unauthorized"},i)}:s.status==="forbidden"?{status:"answered",response:O({reason:"forbidden"},i)}:{status:"signed-in",principal:s.principal,headers:i}},zr=async(n,a,s)=>{const i=await $e(a);if(i.status==="answered")return i.response;const{principal:u,headers:l}=i;if(n==="asset")return vr({principal:u,request:a,signal:a.signal,refresh:!1},s,l);const w=Qe(o,ke(u));l.set(m.EXPLORER_SCOPE_HEADER,w);const g={principal:u,request:a,signal:a.signal,refresh:!1},R=()=>O({reason:"invalid"},l);if(n==="document"){const _=z(s,m.EXPLORER_DATA_QUERY.path);if(_===null||!m.isAcceptableDocumentPath(_))return R();const H=a.headers.has(m.EXPLORER_PROOF_HEADER);return H&&!er(a)?O({reason:"forbidden"},l):S(200,JSON.stringify(await Ie({...g,refresh:H},w,_)),l)}if(n==="text"){const _=z(s,m.EXPLORER_DATA_QUERY.path);return _===null||!m.isAcceptableDocumentPath(_)?R():S(200,JSON.stringify(await Pr(g,_)),l)}if(n==="edit"||n==="save"||n==="preview"||n==="revisions"||n==="revision")return b===void 0?O({reason:"not-found"},l):jr(b,n,g,w,s,l);if(n==="issue-id"){if(A===void 0)return O({reason:"not-found"},l);const _=z(s,m.EXPLORER_DATA_QUERY.path);return _===null||!$.hasDocumentUrl(_)?R():rr(await Er(A,g,_),l)}if(n==="resolve-id"){if(A===void 0)return O({reason:"not-found"},l);const _=z(s,m.EXPLORER_DATA_QUERY.id);if(_===null||!m.isCanonicalDocumentId(_))return R();const H=await xe(A,g,_);return rr(H.status==="resolved"?{status:"ok",path:H.path,source:H.sourceId}:H,l)}const D=z(s,m.EXPLORER_DATA_QUERY.source),L=z(s,m.EXPLORER_DATA_QUERY.path);if(D===null||(n==="children"||n==="ancestors"||n==="reveal")&&(L===null||!m.isAcceptableDocumentPath(L)))return R();const C=M.get(D);if(C===void 0)return O({reason:"not-found"},l);if(n==="tree")return S(200,(await Se(C,u,w,a,a.signal)).json,l);if(n==="refresh"){const _=await Tr(C,u,w,a);return a.signal.aborted||Rr(C,ue(C,w)),S(200,_.json,l)}return n==="ancestors"?C.ancestors===void 0||L===null?O({reason:"not-found"},l):S(200,JSON.stringify(await Or(C,C.ancestors,g,L)),l):n==="reveal"?L===null?R():S(200,JSON.stringify(await Ar(C,g,L)),l):C.children===void 0||L===null?O({reason:"not-found"},l):S(200,JSON.stringify(await kr(C,C.children,g,L)),l)},Ur=async n=>{const{authentication:a,headers:s}=await Ne(n,Mt);if(!s.keys().next().done)throw new TypeError("[markdown-explorer] authenticate returned headers in read-only mode; a read-only authentication must only read the session (none was forwarded)");return a.status==="signed-in"},je=t.embeds.linkCardEndpoint===null?null:r.createLinkCardHandler({authorize:Ur}),Vr=async(n,a)=>{try{return await n(a)}catch(s){return O(v(Je(s),{operation:"authenticate"},a.signal,p))}},le=async(n,a,s)=>{if(new URL(n.url).pathname.endsWith(".data"))return O({reason:"not-found"});if(!m.isExplorerDataOperation(s))return O({reason:"not-found"});if(s==="link-card"){if(je===null)return O({reason:"not-found"});const u=qe(n,s);return u!==null?u:Vr(je,n)}if(Zt.has(s)&&b===void 0)return O({reason:"not-found"});if(Qt.has(s)&&A===void 0)return O({reason:"not-found"});const i=qe(n,s);if(i!==null)return i;if(s==="refresh"&&!er(n))return O({reason:"forbidden"});if((s==="save"||s==="preview")&&!qt(n))return O({reason:"forbidden"});if(s==="issue-id"&&!en(n))return O({reason:"forbidden"});try{return await zr(s,n,a.searchParams)}catch(u){return O(v(u,{operation:s},n.signal,p))}},Fr=async(n,a,s)=>{if(s!=="asset"||n.method.toUpperCase()!=="GET"||new URL(n.url).pathname.endsWith(".data"))return{kind:"response",response:await le(n,a,s)};try{const i=await $e(n);return i.status==="answered"?{kind:"response",response:i.response}:await Sr({principal:i.principal,request:n,signal:n.signal,refresh:!1},a.searchParams,i.headers)}catch(i){return{kind:"response",response:O(v(i,{operation:"asset"},n.signal,p))}}};return Object.freeze({loader:Cr,headers:an,dataLoader:({request:n,url:a,params:s})=>le(n,a,s["*"]),dataAction:({request:n,url:a,params:s})=>le(n,a,s["*"]),planData:({request:n,url:a,params:s})=>Fr(n,a,s["*"]),forgetTree:n=>{if(typeof n!="string")throw new TypeError(`[markdown-explorer] forgetTree needs the string key onTreeRefreshed received; got ${x.describeValue(n)}`);F.forget(n)}})};exports.ASSET_CONTENT_SECURITY_POLICIES=se;exports.ExplorerError=dt;exports.createExplorerServer=cn;
|