@file-viewer/renderer-typst 3.3.1 → 3.3.4
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/typst.js +22 -27
- package/package.json +2 -2
package/dist/typst.js
CHANGED
|
@@ -77,16 +77,6 @@ const createStyle = (documentRef) => {
|
|
|
77
77
|
style.textContent = typstStyle;
|
|
78
78
|
return style;
|
|
79
79
|
};
|
|
80
|
-
const createElement = (documentRef, tagName, className, text) => {
|
|
81
|
-
const element = documentRef.createElement(tagName);
|
|
82
|
-
if (className) {
|
|
83
|
-
element.className = className;
|
|
84
|
-
}
|
|
85
|
-
if (text !== undefined) {
|
|
86
|
-
element.textContent = text;
|
|
87
|
-
}
|
|
88
|
-
return element;
|
|
89
|
-
};
|
|
90
80
|
const getWindowOverride = (key) => {
|
|
91
81
|
if (typeof window === 'undefined') {
|
|
92
82
|
return undefined;
|
|
@@ -420,7 +410,8 @@ const getPageSummary = (pages, t) => {
|
|
|
420
410
|
};
|
|
421
411
|
export default async function renderTypst(buffer, target, _type, context) {
|
|
422
412
|
var _a;
|
|
423
|
-
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
413
|
+
const t = createFileViewerTranslator((context === null || context === void 0 ? void 0 : context.i18n) || (context === null || context === void 0 ? void 0 : context.options));
|
|
414
|
+
const createElement = t.element;
|
|
424
415
|
const source = await readFileViewerText(buffer);
|
|
425
416
|
const documentRef = target.ownerDocument || document;
|
|
426
417
|
const zoomEmitter = createFileViewerZoomChangeEmitter();
|
|
@@ -435,9 +426,9 @@ export default async function renderTypst(buffer, target, _type, context) {
|
|
|
435
426
|
root.dataset.viewerZoomProvider = 'typst';
|
|
436
427
|
const toolbar = createElement(documentRef, 'header', 'typst-toolbar');
|
|
437
428
|
const titleGroup = createElement(documentRef, 'div');
|
|
438
|
-
const title = createElement(documentRef, 'strong', undefined, (context === null || context === void 0 ? void 0 : context.filename) || '
|
|
439
|
-
const summary = createElement(documentRef, 'span', undefined,
|
|
440
|
-
const status = createElement(documentRef, 'em', undefined,
|
|
429
|
+
const title = createElement(documentRef, 'strong', undefined, () => (context === null || context === void 0 ? void 0 : context.filename) || t('ui.typst.ui.typst.document.b37fc0'));
|
|
430
|
+
const summary = t.text(createElement(documentRef, 'span', undefined), 'typst.summaryRenderer');
|
|
431
|
+
const status = t.text(createElement(documentRef, 'em', undefined), 'typst.status.compiling');
|
|
441
432
|
const body = createElement(documentRef, 'div');
|
|
442
433
|
titleGroup.append(title, summary);
|
|
443
434
|
toolbar.append(titleGroup, status);
|
|
@@ -484,21 +475,21 @@ export default async function renderTypst(buffer, target, _type, context) {
|
|
|
484
475
|
const renderLoading = () => {
|
|
485
476
|
const loading = createElement(documentRef, 'div', 'typst-loading');
|
|
486
477
|
loading.setAttribute('role', 'status');
|
|
487
|
-
loading.append(createElement(documentRef, 'span'), createElement(documentRef, 'strong', undefined,
|
|
478
|
+
loading.append(createElement(documentRef, 'span'), t.text(createElement(documentRef, 'strong', undefined), 'typst.loading.title'), t.text(createElement(documentRef, 'p', undefined), 'typst.loading.hint'));
|
|
488
479
|
body.replaceChildren(loading);
|
|
489
480
|
};
|
|
490
481
|
const renderError = () => {
|
|
491
482
|
const error = createElement(documentRef, 'div', 'typst-error');
|
|
492
|
-
error.append(createElement(documentRef, 'strong', undefined,
|
|
483
|
+
error.append(t.text(createElement(documentRef, 'strong', undefined), 'typst.error.title'), createElement(documentRef, 'pre', undefined, errorMessage));
|
|
493
484
|
body.replaceChildren(error);
|
|
494
485
|
};
|
|
495
486
|
const renderPages = () => {
|
|
496
487
|
pageShells.clear();
|
|
497
488
|
const pagesRoot = createElement(documentRef, 'main', 'typst-pages');
|
|
498
|
-
pagesRoot.setAttribute('aria-label', '
|
|
489
|
+
t.bind(pagesRoot, node => node.setAttribute('aria-label', t('ui.typst.ui.typst.preview.pages.7e618f')), 'aria-label');
|
|
499
490
|
pages.forEach(page => {
|
|
500
491
|
const shell = createElement(documentRef, 'section', 'typst-page-shell');
|
|
501
|
-
shell.setAttribute('aria-label',
|
|
492
|
+
t.bind(shell, node => node.setAttribute('aria-label', t('ui.typst.ui.page.2a4109', { p0: page.index })), 'aria-label');
|
|
502
493
|
const content = createElement(documentRef, 'div', 'typst-page-content');
|
|
503
494
|
content.replaceChildren(importTypstSvgPageNode(documentRef, page));
|
|
504
495
|
shell.append(content);
|
|
@@ -509,14 +500,18 @@ export default async function renderTypst(buffer, target, _type, context) {
|
|
|
509
500
|
applyPageZoom();
|
|
510
501
|
};
|
|
511
502
|
const syncUi = () => {
|
|
512
|
-
summary
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
503
|
+
t.bind(summary, localizedNode => {
|
|
504
|
+
localizedNode.textContent = state === 'ready'
|
|
505
|
+
? getPageSummary(pages, t)
|
|
506
|
+
: t('typst.summaryRenderer');
|
|
507
|
+
}, 'textContent');
|
|
508
|
+
t.bind(status, localizedNode => {
|
|
509
|
+
localizedNode.textContent = state === 'loading'
|
|
510
|
+
? t('typst.status.compiling')
|
|
511
|
+
: state === 'error'
|
|
512
|
+
? t('typst.status.failed')
|
|
513
|
+
: t('typst.status.rendered');
|
|
514
|
+
}, 'textContent');
|
|
520
515
|
if (state === 'loading') {
|
|
521
516
|
renderLoading();
|
|
522
517
|
}
|
|
@@ -559,7 +554,7 @@ export default async function renderTypst(buffer, target, _type, context) {
|
|
|
559
554
|
}
|
|
560
555
|
}
|
|
561
556
|
}
|
|
562
|
-
throw lastError instanceof Error ? lastError :
|
|
557
|
+
throw lastError instanceof Error ? lastError : t.error('typst.error.wasmLoadFailed');
|
|
563
558
|
};
|
|
564
559
|
const render = async () => {
|
|
565
560
|
var _a, _b;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-typst",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone Typst renderer plugin for File Viewer powered by browser WASM.",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"README.zh-CN.md"
|
|
83
83
|
],
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@file-viewer/core": "3.3.
|
|
85
|
+
"@file-viewer/core": "3.3.4",
|
|
86
86
|
"@myriaddreamin/typst-ts-renderer": "0.7.0",
|
|
87
87
|
"@myriaddreamin/typst-ts-web-compiler": "0.7.0",
|
|
88
88
|
"@myriaddreamin/typst.ts": "0.7.0"
|