@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.js
CHANGED
|
@@ -8556,6 +8556,47 @@ const PreviewCanvas$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.def
|
|
|
8556
8556
|
__proto__: null,
|
|
8557
8557
|
PreviewCanvas
|
|
8558
8558
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
8559
|
+
function applyThemeToConfig(config, themeOverrides) {
|
|
8560
|
+
var _a, _b, _c;
|
|
8561
|
+
if (!themeOverrides || Object.keys(themeOverrides).length === 0) return config;
|
|
8562
|
+
const cloned = JSON.parse(JSON.stringify(config));
|
|
8563
|
+
if ((_a = cloned.themeConfig) == null ? void 0 : _a.variables) {
|
|
8564
|
+
for (const [key, value] of Object.entries(themeOverrides)) {
|
|
8565
|
+
if (cloned.themeConfig.variables[key]) {
|
|
8566
|
+
cloned.themeConfig.variables[key].value = value;
|
|
8567
|
+
}
|
|
8568
|
+
}
|
|
8569
|
+
}
|
|
8570
|
+
const varMap = /* @__PURE__ */ new Map();
|
|
8571
|
+
if ((_b = cloned.themeConfig) == null ? void 0 : _b.variables) {
|
|
8572
|
+
for (const [key, def] of Object.entries(cloned.themeConfig.variables)) {
|
|
8573
|
+
varMap.set(key, themeOverrides[key] ?? def.value);
|
|
8574
|
+
}
|
|
8575
|
+
}
|
|
8576
|
+
function walkAndApply(nodes) {
|
|
8577
|
+
if (!nodes) return;
|
|
8578
|
+
for (const node of nodes) {
|
|
8579
|
+
const bindings = node.themeBindings;
|
|
8580
|
+
if (bindings) {
|
|
8581
|
+
for (const [prop, varName] of Object.entries(bindings)) {
|
|
8582
|
+
const value = varMap.get(varName);
|
|
8583
|
+
if (value !== void 0) {
|
|
8584
|
+
node[prop] = value;
|
|
8585
|
+
}
|
|
8586
|
+
}
|
|
8587
|
+
}
|
|
8588
|
+
if (node.children) walkAndApply(node.children);
|
|
8589
|
+
}
|
|
8590
|
+
}
|
|
8591
|
+
for (const page of cloned.pages || []) {
|
|
8592
|
+
const bgBinding = (_c = page.themeBindings) == null ? void 0 : _c.backgroundColor;
|
|
8593
|
+
if (bgBinding && varMap.has(bgBinding) && page.settings) {
|
|
8594
|
+
page.settings.backgroundColor = varMap.get(bgBinding);
|
|
8595
|
+
}
|
|
8596
|
+
walkAndApply(page.children || []);
|
|
8597
|
+
}
|
|
8598
|
+
return cloned;
|
|
8599
|
+
}
|
|
8559
8600
|
function mapFormDefFieldType(t) {
|
|
8560
8601
|
if (["text", "email", "tel", "textarea", "date", "url", "number", "toggle", "color", "image"].includes(t)) return t;
|
|
8561
8602
|
if (t === "currency") return "number";
|
|
@@ -10036,7 +10077,7 @@ async function resolveTemplateData(options) {
|
|
|
10036
10077
|
return { config, templateName: template.name || "Untitled", templateId };
|
|
10037
10078
|
}
|
|
10038
10079
|
async function resolveFromForm(options) {
|
|
10039
|
-
var _a, _b, _c, _d, _e;
|
|
10080
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10040
10081
|
const { templateId, formSchemaId, sectionState, themeId, supabaseUrl, supabaseAnonKey } = options;
|
|
10041
10082
|
const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
|
|
10042
10083
|
fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
|
|
@@ -10045,8 +10086,20 @@ async function resolveFromForm(options) {
|
|
|
10045
10086
|
]);
|
|
10046
10087
|
const templateConfig = templateRow.config;
|
|
10047
10088
|
const templateFormSchema = templateRow.form_schema;
|
|
10048
|
-
|
|
10089
|
+
if (templateFormSchema) {
|
|
10090
|
+
if (!Array.isArray(templateConfig.dynamicFields) && Array.isArray(templateFormSchema.dynamicFields)) {
|
|
10091
|
+
templateConfig.dynamicFields = templateFormSchema.dynamicFields;
|
|
10092
|
+
}
|
|
10093
|
+
if (!Array.isArray(templateConfig.fieldGroups) && Array.isArray(templateFormSchema.fieldGroups)) {
|
|
10094
|
+
templateConfig.fieldGroups = templateFormSchema.fieldGroups;
|
|
10095
|
+
}
|
|
10096
|
+
}
|
|
10097
|
+
normalizeLayoutModes(templateConfig);
|
|
10049
10098
|
const repeatableFromSchema = templateFormSchema == null ? void 0 : templateFormSchema.repeatableSections;
|
|
10099
|
+
if ((repeatableFromSchema == null ? void 0 : repeatableFromSchema.length) && templateConfig.pages) {
|
|
10100
|
+
paintRepeatableSections(templateConfig, repeatableFromSchema);
|
|
10101
|
+
}
|
|
10102
|
+
const schemaSections = (_a = formSchemaRow.schema) == null ? void 0 : _a.sections;
|
|
10050
10103
|
const repeatableNodeMap = /* @__PURE__ */ new Map();
|
|
10051
10104
|
if (repeatableFromSchema) {
|
|
10052
10105
|
for (const r of repeatableFromSchema) {
|
|
@@ -10078,9 +10131,7 @@ async function resolveFromForm(options) {
|
|
|
10078
10131
|
}
|
|
10079
10132
|
}
|
|
10080
10133
|
const flatFormData = flattenSectionStateToFormData(mergedSectionState, inferredSections);
|
|
10081
|
-
const
|
|
10082
|
-
const formSchemaDynamicFields = templateFormSchema == null ? void 0 : templateFormSchema.dynamicFields;
|
|
10083
|
-
const dynamicFields = ((configDynamicFields == null ? void 0 : configDynamicFields.length) ? configDynamicFields : formSchemaDynamicFields) || [];
|
|
10134
|
+
const dynamicFields = templateConfig.dynamicFields || [];
|
|
10084
10135
|
const mappings = [];
|
|
10085
10136
|
for (const field of dynamicFields) {
|
|
10086
10137
|
if (field.mappings) {
|
|
@@ -10151,13 +10202,21 @@ async function resolveFromForm(options) {
|
|
|
10151
10202
|
Object.keys(repeatableNestedEntryCounts).length > 0 ? repeatableNestedEntryCounts : void 0,
|
|
10152
10203
|
displayFormatMap.size > 0 ? displayFormatMap : void 0
|
|
10153
10204
|
);
|
|
10154
|
-
if (
|
|
10205
|
+
if ((_d = resolvedConfig.themeConfig) == null ? void 0 : _d.variables) {
|
|
10206
|
+
const baseOverrides = {};
|
|
10207
|
+
for (const [key, def] of Object.entries(resolvedConfig.themeConfig.variables)) {
|
|
10208
|
+
baseOverrides[key] = def.value;
|
|
10209
|
+
}
|
|
10210
|
+
resolvedConfig = applyThemeToConfig(resolvedConfig, baseOverrides);
|
|
10211
|
+
}
|
|
10212
|
+
if (templateConfig.themeConfig) {
|
|
10155
10213
|
const tc = templateConfig.themeConfig;
|
|
10156
|
-
const variant = (
|
|
10157
|
-
|
|
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) {
|
|
10158
10217
|
const themed = JSON.parse(JSON.stringify(resolvedConfig));
|
|
10159
10218
|
for (const prop of tc.properties) {
|
|
10160
|
-
const value = (
|
|
10219
|
+
const value = variant ? (_g = variant.values) == null ? void 0 : _g[prop.id] : prop.defaultValue;
|
|
10161
10220
|
if (value === void 0) continue;
|
|
10162
10221
|
if (prop.targetProperty === "backgroundColor" && prop.elementId === "__pageBackground__") {
|
|
10163
10222
|
themed.pages.forEach((p) => {
|
|
@@ -10196,6 +10255,54 @@ function flattenAll(nodes) {
|
|
|
10196
10255
|
}
|
|
10197
10256
|
return result;
|
|
10198
10257
|
}
|
|
10258
|
+
function normalizeLayoutModes(config) {
|
|
10259
|
+
function walk(node) {
|
|
10260
|
+
if (node.layoutMode === "stack" || node.layoutMode === "stacked") {
|
|
10261
|
+
node.layoutMode = "vertical-stack";
|
|
10262
|
+
}
|
|
10263
|
+
if (Array.isArray(node.children)) {
|
|
10264
|
+
for (const child of node.children) walk(child);
|
|
10265
|
+
}
|
|
10266
|
+
}
|
|
10267
|
+
for (const page of config.pages ?? []) {
|
|
10268
|
+
if (page.children) {
|
|
10269
|
+
for (const child of page.children) walk(child);
|
|
10270
|
+
}
|
|
10271
|
+
}
|
|
10272
|
+
}
|
|
10273
|
+
function paintRepeatableSections(config, repeatableSections) {
|
|
10274
|
+
const pages = config.pages ?? [];
|
|
10275
|
+
function stripFlags(nodes) {
|
|
10276
|
+
for (const node of nodes) {
|
|
10277
|
+
delete node.repeatableSection;
|
|
10278
|
+
if (Array.isArray(node.children)) stripFlags(node.children);
|
|
10279
|
+
}
|
|
10280
|
+
}
|
|
10281
|
+
for (const page of pages) {
|
|
10282
|
+
if (page.children) stripFlags(page.children);
|
|
10283
|
+
}
|
|
10284
|
+
function setRepeatable(nodes, nodeId, payload) {
|
|
10285
|
+
for (const node of nodes) {
|
|
10286
|
+
const id = node.id;
|
|
10287
|
+
if (id && (id === nodeId || baseId(id) === baseId(nodeId))) {
|
|
10288
|
+
node.repeatableSection = payload;
|
|
10289
|
+
return true;
|
|
10290
|
+
}
|
|
10291
|
+
if (Array.isArray(node.children) && setRepeatable(node.children, nodeId, payload)) {
|
|
10292
|
+
return true;
|
|
10293
|
+
}
|
|
10294
|
+
}
|
|
10295
|
+
return false;
|
|
10296
|
+
}
|
|
10297
|
+
for (const section of repeatableSections) {
|
|
10298
|
+
const payload = { label: section.label };
|
|
10299
|
+
if (section.minEntries !== void 0) payload.minEntries = section.minEntries;
|
|
10300
|
+
if (section.maxEntries !== void 0) payload.maxEntries = section.maxEntries;
|
|
10301
|
+
for (const page of pages) {
|
|
10302
|
+
if (setRepeatable(page.children ?? [], section.nodeId, payload)) break;
|
|
10303
|
+
}
|
|
10304
|
+
}
|
|
10305
|
+
}
|
|
10199
10306
|
function PixldocsPreview(props) {
|
|
10200
10307
|
const {
|
|
10201
10308
|
pageIndex = 0,
|
|
@@ -10315,20 +10422,30 @@ async function loadGoogleFontCSS(rawFontFamily) {
|
|
|
10315
10422
|
loadingPromises.delete(fontFamily);
|
|
10316
10423
|
}
|
|
10317
10424
|
function collectFontsFromConfig(config) {
|
|
10425
|
+
var _a;
|
|
10318
10426
|
const fonts = /* @__PURE__ */ new Set();
|
|
10319
10427
|
fonts.add("Open Sans");
|
|
10320
10428
|
function walk(nodes) {
|
|
10321
|
-
var
|
|
10429
|
+
var _a2;
|
|
10322
10430
|
if (!nodes) return;
|
|
10323
10431
|
for (const node of nodes) {
|
|
10324
|
-
if (node.fontFamily) fonts.add(node.fontFamily);
|
|
10325
|
-
if ((
|
|
10432
|
+
if (node.fontFamily) fonts.add(normalizeFontFamily(node.fontFamily));
|
|
10433
|
+
if ((_a2 = node.smartProps) == null ? void 0 : _a2.fontFamily) fonts.add(normalizeFontFamily(node.smartProps.fontFamily));
|
|
10326
10434
|
if (node.children) walk(node.children);
|
|
10327
10435
|
}
|
|
10328
10436
|
}
|
|
10329
10437
|
for (const page of config.pages || []) {
|
|
10330
10438
|
walk(page.children || []);
|
|
10331
10439
|
}
|
|
10440
|
+
if ((_a = config.themeConfig) == null ? void 0 : _a.variables) {
|
|
10441
|
+
for (const def of Object.values(config.themeConfig.variables)) {
|
|
10442
|
+
if (def.value && typeof def.value === "string" && !def.value.startsWith("#") && !def.value.startsWith("rgb")) {
|
|
10443
|
+
if (def.label && /font/i.test(def.label)) {
|
|
10444
|
+
fonts.add(normalizeFontFamily(def.value));
|
|
10445
|
+
}
|
|
10446
|
+
}
|
|
10447
|
+
}
|
|
10448
|
+
}
|
|
10332
10449
|
return fonts;
|
|
10333
10450
|
}
|
|
10334
10451
|
class PixldocsRenderer {
|
|
@@ -10576,47 +10693,6 @@ class PixldocsRenderer {
|
|
|
10576
10693
|
});
|
|
10577
10694
|
}
|
|
10578
10695
|
}
|
|
10579
|
-
function applyThemeToConfig(config, themeOverrides) {
|
|
10580
|
-
var _a, _b, _c;
|
|
10581
|
-
if (!themeOverrides || Object.keys(themeOverrides).length === 0) return config;
|
|
10582
|
-
const cloned = JSON.parse(JSON.stringify(config));
|
|
10583
|
-
if ((_a = cloned.themeConfig) == null ? void 0 : _a.variables) {
|
|
10584
|
-
for (const [key, value] of Object.entries(themeOverrides)) {
|
|
10585
|
-
if (cloned.themeConfig.variables[key]) {
|
|
10586
|
-
cloned.themeConfig.variables[key].value = value;
|
|
10587
|
-
}
|
|
10588
|
-
}
|
|
10589
|
-
}
|
|
10590
|
-
const varMap = /* @__PURE__ */ new Map();
|
|
10591
|
-
if ((_b = cloned.themeConfig) == null ? void 0 : _b.variables) {
|
|
10592
|
-
for (const [key, def] of Object.entries(cloned.themeConfig.variables)) {
|
|
10593
|
-
varMap.set(key, themeOverrides[key] ?? def.value);
|
|
10594
|
-
}
|
|
10595
|
-
}
|
|
10596
|
-
function walkAndApply(nodes) {
|
|
10597
|
-
if (!nodes) return;
|
|
10598
|
-
for (const node of nodes) {
|
|
10599
|
-
const bindings = node.themeBindings;
|
|
10600
|
-
if (bindings) {
|
|
10601
|
-
for (const [prop, varName] of Object.entries(bindings)) {
|
|
10602
|
-
const value = varMap.get(varName);
|
|
10603
|
-
if (value !== void 0) {
|
|
10604
|
-
node[prop] = value;
|
|
10605
|
-
}
|
|
10606
|
-
}
|
|
10607
|
-
}
|
|
10608
|
-
if (node.children) walkAndApply(node.children);
|
|
10609
|
-
}
|
|
10610
|
-
}
|
|
10611
|
-
for (const page of cloned.pages || []) {
|
|
10612
|
-
const bgBinding = (_c = page.themeBindings) == null ? void 0 : _c.backgroundColor;
|
|
10613
|
-
if (bgBinding && varMap.has(bgBinding) && page.settings) {
|
|
10614
|
-
page.settings.backgroundColor = varMap.get(bgBinding);
|
|
10615
|
-
}
|
|
10616
|
-
walkAndApply(page.children || []);
|
|
10617
|
-
}
|
|
10618
|
-
return cloned;
|
|
10619
|
-
}
|
|
10620
10696
|
export {
|
|
10621
10697
|
PixldocsPreview,
|
|
10622
10698
|
PixldocsRenderer,
|