@pixldocs/canvas-renderer 0.3.8 → 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 +129 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +129 -53
- 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),
|
|
@@ -10064,8 +10105,20 @@ async function resolveFromForm(options) {
|
|
|
10064
10105
|
]);
|
|
10065
10106
|
const templateConfig = templateRow.config;
|
|
10066
10107
|
const templateFormSchema = templateRow.form_schema;
|
|
10067
|
-
|
|
10108
|
+
if (templateFormSchema) {
|
|
10109
|
+
if (!Array.isArray(templateConfig.dynamicFields) && Array.isArray(templateFormSchema.dynamicFields)) {
|
|
10110
|
+
templateConfig.dynamicFields = templateFormSchema.dynamicFields;
|
|
10111
|
+
}
|
|
10112
|
+
if (!Array.isArray(templateConfig.fieldGroups) && Array.isArray(templateFormSchema.fieldGroups)) {
|
|
10113
|
+
templateConfig.fieldGroups = templateFormSchema.fieldGroups;
|
|
10114
|
+
}
|
|
10115
|
+
}
|
|
10116
|
+
normalizeLayoutModes(templateConfig);
|
|
10068
10117
|
const repeatableFromSchema = templateFormSchema == null ? void 0 : templateFormSchema.repeatableSections;
|
|
10118
|
+
if ((repeatableFromSchema == null ? void 0 : repeatableFromSchema.length) && templateConfig.pages) {
|
|
10119
|
+
paintRepeatableSections(templateConfig, repeatableFromSchema);
|
|
10120
|
+
}
|
|
10121
|
+
const schemaSections = (_a = formSchemaRow.schema) == null ? void 0 : _a.sections;
|
|
10069
10122
|
const repeatableNodeMap = /* @__PURE__ */ new Map();
|
|
10070
10123
|
if (repeatableFromSchema) {
|
|
10071
10124
|
for (const r of repeatableFromSchema) {
|
|
@@ -10097,9 +10150,7 @@ async function resolveFromForm(options) {
|
|
|
10097
10150
|
}
|
|
10098
10151
|
}
|
|
10099
10152
|
const flatFormData = flattenSectionStateToFormData(mergedSectionState, inferredSections);
|
|
10100
|
-
const
|
|
10101
|
-
const formSchemaDynamicFields = templateFormSchema == null ? void 0 : templateFormSchema.dynamicFields;
|
|
10102
|
-
const dynamicFields = ((configDynamicFields == null ? void 0 : configDynamicFields.length) ? configDynamicFields : formSchemaDynamicFields) || [];
|
|
10153
|
+
const dynamicFields = templateConfig.dynamicFields || [];
|
|
10103
10154
|
const mappings = [];
|
|
10104
10155
|
for (const field of dynamicFields) {
|
|
10105
10156
|
if (field.mappings) {
|
|
@@ -10170,13 +10221,21 @@ async function resolveFromForm(options) {
|
|
|
10170
10221
|
Object.keys(repeatableNestedEntryCounts).length > 0 ? repeatableNestedEntryCounts : void 0,
|
|
10171
10222
|
displayFormatMap.size > 0 ? displayFormatMap : void 0
|
|
10172
10223
|
);
|
|
10173
|
-
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) {
|
|
10174
10232
|
const tc = templateConfig.themeConfig;
|
|
10175
|
-
const variant = (
|
|
10176
|
-
|
|
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) {
|
|
10177
10236
|
const themed = JSON.parse(JSON.stringify(resolvedConfig));
|
|
10178
10237
|
for (const prop of tc.properties) {
|
|
10179
|
-
const value = (
|
|
10238
|
+
const value = variant ? (_g = variant.values) == null ? void 0 : _g[prop.id] : prop.defaultValue;
|
|
10180
10239
|
if (value === void 0) continue;
|
|
10181
10240
|
if (prop.targetProperty === "backgroundColor" && prop.elementId === "__pageBackground__") {
|
|
10182
10241
|
themed.pages.forEach((p) => {
|
|
@@ -10215,6 +10274,54 @@ function flattenAll(nodes) {
|
|
|
10215
10274
|
}
|
|
10216
10275
|
return result;
|
|
10217
10276
|
}
|
|
10277
|
+
function normalizeLayoutModes(config) {
|
|
10278
|
+
function walk(node) {
|
|
10279
|
+
if (node.layoutMode === "stack" || node.layoutMode === "stacked") {
|
|
10280
|
+
node.layoutMode = "vertical-stack";
|
|
10281
|
+
}
|
|
10282
|
+
if (Array.isArray(node.children)) {
|
|
10283
|
+
for (const child of node.children) walk(child);
|
|
10284
|
+
}
|
|
10285
|
+
}
|
|
10286
|
+
for (const page of config.pages ?? []) {
|
|
10287
|
+
if (page.children) {
|
|
10288
|
+
for (const child of page.children) walk(child);
|
|
10289
|
+
}
|
|
10290
|
+
}
|
|
10291
|
+
}
|
|
10292
|
+
function paintRepeatableSections(config, repeatableSections) {
|
|
10293
|
+
const pages = config.pages ?? [];
|
|
10294
|
+
function stripFlags(nodes) {
|
|
10295
|
+
for (const node of nodes) {
|
|
10296
|
+
delete node.repeatableSection;
|
|
10297
|
+
if (Array.isArray(node.children)) stripFlags(node.children);
|
|
10298
|
+
}
|
|
10299
|
+
}
|
|
10300
|
+
for (const page of pages) {
|
|
10301
|
+
if (page.children) stripFlags(page.children);
|
|
10302
|
+
}
|
|
10303
|
+
function setRepeatable(nodes, nodeId, payload) {
|
|
10304
|
+
for (const node of nodes) {
|
|
10305
|
+
const id = node.id;
|
|
10306
|
+
if (id && (id === nodeId || baseId(id) === baseId(nodeId))) {
|
|
10307
|
+
node.repeatableSection = payload;
|
|
10308
|
+
return true;
|
|
10309
|
+
}
|
|
10310
|
+
if (Array.isArray(node.children) && setRepeatable(node.children, nodeId, payload)) {
|
|
10311
|
+
return true;
|
|
10312
|
+
}
|
|
10313
|
+
}
|
|
10314
|
+
return false;
|
|
10315
|
+
}
|
|
10316
|
+
for (const section of repeatableSections) {
|
|
10317
|
+
const payload = { label: section.label };
|
|
10318
|
+
if (section.minEntries !== void 0) payload.minEntries = section.minEntries;
|
|
10319
|
+
if (section.maxEntries !== void 0) payload.maxEntries = section.maxEntries;
|
|
10320
|
+
for (const page of pages) {
|
|
10321
|
+
if (setRepeatable(page.children ?? [], section.nodeId, payload)) break;
|
|
10322
|
+
}
|
|
10323
|
+
}
|
|
10324
|
+
}
|
|
10218
10325
|
function PixldocsPreview(props) {
|
|
10219
10326
|
const {
|
|
10220
10327
|
pageIndex = 0,
|
|
@@ -10334,20 +10441,30 @@ async function loadGoogleFontCSS(rawFontFamily) {
|
|
|
10334
10441
|
loadingPromises.delete(fontFamily);
|
|
10335
10442
|
}
|
|
10336
10443
|
function collectFontsFromConfig(config) {
|
|
10444
|
+
var _a;
|
|
10337
10445
|
const fonts = /* @__PURE__ */ new Set();
|
|
10338
10446
|
fonts.add("Open Sans");
|
|
10339
10447
|
function walk(nodes) {
|
|
10340
|
-
var
|
|
10448
|
+
var _a2;
|
|
10341
10449
|
if (!nodes) return;
|
|
10342
10450
|
for (const node of nodes) {
|
|
10343
|
-
if (node.fontFamily) fonts.add(node.fontFamily);
|
|
10344
|
-
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));
|
|
10345
10453
|
if (node.children) walk(node.children);
|
|
10346
10454
|
}
|
|
10347
10455
|
}
|
|
10348
10456
|
for (const page of config.pages || []) {
|
|
10349
10457
|
walk(page.children || []);
|
|
10350
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
|
+
}
|
|
10351
10468
|
return fonts;
|
|
10352
10469
|
}
|
|
10353
10470
|
class PixldocsRenderer {
|
|
@@ -10595,47 +10712,6 @@ class PixldocsRenderer {
|
|
|
10595
10712
|
});
|
|
10596
10713
|
}
|
|
10597
10714
|
}
|
|
10598
|
-
function applyThemeToConfig(config, themeOverrides) {
|
|
10599
|
-
var _a, _b, _c;
|
|
10600
|
-
if (!themeOverrides || Object.keys(themeOverrides).length === 0) return config;
|
|
10601
|
-
const cloned = JSON.parse(JSON.stringify(config));
|
|
10602
|
-
if ((_a = cloned.themeConfig) == null ? void 0 : _a.variables) {
|
|
10603
|
-
for (const [key, value] of Object.entries(themeOverrides)) {
|
|
10604
|
-
if (cloned.themeConfig.variables[key]) {
|
|
10605
|
-
cloned.themeConfig.variables[key].value = value;
|
|
10606
|
-
}
|
|
10607
|
-
}
|
|
10608
|
-
}
|
|
10609
|
-
const varMap = /* @__PURE__ */ new Map();
|
|
10610
|
-
if ((_b = cloned.themeConfig) == null ? void 0 : _b.variables) {
|
|
10611
|
-
for (const [key, def] of Object.entries(cloned.themeConfig.variables)) {
|
|
10612
|
-
varMap.set(key, themeOverrides[key] ?? def.value);
|
|
10613
|
-
}
|
|
10614
|
-
}
|
|
10615
|
-
function walkAndApply(nodes) {
|
|
10616
|
-
if (!nodes) return;
|
|
10617
|
-
for (const node of nodes) {
|
|
10618
|
-
const bindings = node.themeBindings;
|
|
10619
|
-
if (bindings) {
|
|
10620
|
-
for (const [prop, varName] of Object.entries(bindings)) {
|
|
10621
|
-
const value = varMap.get(varName);
|
|
10622
|
-
if (value !== void 0) {
|
|
10623
|
-
node[prop] = value;
|
|
10624
|
-
}
|
|
10625
|
-
}
|
|
10626
|
-
}
|
|
10627
|
-
if (node.children) walkAndApply(node.children);
|
|
10628
|
-
}
|
|
10629
|
-
}
|
|
10630
|
-
for (const page of cloned.pages || []) {
|
|
10631
|
-
const bgBinding = (_c = page.themeBindings) == null ? void 0 : _c.backgroundColor;
|
|
10632
|
-
if (bgBinding && varMap.has(bgBinding) && page.settings) {
|
|
10633
|
-
page.settings.backgroundColor = varMap.get(bgBinding);
|
|
10634
|
-
}
|
|
10635
|
-
walkAndApply(page.children || []);
|
|
10636
|
-
}
|
|
10637
|
-
return cloned;
|
|
10638
|
-
}
|
|
10639
10715
|
exports.PixldocsPreview = PixldocsPreview;
|
|
10640
10716
|
exports.PixldocsRenderer = PixldocsRenderer;
|
|
10641
10717
|
exports.applyThemeToConfig = applyThemeToConfig;
|