@hyperbook/markdown 0.29.5 → 0.31.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;
@@ -1,3 +1,8 @@
1
+ :root {
2
+ --alert-color: var(--color-nav-border);
3
+ --alert-content: "";
4
+ }
5
+
1
6
  .directive-alert>p {
2
7
  margin-bottom: 0;
3
8
  }
@@ -15,97 +20,45 @@
15
20
  position: relative;
16
21
  border-left-width: 4px;
17
22
  border-left-style: solid;
23
+ background-color: var(--color-nav);
24
+ border-left-color: var(--alert-color);
25
+ border-left-style: solid;
26
+ border-left-width: 4px;
18
27
  }
19
28
 
20
- .directive-alert::before {
29
+ .directive-alert.icon::before {
21
30
  border-radius: 100%;
22
31
  font-size: 14px;
23
32
  font-weight: 700;
24
- left: -12px;
25
- line-height: 20px;
33
+ left: -14px;
26
34
  display: flex;
27
35
  align-items: center;
28
36
  justify-content: center;
29
37
  position: absolute;
30
- height: 20px;
31
- width: 20px;
32
- text-align: center;
33
- top: 12px;
34
- }
35
-
36
- .directive-alert.success {
37
- border-left-style: solid;
38
- border-left-width: 4px;
39
- }
40
-
41
- .directive-alert.success::before {
42
- content: "✓";
43
- }
44
-
45
- .directive-alert.info {
46
- border-left-style: solid;
47
- border-left-width: 4px;
48
- }
49
-
50
- .directive-alert.info::before {
51
- content: "i";
52
- }
53
-
54
- .directive-alert.warn {
55
- border-left-style: solid;
56
- border-left-width: 4px;
57
- }
58
-
59
- .directive-alert.warn::before {
60
- content: "!";
61
- }
62
-
63
- .directive-alert.error {
64
- border-left-style: solid;
65
- border-left-width: 4px;
66
- }
67
-
68
- .directive-alert.error::before {
69
- content: "x";
70
- }
71
-
72
- .directive-alert {
73
- background-color: var(--color-nav);
74
- border-left-color: var(--color-nav-border);
75
- }
76
-
77
- .directive-alert::before {
38
+ height: 24px;
39
+ width: 24px;
40
+ top: 8px;
78
41
  color: #fff;
42
+ content: var(--alert-content);
43
+ background-color: var(--alert-color);
79
44
  }
80
45
 
81
46
  .directive-alert.success {
82
- border-left-color: #00c851;
83
- }
84
-
85
- .directive-alert.success::before {
86
- background-color: #00c851;
47
+ --alert-color: #00c851;
48
+ --alert-content: "✓";
87
49
  }
88
50
 
89
51
  .directive-alert.info {
90
- border-left-color: #33b5e5;
91
- }
92
-
93
- .directive-alert.info::before {
94
- background-color: #33b5e5;
52
+ --alert-color: #33b5e5;
53
+ --alert-content: "i";
95
54
  }
96
55
 
97
56
  .directive-alert.warn {
98
- border-left-color: #f0b429;
99
- }
100
-
101
- .directive-alert.warn::before {
102
- background-color: #f0b429;
57
+ --alert-color: #f0b429;
58
+ --alert-content: "!";
103
59
  }
104
60
 
105
61
  .directive-alert.error {
106
- border-left-color: #ef4e4e;
107
- }
108
-
109
- .directive-alert.error::before {
110
- background-color: #ef4e4e;
62
+ --alert-color: #ef4e4e;
63
+ --alert-content: "x";
111
64
  }
@@ -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
+ }
package/dist/index.js CHANGED
@@ -63923,14 +63923,16 @@ var remarkImage_default = (ctx) => () => {
63923
63923
  });
63924
63924
  }
63925
63925
  node3.data.hName = "figure";
63926
+ let figureProps = node3.data.hProperties;
63926
63927
  node3.data.hProperties = {
63927
- class: "normal"
63928
+ class: "normal " + figureProps?.class
63928
63929
  };
63929
63930
  node3.data.hChildren = [
63930
63931
  {
63931
63932
  type: "element",
63932
63933
  tagName: "img",
63933
63934
  properties: {
63935
+ ...figureProps,
63934
63936
  src: node3.url,
63935
63937
  alt: node3.alt,
63936
63938
  onclick: `hyperbook.toggleLightbox(this)`
@@ -63989,10 +63991,16 @@ var remarkDirectiveAlert_default = (ctx) => () => {
63989
63991
  const data = node3.data || (node3.data = {});
63990
63992
  expectContainerDirective(node3, file, name);
63991
63993
  registerDirective(file, name, [], ["style.css"], []);
63992
- const type = Object.keys(node3.attributes || {}).join(" ");
63994
+ const color2 = node3.attributes?.color;
63995
+ const content5 = node3.attributes?.label;
63996
+ const type = Object.keys(node3.attributes || {}).join(" ").trim();
63997
+ const icon = content5 || type;
63998
+ delete node3.attributes?.color;
63999
+ delete node3.attributes?.label;
63993
64000
  data.hName = "div";
63994
64001
  data.hProperties = {
63995
- class: ("directive-alert " + type).trim()
64002
+ class: `directive-alert ${type} ${icon ? "icon" : ""}`.trim(),
64003
+ style: `${color2 ? `--alert-color: ${color2};` : ""} ${content5 ? `--alert-content: '${content5}';` : ""}`
63996
64004
  };
63997
64005
  }
63998
64006
  });
@@ -78370,6 +78378,93 @@ function supersub() {
78370
78378
  };
78371
78379
  }
78372
78380
 
78381
+ // src/remarkImageAttrs.ts
78382
+ var ATTR_BLOCK_RE = /^\s*\{([\s\S]*?)\}/;
78383
+ var ATTR_PAIR_RE = /([:\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'}]+))/g;
78384
+ var SHORTHAND_RE = /([#.])([\w-]+)/g;
78385
+ function parseAttrBlock(input) {
78386
+ const m = ATTR_BLOCK_RE.exec(input);
78387
+ if (!m) return null;
78388
+ const inner2 = m[1];
78389
+ const attrs = {};
78390
+ let classes = [];
78391
+ let pair;
78392
+ while ((pair = ATTR_PAIR_RE.exec(inner2)) !== null) {
78393
+ const key2 = pair[1];
78394
+ const val = pair[2] ?? pair[3] ?? pair[4] ?? "";
78395
+ attrs[key2] = val;
78396
+ }
78397
+ let sm;
78398
+ while ((sm = SHORTHAND_RE.exec(inner2)) !== null) {
78399
+ if (sm[1] === "#") {
78400
+ attrs["id"] = sm[2];
78401
+ } else if (sm[1] === ".") {
78402
+ classes.push(sm[2]);
78403
+ }
78404
+ }
78405
+ if (classes.length > 0) {
78406
+ attrs["class"] = classes.join(" ");
78407
+ }
78408
+ return { attrs, length: m[0].length };
78409
+ }
78410
+ function detectAlignment(prev, next2) {
78411
+ let left = prev?.value.endsWith("-") ? prev.value.match(/-+$/)?.[0] ?? "" : "";
78412
+ let right = next2?.value.startsWith("-") ? next2.value.match(/^-+/)?.[0] ?? "" : "";
78413
+ if (left === "-" && !right) return "align-left";
78414
+ if (left === "--" && !right) return "align-leftplus";
78415
+ if (right === "-" && !left) return "align-right";
78416
+ if (right === "--" && !left) return "align-rightplus";
78417
+ if (left === "--" && right === "--") return "align-centerplus";
78418
+ return "";
78419
+ }
78420
+ var remarkImageAttrs = (ctx) => () => {
78421
+ return (tree) => {
78422
+ visit(tree, "paragraph", (para) => {
78423
+ const children = para.children;
78424
+ for (let i = 0; i < children.length; i++) {
78425
+ const img = children[i];
78426
+ if (!img || img.type !== "image") continue;
78427
+ const prev = children[i - 1];
78428
+ const next2 = children[i + 1];
78429
+ const alignClass = detectAlignment(prev, next2);
78430
+ img.data ||= {};
78431
+ img.data.hProperties ||= {};
78432
+ const hProps = img.data.hProperties;
78433
+ if (alignClass !== "") {
78434
+ const existing = hProps.class?.split(" ") ?? [];
78435
+ const filtered = existing.filter((c) => !c.startsWith("align-"));
78436
+ hProps.class = [...filtered, alignClass].join(" ");
78437
+ }
78438
+ if (prev && prev.type === "text" && prev.value.endsWith("-")) {
78439
+ prev.value = prev.value.replace(/-+$/, "");
78440
+ if (prev.value === "") children.splice(i - 1, 1);
78441
+ i--;
78442
+ }
78443
+ if (next2 && next2.type === "text" && next2.value.startsWith("-")) {
78444
+ next2.value = next2.value.replace(/^-+/, "");
78445
+ if (next2.value === "") children.splice(i + 1, 1);
78446
+ }
78447
+ const nextAfter = children[i + 1];
78448
+ if (nextAfter && nextAfter.type === "text") {
78449
+ const parsed = parseAttrBlock(nextAfter.value);
78450
+ if (parsed) {
78451
+ for (const [k, v] of Object.entries(parsed.attrs)) {
78452
+ hProps[k] = v;
78453
+ }
78454
+ const remainder = nextAfter.value.slice(parsed.length);
78455
+ if (remainder.length > 0) {
78456
+ nextAfter.value = remainder;
78457
+ } else {
78458
+ children.splice(i + 1, 1);
78459
+ }
78460
+ }
78461
+ }
78462
+ }
78463
+ });
78464
+ };
78465
+ };
78466
+ var remarkImageAttrs_default = remarkImageAttrs;
78467
+
78373
78468
  // src/process.ts
78374
78469
  var remark = (ctx) => {
78375
78470
  i18n.init(ctx.config.language || "en");
@@ -78380,6 +78475,7 @@ var remark = (ctx) => {
78380
78475
  dist_default,
78381
78476
  remarkDirectivePagelist_default(ctx),
78382
78477
  remarkLink_default(ctx),
78478
+ remarkImageAttrs_default(ctx),
78383
78479
  remarkImage_default(ctx),
78384
78480
  remarkGfm,
78385
78481
  supersub,