npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

be-eventing

v0.0.5

Published

Minimal CSP security rules stipulate that inline event handlers are "out of bounds" as far as guaranteeing safety.

Downloads

341

Readme

be-eventing (🏇)

Minimal CSP security rules stipulate that inline event handlers are "out of bounds" as far as guaranteeing safety.

This enhancement is designed to live within those (excessively?) tight constraints, and still be able to attach event handlers "locally" without requiring a framework or custom element host that has to micromanage everything -- leading to tight coupling.

Whereas attaching an event handler using a unique id may work outside the shadow DOM, it doesn't work very well with repeating content, especially inside Shadow Roots. This, in my view, is driving a stake through progressive enhancement.

This enhancement endeavors to blunt the edge of that stake.

1995 scripting, but harder

<button disabled>My Button</button>
<script nomodule be-eventing-on=click>console.log({e})</script>

or

<button disabled>My Button</button>
<script 🏇-on=click>console.log({e})</script>

Either one attaches the click event handler to the previous element sibling (button in this case) by default.

If "disabled" is a property of the target element, be-eventing nudges the attribute -- basically removing it.

By the way, the "click" event is assumed by default, unless the target element is an input element, in which case the "input" event is assumed, or a slot element, in which case the "slotchange" event is assumed.

So this also works:

<button disabled>My Button</button>
<script 🏇>console.log({e})</script>

un-deferring

be-eventing can also "nudge" "defer-[enhancementBase]" attributes:

<ways-of-science itemscope>
    <carrot-nosed-woman></carrot-nosed-woman>
    <a-duck></a-duck>
    <template
        defer-be-switched
        be-switched='On based on ~carrotNosedWoman::weight-change and ~aDuck::molting.'
    >
        <div>A witch!</div>
        <div>Burn her!</div>
    </template>
    <script 🏇-nudge=be-switched 🏇-on=change>
        e.r = Math.abs(e.f.carrotNosedWoman - e.f.aDuck) < 10;
    </script>
</ways-of-science>

What this does, precisely:

  1. Attaches the enhanced event listener to the previous non script element sibling.
  2. "Nudges" the defer-be-switched (eliminating it if there's no numeric value or it has value="1", otherwise decrements the number)

Occasional (?) short cut when the stars align

A pattern seems to be emerging that some enhancements find it natural to raise an event with the same name as the enhancement itself:

<div>
    <input id=searchString type=search>

    <div defer-🔭 🔭='#searchString and punt.'></div>
    <script 🏇=🔭>
        e.target.textContent = e.args[0] + ' World';
    </script>
</div>

This is equivalent to:

<div>
    <input id=searchString type=search>

    <div defer-🔭 🔭='#searchString and punt.'></div>
    <script 🏇-on=🔭 🏇-nudge=🔭>
        e.target.textContent = e.args[0] + ' World';
    </script>
</div>

Withing you were here

Like the native event handlers, the context of the element that dispatched can be accessed easily:

<button>My Button</button>
<script 🏇 nomodule>textContent = 'hello';</script>

Viewing Locally

Any web server that serves static files will do but...

  1. Install git.
  2. Fork/clone this repo.
  3. Install node.
  4. Install Python 3 or later.
  5. Open command window to folder where you cloned this repo.
  6. npm install

  7. npm run serve

  8. Open http://localhost:8000/demo in a modern browser.

Importing in ES Modules:

import 'be-eventing/be-eventing.js';

Using from CDN:

<script type=module crossorigin=anonymous>
    import 'https://esm.run/be-eventing';
</script>