All files / app/mods/media image.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 0/0
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259125x         125x                                                                                                                                   125x                                                                                                                                                                                                                                                                                                                                                                     125x                
import { DateTime } from 'luxon';
import { Plugin } from '../../model/plugin';
import { Mod } from '../../model/tag';
import { Template } from '../../model/template';
 
export const imagePlugin: Plugin = {
  tag: 'plugin/image',
  name: $localize`🖼️ Image`,
  config: {
    mod: $localize`🖼️ Images`,
    version: 4,
    type: 'plugin',
    default: true,
    proxy: true,
    add: true,
    embeddable: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    aiInstructions: ` # plugin/image
    The image plugin indicates a Ref contains an image. It is strongly associated
    with plugin/thumbnail. It contains optional fields { url, width, height } which
    are typically all missing. When the url field is missing it is assumed to be the
    URL of the Ref instead.
    When an image-generation tool is available, use it for requests to create or modify
    images. For every generated image you want retained, return a separate Ref tagged
    plugin/image whose URL is ai:part1, ai:part2, and so on, corresponding to the
    returned assets in order. Never use unnumbered ai:part. Embed the image from the
    first response comment with ![](ai:partN), or link to it with [image](/ref/ai:partN).
    The Ref may include a title, tags, and plugin/image data; when its own URL is
    ai:partN, normally omit plugin/image.url. Only an explicit Ref URL or media-plugin
    URL claims an asset; unclaimed generated assets are discarded. Never invent or
    reference ai:partN unless the corresponding asset was actually returned.
    Claimed assets are uploaded to the cache and all matching references are rewritten.
    Non-ai:part URLs refer to existing resources and are not replaced.
    Only set the width/height in the plugin data to disable autosizing.
    `,
    submit: $localize`🖼️ image`,
    icons: [{ label: $localize`🖼️`, order: 2 }],
    filters: [
      { query: 'plugin/image', label: $localize`🖼️ image`, title: $localize`Images`, group: $localize`Media 🎬️` },
    ],
    extensions: ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'],
    description: $localize`Display an image.`,
    advancedForm: [{
      key: 'url',
      type: 'image',
      props: {
        label: $localize`URL: `,
      },
    }, {
      key: 'width',
      type: 'number',
      props: {
        label: $localize`Width: `,
      },
    }, {
      key: 'height',
      type: 'number',
      props: {
        label: $localize`Height: `,
      },
    }],
  },
  schema: {
    optionalProperties: {
      url: { type: 'string' },
      width: { type: 'uint16' },
      height: { type: 'uint16' },
    },
  },
};
 
export const imageTemplate: Template = {
  tag: 'plugin/image',
  name: $localize`🖼️ Images`,
  config: {
    mod: $localize`🖼️ Images`,
    version: 3,
    type: 'plugin',
    default: true,
    generated: $localize`Generated by jasper-ui ${DateTime.now().toISO()}`,
    view: $localize`🖼️`,
    description: $localize`Activates built-in Image viewer mode for viewing Refs.`,
    // language=CSS
    css: `
      app-ref-list.plugin_image {
        max-width: 100%;
        .list-container {
          grid-auto-flow: row dense;
          padding: 4px;
          gap: 8px;
          grid-template-columns:  1fr;
          @media (min-width: 1000px) {
            grid-template-columns:  1fr 1fr;
          }
          @media (min-width: 1500px) {
            grid-template-columns: 1fr 1fr 1fr;
          }
          @media (min-width: 2000px) {
            grid-template-columns: 1fr 1fr 1fr 1fr;
          }
          .list-number {
            display: none;
          }
          & > .ref {
            position: relative;
            margin: 0;
            padding: 0;
            grid-template-columns:
              [voting] auto
              [thumbnail] auto
              [toggle] auto
              [main] minmax(0, max-content)
              [actions-toggle] auto
              [nav-toggle] auto
              [end] minmax(0, 1fr);
            grid-template-rows: auto auto auto 1fr;
            .expand {
              display: none;
            }
            .image-expand {
              position: relative;
              min-width: 100%;
              min-height: 100%;
              border-radius: 7px;
              overflow: hidden;
              margin: 0;
              padding: 0;
            }
            & > .embed {
              grid-area: 1 / 1 / 5 / -1;
            }
            &::after,
            & > .voting,
            & > .link,
            & > .info,
            & > .actions {
              visibility: hidden;
            }
            &::after {
              content: '';
              grid-area: 1 / voting / 4 / end;
              margin: 6px;
              border-radius: 8px;
              z-index: 1;
              pointer-events: none;
            }
            & > .voting,
            & > .link,
            & > .info,
            & > .actions {
              z-index: 2;
              margin-left: 14px;
            }
            & > .link,
            & > .info,
            & > .actions {
              margin-right: 14px;
              overflow: hidden;
            }
            & > .link {
              grid-row: 1;
              margin-top: 14px;
            }
            & > .info {
              grid-row: 2;
            }
            & > .actions {
              grid-row: 3;
              margin-bottom: 14px;
            }
            &:hover::after,
            &:hover > .voting,
            &:hover > .link,
            &:hover > .info,
            &:hover > .actions {
              visibility: visible;
            }
            & > .embed:focus-within {
              z-index: 3;
            }
            &.mobile-unlock::after,
            &.mobile-unlock > .voting,
            &.mobile-unlock > .link,
            &.mobile-unlock > .info,
            &.mobile-unlock > .actions {
              visibility: visible !important;
            }
            &.mobile-unlock > .embed {
              z-index: auto !important;
            }
            & > .toggle,
            & > .thumbnail {
              display: none;
            }
          }
        }
      }
      body.dark-theme app-ref-list.plugin_image {
        .list-container > .ref::after {
          -webkit-backdrop-filter: grayscale(1) contrast(0.4) brightness(0.4) blur(8px);
          backdrop-filter: grayscale(1) contrast(0.4) brightness(0.4) blur(8px);
          border: 0.5px solid rgba(255, 255, 255, 0.2);
        }
        .list-container > .ref .image-expand {
          -webkit-backdrop-filter: grayscale(1) brightness(0.9) blur(0.5px);
          backdrop-filter: grayscale(1) brightness(0.9) blur(0.5px);
        }
      }
      body.light-theme app-ref-list.plugin_image {
        .list-container > .ref::after {
          -webkit-backdrop-filter: grayscale(1) contrast(0.3) brightness(1.5) blur(8px);
          backdrop-filter: grayscale(1) contrast(0.3) brightness(1.5) blur(8px);
        }
        .list-container > .ref .image-expand {
          -webkit-backdrop-filter: grayscale(1) brightness(0.9) blur(0.5px);
          backdrop-filter: grayscale(1) brightness(0.9) blur(0.5px);
        }
      }
    `,
    advancedForm: [{
      key: 'defaultExpanded',
      type: 'boolean',
      defaultValue: true,
      props: {
        label: $localize`Default Expanded:`,
      },
    }, {
      key: 'hideEdit',
      type: 'boolean',
      defaultValue: true,
      props: {
        label: $localize`Hide Edit:`,
      },
    }, {
      key: 'disableResize',
      type: 'boolean',
      defaultValue: true,
      props: {
        label: $localize`Disable Resize:`,
      },
    }],
  },
  defaults: {
    defaultExpanded: true,
    hideEdit: true,
    disableResize: true,
    defaultCols: 0, // Leave to CSS screen size detection, but show cols dropdown
  }
};
 
export const imageMod: Mod = {
  plugin: [
    imagePlugin,
  ],
   template: [
    imageTemplate,
  ],
};