@ethercorps/sveltekit-og 4.3.0-next.13 → 4.3.0-next.14
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.
|
@@ -4,14 +4,13 @@ import { handleAsync, ErrorCodes } from "../helpers/error-handler.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Lazy singleton around a node/edge wasm module pair. The edge/node choice is
|
|
6
6
|
* made per-runtime via std-env; both sides stay direct import() expressions so
|
|
7
|
-
* the bundler can emit the wasm chunk.
|
|
8
|
-
*
|
|
7
|
+
* the bundler can emit the wasm chunk. Memoizes the init promise (like
|
|
8
|
+
* takumi/renderer.ts) so concurrent first requests share one init, and clears
|
|
9
|
+
* it on rejection so a failed init can be retried.
|
|
9
10
|
*/
|
|
10
11
|
function createProvider(label, errorCode, imports) {
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
if (instance)
|
|
14
|
-
return instance;
|
|
12
|
+
let instancePromise;
|
|
13
|
+
const init = async (debug) => {
|
|
15
14
|
const log = createLogger(debug);
|
|
16
15
|
log.debug(`Initializing ${label}`);
|
|
17
16
|
const isWorkerLikeRuntime = isEdgeLight || isWorkerd;
|
|
@@ -19,8 +18,14 @@ function createProvider(label, errorCode, imports) {
|
|
|
19
18
|
const moduleImport = isWorkerLikeRuntime ? imports.edge() : imports.node();
|
|
20
19
|
const loaded = await handleAsync(() => moduleImport.then((m) => m.default), errorCode, `Failed to import ${label} module`);
|
|
21
20
|
await handleAsync(() => loaded.initWasmPromise, errorCode, `Failed to initialize ${label} WASM`);
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
return loaded;
|
|
22
|
+
};
|
|
23
|
+
return (debug = false) => {
|
|
24
|
+
instancePromise ??= init(debug).catch((error) => {
|
|
25
|
+
instancePromise = undefined;
|
|
26
|
+
throw error;
|
|
27
|
+
});
|
|
28
|
+
return instancePromise;
|
|
24
29
|
};
|
|
25
30
|
}
|
|
26
31
|
const useResvgModule = createProvider("ReSVG", ErrorCodes.RESVG_INIT_FAILED, {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Renderer as NodeRenderer, FontDetails } from "takumi-js/node";
|
|
2
2
|
export type TakumiRenderer = NodeRenderer;
|
|
3
|
-
/** Lazily creates and caches the Takumi renderer for the current runtime.
|
|
3
|
+
/** Lazily creates and caches the Takumi renderer for the current runtime.
|
|
4
|
+
* A rejected init clears the cache so the next request retries. */
|
|
4
5
|
export declare function useTakumiRenderer(): Promise<TakumiRenderer>;
|
|
5
6
|
/** Register each font once, keyed by name/weight/style. */
|
|
6
7
|
export declare function registerTakumiFonts(renderer: TakumiRenderer, fonts: FontDetails[]): Promise<void>;
|
package/dist/takumi/renderer.js
CHANGED
|
@@ -18,9 +18,13 @@ async function initRenderer() {
|
|
|
18
18
|
}, ErrorCodes.TAKUMI_INIT_FAILED, "Failed to initialize Takumi WASM");
|
|
19
19
|
return new Renderer();
|
|
20
20
|
}
|
|
21
|
-
/** Lazily creates and caches the Takumi renderer for the current runtime.
|
|
21
|
+
/** Lazily creates and caches the Takumi renderer for the current runtime.
|
|
22
|
+
* A rejected init clears the cache so the next request retries. */
|
|
22
23
|
export async function useTakumiRenderer() {
|
|
23
|
-
rendererPromise ??= initRenderer()
|
|
24
|
+
rendererPromise ??= initRenderer().catch((error) => {
|
|
25
|
+
rendererPromise = undefined;
|
|
26
|
+
throw error;
|
|
27
|
+
});
|
|
24
28
|
return rendererPromise;
|
|
25
29
|
}
|
|
26
30
|
/** Register each font once, keyed by name/weight/style. */
|