1import { p as prop, e as init, i as if_block, d as bind_this, b as set_class } from './i18n-CMo5lpzy.js'; 2import { R as push, a4 as createEventDispatcher, S as first_child, w as get, a as append, T as pop, U as flushSync, ad as derived_safe_equal, G as deep_read_state, z as untrack, X as sibling, W as from_html, V as child, Y as reset, x as set, t as template_effect, Z as event, a3 as mutable_source } from './index-BvBk1Iap.js'; 3import { b as bubble_event } from './misc-ByVveAau.js'; 4import { u as uploadToHuggingFace } from './utils.svelte-CYLB_jIA.js'; 5import { I as IconButton } from './ScrollFade.svelte_svelte_type_style_lang-Xm-PLg9E.js'; 6import { B as BlockLabel } from './BlockLabel-oGSqUii_.js'; 7import { D as DownloadLink } from './DownloadLink-KvrFKyMn.js'; 8import { E as Empty } from './Empty-CHa-gxv7.js'; 9import { S as ShareButton } from './ShareButton-Dz0y1C1K.js'; 10import { D as Download } from './Download-pFhUaTl4.js'; 11import { I as Image } from './Image-C3F5KG1F.js'; 12import { I as IconButtonWrapper } from './IconButtonWrapper-Ba0GidgU.js'; 13import { F as FullscreenButton } from './FullscreenButton-CNmhk6nd.js'; 14import { I as Image$1 } from './Image-CDw5qb5O.js'; 15/* empty css */ 16 17const get_coordinates_of_clicked_image = (evt) => { 18 let image; 19 if (evt.currentTarget instanceof Element) { 20 image = evt.currentTarget.querySelector("img"); 21 } else { 22 return [NaN, NaN]; 23 } 24 const imageRect = image.getBoundingClientRect(); 25 const xScale = image.naturalWidth / imageRect.width; 26 const yScale = image.naturalHeight / imageRect.height; 27 if (xScale > yScale) { 28 const displayed_height = image.naturalHeight / xScale; 29 const y_offset = (imageRect.height - displayed_height) / 2; 30 var x = Math.round((evt.clientX - imageRect.left) * xScale); 31 var y = Math.round((evt.clientY - imageRect.top - y_offset) * xScale); 32 } else { 33 const displayed_width = image.naturalWidth / yScale; 34 const x_offset = (imageRect.width - displayed_width) / 2; 35 var x = Math.round((evt.clientX - imageRect.left - x_offset) * yScale); 36 var y = Math.round((evt.clientY - imageRect.top) * yScale); 37 } 38 if (x < 0 || x >= image.naturalWidth || y < 0 || y >= image.naturalHeight) { 39 return null; 40 } 41 return [x, y]; 42}; 43 44var root_4 = from_html(`<!> <!> <!>`, 1); 45var root_3 = from_html(`<div class="image-container svelte-12vrxzd"><!> <button class="svelte-12vrxzd"><div><!></div></button></div>`); 46var root = from_html(`<!> <!>`, 1); 47 48function ImagePreview($$anchor, $$props) { 49 push($$props, false); 50 51 let value = prop($$props, 'value', 12); 52 let label = prop($$props, 'label', 12, undefined); 53 let show_label = prop($$props, 'show_label', 12); 54 let buttons = prop($$props, 'buttons', 28, () => []); 55 let on_custom_button_click = prop($$props, 'on_custom_button_click', 12, null); 56 let selectable = prop($$props, 'selectable', 12, false); 57 let i18n = prop($$props, 'i18n', 12); 58 let display_icon_button_wrapper_top_corner = prop($$props, 'display_icon_button_wrapper_top_corner', 12, false); 59 let fullscreen = prop($$props, 'fullscreen', 12, false); 60 let show_button_background = prop($$props, 'show_button_background', 12, true); 61 const dispatch = createEventDispatcher(); 62 63 const handle_click = (evt) => { 64 let coordinates = get_coordinates_of_clicked_image(evt); 65 66 if (coordinates) { 67 dispatch("select", { index: coordinates, value: null }); 68 } 69 }; 70 71 let image_container = mutable_source(); 72 73 var $$exports = { 74 get value() { 75 return value(); 76 }, 77 78 set value($$value) { 79 value($$value); 80 flushSync(); 81 }, 82 83 get label() { 84 return label(); 85 }, 86 87 set label($$value) { 88 label($$value); 89 flushSync(); 90 }, 91 92 get show_label() { 93 return show_label(); 94 }, 95 96 set show_label($$value) { 97 show_label($$value); 98 flushSync(); 99 }, 100 101 get buttons() { 102 return buttons(); 103 }, 104 105 set buttons($$value) { 106 buttons($$value); 107 flushSync(); 108 }, 109 110 get on_custom_button_click() { 111 return on_custom_button_click(); 112 }, 113 114 set on_custom_button_click($$value) { 115 on_custom_button_click($$value); 116 flushSync(); 117 }, 118 119 get selectable() { 120 return selectable(); 121 }, 122 123 set selectable($$value) { 124 selectable($$value); 125 flushSync(); 126 }, 127 128 get i18n() { 129 return i18n(); 130 }, 131 132 set i18n($$value) { 133 i18n($$value); 134 flushSync(); 135 }, 136 137 get display_icon_button_wrapper_top_corner() {
138 return display_icon_button_wrapper_top_corner(); 139 }, 140 141 set display_icon_button_wrapper_top_corner($$value) { 142 display_icon_button_wrapper_top_corner($$value); 143 flushSync(); 144 }, 145 146 get fullscreen() { 147 return fullscreen(); 148 }, 149 150 set fullscreen($$value) { 151 fullscreen($$value); 152 flushSync(); 153 }, 154 155 get show_button_background() { 156 return show_button_background(); 157 }, 158 159 set show_button_background($$value) { 160 show_button_background($$value); 161 flushSync(); 162 } 163 }; 164 165 init(); 166 167 var fragment = root(); 168 var node = first_child(fragment); 169 170 { 171 let $0 = derived_safe_equal(() => ( 172 deep_read_state(show_label()), 173 deep_read_state(label()), 174 deep_read_state(i18n()), 175 untrack(() => !show_label() ? "" : label() || i18n()("image.image")) 176 )); 177 178 BlockLabel(node, { 179 get show_label() { 180 return show_label(); 181 }, 182 183 get Icon() { 184 return Image; 185 }, 186 187 get label() { 188 return get($0); 189 } 190 }); 191 } 192 193 var node_1 = sibling(node, 2); 194 195 { 196 var consequent = ($$anchor) => { 197 Empty($$anchor, { 198 unpadded_box: true, 199 size: 'large', 200 children: ($$anchor, $$slotProps) => { 201 Image($$anchor); 202 }, 203 $$slots: { default: true } 204 }); 205 }; 206 207 var alternate = ($$anchor) => { 208 var div = root_3(); 209 var node_2 = child(div); 210 211 IconButtonWrapper(node_2, { 212 get display_top_corner() { 213 return display_icon_button_wrapper_top_corner(); 214 }, 215 216 get show_background() { 217 return show_button_background(); 218 }, 219 220 get buttons() { 221 return buttons(); 222 }, 223 224 get on_custom_button_click() { 225 return on_custom_button_click(); 226 }, 227 228 children: ($$anchor, $$slotProps) => { 229 var fragment_3 = root_4(); 230 var node_3 = first_child(fragment_3); 231 232 { 233 var consequent_1 = ($$anchor) => { 234 FullscreenButton($$anchor, { 235 get fullscreen() { 236 return fullscreen(); 237 }, 238 239 onclick: (is_fullscreen) => { 240 fullscreen(is_fullscreen); 241 dispatch("fullscreen", is_fullscreen); 242 } 243 }); 244 }; 245 246 if_block(node_3, ($$render) => { 247 if (( 248 deep_read_state(buttons()), 249 untrack(() => buttons().some((btn) => typeof btn === "string" && btn === "fullscreen")) 250 )) $$render(consequent_1); 251 }); 252 } 253 254 var node_4 = sibling(node_3, 2); 255 256 { 257 var consequent_2 = ($$anchor) => { 258 { 259 let $0 = derived_safe_equal(() => ( 260 deep_read_state(value()), 261 untrack(() => value().orig_name || "image") 262 )); 263 264 DownloadLink($$anchor, { 265 get href() { 266 return (deep_read_state(value()), untrack(() => value().url)); 267 }, 268 269 get download() { 270 return get($0); 271 }, 272 273 children: ($$anchor, $$slotProps) => { 274 { 275 let $0 = derived_safe_equal(() => ( 276 deep_read_state(i18n()), 277 untrack(() => i18n()("common.download")) 278 )); 279 280 IconButton($$anchor, { 281 get Icon() { 282 return Download; 283 }, 284 285 get label() { 286 return get($0); 287 } 288 }); 289 } 290 }, 291 $$slots: { default: true } 292 }); 293 } 294 }; 295 296 if_block(node_4, ($$render) => { 297 if (( 298 deep_read_state(buttons()), 299 untrack(() => buttons().some((btn) => typeof btn === "string" && btn === "download")) 300 )) $$render(consequent_2); 301 }); 302 } 303 304 var node_5 = sibling(node_4, 2); 305 306 { 307 var consequent_3 = ($$anchor) => { 308 ShareButton($$anchor, { 309 get i18n() { 310 return i18n(); 311 }, 312 313 formatter: async (value) => { 314 if (!value) return ""; 315 316 let url = await uploadToHuggingFace(value); 317 318 return `<img src="${url}" />`; 319 }, 320 321 get value() { 322 return value(); 323 }, 324 325 $$events: { 326 share($$arg) { 327 bubble_event.call(this, $$props, $$arg); 328 }, 329 330 error($$arg) { 331 bubble_event.call(this, $$props, $$arg); 332 } 333 } 334 }); 335 }; 336 337 if_block(node_5, ($$render) => { 338 if (( 339 deep_read_state(buttons()), 340 untrack(() => buttons().some((btn) => typeof btn === "string" && btn === "share")) 341 )) $$render(consequent_3); 342 }); 343 } 344 345 append($$anchor, fragment_3); 346 }, 347 $$slots: { default: true } 348 }); 349 350 var button = sibling(node_2, 2); 351 var div_1 = child(button); 352 let classes; 353 var node_6 = child(div_1); 354 355 Image$1(node_6, { 356 get src() { 357 return (deep_read_state(value()), untrack(() => value().url)); 358 }, 359 restProps: { loading: "lazy", alt: "" }, 360 $$events: { 361 load($$arg) { 362 bubble_event.call(this, $$props, $$arg); 363 } 364 } 365 }); 366 367 reset(div_1); 368 reset(button); 369 reset(div); 370 bind_this(div, ($$value) => set(image_container, $$value), () => get(image_container)); 371 template_effect(() => classes = set_class(div_1, 1, 'image-frame svelte-12vrxzd', null, classes, { selectable: selectable() })); 372 event('click', button, handle_click); 373 append($$anchor, div); 374 }; 375 376 if_block(node_1, ($$render) => { 377 if (( 378 deep_read_state(value()), 379 untrack(() => value() == null || !value()?.url) 380 )) $$render(consequent); else $$render(alternate, false); 381 }); 382 } 383 384 append($$anchor, fragment); 385 386 return pop($$exports); 387} 388 389const ImagePreview$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({ 390 __proto__: null, 391 default: ImagePreview 392}, Symbol.toStringTag, { value: 'Module' })); 393 394export { ImagePreview as I, ImagePreview$1 as a, get_coordinates_of_clicked_image as g }; 395//# sourceMappingURL=ImagePreview-CCH9abCE.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.