@rspress-theme-anatole/theme-default 0.5.8 → 0.6.0

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/bundle.js +100 -4
  2. package/package.json +3 -3
package/dist/bundle.js CHANGED
@@ -390,7 +390,7 @@ function DocFooter() {
390
390
  (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
391
391
  className: "flex flex-col",
392
392
  children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.EditLink, {})
393
- }),
393
+ }),
394
394
  (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
395
395
  className: "flex flex-col sm:flex-row sm:justify-around gap-4 pt-6",
396
396
  children: [
@@ -1212,7 +1212,7 @@ function DocLayout(props) {
1212
1212
  (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.Overview, {
1213
1213
  content: docContent
1214
1214
  }),
1215
- frontmatter.comment ? (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
1215
+ themeConfig.comment ? (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
1216
1216
  id: 'giscus-comments',
1217
1217
  style: {
1218
1218
  padding: '64px 62px 0 64px',
@@ -1225,7 +1225,10 @@ function DocLayout(props) {
1225
1225
  children: [
1226
1226
  (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
1227
1227
  style: {
1228
- padding: '0 0 28px 64px',
1228
+ padding: '0 64px 28px 64px',
1229
+ display: 'flex',
1230
+ justifyContent: 'space-between',
1231
+ alignItems: 'center',
1229
1232
  },
1230
1233
  children: [
1231
1234
  (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("p", {
@@ -1251,6 +1254,23 @@ function DocLayout(props) {
1251
1254
  ...breadcrumbNav
1252
1255
  ]
1253
1256
  }),
1257
+ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("a", {
1258
+ onClick: exportContentToPDF,
1259
+ children: [
1260
+ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("i", {
1261
+ className: "fa-regular fa-file-pdf",
1262
+ }),
1263
+ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", {
1264
+ className: "ml-2",
1265
+ children: "Export to PDF"
1266
+ })
1267
+ ],
1268
+ style: {
1269
+ fontSize: '15px',
1270
+ fontWeight: '500',
1271
+ cursor: 'pointer',
1272
+ }
1273
+ }),
1254
1274
  ]
1255
1275
  }),
1256
1276
  (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
@@ -1270,7 +1290,7 @@ function DocLayout(props) {
1270
1290
  afterDocFooter
1271
1291
  ]
1272
1292
  }),
1273
- frontmatter.comment ? (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
1293
+ themeConfig.comment ? (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
1274
1294
  id: 'giscus-comments',
1275
1295
  style: {
1276
1296
  padding: '64px 62px 0 64px',
@@ -5454,4 +5474,80 @@ function loadGiscus() {
5454
5474
  }
5455
5475
  }
5456
5476
 
5477
+ function loadScript(src) {
5478
+ return new Promise((resolve, reject) => {
5479
+ if (document.querySelector(`script[src="${src}"]`)) return resolve();
5480
+ const script = document.createElement('script');
5481
+ script.src = src;
5482
+ script.onload = resolve;
5483
+ script.onerror = reject;
5484
+ document.body.appendChild(script);
5485
+ });
5486
+ }
5487
+
5488
+ function fixMermaidSVGs() {
5489
+ // 选取所有doc中的SVG
5490
+ document.querySelectorAll('.rspress-doc svg').forEach(svg => {
5491
+ // 自动根据内容调整宽高
5492
+ const bbox = svg.getBBox();
5493
+ svg.setAttribute('width', bbox.width + bbox.x);
5494
+ svg.setAttribute('height', bbox.height + bbox.y);
5495
+ svg.setAttribute('viewBox', `${bbox.x} ${bbox.y} ${bbox.width} ${bbox.height}`);
5496
+ svg.style.width = '100%';
5497
+ svg.style.height = 'auto';
5498
+ });
5499
+ }
5500
+
5501
+ async function exportContentToPDF() {
5502
+ // 显示生成中提示
5503
+ let tip = document.createElement('div');
5504
+ tip.id = 'pdf-generating-tip';
5505
+ tip.innerText = 'Generating PDF...';
5506
+ Object.assign(tip.style, {
5507
+ position: 'fixed',
5508
+ top: '50%',
5509
+ left: '50%',
5510
+ transform: 'translate(-50%, -50%)',
5511
+ background: 'rgba(0,0,0,0.8)',
5512
+ color: '#fff',
5513
+ padding: '20px 40px',
5514
+ borderRadius: '8px',
5515
+ zIndex: 9999,
5516
+ fontSize: '18px'
5517
+ });
5518
+ document.body.appendChild(tip);
5519
+
5520
+ fixMermaidSVGs();
5521
+
5522
+ if (!window.html2pdf) {
5523
+ await loadScript('https://cdn.jsdelivr.net/npm/html2pdf.js@0.10.1/dist/html2pdf.bundle.min.js');
5524
+ }
5525
+ const element = document.querySelector('.rspress-doc');
5526
+ if (!element) {
5527
+ alert('No content to export.');
5528
+ return;
5529
+ }
5530
+
5531
+ const opt = {
5532
+ margin: 0.5,
5533
+ filename: document.title.replace(/\s+/g, '_') + '.pdf',
5534
+ image: { type: 'jpeg', quality: 0.98 },
5535
+ html2canvas: { scale: 2, useCORS: true },
5536
+ jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' },
5537
+ pagebreak: {
5538
+ mode: ['avoid-all', 'css', 'legacy'],
5539
+ before: '.page-break-before', // 在这些选择器前强制分页
5540
+ after: '.page-break-after', // 在这些选择器后强制分页
5541
+ avoid: '.no-page-break' // 避免这些选择器分页
5542
+ }
5543
+ };
5544
+
5545
+ // 生成 PDF 并在完成后移除提示
5546
+ window.html2pdf().set(opt).from(element).save().then(() => {
5547
+ document.body.removeChild(tip);
5548
+ }).catch(() => {
5549
+ document.body.removeChild(tip);
5550
+ });
5551
+ }
5552
+
5457
5553
  export { Aside, Badge, Button, Card, DocFooter, DocLayout, EditLink, HomeFeature, HomeFooter, HomeLayout, HomepageLayout, HomepageTopSearch, HomepageTopics, HomepageFeatures, HomepageFaqs, LastUpdated, Layout, Link, LinkCard, Nav, NotFoundLayout, Overview, PackageManagerTabs, PrevNextPage, types_RenderType as RenderType, ScrollToTop, Search, SearchPanel, Sidebar, SidebarList, SocialLinks, SourceCode, Steps, SwitchAppearance, Tab, Tabs, Tag, Toc, bindingAsideScroll, src_rslib_entry_ as default, getCustomMDXComponent, isMobileDevice, parseInlineMarkdownText, renderHtmlOrText, renderInlineMarkdown, scrollToTarget, setup, useEditLink, useEnableNav, useFullTextSearch, useHiddenNav, useLocaleSiteData, usePathUtils, usePrevNextPage, useRedirect4FirstVisit, useSidebarData, useThemeState };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rspress-theme-anatole/theme-default",
3
3
  "author": "Anatole Tong",
4
- "version": "0.5.8",
4
+ "version": "0.6.0",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
7
7
  "*.css",
@@ -21,7 +21,7 @@
21
21
  "types": "./dist/bundle.d.ts",
22
22
  "dependencies": {
23
23
  "@mdx-js/react": "2.3.0",
24
- "@rspress-theme-anatole/shared": "0.5.8",
24
+ "@rspress-theme-anatole/shared": "0.6.0",
25
25
  "@rspress/runtime": "1.43.8",
26
26
  "body-scroll-lock": "4.0.0-beta.0",
27
27
  "copy-to-clipboard": "^3.3.3",
@@ -35,7 +35,7 @@
35
35
  "react-helmet-async": "^1.3.0",
36
36
  "react-router-dom": "6.29.0",
37
37
  "react-syntax-highlighter": "^15.6.1",
38
- "@rspress-theme-anatole/rspress-plugin-mermaid": "0.5.8"
38
+ "@rspress-theme-anatole/rspress-plugin-mermaid": "0.6.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@microsoft/api-extractor": "^7.49.2",