npm.io
2.1.7 • Published 6d ago

@master/css-server

Licence
MIT
Version
2.1.7
Deps
0
Vulns
0
Weekly
0
Stars
2.0K

Master CSS

Server-side HTML renderer for Master CSS

GitHub release NPM package ( download / month ) Follow @mastercorg GitHub release workflow

Installation

npm install @master/css-server

@master/css-server owns HTML parsing and style/hydration injection. Every entry requires an explicit MasterCSSManifest; class-only rendering belongs to @master/css/node.

Use this package for the HTML step of the prerender and progressive rendering modes. Both generate CSS from the rendered page. For prerender, pass hydrationManifest: false. For progressive, deliver the hydration manifest so the browser runtime can reuse the page CSS and generate rules for later classes.

API

renderHTML()

The one-shot API owns and releases its render session. Its result is an immutable snapshot and does not expose DOM nodes, bindings, or disposable CSS state.

import { renderHTML } from '@master/css-server'

const result = renderHTML('<div class="text-center"></div>', {
  manifest,
  hydrationManifest: 'inline'
})

console.log(result.html)
console.log(result.cssText)
console.log(result.classNames)
console.log(result.diagnostics)
createServerRenderer()

Create a manifest-scoped renderer when one process renders multiple documents. Generated rules are cached across calls while every call returns an independent snapshot.

import { createServerRenderer } from '@master/css-server'

const renderer = createServerRenderer({ manifest })
const first = renderer.renderHTML('<div class="text-center"></div>')
const second = renderer.renderHTML('<div class="fg-red"></div>')

renderer.dispose()

Long-lived renderers cache up to 8192 unique classes before starting a new cache generation. Finite build jobs can pass { maxCachedClasses: Infinity } and dispose the renderer when the build ends. Recreate the renderer whenever its manifest changes.

createHTMLRenderSession()

Use one session per streaming document. write() accepts successive chunks and end() returns the final transformed chunk plus the complete immutable snapshot. The session owns its renderer and releases it after end(), failure, or dispose().

import { createHTMLRenderSession } from '@master/css-server'

const session = createHTMLRenderSession({ manifest })
const firstChunk = session.write('<html><head>')
const final = session.end('</head><body class="block"></body></html>')

Use official framework integrations when possible; they compose this package with manifest loading, source scanning, and runtime hydration.

Keywords