Skip to content

Commit 1897efa

Browse files
imgix-git-robotfrederickfogerty
authored andcommitted
chore(release): 3.4.0
# [3.4.0](v3.2.2...v3.4.0) (2021-12-16) ### Features * dpr srcset options ([#307](#307)) ([380abf0](380abf0))
1 parent 380abf0 commit 1897efa

File tree

8 files changed

+113
-11
lines changed

8 files changed

+113
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [v3.4.0](https://github.com/imgix/js-core/compare/v3.2.2...v3.4.0) (2021-12-16)
6+
7+
### Features
8+
9+
* dpr srcset options ([#307](https://github.com/imgix/js-core/issues/307)) ([380abf0](https://github.com/imgix/js-core/commit/380abf094ce617d6f23208e57b46169ca9949609))
10+
511
## [v3.2.1](https://github.com/imgix/js-core/compare/v3.2.0...v3.2.1) (2021-06-28)
612

713
* build: remove stale `.d.ts` file from `dist` ([#293](https://github.com/imgix/js-core/pull/293))

dist/imgix-js-core.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.cjs.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ function _objectSpread2(target) {
4545
return target;
4646
}
4747

48+
function _typeof(obj) {
49+
"@babel/helpers - typeof";
50+
51+
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
52+
_typeof = function (obj) {
53+
return typeof obj;
54+
};
55+
} else {
56+
_typeof = function (obj) {
57+
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
58+
};
59+
}
60+
61+
return _typeof(obj);
62+
}
63+
4864
function _classCallCheck(instance, Constructor) {
4965
if (!(instance instanceof Constructor)) {
5066
throw new TypeError("Cannot call a class as a function");
@@ -158,7 +174,7 @@ function _nonIterableRest() {
158174
}
159175

160176
// package version used in the ix-lib parameter
161-
var VERSION = '3.2.1'; // regex pattern used to determine if a domain is valid
177+
var VERSION = '3.4.0'; // regex pattern used to determine if a domain is valid
162178

163179
var DOMAIN_REGEX = /^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i; // minimum generated srcset width
164180

@@ -175,6 +191,7 @@ var DPR_QUALITIES = {
175191
4: 23,
176192
5: 20
177193
};
194+
var DEFAULT_DPR = [1, 2, 3, 4, 5];
178195
var DEFAULT_OPTIONS = {
179196
domain: null,
180197
useHTTPS: true,
@@ -230,6 +247,24 @@ function validateVariableQuality(disableVariableQuality) {
230247
throw new Error('The disableVariableQuality argument can only be passed a Boolean value');
231248
}
232249
}
250+
function validateDevicePixelRatios(devicePixelRatios) {
251+
if (!Array.isArray(devicePixelRatios) || !devicePixelRatios.length) {
252+
throw new Error('The devicePixelRatios argument can only be passed a valid non-empty array of integers');
253+
} else {
254+
var allValidDPR = devicePixelRatios.every(function (dpr) {
255+
return typeof dpr === 'number' && dpr >= 1 && dpr <= 5;
256+
});
257+
258+
if (!allValidDPR) {
259+
throw new Error('The devicePixelRatios argument can only contain positive integer values between 1 and 5');
260+
}
261+
}
262+
}
263+
function validateVariableQualities(variableQualities) {
264+
if (_typeof(variableQualities) !== 'object') {
265+
throw new Error('The variableQualities argument can only be an object');
266+
}
267+
}
233268

234269
var ImgixClient = /*#__PURE__*/function () {
235270
function ImgixClient() {
@@ -364,17 +399,27 @@ var ImgixClient = /*#__PURE__*/function () {
364399
value: function _buildDPRSrcSet(path, params, options) {
365400
var _this2 = this;
366401

367-
var targetRatios = [1, 2, 3, 4, 5];
402+
if (options.devicePixelRatios) {
403+
validateDevicePixelRatios(options.devicePixelRatios);
404+
}
405+
406+
var targetRatios = options.devicePixelRatios || DEFAULT_DPR;
368407
var disableVariableQuality = options.disableVariableQuality || false;
369408

370409
if (!disableVariableQuality) {
371410
validateVariableQuality(disableVariableQuality);
372411
}
373412

413+
if (options.variableQualities) {
414+
validateVariableQualities(options.variableQualities);
415+
}
416+
417+
var qualities = _objectSpread2(_objectSpread2({}, DPR_QUALITIES), options.variableQualities);
418+
374419
var withQuality = function withQuality(path, params, dpr) {
375420
return "".concat(_this2.buildURL(path, _objectSpread2(_objectSpread2({}, params), {}, {
376421
dpr: dpr,
377-
q: params.q || DPR_QUALITIES[dpr]
422+
q: params.q || qualities[dpr] || qualities[Math.floor(dpr)]
378423
})), " ").concat(dpr, "x");
379424
};
380425

dist/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ declare class ImgixClient {
2626
): number[];
2727
}
2828

29+
export type DevicePixelRatio = 1 | 2 | 3 | 4 | 5 | number;
30+
31+
export type VariableQualities = { [key in DevicePixelRatio]?: number };
32+
2933
export interface SrcSetOptions {
3034
widths?: number[];
3135
widthTolerance?: number;
3236
minWidth?: number;
3337
maxWidth?: number;
3438
disableVariableQuality?: boolean;
39+
devicePixelRatios?: DevicePixelRatio[];
40+
variableQualities?: VariableQualities;
3541
}
3642

3743
export default ImgixClient;

dist/index.esm.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ function _objectSpread2(target) {
3939
return target;
4040
}
4141

42+
function _typeof(obj) {
43+
"@babel/helpers - typeof";
44+
45+
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
46+
_typeof = function (obj) {
47+
return typeof obj;
48+
};
49+
} else {
50+
_typeof = function (obj) {
51+
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
52+
};
53+
}
54+
55+
return _typeof(obj);
56+
}
57+
4258
function _classCallCheck(instance, Constructor) {
4359
if (!(instance instanceof Constructor)) {
4460
throw new TypeError("Cannot call a class as a function");
@@ -152,7 +168,7 @@ function _nonIterableRest() {
152168
}
153169

154170
// package version used in the ix-lib parameter
155-
var VERSION = '3.2.1'; // regex pattern used to determine if a domain is valid
171+
var VERSION = '3.4.0'; // regex pattern used to determine if a domain is valid
156172

157173
var DOMAIN_REGEX = /^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i; // minimum generated srcset width
158174

@@ -169,6 +185,7 @@ var DPR_QUALITIES = {
169185
4: 23,
170186
5: 20
171187
};
188+
var DEFAULT_DPR = [1, 2, 3, 4, 5];
172189
var DEFAULT_OPTIONS = {
173190
domain: null,
174191
useHTTPS: true,
@@ -224,6 +241,24 @@ function validateVariableQuality(disableVariableQuality) {
224241
throw new Error('The disableVariableQuality argument can only be passed a Boolean value');
225242
}
226243
}
244+
function validateDevicePixelRatios(devicePixelRatios) {
245+
if (!Array.isArray(devicePixelRatios) || !devicePixelRatios.length) {
246+
throw new Error('The devicePixelRatios argument can only be passed a valid non-empty array of integers');
247+
} else {
248+
var allValidDPR = devicePixelRatios.every(function (dpr) {
249+
return typeof dpr === 'number' && dpr >= 1 && dpr <= 5;
250+
});
251+
252+
if (!allValidDPR) {
253+
throw new Error('The devicePixelRatios argument can only contain positive integer values between 1 and 5');
254+
}
255+
}
256+
}
257+
function validateVariableQualities(variableQualities) {
258+
if (_typeof(variableQualities) !== 'object') {
259+
throw new Error('The variableQualities argument can only be an object');
260+
}
261+
}
227262

228263
var ImgixClient = /*#__PURE__*/function () {
229264
function ImgixClient() {
@@ -358,17 +393,27 @@ var ImgixClient = /*#__PURE__*/function () {
358393
value: function _buildDPRSrcSet(path, params, options) {
359394
var _this2 = this;
360395

361-
var targetRatios = [1, 2, 3, 4, 5];
396+
if (options.devicePixelRatios) {
397+
validateDevicePixelRatios(options.devicePixelRatios);
398+
}
399+
400+
var targetRatios = options.devicePixelRatios || DEFAULT_DPR;
362401
var disableVariableQuality = options.disableVariableQuality || false;
363402

364403
if (!disableVariableQuality) {
365404
validateVariableQuality(disableVariableQuality);
366405
}
367406

407+
if (options.variableQualities) {
408+
validateVariableQualities(options.variableQualities);
409+
}
410+
411+
var qualities = _objectSpread2(_objectSpread2({}, DPR_QUALITIES), options.variableQualities);
412+
368413
var withQuality = function withQuality(path, params, dpr) {
369414
return "".concat(_this2.buildURL(path, _objectSpread2(_objectSpread2({}, params), {}, {
370415
dpr: dpr,
371-
q: params.q || DPR_QUALITIES[dpr]
416+
q: params.q || qualities[dpr] || qualities[Math.floor(dpr)]
372417
})), " ").concat(dpr, "x");
373418
};
374419

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@imgix/js-core",
33
"description": "A JavaScript client library for generating image URLs with imgix",
4-
"version": "3.2.2",
4+
"version": "3.4.0",
55
"repository": "https://github.com/imgix/js-core",
66
"license": "BSD-2-Clause",
77
"main": "dist/index.cjs.js",

src/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// package version used in the ix-lib parameter
2-
export const VERSION = '3.2.2';
2+
export const VERSION = '3.4.0';
33
// regex pattern used to determine if a domain is valid
44
export const DOMAIN_REGEX = /^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i;
55
// minimum generated srcset width

0 commit comments

Comments
 (0)