@dextinity/mail-react 10.3.0-canary-20260901061104 → 10.3.0-canary-20260901101435

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,6 +1,3 @@
1
1
  import type { ReactNode } from "react";
2
- /**
3
- * Internal component that iterates the styles registry and renders one
4
- * `<MjmlStyle>` element per entry.
5
- */
2
+ /** Internal component that renders the styles registry into `<MjmlStyle>` elements. */
6
3
  export declare function Styles(): ReactNode;
@@ -1,16 +1,20 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { MjmlStyle } from "@faire/mjml-react";
3
3
  import { useTheme } from "../theme/ThemeProvider.js";
4
+ import { minifyHeadCss } from "./minifyHeadCss.js";
4
5
  import { getRegisteredStyles } from "./registerStyles.js";
5
- /**
6
- * Internal component that iterates the styles registry and renders one
7
- * `<MjmlStyle>` element per entry.
8
- */
6
+ /** Internal component that renders the styles registry into `<MjmlStyle>` elements. */
9
7
  export function Styles() {
10
8
  const theme = useTheme();
11
9
  const entries = Array.from(getRegisteredStyles().values());
12
- return (_jsx(_Fragment, { children: entries.map((entry, index) => {
13
- const cssString = typeof entry.styles === "function" ? entry.styles(theme) : entry.styles;
14
- return (_jsx(MjmlStyle, { ...entry.mjmlStyleProps, children: cssString }, index));
15
- }) }));
10
+ function resolveCss(styles) {
11
+ return typeof styles === "function" ? styles(theme) : styles;
12
+ }
13
+ const combinedStyleTagCss = entries
14
+ .filter((entry) => !entry.mjmlStyleProps?.inline)
15
+ .map((entry) => resolveCss(entry.styles))
16
+ .filter(Boolean)
17
+ .join("\n");
18
+ const entriesToInline = entries.filter((entry) => entry.mjmlStyleProps?.inline);
19
+ return (_jsxs(_Fragment, { children: [combinedStyleTagCss ? _jsx(MjmlStyle, { children: minifyHeadCss(combinedStyleTagCss) }) : null, entriesToInline.map((entry, index) => (_jsx(MjmlStyle, { ...entry.mjmlStyleProps, children: resolveCss(entry.styles) }, index)))] }));
16
20
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Minifies CSS for a `<style>` tag in the mail head.
3
+ *
4
+ * Gmail discards a mail's `<style>` content once the tags together pass 16,384 characters.
5
+ */
6
+ export declare function minifyHeadCss(css: string): string;
@@ -0,0 +1,14 @@
1
+ import { syntax } from "csso";
2
+ /**
3
+ * Minifies CSS for a `<style>` tag in the mail head.
4
+ *
5
+ * Gmail discards a mail's `<style>` content once the tags together pass 16,384 characters.
6
+ */
7
+ export function minifyHeadCss(css) {
8
+ const parseErrors = [];
9
+ const styleSheet = syntax.parse(css, { onParseError: (error) => parseErrors.push(error.message) });
10
+ if (parseErrors.length > 0) {
11
+ throw new Error(`The registered styles do not parse, so they cannot be minified: ${parseErrors.join("; ")}`);
12
+ }
13
+ return syntax.generate(syntax.compress(styleSheet).ast);
14
+ }
@@ -1,7 +1,7 @@
1
1
  import type { IMjmlStyleProps } from "@faire/mjml-react";
2
2
  import type { Theme } from "../theme/themeTypes.js";
3
3
  import type { css } from "../utils/css.js";
4
- type StylesPayload = ReturnType<typeof css> | ((theme: Theme) => ReturnType<typeof css>);
4
+ export type StylesPayload = ReturnType<typeof css> | ((theme: Theme) => ReturnType<typeof css>);
5
5
  type MjmlStyleOptions = Partial<Omit<IMjmlStyleProps, "children">>;
6
6
  interface StyleRegistryEntry {
7
7
  styles: StylesPayload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dextinity/mail-react",
3
- "version": "10.3.0-canary-20260901061104",
3
+ "version": "10.3.0-canary-20260901101435",
4
4
  "description": "Utilities for building HTML emails with React",
5
5
  "license": "BSD-2-Clause",
6
6
  "type": "module",
@@ -22,6 +22,7 @@
22
22
  "dependencies": {
23
23
  "@faire/mjml-react": "^3.5.4",
24
24
  "clsx": "^2.1.1",
25
+ "csso": "^5.0.5",
25
26
  "mjml": "^4.18.0",
26
27
  "mjml-browser": "^4.18.0",
27
28
  "redraft": "^0.10.2"
@@ -30,6 +31,7 @@
30
31
  "@storybook/addon-docs": "^10.3.5",
31
32
  "@storybook/addon-vitest": "10.3.5",
32
33
  "@storybook/react-vite": "^10.3.5",
34
+ "@types/csso": "^5.0.5",
33
35
  "@types/mjml": "^4.7.4",
34
36
  "@types/mjml-browser": "^4.15.0",
35
37
  "@types/react": "^19.2.15",
@@ -48,8 +50,8 @@
48
50
  "typescript": "^5.9.3",
49
51
  "vite": "^7.3.1",
50
52
  "vitest": "^4.1.8",
51
- "@dextinity/cli": "10.3.0-canary-20260901061104",
52
- "@dextinity/eslint-config": "10.3.0-canary-20260901061104"
53
+ "@dextinity/cli": "10.3.0-canary-20260901101435",
54
+ "@dextinity/eslint-config": "10.3.0-canary-20260901101435"
53
55
  },
54
56
  "peerDependencies": {
55
57
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0",