@pixldocs/canvas-renderer 0.3.9 → 0.3.10
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 +67 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +67 -49
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -8575,6 +8575,47 @@ const PreviewCanvas$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.def
|
|
|
8575
8575
|
__proto__: null,
|
|
8576
8576
|
PreviewCanvas
|
|
8577
8577
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
8578
|
+
function applyThemeToConfig(config, themeOverrides) {
|
|
8579
|
+
var _a, _b, _c;
|
|
8580
|
+
if (!themeOverrides || Object.keys(themeOverrides).length === 0) return config;
|
|
8581
|
+
const cloned = JSON.parse(JSON.stringify(config));
|
|
8582
|
+
if ((_a = cloned.themeConfig) == null ? void 0 : _a.variables) {
|
|
8583
|
+
for (const [key, value] of Object.entries(themeOverrides)) {
|
|
8584
|
+
if (cloned.themeConfig.variables[key]) {
|
|
8585
|
+
cloned.themeConfig.variables[key].value = value;
|
|
8586
|
+
}
|
|
8587
|
+
}
|
|
8588
|
+
}
|
|
8589
|
+
const varMap = /* @__PURE__ */ new Map();
|
|
8590
|
+
if ((_b = cloned.themeConfig) == null ? void 0 : _b.variables) {
|
|
8591
|
+
for (const [key, def] of Object.entries(cloned.themeConfig.variables)) {
|
|
8592
|
+
varMap.set(key, themeOverrides[key] ?? def.value);
|
|
8593
|
+
}
|
|
8594
|
+
}
|
|
8595
|
+
function walkAndApply(nodes) {
|
|
8596
|
+
if (!nodes) return;
|
|
8597
|
+
for (const node of nodes) {
|
|
8598
|
+
const bindings = node.themeBindings;
|
|
8599
|
+
if (bindings) {
|
|
8600
|
+
for (const [prop, varName] of Object.entries(bindings)) {
|
|
8601
|
+
const value = varMap.get(varName);
|
|
8602
|
+
if (value !== void 0) {
|
|
8603
|
+
node[prop] = value;
|
|
8604
|
+
}
|
|
8605
|
+
}
|
|
8606
|
+
}
|
|
8607
|
+
if (node.children) walkAndApply(node.children);
|
|
8608
|
+
}
|
|
8609
|
+
}
|
|
8610
|
+
for (const page of cloned.pages || []) {
|
|
8611
|
+
const bgBinding = (_c = page.themeBindings) == null ? void 0 : _c.backgroundColor;
|
|
8612
|
+
if (bgBinding && varMap.has(bgBinding) && page.settings) {
|
|
8613
|
+
page.settings.backgroundColor = varMap.get(bgBinding);
|
|
8614
|
+
}
|
|
8615
|
+
walkAndApply(page.children || []);
|
|
8616
|
+
}
|
|
8617
|
+
return cloned;
|
|
8618
|
+
}
|
|
8578
8619
|
function mapFormDefFieldType(t) {
|
|
8579
8620
|
if (["text", "email", "tel", "textarea", "date", "url", "number", "toggle", "color", "image"].includes(t)) return t;
|
|
8580
8621
|
if (t === "currency") return "number";
|
|
@@ -10055,7 +10096,7 @@ async function resolveTemplateData(options) {
|
|
|
10055
10096
|
return { config, templateName: template.name || "Untitled", templateId };
|
|
10056
10097
|
}
|
|
10057
10098
|
async function resolveFromForm(options) {
|
|
10058
|
-
var _a, _b, _c, _d, _e;
|
|
10099
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10059
10100
|
const { templateId, formSchemaId, sectionState, themeId, supabaseUrl, supabaseAnonKey } = options;
|
|
10060
10101
|
const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
|
|
10061
10102
|
fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
|
|
@@ -10180,13 +10221,21 @@ async function resolveFromForm(options) {
|
|
|
10180
10221
|
Object.keys(repeatableNestedEntryCounts).length > 0 ? repeatableNestedEntryCounts : void 0,
|
|
10181
10222
|
displayFormatMap.size > 0 ? displayFormatMap : void 0
|
|
10182
10223
|
);
|
|
10183
|
-
if (
|
|
10224
|
+
if ((_d = resolvedConfig.themeConfig) == null ? void 0 : _d.variables) {
|
|
10225
|
+
const baseOverrides = {};
|
|
10226
|
+
for (const [key, def] of Object.entries(resolvedConfig.themeConfig.variables)) {
|
|
10227
|
+
baseOverrides[key] = def.value;
|
|
10228
|
+
}
|
|
10229
|
+
resolvedConfig = applyThemeToConfig(resolvedConfig, baseOverrides);
|
|
10230
|
+
}
|
|
10231
|
+
if (templateConfig.themeConfig) {
|
|
10184
10232
|
const tc = templateConfig.themeConfig;
|
|
10185
|
-
const variant = (
|
|
10186
|
-
|
|
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) {
|
|
10187
10236
|
const themed = JSON.parse(JSON.stringify(resolvedConfig));
|
|
10188
10237
|
for (const prop of tc.properties) {
|
|
10189
|
-
const value = (
|
|
10238
|
+
const value = variant ? (_g = variant.values) == null ? void 0 : _g[prop.id] : prop.defaultValue;
|
|
10190
10239
|
if (value === void 0) continue;
|
|
10191
10240
|
if (prop.targetProperty === "backgroundColor" && prop.elementId === "__pageBackground__") {
|
|
10192
10241
|
themed.pages.forEach((p) => {
|
|
@@ -10392,20 +10441,30 @@ async function loadGoogleFontCSS(rawFontFamily) {
|
|
|
10392
10441
|
loadingPromises.delete(fontFamily);
|
|
10393
10442
|
}
|
|
10394
10443
|
function collectFontsFromConfig(config) {
|
|
10444
|
+
var _a;
|
|
10395
10445
|
const fonts = /* @__PURE__ */ new Set();
|
|
10396
10446
|
fonts.add("Open Sans");
|
|
10397
10447
|
function walk(nodes) {
|
|
10398
|
-
var
|
|
10448
|
+
var _a2;
|
|
10399
10449
|
if (!nodes) return;
|
|
10400
10450
|
for (const node of nodes) {
|
|
10401
|
-
if (node.fontFamily) fonts.add(node.fontFamily);
|
|
10402
|
-
if ((
|
|
10451
|
+
if (node.fontFamily) fonts.add(normalizeFontFamily(node.fontFamily));
|
|
10452
|
+
if ((_a2 = node.smartProps) == null ? void 0 : _a2.fontFamily) fonts.add(normalizeFontFamily(node.smartProps.fontFamily));
|
|
10403
10453
|
if (node.children) walk(node.children);
|
|
10404
10454
|
}
|
|
10405
10455
|
}
|
|
10406
10456
|
for (const page of config.pages || []) {
|
|
10407
10457
|
walk(page.children || []);
|
|
10408
10458
|
}
|
|
10459
|
+
if ((_a = config.themeConfig) == null ? void 0 : _a.variables) {
|
|
10460
|
+
for (const def of Object.values(config.themeConfig.variables)) {
|
|
10461
|
+
if (def.value && typeof def.value === "string" && !def.value.startsWith("#") && !def.value.startsWith("rgb")) {
|
|
10462
|
+
if (def.label && /font/i.test(def.label)) {
|
|
10463
|
+
fonts.add(normalizeFontFamily(def.value));
|
|
10464
|
+
}
|
|
10465
|
+
}
|
|
10466
|
+
}
|
|
10467
|
+
}
|
|
10409
10468
|
return fonts;
|
|
10410
10469
|
}
|
|
10411
10470
|
class PixldocsRenderer {
|
|
@@ -10653,47 +10712,6 @@ class PixldocsRenderer {
|
|
|
10653
10712
|
});
|
|
10654
10713
|
}
|
|
10655
10714
|
}
|
|
10656
|
-
function applyThemeToConfig(config, themeOverrides) {
|
|
10657
|
-
var _a, _b, _c;
|
|
10658
|
-
if (!themeOverrides || Object.keys(themeOverrides).length === 0) return config;
|
|
10659
|
-
const cloned = JSON.parse(JSON.stringify(config));
|
|
10660
|
-
if ((_a = cloned.themeConfig) == null ? void 0 : _a.variables) {
|
|
10661
|
-
for (const [key, value] of Object.entries(themeOverrides)) {
|
|
10662
|
-
if (cloned.themeConfig.variables[key]) {
|
|
10663
|
-
cloned.themeConfig.variables[key].value = value;
|
|
10664
|
-
}
|
|
10665
|
-
}
|
|
10666
|
-
}
|
|
10667
|
-
const varMap = /* @__PURE__ */ new Map();
|
|
10668
|
-
if ((_b = cloned.themeConfig) == null ? void 0 : _b.variables) {
|
|
10669
|
-
for (const [key, def] of Object.entries(cloned.themeConfig.variables)) {
|
|
10670
|
-
varMap.set(key, themeOverrides[key] ?? def.value);
|
|
10671
|
-
}
|
|
10672
|
-
}
|
|
10673
|
-
function walkAndApply(nodes) {
|
|
10674
|
-
if (!nodes) return;
|
|
10675
|
-
for (const node of nodes) {
|
|
10676
|
-
const bindings = node.themeBindings;
|
|
10677
|
-
if (bindings) {
|
|
10678
|
-
for (const [prop, varName] of Object.entries(bindings)) {
|
|
10679
|
-
const value = varMap.get(varName);
|
|
10680
|
-
if (value !== void 0) {
|
|
10681
|
-
node[prop] = value;
|
|
10682
|
-
}
|
|
10683
|
-
}
|
|
10684
|
-
}
|
|
10685
|
-
if (node.children) walkAndApply(node.children);
|
|
10686
|
-
}
|
|
10687
|
-
}
|
|
10688
|
-
for (const page of cloned.pages || []) {
|
|
10689
|
-
const bgBinding = (_c = page.themeBindings) == null ? void 0 : _c.backgroundColor;
|
|
10690
|
-
if (bgBinding && varMap.has(bgBinding) && page.settings) {
|
|
10691
|
-
page.settings.backgroundColor = varMap.get(bgBinding);
|
|
10692
|
-
}
|
|
10693
|
-
walkAndApply(page.children || []);
|
|
10694
|
-
}
|
|
10695
|
-
return cloned;
|
|
10696
|
-
}
|
|
10697
10715
|
exports.PixldocsPreview = PixldocsPreview;
|
|
10698
10716
|
exports.PixldocsRenderer = PixldocsRenderer;
|
|
10699
10717
|
exports.applyThemeToConfig = applyThemeToConfig;
|