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 hljs from "highlight.js"; import { html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import { createRef, ref } from "lit/directives/ref.js"; import { unsafeHTML } from "lit/directives/unsafe-html.js"; import { RefreshCw } from "lucide"; import { RUNTIME_MESSAGE_ROUTER } from "../../components/sandbox/RuntimeMessageRouter.js"; import { i18n } from "../../utils/i18n.js"; import "../../components/SandboxedIframe.js"; import { ArtifactElement } from "./ArtifactElement.js"; import "./Console.js"; import { icon } from "@mariozechner/mini-lit"; import { Button } from "@mariozechner/mini-lit/dist/Button.js"; import { CopyButton } from "@mariozechner/mini-lit/dist/CopyButton.js"; import { DownloadButton } from "@mariozechner/mini-lit/dist/DownloadButton.js"; import { PreviewCodeToggle } from "@mariozechner/mini-lit/dist/PreviewCodeToggle.js"; let HtmlArtifact = class HtmlArtifact extends ArtifactElement { constructor() { super(...arguments); this.filename = ""; this.runtimeProviders = []; this._content = ""; this.logs = []; // Refs for DOM elements this.sandboxIframeRef = createRef(); this.consoleRef = createRef(); this.viewMode = "preview"; } setViewMode(mode) { this.viewMode = mode; } getHeaderButtons() { const toggle = new PreviewCodeToggle(); toggle.mode = this.viewMode; toggle.addEventListener("mode-change", (e) => { this.setViewMode(e.detail); }); const copyButton = new CopyButton(); copyButton.text = this._content; copyButton.title = i18n("Copy HTML"); copyButton.showText = false; // Generate standalone HTML with all runtime code injected for download const sandbox = this.sandboxIframeRef.value; const sandboxId = `artifact-${this.filename}`; const downloadContent = sandbox?.prepareHtmlDocument(sandboxId, this._content, this.runtimeProviders || [], { isHtmlArtifact: true, isStandalone: true, // Skip runtime bridge and navigation interceptor for standalone downloads }) || this._content; return html `