@react-email/text
Advanced tools
Comparing version
@@ -69,52 +69,70 @@ "use strict"; | ||
// src/utils/parse-margins.ts | ||
function parseMargin({ | ||
margin, | ||
marginTop, | ||
marginRight, | ||
marginBottom, | ||
marginLeft | ||
}) { | ||
let mt = marginTop; | ||
let mr = marginRight; | ||
let mb = marginBottom; | ||
let ml = marginLeft; | ||
if (typeof margin === "number") { | ||
mt = margin; | ||
mr = margin; | ||
mb = margin; | ||
ml = margin; | ||
} else if (typeof margin === "string") { | ||
const values = margin.split(/\s+/); | ||
switch (values.length) { | ||
case 1: | ||
mt = values[0]; | ||
mr = values[0]; | ||
mb = values[0]; | ||
ml = values[0]; | ||
break; | ||
case 2: | ||
mt = values[0]; | ||
mb = values[0]; | ||
mr = values[1]; | ||
ml = values[1]; | ||
break; | ||
case 3: | ||
mt = values[0]; | ||
mr = values[1]; | ||
mb = values[2]; | ||
ml = values[1]; | ||
break; | ||
case 4: | ||
mt = values[0]; | ||
mr = values[1]; | ||
mb = values[2]; | ||
ml = values[3]; | ||
break; | ||
default: | ||
break; | ||
// src/utils/compute-margins.ts | ||
function parseMarginValue(value) { | ||
if (typeof value === "number") | ||
return { marginTop: 0, marginBottom: 0, marginLeft: 0, marginRight: 0 }; | ||
if (typeof value === "string") { | ||
const values = value.toString().trim().split(/\s+/); | ||
if (values.length === 1) { | ||
return { | ||
marginTop: values[0], | ||
marginBottom: values[0], | ||
marginLeft: values[0], | ||
marginRight: values[0] | ||
}; | ||
} | ||
if (values.length === 2) { | ||
return { | ||
marginTop: values[0], | ||
marginRight: values[1], | ||
marginBottom: values[0], | ||
marginLeft: values[1] | ||
}; | ||
} | ||
if (values.length === 3) { | ||
return { | ||
marginTop: values[0], | ||
marginRight: values[1], | ||
marginBottom: values[2], | ||
marginLeft: values[1] | ||
}; | ||
} | ||
if (values.length === 4) { | ||
return { | ||
marginTop: values[0], | ||
marginRight: values[1], | ||
marginBottom: values[2], | ||
marginLeft: values[3] | ||
}; | ||
} | ||
} | ||
return { mt, mr, mb, ml }; | ||
return { | ||
marginTop: void 0, | ||
marginBottom: void 0, | ||
marginLeft: void 0, | ||
marginRight: void 0 | ||
}; | ||
} | ||
function computeMargins(properties) { | ||
let result = { | ||
marginTop: void 0, | ||
marginRight: void 0, | ||
marginBottom: void 0, | ||
marginLeft: void 0 | ||
}; | ||
for (const [key, value] of Object.entries(properties)) { | ||
if (key === "margin") { | ||
result = parseMarginValue(value); | ||
} else if (key === "marginTop") { | ||
result.marginTop = value; | ||
} else if (key === "marginRight") { | ||
result.marginRight = value; | ||
} else if (key === "marginBottom") { | ||
result.marginBottom = value; | ||
} else if (key === "marginLeft") { | ||
result.marginLeft = value; | ||
} | ||
} | ||
return result; | ||
} | ||
@@ -126,10 +144,10 @@ // src/text.tsx | ||
var _b = _a, { style } = _b, props = __objRest(_b, ["style"]); | ||
var _a2, _b2; | ||
const margins = parseMargin({ | ||
margin: style == null ? void 0 : style.margin, | ||
marginBottom: (_a2 = style == null ? void 0 : style.marginBottom) != null ? _a2 : "16px", | ||
marginTop: (_b2 = style == null ? void 0 : style.marginTop) != null ? _b2 : "16px", | ||
marginLeft: style == null ? void 0 : style.marginLeft, | ||
marginRight: style == null ? void 0 : style.marginRight | ||
}); | ||
const modifiedStyle = __spreadValues({}, style); | ||
if (modifiedStyle.marginBottom === void 0) { | ||
modifiedStyle.marginBottom = "16px"; | ||
} | ||
if (modifiedStyle.marginTop === void 0) { | ||
modifiedStyle.marginTop = "16px"; | ||
} | ||
const margins = computeMargins(modifiedStyle); | ||
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( | ||
@@ -139,11 +157,6 @@ "p", | ||
ref, | ||
style: __spreadProps(__spreadValues({ | ||
style: __spreadValues(__spreadValues({ | ||
fontSize: "14px", | ||
lineHeight: "24px" | ||
}, style), { | ||
marginBottom: margins.mb, | ||
marginTop: margins.mt, | ||
marginLeft: margins.ml, | ||
marginRight: margins.mr | ||
}) | ||
}, style), margins) | ||
}) | ||
@@ -150,0 +163,0 @@ ); |
{ | ||
"name": "@react-email/text", | ||
"version": "0.1.1", | ||
"version": "0.1.2-canary.0", | ||
"description": "A block of text separated by blank spaces", | ||
@@ -41,5 +41,5 @@ "sideEffects": false, | ||
"devDependencies": { | ||
"typescript": "5.1.6", | ||
"tsconfig": "0.0.0", | ||
"@react-email/render": "1.0.5" | ||
"typescript": "5.8.3", | ||
"@react-email/render": "1.1.0-canary.1", | ||
"tsconfig": "0.0.0" | ||
}, | ||
@@ -46,0 +46,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
15041
6.7%297
9.59%