@laminapdf/sdk 0.0.0-stage → 0.2.0-alpha.2
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/README.md +208 -2
- package/dist/api.d.ts +23 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +11 -0
- package/dist/api.js.map +1 -0
- package/dist/builder.d.ts +319 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +540 -0
- package/dist/builder.js.map +1 -0
- package/dist/defined.d.ts +5 -0
- package/dist/defined.d.ts.map +1 -0
- package/dist/defined.js +7 -0
- package/dist/defined.js.map +1 -0
- package/dist/document.d.ts +241 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +427 -0
- package/dist/document.js.map +1 -0
- package/dist/entry/node.d.ts +30 -0
- package/dist/entry/node.d.ts.map +1 -0
- package/dist/entry/node.js +37 -0
- package/dist/entry/node.js.map +1 -0
- package/dist/entry/workerd.d.ts +30 -0
- package/dist/entry/workerd.d.ts.map +1 -0
- package/dist/entry/workerd.js +37 -0
- package/dist/entry/workerd.js.map +1 -0
- package/dist/errors.d.ts +102 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +137 -0
- package/dist/errors.js.map +1 -0
- package/dist/explain.d.ts +20 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +14 -0
- package/dist/explain.js.map +1 -0
- package/dist/font.d.ts +66 -0
- package/dist/font.d.ts.map +1 -0
- package/dist/font.js +103 -0
- package/dist/font.js.map +1 -0
- package/dist/generated/builder-enums.d.ts +29 -0
- package/dist/generated/builder-enums.d.ts.map +1 -0
- package/dist/generated/builder-enums.js +80 -0
- package/dist/generated/builder-enums.js.map +1 -0
- package/dist/generated/codes.d.ts +97 -0
- package/dist/generated/codes.d.ts.map +1 -0
- package/dist/generated/codes.js +453 -0
- package/dist/generated/codes.js.map +1 -0
- package/dist/generated/explain.d.ts +6 -0
- package/dist/generated/explain.d.ts.map +1 -0
- package/dist/generated/explain.js +138 -0
- package/dist/generated/explain.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +80 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +127 -0
- package/dist/init.js.map +1 -0
- package/dist/loader/fetch.d.ts +3 -0
- package/dist/loader/fetch.d.ts.map +1 -0
- package/dist/loader/fetch.js +2 -0
- package/dist/loader/fetch.js.map +1 -0
- package/dist/loader/node.d.ts +3 -0
- package/dist/loader/node.d.ts.map +1 -0
- package/dist/loader/node.js +9 -0
- package/dist/loader/node.js.map +1 -0
- package/dist/loader/workerd.d.ts +3 -0
- package/dist/loader/workerd.d.ts.map +1 -0
- package/dist/loader/workerd.js +15 -0
- package/dist/loader/workerd.js.map +1 -0
- package/dist/matrix.d.ts +16 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +36 -0
- package/dist/matrix.js.map +1 -0
- package/dist/path.d.ts +34 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +49 -0
- package/dist/path.js.map +1 -0
- package/dist/source/http.d.ts +36 -0
- package/dist/source/http.d.ts.map +1 -0
- package/dist/source/http.js +211 -0
- package/dist/source/http.js.map +1 -0
- package/dist/source/range.d.ts +70 -0
- package/dist/source/range.d.ts.map +1 -0
- package/dist/source/range.js +96 -0
- package/dist/source/range.js.map +1 -0
- package/dist/text.d.ts +90 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +127 -0
- package/dist/text.js.map +1 -0
- package/dist/transaction.d.ts +36 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +47 -0
- package/dist/transaction.js.map +1 -0
- package/dist/types.d.ts +79 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/worker/client.d.ts +87 -0
- package/dist/worker/client.d.ts.map +1 -0
- package/dist/worker/client.js +405 -0
- package/dist/worker/client.js.map +1 -0
- package/dist/worker/emitter.d.ts +12 -0
- package/dist/worker/emitter.d.ts.map +1 -0
- package/dist/worker/emitter.js +34 -0
- package/dist/worker/emitter.js.map +1 -0
- package/dist/worker/entry.d.ts +2 -0
- package/dist/worker/entry.d.ts.map +1 -0
- package/dist/worker/entry.js +4 -0
- package/dist/worker/entry.js.map +1 -0
- package/dist/worker/index.d.ts +7 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +4 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/protocol.d.ts +82 -0
- package/dist/worker/protocol.d.ts.map +1 -0
- package/dist/worker/protocol.js +11 -0
- package/dist/worker/protocol.js.map +1 -0
- package/dist/worker/server.d.ts +51 -0
- package/dist/worker/server.d.ts.map +1 -0
- package/dist/worker/server.js +460 -0
- package/dist/worker/server.js.map +1 -0
- package/dist/worker/support.d.ts +39 -0
- package/dist/worker/support.d.ts.map +1 -0
- package/dist/worker/support.js +25 -0
- package/dist/worker/support.js.map +1 -0
- package/dist/worker/transfer.d.ts +3 -0
- package/dist/worker/transfer.d.ts.map +1 -0
- package/dist/worker/transfer.js +13 -0
- package/dist/worker/transfer.js.map +1 -0
- package/dist/worker/types.d.ts +43 -0
- package/dist/worker/types.d.ts.map +1 -0
- package/dist/worker/types.js +2 -0
- package/dist/worker/types.js.map +1 -0
- package/package.json +91 -3
- package/schemas/error.schema.json +288 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { HttpRangeOptions } from "../source/http.js";
|
|
2
|
+
import type { RangeOptions } from "../source/range.js";
|
|
3
|
+
import type { OpenOptions } from "../types.js";
|
|
4
|
+
import type { CallOptions, RemoteDocument, RequestOptions } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* `openUrl`'s options besides `OpenOptions`: `httpRangeSource`'s without a custom `fetch` (a
|
|
7
|
+
* function can't reach the worker), and `openRange`'s (`budget`, `readahead`, `maxRounds`).
|
|
8
|
+
* `signal` is the call's (`CallOptions`), and cancels the fetches in flight too.
|
|
9
|
+
*/
|
|
10
|
+
export type RemoteHttpOptions = Omit<HttpRangeOptions, "fetch" | "signal"> & Omit<RangeOptions, "signal">;
|
|
11
|
+
/**
|
|
12
|
+
* Where the worker loads a WebAssembly module from: what can be sent to a worker. A string or
|
|
13
|
+
* `URL` is resolved against the page (not the worker file) before it is sent. A `Response`
|
|
14
|
+
* can't cross: pass its bytes, or a `WebAssembly.Module`.
|
|
15
|
+
*/
|
|
16
|
+
export type WorkerWasmSource = string | URL | ArrayBuffer | ArrayBufferView | WebAssembly.Module;
|
|
17
|
+
/** `init()`'s options, with sources the worker can receive. */
|
|
18
|
+
export interface WorkerInitOptions {
|
|
19
|
+
readonly module?: WorkerWasmSource;
|
|
20
|
+
readonly text?: boolean | WorkerWasmSource;
|
|
21
|
+
readonly extract?: boolean | WorkerWasmSource;
|
|
22
|
+
}
|
|
23
|
+
/** `connect()`'s options: the worker to start, a signal to stop connecting, the WebAssembly to load, and what to do with late answers. */
|
|
24
|
+
export interface ConnectOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The worker to use, or a function that makes one (needed for `restart()`). Omitted, the
|
|
27
|
+
* package's own worker file. Pass one for a CSP that forbids the bundled URL, or to serve the
|
|
28
|
+
* worker yourself (from the same `@laminapdf/sdk` build: the handshake checks).
|
|
29
|
+
*/
|
|
30
|
+
readonly worker?: Worker | (() => Worker);
|
|
31
|
+
/** Aborts connecting. */
|
|
32
|
+
readonly signal?: AbortSignal;
|
|
33
|
+
/** What the worker passes to `init()`: where the WebAssembly comes from, and options. */
|
|
34
|
+
readonly init?: WorkerWasmSource | WorkerInitOptions;
|
|
35
|
+
/**
|
|
36
|
+
* Called with each answer that arrives for a call already rejected (aborted, or after a crash
|
|
37
|
+
* or terminate), which nobody will read. The default closes the ImageBitmaps in it (at the top
|
|
38
|
+
* level or one level down), so a cancelled render's bitmap is freed, never painted.
|
|
39
|
+
*/
|
|
40
|
+
readonly onDiscard?: (value: unknown) => void;
|
|
41
|
+
}
|
|
42
|
+
type EventListener = (name: string, data: unknown) => void;
|
|
43
|
+
type CrashListener = (reason: string) => void;
|
|
44
|
+
/** Starts the worker and waits for its handshake. */
|
|
45
|
+
export declare function connect(options?: ConnectOptions): Promise<WorkerClient>;
|
|
46
|
+
/** A connection to one Lamina PDF worker. */
|
|
47
|
+
export declare class WorkerClient {
|
|
48
|
+
#private;
|
|
49
|
+
/** @internal Use {@link connect}. */
|
|
50
|
+
constructor(options: ConnectOptions);
|
|
51
|
+
/** @internal Starts a worker and checks its handshake. */
|
|
52
|
+
start(signal?: AbortSignal): Promise<void>;
|
|
53
|
+
/** Listens for the worker crashing (`reason`: `error`, `messageerror` or `trap`; not `terminate()`). */
|
|
54
|
+
on(event: "crashed", listener: CrashListener): () => void;
|
|
55
|
+
/** Listens for an extension's events (`emit()` in the worker). */
|
|
56
|
+
on(event: "event", listener: EventListener): () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Calls an extension method in the worker (for packages that extend it with `serve(…)`, such
|
|
59
|
+
* as `@laminapdf/viewer`). Same cancellation, transfers and errors as every other call.
|
|
60
|
+
*/
|
|
61
|
+
request(method: string, params: readonly unknown[], options?: RequestOptions): Promise<unknown>;
|
|
62
|
+
/** Ends the worker; pending calls reject with `worker-crashed` (no `crashed` event). */
|
|
63
|
+
terminate(): void;
|
|
64
|
+
/** Starts a new worker (after a crash, or to reset); handles of the old one are `disposed`. */
|
|
65
|
+
restart(signal?: AbortSignal): Promise<void>;
|
|
66
|
+
/** @internal The current worker generation (handles record it). */
|
|
67
|
+
get generation(): number;
|
|
68
|
+
/**
|
|
69
|
+
* @internal Posts a call and waits for its answer. `generation`, for a handle, is the one it
|
|
70
|
+
* was made in. Calls made while a worker starts wait for its handshake.
|
|
71
|
+
*/
|
|
72
|
+
call(handle: number, method: string, params: readonly unknown[], options?: CallOptions, generation?: number): Promise<unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* Opens `bytes` in the worker. They are copied unless `transfer: true` (then the caller's
|
|
75
|
+
* buffer is detached). Opening is one synchronous call there: `signal` drops it if it hasn't
|
|
76
|
+
* started, but can't stop it midway (`terminate()` is the hard stop).
|
|
77
|
+
*/
|
|
78
|
+
open(bytes: Uint8Array | ArrayBuffer, options?: OpenOptions & CallOptions): Promise<RemoteDocument>;
|
|
79
|
+
/** Opens a remote file by HTTP range requests (L2c): the worker fetches what each call needs. */
|
|
80
|
+
openUrl(url: string, options?: OpenOptions & RemoteHttpOptions & CallOptions): Promise<RemoteDocument>;
|
|
81
|
+
/** Loads the text module in the worker (`loadText()`). */
|
|
82
|
+
loadText(options?: CallOptions): Promise<void>;
|
|
83
|
+
/** Loads the extract module in the worker (`loadExtract()`), for `page.text()`. */
|
|
84
|
+
loadExtract(options?: CallOptions): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
export {};
|
|
87
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/worker/client.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,aAAa,CAAC;AAczD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK9E;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;AAE1G;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,GAAG,GAAG,WAAW,GAAG,eAAe,G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OAAO,EAAE,QAAQ,EAAE,aAAa,GAAG,MAAM,IAAI,CAAC;IAUxD;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,OAAO,EAAE,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAElG;IAED,wFAAwF;IACxF,SAAS,IAAI,IAAI,CAEhB;IAED,+FAA+F;IACzF,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjD;IAED,mEAAmE;IACnE,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;OAGG;IACG,IAAI,CACR,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,OAAO,EAAE,EAC1B,OAAO,GAAE,WAAgB,EACzB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC,CA2DlB;IAED;;;;OAIG;IACG,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,EAAE,OAAO,GAAE,WAAW,GAAG,WAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CAI5G;IAED,iGAAiG;IAC3F,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,WAAW,GAAG,iBAAiB,GAAG,WAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CAI/G;IAED,0DAA0D;IACpD,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnD;IAED,mFAAmF;IAC7E,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtD;CAoBF"}
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// The page side of `@laminapdf/sdk/worker` (L2a): `connect()` starts the worker (the literal
|
|
2
|
+
// `new Worker(new URL(…, import.meta.url))` lets Vite and webpack bundle it), checks the
|
|
3
|
+
// handshake, and returns a WorkerClient whose documents and pages are remote handles: proxies
|
|
4
|
+
// whose methods post typed calls. Calls get monotonically increasing IDs; an aborted call is
|
|
5
|
+
// rejected at once (`cancelled`, with the signal's reason as `cause`) and a `cancel` is posted;
|
|
6
|
+
// a late answer is dropped. Errors come back as ADR 0026 objects and are rebuilt as LaminaPdfError.
|
|
7
|
+
// A worker `error` or `messageerror`, or a trap the worker reports, rejects every pending call
|
|
8
|
+
// with `worker-crashed` and emits `crashed`; `restart()` starts a new worker. No heartbeat.
|
|
9
|
+
import { defined } from "../defined.js";
|
|
10
|
+
import { LaminaPdfError, packageError } from "../errors.js";
|
|
11
|
+
import { PageText } from "../text.js";
|
|
12
|
+
import { Emitter } from "./emitter.js";
|
|
13
|
+
import { HANDSHAKE, isHandleRef, isPageTextData, } from "./protocol.js";
|
|
14
|
+
import { DOCUMENT_METHODS, PAGE_METHODS } from "./support.js";
|
|
15
|
+
import { whole } from "./transfer.js";
|
|
16
|
+
/** `Symbol.asyncDispose` where the runtime has it, else the registered symbol (no globals touched). */
|
|
17
|
+
const ASYNC_DISPOSE = Symbol.asyncDispose ?? Symbol.for("Symbol.asyncDispose");
|
|
18
|
+
/** `source` as sent to the worker: URLs made absolute against the page. */
|
|
19
|
+
function sendable(source) {
|
|
20
|
+
if (source instanceof URL)
|
|
21
|
+
return source.href;
|
|
22
|
+
if (typeof source === "string") {
|
|
23
|
+
const base = globalThis.location?.href;
|
|
24
|
+
return base === undefined ? source : new URL(source, base).href;
|
|
25
|
+
}
|
|
26
|
+
return source;
|
|
27
|
+
}
|
|
28
|
+
function sendableInit(init) {
|
|
29
|
+
if (typeof init === "string" ||
|
|
30
|
+
init instanceof URL ||
|
|
31
|
+
init instanceof ArrayBuffer ||
|
|
32
|
+
ArrayBuffer.isView(init) ||
|
|
33
|
+
init instanceof WebAssembly.Module) {
|
|
34
|
+
return sendable(init);
|
|
35
|
+
}
|
|
36
|
+
return Object.fromEntries(Object.entries(defined(init)).map(([k, v]) => [k, typeof v === "boolean" ? v : sendable(v)]));
|
|
37
|
+
}
|
|
38
|
+
/** Closes the ImageBitmaps in `value` and its direct members. */
|
|
39
|
+
function closeBitmaps(value) {
|
|
40
|
+
const close = (v) => {
|
|
41
|
+
if (typeof ImageBitmap !== "undefined" && v instanceof ImageBitmap)
|
|
42
|
+
v.close();
|
|
43
|
+
};
|
|
44
|
+
close(value);
|
|
45
|
+
if (typeof value === "object" && value !== null)
|
|
46
|
+
for (const v of Object.values(value))
|
|
47
|
+
close(v);
|
|
48
|
+
}
|
|
49
|
+
function defaultWorker() {
|
|
50
|
+
return new Worker(new URL("./entry.js", import.meta.url), { type: "module", name: "lamina" });
|
|
51
|
+
}
|
|
52
|
+
function rebuild(error) {
|
|
53
|
+
return new LaminaPdfError(error);
|
|
54
|
+
}
|
|
55
|
+
function crashed(message, reason) {
|
|
56
|
+
return packageError("worker-crashed", message, { data: { reason } });
|
|
57
|
+
}
|
|
58
|
+
/** Starts the worker and waits for its handshake. */
|
|
59
|
+
export async function connect(options = {}) {
|
|
60
|
+
const client = new WorkerClient(options);
|
|
61
|
+
await client.start(options.signal);
|
|
62
|
+
return client;
|
|
63
|
+
}
|
|
64
|
+
/** A connection to one Lamina PDF worker. */
|
|
65
|
+
export class WorkerClient {
|
|
66
|
+
#factory;
|
|
67
|
+
#init;
|
|
68
|
+
#pending = new Map();
|
|
69
|
+
#emitter = new Emitter();
|
|
70
|
+
#onDiscard;
|
|
71
|
+
/** The worker once its handshake succeeded; undefined while starting, stopped or crashed. */
|
|
72
|
+
#worker;
|
|
73
|
+
/** The handshake in progress (calls made meanwhile wait for it), and how `#stop` ends it. */
|
|
74
|
+
#starting;
|
|
75
|
+
#cancelStart;
|
|
76
|
+
/**
|
|
77
|
+
* Bumped for each worker: a handle remembers the generation it was made in, so a handle of a
|
|
78
|
+
* worker that's gone is `disposed` instead of reaching the new worker's objects.
|
|
79
|
+
*/
|
|
80
|
+
#generation = 0;
|
|
81
|
+
#nextId = 1;
|
|
82
|
+
/** @internal Use {@link connect}. */
|
|
83
|
+
constructor(options) {
|
|
84
|
+
const { worker } = options;
|
|
85
|
+
if (typeof worker === "function") {
|
|
86
|
+
this.#factory = worker;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// A given Worker serves the first start; restart() then needs a factory.
|
|
90
|
+
let given = worker;
|
|
91
|
+
this.#factory = () => {
|
|
92
|
+
if (given !== undefined) {
|
|
93
|
+
const w = given;
|
|
94
|
+
given = undefined;
|
|
95
|
+
return w;
|
|
96
|
+
}
|
|
97
|
+
if (worker !== undefined) {
|
|
98
|
+
throw crashed("restart() needs a worker factory: pass `worker: () => new Worker(…)`", "terminated");
|
|
99
|
+
}
|
|
100
|
+
return defaultWorker();
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
this.#init = options.init;
|
|
104
|
+
this.#onDiscard = options.onDiscard ?? closeBitmaps;
|
|
105
|
+
}
|
|
106
|
+
/** @internal Starts a worker and checks its handshake. */
|
|
107
|
+
start(signal) {
|
|
108
|
+
const starting = this.#handshake(signal).finally(() => {
|
|
109
|
+
if (this.#starting === starting)
|
|
110
|
+
this.#starting = undefined;
|
|
111
|
+
});
|
|
112
|
+
this.#starting = starting;
|
|
113
|
+
return starting;
|
|
114
|
+
}
|
|
115
|
+
async #handshake(signal) {
|
|
116
|
+
if (signal?.aborted)
|
|
117
|
+
throw packageError("cancelled", "connecting was cancelled", { cause: signal.reason });
|
|
118
|
+
const generation = ++this.#generation;
|
|
119
|
+
const worker = this.#factory();
|
|
120
|
+
let onAbort;
|
|
121
|
+
try {
|
|
122
|
+
const welcome = await new Promise((resolve, reject) => {
|
|
123
|
+
onAbort = () => reject(packageError("cancelled", "connecting was cancelled", { cause: signal?.reason }));
|
|
124
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
125
|
+
this.#cancelStart = reject;
|
|
126
|
+
worker.onmessage = (event) => {
|
|
127
|
+
if (event.data.kind === "welcome")
|
|
128
|
+
resolve(event.data);
|
|
129
|
+
};
|
|
130
|
+
worker.onerror = (event) => {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
reject(crashed("the worker failed to start", "error"));
|
|
133
|
+
};
|
|
134
|
+
worker.onmessageerror = () => reject(crashed("the worker's answer couldn't be read", "messageerror"));
|
|
135
|
+
const hello = {
|
|
136
|
+
kind: "hello",
|
|
137
|
+
client: HANDSHAKE,
|
|
138
|
+
...(this.#init === undefined ? {} : { init: sendableInit(this.#init) }),
|
|
139
|
+
};
|
|
140
|
+
try {
|
|
141
|
+
worker.postMessage(hello);
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
reject(packageError("invalid-argument", "connect()'s `init` can't be sent to the worker", { cause: e }));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
if (welcome.worker.protocol !== HANDSHAKE.protocol || welcome.worker.version !== HANDSHAKE.version) {
|
|
148
|
+
throw packageError("worker-version-mismatch", "the worker is from another @laminapdf/sdk build", {
|
|
149
|
+
data: { expected: HANDSHAKE, actual: welcome.worker },
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (welcome.error !== undefined)
|
|
153
|
+
throw rebuild(welcome.error);
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
worker.terminate();
|
|
157
|
+
throw e;
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
this.#cancelStart = undefined;
|
|
161
|
+
if (onAbort !== undefined)
|
|
162
|
+
signal?.removeEventListener("abort", onAbort);
|
|
163
|
+
}
|
|
164
|
+
if (generation !== this.#generation) {
|
|
165
|
+
// terminate() or another start() came first: this worker is not wanted any more.
|
|
166
|
+
worker.terminate();
|
|
167
|
+
throw crashed("the worker was stopped while it started", "terminated");
|
|
168
|
+
}
|
|
169
|
+
worker.onmessage = (event) => this.#receive(event.data);
|
|
170
|
+
worker.onerror = (event) => {
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
this.#crash("error");
|
|
173
|
+
};
|
|
174
|
+
worker.onmessageerror = () => this.#crash("messageerror");
|
|
175
|
+
this.#worker = worker;
|
|
176
|
+
}
|
|
177
|
+
#receive(message) {
|
|
178
|
+
switch (message.kind) {
|
|
179
|
+
case "result": {
|
|
180
|
+
const pending = this.#pending.get(message.id);
|
|
181
|
+
// A late answer to a call already rejected (aborted or crashed) is dropped.
|
|
182
|
+
if (pending === undefined) {
|
|
183
|
+
if (message.ok)
|
|
184
|
+
this.#onDiscard(message.result);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this.#pending.delete(message.id);
|
|
188
|
+
if (message.ok)
|
|
189
|
+
pending.resolve(message.result);
|
|
190
|
+
else
|
|
191
|
+
pending.reject(rebuild(message.error));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
case "event":
|
|
195
|
+
this.#emitter.emit("event", { name: message.name, data: message.data });
|
|
196
|
+
return;
|
|
197
|
+
case "progress":
|
|
198
|
+
this.#pending.get(message.id)?.onProgress?.(message.progress);
|
|
199
|
+
return;
|
|
200
|
+
case "crashed":
|
|
201
|
+
this.#crash(message.reason);
|
|
202
|
+
return;
|
|
203
|
+
case "welcome":
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** Ends the current worker and rejects its pending calls; `notify` fires the `crashed` listeners. */
|
|
208
|
+
#stop(reason, notify) {
|
|
209
|
+
const worker = this.#worker;
|
|
210
|
+
this.#worker = undefined;
|
|
211
|
+
// Handles of this worker, and a start in progress, are now stale.
|
|
212
|
+
this.#generation++;
|
|
213
|
+
worker?.terminate();
|
|
214
|
+
// A worker still in its handshake (a stalled `init()`) is ended too.
|
|
215
|
+
this.#cancelStart?.(crashed("the worker was stopped while it started", reason));
|
|
216
|
+
const pending = [...this.#pending.values()];
|
|
217
|
+
this.#pending.clear();
|
|
218
|
+
for (const p of pending)
|
|
219
|
+
p.reject(crashed("the worker stopped", reason));
|
|
220
|
+
if (notify)
|
|
221
|
+
this.#emitter.emit("crashed", reason);
|
|
222
|
+
}
|
|
223
|
+
#crash(reason) {
|
|
224
|
+
if (this.#worker === undefined)
|
|
225
|
+
return;
|
|
226
|
+
this.#stop(reason, true);
|
|
227
|
+
}
|
|
228
|
+
on(event, listener) {
|
|
229
|
+
if (event === "crashed")
|
|
230
|
+
return this.#emitter.on("crashed", listener);
|
|
231
|
+
if (event === "event") {
|
|
232
|
+
const l = listener;
|
|
233
|
+
return this.#emitter.on("event", ({ name, data }) => l(name, data));
|
|
234
|
+
}
|
|
235
|
+
throw new TypeError(`unknown event ${String(event)}`);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Calls an extension method in the worker (for packages that extend it with `serve(…)`, such
|
|
239
|
+
* as `@laminapdf/viewer`). Same cancellation, transfers and errors as every other call.
|
|
240
|
+
*/
|
|
241
|
+
request(method, params, options = {}) {
|
|
242
|
+
return this.call(0, method, params, options);
|
|
243
|
+
}
|
|
244
|
+
/** Ends the worker; pending calls reject with `worker-crashed` (no `crashed` event). */
|
|
245
|
+
terminate() {
|
|
246
|
+
this.#stop("terminated", false);
|
|
247
|
+
}
|
|
248
|
+
/** Starts a new worker (after a crash, or to reset); handles of the old one are `disposed`. */
|
|
249
|
+
async restart(signal) {
|
|
250
|
+
this.terminate();
|
|
251
|
+
await this.start(signal);
|
|
252
|
+
}
|
|
253
|
+
/** @internal The current worker generation (handles record it). */
|
|
254
|
+
get generation() {
|
|
255
|
+
return this.#generation;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @internal Posts a call and waits for its answer. `generation`, for a handle, is the one it
|
|
259
|
+
* was made in. Calls made while a worker starts wait for its handshake.
|
|
260
|
+
*/
|
|
261
|
+
async call(handle, method, params, options = {}, generation) {
|
|
262
|
+
if (this.#worker === undefined && this.#starting !== undefined) {
|
|
263
|
+
// The start's own error reaches its caller; here, the call just finds no worker. The
|
|
264
|
+
// call's signal still rejects it meanwhile.
|
|
265
|
+
await waitWithSignal(this.#starting.catch(() => { }), options.signal);
|
|
266
|
+
}
|
|
267
|
+
const worker = this.#worker;
|
|
268
|
+
if (worker === undefined) {
|
|
269
|
+
throw crashed("the worker isn't running: call restart()", "terminated");
|
|
270
|
+
}
|
|
271
|
+
if (generation !== undefined && generation !== this.#generation) {
|
|
272
|
+
throw packageError("disposed", "the handle belongs to a worker that has stopped");
|
|
273
|
+
}
|
|
274
|
+
const { signal, onProgress, transfer } = options;
|
|
275
|
+
if (signal?.aborted) {
|
|
276
|
+
throw packageError("cancelled", "the call was cancelled", { cause: signal.reason });
|
|
277
|
+
}
|
|
278
|
+
const id = this.#nextId++;
|
|
279
|
+
return new Promise((resolve, reject) => {
|
|
280
|
+
const onAbort = () => {
|
|
281
|
+
if (!this.#pending.delete(id))
|
|
282
|
+
return;
|
|
283
|
+
worker.postMessage({ kind: "cancel", id });
|
|
284
|
+
reject(packageError("cancelled", "the call was cancelled", { cause: signal?.reason }));
|
|
285
|
+
};
|
|
286
|
+
const settle = (f) => (value) => {
|
|
287
|
+
signal?.removeEventListener("abort", onAbort);
|
|
288
|
+
f(value);
|
|
289
|
+
};
|
|
290
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
291
|
+
this.#pending.set(id, { resolve: settle(resolve), reject: settle(reject), onProgress });
|
|
292
|
+
const { priority, key } = options;
|
|
293
|
+
const request = {
|
|
294
|
+
kind: "call",
|
|
295
|
+
id,
|
|
296
|
+
handle,
|
|
297
|
+
method,
|
|
298
|
+
params,
|
|
299
|
+
...(priority === undefined ? {} : { priority }),
|
|
300
|
+
...(key === undefined ? {} : { key }),
|
|
301
|
+
};
|
|
302
|
+
// Only a buffer the parameter covers whole moves; a subarray or a shared buffer is copied.
|
|
303
|
+
const buffers = transfer === true ? params.flatMap(whole) : [];
|
|
304
|
+
try {
|
|
305
|
+
worker.postMessage(request, buffers);
|
|
306
|
+
}
|
|
307
|
+
catch (e) {
|
|
308
|
+
// A parameter that can't be cloned or transferred: nothing reached the worker.
|
|
309
|
+
this.#pending
|
|
310
|
+
.get(id)
|
|
311
|
+
?.reject(packageError("invalid-argument", `a parameter of ${method} can't be sent to the worker`, { cause: e }));
|
|
312
|
+
this.#pending.delete(id);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Opens `bytes` in the worker. They are copied unless `transfer: true` (then the caller's
|
|
318
|
+
* buffer is detached). Opening is one synchronous call there: `signal` drops it if it hasn't
|
|
319
|
+
* started, but can't stop it midway (`terminate()` is the hard stop).
|
|
320
|
+
*/
|
|
321
|
+
async open(bytes, options = {}) {
|
|
322
|
+
const { signal, onProgress, transfer, ...open } = options;
|
|
323
|
+
const ref = await this.call(0, "open", [bytes, open], defined({ signal, onProgress, transfer }));
|
|
324
|
+
return this.#remoteDocument(ref);
|
|
325
|
+
}
|
|
326
|
+
/** Opens a remote file by HTTP range requests (L2c): the worker fetches what each call needs. */
|
|
327
|
+
async openUrl(url, options = {}) {
|
|
328
|
+
const { signal, onProgress, transfer: _, ...open } = options;
|
|
329
|
+
const ref = await this.call(0, "openUrl", [url, open], defined({ signal, onProgress }));
|
|
330
|
+
return this.#remoteDocument(ref);
|
|
331
|
+
}
|
|
332
|
+
/** Loads the text module in the worker (`loadText()`). */
|
|
333
|
+
async loadText(options) {
|
|
334
|
+
await this.call(0, "loadText", [], options);
|
|
335
|
+
}
|
|
336
|
+
/** Loads the extract module in the worker (`loadExtract()`), for `page.text()`. */
|
|
337
|
+
async loadExtract(options) {
|
|
338
|
+
await this.call(0, "loadExtract", [], options);
|
|
339
|
+
}
|
|
340
|
+
#remoteDocument(ref) {
|
|
341
|
+
// A stop rejects every pending call, so an answer comes from the current worker.
|
|
342
|
+
const generation = this.#generation;
|
|
343
|
+
let closed = false;
|
|
344
|
+
// Idempotent, like Document.free(): a second close, or one after the worker stopped, is a no-op.
|
|
345
|
+
const close = async () => {
|
|
346
|
+
if (closed)
|
|
347
|
+
return;
|
|
348
|
+
closed = true;
|
|
349
|
+
if (generation !== this.#generation || this.#worker === undefined)
|
|
350
|
+
return;
|
|
351
|
+
await this.call(ref.$handle, "close", [], {}, generation);
|
|
352
|
+
};
|
|
353
|
+
const incoming = (value) => {
|
|
354
|
+
if (isHandleRef(value))
|
|
355
|
+
return remote(this, value.$handle, generation, PAGE_METHODS, undefined, incoming);
|
|
356
|
+
if (isPageTextData(value))
|
|
357
|
+
return new PageText(value.$pageText);
|
|
358
|
+
return value;
|
|
359
|
+
};
|
|
360
|
+
return remote(this, ref.$handle, generation, DOCUMENT_METHODS, close, incoming);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/** Waits for `p`, or rejects with `cancelled` when `signal` aborts first. */
|
|
364
|
+
async function waitWithSignal(p, signal) {
|
|
365
|
+
if (signal === undefined) {
|
|
366
|
+
await p;
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
let onAbort;
|
|
370
|
+
const aborted = new Promise((_, reject) => {
|
|
371
|
+
onAbort = () => reject(packageError("cancelled", "the call was cancelled", { cause: signal.reason }));
|
|
372
|
+
if (signal.aborted)
|
|
373
|
+
onAbort();
|
|
374
|
+
else
|
|
375
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
376
|
+
});
|
|
377
|
+
try {
|
|
378
|
+
await Promise.race([p, aborted]);
|
|
379
|
+
}
|
|
380
|
+
finally {
|
|
381
|
+
if (onAbort !== undefined)
|
|
382
|
+
signal.removeEventListener("abort", onAbort);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
/** A proxy whose members (by `arity`) post calls on `handle` of worker `generation`. */
|
|
386
|
+
function remote(client, handle, generation, arity, close, incoming) {
|
|
387
|
+
return new Proxy(Object.create(null), {
|
|
388
|
+
get(_, key) {
|
|
389
|
+
if (key === ASYNC_DISPOSE || (close !== undefined && key === "close"))
|
|
390
|
+
return close;
|
|
391
|
+
if (typeof key !== "string" || !Object.hasOwn(arity, key))
|
|
392
|
+
return undefined;
|
|
393
|
+
const n = arity[key] ?? 0;
|
|
394
|
+
return async (...args) => {
|
|
395
|
+
const options = (args.length > n ? args[n] : undefined);
|
|
396
|
+
return incoming(await client.call(handle, key, args.slice(0, n), options, generation));
|
|
397
|
+
};
|
|
398
|
+
},
|
|
399
|
+
has(_, key) {
|
|
400
|
+
return (key === ASYNC_DISPOSE ||
|
|
401
|
+
(typeof key === "string" && (Object.hasOwn(arity, key) || (close !== undefined && key === "close"))));
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/worker/client.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,yFAAyF;AACzF,8FAA8F;AAC9F,6FAA6F;AAC7F,gGAAgG;AAChG,oGAAoG;AACpG,+FAA+F;AAC/F,4FAA4F;AAE5F,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAmB,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI7E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAEL,SAAS,EAGT,WAAW,EACX,cAAc,GAGf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,uGAAuG;AACvG,MAAM,aAAa,GAAY,MAAoC,CAAC,YAAY,IAAI,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAuBtH,2EAA2E;AAC3E,SAAS,QAAQ,CAAI,MAAS;IAC5B,IAAI,MAAM,YAAY,GAAG;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IAC9C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAI,UAA8C,CAAC,QAAQ,EAAE,IAAI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G,KAAK,OAAO,CAAC,CAAC,CAAC,CACrG,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Listeners by event, for the events in `E` (event name → the data a listener gets). A listener
|
|
3
|
+
* that throws is reported asynchronously and doesn't stop the others.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Emitter<E extends object> {
|
|
6
|
+
#private;
|
|
7
|
+
/** Listens for `event`; returns a function that stops listening. */
|
|
8
|
+
on<K extends keyof E>(event: K, listener: (data: E[K]) => void): () => void;
|
|
9
|
+
/** Calls every listener of `event` with `data`. */
|
|
10
|
+
emit<K extends keyof E>(event: K, data: E[K]): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../../src/worker/emitter.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,qBAAa,OAAO,CAAC,CAAC,SAAS,MAAM;;IAGnC,oEAAoE;IACpE,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAS1E;IAED,mDAAmD;IACnD,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAUlD;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The typed event emitter the worker client uses, exported from `@laminapdf/sdk/worker` for the
|
|
2
|
+
// packages that wrap the client (the viewer's ViewerClient).
|
|
3
|
+
/**
|
|
4
|
+
* Listeners by event, for the events in `E` (event name → the data a listener gets). A listener
|
|
5
|
+
* that throws is reported asynchronously and doesn't stop the others.
|
|
6
|
+
*/
|
|
7
|
+
export class Emitter {
|
|
8
|
+
#listeners = new Map();
|
|
9
|
+
/** Listens for `event`; returns a function that stops listening. */
|
|
10
|
+
on(event, listener) {
|
|
11
|
+
let set = this.#listeners.get(event);
|
|
12
|
+
if (set === undefined) {
|
|
13
|
+
set = new Set();
|
|
14
|
+
this.#listeners.set(event, set);
|
|
15
|
+
}
|
|
16
|
+
const l = listener;
|
|
17
|
+
set.add(l);
|
|
18
|
+
return () => set.delete(l);
|
|
19
|
+
}
|
|
20
|
+
/** Calls every listener of `event` with `data`. */
|
|
21
|
+
emit(event, data) {
|
|
22
|
+
for (const listener of this.#listeners.get(event) ?? []) {
|
|
23
|
+
try {
|
|
24
|
+
listener(data);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
queueMicrotask(() => {
|
|
28
|
+
throw e;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/worker/emitter.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,6DAA6D;AAE7D;;;GAGG;AACH,MAAM,OAAO,OAAO;IACT,UAAU,GAAG,IAAI,GAAG,EAAuC,CAAC;IAErE,oEAAoE;IACpE,EAAE,CAAoB,KAAQ,EAAE,QAA8B;QAC5D,IAAI,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;YAChB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,CAAC,GAAG,QAAiC,CAAC;QAC5C,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACX,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IAED,mDAAmD;IACnD,IAAI,CAAoB,KAAQ,EAAE,IAAU;QAC1C,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;YACxD,IAAI,CAAC;gBACF,QAA8B,CAAC,IAAI,CAAC,CAAC;YACxC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,cAAc,CAAC,GAAG,EAAE;oBAClB,MAAM,CAAC,CAAC;gBACV,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/worker/entry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../src/worker/entry.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { ConnectOptions, RemoteHttpOptions, WorkerInitOptions, WorkerWasmSource } from "./client.js";
|
|
2
|
+
export { connect, WorkerClient } from "./client.js";
|
|
3
|
+
export { Emitter } from "./emitter.js";
|
|
4
|
+
export { PROTOCOL_VERSION } from "./protocol.js";
|
|
5
|
+
export type { ExcludedDocumentMembers, ExcludedPageMembers } from "./support.js";
|
|
6
|
+
export type { CallOptions, RemoteDocument, RemoteMember, RemotePage, RemoteResult, RequestOptions } from "./types.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1G,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjF,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|