@file-viewer/renderer-typst 2.1.25 → 2.1.27

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 (2) hide show
  1. package/dist/typst.js +44 -1
  2. package/package.json +2 -2
package/dist/typst.js CHANGED
@@ -384,6 +384,7 @@ const getPageSummary = (pages, t) => {
384
384
  });
385
385
  };
386
386
  export default async function renderTypst(buffer, target, _type, context) {
387
+ var _a;
387
388
  const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
388
389
  const source = await readFileViewerText(buffer);
389
390
  const documentRef = target.ownerDocument || document;
@@ -554,14 +555,56 @@ export default async function renderTypst(buffer, target, _type, context) {
554
555
  }
555
556
  };
556
557
  void render();
558
+ (_a = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _a === void 0 ? void 0 : _a.call(context, {
559
+ beforeCapture: async ({ signal }) => {
560
+ while (state === 'loading' && !disposed) {
561
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
562
+ throw signal.reason;
563
+ }
564
+ await new Promise(resolve => {
565
+ const view = documentRef.defaultView;
566
+ if (view)
567
+ view.setTimeout(resolve, 16);
568
+ else
569
+ setTimeout(resolve, 16);
570
+ });
571
+ }
572
+ if (state === 'error') {
573
+ throw new Error(errorMessage || t('typst.error.title'));
574
+ }
575
+ },
576
+ capture: async ({ width, height, background, signal }) => {
577
+ const firstPage = pages[0];
578
+ if (!firstPage) {
579
+ return null;
580
+ }
581
+ const canvasHost = documentRef.createElement('div');
582
+ const pixelPerPt = Math.max(0.5, Math.min(width / Math.max(firstPage.width, 1), height / Math.max(firstPage.height, 1)));
583
+ await $typst.canvas(canvasHost, {
584
+ mainContent: source,
585
+ pixelPerPt,
586
+ backgroundColor: background,
587
+ });
588
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
589
+ throw signal.reason;
590
+ }
591
+ const canvas = canvasHost.querySelector('canvas');
592
+ if (!canvas) {
593
+ return null;
594
+ }
595
+ return new Promise(resolve => canvas.toBlob(resolve, 'image/png'));
596
+ },
597
+ getTarget: () => pageShells.get(1) || body.querySelector('.typst-page-shell') || body,
598
+ });
557
599
  return {
558
600
  $el: target,
559
601
  unmount() {
560
- var _a;
602
+ var _a, _b;
561
603
  disposed = true;
562
604
  renderToken += 1;
563
605
  unregisterFileViewerZoomProvider(root);
564
606
  (_a = context === null || context === void 0 ? void 0 : context.registerExportAdapter) === null || _a === void 0 ? void 0 : _a.call(context, null);
607
+ (_b = context === null || context === void 0 ? void 0 : context.registerThumbnailAdapter) === null || _b === void 0 ? void 0 : _b.call(context, null);
565
608
  target.replaceChildren();
566
609
  },
567
610
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-typst",
3
- "version": "2.1.25",
3
+ "version": "2.1.27",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone Typst renderer plugin for Flyfish File Viewer powered by browser WASM.",
@@ -54,7 +54,7 @@
54
54
  "LICENSE"
55
55
  ],
56
56
  "dependencies": {
57
- "@file-viewer/core": "2.1.25",
57
+ "@file-viewer/core": "2.1.27",
58
58
  "@myriaddreamin/typst-ts-renderer": "0.7.0",
59
59
  "@myriaddreamin/typst-ts-web-compiler": "0.7.0",
60
60
  "@myriaddreamin/typst.ts": "0.7.0"