@tomsher/cms-theme-kit 0.1.4 → 0.1.7

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.
@@ -2,13 +2,20 @@
2
2
  import {
3
3
  __commonJS,
4
4
  __toESM,
5
+ blockTagPatterns,
5
6
  customFieldTypeConstants,
7
+ defaultTemplate,
6
8
  entityKinds,
9
+ liquidAssetUrlPatterns,
7
10
  liquidEntityQueryOptionPattern,
8
11
  liquidEntityQueryPattern,
9
12
  liquidThemeConfigFilePaths,
10
13
  liquidThemeFolderNames,
11
- liquidThemeTemplatePaths,
14
+ maxContextArray,
15
+ maxContextDepth,
16
+ maxContextKeys,
17
+ privateField,
18
+ publicContextKeys,
12
19
  queryKeys,
13
20
  themeAssetUrlPatterns,
14
21
  themeCustomizerLocaleNamespace,
@@ -16,8 +23,9 @@ import {
16
23
  themeEntityBindingSource,
17
24
  themeFileExtensions,
18
25
  themeLinkTargetKinds,
26
+ themePostMessageEvents,
19
27
  themeSettingTypeConstants
20
- } from "./chunk-UOEFVNM4.js";
28
+ } from "./chunk-VY553LTO.js";
21
29
 
22
30
  // ../node_modules/lodash/isArray.js
23
31
  var require_isArray = __commonJS({
@@ -875,46 +883,104 @@ var require_get = __commonJS({
875
883
  }
876
884
  });
877
885
 
878
- // ../cms-core/dist/utils/index.js
879
- var setTranslatableArrayFieldPathValue = (target, schemaFields, fieldPath, value, isTranslatable) => {
880
- const path = fieldPath.split(".");
881
- const rootField = schemaFields.find((field) => field.type === customFieldTypeConstants.array && String(field.id ?? field.key ?? field.name) === path[0]);
882
- if (!rootField || path.length < 3 || path.length % 2 !== 1) return false;
883
- let targetValue = target[rootField.id ?? rootField.key ?? rootField.name ?? ""];
884
- let nestedFields = rootField.settings?.fields || rootField.fields || [];
885
- for (let index = 1; index < path.length; index += 2) {
886
- const arrayIndex = Number(path[index]);
887
- const fieldId = path[index + 1];
888
- const nestedField = nestedFields.find((field) => String(field.name ?? field.key ?? field.id) === fieldId);
889
- if (!Number.isInteger(arrayIndex) || !nestedField || !Array.isArray(targetValue) || !targetValue[arrayIndex]) return false;
890
- if (index === path.length - 2) {
891
- if (!isTranslatable(nestedField)) return false;
892
- targetValue[arrayIndex][fieldId] = value;
893
- return true;
894
- }
895
- if (nestedField.type !== customFieldTypeConstants.array) return false;
896
- targetValue = targetValue[arrayIndex][fieldId];
897
- nestedFields = nestedField.settings?.fields || nestedField.fields || [];
886
+ // ../cms-core/dist/chunk-BJUDFFBW.js
887
+ var import_get = __toESM(require_get(), 1);
888
+ var import_get2 = __toESM(require_get(), 1);
889
+ import sanitizeHtml from "sanitize-html";
890
+ var formatImageUrl = (url) => {
891
+ if (!url) return "";
892
+ if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("blob:") || url.startsWith("data:")) return url;
893
+ const baseUrl = process.env.NEXT_PUBLIC_IMAGE_URL || process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:5000";
894
+ const cleanBaseUrl = baseUrl.replace(/\/$/, "");
895
+ const cleanPath = url.startsWith("/") ? url : `/${url}`;
896
+ return `${cleanBaseUrl}${cleanPath}`;
897
+ };
898
+ var resolveThemeMediaUrl = (value) => {
899
+ const normalized = String(value || "").trim();
900
+ if (!normalized || themeAssetUrlPatterns.safeExternalUrl.test(normalized) || themeAssetUrlPatterns.safeDataUrl.test(normalized)) return normalized;
901
+ return formatImageUrl(normalized);
902
+ };
903
+ var normalizeAssetName = (value) => value.replace(/^\/+/, "").replace(liquidAssetUrlPatterns.themeAssetPrefix, "");
904
+ var normalizeLiquidAssetValue = (value) => String(value || "").trim();
905
+ var isExternalLiquidAssetUrl = (value) => themeAssetUrlPatterns.safeExternalUrl.test(value) || themeAssetUrlPatterns.safeDataUrl.test(value);
906
+ var isGalleryLiquidAssetUrl = (value) => {
907
+ const normalized = normalizeLiquidAssetValue(value);
908
+ return normalized.startsWith("/uploads/") || normalized.startsWith("uploads/");
909
+ };
910
+ var resolveLiquidMediaUrl = resolveThemeMediaUrl;
911
+ var resolveLiquidAssetUrl = (value, options = {}) => {
912
+ const normalized = normalizeLiquidAssetValue(value);
913
+ if (!normalized) return "";
914
+ if (isExternalLiquidAssetUrl(normalized)) return normalized;
915
+ if (normalized.startsWith("/") || isGalleryLiquidAssetUrl(normalized)) return formatImageUrl(normalized);
916
+ const assetName = normalizeAssetName(normalized);
917
+ const mappedUrl = options.themeAssetUrls?.get(assetName);
918
+ return mappedUrl || "";
919
+ };
920
+ var trustedHtml = /* @__PURE__ */ new WeakSet();
921
+ var asTrustedHtml = (html) => {
922
+ const value = { toString: () => html };
923
+ trustedHtml.add(value);
924
+ return value;
925
+ };
926
+ var publicValue = (value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) => {
927
+ if (value && typeof value === "object" && trustedHtml.has(value)) return value;
928
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
929
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
930
+ if (!value || typeof value !== "object" || depth >= maxContextDepth || seen.has(value)) return null;
931
+ seen.add(value);
932
+ try {
933
+ if (Array.isArray(value)) return value.slice(0, maxContextArray).map((child) => publicValue(child, depth + 1, seen));
934
+ if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return null;
935
+ return Object.fromEntries(Object.entries(value).slice(0, maxContextKeys).filter(([key]) => !privateField.test(key)).map(([key, child]) => [key, publicValue(child, depth + 1, seen)]));
936
+ } finally {
937
+ seen.delete(value);
898
938
  }
899
- return false;
900
939
  };
901
- var hasTranslatableFields = (schemaFields, componentsMap = {}, isFieldTranslatable = (field) => Boolean(field.settings?.isTranslatable)) => {
902
- if (!Array.isArray(schemaFields)) return false;
903
- return schemaFields.some((f) => {
904
- if (isFieldTranslatable(f)) return true;
905
- const nestedFields = f.settings?.fields || f.fields;
906
- if (Array.isArray(nestedFields)) {
907
- return hasTranslatableFields(nestedFields, componentsMap, isFieldTranslatable);
908
- }
909
- if (f.type === customFieldTypeConstants.component) {
910
- const nestedCompId = f.settings?.componentId || f.validations?.componentId;
911
- const nestedComp = componentsMap[nestedCompId];
912
- if (nestedComp?.schema) {
913
- return hasTranslatableFields(nestedComp.schema, componentsMap, isFieldTranslatable);
914
- }
915
- }
916
- return false;
917
- });
940
+ var publicContext = (context = {}) => Object.fromEntries(
941
+ Object.entries(context).filter(([key]) => publicContextKeys.has(key)).map(([key, value]) => [key, publicValue(value)])
942
+ );
943
+ var escapeHtml = (value) => String(value ?? "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
944
+ var richtextAllowedTags = [
945
+ "p",
946
+ "br",
947
+ "strong",
948
+ "b",
949
+ "em",
950
+ "i",
951
+ "u",
952
+ "a",
953
+ "ul",
954
+ "ol",
955
+ "li",
956
+ "h1",
957
+ "h2",
958
+ "h3",
959
+ "h4",
960
+ "h5",
961
+ "h6",
962
+ "blockquote",
963
+ "img",
964
+ "figure",
965
+ "figcaption",
966
+ "span",
967
+ "div",
968
+ "hr"
969
+ ];
970
+ var richtextSanitizeOptions = {
971
+ allowedTags: richtextAllowedTags,
972
+ allowedAttributes: {
973
+ a: ["href", "rel", "target"],
974
+ img: ["src", "alt"]
975
+ },
976
+ allowedSchemes: ["http", "https", "mailto"],
977
+ allowedSchemesAppliedToAttributes: ["href", "src"],
978
+ allowProtocolRelative: false,
979
+ nonTextTags: ["script", "style", "iframe", "textarea", "option"]
980
+ };
981
+ var sanitizeRichtext = (html) => {
982
+ if (html === null || html === void 0) return "";
983
+ return sanitizeHtml(String(html), richtextSanitizeOptions);
918
984
  };
919
985
  var buildStorefrontLocalePrefix = ({ countryCode, languageCode, includeCountry, includeLanguage }) => [
920
986
  ...includeCountry && countryCode ? [countryCode.toLowerCase()] : [],
@@ -956,6 +1022,86 @@ var localizeStorefrontUrl = (url, localization) => {
956
1022
  };
957
1023
  var localizeStorefrontRoutes = (routes, localization) => Object.fromEntries(Object.entries(routes).map(([key, value]) => [key, typeof value === "string" ? localizeStorefrontUrl(value, localization) : value]));
958
1024
  var getThemeEntityQueryKey = (query) => `${query.type}:${query.handle}:${query.as || ""}`;
1025
+ var sanitizeContent = (value, key = "") => {
1026
+ if (Array.isArray(value)) return value.map((item) => sanitizeContent(item, key));
1027
+ if (value && typeof value === "object") {
1028
+ return Object.fromEntries(Object.entries(value).map(([childKey, childValue]) => [childKey, sanitizeContent(childValue, childKey)]));
1029
+ }
1030
+ if (typeof value !== "string") return value;
1031
+ if (/^(url|href|src|action|link)$/i.test(key) && /^\s*javascript:/i.test(value)) return "#";
1032
+ return value.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "").replace(/\son\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "").replace(/javascript\s*:/gi, "");
1033
+ };
1034
+ var localizeLinkTargets = (targets, localization) => targets && Object.fromEntries(
1035
+ targets && Object.entries(targets)?.map(([key, target]) => [
1036
+ key,
1037
+ target.external || !target.available ? target : { ...target, url: localizeStorefrontUrl(target.url, localization) }
1038
+ ])
1039
+ );
1040
+ function buildStorefrontDropsContext(rawCmsData) {
1041
+ const { entities = {}, forms = {}, settings = {}, routes = {}, page, collection, contentCollections = {}, linkTargets = {}, localization, search = { results: [], terms: "", performed: false }, contentLoading = false, contentError } = rawCmsData;
1042
+ const safeEntities = sanitizeContent(entities);
1043
+ const safeForms = sanitizeContent(forms);
1044
+ const formsProxy = new Proxy(safeForms, {
1045
+ get(target, prop) {
1046
+ if (typeof prop !== "string") return void 0;
1047
+ return target[prop] || { handle: prop, name: prop };
1048
+ }
1049
+ });
1050
+ return {
1051
+ settings: sanitizeContent(settings),
1052
+ routes: localizeStorefrontRoutes(routes, localization),
1053
+ ...page ? { page: sanitizeContent(page) } : {},
1054
+ ...collection ? { collection: sanitizeContent(collection) } : {},
1055
+ contentCollections: sanitizeContent(contentCollections),
1056
+ linkTargets: localizeLinkTargets(linkTargets, localization),
1057
+ ...localization ? { localization: sanitizeContent(localization) } : {},
1058
+ search: sanitizeContent(search),
1059
+ entities: safeEntities,
1060
+ forms: formsProxy,
1061
+ contentLoading,
1062
+ contentError
1063
+ };
1064
+ }
1065
+ var resolveMarkupKey = (fileBuffers, directory, name) => {
1066
+ const baseName = [themeFileExtensions.liquid, themeFileExtensions.html].reduce((value, extension) => value.toLowerCase().endsWith(extension) ? value.slice(0, -extension.length) : value, name);
1067
+ const liquidPath = `${directory}/${baseName}${themeFileExtensions.liquid}`;
1068
+ const htmlPath = `${directory}/${baseName}${themeFileExtensions.html}`;
1069
+ return fileBuffers[liquidPath] !== void 0 ? liquidPath : fileBuffers[htmlPath] !== void 0 ? htmlPath : liquidPath;
1070
+ };
1071
+ var sectionKey = (fileBuffers, name) => resolveMarkupKey(fileBuffers, "sections", name);
1072
+ var layoutKey = (fileBuffers, name) => resolveMarkupKey(fileBuffers, "layout", name);
1073
+ var stripAssetsPrefix = (path) => path.replace(/^assets\//, "");
1074
+ var assetKey = (path) => {
1075
+ const value = String(path || "").split("?")[0];
1076
+ const marker = value.indexOf("/assets/");
1077
+ const assetPath = marker >= 0 ? value.slice(marker + 1) : value;
1078
+ return `assets/${stripAssetsPrefix(assetPath)}`;
1079
+ };
1080
+ var parseJson = (raw, fallback) => {
1081
+ if (!raw) return fallback;
1082
+ try {
1083
+ return JSON.parse(raw);
1084
+ } catch {
1085
+ return fallback;
1086
+ }
1087
+ };
1088
+ var resolveTemplatePath = (fileBuffers, templatePath) => {
1089
+ if (fileBuffers[templatePath]) return templatePath;
1090
+ const keys = Object.keys(fileBuffers);
1091
+ return keys.find((k) => k === defaultTemplate) || keys.find((k) => k.startsWith("templates/")) || keys.find((k) => k.startsWith("sections/")) || templatePath;
1092
+ };
1093
+ function extractSectionSchema(liquidSource) {
1094
+ if (!liquidSource) return null;
1095
+ const match = liquidSource.match(/\{%\s*schema\s*%\}([\s\S]*?)\{%\s*endschema\s*%\}/i);
1096
+ if (!match || !match[1]) return null;
1097
+ try {
1098
+ const parsed = JSON.parse(match[1].trim());
1099
+ return parsed;
1100
+ } catch (err) {
1101
+ console.error("Failed to parse Liquid section schema JSON:", err);
1102
+ return null;
1103
+ }
1104
+ }
959
1105
  var hasNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
960
1106
  var isSafeExternalThemeUrl = (value) => {
961
1107
  if (typeof value !== "string") return false;
@@ -1093,273 +1239,6 @@ var renderThemeHtmlWithStylesheets = ({ html, stylesheets }) => {
1093
1239
  return /<head\b[^>]*>/i.test(html) ? html.replace(/<head\b[^>]*>/i, (head) => `${head}${links}`) : `${links}${html}`;
1094
1240
  };
1095
1241
  var ensureThemeStylesheetsBeforeContent = (html) => renderThemeHtmlWithStylesheets(extractThemeStylesheets(html));
1096
-
1097
- // ../cms-theme-engines/dist/chunk-OAKZOSNS.js
1098
- var liquidAssetUrlPatterns = {
1099
- themeAssetPrefix: /^assets\//i
1100
- };
1101
- var maxRenderMs = 3e3;
1102
- var maxOutputBytes = 1024 * 1024;
1103
- var maxTemplateChars = 128 * 1024;
1104
- var maxPackageChars = 4 * 1024 * 1024;
1105
- var maxIterations = 1e6;
1106
- var maxIncludeDepth = 8;
1107
- var maxContextDepth = 12;
1108
- var maxContextArray = 1e3;
1109
- var maxContextKeys = 500;
1110
- var publicContextKeys = /* @__PURE__ */ new Set(["shop", "settings", "routes", "page", "collection", "contentCollections", "linkTargets", "localization", "search", "entities", "forms", "contentLoading", "contentError", "pageTitle", "section", "item"]);
1111
- var privateField = /^(?:__proto__|prototype|constructor|password|secret|token|access[_-]?token|refresh[_-]?token|api[_-]?key|private[_-]?key|notification[_-]?emails|internal[_-]?notes)$/i;
1112
- var allowedTags = /* @__PURE__ */ new Set(["assign", "for", "capture", "case", "comment", "cycle", "if", "unless", "break", "continue", "echo", "raw", "liquid", "#", "tablerow", "increment", "decrement", "render", "section"]);
1113
- var allowedFilters = /* @__PURE__ */ new Set([
1114
- "abs",
1115
- "append",
1116
- "at_least",
1117
- "at_most",
1118
- "capitalize",
1119
- "ceil",
1120
- "compact",
1121
- "concat",
1122
- "date",
1123
- "default",
1124
- "divided_by",
1125
- "downcase",
1126
- "escape",
1127
- "escape_once",
1128
- "first",
1129
- "floor",
1130
- "join",
1131
- "last",
1132
- "lstrip",
1133
- "map",
1134
- "minus",
1135
- "modulo",
1136
- "newline_to_br",
1137
- "plus",
1138
- "prepend",
1139
- "remove",
1140
- "remove_first",
1141
- "replace",
1142
- "replace_first",
1143
- "reverse",
1144
- "round",
1145
- "rstrip",
1146
- "size",
1147
- "slice",
1148
- "sort",
1149
- "sort_natural",
1150
- "split",
1151
- "strip",
1152
- "strip_html",
1153
- "strip_newlines",
1154
- "times",
1155
- "truncate",
1156
- "truncatewords",
1157
- "uniq",
1158
- "upcase",
1159
- "url_encode",
1160
- "where",
1161
- "assetUrl",
1162
- "stylesheetTag",
1163
- "scriptTag",
1164
- "t",
1165
- "json",
1166
- "imageUrl",
1167
- "richtext",
1168
- "localizeUrl"
1169
- ]);
1170
- var defaultTemplate = liquidThemeTemplatePaths.index;
1171
- var defaultLayout = "theme";
1172
- var isSafePartialName = (name) => /^[a-zA-Z0-9][a-zA-Z0-9/_-]{0,127}(?:\.liquid|\.html)?$/.test(name) && !name.includes("//");
1173
- var blockTagPatterns = [
1174
- /\{%\s*schema\s*%\}[\s\S]*?\{%\s*endschema\s*%\}/gi,
1175
- /\{%\s*stylesheet\s*%\}[\s\S]*?\{%\s*endstylesheet\s*%\}/gi,
1176
- /\{%\s*javascript\s*%\}[\s\S]*?\{%\s*endjavascript\s*%\}/gi,
1177
- /\{%\s*entityQuery\b[^%]*%\}/gi
1178
- ];
1179
- var themePostMessageEvents = {
1180
- select: "THEME_CUSTOMIZER_SELECT"
1181
- };
1182
- var customCssKey = "customCss";
1183
-
1184
- // ../cms-theme-engines/dist/chunk-X4AIS34X.js
1185
- import sanitizeHtml from "sanitize-html";
1186
- var import_get = __toESM(require_get(), 1);
1187
- var import_get2 = __toESM(require_get(), 1);
1188
- var formatImageUrl = (url) => {
1189
- if (!url) return "";
1190
- if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("blob:") || url.startsWith("data:")) return url;
1191
- const baseUrl = process.env.NEXT_PUBLIC_IMAGE_URL || process.env.NEXT_PUBLIC_API_BASE_URL || "http://localhost:5000";
1192
- const cleanBaseUrl = baseUrl.replace(/\/$/, "");
1193
- const cleanPath = url.startsWith("/") ? url : `/${url}`;
1194
- return `${cleanBaseUrl}${cleanPath}`;
1195
- };
1196
- var resolveThemeMediaUrl = (value) => {
1197
- const normalized = String(value || "").trim();
1198
- if (!normalized || themeAssetUrlPatterns.safeExternalUrl.test(normalized) || themeAssetUrlPatterns.safeDataUrl.test(normalized)) return normalized;
1199
- return formatImageUrl(normalized);
1200
- };
1201
- var normalizeAssetName = (value) => value.replace(/^\/+/, "").replace(liquidAssetUrlPatterns.themeAssetPrefix, "");
1202
- var normalizeLiquidAssetValue = (value) => String(value || "").trim();
1203
- var isExternalLiquidAssetUrl = (value) => themeAssetUrlPatterns.safeExternalUrl.test(value) || themeAssetUrlPatterns.safeDataUrl.test(value);
1204
- var isGalleryLiquidAssetUrl = (value) => {
1205
- const normalized = normalizeLiquidAssetValue(value);
1206
- return normalized.startsWith("/uploads/") || normalized.startsWith("uploads/");
1207
- };
1208
- var resolveLiquidMediaUrl = resolveThemeMediaUrl;
1209
- var resolveLiquidAssetUrl = (value, options = {}) => {
1210
- const normalized = normalizeLiquidAssetValue(value);
1211
- if (!normalized) return "";
1212
- if (isExternalLiquidAssetUrl(normalized)) return normalized;
1213
- if (normalized.startsWith("/") || isGalleryLiquidAssetUrl(normalized)) return formatImageUrl(normalized);
1214
- const assetName = normalizeAssetName(normalized);
1215
- const mappedUrl = options.themeAssetUrls?.get(assetName);
1216
- return mappedUrl || "";
1217
- };
1218
- var trustedHtml = /* @__PURE__ */ new WeakSet();
1219
- var asTrustedHtml = (html) => {
1220
- const value = { toString: () => html };
1221
- trustedHtml.add(value);
1222
- return value;
1223
- };
1224
- var publicValue = (value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) => {
1225
- if (value && typeof value === "object" && trustedHtml.has(value)) return value;
1226
- if (value === null || typeof value === "string" || typeof value === "boolean") return value;
1227
- if (typeof value === "number") return Number.isFinite(value) ? value : null;
1228
- if (!value || typeof value !== "object" || depth >= maxContextDepth || seen.has(value)) return null;
1229
- seen.add(value);
1230
- try {
1231
- if (Array.isArray(value)) return value.slice(0, maxContextArray).map((child) => publicValue(child, depth + 1, seen));
1232
- if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return null;
1233
- return Object.fromEntries(Object.entries(value).slice(0, maxContextKeys).filter(([key]) => !privateField.test(key)).map(([key, child]) => [key, publicValue(child, depth + 1, seen)]));
1234
- } finally {
1235
- seen.delete(value);
1236
- }
1237
- };
1238
- var publicContext = (context = {}) => Object.fromEntries(
1239
- Object.entries(context).filter(([key]) => publicContextKeys.has(key)).map(([key, value]) => [key, publicValue(value)])
1240
- );
1241
- var escapeHtml = (value) => String(value ?? "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1242
- var richtextAllowedTags = [
1243
- "p",
1244
- "br",
1245
- "strong",
1246
- "b",
1247
- "em",
1248
- "i",
1249
- "u",
1250
- "a",
1251
- "ul",
1252
- "ol",
1253
- "li",
1254
- "h1",
1255
- "h2",
1256
- "h3",
1257
- "h4",
1258
- "h5",
1259
- "h6",
1260
- "blockquote",
1261
- "img",
1262
- "figure",
1263
- "figcaption",
1264
- "span",
1265
- "div",
1266
- "hr"
1267
- ];
1268
- var richtextSanitizeOptions = {
1269
- allowedTags: richtextAllowedTags,
1270
- allowedAttributes: {
1271
- a: ["href", "rel", "target"],
1272
- img: ["src", "alt"]
1273
- },
1274
- allowedSchemes: ["http", "https", "mailto"],
1275
- allowedSchemesAppliedToAttributes: ["href", "src"],
1276
- allowProtocolRelative: false,
1277
- nonTextTags: ["script", "style", "iframe", "textarea", "option"]
1278
- };
1279
- var sanitizeRichtext = (html) => {
1280
- if (html === null || html === void 0) return "";
1281
- return sanitizeHtml(String(html), richtextSanitizeOptions);
1282
- };
1283
- var sanitizeContent = (value, key = "") => {
1284
- if (Array.isArray(value)) return value.map((item) => sanitizeContent(item, key));
1285
- if (value && typeof value === "object") {
1286
- return Object.fromEntries(Object.entries(value).map(([childKey, childValue]) => [childKey, sanitizeContent(childValue, childKey)]));
1287
- }
1288
- if (typeof value !== "string") return value;
1289
- if (/^(url|href|src|action|link)$/i.test(key) && /^\s*javascript:/i.test(value)) return "#";
1290
- return value.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "").replace(/\son\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "").replace(/javascript\s*:/gi, "");
1291
- };
1292
- var localizeLinkTargets = (targets, localization) => targets && Object.fromEntries(
1293
- targets && Object.entries(targets)?.map(([key, target]) => [
1294
- key,
1295
- target.external || !target.available ? target : { ...target, url: localizeStorefrontUrl(target.url, localization) }
1296
- ])
1297
- );
1298
- function buildStorefrontDropsContext(rawCmsData) {
1299
- const { entities = {}, forms = {}, settings = {}, routes = {}, page, collection, contentCollections = {}, linkTargets = {}, localization, search = { results: [], terms: "", performed: false }, contentLoading = false, contentError } = rawCmsData;
1300
- const safeEntities = sanitizeContent(entities);
1301
- const safeForms = sanitizeContent(forms);
1302
- const formsProxy = new Proxy(safeForms, {
1303
- get(target, prop) {
1304
- if (typeof prop !== "string") return void 0;
1305
- return target[prop] || { handle: prop, name: prop };
1306
- }
1307
- });
1308
- return {
1309
- settings: sanitizeContent(settings),
1310
- routes: localizeStorefrontRoutes(routes, localization),
1311
- ...page ? { page: sanitizeContent(page) } : {},
1312
- ...collection ? { collection: sanitizeContent(collection) } : {},
1313
- contentCollections: sanitizeContent(contentCollections),
1314
- linkTargets: localizeLinkTargets(linkTargets, localization),
1315
- ...localization ? { localization: sanitizeContent(localization) } : {},
1316
- search: sanitizeContent(search),
1317
- entities: safeEntities,
1318
- forms: formsProxy,
1319
- contentLoading,
1320
- contentError
1321
- };
1322
- }
1323
- var resolveMarkupKey = (fileBuffers, directory, name) => {
1324
- const baseName = [themeFileExtensions.liquid, themeFileExtensions.html].reduce((value, extension) => value.toLowerCase().endsWith(extension) ? value.slice(0, -extension.length) : value, name);
1325
- const liquidPath = `${directory}/${baseName}${themeFileExtensions.liquid}`;
1326
- const htmlPath = `${directory}/${baseName}${themeFileExtensions.html}`;
1327
- return fileBuffers[liquidPath] !== void 0 ? liquidPath : fileBuffers[htmlPath] !== void 0 ? htmlPath : liquidPath;
1328
- };
1329
- var sectionKey = (fileBuffers, name) => resolveMarkupKey(fileBuffers, "sections", name);
1330
- var layoutKey = (fileBuffers, name) => resolveMarkupKey(fileBuffers, "layout", name);
1331
- var stripAssetsPrefix = (path) => path.replace(/^assets\//, "");
1332
- var assetKey = (path) => {
1333
- const value = String(path || "").split("?")[0];
1334
- const marker = value.indexOf("/assets/");
1335
- const assetPath = marker >= 0 ? value.slice(marker + 1) : value;
1336
- return `assets/${stripAssetsPrefix(assetPath)}`;
1337
- };
1338
- var parseJson = (raw, fallback) => {
1339
- if (!raw) return fallback;
1340
- try {
1341
- return JSON.parse(raw);
1342
- } catch {
1343
- return fallback;
1344
- }
1345
- };
1346
- var resolveTemplatePath = (fileBuffers, templatePath) => {
1347
- if (fileBuffers[templatePath]) return templatePath;
1348
- const keys = Object.keys(fileBuffers);
1349
- return keys.find((k) => k === defaultTemplate) || keys.find((k) => k.startsWith("templates/")) || keys.find((k) => k.startsWith("sections/")) || templatePath;
1350
- };
1351
- function extractSectionSchema(liquidSource) {
1352
- if (!liquidSource) return null;
1353
- const match = liquidSource.match(/\{%\s*schema\s*%\}([\s\S]*?)\{%\s*endschema\s*%\}/i);
1354
- if (!match || !match[1]) return null;
1355
- try {
1356
- const parsed = JSON.parse(match[1].trim());
1357
- return parsed;
1358
- } catch (err) {
1359
- console.error("Failed to parse Liquid section schema JSON:", err);
1360
- return null;
1361
- }
1362
- }
1363
1242
  var collectDefaults = (items) => Object.fromEntries(
1364
1243
  items.map((setting) => ({
1365
1244
  id: setting?.id || setting?.key || setting?.name,
@@ -1699,6 +1578,46 @@ var getLiquidThemeCollectionHandles = (fileBuffers = {}, selectedTemplate) => {
1699
1578
  }
1700
1579
  return [...handles].slice(0, 20);
1701
1580
  };
1581
+ var setTranslatableArrayFieldPathValue = (target, schemaFields, fieldPath, value, isTranslatable) => {
1582
+ const path = fieldPath.split(".");
1583
+ const rootField = schemaFields.find((field) => field.type === customFieldTypeConstants.array && String(field.id ?? field.key ?? field.name) === path[0]);
1584
+ if (!rootField || path.length < 3 || path.length % 2 !== 1) return false;
1585
+ let targetValue = target[rootField.id ?? rootField.key ?? rootField.name ?? ""];
1586
+ let nestedFields = rootField.settings?.fields || rootField.fields || [];
1587
+ for (let index = 1; index < path.length; index += 2) {
1588
+ const arrayIndex = Number(path[index]);
1589
+ const fieldId = path[index + 1];
1590
+ const nestedField = nestedFields.find((field) => String(field.name ?? field.key ?? field.id) === fieldId);
1591
+ if (!Number.isInteger(arrayIndex) || !nestedField || !Array.isArray(targetValue) || !targetValue[arrayIndex]) return false;
1592
+ if (index === path.length - 2) {
1593
+ if (!isTranslatable(nestedField)) return false;
1594
+ targetValue[arrayIndex][fieldId] = value;
1595
+ return true;
1596
+ }
1597
+ if (nestedField.type !== customFieldTypeConstants.array) return false;
1598
+ targetValue = targetValue[arrayIndex][fieldId];
1599
+ nestedFields = nestedField.settings?.fields || nestedField.fields || [];
1600
+ }
1601
+ return false;
1602
+ };
1603
+ var hasTranslatableFields = (schemaFields, componentsMap = {}, isFieldTranslatable = (field) => Boolean(field.settings?.isTranslatable)) => {
1604
+ if (!Array.isArray(schemaFields)) return false;
1605
+ return schemaFields.some((f) => {
1606
+ if (isFieldTranslatable(f)) return true;
1607
+ const nestedFields = f.settings?.fields || f.fields;
1608
+ if (Array.isArray(nestedFields)) {
1609
+ return hasTranslatableFields(nestedFields, componentsMap, isFieldTranslatable);
1610
+ }
1611
+ if (f.type === customFieldTypeConstants.component) {
1612
+ const nestedCompId = f.settings?.componentId || f.validations?.componentId;
1613
+ const nestedComp = componentsMap[nestedCompId];
1614
+ if (nestedComp?.schema) {
1615
+ return hasTranslatableFields(nestedComp.schema, componentsMap, isFieldTranslatable);
1616
+ }
1617
+ }
1618
+ return false;
1619
+ });
1620
+ };
1702
1621
  var localizedSettingTypes = new Set(Object.values(themeCustomizerLocalizedSettingTypes));
1703
1622
  var isThemeCustomizerSettingLocalized = (setting) => {
1704
1623
  return hasTranslatableFields([setting], {}, (field) => Boolean(field.settings?.isTranslatable) && localizedSettingTypes.has(String(field.type)));
@@ -1796,24 +1715,6 @@ var applyThemeCustomizerLocaleOverrides = (fileBuffers, languageCode, defaultLan
1796
1715
  };
1797
1716
 
1798
1717
  export {
1799
- maxRenderMs,
1800
- maxOutputBytes,
1801
- maxTemplateChars,
1802
- maxPackageChars,
1803
- maxIterations,
1804
- maxIncludeDepth,
1805
- allowedTags,
1806
- allowedFilters,
1807
- defaultTemplate,
1808
- defaultLayout,
1809
- isSafePartialName,
1810
- customCssKey,
1811
- localizeStorefrontUrl,
1812
- collectThemeLinkTargetReferences,
1813
- rewriteLiquidThemeAssetBuffers,
1814
- getThemeAssetUrls,
1815
- extractThemeStylesheets,
1816
- ensureThemeStylesheetsBeforeContent,
1817
1718
  require_get,
1818
1719
  resolveThemeMediaUrl,
1819
1720
  normalizeLiquidAssetValue,
@@ -1827,12 +1728,18 @@ export {
1827
1728
  publicContext,
1828
1729
  escapeHtml,
1829
1730
  sanitizeRichtext,
1731
+ localizeStorefrontUrl,
1830
1732
  buildStorefrontDropsContext,
1831
1733
  resolveMarkupKey,
1832
1734
  sectionKey,
1833
1735
  layoutKey,
1834
1736
  parseJson,
1835
1737
  resolveTemplatePath,
1738
+ collectThemeLinkTargetReferences,
1739
+ rewriteLiquidThemeAssetBuffers,
1740
+ getThemeAssetUrls,
1741
+ extractThemeStylesheets,
1742
+ ensureThemeStylesheetsBeforeContent,
1836
1743
  stripSectionSchema,
1837
1744
  resolveSectionSettings,
1838
1745
  buildSectionScope,
@@ -1851,4 +1758,4 @@ export {
1851
1758
  getLiquidThemeCollectionHandles,
1852
1759
  applyThemeCustomizerLocaleOverrides
1853
1760
  };
1854
- //# sourceMappingURL=chunk-IDKQZJPL.js.map
1761
+ //# sourceMappingURL=chunk-UMGL5N53.js.map