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

@a-morphous/frontispiece-ink-processor

v4.2.3

Published

API wrapper around ink to show multiple lines, give ink a JSON visual state that can be saved and loaded, and connect to state.

Downloads

32

Readme

Ink Processor

A generic ink story processor that wraps InkJS and gives you an api for advancing through the story, saving visual state of lines you've seen before, and parsing lines and producing generic commands.

Why?

Ink's parser is very stateful; at any point, the ink story only lets you see the current line, and holds a lot of variables within the core class that cannot easily be serialized. This means that ink doesn't play nice with a lot of Javascript's immutable, data-first frontend stores, which this library attempts to rectify.

Note that this doesn't handle all of Ink's features, and is framework agnostic. More likely for projects, you'll be using one of the other adapters that take the results of ink-processor and hooks it up with a state management system... such as ink-hookstate.

Features

  • Creates an engine wrapper that includes separate visual state for an Ink story, which can be fed into React or other frontend frameworks to display stories (and properly keeps the correct objects mutable / immutable for performance reasons)
  • Exposes a Command engine that lets you create your own logic for lines that are marked as commands, by default any line that begins with $.

Usage

Creating a Story

import { Story } from 'inkjs'
import storyJSON from 'assets/story.json'

const story = new Story(storyJSON)
const config = {
    commandIdentifier: '$' // can be overridden to use a different prefix for identifying commands than $
    lineParser: undefined // can be replaced by a function to produce a different set of tokens than the default.
}
const engine: InkProcessorEngine = new InkProcessorEngine(story, config)

// now you can manipulate the story
engine.advance()
engine.hideAllVisible()
engine.makeChoice(1)

// ...and see the raw Ink state
console.log(engine.inkStory)
// or the visual state
console.log(engine.getVisibleLines())

Creating Commands

Your game can create custom commands that will be parsed from statements beginning with $ (or whatever prefix is chosen).

A command is a function that takes in the ink-processor engine, the parameters parsed from the command string, and optionally the visualState of the current story. It can then do whatever it needs to the story, and returns a CommandReturn object, which determines whether the story should automatically advance after parsing the command.

For example:

import { Command } from '@a-morphous/frontispiece-ink-processor/src/data/command'

export const Pause: Command = (engine, params: string[] = []) => {
	const time = params.length ? parseFloat(params[0]) : 1
	if (time > 0) {
		setTimeout(() => {
			engine.advance()
		}, time * 1000)
	}

	return {
		interruptStoryFlow: true,
	}
}

After creating a command, you register it to make it operate.

engine.registerCommand('pause', Pause)

// now you can run the following lines in the Ink story:
// $pause // pause for 1 second (default)
// $pause 2 // pause for 2 seconds