@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/labels.js CHANGED
@@ -37210,8 +37210,27 @@ function withMathStyles(htmlDocument) {
37210
37210
  const head = htmlDocument.search(/<\/head>/i);
37211
37211
  return head >= 0 ? htmlDocument.slice(0, head) + style + htmlDocument.slice(head) : style + htmlDocument;
37212
37212
  }
37213
+ var PRINT_HOST = /* @__PURE__ */ Symbol.for("ai-matrx.print.host");
37214
+ function getPrintHost() {
37215
+ return globalThis[PRINT_HOST] ?? null;
37216
+ }
37217
+ function handToPrintHost(htmlDocument, title) {
37218
+ const host = getPrintHost();
37219
+ if (!host) return false;
37220
+ try {
37221
+ const done = host(htmlDocument, { title });
37222
+ if (done && typeof done.catch === "function") {
37223
+ done.catch((error) => console.error("[@ai-matrx/print] the host's print failed", error));
37224
+ }
37225
+ return true;
37226
+ } catch (error) {
37227
+ console.error("[@ai-matrx/print] the host's print threw; using the print window instead", error);
37228
+ return false;
37229
+ }
37230
+ }
37213
37231
  function openPrintWindow(rawDocument, filename = "print", windowFeatures = "width=920,height=720,scrollbars=yes") {
37214
37232
  const htmlDocument = withMathStyles(rawDocument);
37233
+ if (handToPrintHost(htmlDocument, filename)) return "opened";
37215
37234
  const win = openOutbound("", "_blank", windowFeatures);
37216
37235
  if (!win) return openPrintWindowFallback(htmlDocument, filename);
37217
37236
  win.document.open();