pdf-smith 0.2.0 → 0.4.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.
@@ -1,104 +0,0 @@
1
- // src/preview/preview-plugin.ts
2
- var VIRTUAL_DOCUMENTS_ID = "virtual:pdf-smith-documents";
3
- var RESOLVED_VIRTUAL_DOCUMENTS_ID = `\0${VIRTUAL_DOCUMENTS_ID}`;
4
- function pdfSmithPreviewPlugin({ pkgSrcDir }) {
5
- return {
6
- name: "pdf-smith-preview",
7
- configureServer(server) {
8
- return () => {
9
- server.middlewares.use((req, res, next) => {
10
- const url = req.url ?? "";
11
- if (url.includes(".") || url.startsWith("/@") || url.startsWith("/node_modules/")) {
12
- next();
13
- return;
14
- }
15
- const html = `<!DOCTYPE html>
16
- <html lang="en">
17
- <head>
18
- <script type="module">
19
- import RefreshRuntime from "/@react-refresh"
20
- RefreshRuntime.injectIntoGlobalHook(window)
21
- window.$RefreshReg$ = () => {}
22
- window.$RefreshSig$ = () => (type) => type
23
- window.__vite_plugin_react_preamble_installed__ = true
24
- </script>
25
- <script type="module" src="/@vite/client"></script>
26
- <meta charset="UTF-8" />
27
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
28
- <title>pdf-smith Preview</title>
29
- <style>
30
- @media print {
31
- [data-pdf-smith-nav] { display: none !important; }
32
- [data-pdf-smith-container] {
33
- margin-left: 0 !important;
34
- padding: 0 !important;
35
- background: none !important;
36
- }
37
- [data-pdf-smith-container] > [data-pdf-smith-document] > div {
38
- margin-bottom: 0 !important;
39
- }
40
- [data-pdf-smith-container] > [data-pdf-smith-document] > div > div:first-child {
41
- display: none !important;
42
- }
43
- }
44
- </style>
45
- </head>
46
- <body>
47
- <div id="root"></div>
48
- <script type="module" src="/@fs/${pkgSrcDir}/preview/entry.tsx"></script>
49
- </body>
50
- </html>`;
51
- res.setHeader("Content-Type", "text/html");
52
- res.statusCode = 200;
53
- res.end(html);
54
- });
55
- };
56
- },
57
- resolveId(id) {
58
- if (id === VIRTUAL_DOCUMENTS_ID) {
59
- return RESOLVED_VIRTUAL_DOCUMENTS_ID;
60
- }
61
- },
62
- load(id) {
63
- if (id === RESOLVED_VIRTUAL_DOCUMENTS_ID) {
64
- return `
65
- const pageModules = import.meta.glob('/pdfs/*/pages/**/*.tsx', { eager: true });
66
- const configModules = import.meta.glob('/pdfs/*/config.ts', { eager: true });
67
-
68
- export function getDocuments() {
69
- const documents = {};
70
-
71
- for (const [path, mod] of Object.entries(pageModules)) {
72
- const match = path.match(/^\\/pdfs\\/([^/]+)\\/pages\\/(.+)\\.[^.]+$/);
73
- if (!match) continue;
74
- const [, slug, pageName] = match;
75
- if (!documents[slug]) {
76
- documents[slug] = { slug, pages: {}, config: undefined };
77
- }
78
- documents[slug].pages[pageName] = mod.default;
79
- }
80
-
81
- for (const [path, mod] of Object.entries(configModules)) {
82
- const match = path.match(/^\\/pdfs\\/([^/]+)\\/config\\.ts$/);
83
- if (!match) continue;
84
- const slug = match[1];
85
- if (documents[slug]) {
86
- documents[slug].config = mod.default;
87
- }
88
- }
89
-
90
- return documents;
91
- }
92
-
93
- export function getDocumentSlugs() {
94
- return Object.keys(getDocuments());
95
- }
96
- `;
97
- }
98
- }
99
- };
100
- }
101
- export {
102
- pdfSmithPreviewPlugin
103
- };
104
- //# sourceMappingURL=preview-plugin-QDLEMAEE.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/preview/preview-plugin.ts"],"sourcesContent":["import type { Plugin } from 'vite';\n\nconst VIRTUAL_DOCUMENTS_ID = 'virtual:pdf-smith-documents';\nconst RESOLVED_VIRTUAL_DOCUMENTS_ID = `\\0${VIRTUAL_DOCUMENTS_ID}`;\n\ninterface PreviewPluginOptions {\n pkgSrcDir: string;\n}\n\nexport function pdfSmithPreviewPlugin({ pkgSrcDir }: PreviewPluginOptions): Plugin {\n return {\n name: 'pdf-smith-preview',\n\n configureServer(server) {\n return () => {\n server.middlewares.use((req, res, next) => {\n const url = req.url ?? '';\n\n // Skip file requests, Vite internals, and node_modules\n if (url.includes('.') || url.startsWith('/@') || url.startsWith('/node_modules/')) {\n next();\n return;\n }\n\n const html = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <script type=\"module\">\nimport RefreshRuntime from \"/@react-refresh\"\nRefreshRuntime.injectIntoGlobalHook(window)\nwindow.$RefreshReg$ = () => {}\nwindow.$RefreshSig$ = () => (type) => type\nwindow.__vite_plugin_react_preamble_installed__ = true\n</script>\n <script type=\"module\" src=\"/@vite/client\"></script>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>pdf-smith Preview</title>\n <style>\n @media print {\n [data-pdf-smith-nav] { display: none !important; }\n [data-pdf-smith-container] {\n margin-left: 0 !important;\n padding: 0 !important;\n background: none !important;\n }\n [data-pdf-smith-container] > [data-pdf-smith-document] > div {\n margin-bottom: 0 !important;\n }\n [data-pdf-smith-container] > [data-pdf-smith-document] > div > div:first-child {\n display: none !important;\n }\n }\n </style>\n</head>\n<body>\n <div id=\"root\"></div>\n <script type=\"module\" src=\"/@fs/${pkgSrcDir}/preview/entry.tsx\"></script>\n</body>\n</html>`;\n\n res.setHeader('Content-Type', 'text/html');\n res.statusCode = 200;\n res.end(html);\n });\n };\n },\n\n resolveId(id) {\n if (id === VIRTUAL_DOCUMENTS_ID) {\n return RESOLVED_VIRTUAL_DOCUMENTS_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_DOCUMENTS_ID) {\n return `\nconst pageModules = import.meta.glob('/pdfs/*/pages/**/*.tsx', { eager: true });\nconst configModules = import.meta.glob('/pdfs/*/config.ts', { eager: true });\n\nexport function getDocuments() {\n const documents = {};\n\n for (const [path, mod] of Object.entries(pageModules)) {\n const match = path.match(/^\\\\/pdfs\\\\/([^/]+)\\\\/pages\\\\/(.+)\\\\.[^.]+$/);\n if (!match) continue;\n const [, slug, pageName] = match;\n if (!documents[slug]) {\n documents[slug] = { slug, pages: {}, config: undefined };\n }\n documents[slug].pages[pageName] = mod.default;\n }\n\n for (const [path, mod] of Object.entries(configModules)) {\n const match = path.match(/^\\\\/pdfs\\\\/([^/]+)\\\\/config\\\\.ts$/);\n if (!match) continue;\n const slug = match[1];\n if (documents[slug]) {\n documents[slug].config = mod.default;\n }\n }\n\n return documents;\n}\n\nexport function getDocumentSlugs() {\n return Object.keys(getDocuments());\n}\n`;\n }\n },\n };\n}\n"],"mappings":";AAEA,IAAM,uBAAuB;AAC7B,IAAM,gCAAgC,KAAK,oBAAoB;AAMxD,SAAS,sBAAsB,EAAE,UAAU,GAAiC;AACjF,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,gBAAgB,QAAQ;AACtB,aAAO,MAAM;AACX,eAAO,YAAY,IAAI,CAAC,KAAK,KAAK,SAAS;AACzC,gBAAM,MAAM,IAAI,OAAO;AAGvB,cAAI,IAAI,SAAS,GAAG,KAAK,IAAI,WAAW,IAAI,KAAK,IAAI,WAAW,gBAAgB,GAAG;AACjF,iBAAK;AACL;AAAA,UACF;AAEA,gBAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAiCa,SAAS;AAAA;AAAA;AAInC,cAAI,UAAU,gBAAgB,WAAW;AACzC,cAAI,aAAa;AACjB,cAAI,IAAI,IAAI;AAAA,QACd,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IAEA,UAAU,IAAI;AACZ,UAAI,OAAO,sBAAsB;AAC/B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAI;AACP,UAAI,OAAO,+BAA+B;AACxC,eAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAiCT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}