@react-email/tailwind 2.0.0-tailwindv4.4 → 2.0.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 CHANGED
@@ -1,6 +1,13 @@
1
1
  import * as React$1 from "react";
2
2
  import { Config } from "tailwindcss";
3
+ import { StyleSheet } from "css-tree";
3
4
 
5
+ //#region src/inline-styles.d.ts
6
+ declare function inlineStyles(styleSheet: StyleSheet, classes: string[]): Record<string, string>;
7
+ //#endregion
8
+ //#region src/sanitize-stylesheet.d.ts
9
+ declare function sanitizeStyleSheet(styleSheet: StyleSheet): void;
10
+ //#endregion
4
11
  //#region src/tailwind.d.ts
5
12
  type TailwindConfig = Omit<Config, 'content'>;
6
13
  interface TailwindProps {
@@ -18,5 +25,12 @@ declare function Tailwind({
18
25
  config
19
26
  }: TailwindProps): React$1.ReactNode;
20
27
  //#endregion
21
- export { EmailElementProps, Tailwind, TailwindConfig, TailwindProps, pixelBasedPreset };
28
+ //#region src/utils/tailwindcss/setup-tailwind.d.ts
29
+ type TailwindSetup = Awaited<ReturnType<typeof setupTailwind>>;
30
+ declare function setupTailwind(config: TailwindConfig): Promise<{
31
+ addUtilities: (candidates: string[]) => void;
32
+ getStyleSheet: () => StyleSheet;
33
+ }>;
34
+ //#endregion
35
+ export { EmailElementProps, Tailwind, TailwindConfig, TailwindProps, TailwindSetup, inlineStyles, pixelBasedPreset, sanitizeStyleSheet, setupTailwind };
22
36
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/tailwind.tsx"],"sourcesContent":[],"mappings":";;;;KAaY,cAAA,GAAiB,KAAK;UAEjB,aAAA;EAFL,QAAA,EAGA,OAAA,CAAM,SAHQ;EAAA,MAAA,CAAA,EAIf,cAJe;;AAAG,UAOZ,iBAAA,CAPY;EAAI,QAAA,CAAA,EAQpB,OAAA,CAAM,SARc;EAEhB,SAAA,CAAA,EAAA,MAAa;EAAA,KAAA,CAAA,EAQpB,OAAA,CAAM,aARc;;AAEnB,cASE,gBATF,EASoB,cATpB;AAAc,iBAoET,QAAA,CApES;EAAA,QAAA;EAAA;AAAA,CAAA,EAoEsB,aApEtB,CAAA,EAoEmC,OAAA,CAAA,SApEnC"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/inline-styles.ts","../src/sanitize-stylesheet.ts","../src/tailwind.tsx","../src/utils/tailwindcss/setup-tailwind.ts"],"sourcesContent":[],"mappings":";;;;;iBAKgB,YAAA,aACF,gCAEX;;;iBCHa,kBAAA,aAA+B;;;KCOnC,cAAA,GAAiB,KAAK;UAEjB,aAAA;YACL,OAAA,CAAM;EFVF,MAAA,CAAA,EEWL,cFXiB;;UEcX,iBAAA;aACJ,OAAA,CAAM;EDfH,SAAA,CAAA,EAAA,MAAA;UCiBN,OAAA,CAAM;;cAGH,kBAAkB;AAbnB,iBAwEI,QAAA,CAxEkB;EAAA,QAAL;EAAI;AAAA,CAAA,EAwEc,aAxEd,CAAA,EAwE2B,OAAA,CAAA,SAxE3B;;;KCJrB,aAAA,GAAgB,QAAQ,kBAAkB;iBAEhC,aAAA,SAAsB,iBAAc;;EHL1C,aAAA,EAAY,GAAA,GGyED,UHxEb"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
+ import { StyleSheet } from "css-tree";
1
2
  import * as React from "react";
2
3
  import { Config } from "tailwindcss";
3
4
 
5
+ //#region src/inline-styles.d.ts
6
+ declare function inlineStyles(styleSheet: StyleSheet, classes: string[]): Record<string, string>;
7
+ //#endregion
8
+ //#region src/sanitize-stylesheet.d.ts
9
+ declare function sanitizeStyleSheet(styleSheet: StyleSheet): void;
10
+ //#endregion
4
11
  //#region src/tailwind.d.ts
5
12
  type TailwindConfig = Omit<Config, 'content'>;
6
13
  interface TailwindProps {
@@ -18,5 +25,12 @@ declare function Tailwind({
18
25
  config
19
26
  }: TailwindProps): React.ReactNode;
20
27
  //#endregion
21
- export { EmailElementProps, Tailwind, TailwindConfig, TailwindProps, pixelBasedPreset };
28
+ //#region src/utils/tailwindcss/setup-tailwind.d.ts
29
+ type TailwindSetup = Awaited<ReturnType<typeof setupTailwind>>;
30
+ declare function setupTailwind(config: TailwindConfig): Promise<{
31
+ addUtilities: (candidates: string[]) => void;
32
+ getStyleSheet: () => StyleSheet;
33
+ }>;
34
+ //#endregion
35
+ export { EmailElementProps, Tailwind, TailwindConfig, TailwindProps, TailwindSetup, inlineStyles, pixelBasedPreset, sanitizeStyleSheet, setupTailwind };
22
36
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/tailwind.tsx"],"sourcesContent":[],"mappings":";;;;KAaY,cAAA,GAAiB,KAAK;UAEjB,aAAA;EAFL,QAAA,EAGA,KAAA,CAAM,SAHQ;EAAA,MAAA,CAAA,EAIf,cAJe;;AAAG,UAOZ,iBAAA,CAPY;EAAI,QAAA,CAAA,EAQpB,KAAA,CAAM,SARc;EAEhB,SAAA,CAAA,EAAA,MAAa;EAAA,KAAA,CAAA,EAQpB,KAAA,CAAM,aARc;;AAEnB,cASE,gBATF,EASoB,cATpB;AAAc,iBAoET,QAAA,CApES;EAAA,QAAA;EAAA;AAAA,CAAA,EAoEsB,aApEtB,CAAA,EAoEmC,KAAA,CAAA,SApEnC"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/inline-styles.ts","../src/sanitize-stylesheet.ts","../src/tailwind.tsx","../src/utils/tailwindcss/setup-tailwind.ts"],"sourcesContent":[],"mappings":";;;;;iBAKgB,YAAA,aACF,gCAEX;;;iBCHa,kBAAA,aAA+B;;;KCOnC,cAAA,GAAiB,KAAK;UAEjB,aAAA;YACL,KAAA,CAAM;EFVF,MAAA,CAAA,EEWL,cFXiB;;UEcX,iBAAA;aACJ,KAAA,CAAM;EDfH,SAAA,CAAA,EAAA,MAAA;UCiBN,KAAA,CAAM;;cAGH,kBAAkB;AAbnB,iBAwEI,QAAA,CAxEkB;EAAA,QAAL;EAAI;AAAA,CAAA,EAwEc,aAxEd,CAAA,EAwE2B,KAAA,CAAA,SAxE3B;;;KCJrB,aAAA,GAAgB,QAAQ,kBAAkB;iBAEhC,aAAA,SAAsB,iBAAc;;EHL1C,aAAA,EAAY,GAAA,GGyED,UHxEb"}
package/dist/index.js CHANGED
@@ -54,6 +54,8 @@ let __react_email_link = require("@react-email/link");
54
54
  __react_email_link = __toESM(__react_email_link);
55
55
  let __react_email_preview = require("@react-email/preview");
56
56
  __react_email_preview = __toESM(__react_email_preview);
57
+ let __react_email_text = require("@react-email/text");
58
+ __react_email_text = __toESM(__react_email_text);
57
59
  let tailwindcss = require("tailwindcss");
58
60
  tailwindcss = __toESM(tailwindcss);
59
61
  let react_jsx_runtime = require("react/jsx-runtime");
@@ -19036,21 +19038,6 @@ const { version } = {
19036
19038
  //#region ../../node_modules/.pnpm/css-tree@3.1.0/node_modules/css-tree/lib/index.js
19037
19039
  const { tokenize, parse, generate, lexer, createLexer, walk, find, findLast, findAll, toPlainObject, fromPlainObject, fork } = syntax_default;
19038
19040
 
19039
- //#endregion
19040
- //#region src/hooks/use-suspended-promise.ts
19041
- const promiseStates = /* @__PURE__ */ new Map();
19042
- function useSuspensedPromise(promiseFn, key) {
19043
- const previousState = promiseStates.get(key);
19044
- if (previousState) {
19045
- if ("error" in previousState) throw previousState.error;
19046
- if ("result" in previousState) return previousState.result;
19047
- throw previousState.promise;
19048
- }
19049
- const state = { promise: promiseFn().then((result) => state.result = result).catch((error) => state.error = error) };
19050
- promiseStates.set(key, state);
19051
- throw state.promise;
19052
- }
19053
-
19054
19041
  //#endregion
19055
19042
  //#region src/utils/css/is-rule-inlinable.ts
19056
19043
  function isRuleInlinable(rule) {
@@ -19087,20 +19074,112 @@ function extractRulesPerClass(root, classes) {
19087
19074
  }
19088
19075
 
19089
19076
  //#endregion
19090
- //#region src/utils/css/populate-parents-for-node-tree.ts
19091
- function populateParentsForNodeTree(node) {
19092
- const parentPath = [];
19077
+ //#region src/utils/css/get-custom-properties.ts
19078
+ function getCustomProperties(node) {
19079
+ const customProperties = /* @__PURE__ */ new Map();
19093
19080
  walk(node, {
19094
- enter(child, parentListItem, parentList) {
19095
- child.parent = parentPath[parentPath.length - 1];
19096
- child.containingItem = parentListItem;
19097
- child.containedIn = parentList;
19098
- parentPath.push(child);
19099
- },
19100
- leave() {
19101
- parentPath.pop();
19081
+ visit: "Atrule",
19082
+ enter(atrule) {
19083
+ if (atrule.name === "property" && atrule.prelude) {
19084
+ const prelude = generate(atrule.prelude);
19085
+ if (prelude.startsWith("--")) {
19086
+ let syntax;
19087
+ let inherits;
19088
+ let initialValue;
19089
+ walk(atrule, {
19090
+ visit: "Declaration",
19091
+ enter(declaration) {
19092
+ if (declaration.property === "syntax") syntax = declaration;
19093
+ if (declaration.property === "inherits") inherits = declaration;
19094
+ if (declaration.property === "initial-value") initialValue = declaration;
19095
+ }
19096
+ });
19097
+ customProperties.set(prelude, {
19098
+ syntax,
19099
+ inherits,
19100
+ initialValue
19101
+ });
19102
+ }
19103
+ }
19104
+ }
19105
+ });
19106
+ return customProperties;
19107
+ }
19108
+
19109
+ //#endregion
19110
+ //#region src/utils/text/from-dash-case-to-camel-case.ts
19111
+ const fromDashCaseToCamelCase = (text) => {
19112
+ return text.replace(/-(\w|$)/g, (_, p1) => p1.toUpperCase());
19113
+ };
19114
+
19115
+ //#endregion
19116
+ //#region src/utils/compatibility/get-react-property.ts
19117
+ function getReactProperty(prop) {
19118
+ const modifiedProp = prop.toLowerCase();
19119
+ if (modifiedProp.startsWith("--")) return modifiedProp;
19120
+ if (modifiedProp.startsWith("-ms-")) return fromDashCaseToCamelCase(modifiedProp.slice(1));
19121
+ return fromDashCaseToCamelCase(modifiedProp);
19122
+ }
19123
+
19124
+ //#endregion
19125
+ //#region src/utils/css/unwrap-value.ts
19126
+ function unwrapValue(value) {
19127
+ if (value.type === "Value" && value.children.size === 1) return value.children.first ?? value;
19128
+ return value;
19129
+ }
19130
+
19131
+ //#endregion
19132
+ //#region src/utils/css/make-inline-styles-for.ts
19133
+ function makeInlineStylesFor(inlinableRules, customProperties) {
19134
+ const styles = {};
19135
+ const localVariableDeclarations = /* @__PURE__ */ new Map();
19136
+ for (const rule of inlinableRules) walk(rule, {
19137
+ visit: "Declaration",
19138
+ enter(declaration) {
19139
+ if (declaration.property.startsWith("--")) localVariableDeclarations.set(declaration.property, declaration);
19102
19140
  }
19103
19141
  });
19142
+ for (const rule of inlinableRules) {
19143
+ walk(rule, {
19144
+ visit: "Function",
19145
+ enter(func, funcParentListItem) {
19146
+ if (func.name === "var") {
19147
+ let variableName;
19148
+ walk(func, {
19149
+ visit: "Identifier",
19150
+ enter(identifier) {
19151
+ variableName = identifier.name;
19152
+ return this.break;
19153
+ }
19154
+ });
19155
+ if (variableName) {
19156
+ const definition = localVariableDeclarations.get(variableName);
19157
+ if (definition) funcParentListItem.data = unwrapValue(definition.value);
19158
+ else {
19159
+ const customProperty = customProperties.get(variableName);
19160
+ if (customProperty?.initialValue) funcParentListItem.data = unwrapValue(customProperty.initialValue.value);
19161
+ }
19162
+ }
19163
+ }
19164
+ }
19165
+ });
19166
+ walk(rule, {
19167
+ visit: "Declaration",
19168
+ enter(declaration) {
19169
+ if (declaration.property.startsWith("--")) return;
19170
+ styles[getReactProperty(declaration.property)] = generate(declaration.value) + (declaration.important ? "!important" : "");
19171
+ }
19172
+ });
19173
+ }
19174
+ return styles;
19175
+ }
19176
+
19177
+ //#endregion
19178
+ //#region src/inline-styles.ts
19179
+ function inlineStyles(styleSheet, classes) {
19180
+ const { inlinable: inlinableRules } = extractRulesPerClass(styleSheet, classes);
19181
+ const customProperties = getCustomProperties(styleSheet);
19182
+ return makeInlineStylesFor(Array.from(inlinableRules.values()), customProperties);
19104
19183
  }
19105
19184
 
19106
19185
  //#endregion
@@ -19108,70 +19187,74 @@ function populateParentsForNodeTree(node) {
19108
19187
  function doSelectorsIntersect(first, second) {
19109
19188
  if (generate(first) === generate(second)) return true;
19110
19189
  let hasSomeUniversal = false;
19111
- const walker = (node) => {
19190
+ const walker = (node, _parentListItem, parentList) => {
19112
19191
  if (hasSomeUniversal) return;
19113
19192
  if (node.type === "PseudoClassSelector" && node.name === "root") hasSomeUniversal = true;
19114
- if (node.type === "TypeSelector" && node.name === "*" && node.containedIn?.size === 1) hasSomeUniversal = true;
19193
+ if (node.type === "TypeSelector" && node.name === "*" && parentList.size === 1) hasSomeUniversal = true;
19115
19194
  };
19116
19195
  walk(first, walker);
19117
19196
  walk(second, walker);
19118
19197
  if (hasSomeUniversal) return true;
19119
19198
  return false;
19120
19199
  }
19121
- function someParent(node, predicate) {
19122
- if (node.parent) {
19123
- if (predicate(node.parent)) return true;
19124
- return someParent(node.parent, predicate);
19125
- }
19126
- return false;
19127
- }
19128
19200
  function resolveAllCssVariables(node) {
19129
- populateParentsForNodeTree(node);
19130
19201
  const variableDefinitions = /* @__PURE__ */ new Set();
19131
19202
  const variableUses = /* @__PURE__ */ new Set();
19203
+ const path = [];
19132
19204
  walk(node, {
19133
- visit: "Declaration",
19134
- enter(declaration) {
19135
- if (someParent(declaration, (ancestor) => ancestor.type === "Atrule" && ancestor.name === "layer" && ancestor.prelude !== null && generate(ancestor.prelude).includes("properties"))) return;
19136
- if (/--[\S]+/.test(declaration.property)) variableDefinitions.add({
19137
- declaration,
19138
- variableName: declaration.property,
19139
- definition: generate(declaration.value)
19140
- });
19141
- else {
19142
- function parseVariableUsesFrom(node$1) {
19143
- walk(node$1, {
19144
- visit: "Function",
19145
- enter(funcNode) {
19146
- if (funcNode.name === "var") {
19147
- const children = funcNode.children.toArray();
19148
- const name$49 = generate(children[0]);
19149
- const fallback = children[2] ? generate(children[2]) : void 0;
19150
- variableUses.add({
19151
- declaration,
19152
- fallback,
19153
- variableName: name$49,
19154
- raw: generate(funcNode)
19155
- });
19156
- if (fallback?.includes("var(")) parseVariableUsesFrom(parse(fallback, { context: "value" }));
19205
+ leave() {
19206
+ path.shift();
19207
+ },
19208
+ enter(node$1) {
19209
+ if (node$1.type === "Declaration") {
19210
+ const declaration = node$1;
19211
+ if (path.some((ancestor) => ancestor.type === "Atrule" && ancestor.name === "layer" && ancestor.prelude !== null && generate(ancestor.prelude).includes("properties"))) {
19212
+ path.unshift(node$1);
19213
+ return;
19214
+ }
19215
+ if (/--[\S]+/.test(declaration.property)) variableDefinitions.add({
19216
+ declaration,
19217
+ path: [...path],
19218
+ variableName: declaration.property,
19219
+ definition: generate(declaration.value)
19220
+ });
19221
+ else {
19222
+ function parseVariableUsesFrom(node$2) {
19223
+ walk(node$2, {
19224
+ visit: "Function",
19225
+ enter(funcNode) {
19226
+ if (funcNode.name === "var") {
19227
+ const children = funcNode.children.toArray();
19228
+ const name$49 = generate(children[0]);
19229
+ const fallback = children[2] ? generate(children[2]) : void 0;
19230
+ variableUses.add({
19231
+ declaration,
19232
+ path: [...path],
19233
+ fallback,
19234
+ variableName: name$49,
19235
+ raw: generate(funcNode)
19236
+ });
19237
+ if (fallback?.includes("var(")) parseVariableUsesFrom(parse(fallback, { context: "value" }));
19238
+ }
19157
19239
  }
19158
- }
19159
- });
19240
+ });
19241
+ }
19242
+ parseVariableUsesFrom(declaration.value);
19160
19243
  }
19161
- parseVariableUsesFrom(declaration.value);
19162
19244
  }
19245
+ path.unshift(node$1);
19163
19246
  }
19164
19247
  });
19165
19248
  for (const use of variableUses) {
19166
19249
  let hasReplaced = false;
19167
19250
  for (const definition of variableDefinitions) {
19168
19251
  if (use.variableName !== definition.variableName) continue;
19169
- if (use.declaration.parent?.type === "Block" && use.declaration.parent?.parent?.type === "Atrule" && use.declaration.parent.parent?.parent?.type === "Block" && use.declaration.parent.parent?.parent?.parent?.type === "Rule" && definition.declaration.parent?.type === "Block" && definition.declaration.parent?.parent?.type === "Rule" && doSelectorsIntersect(use.declaration.parent.parent.parent.parent.prelude, definition.declaration.parent.parent.prelude)) {
19252
+ if (use.path[0]?.type === "Block" && use.path[1]?.type === "Atrule" && use.path[2]?.type === "Block" && use.path[3]?.type === "Rule" && definition.path[0].type === "Block" && definition.path[1].type === "Rule" && doSelectorsIntersect(use.path[3].prelude, definition.path[1].prelude)) {
19170
19253
  use.declaration.value = parse(generate(use.declaration.value).replaceAll(use.raw, definition.definition), { context: "value" });
19171
19254
  hasReplaced = true;
19172
19255
  break;
19173
19256
  }
19174
- if (use.declaration.parent?.type === "Block" && use.declaration.parent?.parent?.type === "Rule" && definition.declaration.parent?.type === "Block" && definition.declaration.parent?.parent?.type === "Rule" && doSelectorsIntersect(use.declaration.parent.parent.prelude, definition.declaration.parent.parent.prelude)) {
19257
+ if (use.path[0]?.type === "Block" && use.path[1]?.type === "Rule" && definition.path[0]?.type === "Block" && definition.path[1]?.type === "Rule" && doSelectorsIntersect(use.path[1].prelude, definition.path[1].prelude)) {
19175
19258
  use.declaration.value = parse(generate(use.declaration.value).replaceAll(use.raw, definition.definition), { context: "value" });
19176
19259
  hasReplaced = true;
19177
19260
  break;
@@ -19273,6 +19356,44 @@ function resolveCalcExpressions(node) {
19273
19356
 
19274
19357
  //#endregion
19275
19358
  //#region src/utils/css/sanitize-declarations.ts
19359
+ function rgbNode(r, g, b, alpha) {
19360
+ const children = new List();
19361
+ children.appendData({
19362
+ type: "Number",
19363
+ value: r.toFixed(0)
19364
+ });
19365
+ children.appendData({
19366
+ type: "Operator",
19367
+ value: ","
19368
+ });
19369
+ children.appendData({
19370
+ type: "Number",
19371
+ value: g.toFixed(0)
19372
+ });
19373
+ children.appendData({
19374
+ type: "Operator",
19375
+ value: ","
19376
+ });
19377
+ children.appendData({
19378
+ type: "Number",
19379
+ value: b.toFixed(0)
19380
+ });
19381
+ if (alpha !== 1 && alpha !== void 0) {
19382
+ children.appendData({
19383
+ type: "Operator",
19384
+ value: ","
19385
+ });
19386
+ children.appendData({
19387
+ type: "Number",
19388
+ value: alpha.toString()
19389
+ });
19390
+ }
19391
+ return {
19392
+ type: "Function",
19393
+ name: "rgb",
19394
+ children
19395
+ };
19396
+ }
19276
19397
  const LAB_TO_LMS = {
19277
19398
  l: [.3963377773761749, .2158037573099136],
19278
19399
  m: [-.1055613458156586, -.0638541728258133],
@@ -19321,9 +19442,9 @@ function oklchToRgb(oklch) {
19321
19442
  const g = 255 * lrgbToRgb(LSM_TO_RGB.g[0] * l + LSM_TO_RGB.g[1] * m + LSM_TO_RGB.g[2] * s);
19322
19443
  const b = 255 * lrgbToRgb(LSM_TO_RGB.b[0] * l + LSM_TO_RGB.b[1] * m + LSM_TO_RGB.b[2] * s);
19323
19444
  return {
19324
- r: clamp(r, 0, 255).toFixed(0),
19325
- g: clamp(g, 0, 255).toFixed(0),
19326
- b: clamp(b, 0, 255).toFixed(0)
19445
+ r: clamp(r, 0, 255),
19446
+ g: clamp(g, 0, 255),
19447
+ b: clamp(b, 0, 255)
19327
19448
  };
19328
19449
  }
19329
19450
  function separteShorthandDeclaration(shorthandToReplace, [start, end]) {
@@ -19364,6 +19485,7 @@ function sanitizeDeclarations(nodeContainingDeclarations) {
19364
19485
  walk(nodeContainingDeclarations, {
19365
19486
  visit: "Declaration",
19366
19487
  enter(declaration, item, list) {
19488
+ if (declaration.value.type === "Raw") declaration.value = parse(declaration.value.value, { context: "value" });
19367
19489
  if (/border-radius\s*:\s*calc\s*\(\s*infinity\s*\*\s*1px\s*\)/i.test(generate(declaration))) declaration.value = parse("9999px", { context: "value" });
19368
19490
  walk(declaration, {
19369
19491
  visit: "Function",
@@ -19413,8 +19535,7 @@ function sanitizeDeclarations(nodeContainingDeclarations) {
19413
19535
  c,
19414
19536
  h
19415
19537
  });
19416
- const alphaString = a !== void 0 ? `,${a}` : "";
19417
- funcParentListItem.data = parse(`rgb(${rgb.r},${rgb.g},${rgb.b}${alphaString})`, { context: "value" });
19538
+ funcParentListItem.data = rgbNode(rgb.r, rgb.g, rgb.b, a);
19418
19539
  }
19419
19540
  if (func.name === "rgb") {
19420
19541
  let r;
@@ -19457,8 +19578,8 @@ function sanitizeDeclarations(nodeContainingDeclarations) {
19457
19578
  }
19458
19579
  }
19459
19580
  if (r === void 0 || g === void 0 || b === void 0) throw new Error("Could not determine the parameters of an rgb() function.", { cause: declaration });
19460
- if (a === void 0 || a === 1) funcParentListItem.data = parse(`rgb(${r},${g},${b})`, { context: "value" });
19461
- else funcParentListItem.data = parse(`rgb(${r},${g},${b},${a})`, { context: "value" });
19581
+ if (a === void 0 || a === 1) funcParentListItem.data = rgbNode(r, g, b);
19582
+ else funcParentListItem.data = rgbNode(r, g, b, a);
19462
19583
  }
19463
19584
  }
19464
19585
  });
@@ -19467,45 +19588,42 @@ function sanitizeDeclarations(nodeContainingDeclarations) {
19467
19588
  enter(hash, hashParentListItem) {
19468
19589
  const hex = hash.value.trim();
19469
19590
  if (hex.length === 3) {
19470
- hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.charAt(0) + hex.charAt(0), 16)},${Number.parseInt(hex.charAt(1) + hex.charAt(1), 16)},${Number.parseInt(hex.charAt(2) + hex.charAt(2), 16)})`, { context: "value" });
19591
+ hashParentListItem.data = rgbNode(Number.parseInt(hex.charAt(0) + hex.charAt(0), 16), Number.parseInt(hex.charAt(1) + hex.charAt(1), 16), Number.parseInt(hex.charAt(2) + hex.charAt(2), 16));
19471
19592
  return;
19472
19593
  }
19473
19594
  if (hex.length === 4) {
19474
- hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.charAt(0) + hex.charAt(0), 16)},${Number.parseInt(hex.charAt(1) + hex.charAt(1), 16)},${Number.parseInt(hex.charAt(2) + hex.charAt(2), 16)},${(Number.parseInt(hex.charAt(3) + hex.charAt(3), 16) / 255).toFixed(1)})`, { context: "value" });
19595
+ hashParentListItem.data = rgbNode(Number.parseInt(hex.charAt(0) + hex.charAt(0), 16), Number.parseInt(hex.charAt(1) + hex.charAt(1), 16), Number.parseInt(hex.charAt(2) + hex.charAt(2), 16), Number.parseInt(hex.charAt(3) + hex.charAt(3), 16) / 255);
19475
19596
  return;
19476
19597
  }
19477
19598
  if (hex.length === 5) {
19478
- hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.charAt(2) + hex.charAt(2), 16)},${Number.parseInt(hex.charAt(3) + hex.charAt(3), 16)},${(Number.parseInt(hex.charAt(4) + hex.charAt(4), 16) / 255).toFixed(1)})`, { context: "value" });
19599
+ hashParentListItem.data = rgbNode(Number.parseInt(hex.slice(0, 2), 16), Number.parseInt(hex.charAt(2) + hex.charAt(2), 16), Number.parseInt(hex.charAt(3) + hex.charAt(3), 16), Number.parseInt(hex.charAt(4) + hex.charAt(4), 16) / 255);
19479
19600
  return;
19480
19601
  }
19481
19602
  if (hex.length === 6) {
19482
- hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.slice(2, 4), 16)},${Number.parseInt(hex.slice(4, 6), 16)})`, { context: "value" });
19603
+ hashParentListItem.data = rgbNode(Number.parseInt(hex.slice(0, 2), 16), Number.parseInt(hex.slice(2, 4), 16), Number.parseInt(hex.slice(4, 6), 16));
19483
19604
  return;
19484
19605
  }
19485
19606
  if (hex.length === 7) {
19486
- hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.slice(2, 4), 16)},${Number.parseInt(hex.slice(4, 6), 16)},${(Number.parseInt(hex.charAt(6) + hex.charAt(6), 16) / 255).toFixed(1)})`, { context: "value" });
19607
+ hashParentListItem.data = rgbNode(Number.parseInt(hex.slice(0, 2), 16), Number.parseInt(hex.slice(2, 4), 16), Number.parseInt(hex.slice(4, 6), 16), Number.parseInt(hex.charAt(6) + hex.charAt(6), 16) / 255);
19487
19608
  return;
19488
19609
  }
19489
- hashParentListItem.data = parse(`rgb(${Number.parseInt(hex.slice(0, 2), 16)},${Number.parseInt(hex.slice(2, 4), 16)},${Number.parseInt(hex.slice(4, 6), 16)},${(Number.parseInt(hex.slice(6, 8), 16) / 255).toFixed(1)})`, { context: "value" });
19610
+ hashParentListItem.data = rgbNode(Number.parseInt(hex.slice(0, 2), 16), Number.parseInt(hex.slice(2, 4), 16), Number.parseInt(hex.slice(4, 6), 16), Number.parseInt(hex.slice(6, 8), 16) / 255);
19490
19611
  }
19491
19612
  });
19492
19613
  walk(declaration, {
19493
19614
  visit: "Function",
19494
19615
  enter(func, parentListItem) {
19495
19616
  if (func.name === "color-mix") {
19496
- const originalColor = find(func, (node) => node.type === "Function" && node.name === "rgb");
19497
- const percentage$1 = find(func, (node) => node.type === "Percentage");
19498
- if (func.children.last?.type === "Identifier" && func.children.last.name === "transparent" && originalColor && percentage$1) {
19499
- const alpha = Number.parseFloat(percentage$1.value) / 100;
19500
- originalColor.children.appendData({
19617
+ const children = func.children.toArray();
19618
+ const color = children[3];
19619
+ const opacity = children[4];
19620
+ if (func.children.last?.type === "Identifier" && func.children.last.name === "transparent" && color?.type === "Function" && color?.name === "rgb" && opacity) {
19621
+ color.children.appendData({
19501
19622
  type: "Operator",
19502
19623
  value: ","
19503
19624
  });
19504
- originalColor.children.appendData({
19505
- type: "Number",
19506
- value: alpha.toString()
19507
- });
19508
- parentListItem.data = originalColor;
19625
+ color.children.appendData(opacity);
19626
+ parentListItem.data = color;
19509
19627
  }
19510
19628
  }
19511
19629
  }
@@ -19530,6 +19648,29 @@ function sanitizeDeclarations(nodeContainingDeclarations) {
19530
19648
  });
19531
19649
  }
19532
19650
 
19651
+ //#endregion
19652
+ //#region src/sanitize-stylesheet.ts
19653
+ function sanitizeStyleSheet(styleSheet) {
19654
+ resolveAllCssVariables(styleSheet);
19655
+ resolveCalcExpressions(styleSheet);
19656
+ sanitizeDeclarations(styleSheet);
19657
+ }
19658
+
19659
+ //#endregion
19660
+ //#region src/hooks/use-suspended-promise.ts
19661
+ const promiseStates = /* @__PURE__ */ new Map();
19662
+ function useSuspensedPromise(promiseFn, key) {
19663
+ const previousState = promiseStates.get(key);
19664
+ if (previousState) {
19665
+ if ("error" in previousState) throw previousState.error;
19666
+ if ("result" in previousState) return previousState.result;
19667
+ throw previousState.promise;
19668
+ }
19669
+ const state = { promise: promiseFn().then((result) => state.result = result).catch((error) => state.error = error) };
19670
+ promiseStates.set(key, state);
19671
+ throw state.promise;
19672
+ }
19673
+
19533
19674
  //#endregion
19534
19675
  //#region src/utils/compatibility/sanitize-class-name.ts
19535
19676
  const digitToNameMap = {
@@ -19598,7 +19739,8 @@ const componentsToTreatAsElements = [
19598
19739
  __react_email_hr.Hr,
19599
19740
  __react_email_img.Img,
19600
19741
  __react_email_link.Link,
19601
- __react_email_preview.Preview
19742
+ __react_email_preview.Preview,
19743
+ __react_email_text.Text
19602
19744
  ];
19603
19745
  const isComponent = (element) => {
19604
19746
  return (typeof element.type === "function" || element.type.render !== void 0) && !componentsToTreatAsElements.includes(element.type);
@@ -19632,66 +19774,9 @@ function mapReactTree(value, process) {
19632
19774
  return mapped && mapped.length === 1 ? mapped[0] : mapped;
19633
19775
  }
19634
19776
 
19635
- //#endregion
19636
- //#region src/utils/text/from-dash-case-to-camel-case.ts
19637
- const fromDashCaseToCamelCase = (text) => {
19638
- return text.replace(/-(\w|$)/g, (_, p1) => p1.toUpperCase());
19639
- };
19640
-
19641
- //#endregion
19642
- //#region src/utils/compatibility/get-react-property.ts
19643
- function getReactProperty(prop) {
19644
- const modifiedProp = prop.toLowerCase();
19645
- if (modifiedProp.startsWith("--")) return modifiedProp;
19646
- if (modifiedProp.startsWith("-ms-")) return fromDashCaseToCamelCase(modifiedProp.slice(1));
19647
- return fromDashCaseToCamelCase(modifiedProp);
19648
- }
19649
-
19650
- //#endregion
19651
- //#region src/utils/css/make-inline-styles-for.ts
19652
- function makeInlineStylesFor(inlinableRules) {
19653
- const styles = {};
19654
- const localVariableDeclarations = /* @__PURE__ */ new Set();
19655
- for (const rule of inlinableRules) walk(rule, {
19656
- visit: "Declaration",
19657
- enter(declaration) {
19658
- if (declaration.property.startsWith("--")) localVariableDeclarations.add(declaration);
19659
- }
19660
- });
19661
- for (const rule of inlinableRules) {
19662
- walk(rule, {
19663
- visit: "Function",
19664
- enter(func, funcParentListItem) {
19665
- if (func.name === "var") {
19666
- let variableName;
19667
- walk(func, {
19668
- visit: "Identifier",
19669
- enter(identifier) {
19670
- variableName = identifier.name;
19671
- return this.break;
19672
- }
19673
- });
19674
- if (variableName) {
19675
- const definition = Array.from(localVariableDeclarations).find((declaration) => variableName === declaration.property);
19676
- if (definition) funcParentListItem.data = definition.value;
19677
- }
19678
- }
19679
- }
19680
- });
19681
- walk(rule, {
19682
- visit: "Declaration",
19683
- enter(declaration) {
19684
- if (declaration.property.startsWith("--")) return;
19685
- styles[getReactProperty(declaration.property)] = generate(declaration.value) + (declaration.important ? "!important" : "");
19686
- }
19687
- });
19688
- }
19689
- return styles;
19690
- }
19691
-
19692
19777
  //#endregion
19693
19778
  //#region src/utils/tailwindcss/clone-element-with-inlined-styles.ts
19694
- function cloneElementWithInlinedStyles(element, inlinableRules, nonInlinableRules) {
19779
+ function cloneElementWithInlinedStyles(element, inlinableRules, nonInlinableRules, customProperties) {
19695
19780
  const propsToOverwrite = {};
19696
19781
  if (element.props.className && !isComponent(element)) {
19697
19782
  const classes = element.props.className.trim().split(/\s+/);
@@ -19703,7 +19788,7 @@ function cloneElementWithInlinedStyles(element, inlinableRules, nonInlinableRule
19703
19788
  else residualClasses.push(className);
19704
19789
  }
19705
19790
  propsToOverwrite.style = {
19706
- ...makeInlineStylesFor(rules),
19791
+ ...makeInlineStylesFor(rules, customProperties),
19707
19792
  ...element.props.style
19708
19793
  };
19709
19794
  if (residualClasses.length > 0) propsToOverwrite.className = residualClasses.map((className) => {
@@ -21606,7 +21691,7 @@ const pixelBasedPreset = { theme: { extend: {
21606
21691
  }
21607
21692
  } } };
21608
21693
  function Tailwind({ children, config }) {
21609
- const tailwindSetup = useSuspensedPromise(() => setupTailwind(config ?? {}), JSON.stringify(config));
21694
+ const tailwindSetup = useSuspensedPromise(() => setupTailwind(config ?? {}), JSON.stringify(config, (_key, value) => typeof value === "function" ? value.toString() : value));
21610
21695
  let classesUsed = [];
21611
21696
  let mappedChildren = mapReactTree(children, (node) => {
21612
21697
  if (react.isValidElement(node)) {
@@ -21619,20 +21704,19 @@ function Tailwind({ children, config }) {
21619
21704
  return node;
21620
21705
  });
21621
21706
  const styleSheet = tailwindSetup.getStyleSheet();
21622
- resolveAllCssVariables(styleSheet);
21623
- resolveCalcExpressions(styleSheet);
21624
- sanitizeDeclarations(styleSheet);
21707
+ sanitizeStyleSheet(styleSheet);
21625
21708
  const { inlinable: inlinableRules, nonInlinable: nonInlinableRules } = extractRulesPerClass(styleSheet, classesUsed);
21626
- sanitizeNonInlinableRules(styleSheet);
21709
+ const customProperties = getCustomProperties(styleSheet);
21627
21710
  const nonInlineStyles = {
21628
21711
  type: "StyleSheet",
21629
- children: new List().fromArray(nonInlinableRules.values().toArray())
21712
+ children: new List().fromArray(Array.from(nonInlinableRules.values()))
21630
21713
  };
21714
+ sanitizeNonInlinableRules(nonInlineStyles);
21631
21715
  const hasNonInlineStylesToApply = nonInlinableRules.size > 0;
21632
21716
  let appliedNonInlineStyles = false;
21633
21717
  mappedChildren = mapReactTree(mappedChildren, (node) => {
21634
21718
  if (react.isValidElement(node)) {
21635
- const elementWithInlinedStyles = cloneElementWithInlinedStyles(node, inlinableRules, nonInlinableRules);
21719
+ const elementWithInlinedStyles = cloneElementWithInlinedStyles(node, inlinableRules, nonInlinableRules, customProperties);
21636
21720
  if (elementWithInlinedStyles.type === "head") {
21637
21721
  appliedNonInlineStyles = true;
21638
21722
  const styleElement = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: generate(nonInlineStyles) });
@@ -21642,7 +21726,7 @@ function Tailwind({ children, config }) {
21642
21726
  }
21643
21727
  return node;
21644
21728
  });
21645
- if (hasNonInlineStylesToApply && !appliedNonInlineStyles) throw new Error(`You are trying to use the following Tailwind classes that cannot be inlined: ${nonInlinableRules.keys().toArray().join(" ")}.
21729
+ if (hasNonInlineStylesToApply && !appliedNonInlineStyles) throw new Error(`You are trying to use the following Tailwind classes that cannot be inlined: ${Array.from(nonInlinableRules.keys()).join(" ")}.
21646
21730
  For the media queries to work properly on rendering, they need to be added into a <style> tag inside of a <head> tag,
21647
21731
  the Tailwind component tried finding a <head> element but just wasn't able to find it.
21648
21732
 
@@ -21656,4 +21740,7 @@ please file a bug https://github.com/resend/react-email/issues/new?assignees=&la
21656
21740
 
21657
21741
  //#endregion
21658
21742
  exports.Tailwind = Tailwind;
21659
- exports.pixelBasedPreset = pixelBasedPreset;
21743
+ exports.inlineStyles = inlineStyles;
21744
+ exports.pixelBasedPreset = pixelBasedPreset;
21745
+ exports.sanitizeStyleSheet = sanitizeStyleSheet;
21746
+ exports.setupTailwind = setupTailwind;