imgix-url-builder 0.0.4 → 0.0.5
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/Client.cjs +143 -0
- package/dist/Client.cjs.map +1 -0
- package/dist/Client.d.ts +145 -0
- package/dist/{index.mjs → Client.js} +11 -41
- package/dist/Client.js.map +1 -0
- package/dist/buildPixelDensitySrcSet.cjs +10 -0
- package/dist/buildPixelDensitySrcSet.cjs.map +1 -0
- package/dist/buildPixelDensitySrcSet.d.ts +58 -0
- package/dist/buildPixelDensitySrcSet.js +10 -0
- package/dist/buildPixelDensitySrcSet.js.map +1 -0
- package/dist/buildURL.cjs +29 -0
- package/dist/buildURL.cjs.map +1 -0
- package/dist/buildURL.d.ts +36 -0
- package/dist/buildURL.js +29 -0
- package/dist/buildURL.js.map +1 -0
- package/dist/buildWidthSrcSet.cjs +10 -0
- package/dist/buildWidthSrcSet.cjs.map +1 -0
- package/dist/buildWidthSrcSet.d.ts +55 -0
- package/dist/buildWidthSrcSet.js +10 -0
- package/dist/buildWidthSrcSet.js.map +1 -0
- package/dist/index.cjs +10 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -2734
- package/dist/index.js +11 -173
- package/dist/index.js.map +1 -0
- package/dist/node/{index.cjs → SecureClient.cjs} +31 -98
- package/dist/node/SecureClient.cjs.map +1 -0
- package/dist/node/SecureClient.d.ts +502 -0
- package/dist/node/{index.mjs → SecureClient.js} +25 -83
- package/dist/node/SecureClient.js.map +1 -0
- package/dist/node/buildSignedPixelDensitySrcSet.cjs +13 -0
- package/dist/node/buildSignedPixelDensitySrcSet.cjs.map +1 -0
- package/dist/node/buildSignedPixelDensitySrcSet.d.ts +54 -0
- package/dist/node/buildSignedPixelDensitySrcSet.js +13 -0
- package/dist/node/buildSignedPixelDensitySrcSet.js.map +1 -0
- package/dist/node/buildSignedURL.cjs +9 -0
- package/dist/node/buildSignedURL.cjs.map +1 -0
- package/dist/node/buildSignedURL.d.ts +49 -0
- package/dist/node/buildSignedURL.js +9 -0
- package/dist/node/buildSignedURL.js.map +1 -0
- package/dist/node/buildSignedWidthSrcSet.cjs +14 -0
- package/dist/node/buildSignedWidthSrcSet.cjs.map +1 -0
- package/dist/node/buildSignedWidthSrcSet.d.ts +54 -0
- package/dist/node/buildSignedWidthSrcSet.js +14 -0
- package/dist/node/buildSignedWidthSrcSet.js.map +1 -0
- package/dist/node/index.d.ts +7 -3196
- package/dist/node/signURL.cjs +12 -0
- package/dist/node/signURL.cjs.map +1 -0
- package/dist/node/signURL.d.ts +27 -0
- package/dist/node/signURL.js +12 -0
- package/dist/node/signURL.js.map +1 -0
- package/dist/node.cjs +15 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.js +15 -0
- package/dist/node.js.map +1 -0
- package/dist/types.generated.d.ts +2746 -0
- package/package.json +57 -33
- package/src/types.generated.ts +1243 -480
- package/dist/index.mjs.map +0 -1
- package/dist/node/index.cjs.map +0 -1
- package/dist/node/index.d.ts.map +0 -1
- package/dist/node/index.mjs.map +0 -1
package/dist/Client.cjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const buildPixelDensitySrcSet = require("./buildPixelDensitySrcSet.cjs");
|
|
7
|
+
const buildURL = require("./buildURL.cjs");
|
|
8
|
+
const buildWidthSrcSet = require("./buildWidthSrcSet.cjs");
|
|
9
|
+
class Client {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new `Client` instance for an Imgix domain.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Options to instantiate a new client.
|
|
14
|
+
*
|
|
15
|
+
* @returns A `Client` instance for the given Imgix domain.
|
|
16
|
+
*/
|
|
17
|
+
constructor(options) {
|
|
18
|
+
__publicField(this, "baseURL");
|
|
19
|
+
this.baseURL = options.baseURL;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Builds a URL to an Imgix image with Imgix URL API parameters for the
|
|
23
|
+
* client's base URL.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const client = new Client({ baseURL: "https://example.imgix.net" });
|
|
29
|
+
* const url = client.buildURLForPath("/image.png", { width: 400 });
|
|
30
|
+
* // => https://example.imgix.net/image.png?width=400
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const client = new Client({
|
|
37
|
+
* baseURL: "https://example.imgix.net/folder",
|
|
38
|
+
* });
|
|
39
|
+
* const url = client.buildURLForPath("./image.png", { width: 400 });
|
|
40
|
+
* // => https://example.imgix.net/folder/image.png?width=400
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param path - Path to the image relative to the client's base URL.
|
|
44
|
+
* @param params - An object of Imgix URL API parameters.
|
|
45
|
+
*
|
|
46
|
+
* @returns The full absolute URL to the image with the given Imgix URL API
|
|
47
|
+
* parameters applied.
|
|
48
|
+
*/
|
|
49
|
+
buildURLForPath(path, params = {}) {
|
|
50
|
+
return buildURL.buildURL(`${new URL(path, this.baseURL)}`, params);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Builds an `<img>` `srcset` attribute value for a given set of widths for
|
|
54
|
+
* the client's base URL. It can also optinally apply Imgix URL API parameters
|
|
55
|
+
* to the URLs.
|
|
56
|
+
*
|
|
57
|
+
* The `width` URL parameter will be applied for each `srcset` entry. If a
|
|
58
|
+
* `width` or `w` parameter is provided to the `params` parameter, it will be
|
|
59
|
+
* ignored.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const client = new Client({ baseURL: "https://example.imgix.net" });
|
|
65
|
+
* const srcset = client.buildWidthSrcSetForPath("/image.png", {
|
|
66
|
+
* widths: [400, 800, 1600],
|
|
67
|
+
* });
|
|
68
|
+
* // => https://example.imgix.net/image.png?width=400 400w,
|
|
69
|
+
* // https://example.imgix.net/image.png?width=800 800w,
|
|
70
|
+
* // https://example.imgix.net/image.png?width=1600 1600w
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const client = new Client({
|
|
77
|
+
* baseURL: "https://example.imgix.net",
|
|
78
|
+
* });
|
|
79
|
+
* const srcset = client.buildWidthSrcSetForPath("/image.png", {
|
|
80
|
+
* widths: [400, 800, 1600],
|
|
81
|
+
* sat: -100,
|
|
82
|
+
* });
|
|
83
|
+
* // => https://example.imgix.net/image.png?width=400&sat=-100 400w,
|
|
84
|
+
* // https://example.imgix.net/image.png?width=800&sat=-100 800w,
|
|
85
|
+
* // https://example.imgix.net/image.png?width=1600&sat=-100 1600w
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @param path - Path to the image relative to the client's base URL.
|
|
89
|
+
* @param params - An object of Imgix URL API parameters. The `widths`
|
|
90
|
+
* parameter defines the resulting `srcset` widths.
|
|
91
|
+
*
|
|
92
|
+
* @returns A `srcset` attribute value for `url` with the given Imgix URL API
|
|
93
|
+
* parameters applied.
|
|
94
|
+
*/
|
|
95
|
+
buildWidthSrcSetForPath(path, params) {
|
|
96
|
+
return buildWidthSrcSet.buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Builds an `<img>` `srcset` attribute value for a given set of pixel
|
|
100
|
+
* densities for the client's base URL. It can also optinally apply Imgix URL
|
|
101
|
+
* API parameters to the URLs.
|
|
102
|
+
*
|
|
103
|
+
* The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`
|
|
104
|
+
* parameter is provided to the `params` parameter, it will be ignored.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* const client = new Client({ baseURL: "https://example.imgix.net" });
|
|
110
|
+
* const srcset = client.buildPixelDensitySrcSetForPath("/image.png", {
|
|
111
|
+
* pixelDensities: [1, 2, 3],
|
|
112
|
+
* });
|
|
113
|
+
* // => https://example.imgix.net/image.png?dpr=1 1x,
|
|
114
|
+
* // https://example.imgix.net/image.png?dpr=2 2x,
|
|
115
|
+
* // https://example.imgix.net/image.png?dpr=3 3x
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* const client = new Client({ baseURL: "https://example.imgix.net" });
|
|
122
|
+
* const srcset = client.buildPixelDensitySrcSetForPath("/image.png", {
|
|
123
|
+
* pixelDensities: [1, 2, 3],
|
|
124
|
+
* sat: -100,
|
|
125
|
+
* });
|
|
126
|
+
* // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,
|
|
127
|
+
* // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,
|
|
128
|
+
* // https://example.imgix.net/image.png?dpr=3&sat=-100 3x
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @param path - Path to the image relative to the client's base URL.
|
|
132
|
+
* @param params - An object of Imgix URL API parameters. The `pixelDensities`
|
|
133
|
+
* parameter defines the resulting `srcset` widths.
|
|
134
|
+
*
|
|
135
|
+
* @returns A `srcset` attribute value for `url` with the given Imgix URL API
|
|
136
|
+
* parameters applied.
|
|
137
|
+
*/
|
|
138
|
+
buildPixelDensitySrcSetForPath(path, params) {
|
|
139
|
+
return buildPixelDensitySrcSet.buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.Client = Client;
|
|
143
|
+
//# sourceMappingURL=Client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.cjs","sources":["../../src/Client.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"./buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"./buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"./types.generated\";\nimport { buildPixelDensitySrcSet } from \"./buildPixelDensitySrcSet\";\nimport { buildURL } from \"./buildURL\";\nimport { buildWidthSrcSet } from \"./buildWidthSrcSet\";\n\n/**\n * Options to instantiate a new client.\n */\nexport type ClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n};\n\n/**\n * An Imgix Rendering API client. A client is paired to a single Imgix domain.\n */\nexport class Client {\n\tbaseURL: string;\n\n\t/**\n\t * Creates a new `Client` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `Client` instance for the given Imgix domain.\n\t */\n\tconstructor(options: ClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}) {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be\n\t * ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(path: string, params: BuildWidthSrcSetParams) {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t) {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n}\n"],"names":["buildURL","buildWidthSrcSet","buildPixelDensitySrcSet"],"mappings":";;;;;;;;MAyBa,OAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUlB,YAAY,SAAsB;AATlC;AAUC,SAAK,UAAU,QAAQ;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8BA,gBAAgB,MAAc,SAAyB,IAAE;AACjD,WAAAA,SAAA,SAAS,GAAG,IAAI,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,MAAM;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6CA,wBAAwB,MAAc,QAA8B;AAC5D,WAAAC,iBAAA,iBAAiB,GAAG,IAAI,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,MAAM;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0CA,+BACC,MACA,QAAqC;AAE9B,WAAAC,wBAAA,wBAAwB,GAAG,IAAI,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,MAAM;AAAA,EACxE;AACA;;"}
|
package/dist/Client.d.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { BuildPixelDensitySrcSetParams } from "./buildPixelDensitySrcSet";
|
|
2
|
+
import type { BuildWidthSrcSetParams } from "./buildWidthSrcSet";
|
|
3
|
+
import type { ImgixURLParams } from "./types.generated";
|
|
4
|
+
/**
|
|
5
|
+
* Options to instantiate a new client.
|
|
6
|
+
*/
|
|
7
|
+
export type ClientOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* The base URL used to construct image URLs from a path. The base URL must
|
|
10
|
+
* include the protocol, domain, and optionally a path.
|
|
11
|
+
*
|
|
12
|
+
* @example `https://example.imgix.net`
|
|
13
|
+
*
|
|
14
|
+
* @example `https://example.imgix.net/folder`
|
|
15
|
+
*/
|
|
16
|
+
baseURL: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* An Imgix Rendering API client. A client is paired to a single Imgix domain.
|
|
20
|
+
*/
|
|
21
|
+
export declare class Client {
|
|
22
|
+
baseURL: string;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new `Client` instance for an Imgix domain.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Options to instantiate a new client.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `Client` instance for the given Imgix domain.
|
|
29
|
+
*/
|
|
30
|
+
constructor(options: ClientOptions);
|
|
31
|
+
/**
|
|
32
|
+
* Builds a URL to an Imgix image with Imgix URL API parameters for the
|
|
33
|
+
* client's base URL.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* const client = new Client({ baseURL: "https://example.imgix.net" });
|
|
39
|
+
* const url = client.buildURLForPath("/image.png", { width: 400 });
|
|
40
|
+
* // => https://example.imgix.net/image.png?width=400
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* const client = new Client({
|
|
47
|
+
* baseURL: "https://example.imgix.net/folder",
|
|
48
|
+
* });
|
|
49
|
+
* const url = client.buildURLForPath("./image.png", { width: 400 });
|
|
50
|
+
* // => https://example.imgix.net/folder/image.png?width=400
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param path - Path to the image relative to the client's base URL.
|
|
54
|
+
* @param params - An object of Imgix URL API parameters.
|
|
55
|
+
*
|
|
56
|
+
* @returns The full absolute URL to the image with the given Imgix URL API
|
|
57
|
+
* parameters applied.
|
|
58
|
+
*/
|
|
59
|
+
buildURLForPath(path: string, params?: ImgixURLParams): string;
|
|
60
|
+
/**
|
|
61
|
+
* Builds an `<img>` `srcset` attribute value for a given set of widths for
|
|
62
|
+
* the client's base URL. It can also optinally apply Imgix URL API parameters
|
|
63
|
+
* to the URLs.
|
|
64
|
+
*
|
|
65
|
+
* The `width` URL parameter will be applied for each `srcset` entry. If a
|
|
66
|
+
* `width` or `w` parameter is provided to the `params` parameter, it will be
|
|
67
|
+
* ignored.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* const client = new Client({ baseURL: "https://example.imgix.net" });
|
|
73
|
+
* const srcset = client.buildWidthSrcSetForPath("/image.png", {
|
|
74
|
+
* widths: [400, 800, 1600],
|
|
75
|
+
* });
|
|
76
|
+
* // => https://example.imgix.net/image.png?width=400 400w,
|
|
77
|
+
* // https://example.imgix.net/image.png?width=800 800w,
|
|
78
|
+
* // https://example.imgix.net/image.png?width=1600 1600w
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* const client = new Client({
|
|
85
|
+
* baseURL: "https://example.imgix.net",
|
|
86
|
+
* });
|
|
87
|
+
* const srcset = client.buildWidthSrcSetForPath("/image.png", {
|
|
88
|
+
* widths: [400, 800, 1600],
|
|
89
|
+
* sat: -100,
|
|
90
|
+
* });
|
|
91
|
+
* // => https://example.imgix.net/image.png?width=400&sat=-100 400w,
|
|
92
|
+
* // https://example.imgix.net/image.png?width=800&sat=-100 800w,
|
|
93
|
+
* // https://example.imgix.net/image.png?width=1600&sat=-100 1600w
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @param path - Path to the image relative to the client's base URL.
|
|
97
|
+
* @param params - An object of Imgix URL API parameters. The `widths`
|
|
98
|
+
* parameter defines the resulting `srcset` widths.
|
|
99
|
+
*
|
|
100
|
+
* @returns A `srcset` attribute value for `url` with the given Imgix URL API
|
|
101
|
+
* parameters applied.
|
|
102
|
+
*/
|
|
103
|
+
buildWidthSrcSetForPath(path: string, params: BuildWidthSrcSetParams): string;
|
|
104
|
+
/**
|
|
105
|
+
* Builds an `<img>` `srcset` attribute value for a given set of pixel
|
|
106
|
+
* densities for the client's base URL. It can also optinally apply Imgix URL
|
|
107
|
+
* API parameters to the URLs.
|
|
108
|
+
*
|
|
109
|
+
* The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`
|
|
110
|
+
* parameter is provided to the `params` parameter, it will be ignored.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* const client = new Client({ baseURL: "https://example.imgix.net" });
|
|
116
|
+
* const srcset = client.buildPixelDensitySrcSetForPath("/image.png", {
|
|
117
|
+
* pixelDensities: [1, 2, 3],
|
|
118
|
+
* });
|
|
119
|
+
* // => https://example.imgix.net/image.png?dpr=1 1x,
|
|
120
|
+
* // https://example.imgix.net/image.png?dpr=2 2x,
|
|
121
|
+
* // https://example.imgix.net/image.png?dpr=3 3x
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* const client = new Client({ baseURL: "https://example.imgix.net" });
|
|
128
|
+
* const srcset = client.buildPixelDensitySrcSetForPath("/image.png", {
|
|
129
|
+
* pixelDensities: [1, 2, 3],
|
|
130
|
+
* sat: -100,
|
|
131
|
+
* });
|
|
132
|
+
* // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,
|
|
133
|
+
* // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,
|
|
134
|
+
* // https://example.imgix.net/image.png?dpr=3&sat=-100 3x
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @param path - Path to the image relative to the client's base URL.
|
|
138
|
+
* @param params - An object of Imgix URL API parameters. The `pixelDensities`
|
|
139
|
+
* parameter defines the resulting `srcset` widths.
|
|
140
|
+
*
|
|
141
|
+
* @returns A `srcset` attribute value for `url` with the given Imgix URL API
|
|
142
|
+
* parameters applied.
|
|
143
|
+
*/
|
|
144
|
+
buildPixelDensitySrcSetForPath(path: string, params: BuildPixelDensitySrcSetParams): string;
|
|
145
|
+
}
|
|
@@ -1,41 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const instance = new URL(url);
|
|
8
|
-
for (const camelCasedParamKey in params) {
|
|
9
|
-
const paramKey = camelCaseToParamCase(camelCasedParamKey);
|
|
10
|
-
const paramValue = params[camelCasedParamKey];
|
|
11
|
-
if (paramValue === void 0) {
|
|
12
|
-
instance.searchParams.delete(paramKey);
|
|
13
|
-
} else if (Array.isArray(paramValue)) {
|
|
14
|
-
instance.searchParams.set(paramKey, paramValue.join(","));
|
|
15
|
-
} else {
|
|
16
|
-
instance.searchParams.set(paramKey, `${paramValue}`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const s = instance.searchParams.get("s");
|
|
20
|
-
if (s) {
|
|
21
|
-
instance.searchParams.delete("s");
|
|
22
|
-
instance.searchParams.append("s", s);
|
|
23
|
-
}
|
|
24
|
-
return instance.toString();
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const buildPixelDensitySrcSet = (url, { pixelDensities, ...params }) => {
|
|
28
|
-
return pixelDensities.map((dpr) => {
|
|
29
|
-
return `${buildURL(url, { ...params, dpr })} ${dpr}x`;
|
|
30
|
-
}).join(", ");
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const buildWidthSrcSet = (url, { widths, ...params }) => {
|
|
34
|
-
return widths.map((width) => {
|
|
35
|
-
return `${buildURL(url, { ...params, w: void 0, width })} ${width}w`;
|
|
36
|
-
}).join(", ");
|
|
37
|
-
};
|
|
38
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { buildPixelDensitySrcSet } from "./buildPixelDensitySrcSet.js";
|
|
5
|
+
import { buildURL } from "./buildURL.js";
|
|
6
|
+
import { buildWidthSrcSet } from "./buildWidthSrcSet.js";
|
|
39
7
|
class Client {
|
|
40
8
|
/**
|
|
41
9
|
* Creates a new `Client` instance for an Imgix domain.
|
|
@@ -45,6 +13,7 @@ class Client {
|
|
|
45
13
|
* @returns A `Client` instance for the given Imgix domain.
|
|
46
14
|
*/
|
|
47
15
|
constructor(options) {
|
|
16
|
+
__publicField(this, "baseURL");
|
|
48
17
|
this.baseURL = options.baseURL;
|
|
49
18
|
}
|
|
50
19
|
/**
|
|
@@ -168,6 +137,7 @@ class Client {
|
|
|
168
137
|
return buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);
|
|
169
138
|
}
|
|
170
139
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
140
|
+
export {
|
|
141
|
+
Client
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=Client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.js","sources":["../../src/Client.ts"],"sourcesContent":["import type { BuildPixelDensitySrcSetParams } from \"./buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"./buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"./types.generated\";\nimport { buildPixelDensitySrcSet } from \"./buildPixelDensitySrcSet\";\nimport { buildURL } from \"./buildURL\";\nimport { buildWidthSrcSet } from \"./buildWidthSrcSet\";\n\n/**\n * Options to instantiate a new client.\n */\nexport type ClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n};\n\n/**\n * An Imgix Rendering API client. A client is paired to a single Imgix domain.\n */\nexport class Client {\n\tbaseURL: string;\n\n\t/**\n\t * Creates a new `Client` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `Client` instance for the given Imgix domain.\n\t */\n\tconstructor(options: ClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}) {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be\n\t * ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(path: string, params: BuildWidthSrcSetParams) {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t) {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n}\n"],"names":[],"mappings":";;;;;;MAyBa,OAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUlB,YAAY,SAAsB;AATlC;AAUC,SAAK,UAAU,QAAQ;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8BA,gBAAgB,MAAc,SAAyB,IAAE;AACjD,WAAA,SAAS,GAAG,IAAI,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,MAAM;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6CA,wBAAwB,MAAc,QAA8B;AAC5D,WAAA,iBAAiB,GAAG,IAAI,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,MAAM;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0CA,+BACC,MACA,QAAqC;AAE9B,WAAA,wBAAwB,GAAG,IAAI,IAAI,MAAM,KAAK,OAAO,CAAC,IAAI,MAAM;AAAA,EACxE;AACA;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const buildURL = require("./buildURL.cjs");
|
|
4
|
+
const buildPixelDensitySrcSet = (url, { pixelDensities, ...params }) => {
|
|
5
|
+
return pixelDensities.map((dpr) => {
|
|
6
|
+
return `${buildURL.buildURL(url, { ...params, dpr })} ${dpr}x`;
|
|
7
|
+
}).join(", ");
|
|
8
|
+
};
|
|
9
|
+
exports.buildPixelDensitySrcSet = buildPixelDensitySrcSet;
|
|
10
|
+
//# sourceMappingURL=buildPixelDensitySrcSet.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildPixelDensitySrcSet.cjs","sources":["../../src/buildPixelDensitySrcSet.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n"],"names":["buildURL"],"mappings":";;;AA4DO,MAAM,0BAA0B,CACtC,KACA,EAAE,gBAAgB,GAAG,aACV;AACJ,SAAA,eACL,IAAI,CAAC,QAAO;AACL,WAAA,GAAGA,SAAAA,SAAS,KAAK,EAAE,GAAG,QAAQ,IAAK,CAAA,CAAC,IAAI,GAAG;AAAA,EAAA,CAClD,EACA,KAAK,IAAI;AACZ;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ImgixURLParams } from "./types.generated";
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for `buildPixelDensitySrcSet`.
|
|
4
|
+
*/
|
|
5
|
+
export type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, "dpr"> & {
|
|
6
|
+
/**
|
|
7
|
+
* The pixel densities to include in the resulting `srcset` value.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* [1, 2, 3];
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
pixelDensities: number[];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Builds an `<img>` `srcset` attribute value for a given set of pixel
|
|
19
|
+
* densities. It can also optinally apply Imgix URL API parameters to the URLs.
|
|
20
|
+
*
|
|
21
|
+
* The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`
|
|
22
|
+
* parameter is provided to the `params` parameter, it will be ignored.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* const srcset = buildPixelDensitySrcSet(
|
|
28
|
+
* "https://example.imgix.net/image.png",
|
|
29
|
+
* { pixelDensities: [1, 2, 3] },
|
|
30
|
+
* );
|
|
31
|
+
* // => https://example.imgix.net/image.png?dpr=1 1x,
|
|
32
|
+
* // https://example.imgix.net/image.png?dpr=2 2x,
|
|
33
|
+
* // https://example.imgix.net/image.png?dpr=3 3x
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* const srcset = buildPixelDensitySrcSet(
|
|
40
|
+
* "https://example.imgix.net/image.png",
|
|
41
|
+
* {
|
|
42
|
+
* pixelDensities: [1, 2, 3],
|
|
43
|
+
* sat: -100,
|
|
44
|
+
* },
|
|
45
|
+
* );
|
|
46
|
+
* // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,
|
|
47
|
+
* // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,
|
|
48
|
+
* // https://example.imgix.net/image.png?dpr=3&sat=-100 3x
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param url - Full absolute URL to the Imgix image.
|
|
52
|
+
* @param params - An object of Imgix URL API parameters. The `pixelDensities`
|
|
53
|
+
* parameter defines the resulting `srcset` widths.
|
|
54
|
+
*
|
|
55
|
+
* @returns A `srcset` attribute value for `url` with the given Imgix URL API
|
|
56
|
+
* parameters applied.
|
|
57
|
+
*/
|
|
58
|
+
export declare const buildPixelDensitySrcSet: (url: string, { pixelDensities, ...params }: BuildPixelDensitySrcSetParams) => string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { buildURL } from "./buildURL.js";
|
|
2
|
+
const buildPixelDensitySrcSet = (url, { pixelDensities, ...params }) => {
|
|
3
|
+
return pixelDensities.map((dpr) => {
|
|
4
|
+
return `${buildURL(url, { ...params, dpr })} ${dpr}x`;
|
|
5
|
+
}).join(", ");
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
buildPixelDensitySrcSet
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=buildPixelDensitySrcSet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildPixelDensitySrcSet.js","sources":["../../src/buildPixelDensitySrcSet.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n"],"names":[],"mappings":";AA4DO,MAAM,0BAA0B,CACtC,KACA,EAAE,gBAAgB,GAAG,aACV;AACJ,SAAA,eACL,IAAI,CAAC,QAAO;AACL,WAAA,GAAG,SAAS,KAAK,EAAE,GAAG,QAAQ,IAAK,CAAA,CAAC,IAAI,GAAG;AAAA,EAAA,CAClD,EACA,KAAK,IAAI;AACZ;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const camelCaseToParamCase = (input) => {
|
|
4
|
+
return input.replace(/[A-Z]/g, (match) => {
|
|
5
|
+
return `-${match.toLowerCase()}`;
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
const buildURL = (url, params) => {
|
|
9
|
+
const instance = new URL(url);
|
|
10
|
+
for (const camelCasedParamKey in params) {
|
|
11
|
+
const paramKey = camelCaseToParamCase(camelCasedParamKey);
|
|
12
|
+
const paramValue = params[camelCasedParamKey];
|
|
13
|
+
if (paramValue === void 0) {
|
|
14
|
+
instance.searchParams.delete(paramKey);
|
|
15
|
+
} else if (Array.isArray(paramValue)) {
|
|
16
|
+
instance.searchParams.set(paramKey, paramValue.join(","));
|
|
17
|
+
} else {
|
|
18
|
+
instance.searchParams.set(paramKey, `${paramValue}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const s = instance.searchParams.get("s");
|
|
22
|
+
if (s) {
|
|
23
|
+
instance.searchParams.delete("s");
|
|
24
|
+
instance.searchParams.append("s", s);
|
|
25
|
+
}
|
|
26
|
+
return instance.toString();
|
|
27
|
+
};
|
|
28
|
+
exports.buildURL = buildURL;
|
|
29
|
+
//# sourceMappingURL=buildURL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildURL.cjs","sources":["../../src/buildURL.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Converts a camel case string to a param case string.\n *\n * @example\n *\n * ```ts\n * camelCaseToParamCase(\"fooBar\");\n * // => 'foo-bar'\n * ```\n *\n * @param input - Camel case string to convert.\n *\n * @returns Param case version of `input`.\n */\nconst camelCaseToParamCase = (input: string): string => {\n\treturn input.replace(/[A-Z]/g, (match) => {\n\t\treturn `-${match.toLowerCase()}`;\n\t});\n};\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params`\n * argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = camelCaseToParamCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n"],"names":[],"mappings":";;AAgBA,MAAM,uBAAuB,CAAC,UAAyB;AACtD,SAAO,MAAM,QAAQ,UAAU,CAAC,UAAS;AACjC,WAAA,IAAI,MAAM,YAAA,CAAa;AAAA,EAAA,CAC9B;AACF;AAoCa,MAAA,WAAW,CAAC,KAAa,WAAkC;AACjE,QAAA,WAAW,IAAI,IAAI,GAAG;AAE5B,aAAW,sBAAsB,QAAQ;AAClC,UAAA,WAAW,qBAAqB,kBAAkB;AAClD,UAAA,aAAa,OAAO,kBAAyC;AAEnE,QAAI,eAAe,QAAW;AACpB,eAAA,aAAa,OAAO,QAAQ;AAAA,IAC3B,WAAA,MAAM,QAAQ,UAAU,GAAG;AACrC,eAAS,aAAa,IAAI,UAAU,WAAW,KAAK,GAAG,CAAC;AAAA,IAAA,OAClD;AACN,eAAS,aAAa,IAAI,UAAU,GAAG,UAAU,EAAE;AAAA,IACpD;AAAA,EACD;AAIA,QAAM,IAAI,SAAS,aAAa,IAAI,GAAG;AACvC,MAAI,GAAG;AACG,aAAA,aAAa,OAAO,GAAG;AACvB,aAAA,aAAa,OAAO,KAAK,CAAC;AAAA,EACpC;AAEA,SAAO,SAAS;AACjB;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ImgixURLParams } from "./types.generated";
|
|
2
|
+
/**
|
|
3
|
+
* Builds a URL to an Imgix image with Imgix URL API parameters.
|
|
4
|
+
*
|
|
5
|
+
* The given URL must be a full absolute URL containing the protocol and domain.
|
|
6
|
+
*
|
|
7
|
+
* URL parameters already applied to the image will be retained. To remove
|
|
8
|
+
* existing parameters, set the parameter to `undefined` in the `params`
|
|
9
|
+
* argument.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const url = buildURL("https://example.imgix.net/image.png", {
|
|
15
|
+
* width: 400,
|
|
16
|
+
* });
|
|
17
|
+
* // => https://example.imgix.net/image.png?width=400
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* const url = buildURL("https://example.imgix.net/image.png?width=400", {
|
|
24
|
+
* height: 300,
|
|
25
|
+
* });
|
|
26
|
+
* // => https://example.imgix.net/image.png?width=400&height=300
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param url - Full absolute URL to the Imgix image.
|
|
30
|
+
* @param params - An object of Imgix URL API parameters.
|
|
31
|
+
*
|
|
32
|
+
* @returns `url` with the given Imgix URL API parameters applied.
|
|
33
|
+
*
|
|
34
|
+
* @see Imgix URL API reference: https://docs.imgix.com/apis/rendering
|
|
35
|
+
*/
|
|
36
|
+
export declare const buildURL: (url: string, params: ImgixURLParams) => string;
|
package/dist/buildURL.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const camelCaseToParamCase = (input) => {
|
|
2
|
+
return input.replace(/[A-Z]/g, (match) => {
|
|
3
|
+
return `-${match.toLowerCase()}`;
|
|
4
|
+
});
|
|
5
|
+
};
|
|
6
|
+
const buildURL = (url, params) => {
|
|
7
|
+
const instance = new URL(url);
|
|
8
|
+
for (const camelCasedParamKey in params) {
|
|
9
|
+
const paramKey = camelCaseToParamCase(camelCasedParamKey);
|
|
10
|
+
const paramValue = params[camelCasedParamKey];
|
|
11
|
+
if (paramValue === void 0) {
|
|
12
|
+
instance.searchParams.delete(paramKey);
|
|
13
|
+
} else if (Array.isArray(paramValue)) {
|
|
14
|
+
instance.searchParams.set(paramKey, paramValue.join(","));
|
|
15
|
+
} else {
|
|
16
|
+
instance.searchParams.set(paramKey, `${paramValue}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const s = instance.searchParams.get("s");
|
|
20
|
+
if (s) {
|
|
21
|
+
instance.searchParams.delete("s");
|
|
22
|
+
instance.searchParams.append("s", s);
|
|
23
|
+
}
|
|
24
|
+
return instance.toString();
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
buildURL
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=buildURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildURL.js","sources":["../../src/buildURL.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Converts a camel case string to a param case string.\n *\n * @example\n *\n * ```ts\n * camelCaseToParamCase(\"fooBar\");\n * // => 'foo-bar'\n * ```\n *\n * @param input - Camel case string to convert.\n *\n * @returns Param case version of `input`.\n */\nconst camelCaseToParamCase = (input: string): string => {\n\treturn input.replace(/[A-Z]/g, (match) => {\n\t\treturn `-${match.toLowerCase()}`;\n\t});\n};\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params`\n * argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = camelCaseToParamCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n"],"names":[],"mappings":"AAgBA,MAAM,uBAAuB,CAAC,UAAyB;AACtD,SAAO,MAAM,QAAQ,UAAU,CAAC,UAAS;AACjC,WAAA,IAAI,MAAM,YAAA,CAAa;AAAA,EAAA,CAC9B;AACF;AAoCa,MAAA,WAAW,CAAC,KAAa,WAAkC;AACjE,QAAA,WAAW,IAAI,IAAI,GAAG;AAE5B,aAAW,sBAAsB,QAAQ;AAClC,UAAA,WAAW,qBAAqB,kBAAkB;AAClD,UAAA,aAAa,OAAO,kBAAyC;AAEnE,QAAI,eAAe,QAAW;AACpB,eAAA,aAAa,OAAO,QAAQ;AAAA,IAC3B,WAAA,MAAM,QAAQ,UAAU,GAAG;AACrC,eAAS,aAAa,IAAI,UAAU,WAAW,KAAK,GAAG,CAAC;AAAA,IAAA,OAClD;AACN,eAAS,aAAa,IAAI,UAAU,GAAG,UAAU,EAAE;AAAA,IACpD;AAAA,EACD;AAIA,QAAM,IAAI,SAAS,aAAa,IAAI,GAAG;AACvC,MAAI,GAAG;AACG,aAAA,aAAa,OAAO,GAAG;AACvB,aAAA,aAAa,OAAO,KAAK,CAAC;AAAA,EACpC;AAEA,SAAO,SAAS;AACjB;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const buildURL = require("./buildURL.cjs");
|
|
4
|
+
const buildWidthSrcSet = (url, { widths, ...params }) => {
|
|
5
|
+
return widths.map((width) => {
|
|
6
|
+
return `${buildURL.buildURL(url, { ...params, w: void 0, width })} ${width}w`;
|
|
7
|
+
}).join(", ");
|
|
8
|
+
};
|
|
9
|
+
exports.buildWidthSrcSet = buildWidthSrcSet;
|
|
10
|
+
//# sourceMappingURL=buildWidthSrcSet.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildWidthSrcSet.cjs","sources":["../../src/buildWidthSrcSet.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<ImgixURLParams, \"width\" | \"w\"> & {\n\t/**\n\t * The pixel widths to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [400, 800, 1600];\n\t * ```\n\t */\n\twidths: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be\n * ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * });\n * // => https://example.imgix.net/image.png?width=400 400w,\n * // https://example.imgix.net/image.png?width=800 800w,\n * // https://example.imgix.net/image.png?width=1600 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildWidthSrcSet = (\n\turl: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n"],"names":["buildURL"],"mappings":";;;AAyDO,MAAM,mBAAmB,CAC/B,KACA,EAAE,QAAQ,GAAG,aACF;AACJ,SAAA,OACL,IAAI,CAAC,UAAS;AACd,WAAO,GAAGA,SAAA,SAAS,KAAK,EAAE,GAAG,QAAQ,GAAG,QAAW,MAAK,CAAE,CAAC,IAAI,KAAK;AAAA,EAAA,CACpE,EACA,KAAK,IAAI;AACZ;;"}
|