Sha256: 7f219072a3e03fa0b638ecd250ec5ae4d8a42c2f02962774979b1ead6592288b

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require "imgix/version"
require "imgix/client"
require "imgix/path"

module Imgix
  # regex pattern used to determine if a domain is valid
  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.freeze

  # determines the growth rate when building out srcset pair widths
  DEFAULT_WIDTH_TOLERANCE = 0.08

  # the default minimum srcset width
  MIN_WIDTH = 100

  # the default maximum srcset width, also the max width supported by imgix
  MAX_WIDTH = 8192

  # returns an array of width values used during scrset generation
  TARGET_WIDTHS = lambda { |tolerance, min, max|
    increment_percentage = tolerance || DEFAULT_WIDTH_TOLERANCE

    unless increment_percentage.is_a?(Numeric) && increment_percentage > 0
      width_increment_error = "error: `width_tolerance` must be a positive `Numeric` value"
      raise ArgumentError, width_increment_error
    end

    max_size = max || MAX_WIDTH
    resolutions = []
    prev = min || MIN_WIDTH

    while prev < max_size
      # ensures that each width is even
      resolutions.push(prev.round)
      prev *= 1 + (increment_percentage * 2)
    end

    resolutions.push(max_size)
    return resolutions
  }

  # hash of default quality parameter values mapped  by each dpr srcset entry
  DPR_QUALITY = {
    1 => 75,
    2 => 50,
    3 => 35,
    4 => 23,
    5 => 20
  }.freeze
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
imgix-4.0.1 lib/imgix.rb
imgix-4.0.0 lib/imgix.rb