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

web-replayer

v1.1.1

Published

To replay in a web viewport by given replay logs.

Downloads

21

Readme

Web Replayer

To replay in a web viewport by given replay logs.

Install

npm i web-replayer

Usage

<div id="replayer"></div>
<script type="module">
    import { createReplayer, createReplayerFramesGenerator } from 'https://unpkg.com/web-replayer';
    const genertor = createReplayerFramesGenerator([
        // logs ...
    ]);
    const replayer = createReplayer(genertor);
    document.querySelector('#replayer').appendChild(replayer);
</script>

API

To create a web replayer, you should provide frames data, the replayer will paly the frames to prsent the content.

createReplayer

Create a web replayer instance.

import { createReplayer } from 'https://unpkg.com/web-replayer';
const replayer = createReplayer();

It receives only parameter which is the frames or the frames generator to prsent. You should use the following tool functions to create frames or frames generator.

createReplayerDriver

const convertor = (context) => [
    // frames
];
const drive = createReplayerDriver(convertor);
const framesGenerator = drive(logs);

// after you append replayer to the document, you can add the frames
replayer.add(framesGenerator);

Firstly, convertor here is a function to convert each log data to a frame object. For example, we provide a log data:

{
    type: 'mousemove',
    time: new Date('2024-03-01T00:00:04.000Z'),
    detail: {
        x: 719,
        y: 225,
    },
}

And we want to convert it to be a frame (reading more in the following parts):

{
    time: 1709251204000,
    invoke() { ... },
    data: log,
}

We should provide a convertor like:

const convertor = (context) => [
    ...,
    {
        type: 'mousemove',
        invoke(log) {
            const { detail: { x, y } } = log;
            context.mouse.move(x, y);
        },
    }
    ...,
];

The convertor provides a mousemove type to create a frame which handle the same type logs.

The context provides some objects from the replayer instance who's replayer, sandbox, mouse, touch. Read more in the following Replayer part.

createReplayerFramesGenerator

A built in package of create a frames generator which following the log data structure of Anys.

const generator = createReplayerFramesGenerator(logsOfAnys);
replayer.add(generator);

Frame

A frame is an operation to replay. It has 4 properties:

  • time: timestamp of the action happened
  • invoke: what to do when the action happened
  • revoke: how to remove the affect of the action
  • data: the original replay information
{
    time: +new Date('2024-03-01T00:00:04.000Z'),
    invoke: (log, i, frames) => {
        const div = document.createElement('div');
        div.id = 'xxx';
        div.innerHTML = 'xxx';
        document.body.appendChild(div);
    },
    revoke: (log, i, frames) => {
        document.body.removeChild(document.querySelector('#xxx'));
    },
    data: log,
}

A frameset is a set of frames. To define a frameset:

{
    img: [frame1, frame2],
    audio: [frame3, frame4],
}

Replayer instances only support receiving frameset, so if you sometimes use web replayer to create your own replayer presenting, you should define your frameset. and invoke replayer.add(frameset) to replay.

Replayer

A web replayer instance is a custom element who has some advanced interfaces to operate.

To create a replayer instance, you should use createReplayer interface to create one.

const replayer = createReplayer();

Then you should append the replayer instance into document.

document.querySelector('#replayer').appendChild(replayer);

Then the replayer will work as expected.

add

Add frameset to the replayer. The parameter can be frames or frames generator.

const frames = [
    { time, invoke },
];
const frameset = { default: frames };
replayer.add(frameset);
const generator = createReplayerFramesGenerator(logsOfAnys);
replayer.add(generator);

clear

If you want to change the frameset of a replayer, you should first clear, and then add new frameset.

replayer.clear();
replayer.add(frameset);

size

Change replayer viewport size.

replayer.size(900, 700);

url

Change replayer url value in navigation part.

replayer.url('new url');

attributes

You can set attributes to change the default behaviour of the replayer:

replayer.setAttribute('supports-dark-mode', 1);
  • speed default play speed
  • color theme color of the replayer
  • tip-color default color of the popover tip
  • font-color default color of the font
  • font-family
  • disable-drag
  • rebuild-when-drag will replay frames from the start to current when drag
  • debug
  • name when debug is set, you can set a name of the replayer, and read it from window.replayers[name]
  • supports-dark-mode when set and your computer system is changed to dark mode, new theme will be used
  • only-progress dont show other elements, only show progress bar

Sandbox

A replayer instance has a sandbox property which is a Sandbox instance. The sandbox instance keep a iframe to present the logs, you can read from sandbox to operate the iframe.

const { sandbox } = replayer;
const { document: doc, window: win } = sandbox;

html

Rewrite the html of the sandbox document.

sandbox.html('<div>xxx</div>');

clear

Clear the content of the sandbox.

sandbox.clear();

License

GNU AFFERO GENERAL PUBLIC LICENSE