@charisol/plexo-sdk 1.0.3 → 1.0.5

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/compiler.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/utilities/compiler';
package/compiler.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/compiler.js';
@@ -0,0 +1 @@
1
+ export * from './dist/utilities/compilerClient';
@@ -0,0 +1 @@
1
+ export * from './dist/compilerClient.js';
@@ -0,0 +1,126 @@
1
+ import React from 'react';
2
+ import { z } from 'zod';
3
+ import type { TemplateJSON } from './utilities/types';
4
+ /**
5
+ * Recursively cleans an object, removing prototype pollution keys
6
+ * and enforcing maximum depth limits.
7
+ */
8
+ export declare function sanitizeObject(obj: any, currentDepth?: number, maxDepth?: number): any;
9
+ /**
10
+ * Safely parses a JSON string, stripping prototype pollution keys,
11
+ * enforcing length bounds, and limiting nested object depth.
12
+ */
13
+ export declare function safeJsonParse(text: string, options?: {
14
+ maxDepth?: number;
15
+ maxBytes?: number;
16
+ }): any;
17
+ export declare const ElementJSONSchema: z.ZodObject<{
18
+ id: z.ZodString;
19
+ type: z.ZodEnum<{
20
+ text: "text";
21
+ button: "button";
22
+ image: "image";
23
+ spacer: "spacer";
24
+ divider: "divider";
25
+ card: "card";
26
+ form_container: "form_container";
27
+ input: "input";
28
+ textarea: "textarea";
29
+ select: "select";
30
+ heading: "heading";
31
+ paragraph: "paragraph";
32
+ carousel: "carousel";
33
+ video: "video";
34
+ social: "social";
35
+ menu: "menu";
36
+ html: "html";
37
+ table: "table";
38
+ timer: "timer";
39
+ icon: "icon";
40
+ }>;
41
+ style: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
42
+ attributes: z.ZodObject<{
43
+ href: z.ZodOptional<z.ZodString>;
44
+ src: z.ZodOptional<z.ZodString>;
45
+ alt: z.ZodOptional<z.ZodString>;
46
+ placeholder: z.ZodOptional<z.ZodString>;
47
+ text: z.ZodOptional<z.ZodString>;
48
+ htmlContent: z.ZodOptional<z.ZodString>;
49
+ autoHeight: z.ZodOptional<z.ZodBoolean>;
50
+ headingType: z.ZodOptional<z.ZodString>;
51
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
52
+ label: z.ZodString;
53
+ value: z.ZodString;
54
+ }, z.core.$strip>>>;
55
+ }, z.core.$catchall<z.ZodAny>>;
56
+ }, z.core.$strip>;
57
+ export declare const ColumnJSONSchema: z.ZodType<any>;
58
+ export declare const RowJSONSchema: z.ZodType<any>;
59
+ export declare const StrataConfigSchema: z.ZodObject<{
60
+ projectId: z.ZodString;
61
+ syncEnabled: z.ZodBoolean;
62
+ }, z.core.$strip>;
63
+ export declare const UploadedImageSchema: z.ZodObject<{
64
+ id: z.ZodString;
65
+ name: z.ZodString;
66
+ src: z.ZodString;
67
+ }, z.core.$strip>;
68
+ export declare const BodyJSONSchema: z.ZodObject<{
69
+ style: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
70
+ rows: z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>;
71
+ strataConfig: z.ZodOptional<z.ZodObject<{
72
+ projectId: z.ZodString;
73
+ syncEnabled: z.ZodBoolean;
74
+ }, z.core.$strip>>;
75
+ uploadedImages: z.ZodOptional<z.ZodArray<z.ZodObject<{
76
+ id: z.ZodString;
77
+ name: z.ZodString;
78
+ src: z.ZodString;
79
+ }, z.core.$strip>>>;
80
+ }, z.core.$strip>;
81
+ export declare const TemplateJSONSchema: z.ZodObject<{
82
+ body: z.ZodObject<{
83
+ style: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
84
+ rows: z.ZodArray<z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>;
85
+ strataConfig: z.ZodOptional<z.ZodObject<{
86
+ projectId: z.ZodString;
87
+ syncEnabled: z.ZodBoolean;
88
+ }, z.core.$strip>>;
89
+ uploadedImages: z.ZodOptional<z.ZodArray<z.ZodObject<{
90
+ id: z.ZodString;
91
+ name: z.ZodString;
92
+ src: z.ZodString;
93
+ }, z.core.$strip>>>;
94
+ }, z.core.$strip>;
95
+ }, z.core.$strip>;
96
+ /**
97
+ * Sanitizes an inline CSS style declaration string to prevent injection
98
+ * (e.g. url(javascript:), expression(), positioning overlays/manipulation)
99
+ */
100
+ export declare function sanitizeStyleString(style: string): string;
101
+ /**
102
+ * Sanitizes a React style object property-by-property
103
+ */
104
+ export declare function sanitizeStyleObject(styleObj: Record<string, any> | undefined): React.CSSProperties;
105
+ /**
106
+ * Purifies raw HTML against XSS/DOM Cloaking with strict tag and attribute whitelists.
107
+ */
108
+ export declare function sanitizeHtml(html: string): string;
109
+ interface SafeHTMLProps {
110
+ html: string;
111
+ className?: string;
112
+ style?: React.CSSProperties;
113
+ tag?: 'div' | 'span' | 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
114
+ }
115
+ /**
116
+ * An isolated safe HTML renderer replacing insecure raw dangerouslySetInnerHTML calls.
117
+ */
118
+ export declare const SafeHTML: React.FC<SafeHTMLProps>;
119
+ export interface PlexoRendererProps {
120
+ template: TemplateJSON | string;
121
+ customCss?: string;
122
+ className?: string;
123
+ style?: React.CSSProperties;
124
+ }
125
+ export declare const PlexoRenderer: React.FC<PlexoRendererProps>;
126
+ export {};
@@ -0,0 +1,286 @@
1
+ //#region src/utilities/compiler.ts
2
+ var e = (e) => e === "twitter" ? "x" : e, t = (t, n = "currentColor") => {
3
+ switch (e(t)) {
4
+ case "facebook": return `<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path fill="${n}" d="M14 8h2V4h-2c-2.2 0-4 1.8-4 4v2H8v4h2v6h4v-6h2.5l.5-4H14V8c0-.55.45-1 1-1Z"/></svg>`;
5
+ case "instagram": return `<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><rect x="4" y="4" width="16" height="16" rx="5" ry="5" fill="none" stroke="${n}" stroke-width="2"/><circle cx="12" cy="12" r="3.5" fill="none" stroke="${n}" stroke-width="2"/><circle cx="17" cy="7" r="1" fill="${n}"/></svg>`;
6
+ case "linkedin": return `<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><circle cx="8" cy="9" r="1.25" fill="${n}"/><path fill="${n}" d="M7 11h2v6H7zM11 11h2v.9c.5-.7 1.34-1.15 2.4-1.15 2 0 3.1 1.25 3.1 3.6V17h-2v-2.2c0-1.3-.45-2.05-1.55-2.05-1.2 0-1.85.8-1.85 2.05V17h-2z"/></svg>`;
7
+ case "x": return `<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path fill="${n}" d="M6 5h3.1l3 4.2L15.7 5H18l-4.8 5.5L18.4 18h-3.1l-3.3-4.7L8 18H5.6l5-5.8z"/></svg>`;
8
+ case "youtube": return `<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><rect x="3" y="6.5" width="18" height="11" rx="3" fill="${n}"/><path fill="#fff" d="m10 9 5 3-5 3z"/></svg>`;
9
+ case "pinterest": return `<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path fill="${n}" d="M12 4a8 8 0 0 0-2.9 15.46c-.04-1.17 0-2.58.3-3.82l1.1-4.6s-.27-.56-.27-1.4c0-1.3.75-2.27 1.68-2.27.8 0 1.18.6 1.18 1.3 0 .8-.5 2-.77 3.12-.22.94.47 1.7 1.4 1.7 1.67 0 2.8-2.15 2.8-4.7 0-1.93-1.3-3.37-3.67-3.37-2.68 0-4.35 2-4.35 4.23 0 .77.23 1.34.6 1.77.17.2.2.29.13.53l-.2.8c-.07.25-.3.34-.56.25-1.55-.63-2.27-2.32-2.27-4.22 0-3.14 2.64-6.9 7.89-6.9 4.21 0 6.98 3.05 6.98 6.32 0 4.32-2.4 7.54-5.93 7.54-1.18 0-2.28-.64-2.65-1.37l-.73 2.78c-.26.95-.77 2.14-1.22 2.96A8 8 0 1 0 12 4Z"/></svg>`;
10
+ case "whatsapp": return `<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path fill="${n}" d="M12 4a8 8 0 0 0-6.9 12.04L4 20l4.11-1.06A8 8 0 1 0 12 4Zm4.55 11.36c-.2.56-1.14 1.04-1.57 1.1-.4.06-.92.09-1.48-.08-.34-.11-.78-.25-1.35-.5-2.37-1.03-3.92-3.45-4.04-3.6-.11-.15-.96-1.27-.96-2.42s.6-1.72.8-1.96c.2-.24.45-.3.6-.3h.43c.14 0 .33-.05.51.38.2.48.7 1.67.75 1.79.06.12.1.26.02.42-.07.15-.11.26-.22.39-.11.13-.23.29-.33.39-.11.11-.22.23-.1.45.11.22.52.86 1.11 1.39.76.68 1.4.89 1.62.99.22.11.35.09.48-.06.13-.15.56-.65.72-.88.15-.22.31-.18.52-.11.22.08 1.36.64 1.6.76.23.11.38.17.44.27.06.1.06.61-.14 1.17Z"/></svg>`;
11
+ case "tiktok": return `<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><path fill="${n}" d="M14.4 4c.24 1.12.9 2.08 1.86 2.67.7.42 1.52.64 2.35.63V10a6.5 6.5 0 0 1-4.2-1.52v5.24A4.72 4.72 0 1 1 9.7 9v2.6a2.12 2.12 0 1 0 2.1 2.12V4z"/></svg>`;
12
+ default: return `<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><circle cx="12" cy="12" r="4" fill="${n}"/></svg>`;
13
+ }
14
+ }, n = (e, t) => {
15
+ let n = null;
16
+ return e.map((e) => {
17
+ let r = e.inheritStylesFromPrevious && n ? {
18
+ ...e,
19
+ fontSize: n.fontSize,
20
+ borderRadius: n.borderRadius,
21
+ borderWidth: n.borderWidth,
22
+ borderColor: n.borderColor,
23
+ labelColor: n.labelColor,
24
+ inputTextColor: n.inputTextColor,
25
+ placeholderColor: n.placeholderColor
26
+ } : e;
27
+ n = r;
28
+ let i = r.required ? "required" : "", a = r.labelColor || "#94a3b8", o = `<label style="display:block;font-size:${r.fontSize || "12px"};color:${a};margin-bottom:4px;">${r.label || r.name || "Field"}${r.required ? " *" : ""}</label>`, s = `${t};${[
29
+ `border-radius: ${r.borderRadius || "12px"}`,
30
+ `border-width: ${r.borderWidth || "1px"}`,
31
+ `border-color: ${r.borderColor || "#cbd5e1"}`,
32
+ `color: ${r.inputTextColor || "#1e293b"}`,
33
+ `font-size: ${r.fontSize || "13px"}`
34
+ ].join(";")}`;
35
+ if (r.kind === "textarea") return `<div style="margin-bottom:12px;">${o}<textarea name="${r.name || ""}" placeholder="${r.placeholder || ""}" ${i} style="width:100%;box-sizing:border-box;min-height:80px;${s}"></textarea></div>`;
36
+ if (r.kind === "select") {
37
+ let e = (r.options || []).map((e) => `<option value="${e.value}">${e.label}</option>`).join("");
38
+ return `<div style="margin-bottom:12px;">${o}<select name="${r.name || ""}" ${i} style="width:100%;box-sizing:border-box;${s}">${e}</select></div>`;
39
+ }
40
+ if (r.kind === "radio" || r.kind === "checkbox") {
41
+ let e = r.kind;
42
+ return `<div style="margin-bottom:12px;">${o}<div>${(r.options || []).map((t) => `<label style="display:inline-flex;align-items:center;gap:8px;margin:0 12px 8px 0;font-size:12px;color:${r.inputTextColor || "#475569"};"><input type="${e}" name="${r.name || ""}" value="${t.value}" ${i} />${t.label}</label>`).join("")}</div></div>`;
43
+ }
44
+ return `<div style="margin-bottom:12px;">${o}<input type="${r.kind === "email" ? "email" : "text"}" name="${r.name || ""}" placeholder="${r.placeholder || ""}" ${i} style="width:100%;box-sizing:border-box;${s}" /></div>`;
45
+ }).join("");
46
+ }, r = (e = {}) => Object.entries(e).filter(([e, t]) => t != null && t !== "").map(([e, t]) => {
47
+ let n = e.replace(/([A-Z])/g, "-$1").toLowerCase(), r = t;
48
+ return typeof t == "number" && [
49
+ "padding",
50
+ "margin",
51
+ "fontSize",
52
+ "borderRadius",
53
+ "borderWidth",
54
+ "width",
55
+ "height"
56
+ ].some((t) => e.toLowerCase().includes(t)) && (r = `${t}px`), `${n}: ${r};`;
57
+ }).join(" "), i = () => ({
58
+ backgroundColor: "#ffffff",
59
+ borderRadius: "20px",
60
+ width: "100%",
61
+ padding: "24px",
62
+ paddingTop: "24px",
63
+ paddingRight: "24px",
64
+ paddingBottom: "24px",
65
+ paddingLeft: "24px",
66
+ fieldSpacing: "12px",
67
+ borderWidth: "1px",
68
+ borderStyle: "solid",
69
+ borderColor: "#dbe4f0",
70
+ boxShadow: "0 18px 40px rgba(15, 23, 42, 0.08)",
71
+ buttonBackgroundColor: "#0f172a",
72
+ buttonTextColor: "#ffffff",
73
+ buttonBorderRadius: "12px",
74
+ buttonPaddingTop: "10px",
75
+ buttonPaddingBottom: "10px",
76
+ buttonPaddingLeft: "14px",
77
+ buttonPaddingRight: "14px",
78
+ buttonFontSize: "13px",
79
+ buttonFontWeight: "700"
80
+ }), a = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), o = (e, t) => {
81
+ if (typeof t != "string") return "";
82
+ let n = t.trim();
83
+ return n ? ` ${e}="${a(n)}"` : "";
84
+ }, s = (e) => {
85
+ let a = r(e.type === "form_container" ? {
86
+ ...i(),
87
+ ...e.style || {}
88
+ } : e.style), o = e.attributes || {};
89
+ switch (e.type) {
90
+ case "heading": return `<h2 style="margin-top: 0; margin-bottom: 8px; ${a}">${o.text || "Heading"}</h2>`;
91
+ case "paragraph": return `<p style="margin-top: 0; margin-bottom: 12px; ${a}">${o.text || "Paragraph text content."}</p>`;
92
+ case "text": return `<div style="${a}">${o.text || ""}</div>`;
93
+ case "button": return `<div style="text-align: ${e.style.textAlign || "center"};"><a href="${o.href || "#"}" target="${o.openInNewTab ? "_blank" : "_self"}" style="display: inline-block; text-decoration: none; ${a}">${o.text || "Button"}</a></div>`;
94
+ case "image": {
95
+ let t = e.style.textAlign === "center" ? "margin: 0 auto; display: block;" : e.style.textAlign === "right" ? "margin-left: auto; display: block;" : "display: inline-block;";
96
+ return `<img src="${o.src || "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe"}" alt="${o.alt || ""}" style="${a} ${t}" />`;
97
+ }
98
+ case "divider": return `<hr style="border: 0; border-top: ${e.style.borderWidth || "1px"} ${e.style.borderStyle || "solid"} ${e.style.borderColor || "#334155"}; ${a}" />`;
99
+ case "spacer": return `<div style="height: ${e.style.height || "24px"};"></div>`;
100
+ case "card": return `<div style="${a}">
101
+ <h3 style="margin-top: 0; margin-bottom: 8px; color: #ffffff;">${o.title || "Card Title"}</h3>
102
+ <p style="margin: 0; color: #94a3b8; font-size: 14px;">${o.description || "Card description."}</p>
103
+ </div>`;
104
+ case "form_container": {
105
+ let t = o.fields || [], r = o.actionMode || "submit", i = r === "submit" && o.actionUrl || "#", s = o.method || "POST", c = r === "javascript" ? `onsubmit="${o.buttonFunction || "handleSubmit"}(event); return false;"` : r === "redirect" ? `onsubmit="window.location.href='${o.redirectUrl || "#"}'; return false;"` : "", l = n(t, "padding:8px 12px;border:1px solid #cbd5e1;border-radius:6px;font-size:13px;background:#fff;color:#1e293b;"), u = r === "submit" ? "submit" : "button", d = r === "javascript" ? `onclick="${o.buttonFunction || "handleSubmit"}(event)"` : r === "redirect" ? `onclick="window.location.href='${o.redirectUrl || "#"}'"` : "", f = [
106
+ "display: inline-block",
107
+ "border: none",
108
+ "cursor: pointer",
109
+ `background-color: ${e.style.buttonBackgroundColor || "#0f172a"}`,
110
+ `color: ${e.style.buttonTextColor || "#ffffff"}`,
111
+ `border-radius: ${e.style.buttonBorderRadius || "12px"}`,
112
+ `font-size: ${e.style.buttonFontSize || "13px"}`,
113
+ `font-weight: ${e.style.buttonFontWeight || "700"}`,
114
+ `padding-top: ${e.style.buttonPaddingTop || e.style.buttonPadding || "10px"}`,
115
+ `padding-bottom: ${e.style.buttonPaddingBottom || e.style.buttonPadding || "10px"}`,
116
+ `padding-left: ${e.style.buttonPaddingLeft || e.style.buttonPadding || "14px"}`,
117
+ `padding-right: ${e.style.buttonPaddingRight || e.style.buttonPadding || "14px"}`,
118
+ e.style.buttonMarginTop || e.style.buttonMargin ? `margin-top: ${e.style.buttonMarginTop || e.style.buttonMargin}` : "",
119
+ e.style.buttonMarginBottom || e.style.buttonMargin ? `margin-bottom: ${e.style.buttonMarginBottom || e.style.buttonMargin}` : "",
120
+ e.style.buttonMarginLeft || e.style.buttonMargin ? `margin-left: ${e.style.buttonMarginLeft || e.style.buttonMargin}` : "",
121
+ e.style.buttonMarginRight || e.style.buttonMargin ? `margin-right: ${e.style.buttonMarginRight || e.style.buttonMargin}` : "",
122
+ o.buttonAutoWidth === !1 ? `width: ${e.style.buttonWidth || "100%"}` : "width: auto",
123
+ o.buttonAutoHeight === !1 ? `height: ${e.style.buttonHeight || "auto"}` : ""
124
+ ].filter(Boolean).join(";"), p = e.style.buttonAlign === "center" ? "center" : e.style.buttonAlign === "right" ? "right" : "left";
125
+ return `<form name="${o.formName || "form"}" action="${i}" method="${s}" ${c} style="${a}">${l}<div style="width:100%;text-align:${p};"><button type="${u}" ${d} style="${f}">${o.submitLabel || "Submit"}</button></div></form>`;
126
+ }
127
+ case "input": return `<div style="margin-bottom: 12px;"><label style="display: block; font-size: 12px; color: #94a3b8; margin-bottom: 4px;">${o.name || "Field"}${o.required ? " *" : ""}</label><input type="text" placeholder="${o.placeholder || ""}" ${o.required ? "required" : ""} style="width: 100%; box-sizing: border-box; ${a}" /></div>`;
128
+ case "textarea": return `<div style="margin-bottom: 12px;"><label style="display: block; font-size: 12px; color: #94a3b8; margin-bottom: 4px;">${o.name || "Field"}${o.required ? " *" : ""}</label><textarea placeholder="${o.placeholder || ""}" ${o.required ? "required" : ""} style="width: 100%; box-sizing: border-box; min-height: 80px; ${a}"></textarea></div>`;
129
+ case "select": {
130
+ let e = (o.options || []).map((e) => `<option value="${e.value}">${e.label}</option>`).join("");
131
+ return `<div style="margin-bottom: 12px;"><label style="display: block; font-size: 12px; color: #94a3b8; margin-bottom: 4px;">${o.name || "Dropdown"}</label><select style="width: 100%; box-sizing: border-box; ${a}">${e}</select></div>`;
132
+ }
133
+ case "menu": {
134
+ let t = (o.links || []).map((e) => `<a href="${e.href || "#"}" style="color: inherit; text-decoration: none; padding: 0 12px;">${e.label}</a>`).join("");
135
+ return `<div style="display: flex; flex-wrap: wrap; justify-content: ${e.style.textAlign === "center" ? "center" : e.style.textAlign === "right" ? "flex-end" : "flex-start"}; ${a}">${t}</div>`;
136
+ }
137
+ case "html": return o.htmlContent ? String(o.htmlContent) : "<!-- Raw HTML empty -->";
138
+ case "table": {
139
+ let t = Number(o.rowCount) || 2, n = Number(o.colCount) || 2, r = e.style.cellPadding || "8px", i = `${e.style.borderWidth || "1px"} ${e.style.borderStyle || "solid"} ${e.style.borderColor || "#334155"}`, s = "";
140
+ for (let e = 0; e < t; e++) {
141
+ let t = "";
142
+ for (let a = 0; a < n; a++) t += `<td style="padding: ${r}; border: ${i};">Cell ${e + 1}, ${a + 1}</td>`;
143
+ s += `<tr>${t}</tr>`;
144
+ }
145
+ return `<table style="width: 100%; border-collapse: collapse; border: ${i}; ${a}">${s}</table>`;
146
+ }
147
+ case "timer": return `<div style="text-align: center; ${a}">
148
+ <span style="font-size: 1.5em; font-weight: bold;">[Countdown Timer to ${o.targetDate || "Future Target"}]</span>
149
+ </div>`;
150
+ case "video": return `<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; ${a}">
151
+ <iframe src="${o.videoUrl || "https://www.youtube.com/embed/dQw4w9WgXcQ"}" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0;" allowfullscreen></iframe>
152
+ </div>`;
153
+ case "social": {
154
+ let n = (o.links || []).map((n) => {
155
+ let r = String(n.color || e.style.iconColor || "#475569"), i = String(n.backgroundColor || e.style.iconBackgroundColor || "#f8fafc"), a = String(n.size || e.style.iconSize || "32px");
156
+ return `<a href="${n.url || "#"}" style="display: inline-flex; align-items: center; justify-content: center; width: ${a}; height: ${a}; border-radius: ${(n.iconType || o.iconType) === "square" ? "10px" : "9999px"}; background: ${i}; color: ${r}; text-decoration: none;">${t(n.provider, r)}</a>`;
157
+ }).join("");
158
+ return `<div style="text-align: ${e.style.textAlign || "center"}; display:flex; flex-wrap:wrap; justify-content:${e.style.textAlign === "center" ? "center" : e.style.textAlign === "right" ? "flex-end" : "flex-start"}; gap:${e.style.iconSpacing || "8px"}; ${a}">${n}</div>`;
159
+ }
160
+ case "carousel": return `<div class="plexo-carousel" style="overflow: hidden;">${(o.images || []).map((e, t) => `<div style="display: ${t === 0 ? "block" : "none"}; text-align: center;"><img src="${e.src}" style="max-width: 100%; height: auto; ${a}" />${e.caption ? `<div style="font-size: 12px; margin-top: 4px;">${e.caption}</div>` : ""}</div>`).join("")}</div>`;
161
+ case "icon": {
162
+ let t = o.iconName || "star", n = e.style.fontSize || "48px", r = e.style.color || "#1e293b", i = o.href || "", a = !!o.openInNewTab, s = `text-align: ${e.style.textAlign || "center"}; padding: ${e.style.padding || "8px"}; margin: ${e.style.margin || "0px"};`, c = `https://cdn.jsdelivr.net/npm/lucide-static@0.415.0/icons/${t}.svg`, l = parseInt(n) || 48, u = `<img src="${c}" width="${l}" height="${l}" alt="${t}" style="${`display: inline-block; vertical-align: middle; fill: ${r}; color: ${r}; width: ${l}px; height: ${l}px;`}" />`;
163
+ return `<div style="${s}">${i ? `<a href="${i}" target="${a ? "_blank" : "_self"}" style="text-decoration: none;">${u}</a>` : u}</div>`;
164
+ }
165
+ default: return `<!-- Unsupported block ${e.type} -->`;
166
+ }
167
+ }, c = (e) => {
168
+ let t = r(e.style), n = o("id", e.htmlId), i = o("class", e.htmlClass), a = `\n <!-- ROW START: ${e.id} -->`;
169
+ a += `\n <div${n}${i} class="plexo-row" style="display: flex; flex-wrap: wrap; margin-left: -8px; margin-right: -8px; ${t}">`;
170
+ for (let t of e.columns) {
171
+ let e = r(t.styles), n = o("id", t.attrs?.htmlId), i = t.attrs?.htmlClass ? ` ${t.attrs.htmlClass}` : "";
172
+ a += `\n <!-- COLUMN START: ${t.id} -->`, a += `\n <div${n} class="plexo-col${i}" style="box-sizing: border-box; padding-left: 8px; padding-right: 8px; width: ${t.width}; ${e}">`;
173
+ for (let e of t.elements) {
174
+ let t = e.attributes || {}, n = typeof t.htmlClassNames == "string" ? t.htmlClassNames : typeof t.htmlClass == "string" ? t.htmlClass : typeof t.className == "string" ? t.className : "", r = o("id", t.htmlId), i = o("class", n);
175
+ a += `\n <div${r}${i} style="margin-bottom: 16px;">`, a += `\n ${s(e)}`, a += "\n </div>";
176
+ }
177
+ if (t.nestedRows && t.nestedRows.length > 0) for (let e of t.nestedRows) a += c(e);
178
+ a += "\n </div>";
179
+ }
180
+ return a += "\n </div>", a;
181
+ }, l = (e) => {
182
+ let t = r(e.body.style), n = typeof e.body.style?.htmlTitle == "string" && e.body.style.htmlTitle.trim() ? e.body.style.htmlTitle.trim() : "Plexo Rendered Page", i = o("id", e.body.style?.htmlId), s = o("class", e.body.style?.htmlClass), l = typeof e.body.style?.customCss == "string" && e.body.style.customCss.trim() ? e.body.style.customCss.trim() : "", u = typeof e.body.style?.customJs == "string" && e.body.style.customJs.trim() ? e.body.style.customJs.trim() : "", d = `<!DOCTYPE html>
183
+ <html>
184
+ <head>
185
+ <meta charset="utf-8">
186
+ <title>${a(n)}</title>
187
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
188
+ <style>
189
+ body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
190
+ .plexo-row {
191
+ display: flex;
192
+ flex-wrap: wrap;
193
+ }
194
+ @media (max-width: 768px) {
195
+ .plexo-row {
196
+ flex-direction: column !important;
197
+ }
198
+ .plexo-col {
199
+ width: 100% !important;
200
+ max-width: 100% !important;
201
+ margin-bottom: 16px;
202
+ }
203
+ }
204
+ </style>
205
+ ${l ? `<style>\n${l}\n </style>` : ""}
206
+ </head>
207
+ <body${i}${s} style="${t}">
208
+ <div style="max-width: 1200px; margin: 0 auto; width: 100%;">`;
209
+ for (let t of e.body.rows) d += c(t);
210
+ return d += `\n </div>
211
+ ${u ? ` <script>\n${u}\n <\/script>` : ""}
212
+ </body>
213
+ </html>`, d;
214
+ }, u = (e) => {
215
+ let t = e.attributes || {};
216
+ switch (e.type) {
217
+ case "heading":
218
+ case "paragraph":
219
+ case "text": return t.text ? String(t.text) : "";
220
+ case "button": return `[ Button: ${t.text || "Button"} -> ${t.href || "#"} ]`;
221
+ case "image": return `[ Image: ${t.alt || "Unnamed Image"} (${t.src || ""}) ]`;
222
+ case "card": return `${t.title || "Card Title"}\n${t.description || ""}`;
223
+ case "form_container": return `[ Form: ${t.formName || "form"} (${t.actionUrl || ""}) ]`;
224
+ case "input":
225
+ case "textarea": return `${t.name || "Field"}: __________`;
226
+ case "select": {
227
+ let e = t.options || [];
228
+ return `${t.name || "Dropdown"}: [ ${e.map((e) => e.label).join(" | ")} ]`;
229
+ }
230
+ case "menu": return `Menu: ${(t.links || []).map((e) => e.label).join(" | ")}`;
231
+ case "html": return "[ Raw HTML Block ]";
232
+ case "table": return `[ Table of size ${Number(t.rowCount) || 2}x${Number(t.colCount) || 2} ]`;
233
+ case "timer": return `[ Countdown Timer target: ${t.targetDate || "Future Target"} ]`;
234
+ case "video": return `[ Video Link: ${t.videoUrl || ""} ]`;
235
+ case "social": return `Social Profiles: ${(t.links || []).map((e) => `${e.provider.toUpperCase()} (${e.url || ""})`).join(", ")}`;
236
+ default: return "";
237
+ }
238
+ }, d = (e) => {
239
+ let t = [], n = (e) => {
240
+ for (let r of e.columns) {
241
+ for (let e of r.elements) {
242
+ let n = u(e);
243
+ n && t.push(n);
244
+ }
245
+ if (r.nestedRows && r.nestedRows.length > 0) for (let e of r.nestedRows) n(e);
246
+ }
247
+ };
248
+ for (let t of e.body.rows) n(t);
249
+ return t.join("\n\n");
250
+ }, f = (e) => {
251
+ let t = (e = {}) => Object.values(e).some((e) => typeof e == "string" && e.includes("var(--strata-") ? !0 : typeof e == "object" && t(e)), n = (e) => {
252
+ if (t(e.style)) return !0;
253
+ for (let r of e.columns) {
254
+ if (t(r.styles)) return !0;
255
+ for (let e of r.elements) if (t(e.style) || t(e.attributes)) return !0;
256
+ if (r.nestedRows && r.nestedRows.length > 0) {
257
+ for (let e of r.nestedRows) if (n(e)) return !0;
258
+ }
259
+ }
260
+ return !1;
261
+ };
262
+ if (t(e.body.style)) return !0;
263
+ for (let t of e.body.rows) if (n(t)) return !0;
264
+ return !1;
265
+ }, p = (e, t) => {
266
+ if (!t) return e;
267
+ let n = `
268
+ <!-- Strata Design System Web Components Bundle -->
269
+ <script defer src="https://cdn.strata.design/v1/strata-web-components.js"><\/script>
270
+ <link rel="stylesheet" href="https://cdn.strata.design/v1/strata-tokens-${t}.css">
271
+ <script>
272
+ // Initialize Strata components when DOM is ready
273
+ if (window.StrataWebComponents) {
274
+ window.StrataWebComponents.init({
275
+ projectId: '${t}',
276
+ syncEnabled: true
277
+ });
278
+ }
279
+ <\/script>`;
280
+ return e.includes("</head>") ? e.replace("</head>", ` ${n}\n</head>`) : e;
281
+ }, m = (e) => {
282
+ let t = l(e), n = e.body.strataConfig?.projectId;
283
+ return n && (t = p(t, n)), t;
284
+ };
285
+ //#endregion
286
+ export { l as compileToHTML, m as compileToHTMLWithStrataAuto, d as compileToPlainText, f as detectStrataUsage, p as injectStrataBundle };
@@ -0,0 +1,61 @@
1
+ //#region src/utilities/compilerClient.ts
2
+ var e = /* @__PURE__ */ new Set([
3
+ "selectable",
4
+ "draggable",
5
+ "duplicatable",
6
+ "deletable",
7
+ "hideable",
8
+ "locked"
9
+ ]), t = (e) => String(e ?? "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"), n = (e = {}) => Object.entries(e).filter(([, e]) => e != null && String(e).trim() !== "").map(([e, t]) => `${e.replace(/([A-Z])/g, "-$1").toLowerCase()}:${String(t)};`).join(""), r = (...e) => e.map((e) => String(e ?? "").trim()).filter(Boolean).join(" "), i = (t, n) => {
10
+ let r = { ...t.attributes || {} };
11
+ if (n === "email") for (let t of e) delete r[t];
12
+ return r;
13
+ }, a = (e, a) => {
14
+ let o = i(e, a), s = n(e.style || {}), c = r(o.htmlClassNames, o.htmlClass, o.validationClass, o.validationClassName), l = t(o.name || o.fieldName || "field"), u = t(o.placeholder || ""), d = o.required ? " required" : "";
15
+ if (a === "email") return `<mj-table><tr><td style="padding:10px 12px;border:1px solid #d1d5db;border-radius:6px;color:#64748b;${s}">${u || l}</td></tr></mj-table>`;
16
+ let f = t(o.inputType || (e.type === "input" ? o.type || "text" : e.type)), p = o.htmlId ? ` id="${t(o.htmlId)}"` : "", m = c ? ` class="${t(c)}"` : "";
17
+ return e.type === "textarea" ? `<textarea${p}${m} name="${l}" placeholder="${u}" style="${s}"${d}>${t(o.value || "")}</textarea>` : e.type === "select" ? `<select${p}${m} name="${l}" style="${s}"${d}>${(o.options || []).map((e) => `<option value="${t(e.value)}">${t(e.label)}</option>`).join("")}</select>` : `<input${p}${m} type="${f}" name="${l}" placeholder="${u}" value="${t(o.value || "")}" style="${s}"${d} />`;
18
+ }, o = (e, o) => {
19
+ let s = i(e, o), c = n(e.style || {}), l = r(s.htmlClassNames, s.htmlClass), u = s.htmlId ? ` id="${t(s.htmlId)}"` : "", d = l ? ` class="${t(l)}"` : "", f = t(s.actionUrl || s.action || "#"), p = t(s.method || "POST"), m = s.fields || [], h = t(s.submitLabel || "Submit");
20
+ return o === "email" ? `<mj-table><tr><td style="${c}"><table role="presentation" width="100%">${m.map((e) => `<tr><td style="padding:8px 0;font-family:Arial,sans-serif;color:#334155;"><strong>${t(e.label || e.name || "Field")}</strong><br/><span style="display:inline-block;margin-top:4px;padding:10px 12px;border:1px solid #d1d5db;border-radius:6px;color:#64748b;">${t(e.placeholder || "") || "&nbsp;"}</span></td></tr>`).join("")}<tr><td style="padding-top:12px;"><a href="${t(s.href || s.submitHref || "#")}" style="display:inline-block;padding:10px 16px;background:#0f172a;color:#ffffff;text-decoration:none;border-radius:6px;">${h}</a></td></tr></table></td></tr></mj-table>` : `<form${u}${d} action="${f}" method="${p}" style="${c}">${m.map((t) => a({
21
+ id: `${e.id}-${String(t.name || t.label || "field")}`,
22
+ type: t.kind === "textarea" || t.kind === "select" ? t.kind : "input",
23
+ style: {
24
+ ...e.style || {},
25
+ ...t.style || {}
26
+ },
27
+ attributes: t
28
+ }, "landing_page")).join("")}<button type="submit">${h}</button></form>`;
29
+ }, s = (e, s) => {
30
+ let c = i(e, s), l = n(e.style || {}), u = c.htmlId ? ` id="${t(c.htmlId)}"` : "", d = r(c.htmlClassNames, c.htmlClass, s === "landing_page" && c.hideOnMobile ? "hidden md:block" : ""), f = d ? ` class="${t(d)}"` : "", p = typeof c.customCss == "string" && c.customCss.trim() ? c.customCss.trim() : "", m = p && s === "landing_page" ? `<style>${p}</style>` : "";
31
+ if (e.type === "form_container") return `${m}${o(e, s)}`;
32
+ if (e.type === "input" || e.type === "select" || e.type === "textarea") return `${m}${a(e, s)}`;
33
+ if (s === "email") {
34
+ if (e.type === "button") {
35
+ let e = t(c.href || "#"), n = t(c.text || "Button");
36
+ return `<mj-button href="${e}" css-class="${c.hideOnDesktop ? "desktop-hide" : ""}" padding="0" inner-padding="10px 16px">${n}</mj-button>`;
37
+ }
38
+ return e.type === "image" ? `<mj-image src="${t(c.src || "")}" alt="${t(c.alt || "")}" />` : `<mj-text${u}${f} css-class="${c.hideOnDesktop ? "desktop-hide" : ""}">${t(c.text || c.htmlContent || "")}</mj-text>`;
39
+ }
40
+ switch (e.type) {
41
+ case "heading": return `${m}<h2${u}${f} style="${l}">${t(c.text || "Heading")}</h2>`;
42
+ case "paragraph":
43
+ case "text": return `${m}<p${u}${f} style="${l}">${t(c.text || "")}</p>`;
44
+ case "button": return `${m}<a${u}${f} href="${t(c.href || "#")}" style="${l}">${t(c.text || "Button")}</a>`;
45
+ case "image": return `${m}<img${u}${f} src="${t(c.src || "")}" alt="${t(c.alt || "")}" style="${l}" />`;
46
+ case "html": return `${m}<div${u}${f} style="${l}">${String(c.htmlContent || "")}</div>`;
47
+ default: return `${m}<div${u}${f} style="${l}">${t(c.text || "")}</div>`;
48
+ }
49
+ }, c = (e, r) => {
50
+ if (r === "email") {
51
+ let n = e.elements.map((e) => s(e, r)).join("");
52
+ return `<mj-column width="${t(e.width || "100%")}">${n}</mj-column>`;
53
+ }
54
+ let i = n(e.styles || {}), a = e.elements.map((e) => s(e, r)).join("");
55
+ return `<div style="width:${t(e.width || "100%")};${i}">${a}</div>`;
56
+ }, l = (e, t) => t === "email" ? `<mj-section css-class="${e.style?.hideOnDesktop ? "desktop-hide" : ""}">${e.columns.map((e) => c(e, t)).join("")}</mj-section>` : `<section style="display:flex;flex-wrap:wrap;${n(e.style || {})}">${e.columns.map((e) => c(e, t)).join("")}</section>`, u = (e, t) => {
57
+ let r = (e.body?.rows || []).map((e) => l(e, t)).join(""), i = n(e.body?.style || {});
58
+ return t === "email" ? `<mjml><mj-head><mj-style>.desktop-hide { display:none !important; max-height:0; overflow:hidden; }</mj-style></mj-head><mj-body><mj-section><mj-column><mj-wrapper css-class="email-root" padding="0"><mj-text css-class="preheader" padding="0" font-size="1px" color="#ffffff">&nbsp;</mj-text></mj-wrapper></mj-column></mj-section>${r}</mj-body></mjml>` : `<!doctype html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /></head><body style="${i}"><main>${r}</main></body></html>`;
59
+ };
60
+ //#endregion
61
+ export { u as parseJsonToTargetFormat };
package/dist/index.d.ts CHANGED
@@ -7,3 +7,5 @@ export { createTokenMapping, applyTokensToElement, getTokensByCategory, generate
7
7
  export type { StrataToken, StrataTokenSet } from './utilities/strataTokenMapping';
8
8
  export type { CompileTarget } from './utilities/compilerClient';
9
9
  export type { BodyJSON, ColumnJSON, ElementAttributes, ElementJSON, ElementStyles, ElementType, RowJSON, RowStyles, TemplateJSON, TemplateStyles, } from './utilities/types';
10
+ export { PlexoRenderer, SafeHTML, safeJsonParse, sanitizeObject, sanitizeHtml, sanitizeStyleString, sanitizeStyleObject, ElementJSONSchema, ColumnJSONSchema, RowJSONSchema, TemplateJSONSchema, } from './PlexoRenderer';
11
+ export type { PlexoRendererProps } from './PlexoRenderer';