@bendyline/squisq-formats 2.4.6 → 2.5.1
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/NOTICE.md +1 -1
- package/dist/{chunk-KN62QJYK.js → chunk-2LT3JL7U.js} +75 -24
- package/dist/{chunk-DNGNODJP.js → chunk-5JQ5NDRC.js} +12 -2
- package/dist/{chunk-DWNNYO5H.js → chunk-A6N6IN3I.js} +5 -1
- package/dist/{chunk-6X5XN3CZ.js → chunk-AVOZAKGP.js} +3 -0
- package/dist/chunk-BXWNU4T5.js +108 -0
- package/dist/{chunk-BGDN7BXK.js → chunk-FIOSE4BO.js} +78 -6
- package/dist/{chunk-XCV242AO.js → chunk-FMQWNPCV.js} +5 -2
- package/dist/{chunk-KT5DX2QP.js → chunk-M7XPXGXW.js} +32 -9
- package/dist/chunk-RX55T5HO.js +1342 -0
- package/dist/{chunk-N2ZN3MQN.js → chunk-T4PX33AG.js} +262 -14
- package/dist/{chunk-BVGJ54NV.js → chunk-TVUX3RUC.js} +1 -1
- package/dist/docx/index.js +4 -3
- package/dist/epub/index.js +3 -2
- package/dist/export-Boq78GMq.d.ts +270 -0
- package/dist/html/index.js +2 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -12
- package/dist/outside-in/index.d.ts +2 -2
- package/dist/outside-in/index.js +2 -2
- package/dist/pdf/index.js +2 -1
- package/dist/pptx/index.js +3 -3
- package/dist/registry/index.d.ts +3 -3
- package/dist/registry/index.js +1 -1
- package/dist/{types-HDLauUoa.d.ts → types-bwP9PBSk.d.ts} +1 -1
- package/dist/xlsx/index.d.ts +2 -2
- package/dist/xlsx/index.js +8 -4
- package/package.json +3 -3
- package/dist/chunk-UIBTXX4L.js +0 -446
- package/dist/export-D9msROJS.d.ts +0 -81
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
fontAwesomeFaces,
|
|
7
7
|
fontAwesomeGlyph
|
|
8
8
|
} from "./chunk-USU6HTKB.js";
|
|
9
|
+
import {
|
|
10
|
+
FootnoteIndex
|
|
11
|
+
} from "./chunk-BXWNU4T5.js";
|
|
9
12
|
|
|
10
13
|
// src/pdf/export.ts
|
|
11
14
|
import { PDFDocument, StandardFonts, rgb, PDFString } from "pdf-lib";
|
|
@@ -450,6 +453,7 @@ async function createExportContext(pdfDoc, options, doc) {
|
|
|
450
453
|
contentWidth: pageWidth - 2 * margin,
|
|
451
454
|
bottomY: margin,
|
|
452
455
|
colors: { text: colorText, heading: colorHeading, link: colorLink },
|
|
456
|
+
footnotes: new FootnoteIndex(doc),
|
|
453
457
|
text: new WinAnsiTracker(),
|
|
454
458
|
signal: options.signal
|
|
455
459
|
};
|
|
@@ -464,19 +468,25 @@ function newPage(ctx) {
|
|
|
464
468
|
ctx.page = page;
|
|
465
469
|
ctx.y = ctx.pageHeight - ctx.margin;
|
|
466
470
|
}
|
|
471
|
+
var VERT_ALIGN_SCALE = 0.72;
|
|
472
|
+
function vertAlignShift(kind, baseSize) {
|
|
473
|
+
return kind === "superscript" ? baseSize * 0.33 : baseSize * -0.14;
|
|
474
|
+
}
|
|
467
475
|
function flattenInlines(nodes, ctx, state) {
|
|
468
476
|
const spans = [];
|
|
469
477
|
for (const node of nodes) {
|
|
470
478
|
switch (node.type) {
|
|
471
479
|
case "text": {
|
|
472
480
|
const font = state.code ? state.bold ? ctx.fonts.monoBold : ctx.fonts.mono : pickFont(ctx, state.bold, state.italic);
|
|
481
|
+
const baseSize = state.code ? CODE_FONT_SIZE : ctx.fontSize;
|
|
473
482
|
spans.push({
|
|
474
483
|
text: ctx.text.clean(node.value),
|
|
475
484
|
font,
|
|
476
|
-
fontSize: state.
|
|
485
|
+
fontSize: state.vertAlign ? baseSize * VERT_ALIGN_SCALE : baseSize,
|
|
477
486
|
color: state.code ? COLOR_CODE_TEXT : state.color ?? ctx.colors.text,
|
|
478
487
|
link: state.link,
|
|
479
|
-
strikethrough: state.strikethrough
|
|
488
|
+
strikethrough: state.strikethrough,
|
|
489
|
+
...state.vertAlign ? { baselineShift: vertAlignShift(state.vertAlign, baseSize) } : {}
|
|
480
490
|
});
|
|
481
491
|
break;
|
|
482
492
|
}
|
|
@@ -498,6 +508,15 @@ function flattenInlines(nodes, ctx, state) {
|
|
|
498
508
|
})
|
|
499
509
|
);
|
|
500
510
|
break;
|
|
511
|
+
case "superscript":
|
|
512
|
+
case "subscript":
|
|
513
|
+
spans.push(
|
|
514
|
+
...flattenInlines(node.children, ctx, {
|
|
515
|
+
...state,
|
|
516
|
+
vertAlign: node.type === "superscript" ? "superscript" : "subscript"
|
|
517
|
+
})
|
|
518
|
+
);
|
|
519
|
+
break;
|
|
501
520
|
case "inlineCode": {
|
|
502
521
|
spans.push({
|
|
503
522
|
text: ctx.text.clean(node.value),
|
|
@@ -585,11 +604,13 @@ function flattenInlines(nodes, ctx, state) {
|
|
|
585
604
|
break;
|
|
586
605
|
case "footnoteReference": {
|
|
587
606
|
const ref = node;
|
|
607
|
+
const marker = ctx.footnotes ? String(ctx.footnotes.cite(ref.identifier).number) : ref.label ?? ref.identifier;
|
|
588
608
|
spans.push({
|
|
589
|
-
text: ctx.text.clean(
|
|
609
|
+
text: ctx.text.clean(marker),
|
|
590
610
|
font: ctx.fonts.regular,
|
|
591
|
-
fontSize: ctx.fontSize *
|
|
592
|
-
color: ctx.colors.link
|
|
611
|
+
fontSize: ctx.fontSize * VERT_ALIGN_SCALE,
|
|
612
|
+
color: ctx.colors.link,
|
|
613
|
+
baselineShift: vertAlignShift("superscript", ctx.fontSize)
|
|
593
614
|
});
|
|
594
615
|
break;
|
|
595
616
|
}
|
|
@@ -626,9 +647,10 @@ function drawSpans(spans, ctx, availableWidth, x0) {
|
|
|
626
647
|
ensureSpace(ctx, lineHeight);
|
|
627
648
|
let x = x0;
|
|
628
649
|
for (const span of line) {
|
|
650
|
+
const spanBaseline = ctx.y - span.fontSize + (span.baselineShift ?? 0);
|
|
629
651
|
ctx.page.drawText(span.text, {
|
|
630
652
|
x,
|
|
631
|
-
y:
|
|
653
|
+
y: spanBaseline,
|
|
632
654
|
// pdf-lib y is baseline
|
|
633
655
|
size: span.fontSize,
|
|
634
656
|
font: span.font,
|
|
@@ -636,7 +658,7 @@ function drawSpans(spans, ctx, availableWidth, x0) {
|
|
|
636
658
|
});
|
|
637
659
|
const textWidth = span.font.widthOfTextAtSize(span.text, span.fontSize);
|
|
638
660
|
if (span.link) {
|
|
639
|
-
const baseline =
|
|
661
|
+
const baseline = spanBaseline;
|
|
640
662
|
ctx.page.drawLine({
|
|
641
663
|
start: { x, y: baseline - 1 },
|
|
642
664
|
end: { x: x + textWidth, y: baseline - 1 },
|
|
@@ -659,7 +681,7 @@ function drawSpans(spans, ctx, availableWidth, x0) {
|
|
|
659
681
|
ctx.page.node.addAnnot(annotation);
|
|
660
682
|
}
|
|
661
683
|
if (span.strikethrough) {
|
|
662
|
-
const midY =
|
|
684
|
+
const midY = spanBaseline + span.fontSize * 0.4;
|
|
663
685
|
ctx.page.drawLine({
|
|
664
686
|
start: { x, y: midY },
|
|
665
687
|
end: { x: x + textWidth, y: midY },
|
|
@@ -1022,7 +1044,8 @@ function renderMathBlock(node, ctx, extraIndent) {
|
|
|
1022
1044
|
ctx.y -= PARAGRAPH_SPACING;
|
|
1023
1045
|
}
|
|
1024
1046
|
function renderFootnoteDefinition(node, ctx, extraIndent) {
|
|
1025
|
-
const
|
|
1047
|
+
const number = ctx.footnotes?.numberFor(node.identifier);
|
|
1048
|
+
const label = ctx.text.clean(number !== void 0 ? `${number}.` : `[${node.identifier}]`);
|
|
1026
1049
|
const lineH = ctx.fontSize * LINE_HEIGHT_FACTOR;
|
|
1027
1050
|
ensureSpace(ctx, lineH);
|
|
1028
1051
|
ctx.page.drawText(label, {
|