@react-email/tailwind 0.0.1-3.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/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +257 -0
- package/dist/index.mjs +223 -0
- package/license.md +7 -0
- package/package.json +72 -0
- package/readme.md +72 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Config } from 'tailwindcss';
|
|
3
|
+
|
|
4
|
+
type TailwindConfig = Omit<Config, "content">;
|
|
5
|
+
interface TailwindProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
config?: TailwindConfig;
|
|
8
|
+
}
|
|
9
|
+
declare const Tailwind: React.FC<TailwindProps>;
|
|
10
|
+
|
|
11
|
+
export { Tailwind, TailwindConfig, TailwindProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Config } from 'tailwindcss';
|
|
3
|
+
|
|
4
|
+
type TailwindConfig = Omit<Config, "content">;
|
|
5
|
+
interface TailwindProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
config?: TailwindConfig;
|
|
8
|
+
}
|
|
9
|
+
declare const Tailwind: React.FC<TailwindProps>;
|
|
10
|
+
|
|
11
|
+
export { Tailwind, TailwindConfig, TailwindProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
+
mod
|
|
44
|
+
));
|
|
45
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
|
|
47
|
+
// src/index.ts
|
|
48
|
+
var src_exports = {};
|
|
49
|
+
__export(src_exports, {
|
|
50
|
+
Tailwind: () => Tailwind
|
|
51
|
+
});
|
|
52
|
+
module.exports = __toCommonJS(src_exports);
|
|
53
|
+
|
|
54
|
+
// src/tailwind.tsx
|
|
55
|
+
var React = __toESM(require("react"));
|
|
56
|
+
var import_server = require("react-dom/server");
|
|
57
|
+
|
|
58
|
+
// src/utils/css-to-jsx-style.ts
|
|
59
|
+
var camelCase = (string) => string.replace(/-(\w|$)/g, (_, p1) => p1.toUpperCase());
|
|
60
|
+
var convertPropertyName = (prop) => {
|
|
61
|
+
let modifiedProp = prop;
|
|
62
|
+
modifiedProp = modifiedProp.toLowerCase();
|
|
63
|
+
if (modifiedProp === "float") {
|
|
64
|
+
return "cssFloat";
|
|
65
|
+
}
|
|
66
|
+
if (modifiedProp.startsWith("--")) {
|
|
67
|
+
return modifiedProp;
|
|
68
|
+
}
|
|
69
|
+
if (modifiedProp.startsWith("-ms-")) {
|
|
70
|
+
modifiedProp = modifiedProp.slice(1);
|
|
71
|
+
}
|
|
72
|
+
return camelCase(modifiedProp);
|
|
73
|
+
};
|
|
74
|
+
var cssToJsxStyle = (cssText) => {
|
|
75
|
+
const style = {};
|
|
76
|
+
const declarations = cssText.matchAll(
|
|
77
|
+
/([a-zA-Z0-9\-_]+)\s*:\s*('[^']*'[^;]*|"[^"]*"[^;]*|.*?\([^)]*\)[^;]*|[^;]*);?/gm
|
|
78
|
+
);
|
|
79
|
+
for (const [_declaration, property, value] of declarations) {
|
|
80
|
+
if (property.length > 0 && value.trim().length > 0) {
|
|
81
|
+
style[convertPropertyName(property)] = value.trim();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return style;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/utils/get-css-for-markup.ts
|
|
88
|
+
var import_postcss = __toESM(require("postcss"));
|
|
89
|
+
var import_tailwindcss = __toESM(require("tailwindcss"));
|
|
90
|
+
var import_postcss_css_variables = __toESM(require("postcss-css-variables"));
|
|
91
|
+
global.__OXIDE__ = void 0;
|
|
92
|
+
var getCssForMarkup = (markup, config) => {
|
|
93
|
+
const corePlugins = config == null ? void 0 : config.corePlugins;
|
|
94
|
+
const tailwindConfig = __spreadProps(__spreadValues({}, config), {
|
|
95
|
+
corePlugins: __spreadValues({
|
|
96
|
+
preflight: false
|
|
97
|
+
}, corePlugins)
|
|
98
|
+
});
|
|
99
|
+
const processor = (0, import_postcss.default)([
|
|
100
|
+
(0, import_tailwindcss.default)(__spreadProps(__spreadValues({}, tailwindConfig), {
|
|
101
|
+
content: [{ raw: markup, extension: "html" }]
|
|
102
|
+
})),
|
|
103
|
+
(0, import_postcss_css_variables.default)()
|
|
104
|
+
]);
|
|
105
|
+
const result = processor.process(
|
|
106
|
+
String.raw`
|
|
107
|
+
@tailwind base;
|
|
108
|
+
@tailwind components;
|
|
109
|
+
@tailwind utilities;
|
|
110
|
+
`,
|
|
111
|
+
{ from: void 0 }
|
|
112
|
+
// no need to use from since the `content` context is sent into tailwind
|
|
113
|
+
);
|
|
114
|
+
return result.css;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/utils/minify-css.ts
|
|
118
|
+
var minifyCss = (css) => {
|
|
119
|
+
return css.replace(/\/\*[\s\S]*?\*\//gm, "").replace(/;\s+/gm, ";").replace(/:\s+/gm, ":").replace(/\)\s*{/gm, "){").replace(/\s+\(/gm, "(").replace(/{\s+/gm, "{").replace(/}\s+/gm, "}").replace(/\s*{/gm, "{").replace(/;?\s*}/gm, "}");
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/utils/get-css-class-properties-map.ts
|
|
123
|
+
var getStylesPerClassMap = (css) => {
|
|
124
|
+
const map = {};
|
|
125
|
+
for (const [_match, className, contents] of css.matchAll(
|
|
126
|
+
/\s*\.([\S]+)\s*{([^}]*)}/gm
|
|
127
|
+
)) {
|
|
128
|
+
map[className.trim()] = contents.replace(/^\n+/, "").replace(/\n+$/, "").trim();
|
|
129
|
+
}
|
|
130
|
+
return map;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/utils/escape-class-name.ts
|
|
134
|
+
var escapeClassName = (className) => {
|
|
135
|
+
return className.replace(
|
|
136
|
+
/* we need this look ahead capturing group to avoid using negative look behinds */
|
|
137
|
+
/([^\\]|^)(?=([^a-zA-Z0-9\-_]))/g,
|
|
138
|
+
(match, prefixCharacter, characterToEscape) => {
|
|
139
|
+
if (prefixCharacter === "" && characterToEscape === "\\")
|
|
140
|
+
return match;
|
|
141
|
+
return `${prefixCharacter}\\`;
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/tailwind.tsx
|
|
147
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
148
|
+
function processElement(element, nonMediaQueryTailwindStylesPerClass) {
|
|
149
|
+
let modifiedElement = element;
|
|
150
|
+
let resultingClassName = modifiedElement.props.className;
|
|
151
|
+
let resultingStyle = modifiedElement.props.style;
|
|
152
|
+
let resultingChildren = [];
|
|
153
|
+
if (modifiedElement.props.className) {
|
|
154
|
+
const fullClassName = modifiedElement.props.className;
|
|
155
|
+
const classNames = fullClassName.split(" ");
|
|
156
|
+
const classNamesToKeep = [];
|
|
157
|
+
const styles = [];
|
|
158
|
+
classNames.forEach((className) => {
|
|
159
|
+
const escapedClassName = escapeClassName(className);
|
|
160
|
+
if (typeof nonMediaQueryTailwindStylesPerClass[escapedClassName] === "undefined") {
|
|
161
|
+
classNamesToKeep.push(className);
|
|
162
|
+
} else {
|
|
163
|
+
styles.push(
|
|
164
|
+
`${nonMediaQueryTailwindStylesPerClass[escapedClassName]};`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
resultingStyle = __spreadValues(__spreadValues({}, modifiedElement.props.style), cssToJsxStyle(styles.join(" ")));
|
|
169
|
+
resultingClassName = classNamesToKeep.length > 0 ? classNamesToKeep.join(" ") : void 0;
|
|
170
|
+
}
|
|
171
|
+
if (modifiedElement.props.children) {
|
|
172
|
+
resultingChildren = React.Children.toArray(
|
|
173
|
+
modifiedElement.props.children
|
|
174
|
+
).map((child) => {
|
|
175
|
+
if (React.isValidElement(child)) {
|
|
176
|
+
return processElement(child, nonMediaQueryTailwindStylesPerClass);
|
|
177
|
+
}
|
|
178
|
+
return child;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
modifiedElement = React.cloneElement(
|
|
182
|
+
modifiedElement,
|
|
183
|
+
__spreadValues(__spreadProps(__spreadValues({}, modifiedElement.props), {
|
|
184
|
+
className: resultingClassName
|
|
185
|
+
}), typeof resultingStyle === "undefined" ? {} : { style: resultingStyle }),
|
|
186
|
+
...resultingChildren
|
|
187
|
+
);
|
|
188
|
+
if (typeof modifiedElement.type === "function") {
|
|
189
|
+
const component = modifiedElement.type;
|
|
190
|
+
const renderedComponent = component(modifiedElement.props);
|
|
191
|
+
if (React.isValidElement(renderedComponent)) {
|
|
192
|
+
modifiedElement = processElement(
|
|
193
|
+
renderedComponent,
|
|
194
|
+
nonMediaQueryTailwindStylesPerClass
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return modifiedElement;
|
|
199
|
+
}
|
|
200
|
+
function processHead(headElement, responsiveStyles) {
|
|
201
|
+
const styleElement = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: minifyCss(responsiveStyles.join("")) });
|
|
202
|
+
return React.cloneElement(
|
|
203
|
+
headElement,
|
|
204
|
+
headElement.props,
|
|
205
|
+
...React.Children.toArray(headElement.props.children),
|
|
206
|
+
styleElement
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
var Tailwind = ({ children, config }) => {
|
|
210
|
+
let headStyles = [];
|
|
211
|
+
const markupWithTailwindClasses = (0, import_server.renderToStaticMarkup)(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children }));
|
|
212
|
+
const markupCSS = getCssForMarkup(markupWithTailwindClasses, config);
|
|
213
|
+
const nonMediaQueryCSS = markupCSS.replaceAll(
|
|
214
|
+
/@media\s*\(.*\)\s*{\s*\.(.*)\s*{[\s\S]*}\s*}/gm,
|
|
215
|
+
(mediaQuery, _className) => {
|
|
216
|
+
headStyles.push(
|
|
217
|
+
mediaQuery.replace(/[\r\n|\r|\n]+/g, "").replace(/\s+/g, " ").replaceAll(/\s*\.[\S]+\s*{([^}]*)}/gm, (match, content) => {
|
|
218
|
+
return match.replace(
|
|
219
|
+
content,
|
|
220
|
+
content.split(";").map(
|
|
221
|
+
(propertyDeclaration) => propertyDeclaration.endsWith("!important") ? propertyDeclaration.trim() : `${propertyDeclaration.trim()}!important`
|
|
222
|
+
).join(";")
|
|
223
|
+
);
|
|
224
|
+
})
|
|
225
|
+
);
|
|
226
|
+
return "";
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
const nonMediaQueryTailwindStylesPerClass = getStylesPerClassMap(nonMediaQueryCSS);
|
|
230
|
+
const childrenArray = React.Children.toArray(children);
|
|
231
|
+
const validElementsWithIndexes = childrenArray.map((child, i) => [child, i]).filter(([child]) => React.isValidElement(child));
|
|
232
|
+
let headElementIndex = -1;
|
|
233
|
+
validElementsWithIndexes.forEach(([element, i]) => {
|
|
234
|
+
childrenArray[i] = processElement(
|
|
235
|
+
element,
|
|
236
|
+
nonMediaQueryTailwindStylesPerClass
|
|
237
|
+
);
|
|
238
|
+
if (element.type === "head" || typeof element.type === "function" && "name" in element.type && element.type.name === "Head") {
|
|
239
|
+
headElementIndex = i;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
headStyles = headStyles.filter((style) => style.trim().length > 0);
|
|
243
|
+
if (headStyles.length > 0) {
|
|
244
|
+
if (headElementIndex === -1) {
|
|
245
|
+
throw new Error(
|
|
246
|
+
"Tailwind: To use responsive styles you must have a <head> element as a direct child of the Tailwind component."
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
const [headElement, headAllElementsIndex] = validElementsWithIndexes[headElementIndex];
|
|
250
|
+
childrenArray[headAllElementsIndex] = processHead(headElement, headStyles);
|
|
251
|
+
}
|
|
252
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: childrenArray });
|
|
253
|
+
};
|
|
254
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
255
|
+
0 && (module.exports = {
|
|
256
|
+
Tailwind
|
|
257
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
21
|
+
// src/tailwind.tsx
|
|
22
|
+
import * as React from "react";
|
|
23
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
24
|
+
|
|
25
|
+
// src/utils/css-to-jsx-style.ts
|
|
26
|
+
var camelCase = (string) => string.replace(/-(\w|$)/g, (_, p1) => p1.toUpperCase());
|
|
27
|
+
var convertPropertyName = (prop) => {
|
|
28
|
+
let modifiedProp = prop;
|
|
29
|
+
modifiedProp = modifiedProp.toLowerCase();
|
|
30
|
+
if (modifiedProp === "float") {
|
|
31
|
+
return "cssFloat";
|
|
32
|
+
}
|
|
33
|
+
if (modifiedProp.startsWith("--")) {
|
|
34
|
+
return modifiedProp;
|
|
35
|
+
}
|
|
36
|
+
if (modifiedProp.startsWith("-ms-")) {
|
|
37
|
+
modifiedProp = modifiedProp.slice(1);
|
|
38
|
+
}
|
|
39
|
+
return camelCase(modifiedProp);
|
|
40
|
+
};
|
|
41
|
+
var cssToJsxStyle = (cssText) => {
|
|
42
|
+
const style = {};
|
|
43
|
+
const declarations = cssText.matchAll(
|
|
44
|
+
/([a-zA-Z0-9\-_]+)\s*:\s*('[^']*'[^;]*|"[^"]*"[^;]*|.*?\([^)]*\)[^;]*|[^;]*);?/gm
|
|
45
|
+
);
|
|
46
|
+
for (const [_declaration, property, value] of declarations) {
|
|
47
|
+
if (property.length > 0 && value.trim().length > 0) {
|
|
48
|
+
style[convertPropertyName(property)] = value.trim();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return style;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/utils/get-css-for-markup.ts
|
|
55
|
+
import postcss from "postcss";
|
|
56
|
+
import tailwindcss from "tailwindcss";
|
|
57
|
+
import postcssCssVariables from "postcss-css-variables";
|
|
58
|
+
global.__OXIDE__ = void 0;
|
|
59
|
+
var getCssForMarkup = (markup, config) => {
|
|
60
|
+
const corePlugins = config == null ? void 0 : config.corePlugins;
|
|
61
|
+
const tailwindConfig = __spreadProps(__spreadValues({}, config), {
|
|
62
|
+
corePlugins: __spreadValues({
|
|
63
|
+
preflight: false
|
|
64
|
+
}, corePlugins)
|
|
65
|
+
});
|
|
66
|
+
const processor = postcss([
|
|
67
|
+
tailwindcss(__spreadProps(__spreadValues({}, tailwindConfig), {
|
|
68
|
+
content: [{ raw: markup, extension: "html" }]
|
|
69
|
+
})),
|
|
70
|
+
postcssCssVariables()
|
|
71
|
+
]);
|
|
72
|
+
const result = processor.process(
|
|
73
|
+
String.raw`
|
|
74
|
+
@tailwind base;
|
|
75
|
+
@tailwind components;
|
|
76
|
+
@tailwind utilities;
|
|
77
|
+
`,
|
|
78
|
+
{ from: void 0 }
|
|
79
|
+
// no need to use from since the `content` context is sent into tailwind
|
|
80
|
+
);
|
|
81
|
+
return result.css;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/utils/minify-css.ts
|
|
85
|
+
var minifyCss = (css) => {
|
|
86
|
+
return css.replace(/\/\*[\s\S]*?\*\//gm, "").replace(/;\s+/gm, ";").replace(/:\s+/gm, ":").replace(/\)\s*{/gm, "){").replace(/\s+\(/gm, "(").replace(/{\s+/gm, "{").replace(/}\s+/gm, "}").replace(/\s*{/gm, "{").replace(/;?\s*}/gm, "}");
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/utils/get-css-class-properties-map.ts
|
|
90
|
+
var getStylesPerClassMap = (css) => {
|
|
91
|
+
const map = {};
|
|
92
|
+
for (const [_match, className, contents] of css.matchAll(
|
|
93
|
+
/\s*\.([\S]+)\s*{([^}]*)}/gm
|
|
94
|
+
)) {
|
|
95
|
+
map[className.trim()] = contents.replace(/^\n+/, "").replace(/\n+$/, "").trim();
|
|
96
|
+
}
|
|
97
|
+
return map;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/utils/escape-class-name.ts
|
|
101
|
+
var escapeClassName = (className) => {
|
|
102
|
+
return className.replace(
|
|
103
|
+
/* we need this look ahead capturing group to avoid using negative look behinds */
|
|
104
|
+
/([^\\]|^)(?=([^a-zA-Z0-9\-_]))/g,
|
|
105
|
+
(match, prefixCharacter, characterToEscape) => {
|
|
106
|
+
if (prefixCharacter === "" && characterToEscape === "\\")
|
|
107
|
+
return match;
|
|
108
|
+
return `${prefixCharacter}\\`;
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/tailwind.tsx
|
|
114
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
115
|
+
function processElement(element, nonMediaQueryTailwindStylesPerClass) {
|
|
116
|
+
let modifiedElement = element;
|
|
117
|
+
let resultingClassName = modifiedElement.props.className;
|
|
118
|
+
let resultingStyle = modifiedElement.props.style;
|
|
119
|
+
let resultingChildren = [];
|
|
120
|
+
if (modifiedElement.props.className) {
|
|
121
|
+
const fullClassName = modifiedElement.props.className;
|
|
122
|
+
const classNames = fullClassName.split(" ");
|
|
123
|
+
const classNamesToKeep = [];
|
|
124
|
+
const styles = [];
|
|
125
|
+
classNames.forEach((className) => {
|
|
126
|
+
const escapedClassName = escapeClassName(className);
|
|
127
|
+
if (typeof nonMediaQueryTailwindStylesPerClass[escapedClassName] === "undefined") {
|
|
128
|
+
classNamesToKeep.push(className);
|
|
129
|
+
} else {
|
|
130
|
+
styles.push(
|
|
131
|
+
`${nonMediaQueryTailwindStylesPerClass[escapedClassName]};`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
resultingStyle = __spreadValues(__spreadValues({}, modifiedElement.props.style), cssToJsxStyle(styles.join(" ")));
|
|
136
|
+
resultingClassName = classNamesToKeep.length > 0 ? classNamesToKeep.join(" ") : void 0;
|
|
137
|
+
}
|
|
138
|
+
if (modifiedElement.props.children) {
|
|
139
|
+
resultingChildren = React.Children.toArray(
|
|
140
|
+
modifiedElement.props.children
|
|
141
|
+
).map((child) => {
|
|
142
|
+
if (React.isValidElement(child)) {
|
|
143
|
+
return processElement(child, nonMediaQueryTailwindStylesPerClass);
|
|
144
|
+
}
|
|
145
|
+
return child;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
modifiedElement = React.cloneElement(
|
|
149
|
+
modifiedElement,
|
|
150
|
+
__spreadValues(__spreadProps(__spreadValues({}, modifiedElement.props), {
|
|
151
|
+
className: resultingClassName
|
|
152
|
+
}), typeof resultingStyle === "undefined" ? {} : { style: resultingStyle }),
|
|
153
|
+
...resultingChildren
|
|
154
|
+
);
|
|
155
|
+
if (typeof modifiedElement.type === "function") {
|
|
156
|
+
const component = modifiedElement.type;
|
|
157
|
+
const renderedComponent = component(modifiedElement.props);
|
|
158
|
+
if (React.isValidElement(renderedComponent)) {
|
|
159
|
+
modifiedElement = processElement(
|
|
160
|
+
renderedComponent,
|
|
161
|
+
nonMediaQueryTailwindStylesPerClass
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return modifiedElement;
|
|
166
|
+
}
|
|
167
|
+
function processHead(headElement, responsiveStyles) {
|
|
168
|
+
const styleElement = /* @__PURE__ */ jsx("style", { children: minifyCss(responsiveStyles.join("")) });
|
|
169
|
+
return React.cloneElement(
|
|
170
|
+
headElement,
|
|
171
|
+
headElement.props,
|
|
172
|
+
...React.Children.toArray(headElement.props.children),
|
|
173
|
+
styleElement
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
var Tailwind = ({ children, config }) => {
|
|
177
|
+
let headStyles = [];
|
|
178
|
+
const markupWithTailwindClasses = renderToStaticMarkup(/* @__PURE__ */ jsx(Fragment, { children }));
|
|
179
|
+
const markupCSS = getCssForMarkup(markupWithTailwindClasses, config);
|
|
180
|
+
const nonMediaQueryCSS = markupCSS.replaceAll(
|
|
181
|
+
/@media\s*\(.*\)\s*{\s*\.(.*)\s*{[\s\S]*}\s*}/gm,
|
|
182
|
+
(mediaQuery, _className) => {
|
|
183
|
+
headStyles.push(
|
|
184
|
+
mediaQuery.replace(/[\r\n|\r|\n]+/g, "").replace(/\s+/g, " ").replaceAll(/\s*\.[\S]+\s*{([^}]*)}/gm, (match, content) => {
|
|
185
|
+
return match.replace(
|
|
186
|
+
content,
|
|
187
|
+
content.split(";").map(
|
|
188
|
+
(propertyDeclaration) => propertyDeclaration.endsWith("!important") ? propertyDeclaration.trim() : `${propertyDeclaration.trim()}!important`
|
|
189
|
+
).join(";")
|
|
190
|
+
);
|
|
191
|
+
})
|
|
192
|
+
);
|
|
193
|
+
return "";
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
const nonMediaQueryTailwindStylesPerClass = getStylesPerClassMap(nonMediaQueryCSS);
|
|
197
|
+
const childrenArray = React.Children.toArray(children);
|
|
198
|
+
const validElementsWithIndexes = childrenArray.map((child, i) => [child, i]).filter(([child]) => React.isValidElement(child));
|
|
199
|
+
let headElementIndex = -1;
|
|
200
|
+
validElementsWithIndexes.forEach(([element, i]) => {
|
|
201
|
+
childrenArray[i] = processElement(
|
|
202
|
+
element,
|
|
203
|
+
nonMediaQueryTailwindStylesPerClass
|
|
204
|
+
);
|
|
205
|
+
if (element.type === "head" || typeof element.type === "function" && "name" in element.type && element.type.name === "Head") {
|
|
206
|
+
headElementIndex = i;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
headStyles = headStyles.filter((style) => style.trim().length > 0);
|
|
210
|
+
if (headStyles.length > 0) {
|
|
211
|
+
if (headElementIndex === -1) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
"Tailwind: To use responsive styles you must have a <head> element as a direct child of the Tailwind component."
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
const [headElement, headAllElementsIndex] = validElementsWithIndexes[headElementIndex];
|
|
217
|
+
childrenArray[headAllElementsIndex] = processHead(headElement, headStyles);
|
|
218
|
+
}
|
|
219
|
+
return /* @__PURE__ */ jsx(Fragment, { children: childrenArray });
|
|
220
|
+
};
|
|
221
|
+
export {
|
|
222
|
+
Tailwind
|
|
223
|
+
};
|
package/license.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2022 Bu Kinoshita and Zeno Rocha
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-email/tailwind",
|
|
3
|
+
"version": "0.0.13.canary.0",
|
|
4
|
+
"description": "A React component to wrap emails with Tailwind CSS",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --external react",
|
|
27
|
+
"clean": "rm -rf dist",
|
|
28
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --external react --watch",
|
|
29
|
+
"lint": "eslint .",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"test": "vitest run"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/resendlabs/react-email.git",
|
|
36
|
+
"directory": "packages/tailwind"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"react",
|
|
40
|
+
"email",
|
|
41
|
+
"tailwind"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"postcss": "8.4.31",
|
|
48
|
+
"postcss-css-variables": "0.19.0",
|
|
49
|
+
"react": "18.2.0",
|
|
50
|
+
"react-dom": "18.2.0",
|
|
51
|
+
"tailwindcss": "3.3.2"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": "18.2.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@babel/core": "7.21.8",
|
|
58
|
+
"@babel/preset-react": "7.22.5",
|
|
59
|
+
"@react-email/head": "workspace:*",
|
|
60
|
+
"@react-email/hr": "workspace:*",
|
|
61
|
+
"@react-email/html": "workspace:*",
|
|
62
|
+
"@testing-library/react": "14.0.0",
|
|
63
|
+
"@types/postcss-css-variables": "0.18.2",
|
|
64
|
+
"eslint-config-custom": "workspace:*",
|
|
65
|
+
"eslint-plugin-regex": "1.10.0",
|
|
66
|
+
"tsconfig": "workspace:*",
|
|
67
|
+
"typescript": "5.1.6"
|
|
68
|
+
},
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public"
|
|
71
|
+
}
|
|
72
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<div align="center"><strong>@react-email/tailwind</strong></div>
|
|
4
|
+
<div align="center">A React component to wrap emails with Tailwind CSS.</div>
|
|
5
|
+
<br />
|
|
6
|
+
<div align="center">
|
|
7
|
+
<a href="https://react.email">Website</a>
|
|
8
|
+
<span> · </span>
|
|
9
|
+
<a href="https://react.email">Documentation</a>
|
|
10
|
+
<span> · </span>
|
|
11
|
+
<a href="https://react.email">Twitter</a>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
Install component from your command line.
|
|
17
|
+
|
|
18
|
+
#### With yarn
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
yarn add @react-email/tailwind -E
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
#### With npm
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npm install @react-email/tailwind -E
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Getting started
|
|
31
|
+
|
|
32
|
+
Add the component around your email body content.
|
|
33
|
+
|
|
34
|
+
```jsx
|
|
35
|
+
import { Button } from "@react-email/button";
|
|
36
|
+
import { Tailwind } from "@react-email/tailwind";
|
|
37
|
+
|
|
38
|
+
const Email = () => {
|
|
39
|
+
return (
|
|
40
|
+
<Tailwind
|
|
41
|
+
config={{
|
|
42
|
+
theme: {
|
|
43
|
+
extend: {
|
|
44
|
+
colors: {
|
|
45
|
+
"custom-color": "#ff0000",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
<Button
|
|
52
|
+
href="https://example.com"
|
|
53
|
+
className="text-custom-color bg-white mx-auto"
|
|
54
|
+
>
|
|
55
|
+
Click me
|
|
56
|
+
</Button>
|
|
57
|
+
</Tailwind>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Support
|
|
63
|
+
|
|
64
|
+
This component was tested using the most popular email clients.
|
|
65
|
+
|
|
66
|
+
| <img src="https://react.email/static/icons/gmail.svg" width="48px" height="48px" alt="Gmail logo"> | <img src="https://react.email/static/icons/apple-mail.svg" width="48px" height="48px" alt="Apple Mail"> | <img src="https://react.email/static/icons/outlook.svg" width="48px" height="48px" alt="Outlook logo"> | <img src="https://react.email/static/icons/yahoo-mail.svg" width="48px" height="48px" alt="Yahoo! Mail logo"> | <img src="https://react.email/static/icons/hey.svg" width="48px" height="48px" alt="HEY logo"> | <img src="https://react.email/static/icons/superhuman.svg" width="48px" height="48px" alt="Superhuman logo"> |
|
|
67
|
+
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
68
|
+
| Gmail ✔ | Apple Mail ✔ | Outlook ✔ | Yahoo! Mail ✔ | HEY ✔ | Superhuman ✔ |
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT License
|