@hyperbook/markdown 0.29.5 → 0.30.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.
- package/dist/assets/client.js +36 -2
- package/dist/assets/content.css +53 -33
- package/dist/assets/shell.css +66 -0
- package/dist/index.js +91 -1
- package/dist/index.js.map +4 -4
- package/dist/remarkImageAttrs.d.ts +4 -0
- package/package.json +1 -1
package/dist/assets/client.js
CHANGED
|
@@ -230,8 +230,42 @@ var hyperbook = (function () {
|
|
|
230
230
|
* @param {HTMLElement} el - The element to toggle.
|
|
231
231
|
*/
|
|
232
232
|
function toggleLightbox(el) {
|
|
233
|
-
|
|
234
|
-
|
|
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) {
|
package/dist/assets/content.css
CHANGED
|
@@ -27,27 +27,42 @@ figure {
|
|
|
27
27
|
max-width: 100%;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
.hyperbook-markdown figure.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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
|
|
170
|
+
.hyperbook-markdown li+li {
|
|
152
171
|
margin-top: 0.25em;
|
|
153
172
|
}
|
|
154
173
|
|
|
155
|
-
.hyperbook-markdown li
|
|
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
|
|
309
|
-
.hyperbook-markdown #toc-toggle
|
|
310
|
-
.hyperbook-markdown #toc-toggle
|
|
311
|
-
.hyperbook-markdown #toc-toggle
|
|
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
|
|
454
|
+
.toc-drawer-content>nav {
|
|
435
455
|
padding: 20px;
|
|
436
456
|
flex: 1;
|
|
437
457
|
}
|
|
438
458
|
|
|
439
|
-
.toc-drawer-content
|
|
459
|
+
.toc-drawer-content>nav li a {
|
|
440
460
|
display: block;
|
|
441
461
|
}
|
|
442
462
|
|
|
443
|
-
.toc-drawer-content
|
|
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
|
|
551
|
-
.hyperbook-markdown #toc-toggle
|
|
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
|
|
559
|
-
.hyperbook-markdown #toc-toggle
|
|
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;
|
package/dist/assets/shell.css
CHANGED
|
@@ -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)`
|
|
@@ -78370,6 +78372,93 @@ function supersub() {
|
|
|
78370
78372
|
};
|
|
78371
78373
|
}
|
|
78372
78374
|
|
|
78375
|
+
// src/remarkImageAttrs.ts
|
|
78376
|
+
var ATTR_BLOCK_RE = /^\s*\{([\s\S]*?)\}/;
|
|
78377
|
+
var ATTR_PAIR_RE = /([:\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'}]+))/g;
|
|
78378
|
+
var SHORTHAND_RE = /([#.])([\w-]+)/g;
|
|
78379
|
+
function parseAttrBlock(input) {
|
|
78380
|
+
const m = ATTR_BLOCK_RE.exec(input);
|
|
78381
|
+
if (!m) return null;
|
|
78382
|
+
const inner2 = m[1];
|
|
78383
|
+
const attrs = {};
|
|
78384
|
+
let classes = [];
|
|
78385
|
+
let pair;
|
|
78386
|
+
while ((pair = ATTR_PAIR_RE.exec(inner2)) !== null) {
|
|
78387
|
+
const key2 = pair[1];
|
|
78388
|
+
const val = pair[2] ?? pair[3] ?? pair[4] ?? "";
|
|
78389
|
+
attrs[key2] = val;
|
|
78390
|
+
}
|
|
78391
|
+
let sm;
|
|
78392
|
+
while ((sm = SHORTHAND_RE.exec(inner2)) !== null) {
|
|
78393
|
+
if (sm[1] === "#") {
|
|
78394
|
+
attrs["id"] = sm[2];
|
|
78395
|
+
} else if (sm[1] === ".") {
|
|
78396
|
+
classes.push(sm[2]);
|
|
78397
|
+
}
|
|
78398
|
+
}
|
|
78399
|
+
if (classes.length > 0) {
|
|
78400
|
+
attrs["class"] = classes.join(" ");
|
|
78401
|
+
}
|
|
78402
|
+
return { attrs, length: m[0].length };
|
|
78403
|
+
}
|
|
78404
|
+
function detectAlignment(prev, next2) {
|
|
78405
|
+
let left = prev?.value.endsWith("-") ? prev.value.match(/-+$/)?.[0] ?? "" : "";
|
|
78406
|
+
let right = next2?.value.startsWith("-") ? next2.value.match(/^-+/)?.[0] ?? "" : "";
|
|
78407
|
+
if (left === "-" && !right) return "align-left";
|
|
78408
|
+
if (left === "--" && !right) return "align-leftplus";
|
|
78409
|
+
if (right === "-" && !left) return "align-right";
|
|
78410
|
+
if (right === "--" && !left) return "align-rightplus";
|
|
78411
|
+
if (left === "--" && right === "--") return "align-centerplus";
|
|
78412
|
+
return "";
|
|
78413
|
+
}
|
|
78414
|
+
var remarkImageAttrs = (ctx) => () => {
|
|
78415
|
+
return (tree) => {
|
|
78416
|
+
visit(tree, "paragraph", (para) => {
|
|
78417
|
+
const children = para.children;
|
|
78418
|
+
for (let i = 0; i < children.length; i++) {
|
|
78419
|
+
const img = children[i];
|
|
78420
|
+
if (!img || img.type !== "image") continue;
|
|
78421
|
+
const prev = children[i - 1];
|
|
78422
|
+
const next2 = children[i + 1];
|
|
78423
|
+
const alignClass = detectAlignment(prev, next2);
|
|
78424
|
+
img.data ||= {};
|
|
78425
|
+
img.data.hProperties ||= {};
|
|
78426
|
+
const hProps = img.data.hProperties;
|
|
78427
|
+
if (alignClass !== "") {
|
|
78428
|
+
const existing = hProps.class?.split(" ") ?? [];
|
|
78429
|
+
const filtered = existing.filter((c) => !c.startsWith("align-"));
|
|
78430
|
+
hProps.class = [...filtered, alignClass].join(" ");
|
|
78431
|
+
}
|
|
78432
|
+
if (prev && prev.type === "text" && prev.value.endsWith("-")) {
|
|
78433
|
+
prev.value = prev.value.replace(/-+$/, "");
|
|
78434
|
+
if (prev.value === "") children.splice(i - 1, 1);
|
|
78435
|
+
i--;
|
|
78436
|
+
}
|
|
78437
|
+
if (next2 && next2.type === "text" && next2.value.startsWith("-")) {
|
|
78438
|
+
next2.value = next2.value.replace(/^-+/, "");
|
|
78439
|
+
if (next2.value === "") children.splice(i + 1, 1);
|
|
78440
|
+
}
|
|
78441
|
+
const nextAfter = children[i + 1];
|
|
78442
|
+
if (nextAfter && nextAfter.type === "text") {
|
|
78443
|
+
const parsed = parseAttrBlock(nextAfter.value);
|
|
78444
|
+
if (parsed) {
|
|
78445
|
+
for (const [k, v] of Object.entries(parsed.attrs)) {
|
|
78446
|
+
hProps[k] = v;
|
|
78447
|
+
}
|
|
78448
|
+
const remainder = nextAfter.value.slice(parsed.length);
|
|
78449
|
+
if (remainder.length > 0) {
|
|
78450
|
+
nextAfter.value = remainder;
|
|
78451
|
+
} else {
|
|
78452
|
+
children.splice(i + 1, 1);
|
|
78453
|
+
}
|
|
78454
|
+
}
|
|
78455
|
+
}
|
|
78456
|
+
}
|
|
78457
|
+
});
|
|
78458
|
+
};
|
|
78459
|
+
};
|
|
78460
|
+
var remarkImageAttrs_default = remarkImageAttrs;
|
|
78461
|
+
|
|
78373
78462
|
// src/process.ts
|
|
78374
78463
|
var remark = (ctx) => {
|
|
78375
78464
|
i18n.init(ctx.config.language || "en");
|
|
@@ -78380,6 +78469,7 @@ var remark = (ctx) => {
|
|
|
78380
78469
|
dist_default,
|
|
78381
78470
|
remarkDirectivePagelist_default(ctx),
|
|
78382
78471
|
remarkLink_default(ctx),
|
|
78472
|
+
remarkImageAttrs_default(ctx),
|
|
78383
78473
|
remarkImage_default(ctx),
|
|
78384
78474
|
remarkGfm,
|
|
78385
78475
|
supersub,
|