@tomsher/cms-theme-kit 0.1.0 → 0.1.2
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/bin.js +5 -5
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-TN3DQWJE.js → chunk-JNTSZZHB.js} +10 -2
- package/dist/chunk-JNTSZZHB.js.map +1 -0
- package/dist/{chunk-ND62XRUU.js → chunk-NRS5OZJC.js} +222 -133
- package/dist/chunk-NRS5OZJC.js.map +1 -0
- package/dist/{chunk-YAYCHT4W.js → chunk-O6HJD7DS.js} +2 -2
- package/dist/{server-SWGQTMET.js → chunk-S4NCVJKH.js} +223 -172
- package/dist/chunk-S4NCVJKH.js.map +1 -0
- package/dist/chunk-VCSHHQGG.js +128 -0
- package/dist/chunk-VCSHHQGG.js.map +1 -0
- package/dist/{data-source-CKDBOWKF.js → data-source-DPKANGMF.js} +4 -4
- package/dist/server-4TLWATN6.js +177 -0
- package/dist/server-4TLWATN6.js.map +1 -0
- package/dist/static-server-SKZUHFNU.js +132 -0
- package/dist/static-server-SKZUHFNU.js.map +1 -0
- package/package.json +3 -4
- package/dist/chunk-6NVYKM2E.js +0 -219
- package/dist/chunk-6NVYKM2E.js.map +0 -1
- package/dist/chunk-ND62XRUU.js.map +0 -1
- package/dist/chunk-TN3DQWJE.js.map +0 -1
- package/dist/chunk-UDJL2R66.js +0 -158
- package/dist/chunk-UDJL2R66.js.map +0 -1
- package/dist/server-SWGQTMET.js.map +0 -1
- package/dist/static-server-BTUWXORJ.js +0 -196
- package/dist/static-server-BTUWXORJ.js.map +0 -1
- /package/dist/{chunk-YAYCHT4W.js.map → chunk-O6HJD7DS.js.map} +0 -0
- /package/dist/{data-source-CKDBOWKF.js.map → data-source-DPKANGMF.js.map} +0 -0
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
getThemeEntityQueryKey,
|
|
4
|
-
getThemeLinkTargetReferenceKey,
|
|
5
|
-
hasTranslatableFields,
|
|
6
|
-
localizeStorefrontRoutes,
|
|
7
|
-
localizeStorefrontUrl,
|
|
8
|
-
setTranslatableArrayFieldPathValue
|
|
9
|
-
} from "./chunk-6NVYKM2E.js";
|
|
10
|
-
import {
|
|
11
|
-
CliError,
|
|
12
3
|
__commonJS,
|
|
13
4
|
__toESM,
|
|
5
|
+
customFieldTypeConstants,
|
|
14
6
|
entityKinds,
|
|
7
|
+
liquidEntityQueryOptionPattern,
|
|
8
|
+
liquidEntityQueryPattern,
|
|
15
9
|
liquidThemeConfigFilePaths,
|
|
16
10
|
liquidThemeFolderNames,
|
|
17
11
|
liquidThemeTemplatePaths,
|
|
18
12
|
queryKeys,
|
|
19
|
-
sha256Hex,
|
|
20
13
|
themeAssetUrlPatterns,
|
|
21
14
|
themeCustomizerLocaleNamespace,
|
|
22
15
|
themeCustomizerLocalizedSettingTypes,
|
|
23
16
|
themeFileExtensions,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} from "./chunk-TN3DQWJE.js";
|
|
17
|
+
themeLinkTargetKinds
|
|
18
|
+
} from "./chunk-JNTSZZHB.js";
|
|
27
19
|
|
|
28
20
|
// ../node_modules/lodash/isArray.js
|
|
29
21
|
var require_isArray = __commonJS({
|
|
@@ -881,11 +873,7 @@ var require_get = __commonJS({
|
|
|
881
873
|
}
|
|
882
874
|
});
|
|
883
875
|
|
|
884
|
-
//
|
|
885
|
-
import { readFile } from "fs/promises";
|
|
886
|
-
import { join } from "path";
|
|
887
|
-
|
|
888
|
-
// ../liquid-engine/dist/chunk-C52D7ZTE.js
|
|
876
|
+
// ../cms-theme-engines/dist/chunk-HLWHVLM3.js
|
|
889
877
|
var liquidAssetUrlPatterns = {
|
|
890
878
|
themeAssetPrefix: /^assets\//i
|
|
891
879
|
};
|
|
@@ -976,10 +964,210 @@ var themePostMessageEvents = {
|
|
|
976
964
|
};
|
|
977
965
|
var customCssKey = "customCss";
|
|
978
966
|
var themeEntityBindingSource = "entity";
|
|
979
|
-
var themeEntityQueryTag = "entityQuery";
|
|
980
967
|
|
|
981
|
-
// ../
|
|
968
|
+
// ../cms-theme-engines/dist/chunk-W3TDIWZX.js
|
|
982
969
|
import sanitizeHtml from "sanitize-html";
|
|
970
|
+
|
|
971
|
+
// ../cms-core/dist/utils/index.js
|
|
972
|
+
var setTranslatableArrayFieldPathValue = (target, schemaFields, fieldPath, value, isTranslatable) => {
|
|
973
|
+
const path = fieldPath.split(".");
|
|
974
|
+
const rootField = schemaFields.find((field) => field.type === customFieldTypeConstants.array && String(field.id ?? field.key ?? field.name) === path[0]);
|
|
975
|
+
if (!rootField || path.length < 3 || path.length % 2 !== 1) return false;
|
|
976
|
+
let targetValue = target[rootField.id ?? rootField.key ?? rootField.name ?? ""];
|
|
977
|
+
let nestedFields = rootField.settings?.fields || rootField.fields || [];
|
|
978
|
+
for (let index = 1; index < path.length; index += 2) {
|
|
979
|
+
const arrayIndex = Number(path[index]);
|
|
980
|
+
const fieldId = path[index + 1];
|
|
981
|
+
const nestedField = nestedFields.find((field) => String(field.name ?? field.key ?? field.id) === fieldId);
|
|
982
|
+
if (!Number.isInteger(arrayIndex) || !nestedField || !Array.isArray(targetValue) || !targetValue[arrayIndex]) return false;
|
|
983
|
+
if (index === path.length - 2) {
|
|
984
|
+
if (!isTranslatable(nestedField)) return false;
|
|
985
|
+
targetValue[arrayIndex][fieldId] = value;
|
|
986
|
+
return true;
|
|
987
|
+
}
|
|
988
|
+
if (nestedField.type !== customFieldTypeConstants.array) return false;
|
|
989
|
+
targetValue = targetValue[arrayIndex][fieldId];
|
|
990
|
+
nestedFields = nestedField.settings?.fields || nestedField.fields || [];
|
|
991
|
+
}
|
|
992
|
+
return false;
|
|
993
|
+
};
|
|
994
|
+
var hasTranslatableFields = (schemaFields, componentsMap = {}, isFieldTranslatable = (field) => Boolean(field.settings?.isTranslatable)) => {
|
|
995
|
+
if (!Array.isArray(schemaFields)) return false;
|
|
996
|
+
return schemaFields.some((f) => {
|
|
997
|
+
if (isFieldTranslatable(f)) return true;
|
|
998
|
+
const nestedFields = f.settings?.fields || f.fields;
|
|
999
|
+
if (Array.isArray(nestedFields)) {
|
|
1000
|
+
return hasTranslatableFields(nestedFields, componentsMap, isFieldTranslatable);
|
|
1001
|
+
}
|
|
1002
|
+
if (f.type === customFieldTypeConstants.component) {
|
|
1003
|
+
const nestedCompId = f.settings?.componentId || f.validations?.componentId;
|
|
1004
|
+
const nestedComp = componentsMap[nestedCompId];
|
|
1005
|
+
if (nestedComp?.schema) {
|
|
1006
|
+
return hasTranslatableFields(nestedComp.schema, componentsMap, isFieldTranslatable);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
return false;
|
|
1010
|
+
});
|
|
1011
|
+
};
|
|
1012
|
+
var buildStorefrontLocalePrefix = ({ countryCode, languageCode, includeCountry, includeLanguage }) => [
|
|
1013
|
+
...includeCountry && countryCode ? [countryCode.toLowerCase()] : [],
|
|
1014
|
+
...includeLanguage && languageCode ? [languageCode.toLowerCase()] : []
|
|
1015
|
+
];
|
|
1016
|
+
var findStorefrontLanguage = (languages, languageCode) => {
|
|
1017
|
+
if (!languageCode) return void 0;
|
|
1018
|
+
const normalizedCode = languageCode.toLowerCase();
|
|
1019
|
+
return languages.find((language) => language.languageCode.toLowerCase() === normalizedCode);
|
|
1020
|
+
};
|
|
1021
|
+
var getStorefrontLocalePrefix = (localization) => {
|
|
1022
|
+
if (!localization) return [];
|
|
1023
|
+
return buildStorefrontLocalePrefix({
|
|
1024
|
+
countryCode: localization.country?.countryCode,
|
|
1025
|
+
languageCode: localization.language?.languageCode,
|
|
1026
|
+
includeCountry: localization.availableCountries.length > 1,
|
|
1027
|
+
includeLanguage: localization.availableLanguages.length > 1
|
|
1028
|
+
});
|
|
1029
|
+
};
|
|
1030
|
+
var localizeStorefrontUrl = (url, localization) => {
|
|
1031
|
+
const value = String(url || "/");
|
|
1032
|
+
if (/^(?:[a-z]+:)?\/\//i.test(value) || value.startsWith("mailto:") || value.startsWith("tel:") || value.startsWith("#") || value.startsWith("?")) return value;
|
|
1033
|
+
const prefix = getStorefrontLocalePrefix(localization);
|
|
1034
|
+
if (!prefix.length) return value;
|
|
1035
|
+
const match = value.match(/^([^?#]*)([?#].*)?$/);
|
|
1036
|
+
const path = match?.[1] || "/";
|
|
1037
|
+
const suffix = match?.[2] || "";
|
|
1038
|
+
const segments = path.split("/").filter(Boolean);
|
|
1039
|
+
const alreadyLocalized = prefix.every((segment, index) => segments[index]?.toLowerCase() === segment);
|
|
1040
|
+
if (alreadyLocalized) return value;
|
|
1041
|
+
const targetCountry = localization?.availableCountries.find((country) => country.countryCode.toLowerCase() === segments[0]?.toLowerCase());
|
|
1042
|
+
if (targetCountry) {
|
|
1043
|
+
const targetLanguages = targetCountry.languages || [];
|
|
1044
|
+
if (targetLanguages.length <= 1 || findStorefrontLanguage(targetLanguages, segments[1])) return value;
|
|
1045
|
+
} else if (localization?.availableCountries.length === 1 && findStorefrontLanguage(localization.availableLanguages, segments[0])) {
|
|
1046
|
+
return value;
|
|
1047
|
+
}
|
|
1048
|
+
return `/${[...prefix, ...segments].join("/")}${suffix}` || "/";
|
|
1049
|
+
};
|
|
1050
|
+
var localizeStorefrontRoutes = (routes, localization) => Object.fromEntries(Object.entries(routes).map(([key, value]) => [key, typeof value === "string" ? localizeStorefrontUrl(value, localization) : value]));
|
|
1051
|
+
var getThemeEntityQueryKey = (query) => `${query.type}:${query.handle}:${query.as || ""}`;
|
|
1052
|
+
var hasNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
1053
|
+
var isSafeExternalThemeUrl = (value) => {
|
|
1054
|
+
if (typeof value !== "string") return false;
|
|
1055
|
+
try {
|
|
1056
|
+
const url = new URL(value);
|
|
1057
|
+
return url.protocol === "https:" && Boolean(url.hostname) && !url.username && !url.password;
|
|
1058
|
+
} catch {
|
|
1059
|
+
return false;
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
var isThemeLinkTargetReference = (value) => {
|
|
1063
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1064
|
+
const reference = value;
|
|
1065
|
+
if (reference.kind === themeLinkTargetKinds.external) return isSafeExternalThemeUrl(reference.url);
|
|
1066
|
+
if (!hasNonEmptyString(reference.provider)) return false;
|
|
1067
|
+
if (!hasNonEmptyString(reference.entityId)) return false;
|
|
1068
|
+
if (reference.kind === themeLinkTargetKinds.single || reference.kind === themeLinkTargetKinds.listing) return true;
|
|
1069
|
+
return reference.kind === themeLinkTargetKinds.entry && hasNonEmptyString(reference.entryId);
|
|
1070
|
+
};
|
|
1071
|
+
var normalizeThemeLinkTargetReference = (value) => {
|
|
1072
|
+
if (!isThemeLinkTargetReference(value)) return null;
|
|
1073
|
+
if (value.kind === themeLinkTargetKinds.external) {
|
|
1074
|
+
return {
|
|
1075
|
+
kind: value.kind,
|
|
1076
|
+
url: value.url.trim()
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
if (value.kind === themeLinkTargetKinds.entry) {
|
|
1080
|
+
return {
|
|
1081
|
+
kind: value.kind,
|
|
1082
|
+
provider: value.provider.trim(),
|
|
1083
|
+
entityId: value.entityId.trim(),
|
|
1084
|
+
entryId: value.entryId.trim()
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
return {
|
|
1088
|
+
kind: value.kind,
|
|
1089
|
+
provider: value.provider.trim(),
|
|
1090
|
+
entityId: value.entityId.trim()
|
|
1091
|
+
};
|
|
1092
|
+
};
|
|
1093
|
+
var getThemeLinkTargetReferenceKey = (value) => {
|
|
1094
|
+
const reference = normalizeThemeLinkTargetReference(value);
|
|
1095
|
+
return reference ? JSON.stringify(reference) : null;
|
|
1096
|
+
};
|
|
1097
|
+
var safeDecodeAssetPath = (path) => {
|
|
1098
|
+
try {
|
|
1099
|
+
return decodeURIComponent(path);
|
|
1100
|
+
} catch {
|
|
1101
|
+
return path;
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
var findThemeAssetUrl = (assetUrls, assetPath) => {
|
|
1105
|
+
const candidates = [.../* @__PURE__ */ new Set([assetPath, safeDecodeAssetPath(assetPath)])];
|
|
1106
|
+
for (const candidate of candidates) {
|
|
1107
|
+
if (assetUrls[candidate]) return assetUrls[candidate];
|
|
1108
|
+
}
|
|
1109
|
+
return void 0;
|
|
1110
|
+
};
|
|
1111
|
+
var findThemeAssetUrlBySuffix = (assetUrls, assetPath) => {
|
|
1112
|
+
const candidates = [.../* @__PURE__ */ new Set([assetPath, safeDecodeAssetPath(assetPath)])].map((candidate) => candidate.toLowerCase());
|
|
1113
|
+
return Object.entries(assetUrls).find(([path]) => {
|
|
1114
|
+
const lowerPath = path.toLowerCase();
|
|
1115
|
+
return candidates.some((candidate) => lowerPath.endsWith(`/${candidate}`));
|
|
1116
|
+
})?.[1];
|
|
1117
|
+
};
|
|
1118
|
+
var rewriteThemeCssAssetUrls = (content, assetUrls) => content.replace(/url\(\s*(['"]?)(?!data:|https?:|blob:|\/)([^'"\)]+)\1\s*\)/gi, (match, quote, assetPath) => {
|
|
1119
|
+
const normalizedPath = assetPath.trim().replace(/^\.\//, "");
|
|
1120
|
+
const assetUrl = findThemeAssetUrl(assetUrls, normalizedPath) || findThemeAssetUrlBySuffix(assetUrls, normalizedPath);
|
|
1121
|
+
return assetUrl ? `url(${quote}${assetUrl}${quote})` : match;
|
|
1122
|
+
});
|
|
1123
|
+
var rewriteThemeHtmlAssetUrls = (content, assetUrls) => content.replace(/\b(src|href|poster)=(['"])(\.\/)?assets\/([^'"]+)\2/gi, (match, attribute, quote, _relativePrefix, assetPath) => {
|
|
1124
|
+
const normalizedPath = assetPath.split(/[?#]/, 1)[0];
|
|
1125
|
+
const assetUrl = findThemeAssetUrl(assetUrls, normalizedPath);
|
|
1126
|
+
return assetUrl ? `${attribute}=${quote}${assetUrl}${assetPath.slice(normalizedPath.length)}${quote}` : match;
|
|
1127
|
+
});
|
|
1128
|
+
var isThemeMarkupFile = (filename) => filename.startsWith(`${liquidThemeFolderNames.layout}/`) || filename.startsWith(`${liquidThemeFolderNames.sections}/`) || filename.startsWith(`${liquidThemeFolderNames.snippets}/`);
|
|
1129
|
+
var rewriteLiquidThemeAssetBuffers = (buffers, assetUrls) => {
|
|
1130
|
+
const rewrittenBuffers = { ...buffers };
|
|
1131
|
+
for (const [filename, content] of Object.entries(buffers)) {
|
|
1132
|
+
if (!content) continue;
|
|
1133
|
+
if (filename.endsWith(".css")) rewrittenBuffers[filename] = rewriteThemeCssAssetUrls(content, assetUrls);
|
|
1134
|
+
if (isThemeMarkupFile(filename)) rewrittenBuffers[filename] = rewriteThemeHtmlAssetUrls(content, assetUrls);
|
|
1135
|
+
}
|
|
1136
|
+
return rewrittenBuffers;
|
|
1137
|
+
};
|
|
1138
|
+
var unsafeAssetPathCharacterPattern = /%(?![0-9a-f]{2})|[^a-z0-9._~:/@!$*+,;=%-]/giu;
|
|
1139
|
+
var encodeAssetPathCharacters = (path) => path.replace(unsafeAssetPathCharacterPattern, (character) => encodeURIComponent(character));
|
|
1140
|
+
var encodeThemeAssetUrl = (url) => {
|
|
1141
|
+
if (/^(?:data|blob):/i.test(url)) return url;
|
|
1142
|
+
const suffixStart = url.search(/[?#]/);
|
|
1143
|
+
if (suffixStart === -1) return encodeAssetPathCharacters(url);
|
|
1144
|
+
return `${encodeAssetPathCharacters(url.slice(0, suffixStart))}${url.slice(suffixStart).replace(/ /g, "%20")}`;
|
|
1145
|
+
};
|
|
1146
|
+
var getThemeAssetUrls = (files, rootDirectory, resolveMediaUrl) => Object.fromEntries(files.flatMap((file) => {
|
|
1147
|
+
const filename = file.path || file.filename;
|
|
1148
|
+
if (!filename || !file.fileUrl || !filename.startsWith(`${rootDirectory}/`)) return [];
|
|
1149
|
+
const paths = [filename, filename.slice(rootDirectory.length + 1)];
|
|
1150
|
+
const url = encodeThemeAssetUrl(resolveMediaUrl(file.fileUrl));
|
|
1151
|
+
return paths.map((path) => [path, url]);
|
|
1152
|
+
}));
|
|
1153
|
+
var decodeHtmlAttribute = (value) => value.replace(/"/g, '"').replace(/�*39;/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
1154
|
+
var extractThemeStylesheets = (html) => {
|
|
1155
|
+
const stylesheets = /* @__PURE__ */ new Set();
|
|
1156
|
+
const content = html.replace(/<link\b[^>]*\brel=(['"])stylesheet\1[^>]*>/gi, (link) => {
|
|
1157
|
+
const href = link.match(/\bhref=(['"])(.*?)\1/i)?.[2];
|
|
1158
|
+
if (href) stylesheets.add(decodeHtmlAttribute(href));
|
|
1159
|
+
return "";
|
|
1160
|
+
});
|
|
1161
|
+
return { html: content, stylesheets: [...stylesheets] };
|
|
1162
|
+
};
|
|
1163
|
+
var renderThemeHtmlWithStylesheets = ({ html, stylesheets }) => {
|
|
1164
|
+
if (!stylesheets.length) return html;
|
|
1165
|
+
const links = stylesheets.map((href) => `<link rel="stylesheet" href="${href.replace(/&/g, "&").replace(/"/g, """)}">`).join("");
|
|
1166
|
+
return /<head\b[^>]*>/i.test(html) ? html.replace(/<head\b[^>]*>/i, (head) => `${head}${links}`) : `${links}${html}`;
|
|
1167
|
+
};
|
|
1168
|
+
var ensureThemeStylesheetsBeforeContent = (html) => renderThemeHtmlWithStylesheets(extractThemeStylesheets(html));
|
|
1169
|
+
|
|
1170
|
+
// ../cms-theme-engines/dist/chunk-W3TDIWZX.js
|
|
983
1171
|
var import_get = __toESM(require_get(), 1);
|
|
984
1172
|
var import_get2 = __toESM(require_get(), 1);
|
|
985
1173
|
var formatImageUrl = (url) => {
|
|
@@ -1352,11 +1540,6 @@ ${css}
|
|
|
1352
1540
|
</style>`;
|
|
1353
1541
|
};
|
|
1354
1542
|
var templateErrorHtml = (path) => `<div style="padding: 24px; color: #dc2626; font-family: sans-serif;"><h3>Template Error</h3><p>Could not parse template: <code>${escapeHtml(path)}</code></p></div>`;
|
|
1355
|
-
var queryPattern = new RegExp(
|
|
1356
|
-
`\\{%\\s*${themeEntityQueryTag}\\s+["']([a-zA-Z0-9_-]+)["']\\s*,\\s*["']([a-zA-Z0-9_-]+)["']\\s*((?:,\\s*[a-zA-Z][a-zA-Z0-9]*\\s*:\\s*(?:"[^"]*"|'[^']*'|[^,\\s]+)\\s*)*)%\\}`,
|
|
1357
|
-
"g"
|
|
1358
|
-
);
|
|
1359
|
-
var optionPattern = /([a-zA-Z][a-zA-Z0-9]*)\s*:\s*(?:"([^"]*)"|'([^']*)'|([^,\s]+))/g;
|
|
1360
1543
|
var getLiquidThemeEntitySources = (fileBuffers = {}, selectedTemplate) => Object.entries(fileBuffers).filter(([path]) => path === selectedTemplate || path === liquidThemeConfigFilePaths.settingsData || path.startsWith(`${liquidThemeFolderNames.sections}/`) || path.startsWith(`${liquidThemeFolderNames.snippets}/`)).map(([, content]) => content);
|
|
1361
1544
|
var markupReferencePattern = /\{%\s*(render|include|section)\s+['"]([^'"]+)['"]/gi;
|
|
1362
1545
|
var hasFile = (fileBuffers, path) => Object.prototype.hasOwnProperty.call(fileBuffers, path);
|
|
@@ -1399,9 +1582,9 @@ var requiresCurrentEntry = (query) => query.relationTarget === "current" || quer
|
|
|
1399
1582
|
var getLiquidThemeEntityQueries = (fileBuffers = {}, selectedTemplate) => {
|
|
1400
1583
|
const source = getLiquidThemeEntitySources(fileBuffers, selectedTemplate).join("\n");
|
|
1401
1584
|
const queries = /* @__PURE__ */ new Map();
|
|
1402
|
-
for (const match of source.matchAll(
|
|
1585
|
+
for (const match of source.matchAll(liquidEntityQueryPattern)) {
|
|
1403
1586
|
const query = { type: match[1], handle: match[2] };
|
|
1404
|
-
for (const option of match[3].matchAll(
|
|
1587
|
+
for (const option of match[3].matchAll(liquidEntityQueryOptionPattern)) {
|
|
1405
1588
|
const key2 = option[1];
|
|
1406
1589
|
const value = option[2] ?? option[3] ?? option[4];
|
|
1407
1590
|
if (key2 === "as") {
|
|
@@ -1597,106 +1780,6 @@ var applyThemeCustomizerLocaleOverrides = (fileBuffers, languageCode, defaultLan
|
|
|
1597
1780
|
return result;
|
|
1598
1781
|
};
|
|
1599
1782
|
|
|
1600
|
-
// ../liquid-engine/dist/utils/index.js
|
|
1601
|
-
var getLiquidThemeTemplateCategory = (path) => {
|
|
1602
|
-
if (path === liquidThemeTemplatePaths.index) return themeTemplateCategoryKeys.pages;
|
|
1603
|
-
if (path === liquidThemeTemplatePaths.collection) return themeTemplateCategoryKeys.collections;
|
|
1604
|
-
if (path === liquidThemeTemplatePaths.entityDetails) return themeTemplateCategoryKeys.details;
|
|
1605
|
-
if (path === liquidThemeTemplatePaths.notFound) return themeTemplateCategoryKeys.system;
|
|
1606
|
-
for (const category of Object.keys(themeTemplateCategories)) {
|
|
1607
|
-
const prefix = themeTemplateCategories[category].prefix;
|
|
1608
|
-
if (!prefix) continue;
|
|
1609
|
-
const categoryPrefix = `${liquidThemeFolderNames.templates}/${prefix}`;
|
|
1610
|
-
const name = path.startsWith(categoryPrefix) ? path.slice(categoryPrefix.length) : "";
|
|
1611
|
-
if (/^[a-z0-9][a-z0-9_-]*\.json$/.test(name)) return category;
|
|
1612
|
-
}
|
|
1613
|
-
return null;
|
|
1614
|
-
};
|
|
1615
|
-
|
|
1616
|
-
// src/lib/dev/data-source.ts
|
|
1617
|
-
var isRecord = (value) => {
|
|
1618
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1619
|
-
};
|
|
1620
|
-
var emptyPreviewData = () => {
|
|
1621
|
-
return { entities: {}, contentCollections: {} };
|
|
1622
|
-
};
|
|
1623
|
-
var buildPreviewRequest = (buffers, templatePath) => {
|
|
1624
|
-
const reachable = getLiquidThemeReachableBuffers(buffers, templatePath);
|
|
1625
|
-
const category = getLiquidThemeTemplateCategory(templatePath);
|
|
1626
|
-
const page = category === themeTemplateCategoryKeys.collections || category === themeTemplateCategoryKeys.details ? { templatePath, category } : void 0;
|
|
1627
|
-
const entities = getLiquidThemeEntityQueries(reachable, templatePath).filter((query) => page || !requiresCurrentEntry(query));
|
|
1628
|
-
const contentCollections = getLiquidThemeCollectionHandles(buffers, templatePath);
|
|
1629
|
-
const sources = getLiquidThemeEntitySources(reachable, templatePath);
|
|
1630
|
-
return { entities, contentCollections, sources, page };
|
|
1631
|
-
};
|
|
1632
|
-
var normalizePreviewData = (raw) => {
|
|
1633
|
-
const body = isRecord(raw) ? raw : {};
|
|
1634
|
-
let payload = body;
|
|
1635
|
-
if (isRecord(body.requestedData)) {
|
|
1636
|
-
payload = body.requestedData;
|
|
1637
|
-
} else if (isRecord(body.data)) {
|
|
1638
|
-
payload = body.data;
|
|
1639
|
-
}
|
|
1640
|
-
return {
|
|
1641
|
-
entities: isRecord(payload.entities) ? payload.entities : {},
|
|
1642
|
-
contentCollections: isRecord(payload.contentCollections) ? payload.contentCollections : {},
|
|
1643
|
-
page: isRecord(payload.page) ? payload.page : void 0,
|
|
1644
|
-
collection: isRecord(payload.collection) ? payload.collection : void 0
|
|
1645
|
-
};
|
|
1646
|
-
};
|
|
1647
|
-
var createFixturesDataSource = (themeDir) => {
|
|
1648
|
-
return {
|
|
1649
|
-
load: async ({ templatePath }) => {
|
|
1650
|
-
const fixturePath = join(themeDir, "fixtures", templatePath.replace(/\//g, "-"));
|
|
1651
|
-
let raw;
|
|
1652
|
-
try {
|
|
1653
|
-
raw = await readFile(fixturePath, "utf8");
|
|
1654
|
-
} catch (error) {
|
|
1655
|
-
if (error.code === "ENOENT") {
|
|
1656
|
-
return emptyPreviewData();
|
|
1657
|
-
}
|
|
1658
|
-
throw error;
|
|
1659
|
-
}
|
|
1660
|
-
try {
|
|
1661
|
-
return normalizePreviewData(JSON.parse(raw));
|
|
1662
|
-
} catch {
|
|
1663
|
-
throw new CliError(`${fixturePath} is not valid JSON.`);
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
};
|
|
1667
|
-
};
|
|
1668
|
-
var hasPreviewWork = (request) => {
|
|
1669
|
-
return request.entities.length > 0 || request.contentCollections.length > 0 || Boolean(request.page);
|
|
1670
|
-
};
|
|
1671
|
-
var cacheKeyOf = (request) => {
|
|
1672
|
-
const keyInput = { entities: request.entities, contentCollections: request.contentCollections, page: request.page };
|
|
1673
|
-
return sha256Hex(new TextEncoder().encode(JSON.stringify(keyInput)));
|
|
1674
|
-
};
|
|
1675
|
-
var createLiveDataSource = (options) => {
|
|
1676
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1677
|
-
return {
|
|
1678
|
-
load: async ({ buffers, templatePath }) => {
|
|
1679
|
-
const request = buildPreviewRequest(buffers, templatePath);
|
|
1680
|
-
if (!hasPreviewWork(request)) {
|
|
1681
|
-
return emptyPreviewData();
|
|
1682
|
-
}
|
|
1683
|
-
const key = cacheKeyOf(request);
|
|
1684
|
-
const cached = cache.get(key);
|
|
1685
|
-
if (cached) {
|
|
1686
|
-
return cached;
|
|
1687
|
-
}
|
|
1688
|
-
const pending = options.client.previewData(options.themeId, request, options.countryCode).then(normalizePreviewData);
|
|
1689
|
-
cache.set(key, pending);
|
|
1690
|
-
pending.catch(() => {
|
|
1691
|
-
if (cache.get(key) === pending) {
|
|
1692
|
-
cache.delete(key);
|
|
1693
|
-
}
|
|
1694
|
-
});
|
|
1695
|
-
return pending;
|
|
1696
|
-
}
|
|
1697
|
-
};
|
|
1698
|
-
};
|
|
1699
|
-
|
|
1700
1783
|
export {
|
|
1701
1784
|
maxRenderMs,
|
|
1702
1785
|
maxOutputBytes,
|
|
@@ -1710,6 +1793,11 @@ export {
|
|
|
1710
1793
|
defaultLayout,
|
|
1711
1794
|
isSafePartialName,
|
|
1712
1795
|
customCssKey,
|
|
1796
|
+
localizeStorefrontUrl,
|
|
1797
|
+
rewriteLiquidThemeAssetBuffers,
|
|
1798
|
+
getThemeAssetUrls,
|
|
1799
|
+
extractThemeStylesheets,
|
|
1800
|
+
ensureThemeStylesheetsBeforeContent,
|
|
1713
1801
|
require_get,
|
|
1714
1802
|
resolveThemeMediaUrl,
|
|
1715
1803
|
normalizeLiquidAssetValue,
|
|
@@ -1740,10 +1828,11 @@ export {
|
|
|
1740
1828
|
buildBlockList,
|
|
1741
1829
|
buildCustomCssBlock,
|
|
1742
1830
|
templateErrorHtml,
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1831
|
+
getLiquidThemeEntitySources,
|
|
1832
|
+
getLiquidThemeReachableBuffers,
|
|
1833
|
+
requiresCurrentEntry,
|
|
1834
|
+
getLiquidThemeEntityQueries,
|
|
1835
|
+
getLiquidThemeCollectionHandles,
|
|
1836
|
+
applyThemeCustomizerLocaleOverrides
|
|
1748
1837
|
};
|
|
1749
|
-
//# sourceMappingURL=chunk-
|
|
1838
|
+
//# sourceMappingURL=chunk-NRS5OZJC.js.map
|