🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

markstream-core

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markstream-core

Framework-agnostic smooth streaming controller and streaming text state utilities for Markstream

Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

markstream-core

Framework-agnostic smooth streaming controller and streaming text state utilities for Markstream.

This package extracts the core pacing algorithm and streaming text resolution logic shared across all Markstream framework packages (Vue 3, Vue 2, React, Angular, Svelte).

Installation

npm install markstream-core

API

createSmoothMarkdownStream

Factory API for a framework-agnostic streaming controller with snapshot + subscribe semantics.

import { createSmoothMarkdownStream } from 'markstream-core'

const controller = createSmoothMarkdownStream({ minCharsPerSecond: 40, maxCharsPerSecond: 1000 })

const unsubscribe = controller.subscribe(() => {
  const snapshot = controller.getSnapshot()
  updateUI(snapshot.visible)
  if (snapshot.final)
    onStreamDone()
})

controller.enqueue(chunk)
controller.finish()
controller.flush()
controller.pause()
controller.resume()
controller.destroy()
controller.dispose() // alias of destroy()
unsubscribe()

SmoothMarkdownStreamController is the public controller interface type returned by createSmoothMarkdownStream.

Options (SmoothMarkdownStreamOptions)

OptionDefaultDescription
minCharsPerSecond40Minimum reveal speed
maxCharsPerSecond1000Maximum reveal speed
targetLatencyMs900Target latency for pacing calculation
catchUpLatencyMs350Latency threshold for catch-up mode
catchUpThreshold600Character backlog that triggers catch-up
maxCommitFps30Maximum commits per second
startDelayMs80Delay before first reveal
maxCharsPerCommit80Maximum characters per animation frame
flushOnFinishfalseAuto-flush when finish() is called

resolveStreamingTextState

Resolves the next streaming text state for simple append detection.

import { resolveStreamingTextState } from 'markstream-core'

const result = resolveStreamingTextState({
  nextContent: 'hello world',
  previousContent: 'hello',
  typewriterEnabled: true,
})
// result = { settledContent: 'hello', streamedDelta: ' world', appended: true }

resolveStreamingTextUpdate

Extended resolver that handles React StrictMode replay guards and stream version resets.

import { resolveStreamingTextUpdate } from 'markstream-core'

const result = resolveStreamingTextUpdate({
  nextContent: 'hello world!',
  currentState: { settledContent: 'hello', streamedDelta: ' world' },
  typewriterEnabled: true,
})

Framework Adapters

  • Vue 3: useSmoothMarkdownStream in markstream-vue wraps the core controller with Vue reactivity.
  • React / Vue 2 / Angular / Svelte: Framework packages depend on markstream-core internally. Import core APIs directly from markstream-core when needed.

License

MIT

Keywords

streaming

FAQs

Package last updated on 16 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts