/** * This file is auto generated from JavaDoc. Do not modify it manually. */ import type { ImageScaler } from "../../types/senselogic/sitevision/api/render/ImageScaler"; import type { Node } from "../../types/javax/jcr/Node"; import type { String } from "../../types/java/lang/String"; import type SourceSetMode from "../SourceSetMode"; import type DimensionMode from "../DimensionMode"; import type FetchPriorityMode from "../FetchPriorityMode"; /** * ImageRenderer is a stateful utility interface that can be used to render valid html img elements based on images of the website. * *

* ImageRenderer is very suitable when rendering more than one image or when you want to render images in different sizes than the original * images (e.g. "thumbnails"). ImageRenderer also supports "hover" images, i.e. another image is displayed whenever the cursor hovers over the image. *

* *

* ImageRenderer has few attributes: *

* * *

* Using the ImageRenderer is pretty straightforward, if you remember that it is stateful and that the previously loaded image * will be cleared whenever you try to load a new one. Conceptually you would typically use it like this: *

*
    *
  1. Get the ImageRenderer
  2. *
  3. Possibly init the renderer with rendering settings (useEncoding, useAutoDescription, useTitleRendering, useAutoTitle, sourceSetMode)
  4. *
  5. Possibly set a style
  6. *
  7. Possibly set a hover image
  8. *
  9. Possibly set an image scaler
  10. *
  11. Set an image
  12. *
  13. Possibly set an image description
  14. *
  15. Do render
  16. *
*

* When you have rendered once, you can re-use the ImageRenderer until you are done. Something like: *

*
    *
  1. Update the image
  2. *
  3. Possibly set an image description
  4. *
  5. Do render.
  6. *
* *

* Example of how this strategy could be implemented in Velocity:
* (You want to do a simple listing of some image nodes in a collection/iterator "$images", and for each image a thumbnail should be displayed * on top of the original *

*

 *    ## Get an ImageScaler that scales images to size 200x100
 *    #set ($imageScaler = $sitevisionUtils.getImageScaler(200, 100))
 *
 *    ## Get an ImageRenderer and apply the ImageScaler
 *    #set ($imageRenderer = $sitevisionUtils.imageRenderer)
 *    $imageRenderer.setImageScaler($imageScaler)
 *    $imageRenderer.clearSourceSetMode() ## Disable source set (to ensure it won't interfere with the scaled size)
 *
 *    ## Iterate through images and render them
 *    <ul style="list-style:none">
 *    #foreach ($image in $images)
 *       ## Load an image
 *       $imageRenderer.update($image)
 *
 *       <li>
 *          ## Render the thumbnail (ensure scaler is active)
 *          $imageRenderer.forceUseImageScaler()
 *          $imageRenderer.render()
 *
 *          ## Render image (ensure scaler is inactive)
 *          $imageRenderer.clearUseImageScaler()
 *          $imageRenderer.render()
 *       </li>
 *    #end
 *    </ul>
 *  
* *

* Since ImageRenderer is stateful and likely will be used in Velocity frequently, there are some "shortcuts" that might be useful. * Due to the lack of proper boolean support in Velocity, the boolean attributes has corresponding force/clear methods to set the boolean * to true/false. Due to the lack of proper null support in Velocity, some attributes has clear methods to set the attribute to null. * For example: *

* * *

* * Image type support! This interface accepts all types of images as specified by * {@link senselogic.sitevision.api.webresource.mime.MimeTypeUtil#isImageType(String)}. * This means that all such images can loaded and rendered, but note that not all types can be scaled by an ImageScaler. *

* *

* * Thread Note! The render method is NOT thread safe! If two threads simultaneously executes * the render method on the SAME ImageRenderer instance, the rendered result is undeterminable. This is in almost * all cases nothing you need to worry about, unless your portlet or servlet actually creates a separate Thread * and starts it. If so - ensure all your created threads creates and uses their own ImageRenderer instance! *

* *

* Note/Tip! This interface helps rendering images. If you want to render linked images, you would typically * use the {@link senselogic.sitevision.api.render.ImageLinkRenderer} instead. *

* *

* An instance of the Sitevision class implementing this interface can be obtained via {@link senselogic.sitevision.api.Utils#getImageRenderer()}. * See {@link senselogic.sitevision.api.Utils} for how to obtain an instance of the Utils interface. *

* @author Magnus Lövgren * @since Sitevision 2.6.1_08 */ export interface ImageRenderer { /** * Sets the image scaler that should be used by the renderer if useImageScaler is true. *

* An image scaler is obtained via {@link senselogic.sitevision.api.Utils#getImageScaler(int, int)} *

* @param anImageScaler the image scaler that can be used by the renderer to create scaled images */ setImageScaler(anImageScaler: ImageScaler): void; /** * Removes the image scaler, i.e. executes setImageScaler(null) * @see #setImageScaler(ImageScaler) */ clearImageScaler(): void; /** * Whether or not an image scaler is loaded. * @return true if an image scaler is loaded, false if not. */ isImageScalerLoaded(): boolean; /** * Decides if an image scaler should be used or not. *

* Default is true. *

* @param useImageScaler decides if an image scaler should be used or not. If true, an image scaler will be used if it is set. If false, no image scaler will be used even if it is set. */ setUseImageScaler(useImageScaler: boolean): void; /** * Utility method for executing setUseImageScaler(true) * @see #setUseImageScaler(boolean) */ forceUseImageScaler(): void; /** * Utility method for executing setUseImageScaler(false) * @see #setUseImageScaler(boolean) */ clearUseImageScaler(): void; /** * Sets a hover image that will be activated on the onmouseover JavaScript event. *

* If the rendered image width exceeds 160 pixels, source sets must be disabled via * {@link #setSourceSetMode(SourceSetMode)} with {@link SourceSetMode#OFF} * for the hover image to work. *

* @param anImageNode the hover image (a node with primary node type sv:image) */ setHoverImage(anImageNode: Node): void; /** * Utility method for executing setHoverImage(null) * @see #setHoverImage(javax.jcr.Node) */ clearHoverImage(): void; /** * Whether or not a hover image is loaded. * @return true if a hover image node is loaded, false if not. */ isHoverImageLoaded(): boolean; /** * Sets the image to be rendered. *

* If anImageNode is not a proper image, the image will be considered as null, i.e. * the renderer will not have any image in subsequent render execution. *

* @param anImageNode the image (a node with primary node type sv:image) */ setImage(anImageNode: Node): void; /** * Updates the renderer with a new image. The description will be removed. *

* If anImageNode is not a proper image, the image will be considered as null, i.e. * the renderer will not have any image in subsequent render execution. *

* @param anImageNode the image (a node with primary node type sv:image) */ update(anImageNode: Node): void; /** * Updates the renderer with a new image and a new description. *

* If anImageNode is not a proper image, the image will be considered as null, i.e. * the renderer will not have any image in subsequent render execution. *

* @param anImageNode the image (a node with primary node type sv:image) * @param aDescription an image description, or null to clear any previous description */ update(anImageNode: Node, aDescription: String | string): void; /** * Whether or not an image is loaded. * @return true if an image node is loaded, false if not. */ isImageLoaded(): boolean; /** * A description fallback strategy that makes it possible to render a description value even if no description has been set. * When autoDescription is enabled, the renderer will try to use the image description metadata if no description is set. *

* Default is false. *

* @param useAutoDescription whether or not the renderer should try to get a description via metadata if no description is set */ setUseAutoDescription(useAutoDescription: boolean): void; /** * Utility method for executing setUseAutoDescription(true) * @see #setUseAutoDescription(boolean) */ forceUseAutoDescription(): void; /** * Utility method for executing setUseAutoDescription(false) * @see #setUseAutoDescription(boolean) */ clearUseAutoDescription(): void; /** * The srcset attribute rendering strategy. *

* Default is {@link SourceSetMode#AUTO}. *

* @param aSourceSetMode the source set mode, determines whether or not a srcset attribute should be rendered * @since Sitevision 4.1 */ setSourceSetMode(aSourceSetMode: SourceSetMode): void; /** * Utility method for executing setSourceSetMode({@link SourceSetMode#ON}). * @see #setSourceSetMode(SourceSetMode) * @since Sitevision 4.1 */ forceSourceSetMode(): void; /** * Utility method for executing setSourceSetMode({@link SourceSetMode#OFF}). * @see #setSourceSetMode(SourceSetMode) * @since Sitevision 4.1 */ clearSourceSetMode(): void; /** * Utility method for executing setSourceSetMode({@link SourceSetMode#AUTO}). * @see #setSourceSetMode(SourceSetMode) * @since Sitevision 4.1 */ resetSourceSetMode(): void; /** * The width/height rendering strategy. *

* Default is {@link DimensionMode#AUTO}. *

* @param aDimensionMode the dimension mode, determines how to render width/height css style properties * @since Sitevision 5 */ setDimensionMode(aDimensionMode: DimensionMode): void; /** * Utility method for executing setDimensionMode({@link DimensionMode#ON}). * @since Sitevision 5 */ forceDimensionMode(): void; /** * Utility method for executing setDimensionMode({@link DimensionMode#OFF}). * @since Sitevision 5 */ clearDimensionMode(): void; /** * Utility method for executing setDimensionMode({@link DimensionMode#AUTO}). * @since Sitevision 5 */ resetDimensionMode(): void; /** * The fetchpriority attribute rendering strategy. *

* Default is {@link FetchPriorityMode#OFF}. The attribute should be used sparingly, as excessive or incorrect prioritization can * degrade performance. See MDN Web Docs * for more information. *

* @param aFetchPriorityMode the fetch priority mode, determines whether and how a fetchpriority attribute is rendered. A null value will be completely ignored, use {@link FetchPriorityMode#OFF} to disable fetch priority. * @since Sitevision 2026.10.1 */ setFetchPriorityMode(aFetchPriorityMode: FetchPriorityMode): void; /** * Utility method for executing setFetchPriorityMode({@link FetchPriorityMode#HIGH}). * @see #setFetchPriorityMode(FetchPriorityMode) * @since Sitevision 2026.10.1 */ setFetchPriorityHigh(): void; /** * Utility method for executing setFetchPriorityMode({@link FetchPriorityMode#LOW}). * @see #setFetchPriorityMode(FetchPriorityMode) * @since Sitevision 2026.10.1 */ setFetchPriorityLow(): void; /** * Utility method for executing setFetchPriorityMode({@link FetchPriorityMode#AUTO}). * @see #setFetchPriorityMode(FetchPriorityMode) * @since Sitevision 2026.10.1 */ setFetchPriorityAuto(): void; /** * Utility method for executing setFetchPriorityMode({@link FetchPriorityMode#OFF}). * @see #setFetchPriorityMode(FetchPriorityMode) * @since Sitevision 2026.10.1 */ clearFetchPriorityMode(): void; /** * A title strategy that makes it possible to render a title attribute with the description as value. * If titleRendering is disabled, no title attribute will be rendered at all. If titleRendering is * enabled, the renderer will always render a title attribute and the descripton will be used as value. *

* Default is false. *

* @param useTitleRendering whether or not a title attribute should be rendered * @see #setUseAutoTitle(boolean) * @since Sitevision 2.6.2_04 */ setUseTitleRendering(useTitleRendering: boolean): void; /** * Utility method for executing setUseTitleRendering(true) * @see #setUseTitleRendering(boolean) * @since Sitevision 2.6.2_04 */ forceUseTitleRendering(): void; /** * Utility method for executing setUseTitleRendering(false) * @see #setUseTitleRendering(boolean) * @since Sitevision 2.6.2_04 */ clearUseTitleRendering(): void; /** * A title fallback strategy that makes it possible to render a title value even if no description is available. * When autoTitle is enabled, the renderer will try to use the image description metadata as title value if no description is available. *

* Default is false. *

*

* Note! * This setting would typically be activated only if the title should be rendered (useTitleRendering * is true) and the autoDescription is not activated (useAutoDescription is false). * Remember - the title value is always the description, so any other cases than previously stated won't actually add anything new * to your code/output... *

* @param useAutoTitle whether or not the renderer should try to get a description via metadata to use as title value if no description is available * @see #setUseTitleRendering(boolean) * @since Sitevision 2.6.2_04 */ setUseAutoTitle(useAutoTitle: boolean): void; /** * Utility method for executing setUseAutoTitle(true) * @see #setUseAutoTitle(boolean) * @since Sitevision 2.6.2_04 */ forceUseAutoTitle(): void; /** * Utility method for executing setUseAutoTitle(false) * @see #setUseAutoTitle(boolean) * @since Sitevision 2.6.2_04 */ clearUseAutoTitle(): void; /** * Sets the image description (alt attribute on the img element). * If there are no description (i.e. description is null) when the result is rendered, an empty alt attribute will be rendered * unless the useAutoDescription feature is active (see {@link #setUseAutoDescription(boolean)}). *

* Default is null. *

* @param aDescription an alternative description of the image */ setDescription(aDescription: String | string): void; /** * Removes the description, i.e. executes setDescription(null) * @see #setDescription(String) */ clearDescription(): void; /** * Sets the style (style attribute on the img element). * If there are no style (i.e. style is null) when the result is rendered, no style attribute will be rendered *

* Default is border:none. *

* @param aStyle the style of the rendered element * @since Sitevision 2.6.1_10 */ setStyle(aStyle: String | string): void; /** * Removes the style, i.e. executes setStyle(null) * @see #setStyle(String) * @since Sitevision 2.6.1_10 */ clearStyle(): void; /** * Sets whether or not descriptions should be encoded. *

* Default is true. *

* @param performEncoding whether descriptions should be encoded or not. */ setUseEncoding(performEncoding: boolean): void; /** * Utility method for executing setUseEncoding(true) * @see #setUseEncoding(boolean) */ forceUseEncoding(): void; /** * Utility method for executing setUseEncoding(false) * @see #setUseEncoding(boolean) */ clearUseEncoding(): void; /** * Sets whether or not the image should be lazy loaded (loaded when it appears in the browser's viewport). *

* Note! Lazy loading depends on JavaScript being enabled. * Be sure to include an img in a noscript-tag for non JavaScript users. *

* *

* Default is false. *

* @param aLazyLoad whether the image should be lazy loaded. * @since Sitevision 5.0 */ setLazyLoad(aLazyLoad: boolean): void; /** * Utility method for executing setLazyLoad(true) * @see #setLazyLoad(boolean) * @since Sitevision 5.0 */ forceUseLazyLoad(): void; /** * Utility method for executing setLazyLoad(false) * @see #setLazyLoad(boolean) * @since Sitevision 5.0 */ clearUseLazyLoad(): void; /** * Adds an HTML5 data-* attribute to the image element. * Data attributes are optional when the result is rendered. Default is no data attributes. *

* There can only be one data attribute per name (i.e. when a data attribute is added it will always replace the possibly existing * data attribute that already use that name). *

* *

* Notes about names and values: *

* * @param aName the name of the data attribute * @param aValue the value of the data attribute * @since Sitevision 2023.02.1 */ addDataAttribute(aName: String | string, aValue: String | string): void; /** * Removes all existing data attributes * @since Sitevision 2023.02.1 */ clearDataAttributes(): void; /** * Adds an aria-* attribute to the image element. * Aria attributes are optional when the result is rendered. Default is no aria attributes. *

* There can only be one aria attribute per name (i.e. when an aria attribute is added it will always replace the possibly existing * aria attribute that already use that name). *

* *

* Notes about names and values: *

* * @param aName the name of the aria attribute * @param aValue the value of the aria attribute * @since Sitevision 2023.02.1 */ addAriaAttribute(aName: String | string, aValue: String | string): void; /** * Removes all existing aria attributes * @since Sitevision 2023.02.1 */ clearAriaAttributes(): void; /** * Adds a css class to the class attribute for the image element. *

* Notes about css classes: *

* * @param aClassName the name of the css class * @since Sitevision 2023.02.1 */ addCssClass(aClassName: String | string): void; /** * Removes all existing css classes * @since Sitevision 2023.02.1 */ clearCssClasses(): void; /** * Builds a html img element based on current state. * *

* Note! The render method is not thread safe (see thread note above) * and not all image types can be rendered when using an image scaler (see image support note above). *

* @return if the renderer has a loaded image a html img element, ready to print out on a page, will be returned. If there are no image to render or rendering fails, an empty string will be returned. */ render(): string; } declare namespace ImageRenderer {} declare var imageRenderer: ImageRenderer; export default imageRenderer;