|
| 1 | +# typed: strong |
| 2 | + |
| 3 | +module Imagekit |
| 4 | + module Models |
| 5 | + class GetImageAttributesOptions < Imagekit::Models::SrcOptions |
| 6 | + OrHash = |
| 7 | + T.type_alias do |
| 8 | + T.any( |
| 9 | + Imagekit::GetImageAttributesOptions, |
| 10 | + Imagekit::Internal::AnyHash |
| 11 | + ) |
| 12 | + end |
| 13 | + |
| 14 | + # Custom list of **device-width breakpoints** in pixels. These define common |
| 15 | + # screen widths for responsive image generation. |
| 16 | + # |
| 17 | + # Defaults to `[640, 750, 828, 1080, 1200, 1920, 2048, 3840]`. Sorted |
| 18 | + # automatically. |
| 19 | + sig { returns(T.nilable(T::Array[Float])) } |
| 20 | + attr_reader :device_breakpoints |
| 21 | + |
| 22 | + sig { params(device_breakpoints: T::Array[Float]).void } |
| 23 | + attr_writer :device_breakpoints |
| 24 | + |
| 25 | + # Custom list of **image-specific breakpoints** in pixels. Useful for generating |
| 26 | + # small variants (e.g., placeholders or thumbnails). |
| 27 | + # |
| 28 | + # Merged with `deviceBreakpoints` before calculating `srcSet`. Defaults to |
| 29 | + # `[16, 32, 48, 64, 96, 128, 256, 384]`. Sorted automatically. |
| 30 | + sig { returns(T.nilable(T::Array[Float])) } |
| 31 | + attr_reader :image_breakpoints |
| 32 | + |
| 33 | + sig { params(image_breakpoints: T::Array[Float]).void } |
| 34 | + attr_writer :image_breakpoints |
| 35 | + |
| 36 | + # The value for the HTML `sizes` attribute (e.g., `"100vw"` or |
| 37 | + # `"(min-width:768px) 50vw, 100vw"`). |
| 38 | + # |
| 39 | + # - If it includes one or more `vw` units, breakpoints smaller than the |
| 40 | + # corresponding percentage of the smallest device width are excluded. |
| 41 | + # - If it contains no `vw` units, the full breakpoint list is used. |
| 42 | + # |
| 43 | + # Enables a width-based strategy and generates `w` descriptors in `srcSet`. |
| 44 | + sig { returns(T.nilable(String)) } |
| 45 | + attr_reader :sizes |
| 46 | + |
| 47 | + sig { params(sizes: String).void } |
| 48 | + attr_writer :sizes |
| 49 | + |
| 50 | + # The intended display width of the image in pixels, used **only when the `sizes` |
| 51 | + # attribute is not provided**. |
| 52 | + # |
| 53 | + # Triggers a DPR-based strategy (1x and 2x variants) and generates `x` descriptors |
| 54 | + # in `srcSet`. |
| 55 | + # |
| 56 | + # Ignored if `sizes` is present. |
| 57 | + sig { returns(T.nilable(Float)) } |
| 58 | + attr_reader :width |
| 59 | + |
| 60 | + sig { params(width: Float).void } |
| 61 | + attr_writer :width |
| 62 | + |
| 63 | + # Options for generating responsive image attributes including `src`, `srcSet`, |
| 64 | + # and `sizes` for HTML `<img>` elements. This schema extends `SrcOptions` to add |
| 65 | + # support for responsive image generation with breakpoints. |
| 66 | + sig do |
| 67 | + params( |
| 68 | + device_breakpoints: T::Array[Float], |
| 69 | + image_breakpoints: T::Array[Float], |
| 70 | + sizes: String, |
| 71 | + width: Float |
| 72 | + ).returns(T.attached_class) |
| 73 | + end |
| 74 | + def self.new( |
| 75 | + # Custom list of **device-width breakpoints** in pixels. These define common |
| 76 | + # screen widths for responsive image generation. |
| 77 | + # |
| 78 | + # Defaults to `[640, 750, 828, 1080, 1200, 1920, 2048, 3840]`. Sorted |
| 79 | + # automatically. |
| 80 | + device_breakpoints: nil, |
| 81 | + # Custom list of **image-specific breakpoints** in pixels. Useful for generating |
| 82 | + # small variants (e.g., placeholders or thumbnails). |
| 83 | + # |
| 84 | + # Merged with `deviceBreakpoints` before calculating `srcSet`. Defaults to |
| 85 | + # `[16, 32, 48, 64, 96, 128, 256, 384]`. Sorted automatically. |
| 86 | + image_breakpoints: nil, |
| 87 | + # The value for the HTML `sizes` attribute (e.g., `"100vw"` or |
| 88 | + # `"(min-width:768px) 50vw, 100vw"`). |
| 89 | + # |
| 90 | + # - If it includes one or more `vw` units, breakpoints smaller than the |
| 91 | + # corresponding percentage of the smallest device width are excluded. |
| 92 | + # - If it contains no `vw` units, the full breakpoint list is used. |
| 93 | + # |
| 94 | + # Enables a width-based strategy and generates `w` descriptors in `srcSet`. |
| 95 | + sizes: nil, |
| 96 | + # The intended display width of the image in pixels, used **only when the `sizes` |
| 97 | + # attribute is not provided**. |
| 98 | + # |
| 99 | + # Triggers a DPR-based strategy (1x and 2x variants) and generates `x` descriptors |
| 100 | + # in `srcSet`. |
| 101 | + # |
| 102 | + # Ignored if `sizes` is present. |
| 103 | + width: nil |
| 104 | + ) |
| 105 | + end |
| 106 | + |
| 107 | + sig do |
| 108 | + override.returns( |
| 109 | + { |
| 110 | + device_breakpoints: T::Array[Float], |
| 111 | + image_breakpoints: T::Array[Float], |
| 112 | + sizes: String, |
| 113 | + width: Float |
| 114 | + } |
| 115 | + ) |
| 116 | + end |
| 117 | + def to_hash |
| 118 | + end |
| 119 | + end |
| 120 | + end |
| 121 | +end |
0 commit comments