hyperbook 0.53.7 → 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
+ }
package/dist/index.js CHANGED
@@ -173369,14 +173369,16 @@ var remarkImage_default = (ctx) => () => {
173369
173369
  });
173370
173370
  }
173371
173371
  node3.data.hName = "figure";
173372
+ let figureProps = node3.data.hProperties;
173372
173373
  node3.data.hProperties = {
173373
- class: "normal"
173374
+ class: "normal " + figureProps?.class
173374
173375
  };
173375
173376
  node3.data.hChildren = [
173376
173377
  {
173377
173378
  type: "element",
173378
173379
  tagName: "img",
173379
173380
  properties: {
173381
+ ...figureProps,
173380
173382
  src: node3.url,
173381
173383
  alt: node3.alt,
173382
173384
  onclick: `hyperbook.toggleLightbox(this)`
@@ -187816,6 +187818,93 @@ function supersub() {
187816
187818
  };
187817
187819
  }
187818
187820
 
187821
+ // src/remarkImageAttrs.ts
187822
+ var ATTR_BLOCK_RE = /^\s*\{([\s\S]*?)\}/;
187823
+ var ATTR_PAIR_RE = /([:\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'}]+))/g;
187824
+ var SHORTHAND_RE = /([#.])([\w-]+)/g;
187825
+ function parseAttrBlock(input) {
187826
+ const m = ATTR_BLOCK_RE.exec(input);
187827
+ if (!m) return null;
187828
+ const inner2 = m[1];
187829
+ const attrs = {};
187830
+ let classes = [];
187831
+ let pair;
187832
+ while ((pair = ATTR_PAIR_RE.exec(inner2)) !== null) {
187833
+ const key2 = pair[1];
187834
+ const val = pair[2] ?? pair[3] ?? pair[4] ?? "";
187835
+ attrs[key2] = val;
187836
+ }
187837
+ let sm;
187838
+ while ((sm = SHORTHAND_RE.exec(inner2)) !== null) {
187839
+ if (sm[1] === "#") {
187840
+ attrs["id"] = sm[2];
187841
+ } else if (sm[1] === ".") {
187842
+ classes.push(sm[2]);
187843
+ }
187844
+ }
187845
+ if (classes.length > 0) {
187846
+ attrs["class"] = classes.join(" ");
187847
+ }
187848
+ return { attrs, length: m[0].length };
187849
+ }
187850
+ function detectAlignment(prev, next2) {
187851
+ let left = prev?.value.endsWith("-") ? prev.value.match(/-+$/)?.[0] ?? "" : "";
187852
+ let right = next2?.value.startsWith("-") ? next2.value.match(/^-+/)?.[0] ?? "" : "";
187853
+ if (left === "-" && !right) return "align-left";
187854
+ if (left === "--" && !right) return "align-leftplus";
187855
+ if (right === "-" && !left) return "align-right";
187856
+ if (right === "--" && !left) return "align-rightplus";
187857
+ if (left === "--" && right === "--") return "align-centerplus";
187858
+ return "";
187859
+ }
187860
+ var remarkImageAttrs = (ctx) => () => {
187861
+ return (tree) => {
187862
+ visit(tree, "paragraph", (para) => {
187863
+ const children = para.children;
187864
+ for (let i = 0; i < children.length; i++) {
187865
+ const img = children[i];
187866
+ if (!img || img.type !== "image") continue;
187867
+ const prev = children[i - 1];
187868
+ const next2 = children[i + 1];
187869
+ const alignClass = detectAlignment(prev, next2);
187870
+ img.data ||= {};
187871
+ img.data.hProperties ||= {};
187872
+ const hProps = img.data.hProperties;
187873
+ if (alignClass !== "") {
187874
+ const existing = hProps.class?.split(" ") ?? [];
187875
+ const filtered = existing.filter((c) => !c.startsWith("align-"));
187876
+ hProps.class = [...filtered, alignClass].join(" ");
187877
+ }
187878
+ if (prev && prev.type === "text" && prev.value.endsWith("-")) {
187879
+ prev.value = prev.value.replace(/-+$/, "");
187880
+ if (prev.value === "") children.splice(i - 1, 1);
187881
+ i--;
187882
+ }
187883
+ if (next2 && next2.type === "text" && next2.value.startsWith("-")) {
187884
+ next2.value = next2.value.replace(/^-+/, "");
187885
+ if (next2.value === "") children.splice(i + 1, 1);
187886
+ }
187887
+ const nextAfter = children[i + 1];
187888
+ if (nextAfter && nextAfter.type === "text") {
187889
+ const parsed = parseAttrBlock(nextAfter.value);
187890
+ if (parsed) {
187891
+ for (const [k, v] of Object.entries(parsed.attrs)) {
187892
+ hProps[k] = v;
187893
+ }
187894
+ const remainder = nextAfter.value.slice(parsed.length);
187895
+ if (remainder.length > 0) {
187896
+ nextAfter.value = remainder;
187897
+ } else {
187898
+ children.splice(i + 1, 1);
187899
+ }
187900
+ }
187901
+ }
187902
+ }
187903
+ });
187904
+ };
187905
+ };
187906
+ var remarkImageAttrs_default = remarkImageAttrs;
187907
+
187819
187908
  // src/process.ts
187820
187909
  var remark = (ctx) => {
187821
187910
  i18n.init(ctx.config.language || "en");
@@ -187826,6 +187915,7 @@ var remark = (ctx) => {
187826
187915
  dist_default,
187827
187916
  remarkDirectivePagelist_default(ctx),
187828
187917
  remarkLink_default(ctx),
187918
+ remarkImageAttrs_default(ctx),
187829
187919
  remarkImage_default(ctx),
187830
187920
  remarkGfm,
187831
187921
  supersub,
@@ -187924,7 +188014,7 @@ pako/dist/pako.esm.mjs:
187924
188014
  //# sourceMappingURL=index.js.map
187925
188015
 
187926
188016
  ;// CONCATENATED MODULE: ./package.json
187927
- const package_namespaceObject = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.53.7","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=12.22.0"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register && node postbuild.mjs"},"devDependencies":{"@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
188017
+ const package_namespaceObject = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.54.0","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=12.22.0"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register && node postbuild.mjs"},"devDependencies":{"@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
187928
188018
  ;// CONCATENATED MODULE: ./build.ts
187929
188019
 
187930
188020
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperbook",
3
- "version": "0.53.7",
3
+ "version": "0.54.0",
4
4
  "author": "Mike Barkmin",
5
5
  "homepage": "https://github.com/openpatch/hyperbook#readme",
6
6
  "license": "MIT",
@@ -54,7 +54,7 @@
54
54
  "update-check": "1.5.4",
55
55
  "ws": "^8.18.0",
56
56
  "@hyperbook/fs": "0.18.3",
57
- "@hyperbook/markdown": "0.29.5",
57
+ "@hyperbook/markdown": "0.30.0",
58
58
  "@hyperbook/types": "0.15.2"
59
59
  },
60
60
  "scripts": {