var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { DownloadButton } from "@mariozechner/mini-lit/dist/DownloadButton.js"; import { html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import * as pdfjsLib from "pdfjs-dist"; import { i18n } from "../../utils/i18n.js"; import { ArtifactElement } from "./ArtifactElement.js"; // Configure PDF.js worker pdfjsLib.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/build/pdf.worker.min.mjs", import.meta.url).toString(); let PdfArtifact = class PdfArtifact extends ArtifactElement { constructor() { super(...arguments); this._content = ""; this.error = null; this.currentLoadingTask = null; } get content() { return this._content; } set content(value) { this._content = value; this.error = null; this.requestUpdate(); } createRenderRoot() { return this; } connectedCallback() { super.connectedCallback(); this.style.display = "block"; this.style.height = "100%"; } disconnectedCallback() { super.disconnectedCallback(); this.cleanup(); } cleanup() { if (this.currentLoadingTask) { this.currentLoadingTask.destroy(); this.currentLoadingTask = null; } } base64ToArrayBuffer(base64) { // Remove data URL prefix if present let base64Data = base64; if (base64.startsWith("data:")) { const base64Match = base64.match(/base64,(.+)/); if (base64Match) { base64Data = base64Match[1]; } } const binaryString = atob(base64Data); const bytes = new Uint8Array(binaryString.length); for (let i = 0; i < binaryString.length; i++) { bytes[i] = binaryString.charCodeAt(i); } return bytes.buffer; } decodeBase64() { let base64Data = this._content; if (this._content.startsWith("data:")) { const base64Match = this._content.match(/base64,(.+)/); if (base64Match) { base64Data = base64Match[1]; } } const binaryString = atob(base64Data); const bytes = new Uint8Array(binaryString.length); for (let i = 0; i < binaryString.length; i++) { bytes[i] = binaryString.charCodeAt(i); } return bytes; } getHeaderButtons() { return html `