UNPKG

@danielbiegler/vendure-plugin-blurry-image-lazy-loading

Version:

Generates image hashes for displaying blurry previews when loading images on the frontend.

35 lines (34 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PreviewImageHashBase = void 0; /** * Shared logic and values to reduce the boilerplate inside strategies * * @category Strategy */ class PreviewImageHashBase { default = { width: 64, background: { r: 255, g: 255, b: 255, alpha: 1 }, encoding: "base64", }; resizeOptions; encoding; /** * Clones the resize options so as to not mutate the passed in object. * @see args.resizeOptions */ constructor(args) { this.resizeOptions = { ...args.resizeOptions, // By default scale by width width: args.resizeOptions?.width === undefined && args.resizeOptions?.height === undefined ? this.default.width : undefined, // Background is separate because its a reference, whereas the rest are primitive types background: args.resizeOptions?.background ?? this.default.background, }; this.encoding = args.encoding ?? this.default.encoding; } } exports.PreviewImageHashBase = PreviewImageHashBase;