@tomsher/cms-theme-kit 0.1.3 → 0.1.6
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 +34 -10
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-ZUBE6H6H.js → chunk-OATE235V.js} +24 -11
- package/dist/chunk-OATE235V.js.map +1 -0
- package/dist/{chunk-C5SWGZ55.js → chunk-PEG6K5NX.js} +2 -2
- package/dist/{chunk-OJEPFH5L.js → chunk-UMGL5N53.js} +236 -310
- package/dist/chunk-UMGL5N53.js.map +1 -0
- package/dist/{chunk-QOSNX2RN.js → chunk-VDICVCKJ.js} +17 -17
- package/dist/chunk-VDICVCKJ.js.map +1 -0
- package/dist/{chunk-UOEFVNM4.js → chunk-VY553LTO.js} +171 -64
- package/dist/chunk-VY553LTO.js.map +1 -0
- package/dist/{data-source-XSFJYQNF.js → data-source-I5BXXWXI.js} +4 -4
- package/dist/{server-EN4JAEFG.js → server-PV5PFQ7A.js} +39 -12
- package/dist/server-PV5PFQ7A.js.map +1 -0
- package/dist/{static-server-7OTKQJZM.js → static-server-7NG4AY2E.js} +5 -5
- package/dist/static-server-7NG4AY2E.js.map +1 -0
- package/package.json +2 -3
- package/dist/chunk-OJEPFH5L.js.map +0 -1
- package/dist/chunk-QOSNX2RN.js.map +0 -1
- package/dist/chunk-UOEFVNM4.js.map +0 -1
- package/dist/chunk-ZUBE6H6H.js.map +0 -1
- package/dist/server-EN4JAEFG.js.map +0 -1
- package/dist/static-server-7OTKQJZM.js.map +0 -1
- /package/dist/{chunk-C5SWGZ55.js.map → chunk-PEG6K5NX.js.map} +0 -0
- /package/dist/{data-source-XSFJYQNF.js.map → data-source-I5BXXWXI.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/dev/data-source.ts","../../cms-core/src/utils/liquid/analysis/template.utils.ts","../../cms-core/src/utils/static/editor/html-editor.utils.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { getLiquidThemeCollectionHandles, getLiquidThemeEntityQueries, getLiquidThemeEntitySources, getLiquidThemeReachableBuffers, getLiquidThemeTemplateCategory, requiresCurrentEntry } from '@tomsher/cms-core/utils';\nimport { themeTemplateCategoryKeys } from '@tomsher/cms-core/constants';\nimport { collectThemeLinkTargetReferences } from '@tomsher/cms-core/utils';\nimport type { CmsClient, RemoteRoute, ThemePreviewRequest } from '../cms-client';\nimport { CliError } from '../errors';\nimport { sha256Hex } from '../hash';\n\nexport interface PreviewData {\n entities: Record<string, Record<string, unknown>>;\n contentCollections: Record<string, unknown>;\n linkTargets?: Record<string, unknown>;\n page?: Record<string, unknown>;\n collection?: Record<string, unknown>;\n}\n\nexport interface DataSourceInput {\n templatePath: string;\n buffers: Record<string, string>;\n path?: string;\n}\n\nexport interface DataSource {\n load: (input: DataSourceInput) => Promise<PreviewData>;\n resolveRoute?: (path: string, templatePaths: string[]) => Promise<string | null>;\n listRoutes?: () => Promise<RemoteRoute[]>;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n};\n\nconst emptyPreviewData = (): PreviewData => {\n return { entities: {}, contentCollections: {} };\n};\n\nconst hasLinkTargetReferences = (content: string): boolean => {\n try {\n return collectThemeLinkTargetReferences(JSON.parse(content)).length > 0;\n } catch {\n return false;\n }\n};\n\n// Mirrors useThemeVisualBuilderEntities in the admin editor.\nexport const buildPreviewRequest = (buffers: Record<string, string>, templatePath: string, path?: string): ThemePreviewRequest => {\n const reachable = getLiquidThemeReachableBuffers(buffers, templatePath);\n const category = getLiquidThemeTemplateCategory(templatePath);\n const page = category === themeTemplateCategoryKeys.collections || category === themeTemplateCategoryKeys.details ? { templatePath, category, ...(path ? { path } : {}) } : undefined;\n const entities = getLiquidThemeEntityQueries(reachable, templatePath).filter((query) => page || !requiresCurrentEntry(query));\n const contentCollections = getLiquidThemeCollectionHandles(buffers, templatePath);\n const sources = getLiquidThemeEntitySources(reachable, templatePath);\n\n const templatePaths = Object.keys(buffers).filter((path) => /^templates\\/[^/]+\\.json$/.test(path));\n const linkSources = Object.entries(buffers)\n .filter(([path, content]) => path.endsWith('.json') && hasLinkTargetReferences(content))\n .map(([, content]) => content);\n\n return { entities, contentCollections, sources, linkSources, templatePaths, page };\n};\n\n// The response is either the envelope { requestedData } or a bare payload; the editor reads requestedData.\nexport const normalizePreviewData = (raw: unknown): PreviewData => {\n const body = isRecord(raw) ? raw : {};\n let payload: Record<string, unknown> = body;\n\n if (isRecord(body.requestedData)) {\n payload = body.requestedData;\n } else if (isRecord(body.data)) {\n payload = body.data;\n }\n\n return {\n entities: isRecord(payload.entities) ? (payload.entities as PreviewData['entities']) : {},\n contentCollections: isRecord(payload.contentCollections) ? payload.contentCollections : {},\n linkTargets: isRecord(payload.linkTargets) ? payload.linkTargets : undefined,\n page: isRecord(payload.page) ? payload.page : undefined,\n collection: isRecord(payload.collection) ? payload.collection : undefined,\n };\n};\n\nexport const createFixturesDataSource = (themeDir: string): DataSource => {\n return {\n load: async ({ templatePath }) => {\n const fixturePath = join(themeDir, 'fixtures', templatePath.replace(/\\//g, '-'));\n let raw: string;\n\n try {\n raw = await readFile(fixturePath, 'utf8');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return emptyPreviewData();\n }\n\n throw error;\n }\n\n try {\n return normalizePreviewData(JSON.parse(raw));\n } catch {\n throw new CliError(`${fixturePath} is not valid JSON.`);\n }\n },\n };\n};\n\nexport interface LiveDataSourceOptions {\n client: CmsClient;\n themeId: string;\n countryCode?: string;\n}\n\nconst hasPreviewWork = (request: ThemePreviewRequest): boolean => {\n return request.entities.length > 0 || request.contentCollections.length > 0 || request.linkSources.length > 0 || Boolean(request.page);\n};\n\n// The key covers the query inputs only, so markup and CSS edits that keep the same queries reuse the cached data.\nconst cacheKeyOf = (request: ThemePreviewRequest): string => {\n const keyInput = { entities: request.entities, contentCollections: request.contentCollections, linkSources: request.linkSources, templatePaths: request.templatePaths, page: request.page };\n return sha256Hex(new TextEncoder().encode(JSON.stringify(keyInput)));\n};\n\n// Cached until the process restarts; a restart is also the only time theme metadata is read again.\nexport const createLiveDataSource = (options: LiveDataSourceOptions): DataSource => {\n const cache = new Map<string, Promise<PreviewData>>();\n\n return {\n resolveRoute: (path, templatePaths) => options.client.resolveRoute(options.themeId, path, templatePaths, options.countryCode),\n listRoutes: () => options.client.listRoutes(options.themeId, options.countryCode),\n load: async ({ buffers, templatePath, path }) => {\n const request = buildPreviewRequest(buffers, templatePath, path);\n\n if (!hasPreviewWork(request)) {\n return emptyPreviewData();\n }\n\n const key = cacheKeyOf(request);\n const cached = cache.get(key);\n\n if (cached) {\n return cached;\n }\n\n const pending = options.client\n .previewData(options.themeId, request, options.countryCode)\n .then(normalizePreviewData);\n\n cache.set(key, pending);\n pending.catch(() => {\n if (cache.get(key) === pending) {\n cache.delete(key);\n }\n });\n\n return pending;\n },\n };\n};\n","import { themeTemplateCategories, themeTemplateCategoryKeys, type ThemeTemplateCategory } from '../../../constants/theme';\nimport { liquidThemeFolderNames, liquidThemeTemplatePaths } from '../../../constants/theme';\n\nexport const getLiquidThemeTemplateCategory = (path: string): ThemeTemplateCategory | 'system' | null => {\n if (path === liquidThemeTemplatePaths.index) return themeTemplateCategoryKeys.pages;\n if (path === liquidThemeTemplatePaths.collection) return themeTemplateCategoryKeys.collections;\n if (path === liquidThemeTemplatePaths.entityDetails) return themeTemplateCategoryKeys.details;\n if (path === liquidThemeTemplatePaths.notFound) return themeTemplateCategoryKeys.system;\n\n for (const category of Object.keys(themeTemplateCategories) as (keyof typeof themeTemplateCategories)[]) {\n const prefix = themeTemplateCategories[category].prefix;\n if (!prefix) continue;\n const categoryPrefix = `${liquidThemeFolderNames.templates}/${prefix}`;\n const name = path.startsWith(categoryPrefix) ? path.slice(categoryPrefix.length) : '';\n if (/^[a-z0-9][a-z0-9_-]*\\.json$/.test(name)) return category;\n }\n return null;\n};\n\nexport const getLiquidThemeTemplateTitle = (path: string, category?: ThemeTemplateCategory): string => {\n if (path === liquidThemeTemplatePaths.index) return 'Home page';\n if (path === liquidThemeTemplatePaths.collection) return 'Collection';\n if (path === liquidThemeTemplatePaths.entityDetails) return 'Entity details';\n\n const templateCategory = category || getLiquidThemeTemplateCategory(path);\n const prefix = templateCategory && templateCategory !== themeTemplateCategoryKeys.system ? themeTemplateCategories[templateCategory].prefix : null;\n const templateName = path.replace(`${liquidThemeFolderNames.templates}/`, '').replace(/\\.json$/, '').replace(prefix || '', '');\n return templateName.replace(/[-_]/g, ' ').replace(/\\b\\w/g, (letter) => letter.toUpperCase());\n};\n\nexport const createLiquidThemeTemplatePath = (category: ThemeTemplateCategory, name: string): string =>\n `${liquidThemeFolderNames.templates}/${themeTemplateCategories[category].prefix}${name}.json`;\n","import { staticThemeFolderNames, staticThemeHtmlExtensionPattern } from '../../../constants/theme';\n\nexport const getStaticHtmlPaths = (files: Array<{ path: string }>): string[] =>\n files\n .map((file) => file.path)\n .filter((path) => path.startsWith(`${staticThemeFolderNames.root}/`) && staticThemeHtmlExtensionPattern.test(path))\n .sort();\n\nexport const getStaticHtmlPageOptions = (paths: string[]) => paths.map((path) => ({ value: path, label: path }));\n\nexport const getStaticHtmlPageContent = (\n selectedPath: string,\n fileBuffers: Record<string, string | undefined>,\n files: Array<{ path: string; content?: string | null }>,\n): string => selectedPath ? fileBuffers[selectedPath] ?? files.find((file) => file.path === selectedPath)?.content ?? '' : '';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY;;;ACEd,IAAM,iCAAiC,CAAC,SAA0D;AACrG,MAAI,SAAS,yBAAyB,MAAO,QAAO,0BAA0B;AAC9E,MAAI,SAAS,yBAAyB,WAAY,QAAO,0BAA0B;AACnF,MAAI,SAAS,yBAAyB,cAAe,QAAO,0BAA0B;AACtF,MAAI,SAAS,yBAAyB,SAAU,QAAO,0BAA0B;A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,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
liquidThemeAllowedDirectories,
|
|
4
4
|
sha256Hex
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-VY553LTO.js";
|
|
6
6
|
|
|
7
7
|
// src/lib/theme-files.ts
|
|
8
8
|
import { readdir, readFile } from "fs/promises";
|
|
@@ -53,4 +53,4 @@ export {
|
|
|
53
53
|
readLocalTheme,
|
|
54
54
|
toHashMap
|
|
55
55
|
};
|
|
56
|
-
//# sourceMappingURL=chunk-
|
|
56
|
+
//# sourceMappingURL=chunk-PEG6K5NX.js.map
|
|
@@ -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
|
-
|
|
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-
|
|
28
|
+
} from "./chunk-VY553LTO.js";
|
|
21
29
|
|
|
22
30
|
// ../node_modules/lodash/isArray.js
|
|
23
31
|
var require_isArray = __commonJS({
|
|
@@ -875,298 +883,10 @@ var require_get = __commonJS({
|
|
|
875
883
|
}
|
|
876
884
|
});
|
|
877
885
|
|
|
878
|
-
// ../cms-
|
|
879
|
-
var liquidAssetUrlPatterns = {
|
|
880
|
-
themeAssetPrefix: /^assets\//i
|
|
881
|
-
};
|
|
882
|
-
var maxRenderMs = 3e3;
|
|
883
|
-
var maxOutputBytes = 1024 * 1024;
|
|
884
|
-
var maxTemplateChars = 128 * 1024;
|
|
885
|
-
var maxPackageChars = 4 * 1024 * 1024;
|
|
886
|
-
var maxIterations = 1e6;
|
|
887
|
-
var maxIncludeDepth = 8;
|
|
888
|
-
var maxContextDepth = 12;
|
|
889
|
-
var maxContextArray = 1e3;
|
|
890
|
-
var maxContextKeys = 500;
|
|
891
|
-
var publicContextKeys = /* @__PURE__ */ new Set(["shop", "settings", "routes", "page", "collection", "contentCollections", "linkTargets", "localization", "search", "entities", "forms", "contentLoading", "contentError", "pageTitle", "section", "item"]);
|
|
892
|
-
var privateField = /^(?:__proto__|prototype|constructor|password|secret|token|access[_-]?token|refresh[_-]?token|api[_-]?key|private[_-]?key|notification[_-]?emails|internal[_-]?notes)$/i;
|
|
893
|
-
var allowedTags = /* @__PURE__ */ new Set(["assign", "for", "capture", "case", "comment", "cycle", "if", "unless", "break", "continue", "echo", "raw", "liquid", "#", "tablerow", "increment", "decrement", "render", "section"]);
|
|
894
|
-
var allowedFilters = /* @__PURE__ */ new Set([
|
|
895
|
-
"abs",
|
|
896
|
-
"append",
|
|
897
|
-
"at_least",
|
|
898
|
-
"at_most",
|
|
899
|
-
"capitalize",
|
|
900
|
-
"ceil",
|
|
901
|
-
"compact",
|
|
902
|
-
"concat",
|
|
903
|
-
"date",
|
|
904
|
-
"default",
|
|
905
|
-
"divided_by",
|
|
906
|
-
"downcase",
|
|
907
|
-
"escape",
|
|
908
|
-
"escape_once",
|
|
909
|
-
"first",
|
|
910
|
-
"floor",
|
|
911
|
-
"join",
|
|
912
|
-
"last",
|
|
913
|
-
"lstrip",
|
|
914
|
-
"map",
|
|
915
|
-
"minus",
|
|
916
|
-
"modulo",
|
|
917
|
-
"newline_to_br",
|
|
918
|
-
"plus",
|
|
919
|
-
"prepend",
|
|
920
|
-
"remove",
|
|
921
|
-
"remove_first",
|
|
922
|
-
"replace",
|
|
923
|
-
"replace_first",
|
|
924
|
-
"reverse",
|
|
925
|
-
"round",
|
|
926
|
-
"rstrip",
|
|
927
|
-
"size",
|
|
928
|
-
"slice",
|
|
929
|
-
"sort",
|
|
930
|
-
"sort_natural",
|
|
931
|
-
"split",
|
|
932
|
-
"strip",
|
|
933
|
-
"strip_html",
|
|
934
|
-
"strip_newlines",
|
|
935
|
-
"times",
|
|
936
|
-
"truncate",
|
|
937
|
-
"truncatewords",
|
|
938
|
-
"uniq",
|
|
939
|
-
"upcase",
|
|
940
|
-
"url_encode",
|
|
941
|
-
"where",
|
|
942
|
-
"assetUrl",
|
|
943
|
-
"stylesheetTag",
|
|
944
|
-
"scriptTag",
|
|
945
|
-
"t",
|
|
946
|
-
"json",
|
|
947
|
-
"imageUrl",
|
|
948
|
-
"richtext",
|
|
949
|
-
"localizeUrl"
|
|
950
|
-
]);
|
|
951
|
-
var defaultTemplate = liquidThemeTemplatePaths.index;
|
|
952
|
-
var defaultLayout = "theme";
|
|
953
|
-
var isSafePartialName = (name) => /^[a-zA-Z0-9][a-zA-Z0-9/_-]{0,127}(?:\.liquid|\.html)?$/.test(name) && !name.includes("//");
|
|
954
|
-
var blockTagPatterns = [
|
|
955
|
-
/\{%\s*schema\s*%\}[\s\S]*?\{%\s*endschema\s*%\}/gi,
|
|
956
|
-
/\{%\s*stylesheet\s*%\}[\s\S]*?\{%\s*endstylesheet\s*%\}/gi,
|
|
957
|
-
/\{%\s*javascript\s*%\}[\s\S]*?\{%\s*endjavascript\s*%\}/gi,
|
|
958
|
-
/\{%\s*entityQuery\b[^%]*%\}/gi
|
|
959
|
-
];
|
|
960
|
-
var themePostMessageEvents = {
|
|
961
|
-
select: "THEME_CUSTOMIZER_SELECT"
|
|
962
|
-
};
|
|
963
|
-
var customCssKey = "customCss";
|
|
964
|
-
|
|
965
|
-
// ../cms-theme-engines/dist/chunk-X4AIS34X.js
|
|
966
|
-
import sanitizeHtml from "sanitize-html";
|
|
967
|
-
|
|
968
|
-
// ../cms-core/dist/utils/index.js
|
|
969
|
-
var setTranslatableArrayFieldPathValue = (target, schemaFields, fieldPath, value, isTranslatable) => {
|
|
970
|
-
const path = fieldPath.split(".");
|
|
971
|
-
const rootField = schemaFields.find((field) => field.type === customFieldTypeConstants.array && String(field.id ?? field.key ?? field.name) === path[0]);
|
|
972
|
-
if (!rootField || path.length < 3 || path.length % 2 !== 1) return false;
|
|
973
|
-
let targetValue = target[rootField.id ?? rootField.key ?? rootField.name ?? ""];
|
|
974
|
-
let nestedFields = rootField.settings?.fields || rootField.fields || [];
|
|
975
|
-
for (let index = 1; index < path.length; index += 2) {
|
|
976
|
-
const arrayIndex = Number(path[index]);
|
|
977
|
-
const fieldId = path[index + 1];
|
|
978
|
-
const nestedField = nestedFields.find((field) => String(field.name ?? field.key ?? field.id) === fieldId);
|
|
979
|
-
if (!Number.isInteger(arrayIndex) || !nestedField || !Array.isArray(targetValue) || !targetValue[arrayIndex]) return false;
|
|
980
|
-
if (index === path.length - 2) {
|
|
981
|
-
if (!isTranslatable(nestedField)) return false;
|
|
982
|
-
targetValue[arrayIndex][fieldId] = value;
|
|
983
|
-
return true;
|
|
984
|
-
}
|
|
985
|
-
if (nestedField.type !== customFieldTypeConstants.array) return false;
|
|
986
|
-
targetValue = targetValue[arrayIndex][fieldId];
|
|
987
|
-
nestedFields = nestedField.settings?.fields || nestedField.fields || [];
|
|
988
|
-
}
|
|
989
|
-
return false;
|
|
990
|
-
};
|
|
991
|
-
var hasTranslatableFields = (schemaFields, componentsMap = {}, isFieldTranslatable = (field) => Boolean(field.settings?.isTranslatable)) => {
|
|
992
|
-
if (!Array.isArray(schemaFields)) return false;
|
|
993
|
-
return schemaFields.some((f) => {
|
|
994
|
-
if (isFieldTranslatable(f)) return true;
|
|
995
|
-
const nestedFields = f.settings?.fields || f.fields;
|
|
996
|
-
if (Array.isArray(nestedFields)) {
|
|
997
|
-
return hasTranslatableFields(nestedFields, componentsMap, isFieldTranslatable);
|
|
998
|
-
}
|
|
999
|
-
if (f.type === customFieldTypeConstants.component) {
|
|
1000
|
-
const nestedCompId = f.settings?.componentId || f.validations?.componentId;
|
|
1001
|
-
const nestedComp = componentsMap[nestedCompId];
|
|
1002
|
-
if (nestedComp?.schema) {
|
|
1003
|
-
return hasTranslatableFields(nestedComp.schema, componentsMap, isFieldTranslatable);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
return false;
|
|
1007
|
-
});
|
|
1008
|
-
};
|
|
1009
|
-
var buildStorefrontLocalePrefix = ({ countryCode, languageCode, includeCountry, includeLanguage }) => [
|
|
1010
|
-
...includeCountry && countryCode ? [countryCode.toLowerCase()] : [],
|
|
1011
|
-
...includeLanguage && languageCode ? [languageCode.toLowerCase()] : []
|
|
1012
|
-
];
|
|
1013
|
-
var findStorefrontLanguage = (languages, languageCode) => {
|
|
1014
|
-
if (!languageCode) return void 0;
|
|
1015
|
-
const normalizedCode = languageCode.toLowerCase();
|
|
1016
|
-
return languages.find((language) => language.languageCode.toLowerCase() === normalizedCode);
|
|
1017
|
-
};
|
|
1018
|
-
var getStorefrontLocalePrefix = (localization) => {
|
|
1019
|
-
if (!localization) return [];
|
|
1020
|
-
return buildStorefrontLocalePrefix({
|
|
1021
|
-
countryCode: localization.country?.countryCode,
|
|
1022
|
-
languageCode: localization.language?.languageCode,
|
|
1023
|
-
includeCountry: localization.availableCountries.length > 1,
|
|
1024
|
-
includeLanguage: localization.availableLanguages.length > 1
|
|
1025
|
-
});
|
|
1026
|
-
};
|
|
1027
|
-
var localizeStorefrontUrl = (url, localization) => {
|
|
1028
|
-
const value = String(url || "/");
|
|
1029
|
-
if (/^(?:[a-z]+:)?\/\//i.test(value) || value.startsWith("mailto:") || value.startsWith("tel:") || value.startsWith("#") || value.startsWith("?")) return value;
|
|
1030
|
-
const prefix = getStorefrontLocalePrefix(localization);
|
|
1031
|
-
if (!prefix.length) return value;
|
|
1032
|
-
const match = value.match(/^([^?#]*)([?#].*)?$/);
|
|
1033
|
-
const path = match?.[1] || "/";
|
|
1034
|
-
const suffix = match?.[2] || "";
|
|
1035
|
-
const segments = path.split("/").filter(Boolean);
|
|
1036
|
-
const alreadyLocalized = prefix.every((segment, index) => segments[index]?.toLowerCase() === segment);
|
|
1037
|
-
if (alreadyLocalized) return value;
|
|
1038
|
-
const targetCountry = localization?.availableCountries.find((country) => country.countryCode.toLowerCase() === segments[0]?.toLowerCase());
|
|
1039
|
-
if (targetCountry) {
|
|
1040
|
-
const targetLanguages = targetCountry.languages || [];
|
|
1041
|
-
if (targetLanguages.length <= 1 || findStorefrontLanguage(targetLanguages, segments[1])) return value;
|
|
1042
|
-
} else if (localization?.availableCountries.length === 1 && findStorefrontLanguage(localization.availableLanguages, segments[0])) {
|
|
1043
|
-
return value;
|
|
1044
|
-
}
|
|
1045
|
-
return `/${[...prefix, ...segments].join("/")}${suffix}` || "/";
|
|
1046
|
-
};
|
|
1047
|
-
var localizeStorefrontRoutes = (routes, localization) => Object.fromEntries(Object.entries(routes).map(([key, value]) => [key, typeof value === "string" ? localizeStorefrontUrl(value, localization) : value]));
|
|
1048
|
-
var getThemeEntityQueryKey = (query) => `${query.type}:${query.handle}:${query.as || ""}`;
|
|
1049
|
-
var hasNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
1050
|
-
var isSafeExternalThemeUrl = (value) => {
|
|
1051
|
-
if (typeof value !== "string") return false;
|
|
1052
|
-
try {
|
|
1053
|
-
const url = new URL(value);
|
|
1054
|
-
return url.protocol === "https:" && Boolean(url.hostname) && !url.username && !url.password;
|
|
1055
|
-
} catch {
|
|
1056
|
-
return false;
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
var isThemeLinkTargetReference = (value) => {
|
|
1060
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1061
|
-
const reference = value;
|
|
1062
|
-
if (reference.kind === themeLinkTargetKinds.external) return isSafeExternalThemeUrl(reference.url);
|
|
1063
|
-
if (!hasNonEmptyString(reference.provider)) return false;
|
|
1064
|
-
if (!hasNonEmptyString(reference.entityId)) return false;
|
|
1065
|
-
if (reference.kind === themeLinkTargetKinds.single || reference.kind === themeLinkTargetKinds.listing) return true;
|
|
1066
|
-
return reference.kind === themeLinkTargetKinds.entry && hasNonEmptyString(reference.entryId);
|
|
1067
|
-
};
|
|
1068
|
-
var normalizeThemeLinkTargetReference = (value) => {
|
|
1069
|
-
if (!isThemeLinkTargetReference(value)) return null;
|
|
1070
|
-
if (value.kind === themeLinkTargetKinds.external) {
|
|
1071
|
-
return {
|
|
1072
|
-
kind: value.kind,
|
|
1073
|
-
url: value.url.trim()
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
if (value.kind === themeLinkTargetKinds.entry) {
|
|
1077
|
-
return {
|
|
1078
|
-
kind: value.kind,
|
|
1079
|
-
provider: value.provider.trim(),
|
|
1080
|
-
entityId: value.entityId.trim(),
|
|
1081
|
-
entryId: value.entryId.trim()
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
return {
|
|
1085
|
-
kind: value.kind,
|
|
1086
|
-
provider: value.provider.trim(),
|
|
1087
|
-
entityId: value.entityId.trim()
|
|
1088
|
-
};
|
|
1089
|
-
};
|
|
1090
|
-
var getThemeLinkTargetReferenceKey = (value) => {
|
|
1091
|
-
const reference = normalizeThemeLinkTargetReference(value);
|
|
1092
|
-
return reference ? JSON.stringify(reference) : null;
|
|
1093
|
-
};
|
|
1094
|
-
var safeDecodeAssetPath = (path) => {
|
|
1095
|
-
try {
|
|
1096
|
-
return decodeURIComponent(path);
|
|
1097
|
-
} catch {
|
|
1098
|
-
return path;
|
|
1099
|
-
}
|
|
1100
|
-
};
|
|
1101
|
-
var findThemeAssetUrl = (assetUrls, assetPath) => {
|
|
1102
|
-
const candidates = [.../* @__PURE__ */ new Set([assetPath, safeDecodeAssetPath(assetPath)])];
|
|
1103
|
-
for (const candidate of candidates) {
|
|
1104
|
-
if (assetUrls[candidate]) return assetUrls[candidate];
|
|
1105
|
-
}
|
|
1106
|
-
return void 0;
|
|
1107
|
-
};
|
|
1108
|
-
var findThemeAssetUrlBySuffix = (assetUrls, assetPath) => {
|
|
1109
|
-
const candidates = [.../* @__PURE__ */ new Set([assetPath, safeDecodeAssetPath(assetPath)])].map((candidate) => candidate.toLowerCase());
|
|
1110
|
-
return Object.entries(assetUrls).find(([path]) => {
|
|
1111
|
-
const lowerPath = path.toLowerCase();
|
|
1112
|
-
return candidates.some((candidate) => lowerPath.endsWith(`/${candidate}`));
|
|
1113
|
-
})?.[1];
|
|
1114
|
-
};
|
|
1115
|
-
var rewriteThemeCssAssetUrls = (content, assetUrls) => content.replace(/url\(\s*(['"]?)(?!data:|https?:|blob:|\/)([^'"\)]+)\1\s*\)/gi, (match, quote, assetPath) => {
|
|
1116
|
-
const normalizedPath = assetPath.trim().replace(/^\.\//, "");
|
|
1117
|
-
const assetUrl = findThemeAssetUrl(assetUrls, normalizedPath) || findThemeAssetUrlBySuffix(assetUrls, normalizedPath);
|
|
1118
|
-
return assetUrl ? `url(${quote}${assetUrl}${quote})` : match;
|
|
1119
|
-
});
|
|
1120
|
-
var rewriteThemeHtmlAssetUrls = (content, assetUrls) => content.replace(/\b(src|href|poster)=(['"])(\.\/)?assets\/([^'"]+)\2/gi, (match, attribute, quote, _relativePrefix, assetPath) => {
|
|
1121
|
-
const normalizedPath = assetPath.split(/[?#]/, 1)[0];
|
|
1122
|
-
const assetUrl = findThemeAssetUrl(assetUrls, normalizedPath);
|
|
1123
|
-
return assetUrl ? `${attribute}=${quote}${assetUrl}${assetPath.slice(normalizedPath.length)}${quote}` : match;
|
|
1124
|
-
});
|
|
1125
|
-
var isThemeMarkupFile = (filename) => filename.startsWith(`${liquidThemeFolderNames.layout}/`) || filename.startsWith(`${liquidThemeFolderNames.sections}/`) || filename.startsWith(`${liquidThemeFolderNames.snippets}/`);
|
|
1126
|
-
var rewriteLiquidThemeAssetBuffers = (buffers, assetUrls) => {
|
|
1127
|
-
const rewrittenBuffers = { ...buffers };
|
|
1128
|
-
for (const [filename, content] of Object.entries(buffers)) {
|
|
1129
|
-
if (!content) continue;
|
|
1130
|
-
if (filename.endsWith(".css")) rewrittenBuffers[filename] = rewriteThemeCssAssetUrls(content, assetUrls);
|
|
1131
|
-
if (isThemeMarkupFile(filename)) rewrittenBuffers[filename] = rewriteThemeHtmlAssetUrls(content, assetUrls);
|
|
1132
|
-
}
|
|
1133
|
-
return rewrittenBuffers;
|
|
1134
|
-
};
|
|
1135
|
-
var unsafeAssetPathCharacterPattern = /%(?![0-9a-f]{2})|[^a-z0-9._~:/@!$*+,;=%-]/giu;
|
|
1136
|
-
var encodeAssetPathCharacters = (path) => path.replace(unsafeAssetPathCharacterPattern, (character) => encodeURIComponent(character));
|
|
1137
|
-
var encodeThemeAssetUrl = (url) => {
|
|
1138
|
-
if (/^(?:data|blob):/i.test(url)) return url;
|
|
1139
|
-
const suffixStart = url.search(/[?#]/);
|
|
1140
|
-
if (suffixStart === -1) return encodeAssetPathCharacters(url);
|
|
1141
|
-
return `${encodeAssetPathCharacters(url.slice(0, suffixStart))}${url.slice(suffixStart).replace(/ /g, "%20")}`;
|
|
1142
|
-
};
|
|
1143
|
-
var getThemeAssetUrls = (files, rootDirectory, resolveMediaUrl) => Object.fromEntries(files.flatMap((file) => {
|
|
1144
|
-
const filename = file.path || file.filename;
|
|
1145
|
-
if (!filename || !file.fileUrl || !filename.startsWith(`${rootDirectory}/`)) return [];
|
|
1146
|
-
const paths = [filename, filename.slice(rootDirectory.length + 1)];
|
|
1147
|
-
const url = encodeThemeAssetUrl(resolveMediaUrl(file.fileUrl));
|
|
1148
|
-
return paths.map((path) => [path, url]);
|
|
1149
|
-
}));
|
|
1150
|
-
var decodeHtmlAttribute = (value) => value.replace(/"/g, '"').replace(/�*39;/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
1151
|
-
var extractThemeStylesheets = (html) => {
|
|
1152
|
-
const stylesheets = /* @__PURE__ */ new Set();
|
|
1153
|
-
const content = html.replace(/<link\b[^>]*\brel=(['"])stylesheet\1[^>]*>/gi, (link) => {
|
|
1154
|
-
const href = link.match(/\bhref=(['"])(.*?)\1/i)?.[2];
|
|
1155
|
-
if (href) stylesheets.add(decodeHtmlAttribute(href));
|
|
1156
|
-
return "";
|
|
1157
|
-
});
|
|
1158
|
-
return { html: content, stylesheets: [...stylesheets] };
|
|
1159
|
-
};
|
|
1160
|
-
var renderThemeHtmlWithStylesheets = ({ html, stylesheets }) => {
|
|
1161
|
-
if (!stylesheets.length) return html;
|
|
1162
|
-
const links = stylesheets.map((href) => `<link rel="stylesheet" href="${href.replace(/&/g, "&").replace(/"/g, """)}">`).join("");
|
|
1163
|
-
return /<head\b[^>]*>/i.test(html) ? html.replace(/<head\b[^>]*>/i, (head) => `${head}${links}`) : `${links}${html}`;
|
|
1164
|
-
};
|
|
1165
|
-
var ensureThemeStylesheetsBeforeContent = (html) => renderThemeHtmlWithStylesheets(extractThemeStylesheets(html));
|
|
1166
|
-
|
|
1167
|
-
// ../cms-theme-engines/dist/chunk-X4AIS34X.js
|
|
886
|
+
// ../cms-core/dist/chunk-BJUDFFBW.js
|
|
1168
887
|
var import_get = __toESM(require_get(), 1);
|
|
1169
888
|
var import_get2 = __toESM(require_get(), 1);
|
|
889
|
+
import sanitizeHtml from "sanitize-html";
|
|
1170
890
|
var formatImageUrl = (url) => {
|
|
1171
891
|
if (!url) return "";
|
|
1172
892
|
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("blob:") || url.startsWith("data:")) return url;
|
|
@@ -1262,6 +982,46 @@ var sanitizeRichtext = (html) => {
|
|
|
1262
982
|
if (html === null || html === void 0) return "";
|
|
1263
983
|
return sanitizeHtml(String(html), richtextSanitizeOptions);
|
|
1264
984
|
};
|
|
985
|
+
var buildStorefrontLocalePrefix = ({ countryCode, languageCode, includeCountry, includeLanguage }) => [
|
|
986
|
+
...includeCountry && countryCode ? [countryCode.toLowerCase()] : [],
|
|
987
|
+
...includeLanguage && languageCode ? [languageCode.toLowerCase()] : []
|
|
988
|
+
];
|
|
989
|
+
var findStorefrontLanguage = (languages, languageCode) => {
|
|
990
|
+
if (!languageCode) return void 0;
|
|
991
|
+
const normalizedCode = languageCode.toLowerCase();
|
|
992
|
+
return languages.find((language) => language.languageCode.toLowerCase() === normalizedCode);
|
|
993
|
+
};
|
|
994
|
+
var getStorefrontLocalePrefix = (localization) => {
|
|
995
|
+
if (!localization) return [];
|
|
996
|
+
return buildStorefrontLocalePrefix({
|
|
997
|
+
countryCode: localization.country?.countryCode,
|
|
998
|
+
languageCode: localization.language?.languageCode,
|
|
999
|
+
includeCountry: localization.availableCountries.length > 1,
|
|
1000
|
+
includeLanguage: localization.availableLanguages.length > 1
|
|
1001
|
+
});
|
|
1002
|
+
};
|
|
1003
|
+
var localizeStorefrontUrl = (url, localization) => {
|
|
1004
|
+
const value = String(url || "/");
|
|
1005
|
+
if (/^(?:[a-z]+:)?\/\//i.test(value) || value.startsWith("mailto:") || value.startsWith("tel:") || value.startsWith("#") || value.startsWith("?")) return value;
|
|
1006
|
+
const prefix = getStorefrontLocalePrefix(localization);
|
|
1007
|
+
if (!prefix.length) return value;
|
|
1008
|
+
const match = value.match(/^([^?#]*)([?#].*)?$/);
|
|
1009
|
+
const path = match?.[1] || "/";
|
|
1010
|
+
const suffix = match?.[2] || "";
|
|
1011
|
+
const segments = path.split("/").filter(Boolean);
|
|
1012
|
+
const alreadyLocalized = prefix.every((segment, index) => segments[index]?.toLowerCase() === segment);
|
|
1013
|
+
if (alreadyLocalized) return value;
|
|
1014
|
+
const targetCountry = localization?.availableCountries.find((country) => country.countryCode.toLowerCase() === segments[0]?.toLowerCase());
|
|
1015
|
+
if (targetCountry) {
|
|
1016
|
+
const targetLanguages = targetCountry.languages || [];
|
|
1017
|
+
if (targetLanguages.length <= 1 || findStorefrontLanguage(targetLanguages, segments[1])) return value;
|
|
1018
|
+
} else if (localization?.availableCountries.length === 1 && findStorefrontLanguage(localization.availableLanguages, segments[0])) {
|
|
1019
|
+
return value;
|
|
1020
|
+
}
|
|
1021
|
+
return `/${[...prefix, ...segments].join("/")}${suffix}` || "/";
|
|
1022
|
+
};
|
|
1023
|
+
var localizeStorefrontRoutes = (routes, localization) => Object.fromEntries(Object.entries(routes).map(([key, value]) => [key, typeof value === "string" ? localizeStorefrontUrl(value, localization) : value]));
|
|
1024
|
+
var getThemeEntityQueryKey = (query) => `${query.type}:${query.handle}:${query.as || ""}`;
|
|
1265
1025
|
var sanitizeContent = (value, key = "") => {
|
|
1266
1026
|
if (Array.isArray(value)) return value.map((item) => sanitizeContent(item, key));
|
|
1267
1027
|
if (value && typeof value === "object") {
|
|
@@ -1342,6 +1102,143 @@ function extractSectionSchema(liquidSource) {
|
|
|
1342
1102
|
return null;
|
|
1343
1103
|
}
|
|
1344
1104
|
}
|
|
1105
|
+
var hasNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
1106
|
+
var isSafeExternalThemeUrl = (value) => {
|
|
1107
|
+
if (typeof value !== "string") return false;
|
|
1108
|
+
try {
|
|
1109
|
+
const url = new URL(value);
|
|
1110
|
+
return url.protocol === "https:" && Boolean(url.hostname) && !url.username && !url.password;
|
|
1111
|
+
} catch {
|
|
1112
|
+
return false;
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
var isThemeLinkTargetReference = (value) => {
|
|
1116
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1117
|
+
const reference = value;
|
|
1118
|
+
if (reference.kind === themeLinkTargetKinds.external) return isSafeExternalThemeUrl(reference.url);
|
|
1119
|
+
if (!hasNonEmptyString(reference.provider)) return false;
|
|
1120
|
+
if (!hasNonEmptyString(reference.entityId)) return false;
|
|
1121
|
+
if (reference.kind === themeLinkTargetKinds.single || reference.kind === themeLinkTargetKinds.listing) return true;
|
|
1122
|
+
return reference.kind === themeLinkTargetKinds.entry && hasNonEmptyString(reference.entryId);
|
|
1123
|
+
};
|
|
1124
|
+
var normalizeThemeLinkTargetReference = (value) => {
|
|
1125
|
+
if (!isThemeLinkTargetReference(value)) return null;
|
|
1126
|
+
if (value.kind === themeLinkTargetKinds.external) {
|
|
1127
|
+
return {
|
|
1128
|
+
kind: value.kind,
|
|
1129
|
+
url: value.url.trim()
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
if (value.kind === themeLinkTargetKinds.entry) {
|
|
1133
|
+
return {
|
|
1134
|
+
kind: value.kind,
|
|
1135
|
+
provider: value.provider.trim(),
|
|
1136
|
+
entityId: value.entityId.trim(),
|
|
1137
|
+
entryId: value.entryId.trim()
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
return {
|
|
1141
|
+
kind: value.kind,
|
|
1142
|
+
provider: value.provider.trim(),
|
|
1143
|
+
entityId: value.entityId.trim()
|
|
1144
|
+
};
|
|
1145
|
+
};
|
|
1146
|
+
var getThemeLinkTargetReferenceKey = (value) => {
|
|
1147
|
+
const reference = normalizeThemeLinkTargetReference(value);
|
|
1148
|
+
return reference ? JSON.stringify(reference) : null;
|
|
1149
|
+
};
|
|
1150
|
+
var collectThemeLinkTargetReferences = (value) => {
|
|
1151
|
+
const references = /* @__PURE__ */ new Map();
|
|
1152
|
+
const visit = (current) => {
|
|
1153
|
+
if (Array.isArray(current)) {
|
|
1154
|
+
current.forEach(visit);
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
if (!current || typeof current !== "object") return;
|
|
1158
|
+
if (current.kind === themeLinkTargetKinds.external) return;
|
|
1159
|
+
const reference = normalizeThemeLinkTargetReference(current);
|
|
1160
|
+
const key = reference && getThemeLinkTargetReferenceKey(reference);
|
|
1161
|
+
if (reference && key) {
|
|
1162
|
+
references.set(key, reference);
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
Object.values(current).forEach(visit);
|
|
1166
|
+
};
|
|
1167
|
+
visit(value);
|
|
1168
|
+
return [...references.values()];
|
|
1169
|
+
};
|
|
1170
|
+
var safeDecodeAssetPath = (path) => {
|
|
1171
|
+
try {
|
|
1172
|
+
return decodeURIComponent(path);
|
|
1173
|
+
} catch {
|
|
1174
|
+
return path;
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
var findThemeAssetUrl = (assetUrls, assetPath) => {
|
|
1178
|
+
const candidates = [.../* @__PURE__ */ new Set([assetPath, safeDecodeAssetPath(assetPath)])];
|
|
1179
|
+
for (const candidate of candidates) {
|
|
1180
|
+
if (assetUrls[candidate]) return assetUrls[candidate];
|
|
1181
|
+
}
|
|
1182
|
+
return void 0;
|
|
1183
|
+
};
|
|
1184
|
+
var findThemeAssetUrlBySuffix = (assetUrls, assetPath) => {
|
|
1185
|
+
const candidates = [.../* @__PURE__ */ new Set([assetPath, safeDecodeAssetPath(assetPath)])].map((candidate) => candidate.toLowerCase());
|
|
1186
|
+
return Object.entries(assetUrls).find(([path]) => {
|
|
1187
|
+
const lowerPath = path.toLowerCase();
|
|
1188
|
+
return candidates.some((candidate) => lowerPath.endsWith(`/${candidate}`));
|
|
1189
|
+
})?.[1];
|
|
1190
|
+
};
|
|
1191
|
+
var rewriteThemeCssAssetUrls = (content, assetUrls) => content.replace(/url\(\s*(['"]?)(?!data:|https?:|blob:|\/)([^'"\)]+)\1\s*\)/gi, (match, quote, assetPath) => {
|
|
1192
|
+
const normalizedPath = assetPath.trim().replace(/^\.\//, "");
|
|
1193
|
+
const assetUrl = findThemeAssetUrl(assetUrls, normalizedPath) || findThemeAssetUrlBySuffix(assetUrls, normalizedPath);
|
|
1194
|
+
return assetUrl ? `url(${quote}${assetUrl}${quote})` : match;
|
|
1195
|
+
});
|
|
1196
|
+
var rewriteThemeHtmlAssetUrls = (content, assetUrls) => content.replace(/\b(src|href|poster)=(['"])(\.\/)?assets\/([^'"]+)\2/gi, (match, attribute, quote, _relativePrefix, assetPath) => {
|
|
1197
|
+
const normalizedPath = assetPath.split(/[?#]/, 1)[0];
|
|
1198
|
+
const assetUrl = findThemeAssetUrl(assetUrls, normalizedPath);
|
|
1199
|
+
return assetUrl ? `${attribute}=${quote}${assetUrl}${assetPath.slice(normalizedPath.length)}${quote}` : match;
|
|
1200
|
+
});
|
|
1201
|
+
var isThemeMarkupFile = (filename) => filename.startsWith(`${liquidThemeFolderNames.layout}/`) || filename.startsWith(`${liquidThemeFolderNames.sections}/`) || filename.startsWith(`${liquidThemeFolderNames.snippets}/`);
|
|
1202
|
+
var rewriteLiquidThemeAssetBuffers = (buffers, assetUrls) => {
|
|
1203
|
+
const rewrittenBuffers = { ...buffers };
|
|
1204
|
+
for (const [filename, content] of Object.entries(buffers)) {
|
|
1205
|
+
if (!content) continue;
|
|
1206
|
+
if (filename.endsWith(".css")) rewrittenBuffers[filename] = rewriteThemeCssAssetUrls(content, assetUrls);
|
|
1207
|
+
if (isThemeMarkupFile(filename)) rewrittenBuffers[filename] = rewriteThemeHtmlAssetUrls(content, assetUrls);
|
|
1208
|
+
}
|
|
1209
|
+
return rewrittenBuffers;
|
|
1210
|
+
};
|
|
1211
|
+
var unsafeAssetPathCharacterPattern = /%(?![0-9a-f]{2})|[^a-z0-9._~:/@!$*+,;=%-]/giu;
|
|
1212
|
+
var encodeAssetPathCharacters = (path) => path.replace(unsafeAssetPathCharacterPattern, (character) => encodeURIComponent(character));
|
|
1213
|
+
var encodeThemeAssetUrl = (url) => {
|
|
1214
|
+
if (/^(?:data|blob):/i.test(url)) return url;
|
|
1215
|
+
const suffixStart = url.search(/[?#]/);
|
|
1216
|
+
if (suffixStart === -1) return encodeAssetPathCharacters(url);
|
|
1217
|
+
return `${encodeAssetPathCharacters(url.slice(0, suffixStart))}${url.slice(suffixStart).replace(/ /g, "%20")}`;
|
|
1218
|
+
};
|
|
1219
|
+
var getThemeAssetUrls = (files, rootDirectory, resolveMediaUrl) => Object.fromEntries(files.flatMap((file) => {
|
|
1220
|
+
const filename = file.path || file.filename;
|
|
1221
|
+
if (!filename || !file.fileUrl || !filename.startsWith(`${rootDirectory}/`)) return [];
|
|
1222
|
+
const paths = [filename, filename.slice(rootDirectory.length + 1)];
|
|
1223
|
+
const url = encodeThemeAssetUrl(resolveMediaUrl(file.fileUrl));
|
|
1224
|
+
return paths.map((path) => [path, url]);
|
|
1225
|
+
}));
|
|
1226
|
+
var decodeHtmlAttribute = (value) => value.replace(/"/g, '"').replace(/�*39;/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
1227
|
+
var extractThemeStylesheets = (html) => {
|
|
1228
|
+
const stylesheets = /* @__PURE__ */ new Set();
|
|
1229
|
+
const content = html.replace(/<link\b[^>]*\brel=(['"])stylesheet\1[^>]*>/gi, (link) => {
|
|
1230
|
+
const href = link.match(/\bhref=(['"])(.*?)\1/i)?.[2];
|
|
1231
|
+
if (href) stylesheets.add(decodeHtmlAttribute(href));
|
|
1232
|
+
return "";
|
|
1233
|
+
});
|
|
1234
|
+
return { html: content, stylesheets: [...stylesheets] };
|
|
1235
|
+
};
|
|
1236
|
+
var renderThemeHtmlWithStylesheets = ({ html, stylesheets }) => {
|
|
1237
|
+
if (!stylesheets.length) return html;
|
|
1238
|
+
const links = stylesheets.map((href) => `<link rel="stylesheet" href="${href.replace(/&/g, "&").replace(/"/g, """)}">`).join("");
|
|
1239
|
+
return /<head\b[^>]*>/i.test(html) ? html.replace(/<head\b[^>]*>/i, (head) => `${head}${links}`) : `${links}${html}`;
|
|
1240
|
+
};
|
|
1241
|
+
var ensureThemeStylesheetsBeforeContent = (html) => renderThemeHtmlWithStylesheets(extractThemeStylesheets(html));
|
|
1345
1242
|
var collectDefaults = (items) => Object.fromEntries(
|
|
1346
1243
|
items.map((setting) => ({
|
|
1347
1244
|
id: setting?.id || setting?.key || setting?.name,
|
|
@@ -1681,6 +1578,46 @@ var getLiquidThemeCollectionHandles = (fileBuffers = {}, selectedTemplate) => {
|
|
|
1681
1578
|
}
|
|
1682
1579
|
return [...handles].slice(0, 20);
|
|
1683
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
|
+
};
|
|
1684
1621
|
var localizedSettingTypes = new Set(Object.values(themeCustomizerLocalizedSettingTypes));
|
|
1685
1622
|
var isThemeCustomizerSettingLocalized = (setting) => {
|
|
1686
1623
|
return hasTranslatableFields([setting], {}, (field) => Boolean(field.settings?.isTranslatable) && localizedSettingTypes.has(String(field.type)));
|
|
@@ -1778,23 +1715,6 @@ var applyThemeCustomizerLocaleOverrides = (fileBuffers, languageCode, defaultLan
|
|
|
1778
1715
|
};
|
|
1779
1716
|
|
|
1780
1717
|
export {
|
|
1781
|
-
maxRenderMs,
|
|
1782
|
-
maxOutputBytes,
|
|
1783
|
-
maxTemplateChars,
|
|
1784
|
-
maxPackageChars,
|
|
1785
|
-
maxIterations,
|
|
1786
|
-
maxIncludeDepth,
|
|
1787
|
-
allowedTags,
|
|
1788
|
-
allowedFilters,
|
|
1789
|
-
defaultTemplate,
|
|
1790
|
-
defaultLayout,
|
|
1791
|
-
isSafePartialName,
|
|
1792
|
-
customCssKey,
|
|
1793
|
-
localizeStorefrontUrl,
|
|
1794
|
-
rewriteLiquidThemeAssetBuffers,
|
|
1795
|
-
getThemeAssetUrls,
|
|
1796
|
-
extractThemeStylesheets,
|
|
1797
|
-
ensureThemeStylesheetsBeforeContent,
|
|
1798
1718
|
require_get,
|
|
1799
1719
|
resolveThemeMediaUrl,
|
|
1800
1720
|
normalizeLiquidAssetValue,
|
|
@@ -1808,12 +1728,18 @@ export {
|
|
|
1808
1728
|
publicContext,
|
|
1809
1729
|
escapeHtml,
|
|
1810
1730
|
sanitizeRichtext,
|
|
1731
|
+
localizeStorefrontUrl,
|
|
1811
1732
|
buildStorefrontDropsContext,
|
|
1812
1733
|
resolveMarkupKey,
|
|
1813
1734
|
sectionKey,
|
|
1814
1735
|
layoutKey,
|
|
1815
1736
|
parseJson,
|
|
1816
1737
|
resolveTemplatePath,
|
|
1738
|
+
collectThemeLinkTargetReferences,
|
|
1739
|
+
rewriteLiquidThemeAssetBuffers,
|
|
1740
|
+
getThemeAssetUrls,
|
|
1741
|
+
extractThemeStylesheets,
|
|
1742
|
+
ensureThemeStylesheetsBeforeContent,
|
|
1817
1743
|
stripSectionSchema,
|
|
1818
1744
|
resolveSectionSettings,
|
|
1819
1745
|
buildSectionScope,
|
|
@@ -1832,4 +1758,4 @@ export {
|
|
|
1832
1758
|
getLiquidThemeCollectionHandles,
|
|
1833
1759
|
applyThemeCustomizerLocaleOverrides
|
|
1834
1760
|
};
|
|
1835
|
-
//# sourceMappingURL=chunk-
|
|
1761
|
+
//# sourceMappingURL=chunk-UMGL5N53.js.map
|