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

waifu-assistant

v1.0.0

Published

Live 2D widged with responsive dialogue.

Downloads

2

Readme

<waifu-assistant>

Usage

Load required js.

<head>
    <!-- Required for live2d rendering -->
    <script src="https://cubism.live2d.com/sdk-web/cubismcore/live2dcubismcore.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/dylanNew/live2d/webgl/Live2D/lib/live2d.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/browser/pixi.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/pixi-live2d-display/dist/index.min.js"></script>

    <!-- The assistant -->
    <script src="waifu-assistant.js" defer></script>
</head>

The script regiesters a new custom element waifu-assistant. This can now be used in html or from js.

Initialize from html

<body>
    <waifu-assistant
        dialogue-src="./dialogue_example.json" 
        model-src="https://cdn.jsdelivr.net/npm/[email protected]/model/Potion-Maker/Tia/index.json">
    </waifu-assistant>
</body>

Initialize from js

You can also initialize the element from js, like any custom element.

const waifu = document.createElement("div", {is: "waifu-assistant"});
waifu.setAttribute("dialogue-src", "/js/dialogue.json");
waifu.setAttribute("model-src", "https://cdn.jsdelivr.net/npm/[email protected]/model/Potion-Maker/Tia/index.json");
document.getElementById("some-parent-element").appendChild(element);

Defining dialogue JSON

Json file loaded by setting the dialogue-src attribute. See demo/dialogue_example.json for example.

Event triggers

Specify html events to trigger dialogue on. For example:

{
    "event": "mouseover",
    "selector": ".someclass",
    "dialogueId": "sample message"
}

This will trigger the dialogue sample message when the mouseover event is triggered on an element matching the css selector .someclass. Note that this will only work on events that bubble up to the document level. If events are captured earlier they will not be detected.

Dialogue

Contains the predefined messages. The messages can be triggered by the auto triggers specified in the json or by calling WaifuAssistant.triggerDialogue(dialogueId). Example:

{
  "id": "sample message",
  "text": ["Hello!"]
}

Each dialogue object can contain the following fields.

  • text: Array of strings. Contains the sequence of messages to be displayed.
  • duration (optional): Array of numbers. Specifies time spent on each message in seconds. Use element null for automatic timing.
  • motion (optional): Array of keys to model motion to be taken during message.
  • expression (optional): Array of keys to model expression to be used during message.
  • behavior (optional): String SEQUENCE|RANDOM. Default SEQUENCE.
    • SEQUENCE: Messages will be displayed in sequence.
    • RANDOM: One message will be displayed at random.
  • priority (optional): String IMMEDIATE|IS_SILENT|INTERRUPT|QUEUE. Dictates how the message is pushed. Default IMMEDIATE.
    • IMMEDIATE: clears the message queue and immediately displays message.
    • IS_SILENT: message only pushed if there is no current message being displayed.
    • INTERRUPT: immedietly displays message but then restores the previous queue.
    • QUEUE: adds the message to the end of the message queue.
  • cooldown (optional): Number. Seconds until this message may be triggered again. -1 for never repeating again.
  • chance (optional): Number from 0 to 1. Chance that the dialogue will display on trigger. Cooldown still applies on failed roll.

Trigger dialogue from js

You can easily trigger dialogue manually from js. Either messages defined in the json or custom ones.

const waifu = document.getElementById("waifu-assistant");
waifu.triggerDialogueById("welcome message"); // Triggers the message with id "welcome message" from the loaded json.
waify.triggerDialogue({
    text: ["hello", "there"]
}); // Triggers the specified dialogue object. Same object specification as detailed in #Dialogue.