@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.js CHANGED
@@ -10077,7 +10077,7 @@ async function resolveTemplateData(options) {
10077
10077
  return { config, templateName: template.name || "Untitled", templateId };
10078
10078
  }
10079
10079
  async function resolveFromForm(options) {
10080
- var _a, _b, _c, _d, _e, _f, _g;
10080
+ var _a, _b, _c, _d;
10081
10081
  const { templateId, formSchemaId, sectionState, themeId, supabaseUrl, supabaseAnonKey } = options;
10082
10082
  const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
10083
10083
  fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
@@ -10209,37 +10209,8 @@ async function resolveFromForm(options) {
10209
10209
  }
10210
10210
  resolvedConfig = applyThemeToConfig(resolvedConfig, baseOverrides);
10211
10211
  }
10212
- if (templateConfig.themeConfig) {
10213
- const tc = templateConfig.themeConfig;
10214
- const variant = themeId && themeId !== "default" ? (_e = tc.variants) == null ? void 0 : _e.find((v) => v.id === themeId) : null;
10215
- const shouldApplyDefaults = !variant && ((_f = tc.properties) == null ? void 0 : _f.length);
10216
- if ((variant || shouldApplyDefaults) && tc.properties) {
10217
- const themed = JSON.parse(JSON.stringify(resolvedConfig));
10218
- for (const prop of tc.properties) {
10219
- const value = variant ? (_g = variant.values) == null ? void 0 : _g[prop.id] : prop.defaultValue;
10220
- if (value === void 0) continue;
10221
- if (prop.targetProperty === "backgroundColor" && prop.elementId === "__pageBackground__") {
10222
- themed.pages.forEach((p) => {
10223
- p.settings.backgroundColor = value;
10224
- });
10225
- continue;
10226
- }
10227
- for (const page of themed.pages) {
10228
- const els = flattenAll(page.children || []);
10229
- for (const el of els) {
10230
- if (el.id === prop.elementId || baseId(el.id) === baseId(prop.elementId)) {
10231
- if (prop.svgColorKey && el.svgColorMap) {
10232
- el.svgColorMap = { ...el.svgColorMap, [prop.svgColorKey]: value };
10233
- } else {
10234
- el[prop.targetProperty] = value;
10235
- }
10236
- }
10237
- }
10238
- }
10239
- }
10240
- resolvedConfig = themed;
10241
- }
10242
- }
10212
+ resolvedConfig = applyThemeVariantToConfig(resolvedConfig, templateConfig.themeConfig, themeId);
10213
+ normalizeConfigForEC2Parity(resolvedConfig);
10243
10214
  resolvedConfig = applyContentBoundsPagination(resolvedConfig);
10244
10215
  return {
10245
10216
  config: resolvedConfig,
@@ -10255,6 +10226,101 @@ function flattenAll(nodes) {
10255
10226
  }
10256
10227
  return result;
10257
10228
  }
10229
+ function themeBaseId(id) {
10230
+ if (!id) return id ?? "";
10231
+ let out = id;
10232
+ out = out.replace(/_inner\d+_\d+_/g, "");
10233
+ out = out.replace(/_clone\d+_/g, "");
10234
+ out = out.replace(/_clone_\d+/g, "");
10235
+ while (/_\d+$/.test(out)) out = out.replace(/_\d+$/, "");
10236
+ return out;
10237
+ }
10238
+ function applyThemeVariantToConfig(config, themeConfig, themeId) {
10239
+ var _a, _b, _c, _d;
10240
+ if (!themeConfig) return config;
10241
+ const variant = themeId && themeId !== "default" ? (_a = themeConfig.variants) == null ? void 0 : _a.find((v) => v.id === themeId) : null;
10242
+ const shouldApplyDefaults = !variant && ((_b = themeConfig.properties) == null ? void 0 : _b.length);
10243
+ if (!variant && !shouldApplyDefaults) return config;
10244
+ if (!((_c = themeConfig.properties) == null ? void 0 : _c.length)) return config;
10245
+ const result = JSON.parse(JSON.stringify(config));
10246
+ const cloneIdMap = config.__cloneIdMap || {};
10247
+ const pageElements = result.pages.map((page) => flattenAll(page.children || []));
10248
+ for (const prop of themeConfig.properties) {
10249
+ const value = variant ? (_d = variant.values) == null ? void 0 : _d[prop.id] : prop.defaultValue;
10250
+ if (value === void 0) continue;
10251
+ if (prop.targetProperty === "backgroundColor" && prop.elementId === "__pageBackground__") {
10252
+ result.pages.forEach((p) => {
10253
+ p.settings.backgroundColor = value;
10254
+ });
10255
+ continue;
10256
+ }
10257
+ if (prop.targetProperty === "backgroundGradient" && prop.elementId === "__pageBackground__" && prop.svgColorKey) {
10258
+ const stopMatch = prop.svgColorKey.match(/^stop:(\d+)$/);
10259
+ if (stopMatch) {
10260
+ const stopIndex = parseInt(stopMatch[1], 10);
10261
+ result.pages.forEach((p) => {
10262
+ var _a2, _b2;
10263
+ if ((_b2 = (_a2 = p.settings.backgroundGradient) == null ? void 0 : _a2.stops) == null ? void 0 : _b2[stopIndex]) {
10264
+ p.settings.backgroundGradient = {
10265
+ ...p.settings.backgroundGradient,
10266
+ stops: p.settings.backgroundGradient.stops.map(
10267
+ (s, i) => i === stopIndex ? { ...s, color: value } : s
10268
+ )
10269
+ };
10270
+ }
10271
+ });
10272
+ }
10273
+ continue;
10274
+ }
10275
+ const propBase = themeBaseId(prop.elementId);
10276
+ const targetIds = /* @__PURE__ */ new Set([prop.elementId, propBase]);
10277
+ for (const [mapKey, mappedId] of Object.entries(cloneIdMap)) {
10278
+ if (mapKey.endsWith(`_${prop.elementId}`) || mapKey.endsWith(`_${propBase}`)) {
10279
+ targetIds.add(mappedId);
10280
+ }
10281
+ }
10282
+ for (const els of pageElements) {
10283
+ for (const el of els) {
10284
+ const elBase = themeBaseId(el.id);
10285
+ const sourceId = el.__sourceId;
10286
+ const sourceBase = sourceId ? themeBaseId(sourceId) : void 0;
10287
+ const cloneBase = el.__baseNodeId;
10288
+ const cloneBaseNorm = cloneBase ? themeBaseId(cloneBase) : void 0;
10289
+ 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);
10290
+ if (!match) continue;
10291
+ if (prop.svgColorKey && el.svgColorMap) {
10292
+ el.svgColorMap = { ...el.svgColorMap, [prop.svgColorKey]: value };
10293
+ } else {
10294
+ el[prop.targetProperty] = value;
10295
+ }
10296
+ }
10297
+ }
10298
+ }
10299
+ return result;
10300
+ }
10301
+ function normalizeConfigForEC2Parity(config) {
10302
+ function walk(node) {
10303
+ if (node.layoutMode === "stack" || node.layoutMode === "stacked") {
10304
+ node.layoutMode = "vertical-stack";
10305
+ }
10306
+ const layoutMode = String(node.layoutMode ?? "");
10307
+ const isStack = isVerticalStackLayoutMode(layoutMode) || layoutMode === "horizontal-stack" || layoutMode === "horizontal-fill";
10308
+ if (isStack && node.stackSpacing == null) node.stackSpacing = 8;
10309
+ if (node.type === "text") {
10310
+ const overflowPolicy = String(node.overflowPolicy ?? "grow-and-push");
10311
+ const fontSize = typeof node.fontSize === "number" ? node.fontSize : 16;
10312
+ if (overflowPolicy === "auto-shrink" && fontSize >= 24) node.overflowPolicy = "grow-and-push";
10313
+ delete node.height;
10314
+ }
10315
+ if (Array.isArray(node.children)) {
10316
+ delete node.height;
10317
+ for (const child of node.children) walk(child);
10318
+ }
10319
+ }
10320
+ for (const page of config.pages ?? []) {
10321
+ for (const child of page.children ?? []) walk(child);
10322
+ }
10323
+ }
10258
10324
  function normalizeLayoutModes(config) {
10259
10325
  function walk(node) {
10260
10326
  if (node.layoutMode === "stack" || node.layoutMode === "stacked") {
@@ -10396,9 +10462,8 @@ async function loadGoogleFontCSS(rawFontFamily) {
10396
10462
  loadedFonts.add(fontFamily);
10397
10463
  return;
10398
10464
  }
10399
- const weights = "100;200;300;400;500;600;700;800;900";
10400
10465
  const encoded = encodeURIComponent(fontFamily);
10401
- const url = `https://fonts.googleapis.com/css2?family=${encoded}:ital,wght@0,${weights};1,${weights}&display=swap`;
10466
+ const url = `https://fonts.googleapis.com/css?family=${encoded}:300,400,500,600,700&display=swap`;
10402
10467
  const link = document.createElement("link");
10403
10468
  link.rel = "stylesheet";
10404
10469
  link.href = url;