@templatical/import-chamaileon 0.36.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 +21 -0
- package/README.md +38 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +1072 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
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,38 @@
|
|
|
1
|
+
# @templatical/import-chamaileon
|
|
2
|
+
|
|
3
|
+
Convert Chamaileon email templates to Templatical format.
|
|
4
|
+
|
|
5
|
+
Reads a Chamaileon persist document — the JSON `editorInstance.methods.getDocument()` returns — into a Templatical `TemplateContent` tree. Email JSON 2.0 through 4.1 is accepted after a key normalizer (kebab-case and camelCase styles, `{ reference, default }` colour variables). The input is that document, not `getEmailHtml()` / the HTML generator.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @templatical/import-chamaileon
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { convertChamaileonTemplate } from "@templatical/import-chamaileon";
|
|
17
|
+
|
|
18
|
+
const document = await editorInstance.methods.getDocument();
|
|
19
|
+
const { content, report } = convertChamaileonTemplate(document);
|
|
20
|
+
|
|
21
|
+
console.log(report.summary);
|
|
22
|
+
console.log(report.warnings);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`convertChamaileonTemplate` also accepts the document serialized as a JSON string.
|
|
26
|
+
|
|
27
|
+
Each entry in `report.entries` carries a `status`:
|
|
28
|
+
|
|
29
|
+
- `converted` — mapped to a Templatical block with no loss of fidelity.
|
|
30
|
+
- `approximated` — mapped to a Templatical block, but something had to be resolved or clamped (e.g. a nested multicolumn flattened, a 4+ column row folded to three, an outlined button, a loop whose children converted without their expression).
|
|
31
|
+
- `html-fallback` — no Templatical block exists for this `type`; the raw node is preserved as JSON inside an `HtmlBlock`.
|
|
32
|
+
- `skipped` — an empty loop or conditional; there were no children to convert.
|
|
33
|
+
|
|
34
|
+
See [Migrating from Chamaileon](https://docs.templatical.com/guide/migration-from-chamaileon) for the full node-mapping table and what does not survive the conversion.
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Type definitions for the Chamaileon importer.
|
|
4
|
+
*
|
|
5
|
+
* The four report types are structurally identical to every other
|
|
6
|
+
* `@templatical/import-*` package's, so a caller can treat all importers
|
|
7
|
+
* uniformly. Changing a shape here without changing the others breaks that.
|
|
8
|
+
*
|
|
9
|
+
* The node type is loose on purpose. Email JSON 2.0.0 and 4.1.0 disagree on
|
|
10
|
+
* key names; a strict 4.1 interface would reject every 2.0 document. Mappers
|
|
11
|
+
* read through the helpers in `normalize.ts` / `attribute-parser.ts`.
|
|
12
|
+
*/
|
|
13
|
+
type ConversionStatus = "converted" | "approximated" | "html-fallback" | "skipped";
|
|
14
|
+
interface ImportReportEntry {
|
|
15
|
+
/** The source Chamaileon `type` string (e.g. "fullwidth", "button", "typed-text"). */
|
|
16
|
+
sourceTag: string;
|
|
17
|
+
/** The Templatical block type produced, or null if skipped. */
|
|
18
|
+
templaticalBlockType: string | null;
|
|
19
|
+
status: ConversionStatus;
|
|
20
|
+
note?: string;
|
|
21
|
+
}
|
|
22
|
+
interface ImportReport {
|
|
23
|
+
entries: ImportReportEntry[];
|
|
24
|
+
warnings: string[];
|
|
25
|
+
summary: {
|
|
26
|
+
total: number;
|
|
27
|
+
converted: number;
|
|
28
|
+
approximated: number;
|
|
29
|
+
htmlFallback: number;
|
|
30
|
+
skipped: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
interface ImportResult {
|
|
34
|
+
content: import("@templatical/types").TemplateContent;
|
|
35
|
+
report: ImportReport;
|
|
36
|
+
}
|
|
37
|
+
/** Document-level design token (`variables[]` in 4.x). */
|
|
38
|
+
interface ChamaileonVariable {
|
|
39
|
+
name?: string;
|
|
40
|
+
value?: unknown;
|
|
41
|
+
type?: string;
|
|
42
|
+
reference?: string;
|
|
43
|
+
default?: unknown;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One node of a Chamaileon document tree.
|
|
47
|
+
*
|
|
48
|
+
* `type` discriminates. `style` keys are kebab-case in 2.0 and camelCase in
|
|
49
|
+
* 4.x; `attrs` holds content (`text`, `href`, `src`, `lineStyle`).
|
|
50
|
+
*/
|
|
51
|
+
interface ChamaileonNode {
|
|
52
|
+
eid?: string;
|
|
53
|
+
type?: string;
|
|
54
|
+
attrs?: Record<string, unknown>;
|
|
55
|
+
style?: Record<string, unknown>;
|
|
56
|
+
children?: ChamaileonNode[];
|
|
57
|
+
placeholder?: ChamaileonNode[];
|
|
58
|
+
customData?: unknown;
|
|
59
|
+
version?: string;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
}
|
|
62
|
+
/** The `getDocument()` object. */
|
|
63
|
+
interface ChamaileonDocument {
|
|
64
|
+
body?: ChamaileonNode;
|
|
65
|
+
variables?: ChamaileonVariable[];
|
|
66
|
+
components?: unknown[];
|
|
67
|
+
title?: string;
|
|
68
|
+
previewText?: string;
|
|
69
|
+
subjectLine?: string;
|
|
70
|
+
fontFiles?: Record<string, string>;
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/converter.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* Convert a Chamaileon `getDocument()` tree into a Templatical template.
|
|
77
|
+
*
|
|
78
|
+
* The input is the document object itself — `{ body, variables?, … }` —
|
|
79
|
+
* not `getEmailHtml()` markup and not an API envelope. That is documented
|
|
80
|
+
* rather than sniffed: guessing between the persist JSON and compiled HTML
|
|
81
|
+
* would send the HTML through the wrong package.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const document = await editorInstance.methods.getDocument();
|
|
86
|
+
* const { content, report } = convertChamaileonTemplate(document);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function convertChamaileonTemplate(doc: ChamaileonDocument | string): ImportResult;
|
|
90
|
+
//#endregion
|
|
91
|
+
export type { ConversionStatus, ImportReport, ImportReportEntry, ImportResult };
|
|
92
|
+
//# sourceMappingURL=index.d.ts.map
|