@emailens/cli 0.13.2 → 0.13.4

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.
@@ -0,0 +1,65 @@
1
+ import { createRequire as __cr } from "node:module";
2
+ const require = __cr(import.meta.url);
3
+ import {
4
+ CompileError
5
+ } from "./chunk-TQGPCAMW.js";
6
+
7
+ // node_modules/@emailens/engine/dist/chunk-E4QE4WXE.js
8
+ var MAX_SOURCE_SIZE = 512e3;
9
+ async function compileMjml(source) {
10
+ var _a;
11
+ if (!source || !source.trim()) {
12
+ throw new CompileError("MJML source must not be empty.", "mjml", "validation");
13
+ }
14
+ if (source.length > MAX_SOURCE_SIZE) {
15
+ throw new CompileError(
16
+ `MJML source exceeds ${MAX_SOURCE_SIZE / 1e3}KB limit.`,
17
+ "mjml",
18
+ "validation"
19
+ );
20
+ }
21
+ if (!/<mjml[\s>]/i.test(source)) {
22
+ throw new CompileError(
23
+ "MJML source must contain a root <mjml> element. Example: <mjml><mj-body><mj-section><mj-column><mj-text>Hello</mj-text></mj-column></mj-section></mj-body></mjml>",
24
+ "mjml",
25
+ "validation"
26
+ );
27
+ }
28
+ let mjml2html;
29
+ try {
30
+ const mjmlModule = await import("mjml");
31
+ mjml2html = (_a = mjmlModule.default) != null ? _a : mjmlModule;
32
+ } catch (e) {
33
+ throw new CompileError(
34
+ 'MJML compilation requires "mjml". Install it:\n npm install mjml',
35
+ "mjml",
36
+ "compile"
37
+ );
38
+ }
39
+ try {
40
+ const result = await mjml2html(source, {
41
+ validationLevel: "soft",
42
+ keepComments: false
43
+ });
44
+ if (result.errors && result.errors.length > 0 && !result.html) {
45
+ const errorMessages = result.errors.map((e) => `Line ${e.line}: ${e.message} (${e.tagName})`).join("; ");
46
+ throw new CompileError(
47
+ `MJML compilation errors: ${errorMessages}`,
48
+ "mjml",
49
+ "compile"
50
+ );
51
+ }
52
+ if (!result.html) {
53
+ throw new CompileError("MJML compilation produced empty output.", "mjml", "compile");
54
+ }
55
+ return result.html;
56
+ } catch (err) {
57
+ if (err instanceof CompileError) throw err;
58
+ const message = err instanceof Error ? err.message : "Unknown MJML compilation error";
59
+ throw new CompileError(`MJML compilation failed: ${message}`, "mjml", "compile");
60
+ }
61
+ }
62
+
63
+ export {
64
+ compileMjml
65
+ };