@marimo-team/frontend 0.19.7-dev31 → 0.19.7-dev34
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/{JsonOutput-CaYsBlIL.js → JsonOutput-DvKIRGOg.js} +10 -10
- package/dist/assets/{add-cell-with-ai-DGWXuion.js → add-cell-with-ai-BHgqYu8P.js} +1 -1
- package/dist/assets/{agent-panel-C_CZ3wsS.js → agent-panel-C9codfcr.js} +1 -1
- package/dist/assets/{cell-editor-DrfE1YS-.js → cell-editor-BxhibLVM.js} +1 -1
- package/dist/assets/{chat-display-BIHBJe4Q.js → chat-display-B0625p01.js} +1 -1
- package/dist/assets/{chat-panel-C4V8R2vf.js → chat-panel-CkHdco_X.js} +1 -1
- package/dist/assets/{column-preview-DfgAxcnz.js → column-preview-C6jEPj3t.js} +1 -1
- package/dist/assets/{command-palette-D4dxpptj.js → command-palette-D1g3pU47.js} +1 -1
- package/dist/assets/{dependency-graph-panel-BbRSXJOA.js → dependency-graph-panel-BWvUSpJI.js} +1 -1
- package/dist/assets/{download-Cphyle83.js → download-vBVDTXQk.js} +2 -2
- package/dist/assets/{edit-page-BiEfjNLG.js → edit-page-UqaWbc_J.js} +3 -3
- package/dist/assets/{file-explorer-panel-Dkqk7q5V.js → file-explorer-panel-y7F8Uqi-.js} +1 -1
- package/dist/assets/hooks-D_OOStv3.js +1 -0
- package/dist/assets/html-to-image-Cdx1xsbU.js +2 -0
- package/dist/assets/{index-0-J_BSHl.js → index-BSBPZDCV.js} +3 -3
- package/dist/assets/index-DmMvDRRC.css +2 -0
- package/dist/assets/{layout-BJ9AHITN.js → layout-Xf51uwDc.js} +1 -1
- package/dist/assets/{markdown-renderer-aprG4bjs.js → markdown-renderer-DSY-ElEE.js} +1 -1
- package/dist/assets/{panels-DDBrdHNH.js → panels-D-yo_63g.js} +1 -1
- package/dist/assets/{readonly-python-code-BwtDUnWb.js → readonly-python-code-B1UBDfCT.js} +1 -1
- package/dist/assets/{run-page-BS9QQKCJ.js → run-page-CoCql9Xm.js} +1 -1
- package/dist/assets/{scratchpad-panel-_4qqJHnW.js → scratchpad-panel-DPnpCcOn.js} +1 -1
- package/dist/assets/{session-panel-sueNTZq5.js → session-panel-CjoiPf6W.js} +1 -1
- package/dist/assets/{useAddCell-B7_Lgd-h.js → useAddCell-M6_IuI4C.js} +1 -1
- package/dist/assets/{useCellActionButton-BxQHrbUZ.js → useCellActionButton-Ddy42rre.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-oTszzY42.js → useDependencyPanelTab-RSRpRVKD.js} +1 -1
- package/dist/assets/{useNotebookActions-DFKZ18Bu.js → useNotebookActions-XKe-QMLa.js} +1 -1
- package/dist/assets/{utilities.esm-BeoTGe8r.js → utilities.esm-mPQPstBT.js} +1 -1
- package/dist/index.html +12 -12
- package/package.json +1 -1
- package/src/components/editor/Output.tsx +6 -10
- package/src/components/editor/actions/useNotebookActions.tsx +2 -2
- package/src/core/export/__tests__/hooks.test.ts +72 -33
- package/src/core/export/hooks.ts +17 -8
- package/src/utils/__tests__/download.test.tsx +18 -18
- package/src/utils/__tests__/mime-types.test.ts +326 -0
- package/src/utils/download.ts +9 -11
- package/src/utils/html-to-image.ts +139 -0
- package/src/utils/mime-types.ts +181 -0
- package/dist/assets/hooks-COmcm0X5.js +0 -1
- package/dist/assets/html-to-image-DiZMGN_d.js +0 -2
- package/dist/assets/index-DHsXOI_M.css +0 -2
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import type { MimeType } from "@/components/editor/Output";
|
|
4
|
+
import { once } from "./once";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for mime type precedence and filtering.
|
|
8
|
+
* Uses Map/Set for O(1) lookups at runtime.
|
|
9
|
+
*/
|
|
10
|
+
export interface MimeTypeConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Pre-computed precedence map: mime type -> sort index.
|
|
13
|
+
* Lower index = higher priority. Types not in the map are placed at the end.
|
|
14
|
+
*/
|
|
15
|
+
precedence: ReadonlyMap<MimeType, number>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Hiding rules: trigger mime type -> set of mime types to hide.
|
|
19
|
+
* When the key mime type is present, all mime types in the value set are hidden.
|
|
20
|
+
*/
|
|
21
|
+
hidingRules: ReadonlyMap<MimeType, ReadonlySet<MimeType>>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Result of processing mime types through the filtering and sorting pipeline.
|
|
26
|
+
*/
|
|
27
|
+
export interface ProcessedMimeTypes<T> {
|
|
28
|
+
/** The filtered and sorted mime entries */
|
|
29
|
+
entries: Array<[MimeType, T]>;
|
|
30
|
+
/** Mime types that were hidden by rules */
|
|
31
|
+
hidden: MimeType[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates a compiled MimeTypeConfig from readable arrays.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const config = createMimeConfig({
|
|
40
|
+
* precedence: ["text/html", "image/png", "text/plain"],
|
|
41
|
+
* hidingRules: {
|
|
42
|
+
* "text/html": ["image/png", "image/jpeg"],
|
|
43
|
+
* },
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function createMimeConfig(input: {
|
|
48
|
+
precedence: MimeType[];
|
|
49
|
+
hidingRules: Record<string, MimeType[]>;
|
|
50
|
+
}): MimeTypeConfig {
|
|
51
|
+
const precedence = new Map<MimeType, number>();
|
|
52
|
+
for (let i = 0; i < input.precedence.length; i++) {
|
|
53
|
+
precedence.set(input.precedence[i], i);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const hidingRules = new Map<MimeType, ReadonlySet<MimeType>>();
|
|
57
|
+
for (const [trigger, toHide] of Object.entries(input.hidingRules)) {
|
|
58
|
+
hidingRules.set(trigger as MimeType, new Set(toHide));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { precedence, hidingRules };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Default configuration for mime type handling.
|
|
66
|
+
* Lazily compiled on first access.
|
|
67
|
+
*
|
|
68
|
+
* Design rationale:
|
|
69
|
+
* - text/html typically contains rich rendered output and should take precedence
|
|
70
|
+
* - When text/html is present, image fallbacks (png, jpeg, etc.) are often redundant
|
|
71
|
+
* static renders and should be hidden to reduce UI clutter
|
|
72
|
+
* - text/markdown should NOT be hidden by text/html as they serve different purposes
|
|
73
|
+
* - Vega charts should remain visible as they provide interactivity
|
|
74
|
+
*/
|
|
75
|
+
export const getDefaultMimeConfig = once((): MimeTypeConfig => {
|
|
76
|
+
const IMAGE_FALLBACKS: MimeType[] = ["image/png", "image/jpeg", "image/gif"];
|
|
77
|
+
|
|
78
|
+
return createMimeConfig({
|
|
79
|
+
precedence: [
|
|
80
|
+
"text/html",
|
|
81
|
+
"application/vnd.vegalite.v6+json",
|
|
82
|
+
"application/vnd.vegalite.v5+json",
|
|
83
|
+
"application/vnd.vega.v6+json",
|
|
84
|
+
"application/vnd.vega.v5+json",
|
|
85
|
+
"image/svg+xml",
|
|
86
|
+
"image/png",
|
|
87
|
+
"image/jpeg",
|
|
88
|
+
"image/gif",
|
|
89
|
+
"text/markdown",
|
|
90
|
+
"text/latex",
|
|
91
|
+
"text/csv",
|
|
92
|
+
"application/json",
|
|
93
|
+
"text/plain",
|
|
94
|
+
"video/mp4",
|
|
95
|
+
"video/mpeg",
|
|
96
|
+
],
|
|
97
|
+
hidingRules: {
|
|
98
|
+
// When HTML is present, hide static image fallbacks
|
|
99
|
+
"text/html": [
|
|
100
|
+
...IMAGE_FALLBACKS,
|
|
101
|
+
"image/avif",
|
|
102
|
+
"image/bmp",
|
|
103
|
+
"image/tiff",
|
|
104
|
+
],
|
|
105
|
+
// When Vega charts are present, hide image fallbacks
|
|
106
|
+
"application/vnd.vegalite.v6+json": IMAGE_FALLBACKS,
|
|
107
|
+
"application/vnd.vegalite.v5+json": IMAGE_FALLBACKS,
|
|
108
|
+
"application/vnd.vega.v6+json": IMAGE_FALLBACKS,
|
|
109
|
+
"application/vnd.vega.v5+json": IMAGE_FALLBACKS,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Filters mime types based on hiding rules.
|
|
116
|
+
*/
|
|
117
|
+
export function applyHidingRules(
|
|
118
|
+
mimeTypes: ReadonlySet<MimeType>,
|
|
119
|
+
rules: ReadonlyMap<MimeType, ReadonlySet<MimeType>>,
|
|
120
|
+
): { visible: Set<MimeType>; hidden: Set<MimeType> } {
|
|
121
|
+
const hidden = new Set<MimeType>();
|
|
122
|
+
|
|
123
|
+
for (const mime of mimeTypes) {
|
|
124
|
+
const toHide = rules.get(mime);
|
|
125
|
+
if (toHide) {
|
|
126
|
+
for (const hideType of toHide) {
|
|
127
|
+
if (mimeTypes.has(hideType)) {
|
|
128
|
+
hidden.add(hideType);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const visible = new Set<MimeType>();
|
|
135
|
+
for (const mime of mimeTypes) {
|
|
136
|
+
if (!hidden.has(mime)) {
|
|
137
|
+
visible.add(mime);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return { visible, hidden };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Sorts mime entries according to a precedence map.
|
|
146
|
+
* Mime types not in the map are placed at the end, preserving their original order.
|
|
147
|
+
*/
|
|
148
|
+
export function sortByPrecedence<T>(
|
|
149
|
+
entries: Array<[MimeType, T]>,
|
|
150
|
+
precedence: ReadonlyMap<MimeType, number>,
|
|
151
|
+
): Array<[MimeType, T]> {
|
|
152
|
+
const unknownPrecedence = precedence.size;
|
|
153
|
+
|
|
154
|
+
return [...entries].sort((a, b) => {
|
|
155
|
+
const indexA = precedence.get(a[0]) ?? unknownPrecedence;
|
|
156
|
+
const indexB = precedence.get(b[0]) ?? unknownPrecedence;
|
|
157
|
+
return indexA - indexB;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Main entry point: processes mime entries by applying hiding rules and sorting.
|
|
163
|
+
*/
|
|
164
|
+
export function processMimeBundle<T>(
|
|
165
|
+
entries: Array<[MimeType, T]>,
|
|
166
|
+
config: MimeTypeConfig = getDefaultMimeConfig(),
|
|
167
|
+
): ProcessedMimeTypes<T> {
|
|
168
|
+
if (entries.length === 0) {
|
|
169
|
+
return { entries: [], hidden: [] };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const mimeTypes = new Set(entries.map(([mime]) => mime));
|
|
173
|
+
const { visible, hidden } = applyHidingRules(mimeTypes, config.hidingRules);
|
|
174
|
+
const filteredEntries = entries.filter(([mime]) => visible.has(mime));
|
|
175
|
+
const sortedEntries = sortByPrecedence(filteredEntries, config.precedence);
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
entries: sortedEntries,
|
|
179
|
+
hidden: Array.from(hidden),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{l as S,p as j,u as E}from"./useEvent-DO6uJBas.js";import{o as T}from"./cells-Mf-pdsEh.js";import{t as I}from"./compiler-runtime-DeeZ7FnK.js";import{a as A,d as x}from"./hotkeys-BHHWjLlp.js";import{i as N}from"./utils-DXvhzCGS.js";import{A as _,w as F}from"./config-CIrPQIbt.js";import{r as P}from"./requests-BsVD4CdD.js";import{f as V}from"./layout-BJ9AHITN.js";import{l as D,o as $}from"./download-Cphyle83.js";import{t as z}from"./use-toast-rmUWldD_.js";import{t as C}from"./useInterval-Cu9ChZf-.js";var B=I(),k=5e3;function H(){let t=(0,B.c)(14),r=E(N),{state:d}=E(F),n=r.auto_download.includes("markdown"),o=r.auto_download.includes("html"),s=r.auto_download.includes("ipynb"),c=d===_.OPEN,l=!n||!c,p=!o||!c,u=!s||!c,{autoExportAsHTML:a,autoExportAsIPYNB:e,autoExportAsMarkdown:i,updateCellOutputs:m}=P(),b=M(),f;t[0]===i?f=t[1]:(f=async()=>{await i({download:!1})},t[0]=i,t[1]=f);let w;t[2]===l?w=t[3]:(w={delayMs:k,whenVisible:!0,disabled:l},t[2]=l,t[3]=w),C(f,w);let h;t[4]===a?h=t[5]:(h=async()=>{await a({download:!1,includeCode:!0,files:V.INSTANCE.filenames()})},t[4]=a,t[5]=h);let v;t[6]===p?v=t[7]:(v={delayMs:k,whenVisible:!0,disabled:p},t[6]=p,t[7]=v),C(h,v);let y;t[8]!==e||t[9]!==b||t[10]!==m?(y=async()=>{await O({progress:D.indeterminate(),takeScreenshots:b,updateCellOutputs:m}),await e({download:!1})},t[8]=e,t[9]=b,t[10]=m,t[11]=y):y=t[11];let g;t[12]===u?g=t[13]:(g={delayMs:k,whenVisible:!0,disabled:u,skipIfRunning:!0},t[12]=u,t[13]=g),C(y,g)}var L=j({}),R=new Set(["text/html","application/vnd.vegalite.v5+json","application/vnd.vega.v5+json","application/vnd.vegalite.v6+json","application/vnd.vega.v6+json"]);function M(){let[t,r]=S(L),d=E(T);return async n=>{var p,u;let o={},s=[];for(let[a,e]of A.entries(d)){let i=(p=e.output)==null?void 0:p.data,m=t[a]!==i;o[a]=i,(u=e.output)!=null&&u.mimetype&&R.has(e.output.mimetype)&&i&&m&&s.push([a,e])}if(r(o),s.length===0)return{};let c=s.length;n.addTotal(c);let l={};for(let[a]of s)try{let e=await $(a,!1);if(!e){x.error(`Failed to capture screenshot for cell ${a}`);continue}l[a]=["image/png",e]}catch(e){x.error(`Error screenshotting cell ${a}:`,e)}finally{n.increment(1)}return l}}async function O(t){let{progress:r,takeScreenshots:d,updateCellOutputs:n}=t;try{let o=await d(r);A.size(o)>0&&await n({cellIdsToOutput:o})}catch(o){x.error("Error updating cell outputs with screenshots:",o),z({title:"Failed to capture cell outputs",description:"Some outputs may not appear in the PDF. Continuing with export.",variant:"danger"})}}export{H as n,M as r,O as t};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{i as B}from"./useEvent-DO6uJBas.js";import{bn as G,ri as $,y as Q}from"./cells-Mf-pdsEh.js";import{d as v}from"./hotkeys-BHHWjLlp.js";import{t as R}from"./requests-BsVD4CdD.js";function I({moduleName:e,variableName:t,onAddImport:r,appStore:n=B}){if(t in n.get(G))return!1;let{cellData:i,cellIds:a}=n.get(Q),o=RegExp(`import[ ]+${e}[ ]+as[ ]+${t}`,"g");for(let l of a.inOrderIds)if(o.test(i[l].code))return!1;return r(`import ${e} as ${t}`),!0}function X({autoInstantiate:e,createNewCell:t,fromCellId:r,before:n}){let i=R(),a=null;return I({moduleName:"marimo",variableName:"mo",onAddImport:o=>{a=$.create(),t({cellId:r??"__end__",before:n??!1,code:o,lastCodeRun:e?o:void 0,newCellId:a,skipIfCodeExists:!0,autoFocus:!1}),e&&i.sendRun({cellIds:[a],codes:[o]})}})?a:null}function J({autoInstantiate:e,createNewCell:t,fromCellId:r}){let n=R(),i=null;return I({moduleName:"altair",variableName:"alt",onAddImport:a=>{i=$.create(),t({cellId:r??"__end__",before:!1,code:a,lastCodeRun:e?a:void 0,newCellId:i,skipIfCodeExists:!0,autoFocus:!1}),e&&n.sendRun({cellIds:[i],codes:[a]})}})?i:null}function K(e,t){if(e.match(/^[a-z]+:\/\//i))return e;if(e.match(/^\/\//))return window.location.protocol+e;if(e.match(/^[a-z]+:/i))return e;let r=document.implementation.createHTMLDocument(),n=r.createElement("base"),i=r.createElement("a");return r.head.appendChild(n),r.body.appendChild(i),t&&(n.href=t),i.href=e,i.href}const Y=(()=>{let e=0,t=()=>`0000${(Math.random()*36**4<<0).toString(36)}`.slice(-4);return()=>(e+=1,`u${t()}${e}`)})();function d(e){let t=[];for(let r=0,n=e.length;r<n;r++)t.push(e[r]);return t}var g=null;function P(e={}){return g||(e.includeStyleProperties?(g=e.includeStyleProperties,g):(g=d(window.getComputedStyle(document.documentElement)),g))}function p(e,t){let r=(e.ownerDocument.defaultView||window).getComputedStyle(e).getPropertyValue(t);return r?parseFloat(r.replace("px","")):0}function Z(e){let t=p(e,"border-left-width"),r=p(e,"border-right-width");return e.clientWidth+t+r}function ee(e){let t=p(e,"border-top-width"),r=p(e,"border-bottom-width");return e.clientHeight+t+r}function N(e,t={}){return{width:t.width||Z(e),height:t.height||ee(e)}}function te(){let e,t;try{t=process}catch{}let r=t&&t.env?t.env.devicePixelRatio:null;return r&&(e=parseInt(r,10),Number.isNaN(e)&&(e=1)),e||window.devicePixelRatio||1}var c=16384;function re(e){(e.width>c||e.height>c)&&(e.width>c&&e.height>c?e.width>e.height?(e.height*=c/e.width,e.width=c):(e.width*=c/e.height,e.height=c):e.width>c?(e.height*=c/e.width,e.width=c):(e.width*=c/e.height,e.height=c))}function w(e){return new Promise((t,r)=>{let n=new Image;n.onload=()=>{n.decode().then(()=>{requestAnimationFrame(()=>t(n))})},n.onerror=r,n.crossOrigin="anonymous",n.decoding="async",n.src=e})}async function ne(e){return Promise.resolve().then(()=>new XMLSerializer().serializeToString(e)).then(encodeURIComponent).then(t=>`data:image/svg+xml;charset=utf-8,${t}`)}async function ie(e,t,r){let n="http://www.w3.org/2000/svg",i=document.createElementNS(n,"svg"),a=document.createElementNS(n,"foreignObject");return i.setAttribute("width",`${t}`),i.setAttribute("height",`${r}`),i.setAttribute("viewBox",`0 0 ${t} ${r}`),a.setAttribute("width","100%"),a.setAttribute("height","100%"),a.setAttribute("x","0"),a.setAttribute("y","0"),a.setAttribute("externalResourcesRequired","true"),i.appendChild(a),a.appendChild(e),ne(i)}const u=(e,t)=>{if(e instanceof t)return!0;let r=Object.getPrototypeOf(e);return r===null?!1:r.constructor.name===t.name||u(r,t)};function ae(e){let t=e.getPropertyValue("content");return`${e.cssText} content: '${t.replace(/'|"/g,"")}';`}function oe(e,t){return P(t).map(r=>`${r}: ${e.getPropertyValue(r)}${e.getPropertyPriority(r)?" !important":""};`).join(" ")}function le(e,t,r,n){let i=`.${e}:${t}`,a=r.cssText?ae(r):oe(r,n);return document.createTextNode(`${i}{${a}}`)}function T(e,t,r,n){let i=window.getComputedStyle(e,r),a=i.getPropertyValue("content");if(a===""||a==="none")return;let o=Y();try{t.className=`${t.className} ${o}`}catch{return}let l=document.createElement("style");l.appendChild(le(o,r,i,n)),t.appendChild(l)}function se(e,t,r){T(e,t,":before",r),T(e,t,":after",r)}var A="application/font-woff",L="image/jpeg",ce={woff:A,woff2:A,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:L,jpeg:L,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function ue(e){let t=/\.([^./]*?)$/g.exec(e);return t?t[1]:""}function E(e){return ce[ue(e).toLowerCase()]||""}function de(e){return e.split(/,/)[1]}function S(e){return e.search(/^(data:)/)!==-1}function k(e,t){return`data:${t};base64,${e}`}async function H(e,t,r){let n=await fetch(e,t);if(n.status===404)throw Error(`Resource "${n.url}" not found`);let i=await n.blob();return new Promise((a,o)=>{let l=new FileReader;l.onerror=o,l.onloadend=()=>{try{a(r({res:n,result:l.result}))}catch(s){o(s)}},l.readAsDataURL(i)})}var C={};function he(e,t,r){let n=e.replace(/\?.*/,"");return r&&(n=e),/ttf|otf|eot|woff2?/i.test(n)&&(n=n.replace(/.*\//,"")),t?`[${t}]${n}`:n}async function x(e,t,r){let n=he(e,t,r.includeQueryParams);if(C[n]!=null)return C[n];r.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+new Date().getTime());let i;try{i=k(await H(e,r.fetchRequestInit,({res:a,result:o})=>(t||(t=a.headers.get("Content-Type")||""),de(o))),t)}catch(a){i=r.imagePlaceholder||"";let o=`Failed to fetch resource: ${e}`;a&&(o=typeof a=="string"?a:a.message),o&&console.warn(o)}return C[n]=i,i}async function fe(e){let t=e.toDataURL();return t==="data:,"?e.cloneNode(!1):w(t)}async function me(e,t){if(e.currentSrc){let n=document.createElement("canvas"),i=n.getContext("2d");return n.width=e.clientWidth,n.height=e.clientHeight,i==null||i.drawImage(e,0,0,n.width,n.height),w(n.toDataURL())}let r=e.poster;return w(await x(r,E(r),t))}async function ge(e,t){var r;try{if((r=e==null?void 0:e.contentDocument)!=null&&r.body)return await y(e.contentDocument.body,t,!0)}catch{}return e.cloneNode(!1)}async function pe(e,t){return u(e,HTMLCanvasElement)?fe(e):u(e,HTMLVideoElement)?me(e,t):u(e,HTMLIFrameElement)?ge(e,t):e.cloneNode(F(e))}var we=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SLOT",F=e=>e.tagName!=null&&e.tagName.toUpperCase()==="SVG";async function ye(e,t,r){if(F(t))return t;let n=[];return n=we(e)&&e.assignedNodes?d(e.assignedNodes()):d((e.shadowRoot??e).childNodes),n.length===0||u(e,HTMLVideoElement)||await n.reduce((i,a)=>i.then(()=>y(a,r)).then(o=>{o&&t.appendChild(o)}),Promise.resolve()),t}function be(e,t,r){let n=t.style;if(!n)return;let i=window.getComputedStyle(e);i.cssText?(n.cssText=i.cssText,n.transformOrigin=i.transformOrigin):P(r).forEach(a=>{let o=i.getPropertyValue(a);a==="font-size"&&o.endsWith("px")&&(o=`${Math.floor(parseFloat(o.substring(0,o.length-2)))-.1}px`),u(e,HTMLIFrameElement)&&a==="display"&&o==="inline"&&(o="block"),a==="d"&&t.getAttribute("d")&&(o=`path(${t.getAttribute("d")})`),n.setProperty(a,o,i.getPropertyPriority(a))})}function Ee(e,t){u(e,HTMLTextAreaElement)&&(t.innerHTML=e.value),u(e,HTMLInputElement)&&t.setAttribute("value",e.value)}function Se(e,t){if(u(e,HTMLSelectElement)){let r=t,n=Array.from(r.children).find(i=>e.value===i.getAttribute("value"));n&&n.setAttribute("selected","")}}function Ce(e,t,r){return u(t,Element)&&(be(e,t,r),se(e,t,r),Ee(e,t),Se(e,t)),t}async function xe(e,t){let r=e.querySelectorAll?e.querySelectorAll("use"):[];if(r.length===0)return e;let n={};for(let a=0;a<r.length;a++){let o=r[a].getAttribute("xlink:href");if(o){let l=e.querySelector(o),s=document.querySelector(o);!l&&s&&!n[o]&&(n[o]=await y(s,t,!0))}}let i=Object.values(n);if(i.length){let a="http://www.w3.org/1999/xhtml",o=document.createElementNS(a,"svg");o.setAttribute("xmlns",a),o.style.position="absolute",o.style.width="0",o.style.height="0",o.style.overflow="hidden",o.style.display="none";let l=document.createElementNS(a,"defs");o.appendChild(l);for(let s=0;s<i.length;s++)l.appendChild(i[s]);e.appendChild(o)}return e}async function y(e,t,r){return!r&&t.filter&&!t.filter(e)?null:Promise.resolve(e).then(n=>pe(n,t)).then(n=>ye(e,n,t)).then(n=>Ce(e,n,t)).then(n=>xe(n,t))}var M=/url\((['"]?)([^'"]+?)\1\)/g,$e=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,ve=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function Re(e){let t=e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return RegExp(`(url\\(['"]?)(${t})(['"]?\\))`,"g")}function Ie(e){let t=[];return e.replace(M,(r,n,i)=>(t.push(i),r)),t.filter(r=>!S(r))}async function Pe(e,t,r,n,i){try{let a=r?K(t,r):t,o=E(t),l;return l=i?k(await i(a),o):await x(a,o,n),e.replace(Re(t),`$1${l}$3`)}catch{}return e}function Ne(e,{preferredFontFormat:t}){return t?e.replace(ve,r=>{for(;;){let[n,,i]=$e.exec(r)||[];if(!i)return"";if(i===t)return`src: ${n};`}}):e}function V(e){return e.search(M)!==-1}async function D(e,t,r){if(!V(e))return e;let n=Ne(e,r);return Ie(n).reduce((i,a)=>i.then(o=>Pe(o,a,t,r)),Promise.resolve(n))}async function f(e,t,r){var i;let n=(i=t.style)==null?void 0:i.getPropertyValue(e);if(n){let a=await D(n,null,r);return t.style.setProperty(e,a,t.style.getPropertyPriority(e)),!0}return!1}async function Te(e,t){await f("background",e,t)||await f("background-image",e,t),await f("mask",e,t)||await f("-webkit-mask",e,t)||await f("mask-image",e,t)||await f("-webkit-mask-image",e,t)}async function Ae(e,t){let r=u(e,HTMLImageElement);if(!(r&&!S(e.src))&&!(u(e,SVGImageElement)&&!S(e.href.baseVal)))return;let n=r?e.src:e.href.baseVal,i=await x(n,E(n),t);await new Promise((a,o)=>{e.onload=a,e.onerror=t.onImageErrorHandler?(...s)=>{try{a(t.onImageErrorHandler(...s))}catch(h){o(h)}}:o;let l=e;l.decode&&(l.decode=a),l.loading==="lazy"&&(l.loading="eager"),r?(e.srcset="",e.src=i):e.href.baseVal=i})}async function Le(e,t){let r=d(e.childNodes).map(n=>O(n,t));await Promise.all(r).then(()=>e)}async function O(e,t){u(e,Element)&&(await Te(e,t),await Ae(e,t),await Le(e,t))}function ke(e,t){let{style:r}=e;t.backgroundColor&&(r.backgroundColor=t.backgroundColor),t.width&&(r.width=`${t.width}px`),t.height&&(r.height=`${t.height}px`);let n=t.style;return n!=null&&Object.keys(n).forEach(i=>{r[i]=n[i]}),e}var _={};async function j(e){let t=_[e];return t??(t={url:e,cssText:await(await fetch(e)).text()},_[e]=t,t)}async function U(e,t){let r=e.cssText,n=/url\(["']?([^"')]+)["']?\)/g,i=(r.match(/url\([^)]+\)/g)||[]).map(async a=>{let o=a.replace(n,"$1");return o.startsWith("https://")||(o=new URL(o,e.url).href),H(o,t.fetchRequestInit,({result:l})=>(r=r.replace(a,`url(${l})`),[a,l]))});return Promise.all(i).then(()=>r)}function q(e){if(e==null)return[];let t=[],r=e.replace(/(\/\*[\s\S]*?\*\/)/gi,""),n=RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){let o=n.exec(r);if(o===null)break;t.push(o[0])}r=r.replace(n,"");let i=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,a=RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");for(;;){let o=i.exec(r);if(o===null){if(o=a.exec(r),o===null)break;i.lastIndex=a.lastIndex}else a.lastIndex=i.lastIndex;t.push(o[0])}return t}async function He(e,t){let r=[],n=[];return e.forEach(i=>{if("cssRules"in i)try{d(i.cssRules||[]).forEach((a,o)=>{if(a.type===CSSRule.IMPORT_RULE){let l=o+1,s=a.href,h=j(s).then(m=>U(m,t)).then(m=>q(m).forEach(b=>{try{i.insertRule(b,b.startsWith("@import")?l+=1:i.cssRules.length)}catch(W){console.error("Error inserting rule from remote css",{rule:b,error:W})}})).catch(m=>{console.error("Error loading remote css",m.toString())});n.push(h)}})}catch(a){let o=e.find(l=>l.href==null)||document.styleSheets[0];i.href!=null&&n.push(j(i.href).then(l=>U(l,t)).then(l=>q(l).forEach(s=>{o.insertRule(s,o.cssRules.length)})).catch(l=>{console.error("Error loading remote stylesheet",l)})),console.error("Error inlining remote css file",a)}}),Promise.all(n).then(()=>(e.forEach(i=>{if("cssRules"in i)try{d(i.cssRules||[]).forEach(a=>{r.push(a)})}catch(a){console.error(`Error while reading CSS rules from ${i.href}`,a)}}),r))}function Fe(e){return e.filter(t=>t.type===CSSRule.FONT_FACE_RULE).filter(t=>V(t.style.getPropertyValue("src")))}async function Me(e,t){if(e.ownerDocument==null)throw Error("Provided element is not within a Document");return Fe(await He(d(e.ownerDocument.styleSheets),t))}function z(e){return e.trim().replace(/["']/g,"")}function Ve(e){let t=new Set;function r(n){(n.style.fontFamily||getComputedStyle(n).fontFamily).split(",").forEach(i=>{t.add(z(i))}),Array.from(n.children).forEach(i=>{i instanceof HTMLElement&&r(i)})}return r(e),t}async function De(e,t){let r=await Me(e,t),n=Ve(e);return(await Promise.all(r.filter(i=>n.has(z(i.style.fontFamily))).map(i=>{let a=i.parentStyleSheet?i.parentStyleSheet.href:null;return D(i.cssText,a,t)}))).join(`
|
|
2
|
-
`)}async function Oe(e,t){let r=t.fontEmbedCSS==null?t.skipFonts?null:await De(e,t):t.fontEmbedCSS;if(r){let n=document.createElement("style"),i=document.createTextNode(r);n.appendChild(i),e.firstChild?e.insertBefore(n,e.firstChild):e.appendChild(n)}}async function _e(e,t={}){let{width:r,height:n}=N(e,t),i=await y(e,t,!0);return await Oe(i,t),await O(i,t),ke(i,t),await ie(i,r,n)}async function je(e,t={}){let{width:r,height:n}=N(e,t),i=await w(await _e(e,t)),a=document.createElement("canvas"),o=a.getContext("2d"),l=t.pixelRatio||te(),s=t.canvasWidth||r,h=t.canvasHeight||n;return a.width=s*l,a.height=h*l,t.skipAutoScale||re(a),a.style.width=`${s}`,a.style.height=`${h}`,t.backgroundColor&&(o.fillStyle=t.backgroundColor,o.fillRect(0,0,a.width,a.height)),o.drawImage(i,0,0,a.width,a.height),a}async function Ue(e,t={}){return(await je(e,t)).toDataURL()}const qe={filter:e=>{try{return!("classList"in e&&(e.classList.contains("mpl-toolbar")||e.classList.contains("no-print")))}catch(t){return v.error("Error filtering node:",t),!0}},onImageErrorHandler:e=>{v.error("Error loading image:",e)}};async function ze(e,t){return Ue(e,{...qe,...t})}export{J as n,X as r,ze as t};
|