@templatical/import-mjml 0.31.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Templatical
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @templatical/import-mjml
2
+
3
+ Convert MJML email templates to Templatical format.
4
+
5
+ Parses `<mjml>` source — hand-written or exported from another tool — into a Templatical `TemplateContent` tree. Structural tags (`mj-section`, `mj-column`, `mj-wrapper`) become `SectionBlock`s and content tags (`mj-text`, `mj-image`, `mj-button`, etc.) map to their Templatical block equivalents. Tags with no Templatical equivalent are preserved verbatim as `HtmlBlock` fallbacks.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @templatical/import-mjml
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { convertMjmlTemplate } from '@templatical/import-mjml';
17
+
18
+ const mjml = await fetch('/path/to/template.mjml').then((r) => r.text());
19
+ const { content, report } = convertMjmlTemplate(mjml);
20
+
21
+ console.log(report.summary);
22
+ console.log(report.warnings);
23
+ ```
24
+
25
+ Each entry in `report.entries` carries a `status`:
26
+
27
+ - `converted` — mapped to a Templatical block with no loss of fidelity.
28
+ - `approximated` — mapped to a Templatical block, but something had to be resolved or clamped (e.g. a heading level beyond h4, a column-width split with no exact Templatical layout, or a multi-section `mj-wrapper`).
29
+ - `html-fallback` — no Templatical block exists for this tag; the original MJML markup is preserved inside an `HtmlBlock`.
30
+ - `skipped` — produced no block at all (e.g. an `<mj-include>`, which the importer can't resolve without filesystem access).
31
+
32
+ See [Migrating from hand-written MJML](https://docs.templatical.com/guide/migration-from-mjml) for the full tag-mapping table.
33
+
34
+ ## License
35
+
36
+ MIT
@@ -0,0 +1,63 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * Type definitions for the MJML email importer.
4
+ *
5
+ * These four types are structurally identical to the ones every other
6
+ * `@templatical/import-*` package exports, so a caller can treat all importers
7
+ * uniformly. Changing a shape here without changing the others breaks that.
8
+ */
9
+ /**
10
+ * Conversion status for each MJML element processed in the import report.
11
+ */
12
+ type ConversionStatus = "converted" | "approximated" | "html-fallback" | "skipped";
13
+ /**
14
+ * A single entry in the import report.
15
+ */
16
+ interface ImportReportEntry {
17
+ /** The source MJML tag name (e.g. "mj-section", "mj-image", "mj-hero"). */
18
+ sourceTag: string;
19
+ /** The Templatical block type produced, or null if skipped. */
20
+ templaticalBlockType: string | null;
21
+ status: ConversionStatus;
22
+ note?: string;
23
+ }
24
+ /**
25
+ * The full import report returned alongside the converted template.
26
+ */
27
+ interface ImportReport {
28
+ entries: ImportReportEntry[];
29
+ warnings: string[];
30
+ summary: {
31
+ total: number;
32
+ converted: number;
33
+ approximated: number;
34
+ htmlFallback: number;
35
+ skipped: number;
36
+ };
37
+ }
38
+ /**
39
+ * The result of an MJML import operation.
40
+ */
41
+ interface ImportResult {
42
+ content: import("@templatical/types").TemplateContent;
43
+ report: ImportReport;
44
+ }
45
+ //#endregion
46
+ //#region src/converter.d.ts
47
+ /**
48
+ * Convert an MJML document into a Templatical template.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const { content, report } = convertMjmlTemplate(mjmlSource);
53
+ *
54
+ * const editor = init({ container: '#editor', content });
55
+ *
56
+ * console.log(report.summary);
57
+ * console.log(report.warnings);
58
+ * ```
59
+ */
60
+ declare function convertMjmlTemplate(mjml: string): ImportResult;
61
+ //#endregion
62
+ export { type ConversionStatus, type ImportReport, type ImportReportEntry, type ImportResult, convertMjmlTemplate };
63
+ //# sourceMappingURL=index.d.ts.map