Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@uwdata/mosaic-spec

Package Overview
Dependencies
Maintainers
3
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uwdata/mosaic-spec

Declarative specification of Mosaic-powered applications.

latest
Source
npmnpm
Version
0.26.0
Version published
Weekly downloads
8.7K
24.47%
Maintainers
3
Weekly downloads
 
Created
Source

mosaic-spec

npm version

Declarative specification of Mosaic-powered applications as JSON or YAML files. This package provides a parser and code generation framework for reading specifications in a JSON format and generating live Mosaic visualizations and dashboards using the vgplot API.

Usage

To parse a specification and generate round-trip JSON output (.toJSON()), JavaScript module code (astToESM), or a live web application (astToDOM):

import { parseSpec, astToDOM, astToESM } from '@uwdata/mosaic-spec';

// declarative specification in JSON format
const spec = {
  plot: [
    {
      mark: 'lineY',
      data: { from: 'table' },
      x: 'date',
      y: 'value'
    }
  ],
  width: 640,
  height: 200
};

// parse specification to internal AST (abstract syntax tree)
const ast = parseSpec(spec);

// serialize back to a normalized JSON format
const json = ast.toJSON();

// generate ESM (ECMAScript Module) code
const code = astToESM(ast);

// instantiate a running application
// assumes standard browser facilities in globabl variable `window`
const {
  element, // root DOM element of the application
  params   // Map of all named Params and Selections
} = await astToDOM(ast);

// add application to current web page
document.body.appendChild(element);

To parse specifications in YAML format, import the yaml library and use it to parse input specification files:

import { parseSpec } from '@uwdata/mosaic-spec';
import { parse } from 'yaml';

const yaml = /* load yaml file file */;
const spec = parse(yaml); // parse yaml to JS objects

// parse specification to internal AST (abstract syntax tree)
const ast = parseSpec(spec);

Visual Tests

Visual tests use Playwright to render each JSON spec and compare screenshots against stored snapshots. Snapshots must be generated inside a Docker container that matches CI so they are pixel-identical across machines.

Run tests (compare against existing snapshots):

bin/visual-test.sh

Update snapshots:

bin/visual-test.sh --update

The script uses Docker by default. On macOS you can use the lightweight Container runtime instead:

brew install --cask container
container system start
CONTAINER_RUNTIME=container bin/visual-test.sh --update
container system stop

Alternatively, you can download updated snapshots from the playwright-test-results artifact uploaded by the browser CI job.

Keywords

mosaic

FAQs

Package last updated on 14 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