@ai-matrx/print 0.12.7 → 0.12.9
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/CHANGELOG.md +15 -0
- package/dist/flashcards.cjs +52 -12
- package/dist/flashcards.cjs.map +1 -1
- package/dist/flashcards.js +52 -12
- package/dist/flashcards.js.map +1 -1
- package/package.json +4 -4
package/dist/flashcards.js
CHANGED
|
@@ -247,13 +247,20 @@ function resolveSettings(raw) {
|
|
|
247
247
|
showImages: b("showImages")
|
|
248
248
|
};
|
|
249
249
|
}
|
|
250
|
+
function toCard(entry) {
|
|
251
|
+
if (!entry || typeof entry !== "object") return null;
|
|
252
|
+
const e = entry;
|
|
253
|
+
if (typeof e.front === "string") return entry;
|
|
254
|
+
const front = e.question ?? e.term;
|
|
255
|
+
if (typeof front !== "string") return null;
|
|
256
|
+
const back = e.back ?? e.answer ?? e.definition;
|
|
257
|
+
return { ...entry, front, back: typeof back === "string" ? back : "" };
|
|
258
|
+
}
|
|
250
259
|
function extractCards(data) {
|
|
251
260
|
if (!data) return [];
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
return [];
|
|
261
|
+
const list = Array.isArray(data) ? data : typeof data === "object" && "cards" in data ? data.cards : null;
|
|
262
|
+
if (!Array.isArray(list)) return [];
|
|
263
|
+
return list.map(toCard).filter((card) => card !== null);
|
|
257
264
|
}
|
|
258
265
|
function faceImageHtml(card, face, showImages = true) {
|
|
259
266
|
if (!showImages) return "";
|
|
@@ -574,16 +581,22 @@ var STUDY_SHEET_STYLES = `
|
|
|
574
581
|
tbody tr:nth-child(even) td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
|
|
575
582
|
}
|
|
576
583
|
`;
|
|
577
|
-
|
|
584
|
+
var STUDY_SHEET_LEGACY_CLASSES = {
|
|
585
|
+
header: "deck-header",
|
|
586
|
+
title: "deck-title",
|
|
587
|
+
meta: "deck-meta",
|
|
588
|
+
rowNum: "row-num"
|
|
589
|
+
};
|
|
590
|
+
function renderStudySheet(cards, title, s, startIndex = 0, c = STUDY_SHEET_LEGACY_CLASSES) {
|
|
578
591
|
const rows = cards.map(
|
|
579
592
|
(card, i) => ` <tr>
|
|
580
|
-
<td><span class="
|
|
593
|
+
<td><span class="${c.rowNum}">${startIndex + i + 1}.</span>${faceImageHtml(card, "front", s.showImages)}${mathTextHtml(card.front)}</td>
|
|
581
594
|
<td>${faceImageHtml(card, "back", s.showImages)}${mathTextHtml(card.back ?? "")}</td>
|
|
582
595
|
</tr>`
|
|
583
596
|
).join("\n");
|
|
584
|
-
return `<div class="
|
|
585
|
-
<h1 class="
|
|
586
|
-
<div class="
|
|
597
|
+
return `<div class="${c.header}">
|
|
598
|
+
<h1 class="${c.title}">${mathTextHtml(title)}</h1>
|
|
599
|
+
<div class="${c.meta}">${cards.length} card${cards.length !== 1 ? "s" : ""} \xB7 Study sheet</div>
|
|
587
600
|
</div>
|
|
588
601
|
<table>
|
|
589
602
|
<thead>
|
|
@@ -597,6 +610,29 @@ ${rows}
|
|
|
597
610
|
</tbody>
|
|
598
611
|
</table>`;
|
|
599
612
|
}
|
|
613
|
+
var COMPOSED_CLASSES = {
|
|
614
|
+
header: "matrx-fc-header",
|
|
615
|
+
title: "matrx-fc-title",
|
|
616
|
+
meta: "matrx-fc-meta",
|
|
617
|
+
rowNum: "matrx-fc-row-num"
|
|
618
|
+
};
|
|
619
|
+
var COMPOSED_STUDY_SHEET_CSS = `
|
|
620
|
+
.matrx-fc-sheet .matrx-fc-header { border-bottom: 1.5px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 16px; }
|
|
621
|
+
.matrx-fc-sheet .matrx-fc-title { font-size: 13pt; font-weight: 700; color: #1e293b; margin: 0 0 4px 0; letter-spacing: -0.01em; border-bottom: none; }
|
|
622
|
+
.matrx-fc-sheet .matrx-fc-meta { font-size: 8.5pt; color: #64748b; }
|
|
623
|
+
.matrx-fc-sheet table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 10pt; }
|
|
624
|
+
.matrx-fc-sheet thead th { background: #1e293b; color: #f1f5f9; padding: 8px 12px; text-align: left; font-size: 8.5pt; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
|
|
625
|
+
.matrx-fc-sheet thead th:first-child { width: 38%; }
|
|
626
|
+
.matrx-fc-sheet tbody tr { page-break-inside: avoid; break-inside: avoid; }
|
|
627
|
+
.matrx-fc-sheet tbody tr:nth-child(even) td { background: #f8fafc; }
|
|
628
|
+
.matrx-fc-sheet tbody td { padding: 8px 12px; vertical-align: top; border-bottom: 1px solid #e2e8f0; line-height: 1.5; white-space: pre-line; }
|
|
629
|
+
.matrx-fc-sheet tbody td:first-child { font-weight: 600; border-right: 1px solid #e2e8f0; color: #1e3a5f; }
|
|
630
|
+
.matrx-fc-sheet .matrx-fc-row-num { display: inline-block; width: 18px; font-size: 8pt; color: #94a3b8; font-weight: 400; margin-right: 4px; }
|
|
631
|
+
.matrx-fc-sheet .matrx-fc-face-image { display: block; max-width: 100%; max-height: 1.6in; margin: 0 auto 6px auto; object-fit: contain; }
|
|
632
|
+
@media print {
|
|
633
|
+
.matrx-fc-sheet thead th, .matrx-fc-sheet tbody tr:nth-child(even) td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
|
|
634
|
+
}
|
|
635
|
+
`;
|
|
600
636
|
var FRONT_ONLY_STYLES = `
|
|
601
637
|
${BASE_STYLES}
|
|
602
638
|
|
|
@@ -1709,8 +1745,12 @@ var flashcardsPrinter = {
|
|
|
1709
1745
|
// paper cannot flip, and a cut sheet belongs to the deck's own print.
|
|
1710
1746
|
toPrintHtml(data) {
|
|
1711
1747
|
const cards = extractCards(data);
|
|
1712
|
-
if (cards.length === 0) return
|
|
1713
|
-
|
|
1748
|
+
if (cards.length === 0) return null;
|
|
1749
|
+
const sheet = renderStudySheet(cards, deriveTitle(data), resolveSettings(void 0), 0, COMPOSED_CLASSES).replaceAll(
|
|
1750
|
+
'class="face-image"',
|
|
1751
|
+
'class="matrx-fc-face-image"'
|
|
1752
|
+
);
|
|
1753
|
+
return { html: `<div class="matrx-fc-sheet">${sheet}</div>`, css: COMPOSED_STUDY_SHEET_CSS };
|
|
1714
1754
|
}
|
|
1715
1755
|
};
|
|
1716
1756
|
export {
|