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

at-html

v0.2.1

Published

Use `{@html }` tags with slots in Svelte apps

Downloads

6

Readme

at-html

Use {@html } tags with slots in Svelte apps

⚠️Same security concerns as with normal @html tags apply, so I repeat it: Svelte doesn't perform any sanitization of the expression inside {@html ...} before it gets inserted into the DOM. In other words, if you use this feature it's critical that you manually escape HTML that comes from sources you don't trust, otherwise you risk exposing your users to XSS attacks.

Installation

npm I --save-dev at-html

Usage

The atHTML factory function creates a Svelte Component, which renders the supplied html string. Slot tags in the html template are replaced. The component accepts no props.

<script>
    import {atHTML} from 'at-html'

    // Create a Svelte Component from html string
    // start variable with capital letter
    const C = atHTML('<h1><slot></slot></h1>')
</script>
<C>Some slotted content</C>

If you change the html string a new Svelte Component is created. So, if you want to call atHTML in a reactive statement, you should use <svelte:component>

Note: the html string is applied via innerHtml. That means the string must be proper html code, especially most elements need open and closing tags. Self-closing elements like <slot/> might not work as expected. Use <slot></slot> instead.

Named slots

Named slots are supported, use the normal Svelte syntax. Eg. <slot name='title'>' in the html string and prop slot='title'` on the slotted component.

Fallback

Content within the slot tags in the html string is shown as fallback, if the slot is not filled.

Server-Side-Rendering (SSR)

SSR is fully supported.

Non-SSR

There is a simplified component factory, if you want to use this library in a non-SSR environment, eg. in a Svelte single-page-application. It can be imported like this:

import {atHTML} from 'at-html/noSSR';

⚠️This library currently is optimized for the use of Vite. It is highly recommended to use the non-SSR components if you don't use Vite. It uses if (import.meta.env.SSR) {...}, which removes the server side code via tree-shaking. Non-Vite environments will pack the whole svelte compiler code into the client-side code.

How it works

This library modifies an already compiled component. As such, it uses methods from svelte/internal. These don't have the same stability guarantees as user-land methods, so this library may be more likely to be incompatible with future versions of Svelte.

License

MIT