${outputResult}
`;
- })
- .join("\n");
-
-
- // Clean the state
- // We're now able to process pager events.
- // As a result, we cannot maintain a true 1-to-1 output order
- // without individually feeding each line
- const msgs = await mainWebR.flush();
-
- // Use `map` to process the filtered "pager" events asynchronously
- const pager = [];
- const browse = [];
-
- await Promise.all(
- msgs.map(
- async (msg) => {
-
- const msgType = msg.type || "unknown";
-
- switch(msgType) {
- case 'pager':
- const pager_data = await qwebrParseTypePager(msg);
- pager.push(pager_data);
- break;
- case 'browse':
- const browse_data = await qwebrParseTypeBrowse(msg);
- browse.push(browse_data);
- break;
- }
- return;
- }
- )
- );
-
- // Nullify the output area of content
- elements.outputCodeDiv.innerHTML = "";
- elements.outputGraphDiv.innerHTML = "";
-
- // Design an output object for messages
- const pre = document.createElement("pre");
- if (/\S/.test(out)) {
- // Display results as HTML elements to retain output styling
- const div = document.createElement("div");
- div.innerHTML = out;
-
- // Calculate a scaled font-size value
- const scaledFontSize = qwebrScaledFontSize(
- elements.outputCodeDiv, options);
-
- // Override output code cell size
- pre.style.fontSize = `${scaledFontSize}px`;
- pre.appendChild(div);
- } else {
- // If nothing is present, hide the element.
- pre.style.visibility = "hidden";
- }
-
- elements.outputCodeDiv.appendChild(pre);
-
- // Determine if we have graphs to display
- if (result.images.length > 0) {
-
- // Create figure element
- const figureElement = document.createElement("figure");
- figureElement.className = "qwebr-canvas-image";
-
- // Place each rendered graphic onto a canvas element
- result.images.forEach((img) => {
-
- // Construct canvas for object
- const canvas = document.createElement("canvas");
-
- // Add an image download button
- qwebrImageCanvasDownloadButton(canvas, figureElement);
-
- // Set canvas size to image
- canvas.width = img.width;
- canvas.height = img.height;
-
- // Apply output truncations
- canvas.style.width = options["out-width"] ? options["out-width"] : `${fig_width}px`;
- if (options["out-height"]) {
- canvas.style.height = options["out-height"];
- }
-
- // Apply styling
- canvas.style.display = "block";
- canvas.style.margin = "auto";
-
- // Draw image onto Canvas
- const ctx = canvas.getContext("2d");
- ctx.drawImage(img, 0, 0, img.width, img.height);
-
- // Append canvas to figure output area
- figureElement.appendChild(canvas);
-
- });
-
- if (options['fig-cap']) {
- // Create figcaption element
- const figcaptionElement = document.createElement('figcaption');
- figcaptionElement.innerText = options['fig-cap'];
- // Append figcaption to figure
- figureElement.appendChild(figcaptionElement);
- }
-
- elements.outputGraphDiv.appendChild(figureElement);
-
- }
-
- // Display the pager data
- if (pager.length > 0) {
- // Use the `pre` element to preserve whitespace.
- pager.forEach((paged_data, index) => {
- const pre_pager = document.createElement("pre");
- pre_pager.innerText = paged_data;
- pre_pager.classList.add("qwebr-output-code-pager");
- pre_pager.setAttribute("id", `qwebr-output-code-pager-editor-${elements.id}-result-${index + 1}`);
- elements.outputCodeDiv.appendChild(pre_pager);
- });
- }
-
- // Display the browse data
- if (browse.length > 0) {
- // Use the `pre` element to preserve whitespace.
- browse.forEach((browse_data, index) => {
- const iframe_browse = document.createElement('iframe');
- iframe_browse.classList.add("qwebr-output-code-browse");
- iframe_browse.setAttribute("id", `qwebr-output-code-browse-editor-${elements.id}-result-${index + 1}`);
- iframe_browse.style.width = "100%";
- iframe_browse.style.minHeight = "500px";
- elements.outputCodeDiv.appendChild(iframe_browse);
-
- iframe_browse.contentWindow.document.open();
- iframe_browse.contentWindow.document.write(browse_data);
- iframe_browse.contentWindow.document.close();
- });
- }
- } finally {
- // Clean up the remaining code
- mainWebRCodeShelter.purge();
- }
-};
-
-// Function to execute the code (accepts code as an argument)
-globalThis.qwebrExecuteCode = async function (
- codeToRun,
- id,
- options = {}) {
-
- // If options are not passed, we fall back on the bare minimum to handle the computation
- if (qwebrIsObjectEmpty(options)) {
- options = {
- "context": "interactive",
- "fig-width": 7, "fig-height": 5,
- "out-width": "700px", "out-height": "",
- "dpi": 72,
- "results": "markup",
- "warning": "true", "message": "true",
- };
- }
-
- // Next, we access the compute areas values
- const elements = {
- runButton: document.getElementById(`qwebr-button-run-${id}`),
- outputCodeDiv: document.getElementById(`qwebr-output-code-area-${id}`),
- outputGraphDiv: document.getElementById(`qwebr-output-graph-area-${id}`),
- id: id,
- }
-
- // Disallowing execution of other code cells
- document.querySelectorAll(".qwebr-button-run").forEach((btn) => {
- btn.disabled = true;
- });
-
- if (options.context == EvalTypes.Interactive) {
- // Emphasize the active code cell
- elements.runButton.innerHTML = ' Run Code';
- }
-
- // Evaluate the code and parse the output into the document
- await qwebrComputeEngine(codeToRun, elements, options);
-
- // Switch to allowing execution of code
- document.querySelectorAll(".qwebr-button-run").forEach((btn) => {
- btn.disabled = false;
- });
-
- if (options.context == EvalTypes.Interactive) {
- // Revert to the initial code cell state
- elements.runButton.innerHTML = ' Run Code';
- }
-}
diff --git a/book/_extensions/coatless/webr/qwebr-document-engine-initialization.js b/book/_extensions/coatless/webr/qwebr-document-engine-initialization.js
deleted file mode 100644
index 723220acc0..0000000000
--- a/book/_extensions/coatless/webr/qwebr-document-engine-initialization.js
+++ /dev/null
@@ -1,98 +0,0 @@
-// Function to install a single package
-async function qwebrInstallRPackage(packageName) {
- await mainWebR.evalRVoid(`webr::install('${packageName}');`);
-}
-
-// Function to load a single package
-async function qwebrLoadRPackage(packageName) {
- await mainWebR.evalRVoid(`require('${packageName}', quietly = TRUE)`);
-}
-
-// Generic function to process R packages
-async function qwebrProcessRPackagesWithStatus(packages, processType, displayStatusMessageUpdate = true) {
- // Switch between contexts
- const messagePrefix = processType === 'install' ? 'Installing' : 'Loading';
-
- // Modify button state
- qwebrSetInteractiveButtonState(`🟡 ${messagePrefix} package ...`, false);
-
- // Iterate over packages
- for (let i = 0; i < packages.length; i++) {
- const activePackage = packages[i];
- const formattedMessage = `${messagePrefix} package ${i + 1} out of ${packages.length}: ${activePackage}`;
-
- // Display the update in header
- if (displayStatusMessageUpdate) {
- qwebrUpdateStatusHeader(formattedMessage);
- }
-
- // Display the update in non-active areas
- qwebrUpdateStatusMessage(formattedMessage);
-
- // Run package installation
- if (processType === 'install') {
- await qwebrInstallRPackage(activePackage);
- } else {
- await qwebrLoadRPackage(activePackage);
- }
- }
-
- // Clean slate
- if (processType === 'load') {
- await mainWebR.flush();
- }
-}
-
-// Start a timer
-const initializeWebRTimerStart = performance.now();
-
-// Encase with a dynamic import statement
-globalThis.qwebrInstance = import(qwebrCustomizedWebROptions.baseURL + "webr.mjs").then(
- async ({ WebR, ChannelType }) => {
- // Populate WebR options with defaults or new values based on `webr` meta
- globalThis.mainWebR = new WebR(qwebrCustomizedWebROptions);
-
- // Initialization WebR
- await mainWebR.init();
-
- // Setup a shelter
- globalThis.mainWebRCodeShelter = await new mainWebR.Shelter();
-
- // Setup a pager to allow processing help documentation
- await mainWebR.evalRVoid('webr::pager_install()');
-
- // Setup a viewer to allow processing htmlwidgets.
- // This might not be available in old webr version
- await mainWebR.evalRVoid('try({ webr::viewer_install() })');
-
- // Override the existing install.packages() to use webr::install()
- await mainWebR.evalRVoid('webr::shim_install()');
-
- // Specify the repositories to pull from
- // Note: webR does not use the `repos` option, but instead uses `webr_pkg_repos`
- // inside of `install()`. However, other R functions still pull from `repos`.
- await mainWebR.evalRVoid(`
- options(
- webr_pkg_repos = c(${qwebrPackageRepoURLS.map(repoURL => `'${repoURL}'`).join(',')}),
- repos = c(${qwebrPackageRepoURLS.map(repoURL => `'${repoURL}'`).join(',')})
- )
- `);
-
- // Check to see if any packages need to be installed
- if (qwebrSetupRPackages) {
- // Obtain only a unique list of packages
- const uniqueRPackageList = Array.from(new Set(qwebrInstallRPackagesList));
-
- // Install R packages one at a time (either silently or with a status update)
- await qwebrProcessRPackagesWithStatus(uniqueRPackageList, 'install', qwebrShowStartupMessage);
-
- if (qwebrAutoloadRPackages) {
- // Load R packages one at a time (either silently or with a status update)
- await qwebrProcessRPackagesWithStatus(uniqueRPackageList, 'load', qwebrShowStartupMessage);
- }
- }
- }
-);
-
-// Stop timer
-const initializeWebRTimerEnd = performance.now();
diff --git a/book/_extensions/coatless/webr/qwebr-document-history.js b/book/_extensions/coatless/webr/qwebr-document-history.js
deleted file mode 100644
index df00091132..0000000000
--- a/book/_extensions/coatless/webr/qwebr-document-history.js
+++ /dev/null
@@ -1,110 +0,0 @@
-// Define a global storage and retrieval solution ----
-
-// Store commands executed in R
-globalThis.qwebrRCommandHistory = [];
-
-// Function to retrieve the command history
-globalThis.qwebrFormatRHistory = function() {
- return qwebrRCommandHistory.join("\n\n");
-}
-
-// Retrieve HTML Elements ----
-
-// Get the command modal
-const command_history_modal = document.getElementById("qwebr-history-modal");
-
-// Get the button that opens the command modal
-const command_history_btn = document.getElementById("qwebrRHistoryButton");
-
-// Get the element that closes the command modal
-const command_history_close_span = document.getElementById("qwebr-command-history-close-btn");
-
-// Get the download button for r history information
-const command_history_download_btn = document.getElementById("qwebr-download-history-btn");
-
-// Plug in command history into modal/download button ----
-
-// Function to populate the modal with command history
-function populateCommandHistoryModal() {
- document.getElementById("qwebr-command-history-contents").innerHTML = qwebrFormatRHistory() || "No commands have been executed yet.";
-}
-
-// Function to format the current date and time to
-// a string with the format YYYY-MM-DD-HH-MM-SS
-function formatDateTime() {
- const now = new Date();
-
- const year = now.getFullYear();
- const day = String(now.getDate()).padStart(2, '0');
- const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero-based
- const hours = String(now.getHours()).padStart(2, '0');
- const minutes = String(now.getMinutes()).padStart(2, '0');
- const seconds = String(now.getSeconds()).padStart(2, '0');
-
- return `${year}-${month}-${day}-${hours}-${minutes}-${seconds}`;
-}
-
-
-// Function to convert document title with datetime to a safe filename
-function safeFileName() {
- // Get the current page title
- let pageTitle = document.title;
-
- // Combine the current page title with the current date and time
- let pageNameWithDateTime = `Rhistory-${pageTitle}-${formatDateTime()}`;
-
- // Replace unsafe characters with safe alternatives
- let safeFilename = pageNameWithDateTime.replace(/[\\/:\*\?! "<>\|]/g, '-');
-
- return safeFilename;
-}
-
-
-// Function to download list contents as text file
-function downloadRHistory() {
- // Get the current page title + datetime and use it as the filename
- const filename = `${safeFileName()}.R`;
-
- // Get the text contents of the R History list
- const text = qwebrFormatRHistory();
-
- // Create a new Blob object with the text contents
- const blob = new Blob([text], { type: 'text/plain' });
-
- // Create a new anchor element for the download
- const a = document.createElement('a');
- a.style.display = 'none';
- a.href = URL.createObjectURL(blob);
- a.download = filename;
-
- // Append the anchor to the body, click it, and remove it
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
-}
-
-// Register event handlers ----
-
-// When the user clicks the View R History button, open the command modal
-command_history_btn.onclick = function() {
- populateCommandHistoryModal();
- command_history_modal.style.display = "block";
-}
-
-// When the user clicks on (x), close the command modal
-command_history_close_span.onclick = function() {
- command_history_modal.style.display = "none";
-}
-
-// When the user clicks anywhere outside of the command modal, close it
-window.onclick = function(event) {
- if (event.target == command_history_modal) {
- command_history_modal.style.display = "none";
- }
-}
-
-// Add an onclick event listener to the download button so that
-// the user can download the R history as a text file
-command_history_download_btn.onclick = function() {
- downloadRHistory();
-};
\ No newline at end of file
diff --git a/book/_extensions/coatless/webr/qwebr-document-settings.js b/book/_extensions/coatless/webr/qwebr-document-settings.js
deleted file mode 100644
index 70495cf667..0000000000
--- a/book/_extensions/coatless/webr/qwebr-document-settings.js
+++ /dev/null
@@ -1,26 +0,0 @@
-// Document level settings ----
-
-// Determine if we need to install R packages
-globalThis.qwebrInstallRPackagesList = [{{INSTALLRPACKAGESLIST}}];
-
-// Specify possible locations to search for the repository
-globalThis.qwebrPackageRepoURLS = [{{RPACKAGEREPOURLS}}];
-
-// Check to see if we have an empty array, if we do set to skip the installation.
-globalThis.qwebrSetupRPackages = !(qwebrInstallRPackagesList.indexOf("") !== -1);
-globalThis.qwebrAutoloadRPackages = {{AUTOLOADRPACKAGES}};
-
-// Display a startup message?
-globalThis.qwebrShowStartupMessage = {{SHOWSTARTUPMESSAGE}};
-globalThis.qwebrShowHeaderMessage = {{SHOWHEADERMESSAGE}};
-
-// Describe the webR settings that should be used
-globalThis.qwebrCustomizedWebROptions = {
- "baseURL": "{{BASEURL}}",
- "serviceWorkerUrl": "{{SERVICEWORKERURL}}",
- "homedir": "{{HOMEDIR}}",
- "channelType": "{{CHANNELTYPE}}"
-};
-
-// Store cell data
-globalThis.qwebrCellDetails = {{QWEBRCELLDETAILS}};
diff --git a/book/_extensions/coatless/webr/qwebr-document-status.js b/book/_extensions/coatless/webr/qwebr-document-status.js
deleted file mode 100644
index 71441df408..0000000000
--- a/book/_extensions/coatless/webr/qwebr-document-status.js
+++ /dev/null
@@ -1,368 +0,0 @@
-// Declare startupMessageQWebR globally
-globalThis.qwebrStartupMessage = document.createElement("p");
-
-// Verify if OffScreenCanvas is supported
-globalThis.qwebrOffScreenCanvasSupport = function() {
- return typeof OffscreenCanvas !== 'undefined'
-}
-
-// Function to set the button text
-globalThis.qwebrSetInteractiveButtonState = function(buttonText, enableCodeButton = true) {
- document.querySelectorAll(".qwebr-button-run").forEach((btn) => {
- btn.innerHTML = buttonText;
- btn.disabled = !enableCodeButton;
- });
-}
-
-// Function to update the status message in non-interactive cells
-globalThis.qwebrUpdateStatusMessage = function(message) {
- document.querySelectorAll(".qwebr-status-text.qwebr-cell-needs-evaluation").forEach((elem) => {
- elem.innerText = message;
- });
-}
-
-// Function to update the status message
-globalThis.qwebrUpdateStatusHeader = function(message) {
- qwebrStartupMessage.innerHTML = `
-
- ${message}`;
-}
-
-// Function to return true if element is found, false if not
-globalThis.qwebrCheckHTMLElementExists = function(selector) {
- const element = document.querySelector(selector);
- return !!element;
-}
-
-// Function that detects whether reveal.js slides are present
-globalThis.qwebrIsRevealJS = function() {
- // If the '.reveal .slides' selector exists, RevealJS is likely present
- return qwebrCheckHTMLElementExists('.reveal .slides');
-}
-
-// Initialize the Quarto sidebar element
-function qwebrSetupQuartoSidebar() {
- var newSideBarDiv = document.createElement('div');
- newSideBarDiv.id = 'quarto-margin-sidebar';
- newSideBarDiv.className = 'sidebar margin-sidebar';
- newSideBarDiv.style.top = '0px';
- newSideBarDiv.style.maxHeight = 'calc(0px + 100vh)';
-
- return newSideBarDiv;
-}
-
-// Position the sidebar in the document
-function qwebrPlaceQuartoSidebar() {
- // Get the reference to the element with id 'quarto-document-content'
- var referenceNode = document.getElementById('quarto-document-content');
-
- // Create the new div element
- var newSideBarDiv = qwebrSetupQuartoSidebar();
-
- // Insert the new div before the 'quarto-document-content' element
- referenceNode.parentNode.insertBefore(newSideBarDiv, referenceNode);
-}
-
-function qwebrPlaceMessageContents(content, html_location = "title-block-header", revealjs_location = "title-slide") {
-
- // Get references to header elements
- const headerHTML = document.getElementById(html_location);
- const headerRevealJS = document.getElementById(revealjs_location);
-
- // Determine where to insert the quartoTitleMeta element
- if (headerHTML || headerRevealJS) {
- // Append to the existing "title-block-header" element or "title-slide" div
- (headerHTML || headerRevealJS).appendChild(content);
- } else {
- // If neither headerHTML nor headerRevealJS is found, insert after "webr-monaco-editor-init" script
- const monacoScript = document.getElementById("qwebr-monaco-editor-init");
- const header = document.createElement("header");
- header.setAttribute("id", "title-block-header");
- header.appendChild(content);
- monacoScript.after(header);
- }
-}
-
-
-
-function qwebrOffScreenCanvasSupportWarningMessage() {
-
- // Verify canvas is supported.
- if(qwebrOffScreenCanvasSupport()) return;
-
- // Create the main container div
- var calloutContainer = document.createElement('div');
- calloutContainer.classList.add('callout', 'callout-style-default', 'callout-warning', 'callout-titled');
-
- // Create the header div
- var headerDiv = document.createElement('div');
- headerDiv.classList.add('callout-header', 'd-flex', 'align-content-center');
-
- // Create the icon container div
- var iconContainer = document.createElement('div');
- iconContainer.classList.add('callout-icon-container');
-
- // Create the icon element
- var iconElement = document.createElement('i');
- iconElement.classList.add('callout-icon');
-
- // Append the icon element to the icon container
- iconContainer.appendChild(iconElement);
-
- // Create the title container div
- var titleContainer = document.createElement('div');
- titleContainer.classList.add('callout-title-container', 'flex-fill');
- titleContainer.innerText = 'Warning: Web Browser Does Not Support Graphing!';
-
- // Append the icon container and title container to the header div
- headerDiv.appendChild(iconContainer);
- headerDiv.appendChild(titleContainer);
-
- // Create the body container div
- var bodyContainer = document.createElement('div');
- bodyContainer.classList.add('callout-body-container', 'callout-body');
-
- // Create the paragraph element for the body content
- var paragraphElement = document.createElement('p');
- paragraphElement.innerHTML = 'This web browser does not have support for displaying graphs through the quarto-webr
extension since it lacks an OffScreenCanvas
. Please upgrade your web browser to one that supports OffScreenCanvas
.';
-
- // Append the paragraph element to the body container
- bodyContainer.appendChild(paragraphElement);
-
- // Append the header div and body container to the main container div
- calloutContainer.appendChild(headerDiv);
- calloutContainer.appendChild(bodyContainer);
-
- // Append the main container div to the document depending on format
- qwebrPlaceMessageContents(calloutContainer, "title-block-header");
-
-}
-
-
-// Function that attaches the document status message and diagnostics
-function displayStartupMessage(showStartupMessage, showHeaderMessage) {
- if (!showStartupMessage) {
- return;
- }
-
- // Create the outermost div element for metadata
- const quartoTitleMeta = document.createElement("div");
- quartoTitleMeta.classList.add("quarto-title-meta");
-
- // Create the first inner div element
- const firstInnerDiv = document.createElement("div");
- firstInnerDiv.setAttribute("id", "qwebr-status-message-area");
-
- // Create the second inner div element for "WebR Status" heading and contents
- const secondInnerDiv = document.createElement("div");
- secondInnerDiv.setAttribute("id", "qwebr-status-message-title");
- secondInnerDiv.classList.add("quarto-title-meta-heading");
- secondInnerDiv.innerText = "WebR Status";
-
- // Create another inner div for contents
- const secondInnerDivContents = document.createElement("div");
- secondInnerDivContents.setAttribute("id", "qwebr-status-message-body");
- secondInnerDivContents.classList.add("quarto-title-meta-contents");
-
- // Describe the WebR state
- qwebrStartupMessage.innerText = "🟡 Loading...";
- qwebrStartupMessage.setAttribute("id", "qwebr-status-message-text");
- // Add `aria-live` to auto-announce the startup status to screen readers
- qwebrStartupMessage.setAttribute("aria-live", "assertive");
-
- // Append the startup message to the contents
- secondInnerDivContents.appendChild(qwebrStartupMessage);
-
- // Add a status indicator for COOP and COEP Headers if needed
- if (showHeaderMessage) {
- const crossOriginMessage = document.createElement("p");
- crossOriginMessage.innerText = `${crossOriginIsolated ? '🟢' : '🟡'} COOP & COEP Headers`;
- crossOriginMessage.setAttribute("id", "qwebr-coop-coep-header");
- secondInnerDivContents.appendChild(crossOriginMessage);
- }
-
- // Combine the inner divs and contents
- firstInnerDiv.appendChild(secondInnerDiv);
- firstInnerDiv.appendChild(secondInnerDivContents);
- quartoTitleMeta.appendChild(firstInnerDiv);
-
- // Place message on webpage
- qwebrPlaceMessageContents(quartoTitleMeta);
-}
-
-function qwebrAddCommandHistoryModal() {
- // Create the modal div
- var modalDiv = document.createElement('div');
- modalDiv.id = 'qwebr-history-modal';
- modalDiv.className = 'qwebr-modal';
-
- // Create the modal content div
- var modalContentDiv = document.createElement('div');
- modalContentDiv.className = 'qwebr-modal-content';
-
- // Create the span for closing the modal
- var closeSpan = document.createElement('span');
- closeSpan.id = 'qwebr-command-history-close-btn';
- closeSpan.className = 'qwebr-modal-close';
- closeSpan.innerHTML = '×';
-
- // Create the h1 element for the modal
- var modalH1 = document.createElement('h1');
- modalH1.textContent = 'R History Command Contents';
-
- // Create an anchor element for downloading the Rhistory file
- var downloadLink = document.createElement('a');
- downloadLink.href = '#';
- downloadLink.id = 'qwebr-download-history-btn';
- downloadLink.className = 'qwebr-download-btn';
-
- // Create an 'i' element for the icon
- var icon = document.createElement('i');
- icon.className = 'bi bi-file-code';
-
- // Append the icon to the anchor element
- downloadLink.appendChild(icon);
-
- // Add the text 'Download R History' to the anchor element
- downloadLink.appendChild(document.createTextNode(' Download R History File'));
-
- // Create the pre for command history contents
- var commandContentsPre = document.createElement('pre');
- commandContentsPre.id = 'qwebr-command-history-contents';
- commandContentsPre.className = 'qwebr-modal-content-code';
-
- // Append the close span, h1, and history contents pre to the modal content div
- modalContentDiv.appendChild(closeSpan);
- modalContentDiv.appendChild(modalH1);
- modalContentDiv.appendChild(downloadLink);
- modalContentDiv.appendChild(commandContentsPre);
-
- // Append the modal content div to the modal div
- modalDiv.appendChild(modalContentDiv);
-
- // Append the modal div to the body
- document.body.appendChild(modalDiv);
-}
-
-function qwebrRegisterRevealJSCommandHistoryModal() {
- // Select the P&&(P=x?D.top-g-2-m:D.bottom+m+2);if(this.position=="absolute"?(c.style.top=(P-i.parent.top)/s+"px",c.style.left=(v-i.parent.left)/r+"px"):(c.style.top=P/s+"px",c.style.left=v/r+"px"),d){let D=f.left+(y?O.x:-O.x)-(v+14-7);d.style.left=D/r+"px"}h.overlap!==!0&&o.push({left:v,top:P,right:C,bottom:P+g}),c.classList.toggle("cm-tooltip-above",x),c.classList.toggle("cm-tooltip-below",!x),h.positioned&&h.positioned(i.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let i of this.manager.tooltipViews)i.dom.style.top=Hn}},{eventObservers:{scroll(){this.maybeMeasure()}}}),zb=E.baseTheme({".cm-tooltip":{zIndex:100,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),Ub={x:0,y:0},gr=A.define({enables:[kh,zb]}),ao=A.define({combine:i=>i.reduce((e,t)=>e.concat(t),[])}),lo=class i{static create(e){return new i(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new oo(e,ao,(t,n)=>this.createHostedView(t,n),t=>t.dom.remove())}createHostedView(e,t){let n=e.create(this.view);return n.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(n.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&n.mount&&n.mount(this.view),n}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let n of this.manager.tooltipViews){let r=n[e];if(r!==void 0){if(t===void 0)t=r;else if(t!==r)return}}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}},Fb=gr.compute([ao],i=>{let e=i.facet(ao);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var n;return(n=t.end)!==null&&n!==void 0?n:t.pos})),create:lo.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),ph=class{constructor(e,t,n,r,s){this.view=e,this.source=t,this.field=n,this.setHover=r,this.hoverTime=s,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e=s:a>s))return new i(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,n)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function Cp(i,e,t,n){let r=i.cursor(),s=[];if(!r.firstChild())return s;if(t!=null){for(let o=!1;!o;)if(o=r.type.is(t),!r.nextSibling())return s}for(;;){if(n!=null&&r.type.is(n))return s;if(r.type.is(e)&&s.push(r.node),!r.nextSibling())return n==null?s:[]}}function Ch(i,e,t=e.length-1){for(let n=i.parent;t>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[t]&&e[t]!=n.name)return!1;t--}}return!0}var Rh=class{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}},Ci=class i extends mo{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(e,t,n){let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.context.start,n);return s<0?null:new i(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,n=0){if(n&oe.ExcludeBuffers)return null;let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new i(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new i(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new i(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,s=n.buffer[this.index+3];if(s>r){let o=n.buffer[this.index+1];e.push(n.slice(r,s,o)),t.push(0)}return new le(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function Ap(i){if(!i.length)return null;let e=0,t=i[0];for(let s=1;s