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

microway

v0.1.3

Published

用于编写HTML标签的JS库

Downloads

3

Readme

项目介绍

一个在js/ts中编写html标签的 dom 库

基础教程

首先引入

import { init, render, t } from 'microway'

init(h => h.to(render))

使用 t 函数来编写 html

let { div, a } = t

const dom = div(
    div`ddd span='14'`(
      a`href='https://baidu.com/' target="_blank"`('百度'),
      456
    ),
  )

document.querySelector('#app')!.append(dom)

接下来是在标签上使用js变量

const pd = '25px'
const num = 123

const on = {
  click() {
    console.log('hello microway')
  }
}

const dom = div(
  div`ddd span='14'`(
    a`${{ href: 'https://baidu.com/' }} target="_blank"`('百度'),
    div`style=${{ 'padding-top': pd }}`(l`span`('fff'), pd),
    num
  ),
  div`${{ on, style: { border: '1px solid red' } }}`('btn')
)

引入变量的情况分为在等号后引入,此时 style 为属性名

div`style=${{ 'padding-top': pd }}`()

以及直接引入对象字面量,此时 href 为属性名

a`${{ href: 'https://baidu.com/' }} target="_blank"`()

响应式

前面的教程都属于静态部分,因为 render 只会编译一次,想要动态内容,就得使用响应式框架,本项目不提供响应式框架实现,但是可 以通过配置引入其他框架,接下来使用 @vue/reactivity 来演示

import { isRef, effect, stop, computed, ref } from '@vue/reactivity'
import { use, signalExtendPlugin } from 'microway'

use({
  signal: {
    is: isRef,
    get: obj => (isRef(obj) ? obj.value : obj),
    memo: computed,
    effect,
    stop
  }
})
use(signalExtendPlugin)

const pd = ref('25px')
const href = ref('https://baidu.com/')
const num = ref(2)

const on = {
  click() {
    num.value++
    console.log('add: ', num.value)
  }
}

const setPd = () => {
  pd.value = '10px'
}

const fgm = div(
  div`ddd span='14'`(
    a`href=${href} target="_blank"`('百度'),
    div`style=${{ 'padding-top': pd }} onclick=${setPd}`(pd),
    456
  ),
  div`${{ on, style: { border: '1px solid red' } }}`('hello'),
  div(() => [...new Array(num.value).keys()].map(i => div`style='color: blue'`(i)))
)

组件化


import { define, definePlugin } from 'microway'

use(definePlugin)

const pd = ref('25px')
const href = ref('https://baidu.com/')
const num = ref(2)

const setPd = () => {
  pd.value = '10px'
}

let { div, a, myDiv } = t

define.myDiv((props: any) =>
  div(
    div`ddd span='14'`(
      a`href=${href} target="_blank"`('百度'),
      div`style=${{ 'padding-top': props.pd }} onclick=${setPd}`(props.pd),
      456
    )
  )
)

document.querySelector('#app')!.append(myDiv`${{ pd }}`())

项目地址