diff --git a/components/playground/element.css b/components/playground/element.css index 9a56bc330..f5a54881d 100644 --- a/components/playground/element.css +++ b/components/playground/element.css @@ -138,7 +138,7 @@ mdn-modal { flex-direction: column; gap: 0.5rem; - &:first-child { + &:not(:last-child) { margin-bottom: 1rem; } } diff --git a/components/playground/element.js b/components/playground/element.js index 5fa9fe858..9c2847848 100644 --- a/components/playground/element.js +++ b/components/playground/element.js @@ -118,6 +118,22 @@ ${"```"}`, } } + async _copyDataUrl() { + const controller = this._controller.value; + if (controller) { + const { css, html, js } = controller.code; + let code = ``; + if (css) code += ``; + if (html) code += html; + if (js) code += ``; + // encode non-space whitespace + code = code.replaceAll(/[^\S ]/g, (ch) => encodeURIComponent(ch)); + await navigator.clipboard.writeText( + `data:text/html;charset=utf-8,${code}`, + ); + } + } + async _createPermalink() { const controller = this._controller.value; if (controller) { @@ -372,10 +388,22 @@ ${"```"}`,

${this.l10n`Share Markdown`}

- ${this.l10n`Copy markdown to clipboard`}
+
+

${this.l10n`Share Data URL`}

+ ${this.l10n`Copy data URL to clipboard`} +

${this.l10n`Share your code via Permalink`}

${this._user.render({ @@ -389,6 +417,7 @@ ${"```"}`, ${this.l10n`Copy to clipboard`} `