@hashicorp/hashi-image
Advanced tools
Comparing version 1.0.6 to 2.0.0-alpha.0
@@ -7,3 +7,3 @@ 'use strict'; | ||
var preact = require('preact'); | ||
var React = _interopDefault(require('react')); | ||
var queryString = _interopDefault(require('query-string')); | ||
@@ -15,13 +15,12 @@ var assign = _interopDefault(require('object-assign')); | ||
_ref$steps = _ref.steps, | ||
steps = _ref$steps === undefined ? [250, 500, 750, 1000, 1500, 2000, 2500] : _ref$steps, | ||
steps = _ref$steps === void 0 ? [250, 500, 750, 1000, 1500, 2000, 2500] : _ref$steps, | ||
_ref$sizes = _ref.sizes, | ||
sizes = _ref$sizes === undefined ? '100vw' : _ref$sizes, | ||
sizes = _ref$sizes === void 0 ? '100vw' : _ref$sizes, | ||
_ref$svg = _ref.svg, | ||
svg = _ref$svg === undefined ? false : _ref$svg, | ||
svg = _ref$svg === void 0 ? false : _ref$svg, | ||
classes = _ref.classes, | ||
aspect_ratio = _ref.aspect_ratio, | ||
_ref$params = _ref.params, | ||
params = _ref$params === undefined ? {} : _ref$params, | ||
params = _ref$params === void 0 ? {} : _ref$params, | ||
alt = _ref.alt; | ||
// set default params, merge user preferences with priority | ||
@@ -32,7 +31,5 @@ var opts = assign({ | ||
q: 80 | ||
}, params); | ||
}, params); // handle aspect ratios & steps passed as a string | ||
// handle aspect ratios & steps passed as a string | ||
aspect_ratio = typeof aspect_ratio === 'string' ? aspect_ratio.split(',').map(Number) : aspect_ratio; | ||
steps = typeof steps === 'string' ? steps.split(',').map(Number) : steps; | ||
@@ -42,3 +39,7 @@ | ||
// if it's an SVG, we don't need the picture element, so return | ||
return preact.h('img', { 'class': classes, src: src, alt: alt }); | ||
return React.createElement("img", { | ||
className: classes, | ||
src: src, | ||
alt: alt | ||
}); | ||
} else { | ||
@@ -48,25 +49,23 @@ // otherwise, we return a picture element with multiple sizes and a webp | ||
var srcDefault = formatSteps(steps, opts, aspect_ratio, src); | ||
var srcWebp = formatSteps(steps, assign({}, opts, { fm: 'webp' }), aspect_ratio, src); | ||
return preact.h( | ||
'picture', | ||
null, | ||
preact.h('source', { type: 'image/webp', srcSet: srcWebp, sizes: sizes }), | ||
preact.h('img', { | ||
'class': classes, | ||
src: format(src, opts, aspect_ratio && aspect_ratio[2], aspect_ratio), | ||
srcSet: srcDefault, | ||
sizes: sizes, | ||
alt: alt | ||
}) | ||
); | ||
var srcWebp = formatSteps(steps, assign({}, opts, { | ||
fm: 'webp' | ||
}), aspect_ratio, src); | ||
return React.createElement("picture", null, React.createElement("source", { | ||
type: "image/webp", | ||
srcSet: srcWebp, | ||
sizes: sizes | ||
}), React.createElement("img", { | ||
className: classes, | ||
src: format(src, opts, aspect_ratio && aspect_ratio[2], aspect_ratio), | ||
srcSet: srcDefault, | ||
sizes: sizes, | ||
alt: alt | ||
})); | ||
} | ||
} | ||
function formatSteps(steps, opts, aspect_ratio, src) { | ||
return steps.map(function (s) { | ||
return format(src, opts, s, aspect_ratio) + ' ' + s + 'w'; | ||
return "".concat(format(src, opts, s, aspect_ratio), " ").concat(s, "w"); | ||
}); | ||
} | ||
function format(src, opts, width, aspect_ratio) { | ||
@@ -76,7 +75,7 @@ var opt = assign({}, opts); | ||
if (width && aspect_ratio) opt.h = aspect_ratio[1] / aspect_ratio[0] * width; | ||
return src + '?' + queryString.stringify(opt); | ||
return "".concat(src, "?").concat(queryString.stringify(opt)); | ||
} | ||
exports.default = Image; | ||
exports.format = format; | ||
exports.formatSteps = formatSteps; | ||
exports.format = format; |
{ | ||
"name": "@hashicorp/hashi-image", | ||
"description": "super optimized image element, pulls from dato and formats for 7 screen sizes in two formats. Skips optimization for SVGs.", | ||
"version": "1.0.6", | ||
"version": "2.0.0-alpha.0", | ||
"author": "Hashicorp - Jeff Escalante", | ||
"main": "dist", | ||
"peerDependencies": { | ||
"dependencies": { | ||
"object-assign": "^4.1.1", | ||
"preact": "^8.2.7", | ||
"query-string": "^5.1.1" | ||
"query-string": "^6.4.2", | ||
"react": "^16.8.6" | ||
}, | ||
"main": "dist", | ||
"publishConfig": { | ||
@@ -18,3 +18,3 @@ "access": "public" | ||
}, | ||
"gitHead": "78236aa1b7f3adda5e4e3dd1d1ba8f084e1c24dc" | ||
"gitHead": "5f9b5a0487251e5846a3eabd9ff839d3fe7e1e31" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4421
68
3
+ Addedobject-assign@^4.1.1
+ Addedquery-string@^6.4.2
+ Addedreact@^16.8.6
+ Addedfilter-obj@1.1.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedquery-string@6.14.1(transitive)
+ Addedreact@16.14.0(transitive)
+ Addedreact-is@16.13.1(transitive)
+ Addedsplit-on-first@1.1.0(transitive)
+ Addedstrict-uri-encode@2.0.0(transitive)
- Removedpreact@8.5.3(transitive)
- Removedquery-string@5.1.1(transitive)
- Removedstrict-uri-encode@1.1.0(transitive)