@grapesjs/studio-sdk-plugins 1.0.25 → 1.0.26-rc.1

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 (65) hide show
  1. package/dist/dataSourceEjs/EjsExporter.d.ts +2 -2
  2. package/dist/dataSourceHandlebars/HandlebarsExporter.d.ts +2 -2
  3. package/dist/flexComponent/index.cjs.js +1 -1
  4. package/dist/flexComponent/index.es.js +1 -1
  5. package/dist/flexComponent/index.umd.js +1 -1
  6. package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
  7. package/dist/googleFontsAssetProvider/index.es.js +4 -4
  8. package/dist/googleFontsAssetProvider/index.umd.js +1 -1
  9. package/dist/iconifyComponent/index.cjs.js +1 -1
  10. package/dist/iconifyComponent/index.es.js +1 -1
  11. package/dist/iconifyComponent/index.umd.js +1 -1
  12. package/dist/index.cjs.js +21 -21
  13. package/dist/index.es.js +219 -216
  14. package/dist/index.umd.js +2 -2
  15. package/dist/layoutSidebarButtons/index.cjs.js +1 -1
  16. package/dist/layoutSidebarButtons/index.es.js +19 -19
  17. package/dist/layoutSidebarButtons/index.umd.js +1 -1
  18. package/dist/layoutSidebarButtons/types.d.ts +2 -1
  19. package/dist/presetPrintable/index.cjs.js +3 -3
  20. package/dist/presetPrintable/index.es.js +101 -101
  21. package/dist/presetPrintable/index.umd.js +1 -1
  22. package/dist/prosemirror/index.cjs.js +1 -1
  23. package/dist/prosemirror/index.es.js +1 -1
  24. package/dist/prosemirror/index.umd.js +1 -1
  25. package/dist/rendererReact/index.cjs.d.ts +3 -2
  26. package/dist/rendererReact/index.cjs.js +1 -1
  27. package/dist/rendererReact/index.d.ts +3 -2
  28. package/dist/rendererReact/index.es.d.ts +3 -2
  29. package/dist/rendererReact/index.es.js +219 -153
  30. package/dist/rendererReact/index.js +1 -0
  31. package/dist/rendererReact/index.umd.js +1 -1
  32. package/dist/rendererReact/rendererCanvas/RenderCanvasComponent.d.ts +4 -2
  33. package/dist/rendererReact/rendererCanvas/customRenderer.d.ts +2 -2
  34. package/dist/rendererReact/rendererCanvas/util.d.ts +27 -7
  35. package/dist/rendererReact/rendererProject/RenderComponent.d.ts +2 -0
  36. package/dist/rendererReact/rendererProject/RenderError.d.ts +2 -0
  37. package/dist/rendererReact/rendererProject/RenderPage.d.ts +2 -0
  38. package/dist/rendererReact/rendererProject/RenderProject.d.ts +3 -0
  39. package/dist/rendererReact/rendererProject/index.cjs.d.ts +1 -2
  40. package/dist/rendererReact/rendererProject/index.cjs.js +2 -10
  41. package/dist/rendererReact/rendererProject/index.d.ts +1 -2
  42. package/dist/rendererReact/rendererProject/index.es.d.ts +1 -2
  43. package/dist/rendererReact/rendererProject/index.es.js +206 -227
  44. package/dist/rendererReact/rendererProject/index.js +2 -10
  45. package/dist/rendererReact/rendererProject/index.umd.js +2 -10
  46. package/dist/rendererReact/rendererProject/parser/parser.d.ts +34 -53
  47. package/dist/rendererReact/rendererProject/types.d.ts +18 -4
  48. package/dist/rendererReact/rendererProject/util.d.ts +0 -11
  49. package/dist/rendererReact/shared/shared.d.ts +3 -0
  50. package/dist/rendererReact/shared/types.d.ts +150 -44
  51. package/dist/rendererReact/shared/util.d.ts +7 -1
  52. package/dist/rendererReact/types.d.ts +9 -12
  53. package/dist/rendererReact/typesSchema.d.ts +116 -49
  54. package/dist/rteTinyMce/index.cjs.js +1 -1
  55. package/dist/rteTinyMce/index.es.js +1 -1
  56. package/dist/rteTinyMce/index.umd.js +1 -1
  57. package/dist/tableComponent/index.cjs.js +1 -1
  58. package/dist/tableComponent/index.es.js +15 -12
  59. package/dist/tableComponent/index.umd.js +1 -1
  60. package/dist/youtubeAssetProvider/index.cjs.js +1 -1
  61. package/dist/youtubeAssetProvider/index.es.js +6 -6
  62. package/dist/youtubeAssetProvider/index.umd.js +1 -1
  63. package/package.json +14 -2
  64. package/dist/rendererReact/rendererProject/GrapesJSProject.d.ts +0 -3
  65. package/dist/rendererReact/rendererProject/RenderProjectComponent.d.ts +0 -12
@@ -1,91 +1,87 @@
1
- import { jsx as u, jsxs as S, Fragment as v } from "react/jsx-runtime";
2
- import { createElement as W, Fragment as T } from "react";
3
- function E(s, t, e) {
4
- const o = s.getId(), a = s.getType(), r = o || void 0;
5
- let n;
6
- return o ? n = o : t ? n = `${t}-${e ?? 0}` : a === "head" ? n = "gjs-head" : t === "gjs-head" ? n = `${t}-${e ?? 0}` : n = `gjs-${a}`, { key: n, nodeId: r };
1
+ import { jsx as l, jsxs as C } from "react/jsx-runtime";
2
+ import { createElement as T, Fragment as v } from "react";
3
+ var m = /* @__PURE__ */ ((n) => (n.NoPagesFound = "noPagesFound", n.PageNotFound = "pageNotFound", n.NoFramesFound = "noFramesFound", n.MissingRootComponent = "missingRootComponent", n.ComponentNotFound = "componentNotFound", n))(m || {});
4
+ function k(n) {
5
+ const { config: t, errorType: e } = n, r = t == null ? void 0 : t.errorComponent;
6
+ return r ? /* @__PURE__ */ l(r, { ...n }) : /* @__PURE__ */ C("div", { children: [
7
+ "Error: ",
8
+ e
9
+ ] });
7
10
  }
8
- const O = {
9
- noPagesFound: () => "No pages found in project",
10
- pageNotFound: ({ pageId: s = "" }) => `Page not found: ${s}`,
11
- noFramesFound: () => "No frames found in page",
12
- missingRootComponent: () => "Missing root component",
13
- componentNotFound: ({ componentId: s = "" }) => `Component not found: ${s}`
14
- };
15
- function R(s) {
11
+ function P(n) {
16
12
  const t = {};
17
13
  let e = !1;
18
- for (const o in s)
19
- if (Object.prototype.hasOwnProperty.call(s, o)) {
20
- const a = s[o];
21
- if (typeof a == "string" || typeof a == "number") {
22
- const r = o.includes("-") ? o.replace(/-([a-z])/g, (n) => n[1].toUpperCase()) : o;
23
- t[r] = a, e = !0;
14
+ for (const r in n)
15
+ if (Object.prototype.hasOwnProperty.call(n, r)) {
16
+ const s = n[r];
17
+ if (typeof s == "string" || typeof s == "number") {
18
+ const o = r.includes("-") ? r.replace(/-([a-z])/g, (i) => i[1].toUpperCase()) : r;
19
+ t[o] = s, e = !0;
24
20
  }
25
21
  }
26
22
  return e ? t : void 0;
27
23
  }
28
- function D(s) {
24
+ function D(n) {
29
25
  const t = {};
30
- return s.split(";").forEach((e) => {
26
+ return n.split(";").forEach((e) => {
31
27
  if (!e.trim()) return;
32
- const o = e.indexOf(":");
33
- if (o > 0) {
34
- const a = e.substring(0, o).trim(), r = e.substring(o + 1).trim();
35
- if (a && r) {
36
- const n = a.replace(/-([a-z])/g, (c) => c[1].toUpperCase());
37
- t[n] = r;
28
+ const r = e.indexOf(":");
29
+ if (r > 0) {
30
+ const s = e.substring(0, r).trim(), o = e.substring(r + 1).trim();
31
+ if (s && o) {
32
+ const i = s.replace(/-([a-z])/g, (c) => c[1].toUpperCase());
33
+ t[i] = o;
38
34
  }
39
35
  }
40
36
  }), Object.keys(t).length > 0 ? t : void 0;
41
37
  }
42
- function I(s) {
43
- if (s) {
44
- if (typeof s == "object" && !Array.isArray(s))
45
- return R(s);
46
- if (typeof s == "string") {
47
- let t = D(s);
38
+ function W(n) {
39
+ if (n) {
40
+ if (typeof n == "object" && !Array.isArray(n))
41
+ return P(n);
42
+ if (typeof n == "string") {
43
+ let t = D(n);
48
44
  if (!t)
49
45
  try {
50
- const e = JSON.parse(s);
51
- typeof e == "object" && e !== null && !Array.isArray(e) && (t = R(e));
46
+ const e = JSON.parse(n);
47
+ typeof e == "object" && e !== null && !Array.isArray(e) && (t = P(e));
52
48
  } catch (e) {
53
49
  console.error("Failed to parse style string as JSON", e);
54
50
  }
55
51
  return t;
56
52
  }
57
- if (Array.isArray(s)) {
53
+ if (Array.isArray(n)) {
58
54
  const t = {};
59
- return s.forEach((e) => {
55
+ return n.forEach((e) => {
60
56
  if (typeof e == "object" && e !== null) {
61
- const o = e.name || e.property, a = e.value;
62
- if (typeof o == "string" && o && a !== void 0 && a !== "") {
63
- const r = o.replace(/-([a-z])/g, (n) => n[1].toUpperCase());
64
- t[r] = a;
57
+ const r = e.name || e.property, s = e.value;
58
+ if (typeof r == "string" && r && s !== void 0 && s !== "") {
59
+ const o = r.replace(/-([a-z])/g, (i) => i[1].toUpperCase());
60
+ t[o] = s;
65
61
  }
66
62
  }
67
63
  }), Object.keys(t).length > 0 ? t : void 0;
68
64
  }
69
65
  }
70
66
  }
71
- function B(s) {
72
- return F[s] ? F[s] : s.includes("-") ? s.replace(/-([a-z])/g, (t, e) => e.toUpperCase()) : s;
67
+ function B(n) {
68
+ return j[n] ? j[n] : n.includes("-") ? n.replace(/-([a-z])/g, (t, e) => e.toUpperCase()) : n;
73
69
  }
74
- function M(s) {
75
- var o;
76
- const t = {}, e = ((o = s.xmlns) == null ? void 0 : o.includes("svg")) || s.viewBox !== void 0 || s.d !== void 0;
77
- for (const [a, r] of Object.entries(s))
78
- if (a === "style")
79
- t.style = I(r);
80
- else if (a.startsWith("data-"))
81
- t[a] = r;
70
+ function I(n) {
71
+ var e;
72
+ const t = {};
73
+ for (const [r, s] of Object.entries(n))
74
+ if (r === "style")
75
+ t.style = W(s);
76
+ else if (r.startsWith("data-"))
77
+ t[r] = s;
82
78
  else {
83
- const n = B(a);
84
- e || L.has(n) || n.startsWith("svg") ? t[n] = r : !z.has(n) && !n.startsWith("on") && !n.startsWith("aria-") && !n.startsWith("data-") ? t[`data-${a.toLowerCase()}`] = r : t[n] = r;
79
+ const o = B(r);
80
+ ((e = n.xmlns) == null ? void 0 : e.includes("svg")) || n.viewBox !== void 0 || n.d !== void 0 || z.has(o) || o.startsWith("svg") ? t[o] = s : !M.has(o) && !o.startsWith("on") && !o.startsWith("aria-") && !o.startsWith("data-") ? t[r] = s : t[o] = s;
85
81
  }
86
82
  return t;
87
83
  }
88
- const z = /* @__PURE__ */ new Set([
84
+ const M = /* @__PURE__ */ new Set([
89
85
  "className",
90
86
  "id",
91
87
  "style",
@@ -126,7 +122,7 @@ const z = /* @__PURE__ */ new Set([
126
122
  "aria-labelledby",
127
123
  "aria-describedby",
128
124
  "role"
129
- ]), L = /* @__PURE__ */ new Set([
125
+ ]), z = /* @__PURE__ */ new Set([
130
126
  "x",
131
127
  "y",
132
128
  "d",
@@ -169,7 +165,7 @@ const z = /* @__PURE__ */ new Set([
169
165
  "clipPath",
170
166
  "overflow",
171
167
  "pointerEvents"
172
- ]), F = {
168
+ ]), j = {
173
169
  class: "className",
174
170
  for: "htmlFor",
175
171
  "http-equiv": "httpEquiv",
@@ -186,117 +182,106 @@ const z = /* @__PURE__ */ new Set([
186
182
  "font-family": "fontFamily",
187
183
  "font-size": "fontSize",
188
184
  "text-anchor": "textAnchor"
189
- }, A = function s(t) {
190
- var $;
191
- const { component: e, config: o, children: a, parentId: r, index: n } = t;
185
+ };
186
+ function L(n, t, e) {
187
+ const { id: r, type: s } = n, o = r || void 0;
188
+ let i;
189
+ return r ? i = r : t ? i = `${t}-${e ?? 0}` : s === "head" ? i = "gjs-head" : t === "gjs-head" ? i = `${t}-${e ?? 0}` : i = `gjs-${s}`, { key: i, nodeId: o };
190
+ }
191
+ const R = function n(t) {
192
+ var w;
193
+ const { component: e, config: r, children: s, parentId: o, index: i } = t;
192
194
  if (!e) return null;
193
- const c = e.getType() || "", p = e.getContent();
194
- if (c === "textnode") return p;
195
- const l = ($ = o.components) == null ? void 0 : $[c], i = (l == null ? void 0 : l.component) || e.getTagName() || "div", h = e.getAttributes(), { key: f, nodeId: w } = E(e, r, n), b = !!(l != null && l.component), C = b ? h : M(h);
196
- b && Object.keys(C).forEach((m) => {
197
- const g = C[m];
198
- typeof g == "string" && !isNaN(Number(g)) && g.trim() !== "" && (C[m] = Number(g));
195
+ const { type: c, content: a } = e;
196
+ if (c === "textnode") return a;
197
+ const u = (w = r == null ? void 0 : r.components) == null ? void 0 : w[c], d = (u == null ? void 0 : u.component) || e.tagName || "div", h = e.attributes, { key: g, nodeId: N } = L(e, o, i), b = !!(u != null && u.component), A = I(h);
198
+ b && Object.keys(A).forEach((y) => {
199
+ const p = A[y];
200
+ typeof p == "string" && !isNaN(Number(p)) && p.trim() !== "" && (A[y] = Number(p));
199
201
  });
200
- const x = e.getComponents(), N = [...x.length ? x.map((m, g) => /* @__PURE__ */ u(
201
- s,
202
- {
203
- config: o,
204
- component: m,
205
- parentId: f,
206
- index: g
207
- },
208
- `${m.getId()}-${g}`
209
- )) : [p], a], P = {
210
- ...C,
211
- ...w ? { id: w } : {}
202
+ const { components: F } = e, x = [...F.length ? F.map((y, p) => /* @__PURE__ */ l(n, { config: r, component: y, parentId: g, index: p }, `${y.id}-${p}`)) : [a], s], $ = {
203
+ ...A,
204
+ ...N ? { id: N } : {}
212
205
  };
213
- return b ? /* @__PURE__ */ u(i, { ...P, children: N }, f) : /* @__PURE__ */ W(i, { ...P, key: f }, e.isVoid() ? null : N);
206
+ return b ? /* @__PURE__ */ l(d, { ...$, children: x }, g) : /* @__PURE__ */ T(d, { ...$, key: g }, e.isVoid ? null : x);
214
207
  };
215
- class k {
208
+ function U(n) {
209
+ var a;
210
+ const { config: t, root: e, css: r } = n, s = (t == null ? void 0 : t.rootComponent) || v, o = ((a = e.docEl) == null ? void 0 : a.tagName) || "html", i = (t == null ? void 0 : t.headAfter) || v, c = (t == null ? void 0 : t.bodyAfter) || v;
211
+ return /* @__PURE__ */ l(o, { children: /* @__PURE__ */ C(s, { children: [
212
+ /* @__PURE__ */ C(R, { component: e.head, config: t, children: [
213
+ /* @__PURE__ */ l("style", { children: `${r}` }),
214
+ /* @__PURE__ */ l(i, {})
215
+ ] }),
216
+ /* @__PURE__ */ l(R, { component: e, config: t, children: /* @__PURE__ */ l(c, {}) })
217
+ ] }) });
218
+ }
219
+ class S {
216
220
  constructor(t) {
217
221
  this.data = t;
218
222
  }
219
- getId() {
223
+ get id() {
220
224
  var t;
221
225
  return (t = this.data.attributes) == null ? void 0 : t.id;
222
226
  }
223
- getType() {
227
+ get type() {
224
228
  return this.data.type || "default";
225
229
  }
226
- getTagName() {
227
- const t = this.getType();
230
+ get tagName() {
231
+ const { type: t } = this;
228
232
  return t === "svg" ? "svg" : t === "image" ? "img" : t === "linkBox" || t === "link" ? "a" : t === "head" ? "head" : t === "wrapper" ? "body" : this.data.tagName || "";
229
233
  }
230
- isVoid() {
231
- return this.getTagName() === "img" ? !0 : !!this.data.void;
234
+ get isVoid() {
235
+ return this.tagName === "img" ? !0 : !!this.data.void;
232
236
  }
233
- getAttributes() {
234
- const t = { ...this.data.attributes }, e = this.getClasses();
237
+ get attributes() {
238
+ const t = { ...this.data.attributes }, { classes: e } = this;
235
239
  e.length && (t.class = e.join(" "));
236
- function o(a, r) {
237
- return Object.prototype.hasOwnProperty.call(a, r);
240
+ function r(s, o) {
241
+ return Object.prototype.hasOwnProperty.call(s, o);
238
242
  }
239
- return o(t, "id") || (t.id = this.getId()), t;
240
- }
241
- getStyle() {
242
- return this.data.style || {};
243
+ return r(t, "id") || (t.id = this.id), t;
243
244
  }
244
- getContent() {
245
+ get content() {
245
246
  return this.data.content || "";
246
247
  }
247
- getComponents() {
248
- return (this.data.components || []).map((t) => new k(t));
248
+ get components() {
249
+ return (this.data.components || []).map((t) => new S(t));
249
250
  }
250
- getHead() {
251
- return this.data.head ? new k(this.data.head) : null;
251
+ get head() {
252
+ return new S(this.data.head || { tagName: "head" });
252
253
  }
253
- getDocEl() {
254
+ get docEl() {
254
255
  return this.data.docEl;
255
256
  }
256
- getClasses() {
257
+ get classes() {
257
258
  return (this.data.classes || []).map((e) => typeof e == "string" ? e : e.name);
258
259
  }
259
- hasClass(t) {
260
- return this.getClasses().includes(t);
261
- }
262
260
  }
263
- class U {
261
+ class _ {
264
262
  constructor(t) {
265
263
  this.data = t;
266
264
  }
267
- getComponent() {
268
- return this.data.component ? new k(this.data.component) : null;
269
- }
270
- getWidth() {
271
- return this.data.width || "";
272
- }
273
- getHeight() {
274
- return this.data.height || "";
265
+ get component() {
266
+ return this.data.component ? new S(this.data.component) : null;
275
267
  }
276
268
  }
277
269
  class V {
278
270
  constructor(t) {
279
271
  this.data = t;
280
272
  }
281
- getId() {
273
+ get id() {
282
274
  return this.data.id;
283
275
  }
284
- getName() {
285
- return this.data.name || "";
286
- }
287
- getFrames() {
288
- return (this.data.frames || []).map((t) => new U(t));
276
+ get frames() {
277
+ return (this.data.frames || []).map((t) => new _(t));
289
278
  }
290
279
  }
291
- class q {
292
- constructor(t) {
293
- this.assets = t;
294
- }
295
- getAll() {
296
- return this.assets;
297
- }
280
+ function E(n) {
281
+ const t = /(-?\d*\.?\d+)\w{0,}/.exec(n);
282
+ return t ? parseFloat(t[1]) : Number.MAX_VALUE;
298
283
  }
299
- class G {
284
+ class q {
300
285
  constructor(t) {
301
286
  this.rules = t;
302
287
  }
@@ -306,50 +291,75 @@ class G {
306
291
  getRulesByGroup(t) {
307
292
  return this.rules.filter((e) => e.group === t);
308
293
  }
309
- getWrapperRules() {
310
- return this.rules.filter((t) => t.wrapper === 1);
294
+ getAtRule(t) {
295
+ const { atRuleType: e, mediaText: r } = t, s = e ? `@${e}` : r ? "@media" : "";
296
+ return s + (r && s ? ` ${r}` : "");
297
+ }
298
+ selectorsToString(t, e = {}) {
299
+ const r = [], { state: s, selectorsAdd: o, selectors: i = [] } = t, c = i.map((u) => this.getFromSelectorName(u)).join(""), a = s && !e.skipState ? `:${s}` : "";
300
+ return c && r.push(`${c}${a}`), o && !e.skipAdd && r.push(o), r.join(", ");
301
+ }
302
+ getFromSelectorName(t = "") {
303
+ return `${t.startsWith("#") ? "" : "."}${t}`;
304
+ }
305
+ styleToString(t = {}) {
306
+ const e = [], { style: r = {}, important: s } = t;
307
+ for (const o in r) {
308
+ const i = Array.isArray(s) ? s.indexOf(o) >= 0 : s;
309
+ if (o.substring(0, 2) === "__") continue;
310
+ const a = r[o];
311
+ (Array.isArray(a) ? a : [a]).forEach((f) => {
312
+ const d = `${f}${i ? " !important" : ""}`;
313
+ d && e.push(`${o}:${d};`);
314
+ });
315
+ }
316
+ return e.join("");
317
+ }
318
+ getDeclaration(t) {
319
+ const { singleAtRule: e } = t, r = this.selectorsToString(t), s = this.styleToString(t);
320
+ let o = "";
321
+ return (r || e) && s && (o = e ? s : `${r}{${s}}`), o;
322
+ }
323
+ buildFromRule(t) {
324
+ let e = "";
325
+ const r = this.selectorsToString(t), { selectorsAdd: s, singleAtRule: o } = t;
326
+ if (r || s || o) {
327
+ const i = this.getDeclaration(t);
328
+ i && (e += i);
329
+ }
330
+ return e;
331
+ }
332
+ sortMediaObject(t = {}) {
333
+ const e = [];
334
+ for (const r in t) {
335
+ const s = t[r];
336
+ e.push({ key: r, value: s });
337
+ }
338
+ return e.sort((r, s) => {
339
+ const o = [r.key, s.key].every((a) => a.indexOf("min-width") !== -1), i = o ? r.key : s.key, c = o ? s.key : r.key;
340
+ return E(i) - E(c);
341
+ });
311
342
  }
312
343
  getCssAsString() {
313
344
  if (!this.rules || !this.rules.length) return "";
314
- const t = (r) => {
315
- if (!r || !r.selectors || !r.style) return "";
316
- let n = r.selectors;
317
- if (typeof n == "string")
318
- n = [n];
319
- else if (!Array.isArray(n))
320
- return "";
321
- const c = n.map(
322
- (i) => typeof i == "string" && !i.startsWith(".") && !i.startsWith("#") && !i.startsWith("[") && !i.startsWith(":") && !i.startsWith(">") && !i.startsWith("*") && !i.startsWith("@") ? "." + i : i
323
- ), p = r.state, l = p ? c.map((i) => `${i.trim()}:${p}`).join(", ") : c.join(""), d = Object.entries(r.style).map(([i, h]) => ` ${i}: ${h};`).join(`
324
- `);
325
- return d ? `${l} {
326
- ${d}
327
- }` : "";
328
- }, e = [], o = {};
329
- this.rules.forEach((r) => {
330
- if (!r || !r.selectors || !r.style) return;
331
- const n = r.atRuleType && r.mediaText ? `@${r.atRuleType} ${r.mediaText}` : r.mediaText ? `@media ${r.mediaText}` : null;
332
- n ? (o[n] || (o[n] = []), o[n].push(r)) : e.push(r);
333
- });
334
- let a = e.map((r) => t(r)).join(`
345
+ const { rules: t } = this, e = {}, r = [];
346
+ return t.forEach((s) => {
347
+ const o = this.getAtRule(s);
348
+ if (o) {
349
+ const i = e[o];
350
+ i ? i.push(s) : e[o] = [s];
351
+ return;
352
+ }
353
+ r.push(this.buildFromRule(s));
354
+ }), this.sortMediaObject(e).forEach((s) => {
355
+ let o = "";
356
+ const i = s.key;
357
+ s.value.forEach((a) => {
358
+ const u = this.buildFromRule(a);
359
+ a.singleAtRule ? r.push(`${i}{${u}}`) : o += u;
360
+ }), o && r.push(`${i}{${o}}`);
361
+ }), r.join(`
335
362
  `);
336
- return Object.keys(o).forEach((r) => {
337
- const n = o[r].map((c) => t(c)).join(`
338
- `);
339
- n && (a += `
340
-
341
- ${r} {
342
- ${n}
343
- }`);
344
- }), a;
345
- }
346
- }
347
- class H {
348
- constructor(t) {
349
- this.symbols = t;
350
- }
351
- getAll() {
352
- return this.symbols;
353
363
  }
354
364
  }
355
365
  class J {
@@ -368,79 +378,48 @@ class K {
368
378
  return this.pages;
369
379
  }
370
380
  }
371
- class _ {
381
+ class G {
372
382
  constructor(t) {
373
- this.assetManager = new q(t.assets || []), this.cssComposer = new G(t.styles || []), this.pages = new K(t.pages || []), this.symbols = new H(t.symbols || []), this.dataSources = new J(t.dataSources || []);
374
- }
375
- getAssetManager() {
376
- return this.assetManager;
377
- }
378
- getCssComposer() {
379
- return this.cssComposer;
380
- }
381
- getPages() {
382
- return this.pages;
383
- }
384
- getSymbols() {
385
- return this.symbols;
386
- }
387
- getDataSources() {
388
- return this.dataSources;
383
+ this.Css = new q(t.styles || []), this.Pages = new K(t.pages || []), this.DataSources = new J(t.dataSources || []);
389
384
  }
390
385
  }
391
- function j(s, t) {
392
- if (s.getId() === t) return s;
393
- for (const e of s.getComponents()) {
394
- const o = j(e, t);
395
- if (o) return o;
386
+ function O(n, t) {
387
+ if (n.id === t) return n;
388
+ for (const e of n.components) {
389
+ const r = O(e, t);
390
+ if (r) return r;
396
391
  }
397
392
  return null;
398
393
  }
399
- function Y(s) {
394
+ const Y = function(n) {
400
395
  var d;
401
- const { config: t, root: e, css: o } = s, a = t.wrapper || T, r = e.getHead(), n = (d = e.getDocEl) == null ? void 0 : d.call(e), c = e.getAttributes().doctype || "<!DOCTYPE html>", p = (n == null ? void 0 : n.tagName) || "html", { skipDocType: l } = t;
402
- return /* @__PURE__ */ S(v, { children: [
403
- l !== void 0 && !l && c,
404
- /* @__PURE__ */ S(p, { children: [
405
- /* @__PURE__ */ u(A, { component: r, config: t, children: /* @__PURE__ */ u("style", { children: `${o}` }) }),
406
- /* @__PURE__ */ u(a, { children: /* @__PURE__ */ u(A, { component: e, config: t }) })
407
- ] })
408
- ] });
409
- }
410
- function y(s, t) {
411
- const e = s ? typeof s == "function" ? s(t) : s : "An error occurred";
412
- return /* @__PURE__ */ u(v, { children: /* @__PURE__ */ u("html", { children: /* @__PURE__ */ u("body", { children: e }) }) });
413
- }
414
- const tt = ({ projectJson: s, config: t = {}, pageId: e, componentId: o }) => {
415
- var i;
416
- const a = new _(s), r = a.getCssComposer().getCssAsString(), n = a.getPages().getAll(), c = { ...O, ...t.errors };
417
- if (!n.length)
418
- return y(c.noPagesFound, { projectJson: s });
419
- const p = e ? n.find((h) => h.getName() === e) : n[0];
420
- if (!p)
421
- return y(c.pageNotFound, { pageId: e });
422
- const l = p.getFrames();
423
- if (!l.length)
424
- return y(c.noFramesFound, { page: p });
425
- const d = (i = l[0]) == null ? void 0 : i.getComponent();
426
- if (!d)
427
- return y(c.missingRootComponent, { frame: l[0] });
428
- if (o) {
429
- const h = j(d, o);
396
+ const { projectData: t, config: e = {}, pageId: r, componentId: s } = n, o = new G(t), i = o.Css.getCssAsString(), c = o.Pages.getAll();
397
+ if (!c.length)
398
+ return /* @__PURE__ */ l(k, { ...n, errorType: m.NoPagesFound });
399
+ const a = r ? c.find((h) => h.id === r) : c[0];
400
+ if (!a)
401
+ return /* @__PURE__ */ l(k, { ...n, errorType: m.PageNotFound });
402
+ const { frames: u } = a;
403
+ if (!u.length)
404
+ return /* @__PURE__ */ l(k, { ...n, errorType: m.NoFramesFound });
405
+ const f = (d = u[0]) == null ? void 0 : d.component;
406
+ if (!f)
407
+ return /* @__PURE__ */ l(k, { ...n, errorType: m.MissingRootComponent });
408
+ if (s) {
409
+ const h = O(f, s);
430
410
  if (!h)
431
- return y(c.componentNotFound, { componentId: o });
411
+ return /* @__PURE__ */ l(k, { ...n, errorType: m.ComponentNotFound });
432
412
  if (h) {
433
- const f = t.wrapper || T;
434
- return /* @__PURE__ */ S(v, { children: [
435
- /* @__PURE__ */ u("style", { children: `${r}` }),
436
- /* @__PURE__ */ u(f, { children: /* @__PURE__ */ u(A, { component: h, config: t }) })
413
+ const g = e.rootComponent || v;
414
+ return /* @__PURE__ */ C(g, { children: [
415
+ /* @__PURE__ */ l("style", { children: `${i}` }),
416
+ /* @__PURE__ */ l(R, { component: h, config: e })
437
417
  ] });
438
418
  }
439
419
  return null;
440
420
  }
441
- return /* @__PURE__ */ u(Y, { config: t, root: d, css: r });
421
+ return /* @__PURE__ */ l(U, { config: e, root: f, css: i });
442
422
  };
443
423
  export {
444
- tt as GrapesJSProject,
445
- A as RenderProjectComponent
424
+ Y as RenderProject
446
425
  };
@@ -1,10 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),S=require("react");function T(s,t,e){const o=s.getId(),a=s.getType(),r=o||void 0;let n;return o?n=o:t?n=`${t}-${e??0}`:a==="head"?n="gjs-head":t==="gjs-head"?n=`${t}-${e??0}`:n=`gjs-${a}`,{key:n,nodeId:r}}const $={noPagesFound:()=>"No pages found in project",pageNotFound:({pageId:s=""})=>`Page not found: ${s}`,noFramesFound:()=>"No frames found in page",missingRootComponent:()=>"Missing root component",componentNotFound:({componentId:s=""})=>`Component not found: ${s}`};function N(s){const t={};let e=!1;for(const o in s)if(Object.prototype.hasOwnProperty.call(s,o)){const a=s[o];if(typeof a=="string"||typeof a=="number"){const r=o.includes("-")?o.replace(/-([a-z])/g,n=>n[1].toUpperCase()):o;t[r]=a,e=!0}}return e?t:void 0}function W(s){const t={};return s.split(";").forEach(e=>{if(!e.trim())return;const o=e.indexOf(":");if(o>0){const a=e.substring(0,o).trim(),r=e.substring(o+1).trim();if(a&&r){const n=a.replace(/-([a-z])/g,l=>l[1].toUpperCase());t[n]=r}}}),Object.keys(t).length>0?t:void 0}function E(s){if(s){if(typeof s=="object"&&!Array.isArray(s))return N(s);if(typeof s=="string"){let t=W(s);if(!t)try{const e=JSON.parse(s);typeof e=="object"&&e!==null&&!Array.isArray(e)&&(t=N(e))}catch(e){console.error("Failed to parse style string as JSON",e)}return t}if(Array.isArray(s)){const t={};return s.forEach(e=>{if(typeof e=="object"&&e!==null){const o=e.name||e.property,a=e.value;if(typeof o=="string"&&o&&a!==void 0&&a!==""){const r=o.replace(/-([a-z])/g,n=>n[1].toUpperCase());t[r]=a}}}),Object.keys(t).length>0?t:void 0}}}function O(s){return R[s]?R[s]:s.includes("-")?s.replace(/-([a-z])/g,(t,e)=>e.toUpperCase()):s}function D(s){var o;const t={},e=((o=s.xmlns)==null?void 0:o.includes("svg"))||s.viewBox!==void 0||s.d!==void 0;for(const[a,r]of Object.entries(s))if(a==="style")t.style=E(r);else if(a.startsWith("data-"))t[a]=r;else{const n=O(a);e||M.has(n)||n.startsWith("svg")?t[n]=r:!I.has(n)&&!n.startsWith("on")&&!n.startsWith("aria-")&&!n.startsWith("data-")?t[`data-${a.toLowerCase()}`]=r:t[n]=r}return t}const I=new Set(["className","id","style","href","src","alt","title","target","rel","type","name","value","placeholder","onClick","onChange","onSubmit","onBlur","onFocus","disabled","readOnly","checked","selected","multiple","width","height","maxLength","min","max","step","rows","cols","autoComplete","autoFocus","required","spellCheck","tabIndex","aria-label","aria-labelledby","aria-describedby","role"]),M=new Set(["x","y","d","cx","cy","r","rx","ry","x1","x2","y1","y2","points","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeOpacity","fillOpacity","fillRule","clipRule","transform","viewBox","preserveAspectRatio","pathLength","vectorEffect","dominantBaseline","alignmentBaseline","textAnchor","fontFamily","fontSize","fontStyle","fontWeight","textDecoration","baselineShift","opacity","mask","clipPath","overflow","pointerEvents"]),R={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","fill-rule":"fillRule","clip-rule":"clipRule","stroke-miterlimit":"strokeMiterlimit","stroke-dasharray":"strokeDasharray","stroke-opacity":"strokeOpacity","fill-opacity":"fillOpacity","font-family":"fontFamily","font-size":"fontSize","text-anchor":"textAnchor"},x=function s(t){var P;const{component:e,config:o,children:a,parentId:r,index:n}=t;if(!e)return null;const l=e.getType()||"",p=e.getContent();if(l==="textnode")return p;const u=(P=o.components)==null?void 0:P[l],i=(u==null?void 0:u.component)||e.getTagName()||"div",h=e.getAttributes(),{key:f,nodeId:k}=T(e,r,n),b=!!(u!=null&&u.component),C=b?h:D(h);b&&Object.keys(C).forEach(m=>{const g=C[m];typeof g=="string"&&!isNaN(Number(g))&&g.trim()!==""&&(C[m]=Number(g))});const A=e.getComponents(),v=[...A.length?A.map((m,g)=>c.jsx(s,{config:o,component:m,parentId:f,index:g},`${m.getId()}-${g}`)):[p],a],w={...C,...k?{id:k}:{}};return b?c.jsx(i,{...w,children:v},f):S.createElement(i,{...w,key:f},e.isVoid()?null:v)};class j{constructor(t){this.data=t}getId(){var t;return(t=this.data.attributes)==null?void 0:t.id}getType(){return this.data.type||"default"}getTagName(){const t=this.getType();return t==="svg"?"svg":t==="image"?"img":t==="linkBox"||t==="link"?"a":t==="head"?"head":t==="wrapper"?"body":this.data.tagName||""}isVoid(){return this.getTagName()==="img"?!0:!!this.data.void}getAttributes(){const t={...this.data.attributes},e=this.getClasses();e.length&&(t.class=e.join(" "));function o(a,r){return Object.prototype.hasOwnProperty.call(a,r)}return o(t,"id")||(t.id=this.getId()),t}getStyle(){return this.data.style||{}}getContent(){return this.data.content||""}getComponents(){return(this.data.components||[]).map(t=>new j(t))}getHead(){return this.data.head?new j(this.data.head):null}getDocEl(){return this.data.docEl}getClasses(){return(this.data.classes||[]).map(e=>typeof e=="string"?e:e.name)}hasClass(t){return this.getClasses().includes(t)}}class B{constructor(t){this.data=t}getComponent(){return this.data.component?new j(this.data.component):null}getWidth(){return this.data.width||""}getHeight(){return this.data.height||""}}class z{constructor(t){this.data=t}getId(){return this.data.id}getName(){return this.data.name||""}getFrames(){return(this.data.frames||[]).map(t=>new B(t))}}class L{constructor(t){this.assets=t}getAll(){return this.assets}}class q{constructor(t){this.rules=t}getAll(){return this.rules}getRulesByGroup(t){return this.rules.filter(e=>e.group===t)}getWrapperRules(){return this.rules.filter(t=>t.wrapper===1)}getCssAsString(){if(!this.rules||!this.rules.length)return"";const t=r=>{if(!r||!r.selectors||!r.style)return"";let n=r.selectors;if(typeof n=="string")n=[n];else if(!Array.isArray(n))return"";const l=n.map(i=>typeof i=="string"&&!i.startsWith(".")&&!i.startsWith("#")&&!i.startsWith("[")&&!i.startsWith(":")&&!i.startsWith(">")&&!i.startsWith("*")&&!i.startsWith("@")?"."+i:i),p=r.state,u=p?l.map(i=>`${i.trim()}:${p}`).join(", "):l.join(""),d=Object.entries(r.style).map(([i,h])=>` ${i}: ${h};`).join(`
2
- `);return d?`${u} {
3
- ${d}
4
- }`:""},e=[],o={};this.rules.forEach(r=>{if(!r||!r.selectors||!r.style)return;const n=r.atRuleType&&r.mediaText?`@${r.atRuleType} ${r.mediaText}`:r.mediaText?`@media ${r.mediaText}`:null;n?(o[n]||(o[n]=[]),o[n].push(r)):e.push(r)});let a=e.map(r=>t(r)).join(`
5
- `);return Object.keys(o).forEach(r=>{const n=o[r].map(l=>t(l)).join(`
6
- `);n&&(a+=`
7
-
8
- ${r} {
9
- ${n}
10
- }`)}),a}}class U{constructor(t){this.symbols=t}getAll(){return this.symbols}}class G{constructor(t){this.list=t}getAll(){return this.list}}class J{constructor(t){this.pages=t.map(e=>new z(e))}getAll(){return this.pages}}class V{constructor(t){this.assetManager=new L(t.assets||[]),this.cssComposer=new q(t.styles||[]),this.pages=new J(t.pages||[]),this.symbols=new U(t.symbols||[]),this.dataSources=new G(t.dataSources||[])}getAssetManager(){return this.assetManager}getCssComposer(){return this.cssComposer}getPages(){return this.pages}getSymbols(){return this.symbols}getDataSources(){return this.dataSources}}function F(s,t){if(s.getId()===t)return s;for(const e of s.getComponents()){const o=F(e,t);if(o)return o}return null}function H(s){var d;const{config:t,root:e,css:o}=s,a=t.wrapper||S.Fragment,r=e.getHead(),n=(d=e.getDocEl)==null?void 0:d.call(e),l=e.getAttributes().doctype||"<!DOCTYPE html>",p=(n==null?void 0:n.tagName)||"html",{skipDocType:u}=t;return c.jsxs(c.Fragment,{children:[u!==void 0&&!u&&l,c.jsxs(p,{children:[c.jsx(x,{component:r,config:t,children:c.jsx("style",{children:`${o}`})}),c.jsx(a,{children:c.jsx(x,{component:e,config:t})})]})]})}function y(s,t){const e=s?typeof s=="function"?s(t):s:"An error occurred";return c.jsx(c.Fragment,{children:c.jsx("html",{children:c.jsx("body",{children:e})})})}const K=({projectJson:s,config:t={},pageId:e,componentId:o})=>{var i;const a=new V(s),r=a.getCssComposer().getCssAsString(),n=a.getPages().getAll(),l={...$,...t.errors};if(!n.length)return y(l.noPagesFound,{projectJson:s});const p=e?n.find(h=>h.getName()===e):n[0];if(!p)return y(l.pageNotFound,{pageId:e});const u=p.getFrames();if(!u.length)return y(l.noFramesFound,{page:p});const d=(i=u[0])==null?void 0:i.getComponent();if(!d)return y(l.missingRootComponent,{frame:u[0]});if(o){const h=F(d,o);if(!h)return y(l.componentNotFound,{componentId:o});if(h){const f=t.wrapper||S.Fragment;return c.jsxs(c.Fragment,{children:[c.jsx("style",{children:`${r}`}),c.jsx(f,{children:c.jsx(x,{component:h,config:t})})]})}return null}return c.jsx(H,{config:t,root:d,css:r})};exports.GrapesJSProject=K;exports.RenderProjectComponent=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),k=require("react");var m=(r=>(r.NoPagesFound="noPagesFound",r.PageNotFound="pageNotFound",r.NoFramesFound="noFramesFound",r.MissingRootComponent="missingRootComponent",r.ComponentNotFound="componentNotFound",r))(m||{});function x(r){const{config:t,errorType:e}=r,s=t==null?void 0:t.errorComponent;return s?a.jsx(s,{...r}):a.jsxs("div",{children:["Error: ",e]})}function P(r){const t={};let e=!1;for(const s in r)if(Object.prototype.hasOwnProperty.call(r,s)){const n=r[s];if(typeof n=="string"||typeof n=="number"){const o=s.includes("-")?s.replace(/-([a-z])/g,i=>i[1].toUpperCase()):s;t[o]=n,e=!0}}return e?t:void 0}function O(r){const t={};return r.split(";").forEach(e=>{if(!e.trim())return;const s=e.indexOf(":");if(s>0){const n=e.substring(0,s).trim(),o=e.substring(s+1).trim();if(n&&o){const i=n.replace(/-([a-z])/g,l=>l[1].toUpperCase());t[i]=o}}}),Object.keys(t).length>0?t:void 0}function T(r){if(r){if(typeof r=="object"&&!Array.isArray(r))return P(r);if(typeof r=="string"){let t=O(r);if(!t)try{const e=JSON.parse(r);typeof e=="object"&&e!==null&&!Array.isArray(e)&&(t=P(e))}catch(e){console.error("Failed to parse style string as JSON",e)}return t}if(Array.isArray(r)){const t={};return r.forEach(e=>{if(typeof e=="object"&&e!==null){const s=e.name||e.property,n=e.value;if(typeof s=="string"&&s&&n!==void 0&&n!==""){const o=s.replace(/-([a-z])/g,i=>i[1].toUpperCase());t[o]=n}}}),Object.keys(t).length>0?t:void 0}}}function D(r){return $[r]?$[r]:r.includes("-")?r.replace(/-([a-z])/g,(t,e)=>e.toUpperCase()):r}function W(r){var e;const t={};for(const[s,n]of Object.entries(r))if(s==="style")t.style=T(n);else if(s.startsWith("data-"))t[s]=n;else{const o=D(s);((e=r.xmlns)==null?void 0:e.includes("svg"))||r.viewBox!==void 0||r.d!==void 0||M.has(o)||o.startsWith("svg")?t[o]=n:!B.has(o)&&!o.startsWith("on")&&!o.startsWith("aria-")&&!o.startsWith("data-")?t[s]=n:t[o]=n}return t}const B=new Set(["className","id","style","href","src","alt","title","target","rel","type","name","value","placeholder","onClick","onChange","onSubmit","onBlur","onFocus","disabled","readOnly","checked","selected","multiple","width","height","maxLength","min","max","step","rows","cols","autoComplete","autoFocus","required","spellCheck","tabIndex","aria-label","aria-labelledby","aria-describedby","role"]),M=new Set(["x","y","d","cx","cy","r","rx","ry","x1","x2","y1","y2","points","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","strokeDasharray","strokeOpacity","fillOpacity","fillRule","clipRule","transform","viewBox","preserveAspectRatio","pathLength","vectorEffect","dominantBaseline","alignmentBaseline","textAnchor","fontFamily","fontSize","fontStyle","fontWeight","textDecoration","baselineShift","opacity","mask","clipPath","overflow","pointerEvents"]),$={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","fill-rule":"fillRule","clip-rule":"clipRule","stroke-miterlimit":"strokeMiterlimit","stroke-dasharray":"strokeDasharray","stroke-opacity":"strokeOpacity","fill-opacity":"fillOpacity","font-family":"fontFamily","font-size":"fontSize","text-anchor":"textAnchor"};function I(r,t,e){const{id:s,type:n}=r,o=s||void 0;let i;return s?i=s:t?i=`${t}-${e??0}`:n==="head"?i="gjs-head":t==="gjs-head"?i=`${t}-${e??0}`:i=`gjs-${n}`,{key:i,nodeId:o}}const v=function r(t){var N;const{component:e,config:s,children:n,parentId:o,index:i}=t;if(!e)return null;const{type:l,content:c}=e;if(l==="textnode")return c;const u=(N=s==null?void 0:s.components)==null?void 0:N[l],d=(u==null?void 0:u.component)||e.tagName||"div",h=e.attributes,{key:g,nodeId:j}=I(e,o,i),C=!!(u!=null&&u.component),A=W(h);C&&Object.keys(A).forEach(y=>{const p=A[y];typeof p=="string"&&!isNaN(Number(p))&&p.trim()!==""&&(A[y]=Number(p))});const{components:R}=e,b=[...R.length?R.map((y,p)=>a.jsx(r,{config:s,component:y,parentId:g,index:p},`${y.id}-${p}`)):[c],n],F={...A,...j?{id:j}:{}};return C?a.jsx(d,{...F,children:b},g):k.createElement(d,{...F,key:g},e.isVoid?null:b)};function z(r){var c;const{config:t,root:e,css:s}=r,n=(t==null?void 0:t.rootComponent)||k.Fragment,o=((c=e.docEl)==null?void 0:c.tagName)||"html",i=(t==null?void 0:t.headAfter)||k.Fragment,l=(t==null?void 0:t.bodyAfter)||k.Fragment;return a.jsx(o,{children:a.jsxs(n,{children:[a.jsxs(v,{component:e.head,config:t,children:[a.jsx("style",{children:`${s}`}),a.jsx(i,{})]}),a.jsx(v,{component:e,config:t,children:a.jsx(l,{})})]})})}class S{constructor(t){this.data=t}get id(){var t;return(t=this.data.attributes)==null?void 0:t.id}get type(){return this.data.type||"default"}get tagName(){const{type:t}=this;return t==="svg"?"svg":t==="image"?"img":t==="linkBox"||t==="link"?"a":t==="head"?"head":t==="wrapper"?"body":this.data.tagName||""}get isVoid(){return this.tagName==="img"?!0:!!this.data.void}get attributes(){const t={...this.data.attributes},{classes:e}=this;e.length&&(t.class=e.join(" "));function s(n,o){return Object.prototype.hasOwnProperty.call(n,o)}return s(t,"id")||(t.id=this.id),t}get content(){return this.data.content||""}get components(){return(this.data.components||[]).map(t=>new S(t))}get head(){return new S(this.data.head||{tagName:"head"})}get docEl(){return this.data.docEl}get classes(){return(this.data.classes||[]).map(e=>typeof e=="string"?e:e.name)}}class L{constructor(t){this.data=t}get component(){return this.data.component?new S(this.data.component):null}}class U{constructor(t){this.data=t}get id(){return this.data.id}get frames(){return(this.data.frames||[]).map(t=>new L(t))}}function w(r){const t=/(-?\d*\.?\d+)\w{0,}/.exec(r);return t?parseFloat(t[1]):Number.MAX_VALUE}class _{constructor(t){this.rules=t}getAll(){return this.rules}getRulesByGroup(t){return this.rules.filter(e=>e.group===t)}getAtRule(t){const{atRuleType:e,mediaText:s}=t,n=e?`@${e}`:s?"@media":"";return n+(s&&n?` ${s}`:"")}selectorsToString(t,e={}){const s=[],{state:n,selectorsAdd:o,selectors:i=[]}=t,l=i.map(u=>this.getFromSelectorName(u)).join(""),c=n&&!e.skipState?`:${n}`:"";return l&&s.push(`${l}${c}`),o&&!e.skipAdd&&s.push(o),s.join(", ")}getFromSelectorName(t=""){return`${t.startsWith("#")?"":"."}${t}`}styleToString(t={}){const e=[],{style:s={},important:n}=t;for(const o in s){const i=Array.isArray(n)?n.indexOf(o)>=0:n;if(o.substring(0,2)==="__")continue;const c=s[o];(Array.isArray(c)?c:[c]).forEach(f=>{const d=`${f}${i?" !important":""}`;d&&e.push(`${o}:${d};`)})}return e.join("")}getDeclaration(t){const{singleAtRule:e}=t,s=this.selectorsToString(t),n=this.styleToString(t);let o="";return(s||e)&&n&&(o=e?n:`${s}{${n}}`),o}buildFromRule(t){let e="";const s=this.selectorsToString(t),{selectorsAdd:n,singleAtRule:o}=t;if(s||n||o){const i=this.getDeclaration(t);i&&(e+=i)}return e}sortMediaObject(t={}){const e=[];for(const s in t){const n=t[s];e.push({key:s,value:n})}return e.sort((s,n)=>{const o=[s.key,n.key].every(c=>c.indexOf("min-width")!==-1),i=o?s.key:n.key,l=o?n.key:s.key;return w(i)-w(l)})}getCssAsString(){if(!this.rules||!this.rules.length)return"";const{rules:t}=this,e={},s=[];return t.forEach(n=>{const o=this.getAtRule(n);if(o){const i=e[o];i?i.push(n):e[o]=[n];return}s.push(this.buildFromRule(n))}),this.sortMediaObject(e).forEach(n=>{let o="";const i=n.key;n.value.forEach(c=>{const u=this.buildFromRule(c);c.singleAtRule?s.push(`${i}{${u}}`):o+=u}),o&&s.push(`${i}{${o}}`)}),s.join(`
2
+ `)}}class q{constructor(t){this.list=t}getAll(){return this.list}}class V{constructor(t){this.pages=t.map(e=>new U(e))}getAll(){return this.pages}}class J{constructor(t){this.Css=new _(t.styles||[]),this.Pages=new V(t.pages||[]),this.DataSources=new q(t.dataSources||[])}}function E(r,t){if(r.id===t)return r;for(const e of r.components){const s=E(e,t);if(s)return s}return null}const K=function(r){var d;const{projectData:t,config:e={},pageId:s,componentId:n}=r,o=new J(t),i=o.Css.getCssAsString(),l=o.Pages.getAll();if(!l.length)return a.jsx(x,{...r,errorType:m.NoPagesFound});const c=s?l.find(h=>h.id===s):l[0];if(!c)return a.jsx(x,{...r,errorType:m.PageNotFound});const{frames:u}=c;if(!u.length)return a.jsx(x,{...r,errorType:m.NoFramesFound});const f=(d=u[0])==null?void 0:d.component;if(!f)return a.jsx(x,{...r,errorType:m.MissingRootComponent});if(n){const h=E(f,n);if(!h)return a.jsx(x,{...r,errorType:m.ComponentNotFound});if(h){const g=e.rootComponent||k.Fragment;return a.jsxs(g,{children:[a.jsx("style",{children:`${i}`}),a.jsx(v,{component:h,config:e})]})}return null}return a.jsx(z,{config:e,root:f,css:i})};exports.RenderProject=K;