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

@wings-j/web-shell-simulator

v1.6.5

Published

网页Shell模拟器

Downloads

5

Readme

网页 Shell 模拟器

在网页中模拟 shell 的工具。

安装

npm install --save-dev @wings-j/web-shell-simulator

使用

复制dist目录下的index.js到代码中,使用 esm 或 script 方式(注入类WebShellSimulator)引入。

import WebShellSimulator from '@wings-j/web-shell-simulator'
<script src="./dist/index.umd.js"></script>

示例

Demo

let shell = new WebShellSimulator({}, { overflow: 'hidden', width: '100%', height: '100%', 'padding-bottom': '100px', 'font-size': '16px' })

document.addEventListener('DOMContentLoaded', () => {
  shell.mount('body')
})

let res

shell.addLine('Web Shell Simulator', { color: '#2266ff' })
shell.addBlank()
shell.addLine('Input something, confirm with enter ...')
res = await shell.addInput().promise
shell.addLine(`Input result: ${res}`)
shell.addLine('Select one, move with up and down ...')
res = await shell.addSelect(['a', 'b', 'c']).promise
shell.addLine(`Select result: ${res}`)
shell.addLine('Select some, check with space ...')
res = await shell.addSelect(['a', 'b', 'c'], { multi: true }).promise
shell.addLine(`Select result: ${res.join(', ')}`)

API

WebShellSimulator

属性

  • dom:DOM
  • elements:所有元素集合

构造方法

new WebShellSimulator(config, style)

参数:

  • config:配置
    • mouse:使能鼠标点击事件
  • style:样式。CSS 属性对象。

挂载

mount(selector: string): void

参数:

  • selector:选择器

清空

clear(): void

添加空行

addBlank(): { element: Blank, promise: Promise<void>}

返回:

  • element:元素

添加文本行

addLine(text: string, config): {element: Line, promise: Promise<void>}

参数:

  • text:字符串。文本
  • config:配置
    • color:字符串。颜色
    • typing:布尔。打字动画
    • typingPeriod:数字。打字动画周期
    • html:渲染 HTML

返回:

  • element:元素

添加输入

addInput(config): {element: Input, promise: Promise<string>}

参数:

  • config:配置
    • color: 颜色
    • prefix: 前缀
    • padding: 前缀后边距
    • value: 预设值
    • callback: 回调。传递输入值
    • removeOnEnter: 回车后移除

返回:

  • element:元素
  • promise:输入 Promise

添加选择

addSelect(selections: string[], config): {element: Select, promise: Promise<string|string[]>}

参数:

  • config:配置
    • color:颜色
    • multi:是否多选
    • singlePositive:单选选中前缀
    • singleNegative:单选未选中前缀
    • multiPositive:多选选中前缀
    • multiNegative:多选未选中前缀
    • padding:左边距
    • callback: 回调。传递选中的选项
    • removeOnEnter: 回车后移除

返回:

  • element:元素
  • promise:选择 Promise

添加表格

addTable(data: (string|number)[][], config): {element: Table, promise: Promise<void>}

参数:

  • data:数据
  • config:配置
    • color:字符串。颜色
    • padding:单元格右边距

返回:

  • element:元素

Element

所有添加方法返回 Element 的子类(Line,Blank 等)。

属性

  • dom:DOM
  • active:激活状态

挂载元素

mount(): void

删除元素

remove(): void