hyperbook 0.53.6 → 0.54.0

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.
@@ -230,8 +230,42 @@ var hyperbook = (function () {
230
230
  * @param {HTMLElement} el - The element to toggle.
231
231
  */
232
232
  function toggleLightbox(el) {
233
- el.parentElement.classList.toggle("lightbox");
234
- el.parentElement.classList.toggle("normal");
233
+ const overlay = document.createElement("div");
234
+ overlay.classList.add("lightbox-overlay");
235
+
236
+ const captionText =
237
+ el.parentElement.querySelector("figcaption")?.textContent || "";
238
+
239
+ // container for image + caption
240
+ const content = document.createElement("div");
241
+ content.classList.add("lightbox-content");
242
+
243
+ // image container fills remaining space
244
+ const imgContainer = document.createElement("div");
245
+ imgContainer.classList.add("lightbox-image-container");
246
+
247
+ const lightboxImg = document.createElement("img");
248
+ lightboxImg.src = el.src;
249
+ imgContainer.appendChild(lightboxImg);
250
+
251
+ content.appendChild(imgContainer);
252
+
253
+ // add caption if exists
254
+ if (captionText) {
255
+ const caption = document.createElement("div");
256
+ caption.classList.add("caption");
257
+ caption.textContent = captionText;
258
+ content.appendChild(caption);
259
+ }
260
+
261
+ overlay.appendChild(content);
262
+
263
+ overlay.addEventListener("click", () => {
264
+ document.body.removeChild(overlay);
265
+ });
266
+
267
+ document.body.appendChild(overlay);
268
+ overlay.style.display = "flex";
235
269
  }
236
270
 
237
271
  function init(root) {
@@ -27,27 +27,42 @@ figure {
27
27
  max-width: 100%;
28
28
  }
29
29
 
30
- .hyperbook-markdown figure.lightbox {
31
- position: fixed;
32
- display: flex;
33
- justify-content: center;
34
- flex-direction: column;
35
- align-items: center;
36
- top: 0;
37
- left: 0;
38
- right: 0;
39
- bottom: 0;
40
- padding: 1em;
41
- z-index: 10000;
42
- margin: 0px;
43
- background: rgba(0, 0, 0, 0.5);
30
+ .hyperbook-markdown figure.align-left {
31
+ display: table;
32
+ float: left;
33
+ margin-right: 1.75rem;
44
34
  }
45
35
 
46
- .hyperbook-markdown figure.lightbox img {
47
- min-width: 100%;
48
- min-height: 100%;
49
- cursor: zoom-out;
50
- object-fit: contain;
36
+ .hyperbook-markdown figure.align-right {
37
+ display: table;
38
+ float: right;
39
+ margin-left: 1.75rem;
40
+ }
41
+
42
+ .hyperbook-markdown figure.align-rightplus {
43
+ display: table;
44
+ float: right;
45
+ margin-left: 1.75rem;
46
+ margin-right: -1.5rem;
47
+ }
48
+
49
+ .hyperbook-markdown figure.align-leftplus {
50
+ display: table;
51
+ float: left;
52
+ margin-right: 1.75rem;
53
+ margin-left: -1.5rem;
54
+ }
55
+
56
+ .hyperbook-markdown figure.align-centerplus {
57
+ display: grid;
58
+ justify-items: center;
59
+ clear: both;
60
+ margin-left: -1.5rem;
61
+ margin-right: -1.5rem;
62
+
63
+ img {
64
+ width: 100%;
65
+ }
51
66
  }
52
67
 
53
68
  .hyperbook-markdown table {
@@ -76,12 +91,16 @@ figure {
76
91
  }
77
92
 
78
93
  .hyperbook-markdown figure.normal {
79
- text-align: center;
94
+ display: grid;
95
+ clear: both;
96
+ justify-items: center;
97
+ align-content: center;
80
98
  margin-top: 10px;
81
99
  margin-bottom: 10px;
82
100
  }
83
101
 
84
102
  .hyperbook-markdown figure.normal img {
103
+ display: inline-block;
85
104
  cursor: zoom-in;
86
105
  }
87
106
 
@@ -148,11 +167,11 @@ figure {
148
167
  margin-bottom: 0;
149
168
  }
150
169
 
151
- .hyperbook-markdown li + li {
170
+ .hyperbook-markdown li+li {
152
171
  margin-top: 0.25em;
153
172
  }
154
173
 
155
- .hyperbook-markdown li > p {
174
+ .hyperbook-markdown li>p {
156
175
  margin-top: 16px;
157
176
  }
158
177
 
@@ -226,6 +245,7 @@ figure {
226
245
  .hyperbook-markdown h4,
227
246
  .hyperbook-markdown h5,
228
247
  .hyperbook-markdown h6 {
248
+ clear: both;
229
249
  font-family: hyperbook-heading, sans-serif;
230
250
  margin-top: 24px;
231
251
  margin-bottom: 16px;
@@ -305,10 +325,10 @@ figure {
305
325
  list-style-type: none;
306
326
  }
307
327
 
308
- .hyperbook-markdown #toc-toggle > .bar1,
309
- .hyperbook-markdown #toc-toggle > .bar2,
310
- .hyperbook-markdown #toc-toggle > .bar3,
311
- .hyperbook-markdown #toc-toggle > .bar4 {
328
+ .hyperbook-markdown #toc-toggle>.bar1,
329
+ .hyperbook-markdown #toc-toggle>.bar2,
330
+ .hyperbook-markdown #toc-toggle>.bar3,
331
+ .hyperbook-markdown #toc-toggle>.bar4 {
312
332
  background-color: var(--color-text);
313
333
  }
314
334
 
@@ -431,16 +451,16 @@ figure {
431
451
  height: 100%;
432
452
  }
433
453
 
434
- .toc-drawer-content > nav {
454
+ .toc-drawer-content>nav {
435
455
  padding: 20px;
436
456
  flex: 1;
437
457
  }
438
458
 
439
- .toc-drawer-content > nav li a {
459
+ .toc-drawer-content>nav li a {
440
460
  display: block;
441
461
  }
442
462
 
443
- .toc-drawer-content > nav li a:hover {
463
+ .toc-drawer-content>nav li a:hover {
444
464
  text-decoration: underline;
445
465
  }
446
466
 
@@ -547,16 +567,16 @@ figure {
547
567
  opacity: 1;
548
568
  }
549
569
 
550
- .hyperbook-markdown #toc-toggle > .bar1,
551
- .hyperbook-markdown #toc-toggle > .bar3 {
570
+ .hyperbook-markdown #toc-toggle>.bar1,
571
+ .hyperbook-markdown #toc-toggle>.bar3 {
552
572
  width: 20px;
553
573
  height: 2px;
554
574
  margin: 2px 3px;
555
575
  transition: 0.4s;
556
576
  }
557
577
 
558
- .hyperbook-markdown #toc-toggle > .bar2,
559
- .hyperbook-markdown #toc-toggle > .bar4 {
578
+ .hyperbook-markdown #toc-toggle>.bar2,
579
+ .hyperbook-markdown #toc-toggle>.bar4 {
560
580
  width: 25px;
561
581
  height: 2px;
562
582
  margin: 2px 3px;
@@ -740,3 +740,69 @@ nav.toc li.level-3 {
740
740
  cursor: pointer;
741
741
  mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLXVwbG9hZCI+PHBhdGggZD0iTTIxIDE1djRhMiAyIDAgMCAxLTIgMkg1YTIgMiAwIDAgMS0yLTJ2LTQiLz48cG9seWxpbmUgcG9pbnRzPSIxNyA4IDEyIDMgNyA4Ii8+PGxpbmUgeDE9IjEyIiB4Mj0iMTIiIHkxPSIzIiB5Mj0iMTUiLz48L3N2Zz4=");
742
742
  }
743
+
744
+ .lightbox-overlay {
745
+ position: fixed;
746
+ top: 0;
747
+ left: 0;
748
+ width: 100%;
749
+ height: 100%;
750
+ display: flex;
751
+ justify-content: center;
752
+ align-items: center;
753
+ background: rgba(0, 0, 0, 0.8);
754
+ z-index: 10000;
755
+ padding: 1em;
756
+ /* small margin around edges */
757
+ box-sizing: border-box;
758
+ }
759
+
760
+ .lightbox-content {
761
+ display: flex;
762
+ flex-direction: column;
763
+ align-items: center;
764
+ max-width: 100%;
765
+ max-height: 100%;
766
+ height: 100vh;
767
+ /* Ensure full height usage */
768
+ box-sizing: border-box;
769
+ }
770
+
771
+ .lightbox-image-container {
772
+ display: flex;
773
+ justify-content: center;
774
+ align-items: center;
775
+ width: 100%;
776
+ flex: 1;
777
+ /* Take up remaining space after caption */
778
+ min-height: 0;
779
+ /* Allow flexbox shrinking */
780
+ }
781
+
782
+ .lightbox-image-container img {
783
+ width: calc(100vw - 1em);
784
+ /* Forces image to grow to this width */
785
+ height: 100%;
786
+ /* Use all available height in the flex container */
787
+ max-width: calc(100vw - 1em);
788
+ /* Prevents overflow */
789
+ max-height: 100%;
790
+ /* Prevents overflow */
791
+ object-fit: contain;
792
+ /* Maintains aspect ratio while filling the space */
793
+ cursor: zoom-out;
794
+ }
795
+
796
+ .lightbox-content .caption {
797
+ color: white;
798
+ font-family: hyperbook-body, sans-serif;
799
+ text-align: center;
800
+ font-size: 1em;
801
+ margin-top: 0.5em;
802
+ margin-bottom: 0.5em;
803
+ /* Add bottom margin for spacing */
804
+ max-width: 90vw;
805
+ word-wrap: break-word;
806
+ flex-shrink: 0;
807
+ /* Prevent caption from shrinking */
808
+ }