@ai-matrx/print 0.12.39 → 0.12.40

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/markdown.cjs CHANGED
@@ -87,8 +87,27 @@ function withMathStyles(htmlDocument) {
87
87
  const head = htmlDocument.search(/<\/head>/i);
88
88
  return head >= 0 ? htmlDocument.slice(0, head) + style + htmlDocument.slice(head) : style + htmlDocument;
89
89
  }
90
+ var PRINT_HOST = /* @__PURE__ */ Symbol.for("ai-matrx.print.host");
91
+ function getPrintHost() {
92
+ return globalThis[PRINT_HOST] ?? null;
93
+ }
94
+ function handToPrintHost(htmlDocument, title) {
95
+ const host = getPrintHost();
96
+ if (!host) return false;
97
+ try {
98
+ const done = host(htmlDocument, { title });
99
+ if (done && typeof done.catch === "function") {
100
+ done.catch((error) => console.error("[@ai-matrx/print] the host's print failed", error));
101
+ }
102
+ return true;
103
+ } catch (error) {
104
+ console.error("[@ai-matrx/print] the host's print threw; using the print window instead", error);
105
+ return false;
106
+ }
107
+ }
90
108
  function openPrintWindow(rawDocument, filename = "print", windowFeatures = "width=920,height=720,scrollbars=yes") {
91
109
  const htmlDocument = withMathStyles(rawDocument);
110
+ if (handToPrintHost(htmlDocument, filename)) return "opened";
92
111
  const win = (0, import_outbound.openOutbound)("", "_blank", windowFeatures);
93
112
  if (!win) return openPrintWindowFallback(htmlDocument, filename);
94
113
  win.document.open();
@@ -97,7 +116,7 @@ function openPrintWindow(rawDocument, filename = "print", windowFeatures = "widt
97
116
  return "opened";
98
117
  }
99
118
  function openPendingPrintWindow(filename = "print", windowFeatures = "width=920,height=720,scrollbars=yes") {
100
- const win = (0, import_outbound.openOutbound)("", "_blank", windowFeatures);
119
+ const win = getPrintHost() ? null : (0, import_outbound.openOutbound)("", "_blank", windowFeatures);
101
120
  if (win) {
102
121
  win.document.open();
103
122
  win.document.write(
@@ -108,6 +127,7 @@ function openPendingPrintWindow(filename = "print", windowFeatures = "width=920,
108
127
  return {
109
128
  write(rawDocument) {
110
129
  const htmlDocument = withMathStyles(rawDocument);
130
+ if (!win && handToPrintHost(htmlDocument, filename)) return "opened";
111
131
  if (!win || win.closed) return openPrintWindowFallback(htmlDocument, filename);
112
132
  win.document.open();
113
133
  win.document.write(htmlDocument);