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