@sparted/shared-library 1.0.12 → 1.0.15
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/cdn/cdn.factory.js +10 -13
- package/cdn/cdn.factory.js.map +1 -1
- package/cdn/types/cdn-factory.type.d.ts +6 -0
- package/cdn/utils/twicpics-transformations.util.d.ts +2 -0
- package/cdn/utils/twicpics-transformations.util.js +15 -0
- package/cdn/utils/twicpics-transformations.util.js.map +1 -0
- package/package.json +1 -1
package/cdn/cdn.factory.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var buildSearchParams = require('../http/build-search-params.js');
|
|
6
6
|
var getCdnFromS3Url_util = require('./utils/get-cdn-from-s3-url.util.js');
|
|
7
7
|
var getCdnUrl_util = require('./utils/get-cdn-url.util.js');
|
|
8
|
+
var twicpicsTransformations_util = require('./utils/twicpics-transformations.util.js');
|
|
8
9
|
|
|
9
10
|
const imgixTransformationQueries = ({ fit, width, height, quality, compress = true, devicePixelRatio, }) => {
|
|
10
11
|
const params = {
|
|
@@ -19,21 +20,17 @@ const imgixTransformationQueries = ({ fit, width, height, quality, compress = tr
|
|
|
19
20
|
return searchParams ? `${searchParams}` : '';
|
|
20
21
|
};
|
|
21
22
|
const twicpicsTransformationQueries = (params) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
return `twic=v1/${params.fit}=${params.width}x${params.height}`;
|
|
23
|
+
const transformations = [];
|
|
24
|
+
const width = params.width || '-';
|
|
25
|
+
const height = params.height || '-';
|
|
26
|
+
const fit = params.fit || 'cover';
|
|
27
|
+
if (params.width !== undefined || params.height !== undefined) {
|
|
28
|
+
transformations.push([fit, `${width}x${height}`]);
|
|
29
29
|
}
|
|
30
|
-
if (params.
|
|
31
|
-
|
|
32
|
-
? `x${params.height}`
|
|
33
|
-
: '';
|
|
34
|
-
return `twic=v1/cover=${params.width}${resizeHeight}`;
|
|
30
|
+
if (params.output !== undefined) {
|
|
31
|
+
transformations.push(['output', params.output]);
|
|
35
32
|
}
|
|
36
|
-
return
|
|
33
|
+
return twicpicsTransformations_util.twicpicsTransformationChainToString(transformations);
|
|
37
34
|
};
|
|
38
35
|
/**
|
|
39
36
|
*
|
package/cdn/cdn.factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdn.factory.js","sources":["../../src/cdn/cdn.factory.ts"],"sourcesContent":["import { buildSearchParams } from '../http/build-search-params';\nimport type { CdnConfig, CdnType, TransformationQueries } from './types';\nimport { getCdnFromS3UrlFactory } from './utils/get-cdn-from-s3-url.util';\nimport { getCdnUrlFactory } from './utils/get-cdn-url.util';\n\nexport const imgixTransformationQueries: TransformationQueries = ({\n fit,\n width,\n height,\n quality,\n compress = true,\n devicePixelRatio,\n}) => {\n const params = {\n auto: compress ? 'compress,format' : undefined,\n fit: fit === 'crop' ? 'crop' : undefined,\n dpr: Number.isFinite(devicePixelRatio) ? devicePixelRatio : undefined,\n h: Number.isFinite(height) ? height : undefined,\n w: Number.isFinite(width) ? width : undefined,\n q: quality !== undefined && quality >= 0 && quality <= 100 ? quality : undefined,\n };\n const searchParams = buildSearchParams(params).toString();\n\n return searchParams ? `${searchParams}` : '';\n};\n\nexport const twicpicsTransformationQueries: TransformationQueries = (\n params,\n) => {\n
|
|
1
|
+
{"version":3,"file":"cdn.factory.js","sources":["../../src/cdn/cdn.factory.ts"],"sourcesContent":["import { buildSearchParams } from '../http/build-search-params';\nimport type { CdnConfig, CdnType, TransformationQueries, TwicpicsTransformationChain } from './types';\nimport { getCdnFromS3UrlFactory } from './utils/get-cdn-from-s3-url.util';\nimport { getCdnUrlFactory } from './utils/get-cdn-url.util';\nimport { twicpicsTransformationChainToString } from './utils/twicpics-transformations.util';\n\nexport const imgixTransformationQueries: TransformationQueries = ({\n fit,\n width,\n height,\n quality,\n compress = true,\n devicePixelRatio,\n}) => {\n const params = {\n auto: compress ? 'compress,format' : undefined,\n fit: fit === 'crop' ? 'crop' : undefined,\n dpr: Number.isFinite(devicePixelRatio) ? devicePixelRatio : undefined,\n h: Number.isFinite(height) ? height : undefined,\n w: Number.isFinite(width) ? width : undefined,\n q: quality !== undefined && quality >= 0 && quality <= 100 ? quality : undefined,\n };\n const searchParams = buildSearchParams(params).toString();\n\n return searchParams ? `${searchParams}` : '';\n};\n\nexport const twicpicsTransformationQueries: TransformationQueries = (\n params,\n) => {\n const transformations: TwicpicsTransformationChain = [];\n\n const width = params.width || '-';\n const height = params.height || '-';\n const fit = params.fit || 'cover';\n\n if (params.width !== undefined || params.height !== undefined) {\n transformations.push([fit, `${width}x${height}`]);\n }\n\n if (params.output !== undefined) {\n transformations.push(['output', params.output]);\n }\n\n return twicpicsTransformationChainToString(transformations);\n};\n\n/**\n *\n * @param type cdn provider: 'twicpics' | 'imgix'\n * @param domain provider domain\n * @param instanceMapper domain + the result of the instanceMapper will form the base path\n * @param cacheVersion\n * @returns \\{ getCdnUrl, transformationQueries \\}\n */\nexport const createCdn = <T extends CdnType>({ type, domain, instanceMapper, cacheVersion }: CdnConfig<T>) => {\n const getCdnUrl = getCdnUrlFactory({\n domain,\n instanceMapper,\n transformationQueries:\n type === 'imgix'\n ? imgixTransformationQueries\n : twicpicsTransformationQueries,\n cacheVersion,\n });\n\n return {\n getCdnUrl,\n getCdnFromS3Url: getCdnFromS3UrlFactory({\n getCdnUrl,\n }),\n };\n};\n"],"names":["buildSearchParams","twicpicsTransformationChainToString","getCdnUrlFactory","getCdnFromS3UrlFactory"],"mappings":";;;;;;;;;MAMa,0BAA0B,GAA0B,CAAC,EAChE,GAAG,EACH,KAAK,EACL,MAAM,EACN,OAAO,EACP,QAAQ,GAAG,IAAI,EACf,gBAAgB,GACjB,KAAI;AACH,IAAA,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,QAAQ,GAAG,iBAAiB,GAAG,SAAS;QAC9C,GAAG,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CAAC,CAAC;AACjD,KAAA;AAED,IAAA,OAAOC,gEAAmC,CAAC,eAAe,CAAC,CAAC;AAC9D,EAAE;AAEF;;;;;;;AAOG;AACI,MAAM,SAAS,GAAG,CAAoB,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAgB,KAAI;IAC3G,MAAM,SAAS,GAAGC,+BAAgB,CAAC;QACjC,MAAM;QACN,cAAc;QACd,qBAAqB,EACnB,IAAI,KAAK,OAAO;AACd,cAAE,0BAA0B;AAC5B,cAAE,6BAA6B;QACnC,YAAY;AACb,KAAA,CAAC,CAAC;IAEH,OAAO;QACL,SAAS;QACT,eAAe,EAAEC,2CAAsB,CAAC;YACtC,SAAS;SACV,CAAC;KACH,CAAC;AACJ;;;;;;"}
|
|
@@ -9,12 +9,17 @@ export declare type Transformation = {
|
|
|
9
9
|
* Only for imgix transformations. Default is true.
|
|
10
10
|
*/
|
|
11
11
|
compress?: boolean;
|
|
12
|
+
output?: 'jpeg' | 'png' | 'webp' | 'image';
|
|
12
13
|
};
|
|
13
14
|
export declare type CdnParams = {
|
|
14
15
|
asThumbnail?: boolean;
|
|
15
16
|
transformation?: Transformation;
|
|
16
17
|
};
|
|
17
18
|
export declare type TransformationQueries = (params: Transformation) => string;
|
|
19
|
+
declare type TwicpicsOutputTransformation = ['output', Transformation['output']];
|
|
20
|
+
declare type TwicpicsFitTransformation = ['cover' | 'crop' | 'contain', string];
|
|
21
|
+
export declare type TwicpicsTransformation = TwicpicsOutputTransformation | TwicpicsFitTransformation;
|
|
22
|
+
export declare type TwicpicsTransformationChain = TwicpicsTransformation[];
|
|
18
23
|
export declare type GetCdnUrl = (instanceId: string, path: `/${string}`, params?: CdnParams) => string;
|
|
19
24
|
export declare type GetCdnFromS3Url = (url: string, params?: CdnParams) => string;
|
|
20
25
|
export declare type InstanceMapper = (instanceId: string) => string;
|
|
@@ -29,3 +34,4 @@ export declare type Cdn = {
|
|
|
29
34
|
getCdnUrl: GetCdnUrl;
|
|
30
35
|
getCdnFromS3Url: GetCdnFromS3Url;
|
|
31
36
|
};
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const twicpicsTransformationChainToString = (transformationChain) => {
|
|
6
|
+
if (transformationChain.length === 0)
|
|
7
|
+
return '';
|
|
8
|
+
const transformations = transformationChain
|
|
9
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
10
|
+
.join('/');
|
|
11
|
+
return `twic=v1/${transformations}`;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.twicpicsTransformationChainToString = twicpicsTransformationChainToString;
|
|
15
|
+
//# sourceMappingURL=twicpics-transformations.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"twicpics-transformations.util.js","sources":["../../../src/cdn/utils/twicpics-transformations.util.ts"],"sourcesContent":["import { TwicpicsTransformationChain } from '../types';\n\nexport const twicpicsTransformationChainToString = (\n transformationChain: TwicpicsTransformationChain,\n): string => {\n if (transformationChain.length === 0) return '';\n\n const transformations = transformationChain\n .map(([key, value]) => `${key}=${value}`)\n .join('/');\n\n return `twic=v1/${transformations}`;\n};\n"],"names":[],"mappings":";;;;AAEa,MAAA,mCAAmC,GAAG,CACjD,mBAAgD,KACtC;AACV,IAAA,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,EAAE,CAAC;IAEhD,MAAM,eAAe,GAAG,mBAAmB;AACxC,SAAA,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAG,EAAA,GAAG,CAAI,CAAA,EAAA,KAAK,EAAE,CAAC;SACxC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEb,OAAO,CAAA,QAAA,EAAW,eAAe,CAAA,CAAE,CAAC;AACtC;;;;"}
|