further logging and auto defaults

This commit is contained in:
cupcakearmy 2020-12-20 10:11:22 +01:00
parent 6646c0ff55
commit f4457d0e1b
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9

View File

@ -28,7 +28,7 @@ export function initialize(cloudinary: Configuration.Options, options: InitParam
const defaults: Transformation | Transformation.Options = { const defaults: Transformation | Transformation.Options = {
fetchFormat: 'auto', fetchFormat: 'auto',
quality: 'auto:good', quality: 'auto',
} }
function calculateApproxRealSize(size: string, step: number): number { function calculateApproxRealSize(size: string, step: number): number {
@ -64,8 +64,9 @@ export function image(node: HTMLImageElement, parameters: ImageParameters) {
let { src, options, bind, lazy, step } = parameters let { src, options, bind, lazy, step } = parameters
log('Image Declared', parameters) log('Image Declared', parameters)
options = options || {} options = options ?? {}
step = step ?? 200 step = step ?? 200
lazy = lazy ?? true
if (!cl) throw new Error('Cloudinary not initialized') if (!cl) throw new Error('Cloudinary not initialized')
if (!src) throw new Error('Src must be set in use:image') if (!src) throw new Error('Src must be set in use:image')
@ -91,6 +92,7 @@ export function image(node: HTMLImageElement, parameters: ImageParameters) {
const all: Transformation | Transformation.Options = { ...defaults, ...options } const all: Transformation | Transformation.Options = { ...defaults, ...options }
const attrs: any = cl.imageTag(parameters.src, all).attributes() const attrs: any = cl.imageTag(parameters.src, all).attributes()
log('Attributes', attrs)
const replace = () => (node.src = attrs.src) const replace = () => (node.src = attrs.src)
if (lazy && typeof IntersectionObserver !== 'undefined') { if (lazy && typeof IntersectionObserver !== 'undefined') {