@aiquants/markdown-explorer 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/CHANGELOG.md +795 -0
  2. package/README.md +119 -55
  3. package/dist/EditSurface-CLG70Vnn.cjs +6 -0
  4. package/dist/EditSurface-D2j1kCEE.js +990 -0
  5. package/dist/ExplorerSplit-CfP1smbT.js +1589 -0
  6. package/dist/ExplorerSplit-D_0VohOv.cjs +2 -0
  7. package/dist/{MultiLayout-DYNGlNy0.js → MultiLayout-BeJ5Lubb.js} +291 -290
  8. package/dist/MultiLayout-CxV5SI7f.cjs +1 -0
  9. package/dist/NativeScrollBar-BM5NULzg.js +62 -0
  10. package/dist/NativeScrollBar-RWXpVhbI.cjs +1 -0
  11. package/dist/TreeLayout-AxLw-36S.js +103 -0
  12. package/dist/TreeLayout-Bg2YH-EY.cjs +1 -0
  13. package/dist/client/MarkdownExplorer.d.cts +14 -1
  14. package/dist/client/MarkdownExplorer.d.ts +14 -1
  15. package/dist/client/edit/lineEndings.d.cts +4 -0
  16. package/dist/client/edit/lineEndings.d.ts +4 -0
  17. package/dist/client/hostContract.d.cts +67 -0
  18. package/dist/client/hostContract.d.ts +67 -0
  19. package/dist/core/config.d.cts +7 -0
  20. package/dist/core/config.d.ts +7 -0
  21. package/dist/core/contracts.d.cts +10 -4
  22. package/dist/core/contracts.d.ts +10 -4
  23. package/dist/core/draftAnswer.d.cts +23 -0
  24. package/dist/core/draftAnswer.d.ts +23 -0
  25. package/dist/core/geometry.d.cts +1 -0
  26. package/dist/core/geometry.d.ts +1 -0
  27. package/dist/core/labels.d.cts +78 -0
  28. package/dist/core/labels.d.ts +78 -0
  29. package/dist/core/location.d.cts +3 -2
  30. package/dist/core/location.d.ts +3 -2
  31. package/dist/core/ownUrls.d.cts +15 -0
  32. package/dist/core/ownUrls.d.ts +15 -0
  33. package/dist/core/treeSettings.d.cts +3 -2
  34. package/dist/core/treeSettings.d.ts +3 -2
  35. package/dist/core/viewSettings.d.cts +5 -1
  36. package/dist/core/viewSettings.d.ts +5 -1
  37. package/dist/describeValue-CLlVRO8d.js +17 -0
  38. package/dist/describeValue-Ccvhbt36.cjs +1 -0
  39. package/dist/explorerCore-DLpDuSev.js +998 -0
  40. package/dist/explorerCore-DYrxS9ez.cjs +1 -0
  41. package/dist/index-C1YMH-yI.js +5816 -0
  42. package/dist/index-LQWQfpAf.cjs +18 -0
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.d.cts +7 -4
  45. package/dist/index.d.ts +7 -4
  46. package/dist/index.js +47 -42
  47. package/dist/licenses/@heroicons/react/LICENSE +21 -0
  48. package/dist/licenses/entities/LICENSE +11 -0
  49. package/dist/licenses/parse5/LICENSE +19 -0
  50. package/dist/location--KvTA0Ri.js +726 -0
  51. package/dist/location-D8DyDkuA.cjs +1 -0
  52. package/dist/lru-DC8GBmkX.js +39 -0
  53. package/dist/lru-SGmUyBQU.cjs +1 -0
  54. package/dist/{merge-D7L_pINl.js → merge-Bb_HpPhe.js} +1 -1
  55. package/dist/{merge-DZI4pkWI.cjs → merge-DQUYEGCx.cjs} +1 -1
  56. package/dist/nestingGuardWorker.js +5511 -0
  57. package/dist/ownUrls-B259RGgd.cjs +1 -0
  58. package/dist/ownUrls-Dh5g6ZJi.js +370 -0
  59. package/dist/sanitizeJob-BYRk17nr.js +21 -0
  60. package/dist/sanitizeJob-Cs9o3Vpl.cjs +1 -0
  61. package/dist/sanitizePolicy-CEMdaLUB.js +139 -0
  62. package/dist/sanitizePolicy-CiQfnxyd.cjs +2 -0
  63. package/dist/sanitizeWorker.cjs +1 -1
  64. package/dist/sanitizeWorker.js +134 -139
  65. package/dist/sanitizerService-BY4CPCoA.cjs +1 -0
  66. package/dist/sanitizerService-KWXv7bPm.js +240 -0
  67. package/dist/server/assetResponse.d.cts +60 -0
  68. package/dist/server/assetResponse.d.ts +60 -0
  69. package/dist/server/browser/browserPlatform.d.cts +12 -0
  70. package/dist/server/browser/browserPlatform.d.ts +12 -0
  71. package/dist/server/createMarkdownExplorer.d.cts +0 -10
  72. package/dist/server/createMarkdownExplorer.d.ts +0 -10
  73. package/dist/server/explorerCore.d.cts +12 -0
  74. package/dist/server/explorerCore.d.ts +12 -0
  75. package/dist/server/fileSystemSource.d.cts +1 -0
  76. package/dist/server/fileSystemSource.d.ts +1 -0
  77. package/dist/server/inProcessFetch.d.cts +5 -0
  78. package/dist/server/inProcessFetch.d.ts +5 -0
  79. package/dist/server/platform.d.cts +18 -0
  80. package/dist/server/platform.d.ts +18 -0
  81. package/dist/server/ports.d.cts +36 -5
  82. package/dist/server/ports.d.ts +36 -5
  83. package/dist/server/sanitizeProtocol.d.cts +3 -0
  84. package/dist/server/sanitizeProtocol.d.ts +3 -0
  85. package/dist/server/sanitizer.d.cts +5 -40
  86. package/dist/server/sanitizer.d.ts +5 -40
  87. package/dist/server/sanitizerOptions.d.cts +24 -0
  88. package/dist/server/sanitizerOptions.d.ts +24 -0
  89. package/dist/server/sanitizerService.d.cts +41 -0
  90. package/dist/server/sanitizerService.d.ts +41 -0
  91. package/dist/server/{workerPool.d.cts → workerJobs.d.cts} +0 -16
  92. package/dist/server/{workerPool.d.ts → workerJobs.d.ts} +0 -16
  93. package/dist/server.cjs +1 -1
  94. package/dist/server.d.cts +3 -1
  95. package/dist/server.d.ts +3 -1
  96. package/dist/server.js +270 -1343
  97. package/dist/serverBrowser.cjs +1 -0
  98. package/dist/serverBrowser.d.cts +1 -0
  99. package/dist/serverBrowser.d.ts +1 -0
  100. package/dist/serverBrowser.js +120 -0
  101. package/dist/serverCore.cjs +1 -0
  102. package/dist/serverCore.d.cts +14 -0
  103. package/dist/serverCore.d.ts +14 -0
  104. package/dist/serverCore.js +46 -0
  105. package/dist/storage-BpYsprog.cjs +1 -0
  106. package/dist/{storage-CmGHg7OA.js → storage-D1uSw-xj.js} +19 -18
  107. package/dist/storage.cjs +1 -1
  108. package/dist/storage.js +1 -1
  109. package/dist/styles/markdown-explorer.css +1 -1
  110. package/dist/tapScrollCircle-BEydRn0y.js +14 -0
  111. package/dist/tapScrollCircle-DdX0Wri0.cjs +1 -0
  112. package/dist/testing.cjs +1 -0
  113. package/dist/testing.d.cts +6 -0
  114. package/dist/testing.d.ts +6 -0
  115. package/dist/testing.js +4 -0
  116. package/dist/useSplitPersistence-B2Fj508K.cjs +1 -0
  117. package/dist/useSplitPersistence-Fkqak8G8.js +44 -0
  118. package/docs/behavior/dom-hooks.md +14 -3
  119. package/docs/behavior/hosting.md +123 -0
  120. package/docs/behavior/layout.md +69 -19
  121. package/docs/behavior/localization.md +28 -10
  122. package/docs/behavior/security.md +34 -14
  123. package/docs/behavior/url-contract.md +13 -6
  124. package/package.json +54 -16
  125. package/dist/EditSurface-BPqqykro.cjs +0 -6
  126. package/dist/EditSurface-CWq35IWQ.js +0 -972
  127. package/dist/ExplorerSplit-BRY4uy6x.js +0 -1493
  128. package/dist/ExplorerSplit-CQxr6b0v.cjs +0 -1
  129. package/dist/MultiLayout-TXbet9k3.cjs +0 -1
  130. package/dist/NativeScrollBar-BsWdvkHa.js +0 -64
  131. package/dist/NativeScrollBar-UpjxjLlB.cjs +0 -1
  132. package/dist/TreeLayout-BQEgZhz9.js +0 -72
  133. package/dist/TreeLayout-C0O1OGi4.cjs +0 -1
  134. package/dist/dataRoute-DLhQfdoW.js +0 -298
  135. package/dist/dataRoute-DwYtgyt6.cjs +0 -1
  136. package/dist/index-CO-RgTml.js +0 -4912
  137. package/dist/index-DSkK8iLE.cjs +0 -15
  138. package/dist/location-BxiJRTyw.cjs +0 -1
  139. package/dist/location-perTmwct.js +0 -663
  140. package/dist/sanitizePolicy-By0tKOpZ.js +0 -98
  141. package/dist/sanitizePolicy-T5T-3vV5.cjs +0 -1
  142. package/dist/storage-DM0EvkVf.cjs +0 -1
  143. package/dist/tapScrollCircle-CRKZremf.js +0 -12
  144. package/dist/tapScrollCircle-Cbf17x8g.cjs +0 -1
  145. package/dist/useSplitPersistence-Du01PHNg.js +0 -42
  146. package/dist/useSplitPersistence-pPmE4GTT.cjs +0 -1
@@ -5,6 +5,7 @@ import { ExplorerAssetDisplay } from "../core/dataRoute.js";
5
5
  import { ExplorerPathRules } from "../core/paths.js";
6
6
  import { ExplorerLogger } from "./errors.js";
7
7
  import { HtmlSanitizerOptions } from "./sanitizer.js";
8
+ import { SanitizerLimitsInput } from "./sanitizerOptions.js";
8
9
  export type ExplorerAuthentication<P> = {
9
10
  readonly status: "signed-in";
10
11
  readonly principal: P;
@@ -57,6 +58,11 @@ export type ExplorerAssetFile = {
57
58
  readonly size: number | null;
58
59
  readonly version: string;
59
60
  readonly open: (range: ExplorerByteRange | null) => Promise<ReadableStream<Uint8Array>>;
61
+ readonly bridge?: {
62
+ readonly uri: string;
63
+ readonly storageVersion: string | null;
64
+ readonly readFailure: (error: unknown) => unknown;
65
+ };
60
66
  };
61
67
  export type ExplorerAssetRedirect = {
62
68
  readonly kind: "redirect";
@@ -70,12 +76,14 @@ export type ExplorerHostDocument = {
70
76
  readonly name: string;
71
77
  readonly htmlContent: string;
72
78
  readonly headings: readonly ExplorerHeading[];
79
+ readonly lang: string;
73
80
  readonly edit: ExplorerDocumentEdit | null;
74
81
  } | {
75
82
  readonly kind: "text";
76
83
  readonly name: string;
77
84
  readonly text: string;
78
85
  readonly truncated: boolean;
86
+ readonly lang: string;
79
87
  readonly version: string;
80
88
  } | {
81
89
  readonly kind: "image";
@@ -108,7 +116,7 @@ export type ExplorerHostEditSource = {
108
116
  readonly kind: "draft";
109
117
  readonly text: string;
110
118
  } | ExplorerGrantRequired;
111
- export type ExplorerDraft = {
119
+ export type ExplorerHostSaveDraft = {
112
120
  readonly text: string;
113
121
  readonly baseVersion: string;
114
122
  };
@@ -126,16 +134,15 @@ export type ExplorerHostPreview = {
126
134
  };
127
135
  export type ExplorerEditPorts<P> = {
128
136
  readonly source: (context: ExplorerSourceContext<P>, path: string, readPath: string) => Promise<ExplorerHostEditSource>;
129
- readonly save: (context: ExplorerSourceContext<P>, path: string, readPath: string, draft: ExplorerDraft) => Promise<ExplorerHostSaveResult>;
137
+ readonly save: (context: ExplorerSourceContext<P>, path: string, readPath: string, draft: ExplorerHostSaveDraft) => Promise<ExplorerHostSaveResult>;
130
138
  readonly preview: (context: ExplorerSourceContext<P>, path: string, readPath: string, text: string) => Promise<ExplorerHostPreview>;
131
139
  readonly revisions: (context: ExplorerSourceContext<P>, path: string, readPath: string) => Promise<readonly ExplorerRevision[]>;
132
140
  readonly revision: (context: ExplorerSourceContext<P>, path: string, readPath: string, revisionId: string) => Promise<string>;
133
141
  };
134
- export type MarkdownExplorerServerConfig<P> = {
142
+ export type ExplorerServerSharedConfig<P> = {
135
143
  readonly config: ExplorerConfig;
136
144
  readonly authenticate: (request: Request, mode: ExplorerAuthenticationMode) => Promise<ExplorerAuthentication<P>>;
137
145
  readonly principalKey: (principal: P) => string;
138
- readonly scopeSecret: string;
139
146
  readonly sources: readonly ExplorerSource<P>[];
140
147
  readonly document: (context: ExplorerSourceContext<P>, path: string, readPath: string) => Promise<ExplorerHostDocument>;
141
148
  readonly asset: (context: ExplorerSourceContext<P>, path: string, readPath: string, options: ExplorerAssetOptions) => Promise<ExplorerAssetFile | ExplorerAssetRedirect>;
@@ -148,7 +155,6 @@ export type MarkdownExplorerServerConfig<P> = {
148
155
  readonly maxEntries?: number;
149
156
  readonly maxBytes?: number;
150
157
  } | false;
151
- readonly sanitizer?: HtmlSanitizerOptions;
152
158
  readonly deferredTimeoutMs?: number;
153
159
  readonly textMaxBytes?: number;
154
160
  readonly edit?: ExplorerEditPorts<P>;
@@ -156,11 +162,36 @@ export type MarkdownExplorerServerConfig<P> = {
156
162
  readonly logger?: ExplorerLogger;
157
163
  readonly onTreeRefreshed?: (key: string) => void;
158
164
  };
165
+ export type MarkdownExplorerServerConfig<P> = ExplorerServerSharedConfig<P> & {
166
+ readonly scopeSecret: string;
167
+ readonly sanitizer?: HtmlSanitizerOptions;
168
+ };
169
+ export type ExplorerServerCoreConfig<P> = ExplorerServerSharedConfig<P> & {
170
+ readonly sanitizer?: SanitizerLimitsInput & Readonly<Record<string, unknown>>;
171
+ readonly readSettings: (request: Request) => string | undefined;
172
+ readonly assetMaxRangeBytes: number | null;
173
+ };
159
174
  export type ExplorerPageLoaderResult = ReturnType<typeof data<ExplorerPageData>>;
175
+ export type ExplorerDataPlan = {
176
+ readonly kind: "response";
177
+ readonly response: Response;
178
+ } | {
179
+ readonly kind: "file";
180
+ readonly status: 200 | 206;
181
+ readonly headers: Headers;
182
+ readonly bridge: {
183
+ readonly uri: string;
184
+ readonly storageVersion: string | null;
185
+ };
186
+ readonly range: ExplorerByteRange | null;
187
+ readonly length: number | null;
188
+ readonly fail: (error: unknown) => Response;
189
+ };
160
190
  export type MarkdownExplorerServer = {
161
191
  readonly loader: (args: LoaderFunctionArgs) => Promise<ExplorerPageLoaderResult>;
162
192
  readonly headers: HeadersFunction;
163
193
  readonly dataLoader: (args: LoaderFunctionArgs) => Promise<Response>;
164
194
  readonly dataAction: (args: ActionFunctionArgs) => Promise<Response>;
195
+ readonly planData: (args: LoaderFunctionArgs) => Promise<ExplorerDataPlan>;
165
196
  readonly forgetTree: (key: string) => void;
166
197
  };
@@ -1,7 +1,9 @@
1
+ import { ExplorerOwnUrls } from "../core/ownUrls.cjs";
1
2
  export type SanitizeJobInput = {
2
3
  readonly html: string;
3
4
  readonly iframeHosts: readonly string[];
4
5
  readonly dataPath: string;
6
+ readonly ownUrls: ExplorerOwnUrls;
5
7
  readonly maxNodes: number;
6
8
  readonly maxAttributeChars: number;
7
9
  readonly maxSanitizedChars: number;
@@ -15,3 +17,4 @@ export type SanitizeJobOutput = {
15
17
  readonly status: "error";
16
18
  readonly message: string;
17
19
  };
20
+ export declare const describeJobError: (error: unknown) => string;
@@ -1,7 +1,9 @@
1
+ import { ExplorerOwnUrls } from "../core/ownUrls.js";
1
2
  export type SanitizeJobInput = {
2
3
  readonly html: string;
3
4
  readonly iframeHosts: readonly string[];
4
5
  readonly dataPath: string;
6
+ readonly ownUrls: ExplorerOwnUrls;
5
7
  readonly maxNodes: number;
6
8
  readonly maxAttributeChars: number;
7
9
  readonly maxSanitizedChars: number;
@@ -15,3 +17,4 @@ export type SanitizeJobOutput = {
15
17
  readonly status: "error";
16
18
  readonly message: string;
17
19
  };
20
+ export declare const describeJobError: (error: unknown) => string;
@@ -1,51 +1,16 @@
1
- import { SanitizeJobInput, SanitizeJobOutput } from "./sanitizeProtocol.cjs";
2
- import { WorkerPool } from "./workerPool.cjs";
3
- export type HtmlSanitizerOptions = {
1
+ import { SanitizerLimitsInput } from "./sanitizerOptions.cjs";
2
+ import { HtmlMeasure, SanitizerCrash, SanitizerPool } from "./sanitizerService.cjs";
3
+ export type HtmlSanitizerOptions = SanitizerLimitsInput & {
4
4
  readonly workers?: number;
5
- readonly deadlineMs?: number;
6
- readonly maxHtmlBytes?: number;
7
- readonly cacheBytes?: number;
8
5
  readonly workerHeapMb?: number;
9
- readonly jobsPerScope?: number;
10
- readonly maxQueuedJobs?: number;
11
6
  };
12
7
  export type ResolvedHtmlSanitizerOptions = Required<HtmlSanitizerOptions>;
13
- export declare const SANITIZER_SCOPE_HEADROOM = 3;
14
8
  export declare const DEFAULT_SANITIZER_WORKERS = 2;
15
- export declare const defaultSanitizerJobsPerScope: (maxPanels: number, workers: number) => number;
16
- export declare const SANITIZER_QUEUED_READERS = 4;
17
9
  export declare const SANITIZER_YOUNG_GENERATION_MB = 32;
18
- export declare const DEFAULT_SANITIZER_WORKER_HEAP_MB = 512;
19
- export declare const SANITIZER_WORKER_BASE_HEAP_MB = 64;
20
- export declare const SANITIZER_HEAP_BYTES_PER_NODE = 4096;
21
- export declare const SANITIZER_HEAP_BYTES_PER_HTML_BYTE = 32;
22
- export declare const MIN_HTML_NODE_BUDGET = 4096;
23
- export declare const SANITIZED_HTML_CHARS_PER_HTML_BYTE = 4;
24
10
  export declare const htmlNodeBudget: ({ workerHeapMb, maxHtmlBytes }: Pick<ResolvedHtmlSanitizerOptions, "workerHeapMb" | "maxHtmlBytes">) => number;
25
- export declare const htmlAttributeCharBudget: ({ maxHtmlBytes }: Pick<ResolvedHtmlSanitizerOptions, "maxHtmlBytes">) => number;
26
- export declare const sanitizedHtmlLimit: ({ maxHtmlBytes }: Pick<ResolvedHtmlSanitizerOptions, "maxHtmlBytes">) => number;
27
11
  export declare const defaultHtmlSanitizerOptions: (maxPanels: number) => ResolvedHtmlSanitizerOptions;
28
- export declare const SANITIZED_HTML_CACHE_ENTRIES = 1024;
29
- export type SanitizedHtml = {
30
- readonly status: "sanitized";
31
- readonly html: string;
32
- } | {
33
- readonly status: "rejected";
34
- readonly reason: "too-large" | "failed";
35
- readonly cause: Error | null;
36
- };
37
- export type SanitizeRequest = {
38
- readonly scope: string;
39
- readonly signal: AbortSignal;
40
- };
41
- export type HtmlSanitizerService = (html: string, request: SanitizeRequest) => Promise<SanitizedHtml>;
42
- export type SanitizerPool = WorkerPool<SanitizeJobInput, SanitizeJobOutput>;
43
12
  export declare const resolveHtmlSanitizerOptions: (value: unknown, maxPanels: number) => ResolvedHtmlSanitizerOptions;
44
13
  export declare const sanitizerWorkerUrl: () => URL;
45
14
  export declare const sharedSanitizerPool: (url: URL, options: Pick<ResolvedHtmlSanitizerOptions, "workers" | "deadlineMs" | "workerHeapMb" | "jobsPerScope" | "maxQueuedJobs">) => SanitizerPool;
46
- export declare const createHtmlSanitizerService: ({ iframeHosts, dataPath, options, pool }: {
47
- readonly iframeHosts: readonly string[];
48
- readonly dataPath: string;
49
- readonly options: ResolvedHtmlSanitizerOptions;
50
- readonly pool: SanitizerPool;
51
- }) => HtmlSanitizerService;
15
+ export declare const nodeHtmlMeasure: (html: string) => HtmlMeasure;
16
+ export declare const nodeCrashClassifier: (workerHeapMb: number) => (error: unknown) => SanitizerCrash | null;
@@ -1,51 +1,16 @@
1
- import { SanitizeJobInput, SanitizeJobOutput } from "./sanitizeProtocol.js";
2
- import { WorkerPool } from "./workerPool.js";
3
- export type HtmlSanitizerOptions = {
1
+ import { SanitizerLimitsInput } from "./sanitizerOptions.js";
2
+ import { HtmlMeasure, SanitizerCrash, SanitizerPool } from "./sanitizerService.js";
3
+ export type HtmlSanitizerOptions = SanitizerLimitsInput & {
4
4
  readonly workers?: number;
5
- readonly deadlineMs?: number;
6
- readonly maxHtmlBytes?: number;
7
- readonly cacheBytes?: number;
8
5
  readonly workerHeapMb?: number;
9
- readonly jobsPerScope?: number;
10
- readonly maxQueuedJobs?: number;
11
6
  };
12
7
  export type ResolvedHtmlSanitizerOptions = Required<HtmlSanitizerOptions>;
13
- export declare const SANITIZER_SCOPE_HEADROOM = 3;
14
8
  export declare const DEFAULT_SANITIZER_WORKERS = 2;
15
- export declare const defaultSanitizerJobsPerScope: (maxPanels: number, workers: number) => number;
16
- export declare const SANITIZER_QUEUED_READERS = 4;
17
9
  export declare const SANITIZER_YOUNG_GENERATION_MB = 32;
18
- export declare const DEFAULT_SANITIZER_WORKER_HEAP_MB = 512;
19
- export declare const SANITIZER_WORKER_BASE_HEAP_MB = 64;
20
- export declare const SANITIZER_HEAP_BYTES_PER_NODE = 4096;
21
- export declare const SANITIZER_HEAP_BYTES_PER_HTML_BYTE = 32;
22
- export declare const MIN_HTML_NODE_BUDGET = 4096;
23
- export declare const SANITIZED_HTML_CHARS_PER_HTML_BYTE = 4;
24
10
  export declare const htmlNodeBudget: ({ workerHeapMb, maxHtmlBytes }: Pick<ResolvedHtmlSanitizerOptions, "workerHeapMb" | "maxHtmlBytes">) => number;
25
- export declare const htmlAttributeCharBudget: ({ maxHtmlBytes }: Pick<ResolvedHtmlSanitizerOptions, "maxHtmlBytes">) => number;
26
- export declare const sanitizedHtmlLimit: ({ maxHtmlBytes }: Pick<ResolvedHtmlSanitizerOptions, "maxHtmlBytes">) => number;
27
11
  export declare const defaultHtmlSanitizerOptions: (maxPanels: number) => ResolvedHtmlSanitizerOptions;
28
- export declare const SANITIZED_HTML_CACHE_ENTRIES = 1024;
29
- export type SanitizedHtml = {
30
- readonly status: "sanitized";
31
- readonly html: string;
32
- } | {
33
- readonly status: "rejected";
34
- readonly reason: "too-large" | "failed";
35
- readonly cause: Error | null;
36
- };
37
- export type SanitizeRequest = {
38
- readonly scope: string;
39
- readonly signal: AbortSignal;
40
- };
41
- export type HtmlSanitizerService = (html: string, request: SanitizeRequest) => Promise<SanitizedHtml>;
42
- export type SanitizerPool = WorkerPool<SanitizeJobInput, SanitizeJobOutput>;
43
12
  export declare const resolveHtmlSanitizerOptions: (value: unknown, maxPanels: number) => ResolvedHtmlSanitizerOptions;
44
13
  export declare const sanitizerWorkerUrl: () => URL;
45
14
  export declare const sharedSanitizerPool: (url: URL, options: Pick<ResolvedHtmlSanitizerOptions, "workers" | "deadlineMs" | "workerHeapMb" | "jobsPerScope" | "maxQueuedJobs">) => SanitizerPool;
46
- export declare const createHtmlSanitizerService: ({ iframeHosts, dataPath, options, pool }: {
47
- readonly iframeHosts: readonly string[];
48
- readonly dataPath: string;
49
- readonly options: ResolvedHtmlSanitizerOptions;
50
- readonly pool: SanitizerPool;
51
- }) => HtmlSanitizerService;
15
+ export declare const nodeHtmlMeasure: (html: string) => HtmlMeasure;
16
+ export declare const nodeCrashClassifier: (workerHeapMb: number) => (error: unknown) => SanitizerCrash | null;
@@ -0,0 +1,24 @@
1
+ export type SanitizerLimitsInput = {
2
+ readonly deadlineMs?: number;
3
+ readonly maxHtmlBytes?: number;
4
+ readonly cacheBytes?: number;
5
+ readonly jobsPerScope?: number;
6
+ readonly maxQueuedJobs?: number;
7
+ };
8
+ export type SanitizerLimits = Required<SanitizerLimitsInput>;
9
+ export declare const DEFAULT_SANITIZER_DEADLINE_MS = 30000;
10
+ export declare const DEFAULT_SANITIZER_MAX_HTML_BYTES: number;
11
+ export declare const DEFAULT_SANITIZER_CACHE_BYTES: number;
12
+ export declare const MAX_HTML_BYTES: number;
13
+ export declare const SANITIZER_SCOPE_HEADROOM = 3;
14
+ export declare const defaultSanitizerJobsPerScope: (maxPanels: number, workers: number) => number;
15
+ export declare const SANITIZER_QUEUED_READERS = 4;
16
+ export declare const DEFAULT_SANITIZER_WORKER_HEAP_MB = 512;
17
+ export declare const SANITIZER_WORKER_BASE_HEAP_MB = 64;
18
+ export declare const SANITIZER_HEAP_BYTES_PER_NODE = 4096;
19
+ export declare const SANITIZER_HEAP_BYTES_PER_HTML_BYTE = 32;
20
+ export declare const MIN_HTML_NODE_BUDGET = 4096;
21
+ export declare const htmlNodeBudgetOf: (maxHtmlBytes: number, workerHeapMb: number) => number;
22
+ export declare const readLimit: (name: string, value: unknown, defaultValue: number, max: number) => number;
23
+ export declare const assertAdmissionCoversPanels: (limits: Pick<SanitizerLimits, "jobsPerScope" | "maxQueuedJobs">, maxPanels: number) => void;
24
+ export declare const resolveBrowserSanitizerLimits: (value: unknown, maxPanels: number) => SanitizerLimits;
@@ -0,0 +1,24 @@
1
+ export type SanitizerLimitsInput = {
2
+ readonly deadlineMs?: number;
3
+ readonly maxHtmlBytes?: number;
4
+ readonly cacheBytes?: number;
5
+ readonly jobsPerScope?: number;
6
+ readonly maxQueuedJobs?: number;
7
+ };
8
+ export type SanitizerLimits = Required<SanitizerLimitsInput>;
9
+ export declare const DEFAULT_SANITIZER_DEADLINE_MS = 30000;
10
+ export declare const DEFAULT_SANITIZER_MAX_HTML_BYTES: number;
11
+ export declare const DEFAULT_SANITIZER_CACHE_BYTES: number;
12
+ export declare const MAX_HTML_BYTES: number;
13
+ export declare const SANITIZER_SCOPE_HEADROOM = 3;
14
+ export declare const defaultSanitizerJobsPerScope: (maxPanels: number, workers: number) => number;
15
+ export declare const SANITIZER_QUEUED_READERS = 4;
16
+ export declare const DEFAULT_SANITIZER_WORKER_HEAP_MB = 512;
17
+ export declare const SANITIZER_WORKER_BASE_HEAP_MB = 64;
18
+ export declare const SANITIZER_HEAP_BYTES_PER_NODE = 4096;
19
+ export declare const SANITIZER_HEAP_BYTES_PER_HTML_BYTE = 32;
20
+ export declare const MIN_HTML_NODE_BUDGET = 4096;
21
+ export declare const htmlNodeBudgetOf: (maxHtmlBytes: number, workerHeapMb: number) => number;
22
+ export declare const readLimit: (name: string, value: unknown, defaultValue: number, max: number) => number;
23
+ export declare const assertAdmissionCoversPanels: (limits: Pick<SanitizerLimits, "jobsPerScope" | "maxQueuedJobs">, maxPanels: number) => void;
24
+ export declare const resolveBrowserSanitizerLimits: (value: unknown, maxPanels: number) => SanitizerLimits;
@@ -0,0 +1,41 @@
1
+ import { ExplorerOwnUrls } from "../core/ownUrls.cjs";
2
+ import { SanitizeJobInput, SanitizeJobOutput } from "./sanitizeProtocol.cjs";
3
+ import { SanitizerLimits } from "./sanitizerOptions.cjs";
4
+ import { WorkerPool } from "./workerJobs.cjs";
5
+ export declare const SANITIZED_HTML_CHARS_PER_HTML_BYTE = 4;
6
+ export declare const htmlAttributeCharBudget: ({ maxHtmlBytes }: Pick<SanitizerLimits, "maxHtmlBytes">) => number;
7
+ export declare const sanitizedHtmlLimit: ({ maxHtmlBytes }: Pick<SanitizerLimits, "maxHtmlBytes">) => number;
8
+ export declare const SANITIZED_HTML_CACHE_ENTRIES = 1024;
9
+ export type SanitizedHtml = {
10
+ readonly status: "sanitized";
11
+ readonly html: string;
12
+ } | {
13
+ readonly status: "rejected";
14
+ readonly reason: "too-large" | "failed";
15
+ readonly cause: Error | null;
16
+ };
17
+ export type SanitizeRequest = {
18
+ readonly scope: string;
19
+ readonly signal: AbortSignal;
20
+ };
21
+ export type HtmlSanitizerService = (html: string, request: SanitizeRequest) => Promise<SanitizedHtml>;
22
+ export type SanitizerPool = WorkerPool<SanitizeJobInput, SanitizeJobOutput>;
23
+ export type HtmlMeasure = {
24
+ readonly utf8Bytes: number;
25
+ readonly hash: string;
26
+ };
27
+ export type SanitizerCrash = {
28
+ readonly reason: "too-large";
29
+ readonly message: string;
30
+ };
31
+ export type HtmlSanitizerServiceSettings = {
32
+ readonly iframeHosts: readonly string[];
33
+ readonly dataPath: string;
34
+ readonly ownUrls: ExplorerOwnUrls;
35
+ readonly limits: SanitizerLimits;
36
+ readonly nodeBudget: number;
37
+ readonly measureHtml: (html: string) => HtmlMeasure | Promise<HtmlMeasure>;
38
+ readonly classifyCrash: (error: unknown) => SanitizerCrash | null;
39
+ readonly pool: SanitizerPool;
40
+ };
41
+ export declare const createHtmlSanitizerService: ({ iframeHosts, dataPath, ownUrls, limits, nodeBudget, measureHtml, classifyCrash, pool }: HtmlSanitizerServiceSettings) => HtmlSanitizerService;
@@ -0,0 +1,41 @@
1
+ import { ExplorerOwnUrls } from "../core/ownUrls.js";
2
+ import { SanitizeJobInput, SanitizeJobOutput } from "./sanitizeProtocol.js";
3
+ import { SanitizerLimits } from "./sanitizerOptions.js";
4
+ import { WorkerPool } from "./workerJobs.js";
5
+ export declare const SANITIZED_HTML_CHARS_PER_HTML_BYTE = 4;
6
+ export declare const htmlAttributeCharBudget: ({ maxHtmlBytes }: Pick<SanitizerLimits, "maxHtmlBytes">) => number;
7
+ export declare const sanitizedHtmlLimit: ({ maxHtmlBytes }: Pick<SanitizerLimits, "maxHtmlBytes">) => number;
8
+ export declare const SANITIZED_HTML_CACHE_ENTRIES = 1024;
9
+ export type SanitizedHtml = {
10
+ readonly status: "sanitized";
11
+ readonly html: string;
12
+ } | {
13
+ readonly status: "rejected";
14
+ readonly reason: "too-large" | "failed";
15
+ readonly cause: Error | null;
16
+ };
17
+ export type SanitizeRequest = {
18
+ readonly scope: string;
19
+ readonly signal: AbortSignal;
20
+ };
21
+ export type HtmlSanitizerService = (html: string, request: SanitizeRequest) => Promise<SanitizedHtml>;
22
+ export type SanitizerPool = WorkerPool<SanitizeJobInput, SanitizeJobOutput>;
23
+ export type HtmlMeasure = {
24
+ readonly utf8Bytes: number;
25
+ readonly hash: string;
26
+ };
27
+ export type SanitizerCrash = {
28
+ readonly reason: "too-large";
29
+ readonly message: string;
30
+ };
31
+ export type HtmlSanitizerServiceSettings = {
32
+ readonly iframeHosts: readonly string[];
33
+ readonly dataPath: string;
34
+ readonly ownUrls: ExplorerOwnUrls;
35
+ readonly limits: SanitizerLimits;
36
+ readonly nodeBudget: number;
37
+ readonly measureHtml: (html: string) => HtmlMeasure | Promise<HtmlMeasure>;
38
+ readonly classifyCrash: (error: unknown) => SanitizerCrash | null;
39
+ readonly pool: SanitizerPool;
40
+ };
41
+ export declare const createHtmlSanitizerService: ({ iframeHosts, dataPath, ownUrls, limits, nodeBudget, measureHtml, classifyCrash, pool }: HtmlSanitizerServiceSettings) => HtmlSanitizerService;
@@ -1,15 +1,3 @@
1
- export type WorkerHeapLimits = {
2
- readonly maxOldGenerationSizeMb: number;
3
- readonly maxYoungGenerationSizeMb: number;
4
- };
5
- export type WorkerPoolOptions = {
6
- readonly url: URL;
7
- readonly size: number;
8
- readonly deadlineMs: number;
9
- readonly jobsPerScope: number;
10
- readonly maxQueuedJobs: number;
11
- readonly heapLimits: WorkerHeapLimits;
12
- };
13
1
  export type WorkerJobTicket = {
14
2
  readonly scope: string;
15
3
  readonly signal: AbortSignal;
@@ -35,8 +23,4 @@ export type WorkerPool<I, O> = {
35
23
  readonly run: (input: I, ticket: WorkerJobTicket) => Promise<WorkerJobResult<O>>;
36
24
  readonly workers: () => number;
37
25
  };
38
- export declare const WORKER_READY_MESSAGE: Readonly<{
39
- ready: true;
40
- }>;
41
26
  export declare const jobsRunningPerScope: (size: number) => number;
42
- export declare const createWorkerPool: <I, O>({ url, size, deadlineMs, jobsPerScope, maxQueuedJobs, heapLimits }: WorkerPoolOptions) => WorkerPool<I, O>;
@@ -1,15 +1,3 @@
1
- export type WorkerHeapLimits = {
2
- readonly maxOldGenerationSizeMb: number;
3
- readonly maxYoungGenerationSizeMb: number;
4
- };
5
- export type WorkerPoolOptions = {
6
- readonly url: URL;
7
- readonly size: number;
8
- readonly deadlineMs: number;
9
- readonly jobsPerScope: number;
10
- readonly maxQueuedJobs: number;
11
- readonly heapLimits: WorkerHeapLimits;
12
- };
13
1
  export type WorkerJobTicket = {
14
2
  readonly scope: string;
15
3
  readonly signal: AbortSignal;
@@ -35,8 +23,4 @@ export type WorkerPool<I, O> = {
35
23
  readonly run: (input: I, ticket: WorkerJobTicket) => Promise<WorkerJobResult<O>>;
36
24
  readonly workers: () => number;
37
25
  };
38
- export declare const WORKER_READY_MESSAGE: Readonly<{
39
- ready: true;
40
- }>;
41
26
  export declare const jobsRunningPerScope: (size: number) => number;
42
- export declare const createWorkerPool: <I, O>({ url, size, deadlineMs, jobsPerScope, maxQueuedJobs, heapLimits }: WorkerPoolOptions) => WorkerPool<I, O>;