@ahmedrowaihi/pdf-forge-preview 1.0.0-canary.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.
- package/.next/BUILD_ID +1 -0
- package/.next/app-path-routes-manifest.json +7 -0
- package/.next/build/chunks/[root-of-the-server]__12fb5caf._.js +233 -0
- package/.next/build/chunks/[root-of-the-server]__12fb5caf._.js.map +8 -0
- package/.next/build/chunks/[root-of-the-server]__242deb00._.js +500 -0
- package/.next/build/chunks/[root-of-the-server]__242deb00._.js.map +11 -0
- package/.next/build/chunks/[turbopack-node]_transforms_postcss_ts_ad9a1eec._.js +13 -0
- package/.next/build/chunks/[turbopack-node]_transforms_postcss_ts_ad9a1eec._.js.map +5 -0
- package/.next/build/chunks/[turbopack]_runtime.js +795 -0
- package/.next/build/chunks/[turbopack]_runtime.js.map +10 -0
- package/.next/build/chunks/node_modules__pnpm_806d01c0._.js +6758 -0
- package/.next/build/chunks/node_modules__pnpm_806d01c0._.js.map +47 -0
- package/.next/build/package.json +1 -0
- package/.next/build/postcss.js +6 -0
- package/.next/build/postcss.js.map +5 -0
- package/.next/build-manifest.json +20 -0
- package/.next/diagnostics/build-diagnostics.json +6 -0
- package/.next/diagnostics/framework.json +1 -0
- package/.next/export-marker.json +6 -0
- package/.next/fallback-build-manifest.json +12 -0
- package/.next/images-manifest.json +66 -0
- package/.next/next-minimal-server.js.nft.json +1 -0
- package/.next/next-server.js.nft.json +1 -0
- package/.next/package.json +1 -0
- package/.next/prerender-manifest.json +65 -0
- package/.next/required-server-files.js +163 -0
- package/.next/required-server-files.json +163 -0
- package/.next/routes-manifest.json +77 -0
- package/.next/server/app/_global-error/page/app-paths-manifest.json +3 -0
- package/.next/server/app/_global-error/page/build-manifest.json +17 -0
- package/.next/server/app/_global-error/page/next-font-manifest.json +6 -0
- package/.next/server/app/_global-error/page/react-loadable-manifest.json +1 -0
- package/.next/server/app/_global-error/page/server-reference-manifest.json +4 -0
- package/.next/server/app/_global-error/page.js +11 -0
- package/.next/server/app/_global-error/page.js.map +5 -0
- package/.next/server/app/_global-error/page.js.nft.json +1 -0
- package/.next/server/app/_global-error/page_client-reference-manifest.js +2 -0
- package/.next/server/app/_global-error.html +2 -0
- package/.next/server/app/_global-error.meta +15 -0
- package/.next/server/app/_global-error.rsc +13 -0
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +5 -0
- package/.next/server/app/_global-error.segments/_full.segment.rsc +13 -0
- package/.next/server/app/_global-error.segments/_head.segment.rsc +6 -0
- package/.next/server/app/_global-error.segments/_index.segment.rsc +4 -0
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -0
- package/.next/server/app/_not-found/page/app-paths-manifest.json +3 -0
- package/.next/server/app/_not-found/page/build-manifest.json +17 -0
- package/.next/server/app/_not-found/page/next-font-manifest.json +16 -0
- package/.next/server/app/_not-found/page/react-loadable-manifest.json +1 -0
- package/.next/server/app/_not-found/page/server-reference-manifest.json +20 -0
- package/.next/server/app/_not-found/page.js +14 -0
- package/.next/server/app/_not-found/page.js.map +5 -0
- package/.next/server/app/_not-found/page.js.nft.json +1 -0
- package/.next/server/app/_not-found/page_client-reference-manifest.js +2 -0
- package/.next/server/app/favicon.ico/route/app-paths-manifest.json +3 -0
- package/.next/server/app/favicon.ico/route/build-manifest.json +11 -0
- package/.next/server/app/favicon.ico/route.js +6 -0
- package/.next/server/app/favicon.ico/route.js.map +5 -0
- package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
- package/.next/server/app/favicon.ico.body +0 -0
- package/.next/server/app/favicon.ico.meta +1 -0
- package/.next/server/app/page/app-paths-manifest.json +3 -0
- package/.next/server/app/page/build-manifest.json +17 -0
- package/.next/server/app/page/next-font-manifest.json +16 -0
- package/.next/server/app/page/react-loadable-manifest.json +1 -0
- package/.next/server/app/page/server-reference-manifest.json +20 -0
- package/.next/server/app/page.js +17 -0
- package/.next/server/app/page.js.map +5 -0
- package/.next/server/app/page.js.nft.json +1 -0
- package/.next/server/app/page_client-reference-manifest.js +2 -0
- package/.next/server/app/preview/[...slug]/page/app-paths-manifest.json +3 -0
- package/.next/server/app/preview/[...slug]/page/build-manifest.json +17 -0
- package/.next/server/app/preview/[...slug]/page/next-font-manifest.json +16 -0
- package/.next/server/app/preview/[...slug]/page/react-loadable-manifest.json +1 -0
- package/.next/server/app/preview/[...slug]/page/server-reference-manifest.json +65 -0
- package/.next/server/app/preview/[...slug]/page.js +19 -0
- package/.next/server/app/preview/[...slug]/page.js.map +5 -0
- package/.next/server/app/preview/[...slug]/page.js.nft.json +1 -0
- package/.next/server/app/preview/[...slug]/page_client-reference-manifest.js +2 -0
- package/.next/server/app-paths-manifest.json +7 -0
- package/.next/server/chunks/730ea_preview-server__next-internal_server_app_favicon_ico_route_actions_a71a8ae7.js +3 -0
- package/.next/server/chunks/730ea_preview-server__next-internal_server_app_favicon_ico_route_actions_a71a8ae7.js.map +1 -0
- package/.next/server/chunks/[externals]_next_dist_a6d89067._.js +3 -0
- package/.next/server/chunks/[externals]_next_dist_a6d89067._.js.map +1 -0
- package/.next/server/chunks/[root-of-the-server]__a62cd78d._.js +21 -0
- package/.next/server/chunks/[root-of-the-server]__a62cd78d._.js.map +1 -0
- package/.next/server/chunks/[turbopack]_runtime.js +795 -0
- package/.next/server/chunks/[turbopack]_runtime.js.map +10 -0
- package/.next/server/chunks/ssr/730ea_preview-server__next-internal_server_app__global-error_page_actions_986e2de5.js +3 -0
- package/.next/server/chunks/ssr/730ea_preview-server__next-internal_server_app__global-error_page_actions_986e2de5.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__025eaae9._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__025eaae9._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__1536282c._.js +4 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__1536282c._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__15cf9d36._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__15cf9d36._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__450f653e._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__450f653e._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__4874d0d7._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__4874d0d7._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__49771cdc._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__49771cdc._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__9ff74047._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__9ff74047._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__a9be37b1._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__a9be37b1._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__aeefe74e._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__aeefe74e._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__b13738d2._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__b13738d2._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__bb428c83._.js +4 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__bb428c83._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__c61333e3._.js +10 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__c61333e3._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__cb0c7b1a._.js +4 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__cb0c7b1a._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__dafcae4c._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__dafcae4c._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__e47d0c07._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__e47d0c07._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__ecac8617._.js +31 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__ecac8617._.js.map +1 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__fd4bda25._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__fd4bda25._.js.map +1 -0
- package/.next/server/chunks/ssr/[turbopack]_runtime.js +795 -0
- package/.next/server/chunks/ssr/[turbopack]_runtime.js.map +10 -0
- package/.next/server/chunks/ssr/_19494208._.js +19 -0
- package/.next/server/chunks/ssr/_19494208._.js.map +1 -0
- package/.next/server/chunks/ssr/_810f54e9._.js +4 -0
- package/.next/server/chunks/ssr/_810f54e9._.js.map +1 -0
- package/.next/server/chunks/ssr/_aa01e67e._.js +4 -0
- package/.next/server/chunks/ssr/_aa01e67e._.js.map +1 -0
- package/.next/server/chunks/ssr/_bf10718b._.js +4 -0
- package/.next/server/chunks/ssr/_bf10718b._.js.map +1 -0
- package/.next/server/chunks/ssr/_c57c12df._.js +4 -0
- package/.next/server/chunks/ssr/_c57c12df._.js.map +1 -0
- package/.next/server/chunks/ssr/_d9b57cb8._.js +5 -0
- package/.next/server/chunks/ssr/_d9b57cb8._.js.map +1 -0
- package/.next/server/chunks/ssr/_e2a766a8._.js +3 -0
- package/.next/server/chunks/ssr/_e2a766a8._.js.map +1 -0
- package/.next/server/chunks/ssr/_e2b86512._.js +8 -0
- package/.next/server/chunks/ssr/_e2b86512._.js.map +1 -0
- package/.next/server/chunks/ssr/_ee8ea3aa._.js +19 -0
- package/.next/server/chunks/ssr/_ee8ea3aa._.js.map +1 -0
- package/.next/server/chunks/ssr/e8449_next_dist_5870db32._.js +3 -0
- package/.next/server/chunks/ssr/e8449_next_dist_5870db32._.js.map +1 -0
- package/.next/server/chunks/ssr/e8449_next_dist_client_components_builtin_forbidden_5542069c.js +3 -0
- package/.next/server/chunks/ssr/e8449_next_dist_client_components_builtin_forbidden_5542069c.js.map +1 -0
- package/.next/server/chunks/ssr/e8449_next_dist_client_components_builtin_global-error_d0870f3a.js +3 -0
- package/.next/server/chunks/ssr/e8449_next_dist_client_components_builtin_global-error_d0870f3a.js.map +1 -0
- package/.next/server/chunks/ssr/e8449_next_dist_client_components_builtin_unauthorized_4c01c8d5.js +3 -0
- package/.next/server/chunks/ssr/e8449_next_dist_client_components_builtin_unauthorized_4c01c8d5.js.map +1 -0
- package/.next/server/chunks/ssr/e8449_next_dist_client_components_d90ace34._.js +3 -0
- package/.next/server/chunks/ssr/e8449_next_dist_client_components_d90ace34._.js.map +1 -0
- package/.next/server/chunks/ssr/e8449_next_dist_esm_af7aafb8._.js +6 -0
- package/.next/server/chunks/ssr/e8449_next_dist_esm_af7aafb8._.js.map +1 -0
- package/.next/server/chunks/ssr/e8449_next_dist_esm_build_templates_app-page_f16f0848.js +4 -0
- package/.next/server/chunks/ssr/e8449_next_dist_esm_build_templates_app-page_f16f0848.js.map +1 -0
- package/.next/server/chunks/ssr/e8449_next_dist_f0d8a2cc._.js +4 -0
- package/.next/server/chunks/ssr/e8449_next_dist_f0d8a2cc._.js.map +1 -0
- package/.next/server/chunks/ssr/node_modules__pnpm_37510d96._.js +5 -0
- package/.next/server/chunks/ssr/node_modules__pnpm_37510d96._.js.map +1 -0
- package/.next/server/chunks/ssr/packages_preview-server_src_app_897ecf1c._.js +3 -0
- package/.next/server/chunks/ssr/packages_preview-server_src_app_897ecf1c._.js.map +1 -0
- package/.next/server/chunks/ssr/packages_preview-server_src_e17a2a9b._.js +3 -0
- package/.next/server/chunks/ssr/packages_preview-server_src_e17a2a9b._.js.map +1 -0
- package/.next/server/functions-config-manifest.json +4 -0
- package/.next/server/interception-route-rewrite-manifest.js +1 -0
- package/.next/server/middleware-build-manifest.js +21 -0
- package/.next/server/middleware-manifest.json +6 -0
- package/.next/server/next-font-manifest.js +1 -0
- package/.next/server/next-font-manifest.json +34 -0
- package/.next/server/pages/500.html +2 -0
- package/.next/server/pages-manifest.json +3 -0
- package/.next/server/server-reference-manifest.js +1 -0
- package/.next/server/server-reference-manifest.json +80 -0
- package/.next/static/cdYIhKFtJ0GB-yJK5ywz_/_buildManifest.js +11 -0
- package/.next/static/cdYIhKFtJ0GB-yJK5ywz_/_clientMiddlewareManifest.json +1 -0
- package/.next/static/cdYIhKFtJ0GB-yJK5ywz_/_ssgManifest.js +1 -0
- package/.next/static/chunks/0464c7ff175ee6ff.js +1 -0
- package/.next/static/chunks/10468413db24762a.js +14 -0
- package/.next/static/chunks/2de338262e51ef94.js +3 -0
- package/.next/static/chunks/37adc260f85da877.js +1 -0
- package/.next/static/chunks/521eee9903bc4d1f.js +5 -0
- package/.next/static/chunks/6051bd38272cb442.js +14 -0
- package/.next/static/chunks/8d433d4b9d701456.js +1 -0
- package/.next/static/chunks/92ba72595aad9df6.js +1 -0
- package/.next/static/chunks/959ed978a6e89a66.js +1 -0
- package/.next/static/chunks/a6dad97d9634a72d.js +1 -0
- package/.next/static/chunks/a6dad97d9634a72d.js.map +1 -0
- package/.next/static/chunks/a6db6456c5b75734.js +1 -0
- package/.next/static/chunks/c3ece0a7e3e07076.js +1 -0
- package/.next/static/chunks/d1b29a74f6814a03.css +3 -0
- package/.next/static/chunks/f7ec22614fe1c1fe.js +1 -0
- package/.next/static/chunks/turbopack-e062a8e6d6034eb0.js +4 -0
- package/.next/static/media/1bffadaabf893a1e-s.7cd81963.woff2 +0 -0
- package/.next/static/media/2bbe8d2671613f1f-s.76dcb0b2.woff2 +0 -0
- package/.next/static/media/2c55a0e60120577a-s.2a48534a.woff2 +0 -0
- package/.next/static/media/5476f68d60460930-s.c995e352.woff2 +0 -0
- package/.next/static/media/83afe278b6a6bb3c-s.p.3a6ba036.woff2 +0 -0
- package/.next/static/media/9c72aa0f40e4eef8-s.18a48cbc.woff2 +0 -0
- package/.next/static/media/SFMonoBold-s.p.b90ec775.otf +0 -0
- package/.next/static/media/SFMonoHeavy-s.p.545fe93b.otf +0 -0
- package/.next/static/media/SFMonoLight-s.p.7c5363a6.otf +0 -0
- package/.next/static/media/SFMonoMedium-s.p.a4fc9904.otf +0 -0
- package/.next/static/media/SFMonoRegular-s.p.04ea7bf3.otf +0 -0
- package/.next/static/media/SFMonoSemibold-s.p.2d2ddb43.otf +0 -0
- package/.next/static/media/ad66f9afd8947f86-s.7a40eb73.woff2 +0 -0
- package/.next/static/media/favicon.678eb597.ico +0 -0
- package/.next/static/media/logo.22a370b0.png +0 -0
- package/.next/trace +1 -0
- package/.next/trace-build +1 -0
- package/.next/turbopack +0 -0
- package/.next/types/routes.d.ts +58 -0
- package/.next/types/validator.ts +70 -0
- package/CHANGELOG.md +12 -0
- package/LICENSE.md +8 -0
- package/index.mjs +17 -0
- package/jsx-runtime/jsx-dev-runtime.js +26 -0
- package/module-punycode.d.ts +3 -0
- package/next-env.d.ts +6 -0
- package/next.config.mjs +15 -0
- package/package.json +78 -0
- package/postcss.config.js +5 -0
- package/readme.md +33 -0
- package/scripts/build-preview-server.mts +25 -0
- package/scripts/dev.mts +57 -0
- package/scripts/seed.mts +36 -0
- package/src/actions/export-single-template.ts +74 -0
- package/src/actions/get-template-path-from-slug.ts +32 -0
- package/src/actions/get-templates-directory-metadata-action.ts +19 -0
- package/src/actions/render-template-by-path.tsx +313 -0
- package/src/actions/safe-action.ts +15 -0
- package/src/animated-icons-data/help.json +1082 -0
- package/src/animated-icons-data/link.json +1309 -0
- package/src/animated-icons-data/load.json +443 -0
- package/src/animated-icons-data/mail.json +1320 -0
- package/src/app/env.ts +14 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/fonts/SFMono/SFMonoBold.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoBoldItalic.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoHeavy.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoHeavyItalic.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoLight.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoLightItalic.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoMedium.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoMediumItalic.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoRegular.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoRegularItalic.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoSemibold.otf +0 -0
- package/src/app/fonts/SFMono/SFMonoSemiboldItalic.otf +0 -0
- package/src/app/fonts.ts +39 -0
- package/src/app/globals.css +136 -0
- package/src/app/layout.tsx +46 -0
- package/src/app/logo.png +0 -0
- package/src/app/page.tsx +52 -0
- package/src/app/preview/[...slug]/download-button.tsx +138 -0
- package/src/app/preview/[...slug]/error-overlay.tsx +58 -0
- package/src/app/preview/[...slug]/page.tsx +90 -0
- package/src/app/preview/[...slug]/preview.tsx +249 -0
- package/src/app/preview/[...slug]/template-frame.tsx +68 -0
- package/src/components/button.tsx +101 -0
- package/src/components/code-container.tsx +169 -0
- package/src/components/code-snippet.tsx +9 -0
- package/src/components/code.tsx +185 -0
- package/src/components/heading.tsx +113 -0
- package/src/components/icons/icon-arrow-down.tsx +16 -0
- package/src/components/icons/icon-base.tsx +26 -0
- package/src/components/icons/icon-bug.tsx +19 -0
- package/src/components/icons/icon-button.tsx +23 -0
- package/src/components/icons/icon-check.tsx +19 -0
- package/src/components/icons/icon-clipboard.tsx +40 -0
- package/src/components/icons/icon-cloud-alert.tsx +18 -0
- package/src/components/icons/icon-cloud-check.tsx +17 -0
- package/src/components/icons/icon-download.tsx +19 -0
- package/src/components/icons/icon-file.tsx +19 -0
- package/src/components/icons/icon-folder-open.tsx +19 -0
- package/src/components/icons/icon-folder.tsx +18 -0
- package/src/components/icons/icon-hide-sidebar.tsx +23 -0
- package/src/components/icons/icon-image.tsx +19 -0
- package/src/components/icons/icon-info.tsx +18 -0
- package/src/components/icons/icon-link.tsx +14 -0
- package/src/components/icons/icon-loader.tsx +16 -0
- package/src/components/icons/icon-monitor.tsx +19 -0
- package/src/components/icons/icon-moon.tsx +16 -0
- package/src/components/icons/icon-phone.tsx +26 -0
- package/src/components/icons/icon-reload.tsx +18 -0
- package/src/components/icons/icon-source.tsx +19 -0
- package/src/components/icons/icon-stamp.tsx +14 -0
- package/src/components/icons/icon-sun.tsx +74 -0
- package/src/components/icons/icon-warning.tsx +31 -0
- package/src/components/index.ts +7 -0
- package/src/components/logo.tsx +41 -0
- package/src/components/resizable-wrapper.tsx +269 -0
- package/src/components/shell.tsx +95 -0
- package/src/components/sidebar/file-tree-directory-children.tsx +142 -0
- package/src/components/sidebar/file-tree-directory.tsx +92 -0
- package/src/components/sidebar/file-tree.tsx +31 -0
- package/src/components/sidebar/index.ts +1 -0
- package/src/components/sidebar/sidebar.tsx +46 -0
- package/src/components/text.tsx +99 -0
- package/src/components/toolbar/checking-results.tsx +150 -0
- package/src/components/toolbar/code-preview-line-link.tsx +39 -0
- package/src/components/toolbar/results-table.tsx +0 -0
- package/src/components/toolbar/results.tsx +52 -0
- package/src/components/toolbar/toolbar-button.tsx +52 -0
- package/src/components/toolbar/use-cached-state.ts +36 -0
- package/src/components/toolbar.tsx +182 -0
- package/src/components/tooltip-content.tsx +31 -0
- package/src/components/tooltip.tsx +19 -0
- package/src/components/topbar/active-view-toggle-group.tsx +86 -0
- package/src/components/topbar/emulated-dark-mode-toggle.tsx +58 -0
- package/src/components/topbar/view-size-controls.tsx +173 -0
- package/src/components/topbar.tsx +59 -0
- package/src/contexts/preview.tsx +91 -0
- package/src/contexts/templates.tsx +57 -0
- package/src/contexts/toolbar.tsx +22 -0
- package/src/hooks/use-clamped-state.ts +24 -0
- package/src/hooks/use-fragment-identifier.ts +14 -0
- package/src/hooks/use-hot-reload.ts +31 -0
- package/src/hooks/use-rendering-metadata.ts +37 -0
- package/src/hooks/use-template-rendering-result.ts +58 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/constants.ts +8 -0
- package/src/utils/contains-template.ts +52 -0
- package/src/utils/convert-stack-with-sourcemap.ts +79 -0
- package/src/utils/copy-text-to-clipboard.ts +7 -0
- package/src/utils/create-jsx-runtime.ts +47 -0
- package/src/utils/esbuild/escape-string-for-regex.ts +3 -0
- package/src/utils/esbuild/renderring-utilities-exporter.ts +64 -0
- package/src/utils/get-line-and-column-from-offset.ts +11 -0
- package/src/utils/get-template-component.ts +158 -0
- package/src/utils/get-templates-directory-metadata.ts +195 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/language-map.ts +7 -0
- package/src/utils/load-stream.ts +15 -0
- package/src/utils/register-spinner-autostopping.ts +28 -0
- package/src/utils/result.ts +49 -0
- package/src/utils/run-bundled-code.ts +86 -0
- package/src/utils/sanitize.ts +6 -0
- package/src/utils/sleep.ts +3 -0
- package/src/utils/snake-to-camel.ts +5 -0
- package/src/utils/static-node-modules-for-vm.ts +93 -0
- package/src/utils/style-text.ts +11 -0
- package/src/utils/types/as.ts +26 -0
- package/src/utils/types/error-object.ts +11 -0
- package/src/utils/types/hot-reload-change.ts +13 -0
- package/src/utils/types/template.ts +8 -0
- package/src/utils/unreachable.ts +8 -0
- package/templates/.gitkeep +0 -0
- package/tsconfig.json +47 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { use } from 'react';
|
|
4
|
+
import { cn } from '../utils';
|
|
5
|
+
import { Heading } from './heading';
|
|
6
|
+
import { IconHideSidebar } from './icons/icon-hide-sidebar';
|
|
7
|
+
import { ShellContext } from './shell';
|
|
8
|
+
import { Tooltip } from './tooltip';
|
|
9
|
+
|
|
10
|
+
interface TopbarProps extends React.ComponentProps<'header'> {
|
|
11
|
+
templateTitle: string;
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const Topbar = ({
|
|
16
|
+
templateTitle,
|
|
17
|
+
children,
|
|
18
|
+
className,
|
|
19
|
+
...props
|
|
20
|
+
}: TopbarProps) => {
|
|
21
|
+
const { toggleSidebar } = use(ShellContext)!;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Tooltip.Provider>
|
|
25
|
+
<header
|
|
26
|
+
{...props}
|
|
27
|
+
className={cn(
|
|
28
|
+
'flex h-14 items-center justify-between gap-3 border-slate-6 border-b px-3 py-2',
|
|
29
|
+
className,
|
|
30
|
+
)}
|
|
31
|
+
>
|
|
32
|
+
<div className="flex w-fit items-center gap-3">
|
|
33
|
+
<Tooltip>
|
|
34
|
+
<Tooltip.Trigger asChild>
|
|
35
|
+
<button
|
|
36
|
+
className="hidden rounded-lg px-2 py-2 text-slate-11 transition duration-200 ease-in-out hover:bg-slate-5 hover:text-slate-12 lg:flex"
|
|
37
|
+
onClick={() => {
|
|
38
|
+
toggleSidebar();
|
|
39
|
+
}}
|
|
40
|
+
type="button"
|
|
41
|
+
>
|
|
42
|
+
<IconHideSidebar height={20} width={20} />
|
|
43
|
+
</button>
|
|
44
|
+
</Tooltip.Trigger>
|
|
45
|
+
<Tooltip.Content>Show/hide sidebar</Tooltip.Content>
|
|
46
|
+
</Tooltip>
|
|
47
|
+
<div className="hidden items-center overflow-hidden text-center lg:flex">
|
|
48
|
+
<Heading as="h2" className="truncate" size="2" weight="medium">
|
|
49
|
+
{templateTitle}
|
|
50
|
+
</Heading>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
<div className="flex w-full items-center justify-between gap-3 lg:w-fit lg:justify-start">
|
|
54
|
+
{children}
|
|
55
|
+
</div>
|
|
56
|
+
</header>
|
|
57
|
+
</Tooltip.Provider>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useRouter } from 'next/navigation';
|
|
3
|
+
import { createContext, useContext } from 'react';
|
|
4
|
+
import type {
|
|
5
|
+
RenderedTemplateMetadata,
|
|
6
|
+
TemplateRenderingResult,
|
|
7
|
+
} from '../actions/render-template-by-path';
|
|
8
|
+
import { isBuilding, isPreviewDevelopment } from '../app/env';
|
|
9
|
+
import { useHotreload } from '../hooks/use-hot-reload';
|
|
10
|
+
import { useRenderingMetadata } from '../hooks/use-rendering-metadata';
|
|
11
|
+
import { useTemplateRenderingResult } from '../hooks/use-template-rendering-result';
|
|
12
|
+
|
|
13
|
+
export const PreviewContext = createContext<
|
|
14
|
+
| {
|
|
15
|
+
renderedTemplateMetadata: RenderedTemplateMetadata | undefined;
|
|
16
|
+
renderingResult: TemplateRenderingResult;
|
|
17
|
+
|
|
18
|
+
templateSlug: string;
|
|
19
|
+
templatePath: string;
|
|
20
|
+
}
|
|
21
|
+
| undefined
|
|
22
|
+
>(undefined);
|
|
23
|
+
|
|
24
|
+
interface PreviewProvider {
|
|
25
|
+
templateSlug: string;
|
|
26
|
+
templatePath: string;
|
|
27
|
+
|
|
28
|
+
serverRenderingResult: TemplateRenderingResult;
|
|
29
|
+
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const PreviewProvider = ({
|
|
34
|
+
templateSlug,
|
|
35
|
+
templatePath,
|
|
36
|
+
serverRenderingResult,
|
|
37
|
+
children,
|
|
38
|
+
}: PreviewProvider) => {
|
|
39
|
+
const router = useRouter();
|
|
40
|
+
|
|
41
|
+
const renderingResult = useTemplateRenderingResult(
|
|
42
|
+
templatePath,
|
|
43
|
+
serverRenderingResult,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const renderedTemplateMetadata = useRenderingMetadata(
|
|
47
|
+
templatePath,
|
|
48
|
+
renderingResult,
|
|
49
|
+
serverRenderingResult,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (!isBuilding && !isPreviewDevelopment) {
|
|
53
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: this will not change on runtime so it doesn't violate the rules of hooks
|
|
54
|
+
useHotreload((changes) => {
|
|
55
|
+
const changeForThisTemplate = changes.find((change) =>
|
|
56
|
+
change.filename.includes(templateSlug),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (typeof changeForThisTemplate !== 'undefined') {
|
|
60
|
+
if (changeForThisTemplate.event === 'unlink') {
|
|
61
|
+
router.push('/');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<PreviewContext.Provider
|
|
69
|
+
value={{
|
|
70
|
+
templatePath,
|
|
71
|
+
templateSlug,
|
|
72
|
+
renderedTemplateMetadata,
|
|
73
|
+
renderingResult,
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
{children}
|
|
77
|
+
</PreviewContext.Provider>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const usePreviewContext = () => {
|
|
82
|
+
const previewContext = useContext(PreviewContext);
|
|
83
|
+
|
|
84
|
+
if (typeof previewContext === 'undefined') {
|
|
85
|
+
throw new Error(
|
|
86
|
+
'Cannot call `usePreviewContext` outside of an `PreviewContext` provider.',
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return previewContext;
|
|
91
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext, useState } from 'react';
|
|
4
|
+
import { getTemplatesDirectoryMetadataAction } from '../actions/get-templates-directory-metadata-action';
|
|
5
|
+
import { isBuilding, isPreviewDevelopment } from '../app/env';
|
|
6
|
+
import { useHotreload } from '../hooks/use-hot-reload';
|
|
7
|
+
import type { TemplatesDirectory } from '../utils/get-templates-directory-metadata';
|
|
8
|
+
|
|
9
|
+
const TemplatesContext = createContext<
|
|
10
|
+
| {
|
|
11
|
+
templatesDirectoryMetadata: TemplatesDirectory;
|
|
12
|
+
}
|
|
13
|
+
| undefined
|
|
14
|
+
>(undefined);
|
|
15
|
+
|
|
16
|
+
export const useTemplates = () => {
|
|
17
|
+
const providerValue = useContext(TemplatesContext);
|
|
18
|
+
|
|
19
|
+
if (typeof providerValue === 'undefined') {
|
|
20
|
+
throw new Error(
|
|
21
|
+
'Cannot call `useTemplates` outside of a `TemplatesContext` provider.',
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return providerValue;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const TemplatesProvider = (props: {
|
|
29
|
+
initialTemplatesDirectoryMetadata: TemplatesDirectory;
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
}) => {
|
|
32
|
+
const [templatesDirectoryMetadata, setTemplatesDirectoryMetadata] =
|
|
33
|
+
useState<TemplatesDirectory>(props.initialTemplatesDirectoryMetadata);
|
|
34
|
+
|
|
35
|
+
if (!isBuilding && !isPreviewDevelopment) {
|
|
36
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: this will not change on runtime so it doesn't violate the rules of hooks
|
|
37
|
+
useHotreload(() => {
|
|
38
|
+
void getTemplatesDirectoryMetadataAction(
|
|
39
|
+
props.initialTemplatesDirectoryMetadata.absolutePath,
|
|
40
|
+
).then((metadata) => {
|
|
41
|
+
if (metadata) {
|
|
42
|
+
setTemplatesDirectoryMetadata(metadata);
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error(
|
|
45
|
+
'Hot reloading: unable to find the templates directory to update the sidebar',
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<TemplatesContext.Provider value={{ templatesDirectoryMetadata }}>
|
|
54
|
+
{props.children}
|
|
55
|
+
</TemplatesContext.Provider>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { createContext, use } from 'react';
|
|
4
|
+
|
|
5
|
+
const ToolbarContext = createContext<undefined>(undefined);
|
|
6
|
+
|
|
7
|
+
interface ToolbarProviderProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function ToolbarProvider({ children }: ToolbarProviderProps) {
|
|
12
|
+
return (
|
|
13
|
+
<ToolbarContext.Provider value={undefined}>
|
|
14
|
+
{children}
|
|
15
|
+
</ToolbarContext.Provider>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const useToolbarContext = () => {
|
|
20
|
+
const previewContext = use(ToolbarContext);
|
|
21
|
+
return previewContext;
|
|
22
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
const clamp = (v: number, min: number, max: number) => {
|
|
4
|
+
return Math.min(Math.max(v, min), max);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const useClampedState = (initial: number, min: number, max: number) => {
|
|
8
|
+
const [v, setV] = useState(initial);
|
|
9
|
+
|
|
10
|
+
return [
|
|
11
|
+
clamp(v, min, max),
|
|
12
|
+
(valueOrFunction: number | ((v: number) => number)) => {
|
|
13
|
+
if (typeof valueOrFunction === 'function') {
|
|
14
|
+
setV((value: number) => {
|
|
15
|
+
const currentValue = clamp(value, min, max);
|
|
16
|
+
|
|
17
|
+
return clamp(valueOrFunction(currentValue), min, max);
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
setV(clamp(valueOrFunction, min, max));
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
] as const;
|
|
24
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { usePathname, useSearchParams } from 'next/navigation';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
export const useFragmentIdentifier = () => {
|
|
5
|
+
const pathname = usePathname();
|
|
6
|
+
const searchParams = useSearchParams();
|
|
7
|
+
const [fragmentIdentifier, setFragmentIdentifier] = useState<string>();
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setFragmentIdentifier(global.location?.hash);
|
|
11
|
+
}, [pathname, searchParams]);
|
|
12
|
+
|
|
13
|
+
return fragmentIdentifier;
|
|
14
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { io, type Socket } from 'socket.io-client';
|
|
5
|
+
import type { HotReloadChange } from '../utils/types/hot-reload-change';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook that detects any "reload" event sent from the CLI's web socket
|
|
9
|
+
* and calls the received parameter callback
|
|
10
|
+
*/
|
|
11
|
+
export const useHotreload = (
|
|
12
|
+
onShouldReload: (changes: HotReloadChange[]) => void,
|
|
13
|
+
) => {
|
|
14
|
+
const socketRef = useRef<Socket | null>(null);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!socketRef.current) {
|
|
18
|
+
socketRef.current = io();
|
|
19
|
+
}
|
|
20
|
+
const socket = socketRef.current;
|
|
21
|
+
|
|
22
|
+
socket.on('reload', (changes: HotReloadChange[]) => {
|
|
23
|
+
console.debug('Reloading...');
|
|
24
|
+
void onShouldReload(changes);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return () => {
|
|
28
|
+
socket.off();
|
|
29
|
+
};
|
|
30
|
+
}, [onShouldReload]);
|
|
31
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
RenderedTemplateMetadata,
|
|
4
|
+
TemplateRenderingResult,
|
|
5
|
+
} from '../actions/render-template-by-path';
|
|
6
|
+
|
|
7
|
+
const lastRenderingMetadataPerTemplatePath = {} as Record<
|
|
8
|
+
string,
|
|
9
|
+
RenderedTemplateMetadata
|
|
10
|
+
>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns the rendering metadata if the given `renderingResult`
|
|
14
|
+
* does not error. If it does error it returns the last value it had for the hook.
|
|
15
|
+
*/
|
|
16
|
+
export const useRenderingMetadata = (
|
|
17
|
+
templatePath: string,
|
|
18
|
+
renderingResult: TemplateRenderingResult,
|
|
19
|
+
serverRenderingMetadata: TemplateRenderingResult,
|
|
20
|
+
): RenderedTemplateMetadata | undefined => {
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if ('markup' in renderingResult) {
|
|
23
|
+
lastRenderingMetadataPerTemplatePath[templatePath] = renderingResult;
|
|
24
|
+
} else if (
|
|
25
|
+
typeof serverRenderingMetadata !== 'undefined' &&
|
|
26
|
+
'markup' in serverRenderingMetadata &&
|
|
27
|
+
typeof lastRenderingMetadataPerTemplatePath[templatePath] === 'undefined'
|
|
28
|
+
) {
|
|
29
|
+
lastRenderingMetadataPerTemplatePath[templatePath] =
|
|
30
|
+
serverRenderingMetadata;
|
|
31
|
+
}
|
|
32
|
+
}, [renderingResult, templatePath, serverRenderingMetadata]);
|
|
33
|
+
|
|
34
|
+
return 'error' in renderingResult
|
|
35
|
+
? lastRenderingMetadataPerTemplatePath[templatePath]
|
|
36
|
+
: renderingResult;
|
|
37
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { getTemplatePathFromSlug } from '../actions/get-template-path-from-slug';
|
|
3
|
+
import {
|
|
4
|
+
renderTemplateByPath,
|
|
5
|
+
type TemplateRenderingResult,
|
|
6
|
+
} from '../actions/render-template-by-path';
|
|
7
|
+
import { isBuilding, isPreviewDevelopment } from '../app/env';
|
|
8
|
+
import { useTemplates } from '../contexts/templates';
|
|
9
|
+
import { containsTemplate } from '../utils/contains-template';
|
|
10
|
+
import { useHotreload } from './use-hot-reload';
|
|
11
|
+
|
|
12
|
+
export const useTemplateRenderingResult = (
|
|
13
|
+
templatePath: string,
|
|
14
|
+
serverTemplateRenderedResult: TemplateRenderingResult,
|
|
15
|
+
) => {
|
|
16
|
+
const [renderingResult, setRenderingResult] = useState(
|
|
17
|
+
serverTemplateRenderedResult,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const { templatesDirectoryMetadata } = useTemplates();
|
|
21
|
+
|
|
22
|
+
if (!isBuilding && !isPreviewDevelopment) {
|
|
23
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: This is fine since isBuilding does not change at runtime
|
|
24
|
+
useHotreload(async (changes) => {
|
|
25
|
+
for await (const change of changes) {
|
|
26
|
+
const relativePathForChangedFile =
|
|
27
|
+
// ex: apple-receipt.tsx
|
|
28
|
+
// it will be the path relative to the templates directory, so it is already
|
|
29
|
+
// going to be equivalent to the slug
|
|
30
|
+
change.filename;
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
!containsTemplate(
|
|
34
|
+
relativePathForChangedFile,
|
|
35
|
+
templatesDirectoryMetadata,
|
|
36
|
+
)
|
|
37
|
+
) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const pathForChangedTemplate = await getTemplatePathFromSlug(
|
|
42
|
+
relativePathForChangedFile,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const newRenderingResult = await renderTemplateByPath(
|
|
46
|
+
pathForChangedTemplate,
|
|
47
|
+
true,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (pathForChangedTemplate === templatePath) {
|
|
51
|
+
setRenderingResult(newRenderingResult);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return renderingResult;
|
|
58
|
+
};
|
package/src/utils/cn.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { TemplatesDirectory } from './get-templates-directory-metadata';
|
|
2
|
+
|
|
3
|
+
export const removeFilenameExtension = (filename: string): string => {
|
|
4
|
+
const parts = filename.split('.');
|
|
5
|
+
|
|
6
|
+
if (parts.length > 1) {
|
|
7
|
+
return parts.slice(0, -1).join('.');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return filename;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const containsTemplate = (
|
|
14
|
+
relativeTemplatePath: string,
|
|
15
|
+
directory: TemplatesDirectory,
|
|
16
|
+
) => {
|
|
17
|
+
const templatePathSegments = relativeTemplatePath
|
|
18
|
+
.replace(directory.relativePath, '')
|
|
19
|
+
.split('/')
|
|
20
|
+
.filter(Boolean);
|
|
21
|
+
|
|
22
|
+
return containsTemplatePathSegments(templatePathSegments, directory);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const containsTemplatePathSegments = (
|
|
26
|
+
relativeTemplateSegments: string[],
|
|
27
|
+
directory: TemplatesDirectory,
|
|
28
|
+
) => {
|
|
29
|
+
if (relativeTemplateSegments.length === 1) {
|
|
30
|
+
const templateFilename = removeFilenameExtension(
|
|
31
|
+
relativeTemplateSegments[0]!,
|
|
32
|
+
);
|
|
33
|
+
return directory.templateFilenames.includes(templateFilename);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const remainingPath = relativeTemplateSegments.join('/');
|
|
37
|
+
|
|
38
|
+
for (const subDirectory of directory.subDirectories) {
|
|
39
|
+
if (remainingPath.startsWith(subDirectory.directoryName)) {
|
|
40
|
+
const matchedSegments = subDirectory.directoryName
|
|
41
|
+
.split('/')
|
|
42
|
+
.filter(Boolean).length;
|
|
43
|
+
|
|
44
|
+
return containsTemplatePathSegments(
|
|
45
|
+
relativeTemplateSegments.slice(matchedSegments),
|
|
46
|
+
subDirectory,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return false;
|
|
52
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { type RawSourceMap, SourceMapConsumer } from 'source-map-js';
|
|
3
|
+
import * as stackTraceParser from 'stacktrace-parser';
|
|
4
|
+
|
|
5
|
+
export const convertStackWithSourceMap = (
|
|
6
|
+
rawStack: string | undefined,
|
|
7
|
+
|
|
8
|
+
originalFilePath: string,
|
|
9
|
+
sourceMapToOriginalFile: RawSourceMap,
|
|
10
|
+
): string | undefined => {
|
|
11
|
+
let stack: string | undefined;
|
|
12
|
+
|
|
13
|
+
const sourceRoot =
|
|
14
|
+
sourceMapToOriginalFile.sourceRoot ?? path.dirname(originalFilePath);
|
|
15
|
+
|
|
16
|
+
const getStackLineFromMethodNameAndSource = (
|
|
17
|
+
methodName: string,
|
|
18
|
+
source: string,
|
|
19
|
+
line: number | undefined | null,
|
|
20
|
+
column: number | undefined | null,
|
|
21
|
+
) => {
|
|
22
|
+
const columnAndLine =
|
|
23
|
+
column || line
|
|
24
|
+
? `${line ?? ''}${line && column ? ':' : ''}${column ?? ''}`
|
|
25
|
+
: undefined;
|
|
26
|
+
const sourceToDisplay = path.relative(sourceRoot, source);
|
|
27
|
+
return methodName === '<unknown>'
|
|
28
|
+
? ` at ${sourceToDisplay}${columnAndLine ? `:${columnAndLine}` : ''}`
|
|
29
|
+
: ` at ${methodName} (${sourceToDisplay}${
|
|
30
|
+
columnAndLine ? `:${columnAndLine}` : ''
|
|
31
|
+
})`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (rawStack) {
|
|
35
|
+
const parsedStack = stackTraceParser.parse(rawStack);
|
|
36
|
+
const sourceMapConsumer = new SourceMapConsumer(sourceMapToOriginalFile);
|
|
37
|
+
const newStackLines = [] as string[];
|
|
38
|
+
for (const stackFrame of parsedStack) {
|
|
39
|
+
if (stackFrame.file === originalFilePath) {
|
|
40
|
+
if (stackFrame.column || stackFrame.lineNumber) {
|
|
41
|
+
const positionWithError = sourceMapConsumer.originalPositionFor({
|
|
42
|
+
column: stackFrame.column ?? 0,
|
|
43
|
+
line: stackFrame.lineNumber ?? 0,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
newStackLines.push(
|
|
47
|
+
getStackLineFromMethodNameAndSource(
|
|
48
|
+
stackFrame.methodName,
|
|
49
|
+
// This can actually be null
|
|
50
|
+
positionWithError.source ?? stackFrame.file,
|
|
51
|
+
positionWithError.line,
|
|
52
|
+
positionWithError.column,
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
} else {
|
|
56
|
+
newStackLines.push(
|
|
57
|
+
getStackLineFromMethodNameAndSource(
|
|
58
|
+
stackFrame.methodName,
|
|
59
|
+
stackFrame.file,
|
|
60
|
+
stackFrame.lineNumber,
|
|
61
|
+
stackFrame.column,
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
} else if (stackFrame.file) {
|
|
66
|
+
const stackLine = getStackLineFromMethodNameAndSource(
|
|
67
|
+
stackFrame.methodName,
|
|
68
|
+
stackFrame.file,
|
|
69
|
+
stackFrame.lineNumber,
|
|
70
|
+
stackFrame.column,
|
|
71
|
+
);
|
|
72
|
+
newStackLines.push(stackLine);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
stack = newStackLines.join('\n');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return stack;
|
|
79
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import esbuild from 'esbuild';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Bundles the JSX runtime with the specified {@link cwd}. This is needed because the JSX runtime
|
|
7
|
+
* imports React's which is forcefully the production one if the `NODE_ENV` is set to `production`,
|
|
8
|
+
* even though we want to use the development one.
|
|
9
|
+
*
|
|
10
|
+
* It bundles into `/node_modules/.react-pdf-jsx-runtime` with the root being the {@link cwd}.
|
|
11
|
+
*/
|
|
12
|
+
export const createJsxRuntime = async (
|
|
13
|
+
cwd: string,
|
|
14
|
+
originalJsxRuntimePath: string,
|
|
15
|
+
) => {
|
|
16
|
+
const jsxRuntimePath = path.join(
|
|
17
|
+
cwd,
|
|
18
|
+
'node_modules',
|
|
19
|
+
'.react-pdf-jsx-runtime',
|
|
20
|
+
);
|
|
21
|
+
if (!fs.existsSync(jsxRuntimePath)) {
|
|
22
|
+
await fs.promises.mkdir(jsxRuntimePath, {
|
|
23
|
+
recursive: true,
|
|
24
|
+
});
|
|
25
|
+
await fs.promises.writeFile(
|
|
26
|
+
path.join(jsxRuntimePath, 'package.json'),
|
|
27
|
+
'{"type": "commonjs"}',
|
|
28
|
+
'utf8',
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
await esbuild.build({
|
|
32
|
+
bundle: true,
|
|
33
|
+
outfile: path.join(jsxRuntimePath, 'jsx-dev-runtime.js'),
|
|
34
|
+
format: 'cjs',
|
|
35
|
+
logLevel: 'silent',
|
|
36
|
+
stdin: {
|
|
37
|
+
resolveDir: cwd,
|
|
38
|
+
sourcefile: 'jsx-dev-runtime.js',
|
|
39
|
+
loader: 'js',
|
|
40
|
+
contents: await fs.promises.readFile(
|
|
41
|
+
path.join(originalJsxRuntimePath, 'jsx-dev-runtime.js'),
|
|
42
|
+
),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return jsxRuntimePath;
|
|
47
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import type { Loader, PluginBuild, ResolveOptions } from 'esbuild';
|
|
4
|
+
import { escapeStringForRegex } from './escape-string-for-regex';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Made to export the `render` function out of the user's PDF template
|
|
8
|
+
* so that issues like React version mismatches don't
|
|
9
|
+
* happen.
|
|
10
|
+
*
|
|
11
|
+
* This also exports the `createElement` from the user's React version as well
|
|
12
|
+
* to avoid mismatches.
|
|
13
|
+
*
|
|
14
|
+
* This avoids multiple versions of React being involved, i.e., the version
|
|
15
|
+
* in the CLI vs. the version the user has on their templates.
|
|
16
|
+
*/
|
|
17
|
+
export const renderingUtilitiesExporter = (pdfTemplates: string[]) => ({
|
|
18
|
+
name: 'rendering-utilities-exporter',
|
|
19
|
+
setup: async (b: PluginBuild) => {
|
|
20
|
+
const filterOptions = await Promise.all(
|
|
21
|
+
pdfTemplates.map(async (templatePath) =>
|
|
22
|
+
escapeStringForRegex(await fs.realpath(templatePath)),
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
b.onLoad(
|
|
26
|
+
{
|
|
27
|
+
filter: new RegExp(filterOptions.join('|')),
|
|
28
|
+
},
|
|
29
|
+
async ({ path: pathToFile }) => {
|
|
30
|
+
return {
|
|
31
|
+
contents: `${await fs.readFile(pathToFile, 'utf8')};
|
|
32
|
+
export { render } from 'react-pdf-module-that-will-export-render'
|
|
33
|
+
export { createElement as reactPDFCreateReactElement } from 'react';
|
|
34
|
+
`,
|
|
35
|
+
loader: path.extname(pathToFile).slice(1) as Loader,
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
b.onResolve(
|
|
41
|
+
{ filter: /^react-pdf-module-that-will-export-render$/ },
|
|
42
|
+
async (args) => {
|
|
43
|
+
const options: ResolveOptions = {
|
|
44
|
+
kind: 'import-statement',
|
|
45
|
+
importer: args.importer,
|
|
46
|
+
resolveDir: args.resolveDir,
|
|
47
|
+
namespace: args.namespace,
|
|
48
|
+
};
|
|
49
|
+
let result = await b.resolve('@ahmedrowaihi/pdf-forge-core', options);
|
|
50
|
+
if (result.errors.length === 0) {
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// If @ahmedrowaihi/pdf-forge-core does not exist, resolve to @ahmedrowaihi/pdf-forge-components
|
|
55
|
+
result = await b.resolve('@ahmedrowaihi/pdf-forge-components', options);
|
|
56
|
+
if (result.errors.length > 0 && result.errors[0]) {
|
|
57
|
+
result.errors[0].text =
|
|
58
|
+
"Failed trying to import `render` from either `@ahmedrowaihi/pdf-forge-core` or `@ahmedrowaihi/pdf-forge-components` to be able to render your PDF template.\n Maybe you don't have either of them installed?";
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const getLineAndColumnFromOffset = (
|
|
2
|
+
offset: number,
|
|
3
|
+
content: string,
|
|
4
|
+
): [line: number, column: number] => {
|
|
5
|
+
const lineBreaks = [...content.slice(0, offset).matchAll(/\n|\r|\r\n/g)];
|
|
6
|
+
|
|
7
|
+
const line = lineBreaks.length + 1;
|
|
8
|
+
const column = offset - (lineBreaks[lineBreaks.length - 1]?.index ?? 0);
|
|
9
|
+
|
|
10
|
+
return [line, column];
|
|
11
|
+
};
|