images-viewer-js 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ImagesViewer 图片查看器
2
2
 
3
- 一个功能丰富、响应式的图片查看器,支持缩放、旋转、导航等操作。
3
+ 一个功能丰富、响应式的图片查看器,支持缩放、旋转、导航等操作。[预览地址](https://ybchen292.github.io/images-viewer/)
4
4
 
5
5
  ## 特性
6
6
 
package/dist/index.esm.js CHANGED
@@ -196,7 +196,7 @@ var imageViewer = {exports: {}};
196
196
  // 注入CSS样式
197
197
  injectStyles() {
198
198
  const style = document.createElement('style');
199
- style.id = 'image-viewer-styles';
199
+ style.id = 'images-viewer-styles';
200
200
  style.textContent = `
201
201
  :root {
202
202
  /* 背景相关变量 */
@@ -243,7 +243,7 @@ var imageViewer = {exports: {}};
243
243
  --transition-speed: ${this.options.theme.transitionSpeed};
244
244
  }
245
245
 
246
- .image-viewer-container {
246
+ .images-viewer-container {
247
247
  position: fixed;
248
248
  top: 0;
249
249
  left: 0;
@@ -260,7 +260,7 @@ var imageViewer = {exports: {}};
260
260
  }
261
261
 
262
262
  /* 修复图片容器样式 - 确保居中 */
263
- .image-viewer-image-container {
263
+ .images-viewer-image-container {
264
264
  position: absolute;
265
265
  top: 0;
266
266
  left: 0;
@@ -274,7 +274,7 @@ var imageViewer = {exports: {}};
274
274
  }
275
275
 
276
276
  /* 修复图片样式 - 确保居中 */
277
- .image-viewer-image {
277
+ .images-viewer-image {
278
278
  position: relative;
279
279
  object-fit: contain;
280
280
  cursor: grab;
@@ -287,17 +287,17 @@ var imageViewer = {exports: {}};
287
287
  touch-action: none;
288
288
  }
289
289
 
290
- .image-viewer-image.loaded {
290
+ .images-viewer-image.loaded {
291
291
  opacity: 1;
292
292
  }
293
293
 
294
- .image-viewer-image.dragging {
294
+ .images-viewer-image.dragging {
295
295
  cursor: grabbing;
296
296
  transition: none;
297
297
  }
298
298
 
299
299
  /* 加载指示器 */
300
- .image-viewer-loading {
300
+ .images-viewer-loading {
301
301
  position: absolute;
302
302
  top: 50%;
303
303
  left: 50%;
@@ -316,11 +316,11 @@ var imageViewer = {exports: {}};
316
316
  z-index: 3;
317
317
  }
318
318
 
319
- .image-viewer-loading.active {
319
+ .images-viewer-loading.active {
320
320
  opacity: 1;
321
321
  }
322
322
 
323
- .image-viewer-loading-spinner {
323
+ .images-viewer-loading-spinner {
324
324
  width: 40px;
325
325
  height: 40px;
326
326
  border: 4px solid rgba(255, 255, 255, 0.2);
@@ -336,7 +336,7 @@ var imageViewer = {exports: {}};
336
336
  }
337
337
 
338
338
  /* 右上角关闭按钮样式 */
339
- .image-viewer-top-close-btn {
339
+ .images-viewer-top-close-btn {
340
340
  position: absolute;
341
341
  top: var(--top-close-btn-top);
342
342
  right: var(--top-close-btn-right);
@@ -357,13 +357,13 @@ var imageViewer = {exports: {}};
357
357
  box-shadow: 0 2px 8px var(--shadow-color);
358
358
  }
359
359
 
360
- .image-viewer-top-close-btn:hover {
360
+ .images-viewer-top-close-btn:hover {
361
361
  background-color: rgba(255, 50, 50, 0.3);
362
362
  transform: scale(1.1);
363
363
  }
364
364
 
365
365
  /* 缩放指示器样式 */
366
- .image-viewer-zoom-indicator {
366
+ .images-viewer-zoom-indicator {
367
367
  position: absolute;
368
368
  top: var(--zoom-indicator-top);
369
369
  left: var(--zoom-indicator-left);
@@ -381,7 +381,7 @@ var imageViewer = {exports: {}};
381
381
  }
382
382
 
383
383
  /* 信息栏样式 */
384
- .image-viewer-image-info {
384
+ .images-viewer-image-info {
385
385
  position: absolute;
386
386
  top: var(--info-top);
387
387
  left: var(--info-left);
@@ -398,22 +398,22 @@ var imageViewer = {exports: {}};
398
398
  border: 1px solid rgba(255, 255, 255, 0.1);
399
399
  }
400
400
 
401
- .image-viewer-image-info.visible {
401
+ .images-viewer-image-info.visible {
402
402
  display: block;
403
403
  animation: imageViewerFadeIn 0.3s ease;
404
404
  }
405
405
 
406
- .image-viewer-image-info p {
406
+ .images-viewer-image-info p {
407
407
  margin: 4px 0;
408
408
  line-height: 1.4;
409
409
  }
410
410
 
411
- .image-viewer-image-info .info-label {
411
+ .images-viewer-image-info .info-label {
412
412
  color: #ddd;
413
413
  margin-right: 5px;
414
414
  }
415
415
 
416
- .image-viewer-shortcuts-title {
416
+ .images-viewer-shortcuts-title {
417
417
  margin-top: 10px;
418
418
  padding-top: 10px;
419
419
  border-top: 1px solid rgba(255, 255, 255, 0.1);
@@ -433,7 +433,7 @@ var imageViewer = {exports: {}};
433
433
  }
434
434
 
435
435
  /* 图片计数器 */
436
- .image-viewer-image-counter {
436
+ .images-viewer-image-counter {
437
437
  position: absolute;
438
438
  top: 20px;
439
439
  left: 50%;
@@ -450,7 +450,7 @@ var imageViewer = {exports: {}};
450
450
  }
451
451
 
452
452
  /* 导航按钮 */
453
- .image-viewer-nav-buttons {
453
+ .images-viewer-nav-buttons {
454
454
  position: absolute;
455
455
  top: 50%;
456
456
  left: 0;
@@ -463,7 +463,7 @@ var imageViewer = {exports: {}};
463
463
  padding: 0 10px;
464
464
  }
465
465
 
466
- .image-viewer-nav-btn {
466
+ .images-viewer-nav-btn {
467
467
  width: var(--button-size);
468
468
  height: var(--button-size);
469
469
  border-radius: 50%;
@@ -483,20 +483,20 @@ var imageViewer = {exports: {}};
483
483
  z-index: 6;
484
484
  }
485
485
 
486
- .image-viewer-nav-btn:hover {
486
+ .images-viewer-nav-btn:hover {
487
487
  background-color: var(--button-hover-bg);
488
488
  opacity: 1;
489
489
  transform: scale(1.1);
490
490
  }
491
491
 
492
- .image-viewer-nav-btn:disabled {
492
+ .images-viewer-nav-btn:disabled {
493
493
  opacity: 0.3;
494
494
  cursor: not-allowed;
495
495
  transform: none;
496
496
  }
497
497
 
498
498
  /* 工具栏样式 */
499
- .image-viewer-toolbar {
499
+ .images-viewer-toolbar {
500
500
  position: absolute;
501
501
  bottom: var(--toolbar-bottom);
502
502
  left: 50%;
@@ -518,11 +518,11 @@ var imageViewer = {exports: {}};
518
518
  -webkit-overflow-scrolling: touch;
519
519
  }
520
520
 
521
- .image-viewer-toolbar::-webkit-scrollbar {
521
+ .images-viewer-toolbar::-webkit-scrollbar {
522
522
  display: none;
523
523
  }
524
524
 
525
- .image-viewer-tool-btn {
525
+ .images-viewer-tool-btn {
526
526
  width: var(--button-size);
527
527
  height: var(--button-size);
528
528
  background-color: transparent;
@@ -539,26 +539,27 @@ var imageViewer = {exports: {}};
539
539
  border-radius: var(--button-border-radius);
540
540
  margin: 0 2px;
541
541
  z-index: 11;
542
+ line-height: 1;
542
543
  }
543
544
 
544
- .image-viewer-tool-btn:hover {
545
+ .images-viewer-tool-btn:hover {
545
546
  background-color: var(--button-hover-bg);
546
547
  transform: translateY(-2px);
547
548
  box-shadow: 0 4px 10px var(--shadow-color);
548
549
  }
549
550
 
550
- .image-viewer-tool-btn:active {
551
+ .images-viewer-tool-btn:active {
551
552
  background-color: rgba(255, 255, 255, 0.3);
552
553
  transform: translateY(0);
553
554
  }
554
555
 
555
- .image-viewer-tool-btn:disabled {
556
+ .images-viewer-tool-btn:disabled {
556
557
  opacity: 0.5;
557
558
  cursor: not-allowed;
558
559
  }
559
560
 
560
561
  /* 缩略图容器 */
561
- .image-viewer-thumbnails-container {
562
+ .images-viewer-thumbnails-container {
562
563
  position: absolute;
563
564
  bottom: 90px;
564
565
  left: 50%;
@@ -579,11 +580,11 @@ var imageViewer = {exports: {}};
579
580
  border: 1px solid rgba(255, 255, 255, 0.1);
580
581
  }
581
582
 
582
- .image-viewer-thumbnails-container::-webkit-scrollbar {
583
+ .images-viewer-thumbnails-container::-webkit-scrollbar {
583
584
  display: none;
584
585
  }
585
586
 
586
- .image-viewer-thumbnail-item {
587
+ .images-viewer-thumbnail-item {
587
588
  width: 70px;
588
589
  height: 45px;
589
590
  border: 2px solid transparent;
@@ -595,83 +596,83 @@ var imageViewer = {exports: {}};
595
596
  z-index: 11;
596
597
  }
597
598
 
598
- .image-viewer-thumbnail-item img {
599
+ .images-viewer-thumbnail-item img {
599
600
  width: 100%;
600
601
  height: 100%;
601
602
  object-fit: cover;
602
603
  }
603
604
 
604
- .image-viewer-thumbnail-item.active {
605
+ .images-viewer-thumbnail-item.active {
605
606
  border-color: var(--active-color);
606
607
  transform: scale(1.05);
607
608
  }
608
609
 
609
- .image-viewer-thumbnail-item:hover {
610
+ .images-viewer-thumbnail-item:hover {
610
611
  transform: scale(1.05);
611
612
  }
612
613
 
613
614
  @media (max-width: 768px) {
614
- .image-viewer-tool-btn {
615
+ .images-viewer-tool-btn {
615
616
  width: 44px;
616
617
  height: 44px;
617
618
  font-size: 18px;
618
619
  }
619
620
 
620
- .image-viewer-toolbar {
621
+ .images-viewer-toolbar {
621
622
  padding: 6px 8px;
622
623
  bottom: 15px;
623
624
  border-radius: 25px;
624
625
  max-width: 95%;
625
626
  }
626
627
 
627
- .image-viewer-thumbnails-container {
628
+ .images-viewer-thumbnails-container {
628
629
  bottom: 80px;
629
630
  padding: 8px 10px;
630
631
  gap: 8px;
631
632
  max-width: 95%;
632
633
  }
633
634
 
634
- .image-viewer-thumbnail-item {
635
+ .images-viewer-thumbnail-item {
635
636
  width: 60px;
636
637
  height: 40px;
637
638
  }
638
639
 
639
- .image-viewer-nav-btn {
640
+ .images-viewer-nav-btn {
640
641
  width: 44px;
641
642
  height: 44px;
642
643
  font-size: 20px;
643
644
  }
644
645
 
645
- .image-viewer-top-close-btn {
646
+ .images-viewer-top-close-btn {
646
647
  width: 40px;
647
648
  height: 40px;
648
649
  top: 15px;
649
650
  right: 15px;
650
651
  }
651
652
 
652
- .image-viewer-image-info {
653
+ .images-viewer-image-info {
653
654
  font-size: 12px;
654
655
  padding: 8px 12px;
655
656
  }
656
657
 
657
- .image-viewer-zoom-indicator,
658
- .image-viewer-image-counter {
658
+ .images-viewer-zoom-indicator,
659
+ .images-viewer-image-counter {
659
660
  font-size: 12px;
660
661
  }
661
662
  }
662
663
 
663
664
  @media (max-width: 480px) {
664
- .image-viewer-thumbnails-container {
665
+ .images-viewer-thumbnails-container {
665
666
  max-width: 95%;
666
667
  padding: 6px 8px;
667
668
  }
668
669
 
669
- .image-viewer-thumbnail-item {
670
+ .images-viewer-thumbnail-item {
670
671
  width: 50px;
671
672
  height: 35px;
672
673
  }
673
674
 
674
- .image-viewer-toolbar {
675
+ .images-viewer-toolbar {
675
676
  max-width: 95%;
676
677
  }
677
678
  }
@@ -683,26 +684,26 @@ var imageViewer = {exports: {}};
683
684
  createOptimizedElements() {
684
685
  // 主容器
685
686
  this.container = document.createElement('div');
686
- this.container.className = 'image-viewer-container';
687
+ this.container.className = 'images-viewer-container';
687
688
  document.body.appendChild(this.container);
688
689
 
689
690
  // 图片容器 - 使用flex确保居中
690
691
  this.imageContainer = document.createElement('div');
691
- this.imageContainer.className = 'image-viewer-image-container';
692
+ this.imageContainer.className = 'images-viewer-image-container';
692
693
  this.container.appendChild(this.imageContainer);
693
694
 
694
695
  // 图片元素
695
696
  this.image = document.createElement('img');
696
- this.image.className = 'image-viewer-image';
697
+ this.image.className = 'images-viewer-image';
697
698
  this.image.alt = '预览图片';
698
699
  this.image.crossOrigin = 'anonymous';
699
700
  this.imageContainer.appendChild(this.image);
700
701
 
701
702
  // 加载指示器
702
703
  this.loading = document.createElement('div');
703
- this.loading.className = 'image-viewer-loading';
704
+ this.loading.className = 'images-viewer-loading';
704
705
  this.loading.innerHTML = `
705
- <div class="image-viewer-loading-spinner"></div>
706
+ <div class="images-viewer-loading-spinner"></div>
706
707
  <div>加载中...</div>
707
708
  `;
708
709
  this.imageContainer.appendChild(this.loading);
@@ -710,7 +711,7 @@ var imageViewer = {exports: {}};
710
711
  // 右上角关闭按钮
711
712
  if (this.options.buttons.topClose) {
712
713
  this.topCloseBtn = document.createElement('button');
713
- this.topCloseBtn.className = 'image-viewer-top-close-btn';
714
+ this.topCloseBtn.className = 'images-viewer-top-close-btn';
714
715
  this.topCloseBtn.textContent = '×';
715
716
  this.topCloseBtn.title = '关闭预览 (ESC)';
716
717
  this.container.appendChild(this.topCloseBtn);
@@ -718,20 +719,20 @@ var imageViewer = {exports: {}};
718
719
 
719
720
  // 缩放比例显示元素
720
721
  this.zoomIndicator = document.createElement('div');
721
- this.zoomIndicator.className = 'image-viewer-zoom-indicator';
722
+ this.zoomIndicator.className = 'images-viewer-zoom-indicator';
722
723
  this.container.appendChild(this.zoomIndicator);
723
724
 
724
725
  // 图片信息面板
725
726
  if (this.options.buttons.info) {
726
727
  this.imageInfoPanel = document.createElement('div');
727
- this.imageInfoPanel.className = `image-viewer-image-info ${this.imageInfoVisible ? 'visible' : ''}`;
728
+ this.imageInfoPanel.className = `images-viewer-image-info ${this.imageInfoVisible ? 'visible' : ''}`;
728
729
  this.container.appendChild(this.imageInfoPanel);
729
730
  }
730
731
 
731
732
  // 图片计数器
732
733
  if (this.images.length > 1) {
733
734
  this.counter = document.createElement('div');
734
- this.counter.className = 'image-viewer-image-counter';
735
+ this.counter.className = 'images-viewer-image-counter';
735
736
  this.container.appendChild(this.counter);
736
737
  }
737
738
 
@@ -752,7 +753,7 @@ var imageViewer = {exports: {}};
752
753
  // 创建导航按钮
753
754
  createNavButtons() {
754
755
  const navContainer = document.createElement('div');
755
- navContainer.className = 'image-viewer-nav-buttons';
756
+ navContainer.className = 'images-viewer-nav-buttons';
756
757
 
757
758
  navContainer.addEventListener('click', e => {
758
759
  e.stopPropagation();
@@ -760,7 +761,7 @@ var imageViewer = {exports: {}};
760
761
 
761
762
  if (this.options.buttons.prev) {
762
763
  this.prevBtn = document.createElement('button');
763
- this.prevBtn.className = 'image-viewer-nav-btn image-viewer-prev-btn';
764
+ this.prevBtn.className = 'images-viewer-nav-btn images-viewer-prev-btn';
764
765
  this.prevBtn.textContent = '←';
765
766
  this.prevBtn.title = '上一张 (←)';
766
767
  this.prevBtn.addEventListener('click', e => {
@@ -772,7 +773,7 @@ var imageViewer = {exports: {}};
772
773
 
773
774
  if (this.options.buttons.next) {
774
775
  this.nextBtn = document.createElement('button');
775
- this.nextBtn.className = 'image-viewer-nav-btn image-viewer-next-btn';
776
+ this.nextBtn.className = 'images-viewer-nav-btn images-viewer-next-btn';
776
777
  this.nextBtn.textContent = '→';
777
778
  this.nextBtn.title = '下一张 (→)';
778
779
  this.nextBtn.addEventListener('click', e => {
@@ -788,7 +789,7 @@ var imageViewer = {exports: {}};
788
789
  // 创建工具栏
789
790
  createToolbar() {
790
791
  const toolbar = document.createElement('div');
791
- toolbar.className = 'image-viewer-toolbar';
792
+ toolbar.className = 'images-viewer-toolbar';
792
793
 
793
794
  toolbar.addEventListener('click', e => {
794
795
  e.stopPropagation();
@@ -805,11 +806,6 @@ var imageViewer = {exports: {}};
805
806
  this.toolbarNextBtn = this.createToolButton('→', () => this.nextImage());
806
807
  toolbar.appendChild(this.toolbarNextBtn);
807
808
  }
808
-
809
- const separator = document.createElement('div');
810
- separator.style.width = '10px';
811
- separator.style.flexShrink = '0';
812
- toolbar.appendChild(separator);
813
809
  }
814
810
 
815
811
  // 缩放按钮
@@ -851,7 +847,7 @@ var imageViewer = {exports: {}};
851
847
  }
852
848
 
853
849
  if (this.options.buttons.download) {
854
- this.downloadBtn = this.createToolButton('', () => this.downloadImage());
850
+ this.downloadBtn = this.createToolButton('', () => this.downloadImage());
855
851
  toolbar.appendChild(this.downloadBtn);
856
852
  }
857
853
 
@@ -871,7 +867,7 @@ var imageViewer = {exports: {}};
871
867
  // 创建工具按钮
872
868
  createToolButton(icon, onClick) {
873
869
  const button = document.createElement('button');
874
- button.className = 'image-viewer-tool-btn';
870
+ button.className = 'images-viewer-tool-btn';
875
871
 
876
872
  const iconSpan = document.createElement('span');
877
873
  iconSpan.textContent = icon;
@@ -889,7 +885,7 @@ var imageViewer = {exports: {}};
889
885
  // 创建缩略图
890
886
  createThumbnails() {
891
887
  const thumbContainer = document.createElement('div');
892
- thumbContainer.className = 'image-viewer-thumbnails-container';
888
+ thumbContainer.className = 'images-viewer-thumbnails-container';
893
889
 
894
890
  thumbContainer.addEventListener('click', e => {
895
891
  e.stopPropagation();
@@ -897,7 +893,7 @@ var imageViewer = {exports: {}};
897
893
 
898
894
  this.images.forEach((url, index) => {
899
895
  const thumbItem = document.createElement('div');
900
- thumbItem.className = `image-viewer-thumbnail-item ${index === 0 ? 'active' : ''}`;
896
+ thumbItem.className = `images-viewer-thumbnail-item ${index === 0 ? 'active' : ''}`;
901
897
  thumbItem.dataset.index = index;
902
898
 
903
899
  const thumbImg = document.createElement('img');
@@ -1127,7 +1123,7 @@ var imageViewer = {exports: {}};
1127
1123
  }
1128
1124
 
1129
1125
  infoHtml += `
1130
- <div class="image-viewer-shortcuts-title">快捷键</div>
1126
+ <div class="images-viewer-shortcuts-title">快捷键</div>
1131
1127
  <p><span class="info-label">放大:</span> + / =</p>
1132
1128
  <p><span class="info-label">缩小:</span> -</p>
1133
1129
  <p><span class="info-label">上一张:</span> ←</p>
@@ -1167,11 +1163,11 @@ var imageViewer = {exports: {}};
1167
1163
  updateThumbnails() {
1168
1164
  if (this.images.length <= 1) return;
1169
1165
 
1170
- document.querySelectorAll('.image-viewer-thumbnail-item').forEach(item => {
1166
+ document.querySelectorAll('.images-viewer-thumbnail-item').forEach(item => {
1171
1167
  item.classList.remove('active');
1172
1168
  });
1173
1169
 
1174
- const activeItem = document.querySelector(`.image-viewer-thumbnail-item[data-index="${this.currentIndex}"]`);
1170
+ const activeItem = document.querySelector(`.images-viewer-thumbnail-item[data-index="${this.currentIndex}"]`);
1175
1171
  if (activeItem) {
1176
1172
  activeItem.classList.add('active');
1177
1173
  activeItem.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' });
@@ -1259,7 +1255,7 @@ var imageViewer = {exports: {}};
1259
1255
  }
1260
1256
 
1261
1257
  rotatePoint(x, y, angleDegrees) {
1262
- const angle = (angleDegrees * Math.PI) / 180;
1258
+ const angle = angleDegrees * Math.PI;
1263
1259
  const cos = Math.cos(angle);
1264
1260
  const sin = Math.sin(angle);
1265
1261
  return {
@@ -1298,6 +1294,28 @@ var imageViewer = {exports: {}};
1298
1294
  e.preventDefault();
1299
1295
  });
1300
1296
 
1297
+ // this.addEvent(document, 'mousemove', e => {
1298
+ // if (!this.isDragging) return;
1299
+
1300
+ // const deltaX = e.clientX - this.startX;
1301
+ // const deltaY = e.clientY - this.startY;
1302
+
1303
+ // // 修复:根据旋转角度正确计算拖拽方向
1304
+ // const angleRad = this.rotation * Math.PI;
1305
+
1306
+ // // 直接应用旋转矩阵到拖拽向量
1307
+ // const rotatedDeltaX = deltaX * Math.cos(angleRad) - deltaY * Math.sin(angleRad);
1308
+ // console.log('🚀 ~ rotatedDeltaX:', rotatedDeltaX);
1309
+ // const rotatedDeltaY = deltaX * Math.sin(angleRad) + deltaY * Math.cos(angleRad);
1310
+ // console.log('🚀 ~ rotatedDeltaY:', rotatedDeltaY);
1311
+
1312
+ // this.translateX = this.startTranslateX + rotatedDeltaX;
1313
+ // this.translateY = this.startTranslateY + rotatedDeltaY;
1314
+
1315
+ // this.updateImageTransform();
1316
+ // e.preventDefault();
1317
+ // });
1318
+
1301
1319
  // 鼠标释放
1302
1320
  this.addEvent(document, 'mouseup', () => {
1303
1321
  if (this.isDragging) {
@@ -1792,7 +1810,7 @@ var imageViewer = {exports: {}};
1792
1810
  this.container.style.opacity = '0';
1793
1811
  setTimeout(() => {
1794
1812
  this.container.style.display = 'none';
1795
- const styles = document.getElementById('image-viewer-styles');
1813
+ const styles = document.getElementById('images-viewer-styles');
1796
1814
  if (styles) styles.remove();
1797
1815
  if (this.container) this.container.remove();
1798
1816
  }, 300);