@pretextbook/import 0.6.0 → 0.8.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/dist/convert-worker.cjs +1 -0
- package/dist/convert-worker.js +29 -0
- package/dist/import-mode-BCGuSwkM.js +112 -0
- package/dist/import-mode-D1gOJw3N.cjs +3 -0
- package/dist/import.css +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +240 -156
- package/dist/lib/clean/latex-preamble.d.ts +21 -4
- package/dist/react/import-wizard.d.ts +22 -4
- package/dist/react/index.d.ts +2 -0
- package/dist/react/processing-panel.d.ts +6 -0
- package/dist/react.cjs +2 -2
- package/dist/react.js +498 -409
- package/dist/{import-mode-C0KIll3S.js → upload-BmErkg8I.js} +2382 -2265
- package/dist/upload-BtS22hIH.cjs +135 -0
- package/dist/worker/convert-worker.d.ts +1 -0
- package/dist/worker/protocol.d.ts +30 -0
- package/dist/worker/worker-engine.d.ts +52 -0
- package/package.json +7 -2
- package/dist/import-mode-Bu7Pi9k4.cjs +0 -135
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ImportProjectOptions } from '../lib/upload';
|
|
2
|
+
import { ImportedProjectResult } from '../lib/types';
|
|
3
|
+
/** Sent to the worker to start a conversion. */
|
|
4
|
+
export interface ConvertRequest {
|
|
5
|
+
type: "convert";
|
|
6
|
+
/** Correlates the reply, so a stale run's messages can be ignored. */
|
|
7
|
+
requestId: string;
|
|
8
|
+
files: Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Binary assets, sent as transferables. Carried here rather than inside
|
|
11
|
+
* `options` so the buffers can be listed in the `postMessage` transfer list
|
|
12
|
+
* instead of being structured-cloned.
|
|
13
|
+
*/
|
|
14
|
+
assets: Record<string, Uint8Array>;
|
|
15
|
+
/** Everything except `assets`, which travels in its own field above. */
|
|
16
|
+
options: Omit<ImportProjectOptions, "assets">;
|
|
17
|
+
}
|
|
18
|
+
export type WorkerRequest = ConvertRequest;
|
|
19
|
+
export interface ResultResponse {
|
|
20
|
+
type: "result";
|
|
21
|
+
requestId: string;
|
|
22
|
+
result: ImportedProjectResult;
|
|
23
|
+
}
|
|
24
|
+
/** A throw that escaped the pipeline — distinct from a `pretextError` result. */
|
|
25
|
+
export interface ErrorResponse {
|
|
26
|
+
type: "error";
|
|
27
|
+
requestId: string;
|
|
28
|
+
message: string;
|
|
29
|
+
}
|
|
30
|
+
export type WorkerResponse = ResultResponse | ErrorResponse;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ImportProjectOptions } from '../lib/upload';
|
|
2
|
+
import { ImportEngine } from '../react/import-wizard';
|
|
3
|
+
import { ImportedProjectResult } from '../lib/types';
|
|
4
|
+
import { WorkerRequest, WorkerResponse } from './protocol';
|
|
5
|
+
/** The minimum of the `Worker` API this engine uses. */
|
|
6
|
+
export interface ConversionWorker {
|
|
7
|
+
postMessage(message: WorkerRequest, transfer?: Transferable[]): void;
|
|
8
|
+
terminate(): void;
|
|
9
|
+
addEventListener(type: "message", listener: (event: MessageEvent<WorkerResponse>) => void): void;
|
|
10
|
+
addEventListener(type: "error", listener: (event: unknown) => void): void;
|
|
11
|
+
}
|
|
12
|
+
export interface WorkerEngineOptions {
|
|
13
|
+
/** Builds a fresh worker. Called once per conversion. */
|
|
14
|
+
createWorker: () => ConversionWorker;
|
|
15
|
+
id?: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
acceptExtensions?: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One conversion in flight. `cancel` terminates the worker outright — the
|
|
22
|
+
* pipeline has no yield points, so a cooperative cancellation flag would never
|
|
23
|
+
* be read; killing the thread is the only way to stop it mid-grind.
|
|
24
|
+
*/
|
|
25
|
+
export interface RunningConversion {
|
|
26
|
+
result: Promise<ImportedProjectResult>;
|
|
27
|
+
cancel: () => void;
|
|
28
|
+
}
|
|
29
|
+
/** Raised on the `result` promise when `cancel()` is called. */
|
|
30
|
+
export declare class ConversionCancelledError extends Error {
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Run one conversion on a freshly spawned worker.
|
|
35
|
+
*
|
|
36
|
+
* A worker per conversion rather than a long-lived pooled one: cancellation is
|
|
37
|
+
* `terminate()`, which destroys the thread, and the pipeline holds no state
|
|
38
|
+
* worth keeping warm between runs. Spawn cost is milliseconds against a
|
|
39
|
+
* multi-second conversion.
|
|
40
|
+
*/
|
|
41
|
+
export declare function runConversionInWorker(createWorker: () => ConversionWorker, files: Record<string, string>, options?: ImportProjectOptions): RunningConversion;
|
|
42
|
+
/**
|
|
43
|
+
* Build an `ImportEngine` that converts on a worker.
|
|
44
|
+
*
|
|
45
|
+
* `prepare` stays on the main thread: unpacking is real async I/O that already
|
|
46
|
+
* yields, and it is cheap next to the conversion. Only `convertPrepared` and
|
|
47
|
+
* `convertFile` — the multi-second synchronous grind — go off-thread.
|
|
48
|
+
*
|
|
49
|
+
* The returned engine is stateful: it remembers the run in flight so `cancel`
|
|
50
|
+
* can terminate it. One engine instance therefore drives one wizard.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createWorkerEngine(options: WorkerEngineOptions): ImportEngine;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pretextbook/import",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Shared import helpers for converting LaTeX/Markdown/PreTeXt into PreTeXt for VS Code and web apps",
|
|
5
5
|
"author": "Oscar Levin",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,12 @@
|
|
|
30
30
|
"require": "./dist/react.cjs",
|
|
31
31
|
"default": "./dist/react.js"
|
|
32
32
|
},
|
|
33
|
-
"./react.css": "./dist/import.css"
|
|
33
|
+
"./react.css": "./dist/import.css",
|
|
34
|
+
"./worker": {
|
|
35
|
+
"types": "./dist/worker/convert-worker.d.ts",
|
|
36
|
+
"import": "./dist/convert-worker.js",
|
|
37
|
+
"default": "./dist/convert-worker.js"
|
|
38
|
+
}
|
|
34
39
|
},
|
|
35
40
|
"sideEffects": [
|
|
36
41
|
"*.css",
|