UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 1.99 kB
{"version":3,"file":"resolve-processing-request.mjs","names":["constants"],"sources":["../../../src/utils/media/resolve-processing-request.ts"],"sourcesContent":["import constants from \"../../constants/constants.js\";\nimport chooseAcceptHeaderFormat from \"./choose-accept-header-format.js\";\n\ntype MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\n\ntype ProcessingPreset = {\n\twidth?: number;\n\theight?: number;\n\tfit?: \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\tformat?: MediaFormat;\n\tquality?: number;\n};\n\ntype ProcessingQuery = {\n\tpreset?: string;\n\tformat?: MediaFormat;\n};\n\n/**\n * Resolves the public processing request into the exact internal options Lucid will use.\n */\nconst resolveProcessingRequest = (props: {\n\tpresets?: Record<string, ProcessingPreset>;\n\tallowFormatQuery: boolean;\n\tquery: ProcessingQuery;\n\taccept?: string;\n}) => {\n\tconst selectedPreset = props.presets?.[props.query.preset ?? \"\"];\n\tconst format = props.allowFormatQuery\n\t\t? chooseAcceptHeaderFormat(props.accept, props.query.format)\n\t\t: selectedPreset?.format;\n\n\treturn {\n\t\tselectedPreset,\n\t\tformat,\n\t\tquality: selectedPreset?.quality ?? constants.media.imagePresetQuality,\n\t\twidth: selectedPreset?.width,\n\t\theight: selectedPreset?.height,\n\t\tfit: selectedPreset?.fit ?? \"cover\",\n\t\thasProcessing: Boolean(selectedPreset || format),\n\t\tpublicQuery: {\n\t\t\tpreset: selectedPreset ? props.query.preset : undefined,\n\t\t\tformat: props.allowFormatQuery ? format : undefined,\n\t\t},\n\t};\n};\n\nexport default resolveProcessingRequest;\n"],"mappings":"8FAqBA,MAAM,EAA4B,GAK5B,CACL,IAAM,EAAiB,EAAM,UAAU,EAAM,MAAM,QAAU,IACvD,EAAS,EAAM,iBAClB,EAAyB,EAAM,OAAQ,EAAM,MAAM,MAAM,EACzD,GAAgB,OAEnB,MAAO,CACN,iBACA,SACA,QAAS,GAAgB,SAAWA,EAAU,MAAM,mBACpD,MAAO,GAAgB,MACvB,OAAQ,GAAgB,OACxB,IAAK,GAAgB,KAAO,QAC5B,cAAe,GAAQ,GAAkB,GACzC,YAAa,CACZ,OAAQ,EAAiB,EAAM,MAAM,OAAS,IAAA,GAC9C,OAAQ,EAAM,iBAAmB,EAAS,IAAA,EAC3C,CACD,CACD"}