@gravito/signal 3.0.3 → 3.0.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +89 -60
  3. package/README.zh-TW.md +140 -9
  4. package/dist/MjmlRenderer-IUH663FT.mjs +8 -0
  5. package/dist/ReactMjmlRenderer-C3P5YO5L.mjs +8 -0
  6. package/dist/ReactRenderer-2JFLRVST.mjs +45 -0
  7. package/dist/{ReactRenderer-L5INVYKT.mjs → ReactRenderer-LYEOSYFS.mjs} +9 -8
  8. package/dist/ReactRenderer-V54CUUEI.mjs +45 -0
  9. package/dist/VueMjmlRenderer-4F4CXHDB.mjs +8 -0
  10. package/dist/VueMjmlRenderer-5WZR4CQG.mjs +8 -0
  11. package/dist/VueMjmlRenderer-U5YMWI44.mjs +8 -0
  12. package/dist/VueRenderer-3YBRQXME.mjs +48 -0
  13. package/dist/VueRenderer-46JGXTJ2.mjs +48 -0
  14. package/dist/VueRenderer-5KWD4R3C.mjs +48 -0
  15. package/dist/VueRenderer-C23U4O5E.mjs +48 -0
  16. package/dist/VueRenderer-LEVDFLHP.mjs +31 -0
  17. package/dist/VueRenderer-RNHSCCRI.mjs +48 -0
  18. package/dist/chunk-3WOR3XSL.mjs +82 -0
  19. package/dist/chunk-DBFIVHHG.mjs +79 -0
  20. package/dist/{chunk-6DZX6EAA.mjs → chunk-HEBXNMVQ.mjs} +12 -1
  21. package/dist/chunk-KB7IDDBT.mjs +82 -0
  22. package/dist/chunk-LZL5UUPC.mjs +82 -0
  23. package/dist/chunk-W6LXIJKK.mjs +57 -0
  24. package/dist/chunk-XBIVBJS2.mjs +8 -0
  25. package/dist/index.d.mts +1680 -209
  26. package/dist/index.d.ts +1680 -209
  27. package/dist/index.js +69405 -542
  28. package/dist/index.mjs +993 -110
  29. package/dist/lib-HJTRWKU5.mjs +67788 -0
  30. package/dist/{VueRenderer-Z5PRVBNH.mjs → server-renderer-4IM3P5XZ.mjs} +308 -423
  31. package/dist/server-renderer-7KWFSTPV.mjs +37193 -0
  32. package/dist/{VueRenderer-S65ZARRI.mjs → server-renderer-S5FPSTJ2.mjs} +931 -877
  33. package/dist/server-renderer-X5LUFVWT.mjs +37193 -0
  34. package/doc/OPTIMIZATION_PLAN.md +496 -0
  35. package/package.json +14 -12
  36. package/scripts/check-coverage.ts +64 -0
  37. package/src/Mailable.ts +340 -44
  38. package/src/OrbitSignal.ts +350 -50
  39. package/src/TypedMailable.ts +96 -0
  40. package/src/dev/DevMailbox.ts +89 -33
  41. package/src/dev/DevServer.ts +14 -14
  42. package/src/dev/storage/FileMailboxStorage.ts +66 -0
  43. package/src/dev/storage/MailboxStorage.ts +15 -0
  44. package/src/dev/storage/MemoryMailboxStorage.ts +36 -0
  45. package/src/dev/ui/mailbox.ts +1 -1
  46. package/src/dev/ui/preview.ts +4 -4
  47. package/src/errors.ts +69 -0
  48. package/src/events.ts +72 -0
  49. package/src/index.ts +20 -1
  50. package/src/renderers/HtmlRenderer.ts +20 -18
  51. package/src/renderers/MjmlRenderer.ts +73 -0
  52. package/src/renderers/ReactMjmlRenderer.ts +94 -0
  53. package/src/renderers/ReactRenderer.ts +26 -21
  54. package/src/renderers/Renderer.ts +43 -3
  55. package/src/renderers/TemplateRenderer.ts +48 -15
  56. package/src/renderers/VueMjmlRenderer.ts +99 -0
  57. package/src/renderers/VueRenderer.ts +26 -21
  58. package/src/renderers/mjml-templates.ts +50 -0
  59. package/src/transports/BaseTransport.ts +148 -0
  60. package/src/transports/LogTransport.ts +28 -6
  61. package/src/transports/MemoryTransport.ts +34 -6
  62. package/src/transports/SesTransport.ts +62 -17
  63. package/src/transports/SmtpTransport.ts +123 -27
  64. package/src/transports/Transport.ts +33 -4
  65. package/src/types.ts +172 -3
  66. package/src/utils/html.ts +43 -0
  67. package/src/webhooks/SendGridWebhookDriver.ts +80 -0
  68. package/src/webhooks/SesWebhookDriver.ts +44 -0
  69. package/tests/DevMailbox.test.ts +54 -0
  70. package/tests/FileMailboxStorage.test.ts +56 -0
  71. package/tests/MjmlLayout.test.ts +28 -0
  72. package/tests/MjmlRenderer.test.ts +53 -0
  73. package/tests/OrbitSignalWebhook.test.ts +56 -0
  74. package/tests/ReactMjmlRenderer.test.ts +33 -0
  75. package/tests/SendGridWebhookDriver.test.ts +69 -0
  76. package/tests/SesWebhookDriver.test.ts +46 -0
  77. package/tests/VueMjmlRenderer.test.ts +35 -0
  78. package/tests/dev-server.test.ts +1 -1
  79. package/tests/transports.test.ts +3 -3
  80. package/tsconfig.json +12 -24
  81. package/dist/OrbitMail-2Z7ZTKYA.mjs +0 -7
  82. package/dist/OrbitMail-BGV32HWN.mjs +0 -7
  83. package/dist/OrbitMail-FUYZQSAV.mjs +0 -7
  84. package/dist/OrbitMail-NAPCRK7B.mjs +0 -7
  85. package/dist/OrbitMail-REGJ276B.mjs +0 -7
  86. package/dist/OrbitMail-TCFBJWDT.mjs +0 -7
  87. package/dist/OrbitMail-XZZW6U4N.mjs +0 -7
  88. package/dist/OrbitSignal-IPSA2CDO.mjs +0 -7
  89. package/dist/OrbitSignal-MABW4DDW.mjs +0 -7
  90. package/dist/OrbitSignal-QSW5VQ5M.mjs +0 -7
  91. package/dist/OrbitSignal-R22QHWAA.mjs +0 -7
  92. package/dist/OrbitSignal-ZKKMEC27.mjs +0 -7
  93. package/dist/chunk-3U2CYJO5.mjs +0 -367
  94. package/dist/chunk-3XFC4T6M.mjs +0 -392
  95. package/dist/chunk-456QRYFW.mjs +0 -401
  96. package/dist/chunk-DT3R2TNV.mjs +0 -367
  97. package/dist/chunk-F6MVTUCT.mjs +0 -421
  98. package/dist/chunk-GADWIVC4.mjs +0 -400
  99. package/dist/chunk-HHKFAMSE.mjs +0 -380
  100. package/dist/chunk-NEQCQSZI.mjs +0 -406
  101. package/dist/chunk-OKRNL6PN.mjs +0 -400
  102. package/dist/chunk-ULN3GMY2.mjs +0 -367
  103. package/dist/chunk-XAWO7RSP.mjs +0 -398
  104. package/dist/chunk-YLVDJSED.mjs +0 -431
@@ -0,0 +1,48 @@
1
+ import {
2
+ stripHtml
3
+ } from "./chunk-XBIVBJS2.mjs";
4
+ import "./chunk-EBO3CZXG.mjs";
5
+
6
+ // src/renderers/VueRenderer.ts
7
+ var VueRenderer = class {
8
+ /**
9
+ * Creates an instance of VueRenderer.
10
+ *
11
+ * @param component - The Vue component to render.
12
+ * @param props - Initial props for the component.
13
+ * @param deps - Optional dependency injection for testing.
14
+ */
15
+ constructor(component, props, deps = {}) {
16
+ this.component = component;
17
+ this.props = props;
18
+ this.deps = deps;
19
+ }
20
+ /**
21
+ * Renders the Vue component to a static HTML string.
22
+ *
23
+ * This method performs dynamic imports of `vue` and `@vue/server-renderer`
24
+ * to ensure they are only loaded if this renderer is actually used.
25
+ *
26
+ * @param data - Runtime data to be merged with initial props.
27
+ * @returns A promise resolving to the rendered content.
28
+ * @throws {Error} If Vue dependencies cannot be loaded or rendering fails.
29
+ */
30
+ async render(data) {
31
+ const createSSRApp = this.deps.createSSRApp ?? (await import("vue")).createSSRApp;
32
+ const h = this.deps.h ?? (await import("vue")).h;
33
+ const renderToString = this.deps.renderToString ?? (await import("./server-renderer-4W4FI7YG.mjs")).renderToString;
34
+ const mergedProps = { ...this.props, ...data };
35
+ const app = createSSRApp({
36
+ render: () => h(this.component, mergedProps)
37
+ });
38
+ const html = await renderToString(app);
39
+ const fullHtml = html.startsWith("<!DOCTYPE") ? html : `<!DOCTYPE html>${html}`;
40
+ return {
41
+ html: fullHtml,
42
+ text: stripHtml(html)
43
+ };
44
+ }
45
+ };
46
+ export {
47
+ VueRenderer
48
+ };
@@ -0,0 +1,48 @@
1
+ import {
2
+ stripHtml
3
+ } from "./chunk-XBIVBJS2.mjs";
4
+ import "./chunk-HEBXNMVQ.mjs";
5
+
6
+ // src/renderers/VueRenderer.ts
7
+ var VueRenderer = class {
8
+ /**
9
+ * Creates an instance of VueRenderer.
10
+ *
11
+ * @param component - The Vue component to render.
12
+ * @param props - Initial props for the component.
13
+ * @param deps - Optional dependency injection for testing.
14
+ */
15
+ constructor(component, props, deps = {}) {
16
+ this.component = component;
17
+ this.props = props;
18
+ this.deps = deps;
19
+ }
20
+ /**
21
+ * Renders the Vue component to a static HTML string.
22
+ *
23
+ * This method performs dynamic imports of `vue` and `@vue/server-renderer`
24
+ * to ensure they are only loaded if this renderer is actually used.
25
+ *
26
+ * @param data - Runtime data to be merged with initial props.
27
+ * @returns A promise resolving to the rendered content.
28
+ * @throws {Error} If Vue dependencies cannot be loaded or rendering fails.
29
+ */
30
+ async render(data) {
31
+ const createSSRApp = this.deps.createSSRApp ?? (await import("vue")).createSSRApp;
32
+ const h = this.deps.h ?? (await import("vue")).h;
33
+ const renderToString = this.deps.renderToString ?? (await import("./server-renderer-X5LUFVWT.mjs")).renderToString;
34
+ const mergedProps = { ...this.props, ...data };
35
+ const app = createSSRApp({
36
+ render: () => h(this.component, mergedProps)
37
+ });
38
+ const html = await renderToString(app);
39
+ const fullHtml = html.startsWith("<!DOCTYPE") ? html : `<!DOCTYPE html>${html}`;
40
+ return {
41
+ html: fullHtml,
42
+ text: stripHtml(html)
43
+ };
44
+ }
45
+ };
46
+ export {
47
+ VueRenderer
48
+ };
@@ -0,0 +1,31 @@
1
+ import {
2
+ stripHtml
3
+ } from "./chunk-XBIVBJS2.mjs";
4
+ import "./chunk-EBO3CZXG.mjs";
5
+
6
+ // src/renderers/VueRenderer.ts
7
+ var VueRenderer = class {
8
+ constructor(component, props, deps = {}) {
9
+ this.component = component;
10
+ this.props = props;
11
+ this.deps = deps;
12
+ }
13
+ async render(data) {
14
+ const createSSRApp = this.deps.createSSRApp ?? (await import("vue")).createSSRApp;
15
+ const h = this.deps.h ?? (await import("vue")).h;
16
+ const renderToString = this.deps.renderToString ?? (await import("./server-renderer-4W4FI7YG.mjs")).renderToString;
17
+ const mergedProps = { ...this.props, ...data };
18
+ const app = createSSRApp({
19
+ render: () => h(this.component, mergedProps)
20
+ });
21
+ const html = await renderToString(app);
22
+ const fullHtml = html.startsWith("<!DOCTYPE") ? html : `<!DOCTYPE html>${html}`;
23
+ return {
24
+ html: fullHtml,
25
+ text: stripHtml(html)
26
+ };
27
+ }
28
+ };
29
+ export {
30
+ VueRenderer
31
+ };
@@ -0,0 +1,48 @@
1
+ import {
2
+ stripHtml
3
+ } from "./chunk-XBIVBJS2.mjs";
4
+ import "./chunk-HEBXNMVQ.mjs";
5
+
6
+ // src/renderers/VueRenderer.ts
7
+ var VueRenderer = class {
8
+ /**
9
+ * Creates an instance of VueRenderer.
10
+ *
11
+ * @param component - The Vue component to render.
12
+ * @param props - Initial props for the component.
13
+ * @param deps - Optional dependency injection for testing.
14
+ */
15
+ constructor(component, props, deps = {}) {
16
+ this.component = component;
17
+ this.props = props;
18
+ this.deps = deps;
19
+ }
20
+ /**
21
+ * Renders the Vue component to a static HTML string.
22
+ *
23
+ * This method performs dynamic imports of `vue` and `@vue/server-renderer`
24
+ * to ensure they are only loaded if this renderer is actually used.
25
+ *
26
+ * @param data - Runtime data to be merged with initial props.
27
+ * @returns A promise resolving to the rendered content.
28
+ * @throws {Error} If Vue dependencies cannot be loaded or rendering fails.
29
+ */
30
+ async render(data) {
31
+ const createSSRApp = this.deps.createSSRApp ?? (await import("vue")).createSSRApp;
32
+ const h = this.deps.h ?? (await import("vue")).h;
33
+ const renderToString = this.deps.renderToString ?? (await import("./server-renderer-4IM3P5XZ.mjs")).renderToString;
34
+ const mergedProps = { ...this.props, ...data };
35
+ const app = createSSRApp({
36
+ render: () => h(this.component, mergedProps)
37
+ });
38
+ const html = await renderToString(app);
39
+ const fullHtml = html.startsWith("<!DOCTYPE") ? html : `<!DOCTYPE html>${html}`;
40
+ return {
41
+ html: fullHtml,
42
+ text: stripHtml(html)
43
+ };
44
+ }
45
+ };
46
+ export {
47
+ VueRenderer
48
+ };
@@ -0,0 +1,82 @@
1
+ import {
2
+ stripHtml
3
+ } from "./chunk-XBIVBJS2.mjs";
4
+
5
+ // src/renderers/VueMjmlRenderer.ts
6
+ var VueMjmlRenderer = class {
7
+ /**
8
+ * Creates an instance of VueMjmlRenderer.
9
+ *
10
+ * @param component - The Vue component to render.
11
+ * @param props - Initial props for the component.
12
+ * @param options - Optional MJML transformation options.
13
+ * @param deps - Optional dependency injection for testing.
14
+ */
15
+ constructor(component, props, options = {}, deps = {}) {
16
+ this.component = component;
17
+ this.props = props;
18
+ this.options = options;
19
+ this.deps = deps;
20
+ }
21
+ /**
22
+ * Renders the Vue component to a static HTML string via MJML.
23
+ *
24
+ * @param data - Runtime data to be merged with initial props.
25
+ * @returns A promise resolving to the rendered content.
26
+ * @throws {Error} If MJML rendering fails.
27
+ */
28
+ async render(data) {
29
+ let { createSSRApp, h, renderToString, mjml2html } = this.deps;
30
+ if (!createSSRApp || !h || !renderToString) {
31
+ try {
32
+ const vue = await import("vue");
33
+ const vueServerRenderer = await import("./server-renderer-4IM3P5XZ.mjs");
34
+ createSSRApp ??= vue.createSSRApp;
35
+ h ??= vue.h;
36
+ renderToString ??= vueServerRenderer.renderToString;
37
+ } catch (_e) {
38
+ throw new Error(
39
+ '[OrbitSignal] The "vue" and "@vue/server-renderer" packages are required for VueMjmlRenderer. Please install them using "bun add vue @vue/server-renderer".'
40
+ );
41
+ }
42
+ }
43
+ if (!mjml2html) {
44
+ try {
45
+ mjml2html = (await import("./lib-HJTRWKU5.mjs")).default;
46
+ } catch (_e) {
47
+ throw new Error(
48
+ '[OrbitSignal] The "mjml" package is required for VueMjmlRenderer. Please install it using "bun add mjml".'
49
+ );
50
+ }
51
+ }
52
+ const mergedProps = { ...this.props, ...data };
53
+ const app = createSSRApp?.({
54
+ render: () => h?.(this.component, mergedProps)
55
+ });
56
+ const mjml = await renderToString?.(app);
57
+ if (!mjml) {
58
+ throw new Error("Failed to render MJML template");
59
+ }
60
+ const result = mjml2html?.(mjml, {
61
+ validationLevel: "soft",
62
+ ...this.options
63
+ });
64
+ if (!result) {
65
+ throw new Error("Failed to convert MJML to HTML");
66
+ }
67
+ const { html, errors } = result;
68
+ if (errors && errors.length > 0 && this.options.validationLevel === "strict") {
69
+ throw new Error(
70
+ `MJML rendering failed: ${errors.map((e) => e.formattedMessage).join(", ")}`
71
+ );
72
+ }
73
+ return {
74
+ html,
75
+ text: stripHtml(html)
76
+ };
77
+ }
78
+ };
79
+
80
+ export {
81
+ VueMjmlRenderer
82
+ };
@@ -0,0 +1,79 @@
1
+ import {
2
+ stripHtml
3
+ } from "./chunk-XBIVBJS2.mjs";
4
+
5
+ // src/renderers/ReactMjmlRenderer.ts
6
+ var ReactMjmlRenderer = class {
7
+ /**
8
+ * Creates an instance of ReactMjmlRenderer.
9
+ *
10
+ * @param component - The React component to render.
11
+ * @param props - Initial props for the component.
12
+ * @param options - Optional MJML transformation options.
13
+ * @param deps - Optional dependency injection for testing.
14
+ */
15
+ constructor(component, props, options = {}, deps = {}) {
16
+ this.component = component;
17
+ this.props = props;
18
+ this.options = options;
19
+ this.deps = deps;
20
+ }
21
+ /**
22
+ * Renders the React component to a static HTML string via MJML.
23
+ *
24
+ * @param data - Runtime data to be merged with initial props.
25
+ * @returns A promise resolving to the rendered content.
26
+ * @throws {Error} If MJML rendering fails.
27
+ */
28
+ async render(data) {
29
+ let { createElement, renderToStaticMarkup, mjml2html } = this.deps;
30
+ if (!createElement || !renderToStaticMarkup) {
31
+ try {
32
+ const react = await import("react");
33
+ const reactDomServer = await import("react-dom/server");
34
+ createElement ??= react.createElement;
35
+ renderToStaticMarkup ??= reactDomServer.renderToStaticMarkup;
36
+ } catch (_e) {
37
+ throw new Error(
38
+ '[OrbitSignal] The "react" and "react-dom" packages are required for ReactMjmlRenderer. Please install them using "bun add react react-dom".'
39
+ );
40
+ }
41
+ }
42
+ if (!mjml2html) {
43
+ try {
44
+ mjml2html = (await import("./lib-HJTRWKU5.mjs")).default;
45
+ } catch (_e) {
46
+ throw new Error(
47
+ '[OrbitSignal] The "mjml" package is required for ReactMjmlRenderer. Please install it using "bun add mjml".'
48
+ );
49
+ }
50
+ }
51
+ const mergedProps = { ...this.props, ...data };
52
+ const element = createElement?.(this.component, mergedProps);
53
+ const mjml = renderToStaticMarkup?.(element);
54
+ if (!mjml) {
55
+ throw new Error("Failed to render MJML template");
56
+ }
57
+ const result = mjml2html?.(mjml, {
58
+ validationLevel: "soft",
59
+ ...this.options
60
+ });
61
+ if (!result) {
62
+ throw new Error("Failed to convert MJML to HTML");
63
+ }
64
+ const { html, errors } = result;
65
+ if (errors && errors.length > 0 && this.options.validationLevel === "strict") {
66
+ throw new Error(
67
+ `MJML rendering failed: ${errors.map((e) => e.formattedMessage).join(", ")}`
68
+ );
69
+ }
70
+ return {
71
+ html,
72
+ text: stripHtml(html)
73
+ };
74
+ }
75
+ };
76
+
77
+ export {
78
+ ReactMjmlRenderer
79
+ };
@@ -10,9 +10,16 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
10
10
  if (typeof require !== "undefined") return require.apply(this, arguments);
11
11
  throw Error('Dynamic require of "' + x + '" is not supported');
12
12
  });
13
+ var __esm = (fn, res) => function __init() {
14
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
15
+ };
13
16
  var __commonJS = (cb, mod) => function __require2() {
14
17
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
18
  };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, { get: all[name], enumerable: true });
22
+ };
16
23
  var __copyProps = (to, from, except, desc) => {
17
24
  if (from && typeof from === "object" || typeof from === "function") {
18
25
  for (let key of __getOwnPropNames(from))
@@ -29,9 +36,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
36
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
37
  mod
31
38
  ));
39
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
40
 
33
41
  export {
34
42
  __require,
43
+ __esm,
35
44
  __commonJS,
36
- __toESM
45
+ __export,
46
+ __toESM,
47
+ __toCommonJS
37
48
  };
@@ -0,0 +1,82 @@
1
+ import {
2
+ stripHtml
3
+ } from "./chunk-XBIVBJS2.mjs";
4
+
5
+ // src/renderers/VueMjmlRenderer.ts
6
+ var VueMjmlRenderer = class {
7
+ /**
8
+ * Creates an instance of VueMjmlRenderer.
9
+ *
10
+ * @param component - The Vue component to render.
11
+ * @param props - Initial props for the component.
12
+ * @param options - Optional MJML transformation options.
13
+ * @param deps - Optional dependency injection for testing.
14
+ */
15
+ constructor(component, props, options = {}, deps = {}) {
16
+ this.component = component;
17
+ this.props = props;
18
+ this.options = options;
19
+ this.deps = deps;
20
+ }
21
+ /**
22
+ * Renders the Vue component to a static HTML string via MJML.
23
+ *
24
+ * @param data - Runtime data to be merged with initial props.
25
+ * @returns A promise resolving to the rendered content.
26
+ * @throws {Error} If MJML rendering fails.
27
+ */
28
+ async render(data) {
29
+ let { createSSRApp, h, renderToString, mjml2html } = this.deps;
30
+ if (!createSSRApp || !h || !renderToString) {
31
+ try {
32
+ const vue = await import("vue");
33
+ const vueServerRenderer = await import("./server-renderer-7KWFSTPV.mjs");
34
+ createSSRApp ??= vue.createSSRApp;
35
+ h ??= vue.h;
36
+ renderToString ??= vueServerRenderer.renderToString;
37
+ } catch (_e) {
38
+ throw new Error(
39
+ '[OrbitSignal] The "vue" and "@vue/server-renderer" packages are required for VueMjmlRenderer. Please install them using "bun add vue @vue/server-renderer".'
40
+ );
41
+ }
42
+ }
43
+ if (!mjml2html) {
44
+ try {
45
+ mjml2html = (await import("./lib-HJTRWKU5.mjs")).default;
46
+ } catch (_e) {
47
+ throw new Error(
48
+ '[OrbitSignal] The "mjml" package is required for VueMjmlRenderer. Please install it using "bun add mjml".'
49
+ );
50
+ }
51
+ }
52
+ const mergedProps = { ...this.props, ...data };
53
+ const app = createSSRApp?.({
54
+ render: () => h?.(this.component, mergedProps)
55
+ });
56
+ const mjml = await renderToString?.(app);
57
+ if (!mjml) {
58
+ throw new Error("Failed to render MJML template");
59
+ }
60
+ const result = mjml2html?.(mjml, {
61
+ validationLevel: "soft",
62
+ ...this.options
63
+ });
64
+ if (!result) {
65
+ throw new Error("Failed to convert MJML to HTML");
66
+ }
67
+ const { html, errors } = result;
68
+ if (errors && errors.length > 0 && this.options.validationLevel === "strict") {
69
+ throw new Error(
70
+ `MJML rendering failed: ${errors.map((e) => e.formattedMessage).join(", ")}`
71
+ );
72
+ }
73
+ return {
74
+ html,
75
+ text: stripHtml(html)
76
+ };
77
+ }
78
+ };
79
+
80
+ export {
81
+ VueMjmlRenderer
82
+ };
@@ -0,0 +1,82 @@
1
+ import {
2
+ stripHtml
3
+ } from "./chunk-XBIVBJS2.mjs";
4
+
5
+ // src/renderers/VueMjmlRenderer.ts
6
+ var VueMjmlRenderer = class {
7
+ /**
8
+ * Creates an instance of VueMjmlRenderer.
9
+ *
10
+ * @param component - The Vue component to render.
11
+ * @param props - Initial props for the component.
12
+ * @param options - Optional MJML transformation options.
13
+ * @param deps - Optional dependency injection for testing.
14
+ */
15
+ constructor(component, props, options = {}, deps = {}) {
16
+ this.component = component;
17
+ this.props = props;
18
+ this.options = options;
19
+ this.deps = deps;
20
+ }
21
+ /**
22
+ * Renders the Vue component to a static HTML string via MJML.
23
+ *
24
+ * @param data - Runtime data to be merged with initial props.
25
+ * @returns A promise resolving to the rendered content.
26
+ * @throws {Error} If MJML rendering fails.
27
+ */
28
+ async render(data) {
29
+ let { createSSRApp, h, renderToString, mjml2html } = this.deps;
30
+ if (!createSSRApp || !h || !renderToString) {
31
+ try {
32
+ const vue = await import("vue");
33
+ const vueServerRenderer = await import("./server-renderer-X5LUFVWT.mjs");
34
+ createSSRApp ??= vue.createSSRApp;
35
+ h ??= vue.h;
36
+ renderToString ??= vueServerRenderer.renderToString;
37
+ } catch (_e) {
38
+ throw new Error(
39
+ '[OrbitSignal] The "vue" and "@vue/server-renderer" packages are required for VueMjmlRenderer. Please install them using "bun add vue @vue/server-renderer".'
40
+ );
41
+ }
42
+ }
43
+ if (!mjml2html) {
44
+ try {
45
+ mjml2html = (await import("./lib-HJTRWKU5.mjs")).default;
46
+ } catch (_e) {
47
+ throw new Error(
48
+ '[OrbitSignal] The "mjml" package is required for VueMjmlRenderer. Please install it using "bun add mjml".'
49
+ );
50
+ }
51
+ }
52
+ const mergedProps = { ...this.props, ...data };
53
+ const app = createSSRApp?.({
54
+ render: () => h?.(this.component, mergedProps)
55
+ });
56
+ const mjml = await renderToString?.(app);
57
+ if (!mjml) {
58
+ throw new Error("Failed to render MJML template");
59
+ }
60
+ const result = mjml2html?.(mjml, {
61
+ validationLevel: "soft",
62
+ ...this.options
63
+ });
64
+ if (!result) {
65
+ throw new Error("Failed to convert MJML to HTML");
66
+ }
67
+ const { html, errors } = result;
68
+ if (errors && errors.length > 0 && this.options.validationLevel === "strict") {
69
+ throw new Error(
70
+ `MJML rendering failed: ${errors.map((e) => e.formattedMessage).join(", ")}`
71
+ );
72
+ }
73
+ return {
74
+ html,
75
+ text: stripHtml(html)
76
+ };
77
+ }
78
+ };
79
+
80
+ export {
81
+ VueMjmlRenderer
82
+ };
@@ -0,0 +1,57 @@
1
+ import {
2
+ stripHtml
3
+ } from "./chunk-XBIVBJS2.mjs";
4
+
5
+ // src/renderers/MjmlRenderer.ts
6
+ var MjmlRenderer = class {
7
+ /**
8
+ * Creates an instance of MjmlRenderer.
9
+ *
10
+ * @param content - The MJML markup string to be rendered.
11
+ * @param options - Optional MJML transformation options.
12
+ * @param deps - Optional dependency injection for testing.
13
+ */
14
+ constructor(content, options = {}, deps = {}) {
15
+ this.content = content;
16
+ this.options = options;
17
+ this.deps = deps;
18
+ }
19
+ /**
20
+ * Renders the MJML content to static HTML.
21
+ *
22
+ * This method performs a dynamic import of `mjml` to ensure it's only
23
+ * loaded if this renderer is actually used.
24
+ *
25
+ * @returns A promise resolving to the rendered content.
26
+ * @throws {Error} If MJML dependencies cannot be loaded or rendering fails.
27
+ */
28
+ async render() {
29
+ let mjml2html = this.deps.mjml2html;
30
+ if (!mjml2html) {
31
+ try {
32
+ mjml2html = (await import("./lib-HJTRWKU5.mjs")).default;
33
+ } catch (_e) {
34
+ throw new Error(
35
+ '[OrbitSignal] The "mjml" package is required for MjmlRenderer. Please install it using "bun add mjml".'
36
+ );
37
+ }
38
+ }
39
+ const { html, errors } = mjml2html(this.content, {
40
+ validationLevel: "soft",
41
+ ...this.options
42
+ });
43
+ if (errors && errors.length > 0 && this.options.validationLevel === "strict") {
44
+ throw new Error(
45
+ `MJML rendering failed: ${errors.map((e) => e.formattedMessage).join(", ")}`
46
+ );
47
+ }
48
+ return {
49
+ html,
50
+ text: stripHtml(html)
51
+ };
52
+ }
53
+ };
54
+
55
+ export {
56
+ MjmlRenderer
57
+ };
@@ -0,0 +1,8 @@
1
+ // src/utils/html.ts
2
+ function stripHtml(html) {
3
+ return html.replace(/<style(?:\s[^>]*)?>[\s\S]*?<\/style>/gi, "").replace(/<script(?:\s[^>]*)?>[\s\S]*?<\/script>/gi, "").replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/\s+/g, " ").trim();
4
+ }
5
+
6
+ export {
7
+ stripHtml
8
+ };