@pixldocs/canvas-renderer 0.3.10 → 0.3.12

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/dist/index.cjs CHANGED
@@ -10096,7 +10096,7 @@ async function resolveTemplateData(options) {
10096
10096
  return { config, templateName: template.name || "Untitled", templateId };
10097
10097
  }
10098
10098
  async function resolveFromForm(options) {
10099
- var _a, _b, _c, _d, _e, _f, _g;
10099
+ var _a, _b, _c, _d;
10100
10100
  const { templateId, formSchemaId, sectionState, themeId, supabaseUrl, supabaseAnonKey } = options;
10101
10101
  const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
10102
10102
  fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
@@ -10228,37 +10228,8 @@ async function resolveFromForm(options) {
10228
10228
  }
10229
10229
  resolvedConfig = applyThemeToConfig(resolvedConfig, baseOverrides);
10230
10230
  }
10231
- if (templateConfig.themeConfig) {
10232
- const tc = templateConfig.themeConfig;
10233
- const variant = themeId && themeId !== "default" ? (_e = tc.variants) == null ? void 0 : _e.find((v) => v.id === themeId) : null;
10234
- const shouldApplyDefaults = !variant && ((_f = tc.properties) == null ? void 0 : _f.length);
10235
- if ((variant || shouldApplyDefaults) && tc.properties) {
10236
- const themed = JSON.parse(JSON.stringify(resolvedConfig));
10237
- for (const prop of tc.properties) {
10238
- const value = variant ? (_g = variant.values) == null ? void 0 : _g[prop.id] : prop.defaultValue;
10239
- if (value === void 0) continue;
10240
- if (prop.targetProperty === "backgroundColor" && prop.elementId === "__pageBackground__") {
10241
- themed.pages.forEach((p) => {
10242
- p.settings.backgroundColor = value;
10243
- });
10244
- continue;
10245
- }
10246
- for (const page of themed.pages) {
10247
- const els = flattenAll(page.children || []);
10248
- for (const el of els) {
10249
- if (el.id === prop.elementId || baseId(el.id) === baseId(prop.elementId)) {
10250
- if (prop.svgColorKey && el.svgColorMap) {
10251
- el.svgColorMap = { ...el.svgColorMap, [prop.svgColorKey]: value };
10252
- } else {
10253
- el[prop.targetProperty] = value;
10254
- }
10255
- }
10256
- }
10257
- }
10258
- }
10259
- resolvedConfig = themed;
10260
- }
10261
- }
10231
+ resolvedConfig = applyThemeVariantToConfig(resolvedConfig, templateConfig.themeConfig, themeId);
10232
+ normalizeConfigForEC2Parity(resolvedConfig);
10262
10233
  resolvedConfig = applyContentBoundsPagination(resolvedConfig);
10263
10234
  return {
10264
10235
  config: resolvedConfig,
@@ -10274,6 +10245,101 @@ function flattenAll(nodes) {
10274
10245
  }
10275
10246
  return result;
10276
10247
  }
10248
+ function themeBaseId(id) {
10249
+ if (!id) return id ?? "";
10250
+ let out = id;
10251
+ out = out.replace(/_inner\d+_\d+_/g, "");
10252
+ out = out.replace(/_clone\d+_/g, "");
10253
+ out = out.replace(/_clone_\d+/g, "");
10254
+ while (/_\d+$/.test(out)) out = out.replace(/_\d+$/, "");
10255
+ return out;
10256
+ }
10257
+ function applyThemeVariantToConfig(config, themeConfig, themeId) {
10258
+ var _a, _b, _c, _d;
10259
+ if (!themeConfig) return config;
10260
+ const variant = themeId && themeId !== "default" ? (_a = themeConfig.variants) == null ? void 0 : _a.find((v) => v.id === themeId) : null;
10261
+ const shouldApplyDefaults = !variant && ((_b = themeConfig.properties) == null ? void 0 : _b.length);
10262
+ if (!variant && !shouldApplyDefaults) return config;
10263
+ if (!((_c = themeConfig.properties) == null ? void 0 : _c.length)) return config;
10264
+ const result = JSON.parse(JSON.stringify(config));
10265
+ const cloneIdMap = config.__cloneIdMap || {};
10266
+ const pageElements = result.pages.map((page) => flattenAll(page.children || []));
10267
+ for (const prop of themeConfig.properties) {
10268
+ const value = variant ? (_d = variant.values) == null ? void 0 : _d[prop.id] : prop.defaultValue;
10269
+ if (value === void 0) continue;
10270
+ if (prop.targetProperty === "backgroundColor" && prop.elementId === "__pageBackground__") {
10271
+ result.pages.forEach((p) => {
10272
+ p.settings.backgroundColor = value;
10273
+ });
10274
+ continue;
10275
+ }
10276
+ if (prop.targetProperty === "backgroundGradient" && prop.elementId === "__pageBackground__" && prop.svgColorKey) {
10277
+ const stopMatch = prop.svgColorKey.match(/^stop:(\d+)$/);
10278
+ if (stopMatch) {
10279
+ const stopIndex = parseInt(stopMatch[1], 10);
10280
+ result.pages.forEach((p) => {
10281
+ var _a2, _b2;
10282
+ if ((_b2 = (_a2 = p.settings.backgroundGradient) == null ? void 0 : _a2.stops) == null ? void 0 : _b2[stopIndex]) {
10283
+ p.settings.backgroundGradient = {
10284
+ ...p.settings.backgroundGradient,
10285
+ stops: p.settings.backgroundGradient.stops.map(
10286
+ (s, i) => i === stopIndex ? { ...s, color: value } : s
10287
+ )
10288
+ };
10289
+ }
10290
+ });
10291
+ }
10292
+ continue;
10293
+ }
10294
+ const propBase = themeBaseId(prop.elementId);
10295
+ const targetIds = /* @__PURE__ */ new Set([prop.elementId, propBase]);
10296
+ for (const [mapKey, mappedId] of Object.entries(cloneIdMap)) {
10297
+ if (mapKey.endsWith(`_${prop.elementId}`) || mapKey.endsWith(`_${propBase}`)) {
10298
+ targetIds.add(mappedId);
10299
+ }
10300
+ }
10301
+ for (const els of pageElements) {
10302
+ for (const el of els) {
10303
+ const elBase = themeBaseId(el.id);
10304
+ const sourceId = el.__sourceId;
10305
+ const sourceBase = sourceId ? themeBaseId(sourceId) : void 0;
10306
+ const cloneBase = el.__baseNodeId;
10307
+ const cloneBaseNorm = cloneBase ? themeBaseId(cloneBase) : void 0;
10308
+ const match = targetIds.has(el.id) || targetIds.has(elBase) || (sourceId ? targetIds.has(sourceId) : false) || (sourceBase ? targetIds.has(sourceBase) : false) || (cloneBase ? targetIds.has(cloneBase) : false) || (cloneBaseNorm ? targetIds.has(cloneBaseNorm) : false);
10309
+ if (!match) continue;
10310
+ if (prop.svgColorKey && el.svgColorMap) {
10311
+ el.svgColorMap = { ...el.svgColorMap, [prop.svgColorKey]: value };
10312
+ } else {
10313
+ el[prop.targetProperty] = value;
10314
+ }
10315
+ }
10316
+ }
10317
+ }
10318
+ return result;
10319
+ }
10320
+ function normalizeConfigForEC2Parity(config) {
10321
+ function walk(node) {
10322
+ if (node.layoutMode === "stack" || node.layoutMode === "stacked") {
10323
+ node.layoutMode = "vertical-stack";
10324
+ }
10325
+ const layoutMode = String(node.layoutMode ?? "");
10326
+ const isStack = isVerticalStackLayoutMode(layoutMode) || layoutMode === "horizontal-stack" || layoutMode === "horizontal-fill";
10327
+ if (isStack && node.stackSpacing == null) node.stackSpacing = 8;
10328
+ if (node.type === "text") {
10329
+ const overflowPolicy = String(node.overflowPolicy ?? "grow-and-push");
10330
+ const fontSize = typeof node.fontSize === "number" ? node.fontSize : 16;
10331
+ if (overflowPolicy === "auto-shrink" && fontSize >= 24) node.overflowPolicy = "grow-and-push";
10332
+ delete node.height;
10333
+ }
10334
+ if (Array.isArray(node.children)) {
10335
+ delete node.height;
10336
+ for (const child of node.children) walk(child);
10337
+ }
10338
+ }
10339
+ for (const page of config.pages ?? []) {
10340
+ for (const child of page.children ?? []) walk(child);
10341
+ }
10342
+ }
10277
10343
  function normalizeLayoutModes(config) {
10278
10344
  function walk(node) {
10279
10345
  if (node.layoutMode === "stack" || node.layoutMode === "stacked") {
@@ -10415,9 +10481,8 @@ async function loadGoogleFontCSS(rawFontFamily) {
10415
10481
  loadedFonts.add(fontFamily);
10416
10482
  return;
10417
10483
  }
10418
- const weights = "100;200;300;400;500;600;700;800;900";
10419
10484
  const encoded = encodeURIComponent(fontFamily);
10420
- const url = `https://fonts.googleapis.com/css2?family=${encoded}:ital,wght@0,${weights};1,${weights}&display=swap`;
10485
+ const url = `https://fonts.googleapis.com/css?family=${encoded}:300,400,500,600,700&display=swap`;
10421
10486
  const link = document.createElement("link");
10422
10487
  link.rel = "stylesheet";
10423
10488
  link.href = url;