Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="ph app" id="app">
  <header class="ph header">
    <a class="ph home" href="https://phun-ky.net" target="_blank">home</a>
    <a class="ph projects-home" href="https://phun-ky.net/projects" target="_blank">projects</a>
    <div class="ph header-menu">
      <a class="ph" href="https://www.paypal.me/phunky/20" rel="noopener noreferrer" target="_blank">buy me a coffee?</a>
      <a class="ph" href="https://github.com/sponsors/phun-ky" rel="noopener noreferrer" target="_blank">sponsor me!</a>
      <button class="ph darkmode-button">
        <svg xmlns="http://www.w3.org/2000/svg" aria-label="Sun Icon" fill="currentColor" stroke="none" class="ph hide-dark" viewBox="0 0 20 20">
          <path fill-rule="evenodd" d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" clip-rule="evenodd"></path>
        </svg>
        <svg xmlns="http://www.w3.org/2000/svg" aria-label="Moon Icon" fill="currentColor" stroke="none" class="ph hide-light" viewBox="0 0 20 20">
          <path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"></path>
        </svg>
      </button>
    </div>
  </header>
  <main class="ph">
    <section class="ph section">
      <div class="ph container">
        <h1 class="ph">Invoker shim</h1>
        <p class="ph"></p>

      </div>
    </section>
    <section class="ph section">
      <div class="ph container">
        <div class="ph counter">
          <button class="ph" commandfor="num" command="stepDown">-</button>
          <input class="ph" type="number" min="1" id="num" value="1" />
          <button class="ph" commandfor="num" command="stepUp">+</button>
        </div>
        <p class="ph">
          Click on the minus and plus buttons, and the invoker shim will work :)
        </p>
        <div class="ph message note">
          <span class="ph title"><svg class="ph icon" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">
              <path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path>
            </svg>Note</span>
          <p class="ph">
            This is just a shim, if you need a polyfill, check out <a href="https://github.com/keithamus/invokers-polyfill" class="ph">https://github.com/keithamus/invokers-polyfill</a>
          </p>
        </div>

      </div>
    </section>
    <section class="ph section">
      <div class="ph container">
        <pre class="ph language-html"><code class="ph language-html">&lt;div class="ph counter"&gt;
  &lt;button class="ph" commandfor="num" command="stepDown"&gt;-&lt;/button&gt;
  &lt;input class="ph" type="number" min="1" id="num" value="1" /&gt;
  &lt;button class="ph" commandfor="num" command="stepUp"&gt;+&lt;/button&gt;
&lt;/div&gt;</code></pre>
      </div>
    </section>
    <section class="ph section">
      <div class="ph container">
        <pre class="ph language-js"><code class="ph language-js">const invoke = (): void => {
  document.querySelectorAll("[commandfor]").forEach((element) => {
    const command = element.getAttribute("command");
    const targetElementSelector = element.getAttribute("commandfor");
    if (!command || !targetElementSelector) return;

    const targetElement = document.getElementById(targetElementSelector);
    if (!targetElement) return;

    const handleClick = () => {
      try {
        if (typeof targetElement[command as keyof HTMLElement] === "function") {
          (targetElement[command as keyof HTMLElement] as Function).call(
            targetElement
          );
        } else {
          console.error(
            `Command '${command}' is not a function on the target element.`
          );
        }
      } catch (e) {
        console.error(
          `Failed to execute command '${command}' on target element:`,
          e
        );
      }
    };

    element.removeEventListener("click", handleClick);
    element.addEventListener("click", handleClick);
  });
};

// Bind command events when the script is loaded
invoke();</code></pre>

      </div>
    </section>
  </main>

  <footer class="ph">
    <div class="ph container">
      <p class="ph">
        Made with <strong class="ph">saturated fat</strong> by
        <a class="ph" target="_blank" href="https://phun-ky.net">Alexander Vassbotn Røyne-Helgesen</a>. Buy <strong class="ph">me</strong> some
        <a class="ph" href="https://www.paypal.me/phunky/20">bacon?</a>
      </p>
      <p class="ph">
        This project created by
        <a rel="noopener noreferrer" target="_blank" class="ph" href="http://phun-ky.net" property="cc:attributionName">
          Alexander Vassbotn Røyne-Helgesen</a>
        is licensed under a
        <a rel="noopener noreferrer" target="_blank" class="ph" href="https://choosealicense.com/licenses/mit/">
          MIT License </a>.
      </p>
      <p class="ph">
        <a rel="noopener noreferrer" target="_blank" class="ph" rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">
          <img alt="Creative Commons Licence" style="border-width: 0" width="88" height="31" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" />
        </a>
        <br />Any other creation or work related to this project, if not specified, like
        templates, logos etc created by
        <a rel="noopener noreferrer" target="_blank" class="ph" href="http://phun-ky.net" property="cc:attributionName" rel="cc:attributionURL">
          Alexander Vassbotn Røyne-Helgesen</a>
        is licensed under a
        <a rel="noopener noreferrer" target="_blank" class="ph" rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">
          Creative Commons Attribution-NonCommercial-ShareAlike 4.0
          International License </a>.
      </p>
    </div>
  </footer>
</div>

<script src="https://unpkg.com/prismjs@1.29.0/prism.js"></script>
<script src="https://unpkg.com/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
<script src="https://unpkg.com/prismjs@1.29.0/components/prism-css-extras.min.js"></script>
<script src="https://unpkg.com/prismjs@1.29.0/plugins/inline-color/prism-inline-color.min.js"></script>
<link async href="https://unpkg.com/prismjs@1.29.0/plugins/inline-color/prism-inline-color.min.css" rel="stylesheet" type="text/css" />
              
            
!

CSS

              
                *.ph,
*.ph::after,
*.ph::before {
  margin: 0;
  padding: 0;
  word-break: break-word;
  box-sizing: border-box;
  -webkit-font-smoothing: antialised;
}
html {
  font-family: var(
    --ph-font-family,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Helvetica,
    Arial,
    sans-serif,
    Apple Color Emoji,
    Segoe UI Emoji
  );
}
html,
body {
  height: 100%;
  min-height: 100%;
}
body {
  background-color: var(--ph-color-background, #181a22);
  color: var(--ph-color-text, #9fa8ad);
  padding: 0;
  margin: 0;
  line-height: 1.5;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif;
}
main.ph {
  flex-grow: 1;
}
.ph.container {
  max-width: 48rem;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  margin-top: 2.5rem;
  margin-bottom: 2.5rem;
}

.ph.frontpage .ph.container {
  margin-bottom: 1.25rem;
  margin-top: 1.25rem;
  max-width: 1024px;
}

.ph.project .ph.banner .ph.container {
  max-width: 48rem;
  width: 100%;
  margin-top: 2.5rem;
  margin-bottom: 2.5rem;
  padding-top: 6rem;
  padding-bottom: 6rem;
}
footer.ph.footer {
  font-size: 1.25rem;
  z-index: 100;
  flex-grow: 0;
  margin-top: auto;
}
.ph.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  position: relative;
  padding: 1.25rem;
}
a.ph {
  color: var(--ph-color-link, #6ca7f9);
  font-weight: 500;
}
a.ph:visited {
  color: var(--ph-color-link-visited, #6ca7f9);
}
a.ph:active {
  color: var(--ph-color-link-active, #6ca7f9);
}
a.ph:hover {
  color: var(--ph-color-link-hover, #6ca7f9);
}
p,
p.ph,
.ph.byline {
  font-style: normal;
  max-width: 65ch;
  font-size: 1rem;
  line-height: 1.75rem;
  color: var(--ph-color-text, #9fa8ad);
  margin-top: 1.25em;
  margin-bottom: 1.25em;
}
.ph.byline time,
.ph.byline .ph.read-time {
  opacity: 0.7;
}
article.ph {
  color: var(--ph-color-text, #9fa8ad);
  font-size: 1rem;
  line-height: 1.75rem;
}
p.lead,
p.ph.lead {
  color: var(--ph-color-text-accent, #e4e4e7);
  font-weight: 600;
  line-height: 1.75rem;
  margin-bottom: 2.5rem;
  font-size: 1.125rem;
}
.ph.frontpage p.ph.lead {
  padding-top: 2.5rem;
  padding-bottom: 2.5rem;
  margin: 0;
  font-weight: normal;
  color: inherit;
}
.ph.author p.ph,
footer.ph p.ph {
  max-width: none;
}
h1.ph,
h2.ph,
h3.ph,
h4.ph,
h5.ph,
h6.ph {
  color: var(--ph-color-text-accent, #e4e4e7);
}
h1.ph {
  margin-bottom: 2.5rem;
  font-size: 2.25rem;
  line-height: 1.25;
  font-weight: 700;
}
@media screen and (min-width: 768px) {
  h1.ph {
    font-size: 3rem;
    line-height: 1.375;
  }
}
@media screen and (min-width: 1024px) {
  h1.ph {
    font-size: 3.75rem;
    line-height: 1.375;
  }
}
h1.ph > em.ph {
  font-weight: normal;
  max-width: 65ch;
  font-size: 1rem;
  line-height: 1.75rem;
  display: block;
  color: var(--ph-color-text);
}
.ph.frontpage h1.ph {
  margin-bottom: 2.5rem;
  font-size: 3rem;
  line-height: 1.375;
}
@media screen and (min-width: 1024px) {
  .ph.frontpage h1.ph {
    font-size: 4.75rem;
  }
}
h2.ph {
  font-size: 1.75rem;
  line-height: 1.3333333;
  margin-bottom: 1rem;
  margin-top: 2rem;
}
h3.ph {
  font-size: 1.5rem;
  line-height: 1.3333333;
  margin-bottom: 1rem;
  margin-top: 1rem;
  font-weight: 400;
}
h4.ph {
  font-size: 1.25rem;
  line-height: 1.3333333;
  margin-bottom: 1rem;
  margin-top: 1rem;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--ph-color-text);
}
header.ph.header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-grow: 0;
  grid-gap: 1rem;
  min-height: 3rem;
}
@media screen and (min-width: 1440px) {
  header.ph.header {
    position: sticky;
    top: 20px;
    z-index: 100;
  }

  .ph.project header.ph.header {
    position: static;
    top: unset;
  }
}
.ph.header-menu {
  margin-left: auto;
  min-height: 3rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  grid-gap: 1rem;
}
.ph.header-menu a.ph {
  display: none;
}
@media screen and (min-width: 640px) {
  .ph.header-menu a.ph {
    display: inline-block;
  }
}
.ph.darkmode-button {
  align-items: center;
  background-color: transparent;
  border: none;
  border-radius: 50%;
  color: var(--ph-color-text);
  cursor: pointer;
  display: flex;
  height: 3rem;
  justify-content: center;
  width: 3rem;
}
.ph.darkmode-button:active,
.ph.darkmode-button:hover {
  background-color: var(--ph-color-well-background);
}
.ph.darkmode-button > svg.ph {
  pointer-events: none;
  height: 2rem;
  width: 2rem;
}
.ph.hide-dark {
  display: none;
}
.ph.hide-light {
  display: block;
}
.ph.theme--light .hide-light {
  display: none;
}
.ph.theme--light .hide-dark {
  display: block;
}
p.ph:has(> img[src^="/img"]) {
  max-width: none;
}

.ph.counter button.ph {
  height: 3rem;
  width: 3rem;
  font-size: 2rem;
  font-weight: bold;
}
.ph.counter input.ph {
  height: 3rem;
  width: auto;
  max-width: 5rem;
  font-size: 2rem;
  font-weight: bold;
}
.ph.counter {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  grid-gap: 0.5rem;
}

/**

Template stuff, ignore this

**/
code[class*="language-"] .namespace,
pre[class*="language-"] .namespace {
  opacity: 0.7;
}
code[class*="language-"] .token.comment,
code[class*="language-"] .token.prolog,
code[class*="language-"] .token.doctype,
code[class*="language-"] .token.cdata,
pre[class*="language-"] .token.comment,
pre[class*="language-"] .token.prolog,
pre[class*="language-"] .token.doctype,
pre[class*="language-"] .token.cdata {
  color: var(--ph-color-code-color-1);
}
code[class*="language-"] .token.null,
code[class*="language-"] .token.operator,
code[class*="language-"] .token.boolean,
code[class*="language-"] .token.number,
pre[class*="language-"] .token.null,
pre[class*="language-"] .token.operator,
pre[class*="language-"] .token.boolean,
pre[class*="language-"] .token.number {
  color: var(--ph-color-code-color-2);
}
code[class*="language-"] .token.attr-name,
code[class*="language-"] .token.string,
pre[class*="language-"] .token.attr-name,
pre[class*="language-"] .token.string {
  color: var(--ph-color-code-color-3);
}
code[class*="language-"] .token.entity,
code[class*="language-"] .token.url,
.language-css code[class*="language-"] .token.string,
.style code[class*="language-"] .token.string,
pre[class*="language-"] .token.entity,
pre[class*="language-"] .token.url,
.language-css pre[class*="language-"] .token.string,
.style pre[class*="language-"] .token.string {
  color: var(--ph-color-code-color-3);
}
code[class*="language-"] .token.selector,
pre[class*="language-"] .token.selector {
  color: var(--ph-color-code-block);
}
code[class*="language-"] .token.atrule,
code[class*="language-"] .token.attr-value,
code[class*="language-"] .token.keyword,
code[class*="language-"] .token.control,
code[class*="language-"] .token.directive,
code[class*="language-"] .token.important,
code[class*="language-"] .token.unit,
pre[class*="language-"] .token.atrule,
pre[class*="language-"] .token.attr-value,
pre[class*="language-"] .token.keyword,
pre[class*="language-"] .token.control,
pre[class*="language-"] .token.directive,
pre[class*="language-"] .token.important,
pre[class*="language-"] .token.unit {
  color: var(--ph-color-code-color-4);
}
code[class*="language-"] .token.regex,
code[class*="language-"] .token.statement,
pre[class*="language-"] .token.regex,
pre[class*="language-"] .token.statement {
  color: var(--ph-color-code-color-3);
}
code[class*="language-"] .token.placeholder,
code[class*="language-"] .token.variable,
pre[class*="language-"] .token.placeholder,
pre[class*="language-"] .token.variable {
  color: var(--ph-color-code-color-4);
}
code[class*="language-"] .token.property,
code[class*="language-"] .token.tag,
pre[class*="language-"] .token.property,
pre[class*="language-"] .token.tag {
  font-style: italic;
}
code[class*="language-"] .token.important,
code[class*="language-"] .token.statement,
pre[class*="language-"] .token.important,
pre[class*="language-"] .token.statement {
  font-weight: bold;
}
code[class*="language-"] .token.punctuation,
pre[class*="language-"] .token.punctuation {
  color: var(--ph-color-code-color-5);
}
code[class*="language-"] .token.entity,
pre[class*="language-"] .token.entity {
  cursor: help;
}
code[class*="language-"] .token.debug,
pre[class*="language-"] .token.debug {
  color: var(--ph-color-code-color-8);
}

pre,
pre.ph {
  background-color: var(--ph-color-code-block-background);
  border-radius: 0.375rem;
  color: var(--ph-color-code-block);
  font-size: 0.875rem;
  line-height: 1.5rem;
  margin-bottom: 1.5rem;
  margin-top: 1.5rem;
  max-height: 80vh;
  overflow-x: auto;
  padding: 0.75rem 1rem;
}

@media screen and (min-width: 1024px) {
  pre,
  pre.ph {
    font-size: 1rem;
    line-height: 1.75rem;
    margin-bottom: 2rem;
    margin-top: 2rem;
    padding: 1rem 1.5rem;
  }
}

code,
kbd,
samp,
pre {
  font-family: var(--ph-font-family-code);
}

.ph span.inline-color-wrapper {
  border-radius: 50%;
  border: 1pt solid white;
  background-clip: padding-box;
  outline: none;
  margin: 0 0.5ch 0 0.333ch;
}

.theme--light .ph span.inline-color-wrapper {
  border: 1pt solid black;
}

              
            
!

JS

              
                console.clear();
/**
 * @author Alexander Vassbotn Røyne-Helgesen <alexander@phun-ky.net>
 * @license
 * Copyright (c) 2024 Alexander Vassbotn Røyne-Helgesen
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/**
 * An invoker shim (https://open-ui.org/components/invokers.explainer/)
 * It binds click events to elements with a `commandfor` attribute to execute a specified command on a target element.
 *
 * This function selects all elements with a `commandfor` attribute and adds a click event listener that executes
 * the specified command on the target element identified by the `commandfor` attribute.
 *
 * @example
 * ```ts
 * // HTML example
 * // <button command="focus" commandfor="inputField">Focus Input</button>
 * // <input id="inputField" type="text" />
 *
 * // JavaScript
 * invoke();
 * ```
 */
const invoke = (): void => {
  document.querySelectorAll("[commandfor]").forEach((element) => {
    const command = element.getAttribute("command");
    const targetElementSelector = element.getAttribute("commandfor");
    if (!command || !targetElementSelector) return;

    const targetElement = document.getElementById(targetElementSelector);
    if (!targetElement) return;

    const handleClick = () => {
      try {
        if (typeof targetElement[command as keyof HTMLElement] === "function") {
          (targetElement[command as keyof HTMLElement] as Function).call(
            targetElement
          );
        } else {
          console.error(
            `Command '${command}' is not a function on the target element.`
          );
        }
      } catch (e) {
        console.error(
          `Failed to execute command '${command}' on target element:`,
          e
        );
      }
    };

    element.removeEventListener("click", handleClick);
    element.addEventListener("click", handleClick);
  });
};

// Bind command events when the script is loaded
invoke();

              
            
!
999px

Console