文件
mynode/packages/pdf-viewer/main.tsx
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

47 行
1.5 KiB
TypeScript

import React from 'react';
import shim from '@joplin/lib/shim';
shim.setReact(React);
const { createRoot } = require('react-dom/client');
import * as pdfjsLib from 'pdfjs-dist';
import MiniViewerApp from './miniViewer';
import MessageService from './messageService';
import FullViewer from './FullViewer';
require('./common.css');
// Setting worker path to worker bundle.
pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdf.worker.js';
const url = window.frameElement.getAttribute('x-url');
const type = window.frameElement.getAttribute('x-type');
const appearance = window.frameElement.getAttribute('x-appearance');
const anchorPage = Number(window.frameElement.getAttribute('x-anchorPage')) || null;
const pdfId = window.frameElement.getAttribute('id');
const resourceId = window.frameElement.getAttribute('x-resourceid');
const title = window.frameElement.getAttribute('x-title');
document.documentElement.setAttribute('data-theme', appearance);
const messageService = new MessageService(type);
function App() {
if (type === 'mini') {
return <MiniViewerApp pdfPath={url}
isDarkTheme={appearance === 'dark'}
anchorPage={anchorPage}
pdfId={pdfId}
resourceId={resourceId}
messageService={messageService}/>;
} else if (type === 'full') {
return <FullViewer pdfPath={url}
isDarkTheme={appearance === 'dark'}
startPage={anchorPage || 1}
title={title}
messageService={messageService} />;
}
return <div>Error: Unknown app type "{type}"</div>;
}
const root = createRoot(document.getElementById('pdf-root'));
root.render(<App/>);