@react-email/preview-server 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.
Files changed (265) hide show
  1. package/.next/BUILD_ID +1 -0
  2. package/.next/app-build-manifest.json +44 -0
  3. package/.next/app-path-routes-manifest.json +6 -0
  4. package/.next/build-manifest.json +33 -0
  5. package/.next/diagnostics/build-diagnostics.json +6 -0
  6. package/.next/diagnostics/framework.json +1 -0
  7. package/.next/export-marker.json +6 -0
  8. package/.next/images-manifest.json +57 -0
  9. package/.next/next-minimal-server.js.nft.json +1 -0
  10. package/.next/next-server.js.nft.json +1 -0
  11. package/.next/package.json +1 -0
  12. package/.next/prerender-manifest.json +41 -0
  13. package/.next/react-loadable-manifest.json +1 -0
  14. package/.next/required-server-files.json +311 -0
  15. package/.next/routes-manifest.json +64 -0
  16. package/.next/server/app/_not-found/page.js +1 -0
  17. package/.next/server/app/_not-found/page.js.nft.json +1 -0
  18. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
  19. package/.next/server/app/favicon.ico/route.js +1 -0
  20. package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
  21. package/.next/server/app/favicon.ico.body +0 -0
  22. package/.next/server/app/favicon.ico.meta +1 -0
  23. package/.next/server/app/page.js +1 -0
  24. package/.next/server/app/page.js.nft.json +1 -0
  25. package/.next/server/app/page_client-reference-manifest.js +1 -0
  26. package/.next/server/app/preview/[...slug]/page.js +321 -0
  27. package/.next/server/app/preview/[...slug]/page.js.nft.json +1 -0
  28. package/.next/server/app/preview/[...slug]/page_client-reference-manifest.js +1 -0
  29. package/.next/server/app-paths-manifest.json +6 -0
  30. package/.next/server/chunks/134.js +6 -0
  31. package/.next/server/chunks/235.js +15 -0
  32. package/.next/server/chunks/278.js +1 -0
  33. package/.next/server/chunks/343.js +20 -0
  34. package/.next/server/chunks/428.js +14 -0
  35. package/.next/server/chunks/963.js +1 -0
  36. package/.next/server/chunks/999.js +1 -0
  37. package/.next/server/functions-config-manifest.json +4 -0
  38. package/.next/server/interception-route-rewrite-manifest.js +1 -0
  39. package/.next/server/middleware-build-manifest.js +1 -0
  40. package/.next/server/middleware-manifest.json +6 -0
  41. package/.next/server/middleware-react-loadable-manifest.js +1 -0
  42. package/.next/server/next-font-manifest.js +1 -0
  43. package/.next/server/next-font-manifest.json +1 -0
  44. package/.next/server/pages/500.html +1 -0
  45. package/.next/server/pages/_app.js +1 -0
  46. package/.next/server/pages/_app.js.nft.json +1 -0
  47. package/.next/server/pages/_document.js +1 -0
  48. package/.next/server/pages/_document.js.nft.json +1 -0
  49. package/.next/server/pages/_error.js +1 -0
  50. package/.next/server/pages/_error.js.nft.json +1 -0
  51. package/.next/server/pages-manifest.json +5 -0
  52. package/.next/server/server-reference-manifest.js +1 -0
  53. package/.next/server/server-reference-manifest.json +1 -0
  54. package/.next/server/webpack-runtime.js +1 -0
  55. package/.next/static/VkyJa9K30jCrKBesOgrQT/_buildManifest.js +1 -0
  56. package/.next/static/VkyJa9K30jCrKBesOgrQT/_ssgManifest.js +1 -0
  57. package/.next/static/chunks/107-3043079e7cb8bcae.js +1 -0
  58. package/.next/static/chunks/293-67391ef0e44ffa4f.js +1 -0
  59. package/.next/static/chunks/3bd82e28-cda2c00a924937c5.js +1 -0
  60. package/.next/static/chunks/45-1021fac82f766268.js +1 -0
  61. package/.next/static/chunks/484-1969fe871b27074e.js +1 -0
  62. package/.next/static/chunks/484-e02de792ff5f9ea5.js +1 -0
  63. package/.next/static/chunks/589-817d8691661d370e.js +1 -0
  64. package/.next/static/chunks/902-c34acb56733e0ce1.js +1 -0
  65. package/.next/static/chunks/app/_not-found/page-4cbc7dce3ad33336.js +1 -0
  66. package/.next/static/chunks/app/layout-74628781c0b7e7bf.js +1 -0
  67. package/.next/static/chunks/app/layout-daeba68330ab58bb.js +1 -0
  68. package/.next/static/chunks/app/page-55cf199b7ca71958.js +1 -0
  69. package/.next/static/chunks/app/preview/[...slug]/page-07dd9a701d0b3e56.js +1 -0
  70. package/.next/static/chunks/app/preview/[...slug]/page-61b0ea70a8d72916.js +1 -0
  71. package/.next/static/chunks/f33a14d2-ec7c5f0b91818561.js +6 -0
  72. package/.next/static/chunks/framework-b887e9fc751a9906.js +1 -0
  73. package/.next/static/chunks/main-9a03e7ba8acb1900.js +1 -0
  74. package/.next/static/chunks/main-app-5bc2d814f500db60.js +1 -0
  75. package/.next/static/chunks/pages/_app-542a93a5a214e1c0.js +1 -0
  76. package/.next/static/chunks/pages/_error-d5fe1b1612642f76.js +1 -0
  77. package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  78. package/.next/static/chunks/webpack-31c45daa2bd82a7b.js +1 -0
  79. package/.next/static/css/35e8811589f0962b.css +3 -0
  80. package/.next/static/j4oDiQwPKPQgK5jAoiUTk/_buildManifest.js +1 -0
  81. package/.next/static/j4oDiQwPKPQgK5jAoiUTk/_ssgManifest.js +1 -0
  82. package/.next/static/media/05613964ce6c782e-s.p.otf +0 -0
  83. package/.next/static/media/11c6126b9369e85e-s.p.otf +0 -0
  84. package/.next/static/media/26a46d62cd723877-s.woff2 +0 -0
  85. package/.next/static/media/26cb97734d8cb717-s.p.otf +0 -0
  86. package/.next/static/media/55c55f0601d81cf3-s.woff2 +0 -0
  87. package/.next/static/media/581909926a08bbc8-s.woff2 +0 -0
  88. package/.next/static/media/6d93bde91c0c2823-s.woff2 +0 -0
  89. package/.next/static/media/97e0cb1ae144a2a9-s.woff2 +0 -0
  90. package/.next/static/media/a34f9d1faa5f3315-s.p.woff2 +0 -0
  91. package/.next/static/media/bb6462617151f6b7-s.p.otf +0 -0
  92. package/.next/static/media/cf6daef822ab0142-s.p.otf +0 -0
  93. package/.next/static/media/df0a9ae256c0569c-s.woff2 +0 -0
  94. package/.next/static/media/e4051546b3043204-s.p.otf +0 -0
  95. package/.next/static/media/logo.2ce2a759.png +0 -0
  96. package/.next/trace +27 -0
  97. package/.next/types/app/layout.ts +84 -0
  98. package/.next/types/app/page.ts +84 -0
  99. package/.next/types/app/preview/[...slug]/page.ts +84 -0
  100. package/.next/types/cache-life.d.ts +141 -0
  101. package/.next/types/package.json +1 -0
  102. package/_index.js +4 -0
  103. package/license.md +7 -0
  104. package/module-punycode.d.ts +3 -0
  105. package/next-env.d.ts +5 -0
  106. package/next.config.js +22 -0
  107. package/package.json +82 -0
  108. package/postcss.config.js +8 -0
  109. package/scripts/build-preview-server.mjs +29 -0
  110. package/scripts/fill-caniemail-data.mjs +36 -0
  111. package/src/actions/email-validation/caniemail-data.ts +85993 -0
  112. package/src/actions/email-validation/check-compatibility.ts +333 -0
  113. package/src/actions/email-validation/check-images.spec.tsx +100 -0
  114. package/src/actions/email-validation/check-images.ts +160 -0
  115. package/src/actions/email-validation/check-links.spec.tsx +113 -0
  116. package/src/actions/email-validation/check-links.ts +113 -0
  117. package/src/actions/email-validation/get-code-location-from-ast-element.ts +18 -0
  118. package/src/actions/email-validation/quick-fetch.ts +14 -0
  119. package/src/actions/get-email-path-from-slug.ts +32 -0
  120. package/src/actions/get-emails-directory-metadata-action.ts +19 -0
  121. package/src/actions/render-email-by-path.tsx +121 -0
  122. package/src/animated-icons-data/help.json +1082 -0
  123. package/src/animated-icons-data/link.json +1309 -0
  124. package/src/animated-icons-data/load.json +443 -0
  125. package/src/animated-icons-data/mail.json +1320 -0
  126. package/src/app/env.ts +15 -0
  127. package/src/app/favicon.ico +0 -0
  128. package/src/app/fonts/SFMono/SFMonoBold.otf +0 -0
  129. package/src/app/fonts/SFMono/SFMonoBoldItalic.otf +0 -0
  130. package/src/app/fonts/SFMono/SFMonoHeavy.otf +0 -0
  131. package/src/app/fonts/SFMono/SFMonoHeavyItalic.otf +0 -0
  132. package/src/app/fonts/SFMono/SFMonoLight.otf +0 -0
  133. package/src/app/fonts/SFMono/SFMonoLightItalic.otf +0 -0
  134. package/src/app/fonts/SFMono/SFMonoMedium.otf +0 -0
  135. package/src/app/fonts/SFMono/SFMonoMediumItalic.otf +0 -0
  136. package/src/app/fonts/SFMono/SFMonoRegular.otf +0 -0
  137. package/src/app/fonts/SFMono/SFMonoRegularItalic.otf +0 -0
  138. package/src/app/fonts/SFMono/SFMonoSemibold.otf +0 -0
  139. package/src/app/fonts/SFMono/SFMonoSemiboldItalic.otf +0 -0
  140. package/src/app/fonts.ts +39 -0
  141. package/src/app/globals.css +15 -0
  142. package/src/app/layout.tsx +43 -0
  143. package/src/app/logo.png +0 -0
  144. package/src/app/page.tsx +46 -0
  145. package/src/app/preview/[...slug]/page.tsx +157 -0
  146. package/src/app/preview/[...slug]/preview.tsx +216 -0
  147. package/src/app/preview/[...slug]/rendering-error.tsx +40 -0
  148. package/src/components/button.tsx +101 -0
  149. package/src/components/code-container.tsx +164 -0
  150. package/src/components/code-snippet.tsx +9 -0
  151. package/src/components/code.tsx +184 -0
  152. package/src/components/heading.tsx +113 -0
  153. package/src/components/icons/icon-arrow-down.tsx +16 -0
  154. package/src/components/icons/icon-base.tsx +26 -0
  155. package/src/components/icons/icon-bug.tsx +19 -0
  156. package/src/components/icons/icon-button.tsx +23 -0
  157. package/src/components/icons/icon-check.tsx +19 -0
  158. package/src/components/icons/icon-clipboard.tsx +40 -0
  159. package/src/components/icons/icon-download.tsx +19 -0
  160. package/src/components/icons/icon-email.tsx +18 -0
  161. package/src/components/icons/icon-file.tsx +19 -0
  162. package/src/components/icons/icon-folder-open.tsx +19 -0
  163. package/src/components/icons/icon-folder.tsx +18 -0
  164. package/src/components/icons/icon-hide-sidebar.tsx +23 -0
  165. package/src/components/icons/icon-image.tsx +19 -0
  166. package/src/components/icons/icon-info.tsx +18 -0
  167. package/src/components/icons/icon-link.tsx +14 -0
  168. package/src/components/icons/icon-monitor.tsx +19 -0
  169. package/src/components/icons/icon-phone.tsx +26 -0
  170. package/src/components/icons/icon-reload.tsx +18 -0
  171. package/src/components/icons/icon-source.tsx +19 -0
  172. package/src/components/icons/icon-stamp.tsx +14 -0
  173. package/src/components/icons/icon-warning.tsx +31 -0
  174. package/src/components/index.ts +7 -0
  175. package/src/components/logo.tsx +63 -0
  176. package/src/components/resizable-wrapper.tsx +173 -0
  177. package/src/components/send.tsx +134 -0
  178. package/src/components/shell.tsx +92 -0
  179. package/src/components/sidebar/file-tree-directory-children.tsx +139 -0
  180. package/src/components/sidebar/file-tree-directory.tsx +92 -0
  181. package/src/components/sidebar/file-tree.tsx +31 -0
  182. package/src/components/sidebar/index.ts +1 -0
  183. package/src/components/sidebar/sidebar.tsx +43 -0
  184. package/src/components/text.tsx +99 -0
  185. package/src/components/toolbar/checking-results.tsx +150 -0
  186. package/src/components/toolbar/code-preview-line-link.tsx +40 -0
  187. package/src/components/toolbar/compatibility.tsx +113 -0
  188. package/src/components/toolbar/linter.tsx +278 -0
  189. package/src/components/toolbar/results-table.tsx +0 -0
  190. package/src/components/toolbar/results.tsx +51 -0
  191. package/src/components/toolbar/spam-assassin.tsx +155 -0
  192. package/src/components/toolbar/toolbar-button.tsx +52 -0
  193. package/src/components/toolbar/use-cached-state.ts +33 -0
  194. package/src/components/toolbar.tsx +349 -0
  195. package/src/components/tooltip-content.tsx +31 -0
  196. package/src/components/tooltip.tsx +19 -0
  197. package/src/components/topbar/active-view-toggle-group.tsx +86 -0
  198. package/src/components/topbar/view-size-controls.tsx +247 -0
  199. package/src/components/topbar.tsx +59 -0
  200. package/src/contexts/emails.tsx +59 -0
  201. package/src/contexts/fragment-identifier.tsx +48 -0
  202. package/src/contexts/preview.tsx +79 -0
  203. package/src/hooks/use-clamped-state.ts +24 -0
  204. package/src/hooks/use-email-rendering-result.ts +58 -0
  205. package/src/hooks/use-fragment-identifier.ts +14 -0
  206. package/src/hooks/use-hot-reload.ts +31 -0
  207. package/src/hooks/use-icon-animation.ts +41 -0
  208. package/src/hooks/use-rendering-metadata.ts +36 -0
  209. package/src/utils/__snapshots__/get-email-component.spec.ts.snap +3 -0
  210. package/src/utils/caniemail/all-css-properties.ts +358 -0
  211. package/src/utils/caniemail/ast/__snapshots__/get-object-variables.spec.ts.snap +74 -0
  212. package/src/utils/caniemail/ast/__snapshots__/get-used-style-properties.spec.ts.snap +24 -0
  213. package/src/utils/caniemail/ast/get-object-variables.spec.ts +19 -0
  214. package/src/utils/caniemail/ast/get-object-variables.ts +61 -0
  215. package/src/utils/caniemail/ast/get-used-style-properties.spec.ts +23 -0
  216. package/src/utils/caniemail/ast/get-used-style-properties.ts +91 -0
  217. package/src/utils/caniemail/get-compatibility-stats-for-entry.ts +118 -0
  218. package/src/utils/caniemail/get-css-functions.ts +25 -0
  219. package/src/utils/caniemail/get-css-property-names.ts +32 -0
  220. package/src/utils/caniemail/get-css-property-with-value.ts +14 -0
  221. package/src/utils/caniemail/get-css-unit.ts +3 -0
  222. package/src/utils/caniemail/get-element-attributes.ts +7 -0
  223. package/src/utils/caniemail/get-element-names.ts +20 -0
  224. package/src/utils/caniemail/tailwind/generate-tailwind-rules.ts +30 -0
  225. package/src/utils/caniemail/tailwind/get-tailwind-config.ts +187 -0
  226. package/src/utils/caniemail/tailwind/get-tailwind-metadata.spec.ts +25 -0
  227. package/src/utils/caniemail/tailwind/get-tailwind-metadata.ts +45 -0
  228. package/src/utils/caniemail/tailwind/setup-tailwind-context.ts +15 -0
  229. package/src/utils/cn.ts +6 -0
  230. package/src/utils/constants.ts +6 -0
  231. package/src/utils/contains-email-template.spec.ts +124 -0
  232. package/src/utils/contains-email-template.ts +33 -0
  233. package/src/utils/copy-text-to-clipboard.ts +7 -0
  234. package/src/utils/esbuild/escape-string-for-regex.ts +3 -0
  235. package/src/utils/esbuild/renderring-utilities-exporter.ts +63 -0
  236. package/src/utils/get-email-component.spec.ts +41 -0
  237. package/src/utils/get-email-component.ts +134 -0
  238. package/src/utils/get-emails-directory-metadata.spec.ts +82 -0
  239. package/src/utils/get-emails-directory-metadata.ts +141 -0
  240. package/src/utils/get-line-and-column-from-offset.spec.ts +11 -0
  241. package/src/utils/get-line-and-column-from-offset.ts +11 -0
  242. package/src/utils/improve-error-with-sourcemap.ts +85 -0
  243. package/src/utils/index.ts +6 -0
  244. package/src/utils/js-email-detection.spec.ts +24 -0
  245. package/src/utils/language-map.ts +7 -0
  246. package/src/utils/linting.ts +60 -0
  247. package/src/utils/load-stream.ts +15 -0
  248. package/src/utils/register-spinner-autostopping.ts +28 -0
  249. package/src/utils/result.ts +49 -0
  250. package/src/utils/run-bundled-code.ts +64 -0
  251. package/src/utils/sanitize.ts +6 -0
  252. package/src/utils/static-node-modules-for-vm.ts +93 -0
  253. package/src/utils/testing/js-email-export-default.js +17 -0
  254. package/src/utils/testing/js-email-test.js +18 -0
  255. package/src/utils/testing/mdx-email-test.js +128 -0
  256. package/src/utils/testing/request-response-email.tsx +9 -0
  257. package/src/utils/types/as.ts +26 -0
  258. package/src/utils/types/email-template.ts +8 -0
  259. package/src/utils/types/error-object.ts +11 -0
  260. package/src/utils/types/hot-reload-change.ts +13 -0
  261. package/src/utils/unreachable.ts +8 -0
  262. package/tailwind-internals.d.ts +133 -0
  263. package/tailwind.config.ts +99 -0
  264. package/tsconfig.json +45 -0
  265. package/vitest.config.ts +15 -0
@@ -0,0 +1,101 @@
1
+ 'use client';
2
+ import { DotLottieReact } from '@lottiefiles/dotlottie-react';
3
+ import * as SlotPrimitive from '@radix-ui/react-slot';
4
+ import type * as React from 'react';
5
+ import animatedLoadIcon from '../animated-icons-data/load.json';
6
+ import { cn } from '../utils/cn';
7
+ import { unreachable } from '../utils/unreachable';
8
+
9
+ type RootProps = React.ComponentProps<'button'>;
10
+
11
+ type Appearance = 'white' | 'gradient';
12
+ type Size = '1' | '2' | '3' | '4';
13
+
14
+ interface ButtonProps extends RootProps {
15
+ asChild?: boolean;
16
+ appearance?: Appearance;
17
+ size?: Size;
18
+ loading?: boolean;
19
+ }
20
+
21
+ export const Button = ({
22
+ asChild,
23
+ appearance = 'white',
24
+ className,
25
+ children,
26
+ size = '2',
27
+ loading,
28
+ ref,
29
+ ...props
30
+ }: ButtonProps) => {
31
+ const Root = asChild ? SlotPrimitive.Slot : 'button';
32
+
33
+ return (
34
+ <Root
35
+ ref={ref}
36
+ type="button"
37
+ {...props}
38
+ className={cn(
39
+ getSize(size),
40
+ getAppearance(appearance),
41
+ 'inline-flex items-center justify-center gap-2 border font-medium',
42
+ className,
43
+ )}
44
+ aria-disabled={loading}
45
+ >
46
+ <span
47
+ className={cn(
48
+ '-ml-7 opacity-0 transition-opacity duration-200',
49
+ loading && 'opacity-100',
50
+ )}
51
+ >
52
+ <DotLottieReact
53
+ data={animatedLoadIcon}
54
+ autoplay={false}
55
+ className="h-5 w-5"
56
+ loop={true}
57
+ />
58
+ </span>
59
+ <SlotPrimitive.Slottable>{children}</SlotPrimitive.Slottable>
60
+ </Root>
61
+ );
62
+ };
63
+
64
+ Button.displayName = 'Button';
65
+
66
+ const getAppearance = (appearance: Appearance | undefined) => {
67
+ switch (appearance) {
68
+ case undefined:
69
+ case 'white':
70
+ return [
71
+ 'border-white bg-white text-black transition-colors duration-200 ease-in-out',
72
+ 'hover:bg-white/90',
73
+ 'focus:bg-white/90 focus:outline-none focus:ring-2 focus:ring-white/20',
74
+ 'mt-2 mb-4 aria-disabled:border-transparent aria-disabled:bg-slate-11',
75
+ ];
76
+ case 'gradient':
77
+ return [
78
+ 'bg-gradient border-[#34343A] backdrop-blur-[1.25rem]',
79
+ 'hover:bg-gradientHover',
80
+ 'focus:bg-gradientHover focus:outline-none focus:ring-2 focus:ring-white/20',
81
+ ];
82
+ default:
83
+ unreachable(appearance);
84
+ }
85
+ };
86
+
87
+ const getSize = (size: Size | undefined) => {
88
+ switch (size) {
89
+ case '1':
90
+ return '';
91
+ case undefined:
92
+ case '2':
93
+ return 'text-[.875rem] h-8 px-3 rounded-md gap-2';
94
+ case '3':
95
+ return 'text-[.875rem] h-10 px-4 rounded-md gap-2';
96
+ case '4':
97
+ return 'text-base h-11 px-4 rounded-md gap-2';
98
+ default:
99
+ unreachable(size);
100
+ }
101
+ };
@@ -0,0 +1,164 @@
1
+ import { LayoutGroup, motion } from 'framer-motion';
2
+ import type { Language } from 'prism-react-renderer';
3
+ import * as React from 'react';
4
+ import { copyTextToClipboard } from '../utils';
5
+ import { tabTransition } from '../utils/constants';
6
+ import languageMap from '../utils/language-map';
7
+ import { Code } from './code';
8
+ import { IconButton } from './icons/icon-button';
9
+ import { IconCheck } from './icons/icon-check';
10
+ import { IconClipboard } from './icons/icon-clipboard';
11
+ import { IconDownload } from './icons/icon-download';
12
+ import { Tooltip } from './tooltip';
13
+
14
+ interface CodeContainerProps {
15
+ markups: MarkupProps[];
16
+ activeLang: string;
17
+ setActiveLang: (lang: string) => void;
18
+ }
19
+
20
+ interface MarkupProps {
21
+ language: Language;
22
+ content: string;
23
+ }
24
+
25
+ export const CodeContainer: React.FC<Readonly<CodeContainerProps>> = ({
26
+ markups,
27
+ activeLang,
28
+ setActiveLang,
29
+ }) => {
30
+ const activeMarkup = markups.find(({ language }) => activeLang === language);
31
+ if (!activeMarkup) {
32
+ throw new Error('No markup found for the active language!', {
33
+ cause: {
34
+ activeLang,
35
+ markups,
36
+ },
37
+ });
38
+ }
39
+
40
+ return (
41
+ <div
42
+ className="relative max-h-[650px] w-full h-full whitespace-pre rounded-md border border-slate-6 text-sm"
43
+ style={{
44
+ lineHeight: '130%',
45
+ background:
46
+ 'linear-gradient(145.37deg, rgba(255, 255, 255, 0.09) -8.75%, rgba(255, 255, 255, 0.027) 83.95%)',
47
+ boxShadow: 'rgb(0 0 0 / 10%) 0px 5px 30px -5px',
48
+ }}
49
+ >
50
+ <div className="h-9 border-b border-slate-6">
51
+ <div className="flex">
52
+ <LayoutGroup id="code">
53
+ {markups.map(({ language }) => {
54
+ const isCurrentLang = activeLang === language;
55
+ return (
56
+ <motion.button
57
+ className={`relative px-4 py-[8px] font-sans text-sm font-medium transition duration-200 ease-in-out hover:text-slate-12 ${
58
+ activeLang !== language ? 'text-slate-11' : 'text-slate-12'
59
+ }`}
60
+ key={language}
61
+ onClick={() => {
62
+ setActiveLang(language);
63
+ }}
64
+ >
65
+ {isCurrentLang ? (
66
+ <motion.span
67
+ animate={{ opacity: 1 }}
68
+ className="absolute bottom-0 left-0 right-0 top-0 bg-slate-4"
69
+ exit={{ opacity: 0 }}
70
+ initial={{ opacity: 0 }}
71
+ layoutId="code"
72
+ transition={tabTransition}
73
+ />
74
+ ) : null}
75
+ {languageMap[language]}
76
+ </motion.button>
77
+ );
78
+ })}
79
+ </LayoutGroup>
80
+ </div>
81
+ <CopyToClipboardButton content={activeMarkup.content} />
82
+ <DownloadButton
83
+ content={activeMarkup.content}
84
+ filename={`email.${activeMarkup.language}`}
85
+ />
86
+ </div>
87
+ <div className="h-[calc(100%-2.25rem)]">
88
+ <Code language={activeLang}>{activeMarkup.content}</Code>
89
+ </div>
90
+ </div>
91
+ );
92
+ };
93
+
94
+ interface CopyToClipboardButtonProps {
95
+ content: string;
96
+ }
97
+
98
+ const CopyToClipboardButton = ({ content }: CopyToClipboardButtonProps) => {
99
+ const [isCopied, setIsCopied] = React.useState(false);
100
+
101
+ const unsetIsCopiedTimeout = React.useRef<NodeJS.Timeout>(undefined);
102
+ React.useEffect(() => {
103
+ setIsCopied(false);
104
+ clearTimeout(unsetIsCopiedTimeout.current);
105
+ unsetIsCopiedTimeout.current = undefined;
106
+ }, [content]);
107
+
108
+ return (
109
+ <Tooltip>
110
+ <Tooltip.Trigger
111
+ asChild
112
+ className="absolute right-2 top-2 hidden md:block"
113
+ >
114
+ <IconButton
115
+ onClick={async () => {
116
+ setIsCopied(true);
117
+ await copyTextToClipboard(content);
118
+ unsetIsCopiedTimeout.current = setTimeout(() => {
119
+ setIsCopied(false);
120
+ }, 3000);
121
+ }}
122
+ >
123
+ {isCopied ? <IconCheck /> : <IconClipboard />}
124
+ </IconButton>
125
+ </Tooltip.Trigger>
126
+ <Tooltip.Content>Copy to Clipboard</Tooltip.Content>
127
+ </Tooltip>
128
+ );
129
+ };
130
+
131
+ interface DownloadButtonProps {
132
+ content: string;
133
+ filename: string;
134
+ }
135
+
136
+ const DownloadButton = ({ content, filename }: DownloadButtonProps) => {
137
+ const generatedUrl = React.useMemo(() => {
138
+ const file = new File([content], filename);
139
+ return URL.createObjectURL(file);
140
+ }, [content, filename]);
141
+ const url = React.useSyncExternalStore(
142
+ () => () => {},
143
+ () => generatedUrl,
144
+ () => undefined,
145
+ );
146
+
147
+ return (
148
+ <Tooltip>
149
+ <Tooltip.Trigger
150
+ asChild
151
+ className="text-gray-11 absolute right-8 top-2 hidden md:block"
152
+ >
153
+ <a
154
+ className="text-slate-11 transition duration-200 ease-in-out hover:text-slate-12"
155
+ download={filename}
156
+ href={url}
157
+ >
158
+ <IconDownload />
159
+ </a>
160
+ </Tooltip.Trigger>
161
+ <Tooltip.Content>Download</Tooltip.Content>
162
+ </Tooltip>
163
+ );
164
+ };
@@ -0,0 +1,9 @@
1
+ const CodeSnippet = ({ children }) => {
2
+ return (
3
+ <code className="m-0.5 inline-block rounded-md bg-white/10 p-1 font-mono leading-none text-slate-12">
4
+ {children}
5
+ </code>
6
+ );
7
+ };
8
+
9
+ export default CodeSnippet;
@@ -0,0 +1,184 @@
1
+ 'use client';
2
+ import Link from 'next/link';
3
+ import { useSearchParams } from 'next/navigation';
4
+ import type { Language } from 'prism-react-renderer';
5
+ import { Highlight } from 'prism-react-renderer';
6
+ import { Fragment, useEffect, useRef } from 'react';
7
+ import { useFragmentIdentifier } from '../hooks/use-fragment-identifier';
8
+ import { cn } from '../utils';
9
+
10
+ interface CodeProps {
11
+ children: string;
12
+ className?: string;
13
+ language?: Language;
14
+ }
15
+
16
+ const theme = {
17
+ plain: {
18
+ color: '#EDEDEF',
19
+ fontSize: 13,
20
+ fontFamily: 'MonoLisa, Menlo, monospace',
21
+ },
22
+ styles: [
23
+ {
24
+ types: ['comment'],
25
+ style: {
26
+ color: '#706F78',
27
+ },
28
+ },
29
+ {
30
+ types: ['atrule', 'keyword', 'attr-name', 'selector'],
31
+ style: {
32
+ color: '#7E7D86',
33
+ },
34
+ },
35
+ {
36
+ types: ['punctuation', 'operator'],
37
+ style: {
38
+ color: '#706F78',
39
+ },
40
+ },
41
+ {
42
+ types: ['class-name', 'function', 'tag', 'key-white'],
43
+ style: {
44
+ color: '#EDEDEF',
45
+ },
46
+ },
47
+ ],
48
+ };
49
+
50
+ const lineHashRegex = /#L(?<start>\d+)(?:,(?<end>\d+))?/;
51
+
52
+ export const Code: React.FC<Readonly<CodeProps>> = ({
53
+ children,
54
+ language = 'html',
55
+ }) => {
56
+ const locationHash = useFragmentIdentifier();
57
+ const highlight = (() => {
58
+ if (locationHash) {
59
+ const match = locationHash.match(lineHashRegex);
60
+ if (match?.groups?.start) {
61
+ const start = Number.parseInt(match.groups.start);
62
+ const end = match.groups.end
63
+ ? Number.parseInt(match.groups.end)
64
+ : start;
65
+ return [start, end] as const;
66
+ }
67
+ }
68
+ })();
69
+
70
+ const isHighlighting = (line: number) => {
71
+ if (!highlight) return false;
72
+
73
+ return highlight[0] <= line && highlight[1] >= line;
74
+ };
75
+
76
+ const scrollerRef = useRef<HTMLDivElement>(null);
77
+
78
+ useEffect(() => {
79
+ const scroller = scrollerRef.current;
80
+ if (highlight && scroller) {
81
+ const lineElement = scroller.querySelector(`#L${highlight[0]}`);
82
+ if (lineElement instanceof HTMLAnchorElement) {
83
+ scroller.scrollTo({
84
+ top: Math.max(lineElement.offsetTop - 325, 0),
85
+ behavior: 'smooth',
86
+ });
87
+ }
88
+ }
89
+ }, [highlight]);
90
+
91
+ const searchParams = useSearchParams();
92
+
93
+ const value = children.trim();
94
+
95
+ return (
96
+ <Highlight code={value} language={language} theme={theme}>
97
+ {({ tokens, getLineProps, getTokenProps }) => (
98
+ <>
99
+ <div
100
+ className="absolute right-0 top-0 h-px w-[200px]"
101
+ style={{
102
+ background:
103
+ 'linear-gradient(90deg, rgba(56, 189, 248, 0) 0%, rgba(56, 189, 248, 0) 0%, rgba(232, 232, 232, 0.2) 33.02%, rgba(143, 143, 143, 0.6719) 64.41%, rgba(236, 72, 153, 0) 98.93%)',
104
+ }}
105
+ />
106
+ <div
107
+ ref={scrollerRef}
108
+ className="flex max-h-[650px] h-full p-4 after:w-full after:static after:block after:h-4 after:content-[''] overflow-auto"
109
+ >
110
+ <div className="text-[#49494f] text-[13px] font-light font-[MonoLisa,_Menlo,_monospace]">
111
+ {tokens.map((_, i) => (
112
+ <Link
113
+ id={`L${i + 1}`}
114
+ key={i}
115
+ href={{
116
+ hash: `#L${i + 1}`,
117
+ search: searchParams.toString(),
118
+ }}
119
+ scroll={false}
120
+ className={cn(
121
+ 'align-middle block scroll-mt-[325px] rounded-l-sm select-none pr-3 cursor-pointer hover:text-slate-12',
122
+ isHighlighting(i + 1) &&
123
+ 'text-cyan-11 hover:text-cyan-11 bg-cyan-5',
124
+ )}
125
+ type="button"
126
+ >
127
+ {i + 1}
128
+ </Link>
129
+ ))}
130
+ </div>
131
+ <pre>
132
+ {tokens.map((line, i) => {
133
+ const lineProps = getLineProps({
134
+ line,
135
+ key: i,
136
+ });
137
+ return (
138
+ <div
139
+ {...lineProps}
140
+ className={cn(
141
+ 'whitespace-pre flex transition-colors rounded-r-sm',
142
+ isHighlighting(i + 1) && 'bg-cyan-5',
143
+ {
144
+ "before:mr-2 before:text-slate-11 before:content-['$']":
145
+ language === 'bash' && tokens.length === 1,
146
+ },
147
+ )}
148
+ key={i}
149
+ >
150
+ {line.map((token, key) => {
151
+ const tokenProps = getTokenProps({
152
+ token,
153
+ });
154
+ const isException =
155
+ token.content === 'from' &&
156
+ line[key + 1]?.content === ':';
157
+ const newTypes = isException
158
+ ? [...token.types, 'key-white']
159
+ : token.types;
160
+ token.types = newTypes;
161
+
162
+ return (
163
+ <Fragment key={key}>
164
+ <span {...tokenProps} />
165
+ </Fragment>
166
+ );
167
+ })}
168
+ </div>
169
+ );
170
+ })}
171
+ </pre>
172
+ <div
173
+ className="absolute bottom-0 left-0 h-px w-[200px]"
174
+ style={{
175
+ background:
176
+ 'linear-gradient(90deg, rgba(56, 189, 248, 0) 0%, rgba(56, 189, 248, 0) 0%, rgba(232, 232, 232, 0.2) 33.02%, rgba(143, 143, 143, 0.6719) 64.41%, rgba(236, 72, 153, 0) 98.93%)',
177
+ }}
178
+ />
179
+ </div>
180
+ </>
181
+ )}
182
+ </Highlight>
183
+ );
184
+ };
@@ -0,0 +1,113 @@
1
+ import * as SlotPrimitive from '@radix-ui/react-slot';
2
+ import * as React from 'react';
3
+ import { type As, cn, unreachable } from '../utils';
4
+
5
+ export type HeadingSize =
6
+ | '1'
7
+ | '2'
8
+ | '3'
9
+ | '4'
10
+ | '5'
11
+ | '6'
12
+ | '7'
13
+ | '8'
14
+ | '9'
15
+ | '10';
16
+ export type HeadingColor = 'white' | 'gray';
17
+ export type HeadingWeight = 'medium' | 'bold';
18
+
19
+ interface HeadingOwnProps {
20
+ size?: HeadingSize;
21
+ color?: HeadingColor;
22
+ weight?: HeadingWeight;
23
+ }
24
+
25
+ type HeadingProps = As<'h1', 'h2', 'h3', 'h4', 'h5', 'h6'> & HeadingOwnProps;
26
+
27
+ export const Heading = React.forwardRef<
28
+ HTMLHeadingElement,
29
+ Readonly<HeadingProps>
30
+ >(
31
+ (
32
+ {
33
+ as: Tag = 'h1',
34
+ size = '3',
35
+ className,
36
+ color = 'white',
37
+ children,
38
+ weight = 'bold',
39
+ ...props
40
+ },
41
+ forwardedRef,
42
+ ) => (
43
+ <SlotPrimitive.Slot
44
+ className={cn(
45
+ className,
46
+ getSizesClassNames(size),
47
+ getColorClassNames(color),
48
+ getWeightClassNames(weight),
49
+ )}
50
+ ref={forwardedRef}
51
+ {...props}
52
+ >
53
+ <Tag>{children}</Tag>
54
+ </SlotPrimitive.Slot>
55
+ ),
56
+ );
57
+
58
+ const getSizesClassNames = (size: HeadingSize | undefined) => {
59
+ switch (size) {
60
+ case '1':
61
+ return 'text-xs';
62
+ case '2':
63
+ return 'text-sm';
64
+ case undefined:
65
+ case '3':
66
+ return 'text-base';
67
+ case '4':
68
+ return 'text-lg';
69
+ case '5':
70
+ return 'text-xl tracking-[-0.16px]';
71
+ case '6':
72
+ return 'text-2xl tracking-[-0.288px]';
73
+ case '7':
74
+ return 'text-[28px] leading-[34px] tracking-[-0.416px]';
75
+ case '8':
76
+ return 'text-[35px] leading-[42px] tracking-[-0.64px]';
77
+ case '9':
78
+ return 'text-6xl leading-[73px] tracking-[-0.896px]';
79
+ case '10':
80
+ return [
81
+ 'text-[38px] leading-[46px]',
82
+ 'md:text-[70px] md:leading-[85px] tracking-[-1.024px;]',
83
+ ];
84
+ default:
85
+ return unreachable(size);
86
+ }
87
+ };
88
+
89
+ const getColorClassNames = (color: HeadingColor | undefined) => {
90
+ switch (color) {
91
+ case 'gray':
92
+ return 'text-slate-11';
93
+ case 'white':
94
+ case undefined:
95
+ return 'text-slate-12';
96
+ default:
97
+ return unreachable(color);
98
+ }
99
+ };
100
+
101
+ const getWeightClassNames = (weight: HeadingWeight | undefined) => {
102
+ switch (weight) {
103
+ case 'medium':
104
+ return 'font-medium';
105
+ case 'bold':
106
+ case undefined:
107
+ return 'font-bold';
108
+ default:
109
+ return unreachable(weight);
110
+ }
111
+ };
112
+
113
+ Heading.displayName = 'Heading';
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import type { IconElement, IconProps } from './icon-base';
3
+ import { IconBase } from './icon-base';
4
+
5
+ export const IconArrowDown = React.forwardRef<IconElement, Readonly<IconProps>>(
6
+ ({ ...props }, forwardedRef) => (
7
+ <IconBase ref={forwardedRef} {...props}>
8
+ <path
9
+ d="M12 16L6 9.85966L6.84 9L12 14.2808L17.16 9L18 9.85966L12 16Z"
10
+ fill="currentColor"
11
+ />
12
+ </IconBase>
13
+ ),
14
+ );
15
+
16
+ IconArrowDown.displayName = 'IconArrowDown';
@@ -0,0 +1,26 @@
1
+ import * as React from 'react';
2
+
3
+ export type IconElement = React.ElementRef<'svg'>;
4
+ export type RootProps = React.ComponentPropsWithoutRef<'svg'>;
5
+
6
+ export interface IconProps extends RootProps {
7
+ size?: number;
8
+ }
9
+
10
+ export const IconBase = React.forwardRef<IconElement, Readonly<IconProps>>(
11
+ ({ size = 20, children, ...props }, forwardedRef) => (
12
+ <svg
13
+ fill="none"
14
+ height={size}
15
+ ref={forwardedRef}
16
+ viewBox="0 0 24 24"
17
+ width={size}
18
+ xmlns="http://www.w3.org/2000/svg"
19
+ {...props}
20
+ >
21
+ {children}
22
+ </svg>
23
+ ),
24
+ );
25
+
26
+ IconBase.displayName = 'IconBase';
@@ -0,0 +1,19 @@
1
+ import { forwardRef } from 'react';
2
+ import type { IconElement, IconProps } from './icon-base';
3
+ import { IconBase } from './icon-base';
4
+
5
+ export const IconBug = forwardRef<IconElement, IconProps>((props, ref) => (
6
+ <IconBase {...props} ref={ref}>
7
+ <g
8
+ fill="none"
9
+ stroke="currentColor"
10
+ strokeLinecap="round"
11
+ strokeLinejoin="round"
12
+ strokeWidth="2"
13
+ >
14
+ <path d="m8 2l1.88 1.88m4.24 0L16 2M9 7.13v-1a3.003 3.003 0 1 1 6 0v1" />
15
+ <path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6m0 0v-9" />
16
+ <path d="M6.53 9C4.6 8.8 3 7.1 3 5m3 8H2m1 8c0-2.1 1.7-3.9 3.8-4M20.97 5c0 2.1-1.6 3.8-3.5 4M22 13h-4m-.8 4c2.1.1 3.8 1.9 3.8 4" />
17
+ </g>
18
+ </IconBase>
19
+ ));
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ import { cn } from '../../utils';
3
+
4
+ export type IconButtonProps = React.ComponentPropsWithoutRef<'button'>;
5
+
6
+ export const IconButton = React.forwardRef<
7
+ HTMLButtonElement,
8
+ Readonly<IconButtonProps>
9
+ >(({ children, className, ...props }, forwardedRef) => (
10
+ <button
11
+ type="button"
12
+ {...props}
13
+ className={cn(
14
+ 'focus:ring-gray-8 rounded text-slate-11 transition duration-200 ease-in-out hover:text-slate-12 focus:text-slate-12 focus:outline-none focus:ring-2',
15
+ className,
16
+ )}
17
+ ref={forwardedRef}
18
+ >
19
+ {children}
20
+ </button>
21
+ ));
22
+
23
+ IconButton.displayName = 'IconButton';
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import type { IconElement, IconProps } from './icon-base';
3
+ import { IconBase } from './icon-base';
4
+
5
+ export const IconCheck = React.forwardRef<IconElement, Readonly<IconProps>>(
6
+ ({ ...props }, forwardedRef) => (
7
+ <IconBase ref={forwardedRef} {...props}>
8
+ <path
9
+ d="M16.25 8.75L10.406 15.25L7.75 12.75"
10
+ stroke="currentColor"
11
+ strokeLinecap="round"
12
+ strokeLinejoin="round"
13
+ strokeWidth="1.5"
14
+ />
15
+ </IconBase>
16
+ ),
17
+ );
18
+
19
+ IconCheck.displayName = 'IconCheck';