File size: 6,699 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Upload</title>
<style>
  * { box-sizing: border-box; }
  body { font-family: Inter,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; margin: 0; background: #f5f7fb; color: #263248; }
  header { background: #18243c; color: #fff; padding: 21px max(24px,calc((100vw - 1060px)/2)); }
  header h1 { margin: 0; font-size: 18px; letter-spacing:-.02em }
  main { max-width: 1040px; margin: 0 auto; padding: 48px 24px 90px; }
  .intro { margin-bottom:30px}.eyebrow { color:#5967ca;font-size:12px;font-weight:800;letter-spacing:.16em }.intro h2 {font-size:clamp(30px,4vw,43px);letter-spacing:-.05em;margin:10px 0}.intro p{color:#69788f;margin:0;line-height:1.6}
  .uploader { background: #fff; border: 2px dashed #b8c6e8; border-radius: 20px; padding: 46px 28px; text-align: center; box-shadow:0 15px 45px rgba(31,49,84,.05) }
  .uploader .icon{width:56px;height:56px;display:grid;place-items:center;margin:0 auto 16px;border-radius:16px;background:#eef0ff;color:#505ed2;font-size:28px}
  .uploader p:first-of-type{font-size:18px;font-weight:700;margin:0 0 5px}
  .uploader input[type=file] { margin-top: 18px;max-width:100%;font:inherit;color:#58647b }
  .uploader input[type=file]::file-selector-button{border:0;border-radius:9px;background:#4f5bd5;color:white;font-weight:700;padding:11px 16px;margin-right:13px;cursor:pointer}
  .gallery-head{display:flex;justify-content:space-between;align-items:center;margin-top:36px;border-bottom:1px solid #e1e6ef;padding-bottom:12px}.gallery-head h2{font-size:19px;margin:0}
  .gallery { display: flex; flex-wrap: wrap; gap: 15px; margin-top: 20px; min-height:160px }
  .gallery:empty:before{content:"No images yet. Uploaded images will appear here.";color:#9aa6b8;display:grid;place-items:center;width:100%;border:1px solid #e3e8f1;border-radius:15px;background:#fff}
  .gallery img { width: 155px; height: 155px; object-fit: cover; border-radius: 12px; border: 1px solid #d9e0eb; cursor: zoom-in; background: #fff; box-shadow:0 7px 20px rgba(31,49,84,.07) }
  .gallery img:hover{transform:translateY(-2px)}
  .hint { color: #69788f; margin-top: 12px;font-size:13px }
  /* preview / zoom modal */
  .preview-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
                   align-items: center; justify-content: center; flex-direction: column; gap: 12px; z-index: 10; }
  .preview-modal.open { display: flex; }
  .preview-modal img { max-width: 80vw; max-height: 70vh; transform: scale(var(--zoom, 1)); transition: transform .15s; border-radius:10px;box-shadow:0 20px 60px rgba(0,0,0,.28) }
  .preview-controls button { padding: 10px 17px; border: 1px solid #c5d0e8; border-radius: 9px; background: #fff; color: #30415e; cursor: pointer; margin: 0 4px; font-weight:700 }
  .preview-controls button:hover{background:#eff1ff}
</style>
</head>
<body>
  <header><h1>Image Gallery</h1></header>
  <main>
    <div class="intro"><span class="eyebrow">YOUR WORKSPACE</span><h2>Collect Every Great Image</h2><p>Upload, preview, and zoom in on images to keep your visual assets organized.</p></div>
    <section class="uploader">
      <div class="icon" aria-hidden="true">↑</div>
      <p>Add images to your workspace</p>
      <span style="color:#8b98ad;font-size:14px">Select multiple images at once, then click a thumbnail to view it full size.</span><br>
      <input data-testid="image-upload" type="file" accept="image/*" multiple aria-label="upload image">
      <p class="hint" data-testid="status">No images uploaded</p>
    </section>

    <!-- in-memory store abstraction for the fixture -->
    <div data-testid="image-store" data-storage="local" hidden></div>

    <div class="gallery-head"><h2>Images</h2><span style="color:#8b98ad;font-size:13px">Click an image to preview it</span></div>
    <div class="gallery" data-testid="image-list"></div>
  </main>

  <!-- preview + zoom modal -->
  <div class="preview-modal" data-testid="image-preview">
    <img data-testid="preview-image" alt="preview">
    <div class="preview-controls">
      <button data-testid="zoom-button" aria-label="zoom in">Zoom In</button>
      <button data-testid="zoom-out-button" aria-label="zoom out">Zoom Out</button>
      <button data-testid="close-preview">Close</button>
    </div>
  </div>

<script>
  (function () {
    var store = [];                                   // local in-memory image store
    window.__getImageStore=()=>JSON.parse(JSON.stringify(store));
    var input = document.querySelector('[data-testid="image-upload"]');
    var list = document.querySelector('[data-testid="image-list"]');
    var status = document.querySelector('[data-testid="status"]');
    var modal = document.querySelector('[data-testid="image-preview"]');
    var previewImg = document.querySelector('[data-testid="preview-image"]');
    var zoom = 1;

    function openPreview(src) {
      zoom = 1;
      previewImg.style.setProperty('--zoom', zoom);
      previewImg.src = src;
      modal.classList.add('open');
    }
    function addImage(src) {
      store.push(src);
      var img = document.createElement('img');
      img.src = src;
      img.alt = 'uploaded image';
      img.setAttribute('data-testid', 'uploaded-image');
      img.addEventListener('click', function () { openPreview(src); });
      list.appendChild(img);
      status.textContent = store.length + ' image(s) uploaded';
    }

    input.addEventListener('change', async function (e) {
      var files = Array.prototype.slice.call(e.target.files || []);
      for (const file of files) {
        if (!file.type.startsWith('image/')) {
          status.textContent = 'Only image files can be uploaded';
          continue;
        }
        const src = await new Promise((resolve, reject) => {
          const reader = new FileReader();
          reader.onload = () => resolve(reader.result);
          reader.onerror = () => reject(reader.error);
          reader.readAsDataURL(file);
        });
        addImage(src);
      }
    });

    document.querySelector('[data-testid="zoom-button"]').addEventListener('click', function () {
      zoom = Math.min(zoom + 0.25, 3);
      previewImg.style.setProperty('--zoom', zoom);
    });
    document.querySelector('[data-testid="zoom-out-button"]').addEventListener('click', function () {
      zoom = Math.max(zoom - 0.25, 0.25);
      previewImg.style.setProperty('--zoom', zoom);
    });
    document.querySelector('[data-testid="close-preview"]').addEventListener('click', function () {
      modal.classList.remove('open');
    });
  })();
</script>
</body>
</html>