# @viamrobotics/prime-core

> `@viamrobotics/prime-core` is a collection of core Svelte components.

Latest version **0.1.23** (published 2026-07-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @viamrobotics/prime-core
pnpm add @viamrobotics/prime-core
yarn add @viamrobotics/prime-core
bun add @viamrobotics/prime-core
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.23 |
| Published | 2026-07-21 |
| First published | 2023-07-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 20 |
| Unpacked size | 1.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | cheukt, stevebriskin, viambot, micheal.parks, mpviam, njooma, devin-viam, ale7714, amaschas |

## Links

- npm: https://www.npmjs.com/package/@viamrobotics/prime-core
- npm.io page: https://npm.io/package/@viamrobotics/prime-core

## Dependencies (20)

- [nanoid](https://npm.io/package/nanoid.md) ^5.1.0
- [@mdi/js](https://npm.io/package/@mdi/js.md) ^7.3.67
- [lodash-es](https://npm.io/package/lodash-es.md) ^4.18.0
- [codemirror](https://npm.io/package/codemirror.md) 6.0.1
- [highlight.js](https://npm.io/package/highlight.js.md) 11.11.1
- [@zag-js/svelte](https://npm.io/package/@zag-js/svelte.md) 1.40.0
- [@codemirror/view](https://npm.io/package/@codemirror/view.md) 6.43.1
- [@floating-ui/dom](https://npm.io/package/@floating-ui/dom.md) 1.5.3
- [codemirror-json5](https://npm.io/package/codemirror-json5.md) 1.0.3
- [@codemirror/merge](https://npm.io/package/@codemirror/merge.md) 6.11.2
- [@codemirror/state](https://npm.io/package/@codemirror/state.md) 6.6.0
- [@codemirror/lang-go](https://npm.io/package/@codemirror/lang-go.md) 6.0.1
- [@zag-js/collapsible](https://npm.io/package/@zag-js/collapsible.md) 1.40.0
- [@zag-js/date-picker](https://npm.io/package/@zag-js/date-picker.md) 1.40.0
- [@codemirror/commands](https://npm.io/package/@codemirror/commands.md) 6.3.0
- [@codemirror/lang-sql](https://npm.io/package/@codemirror/lang-sql.md) 6.10.0
- [@codemirror/language](https://npm.io/package/@codemirror/language.md) 6.12.3
- [@codemirror/lang-json](https://npm.io/package/@codemirror/lang-json.md) 6.0.2
- [@codemirror/lang-python](https://npm.io/package/@codemirror/lang-python.md) 6.2.1
- [@viamrobotics/tailwind-config](https://npm.io/package/@viamrobotics/tailwind-config.md) ^1.1.0

## Recent versions

- 0.1.23 (latest) — 2026-07-21
- 0.1.22 — 2026-05-19
- 0.1.21 — 2026-05-04
- 0.1.20 — 2026-05-04
- 0.1.19 — 2026-04-28
- 0.1.18 — 2026-04-23
- 0.1.17 — 2026-04-17
- 0.1.16 — 2026-03-19
- 0.1.15 — 2026-03-16
- 0.1.14 — 2026-02-23
- 0.1.13 — 2026-01-15
- 0.1.12 — 2025-12-31
- 0.1.11 — 2025-12-17
- 0.1.10 — 2025-12-05
- 0.1.9 — 2025-11-11
- … 188 more at https://npm.io/package/@viamrobotics/prime-core/versions

## README

# `@viamrobotics/prime-core`

## Getting started

`@viamrobotics/prime-core` is a collection of core Svelte components.

## Installation

Add PRIME core using your package manager of choice:

```
pnpm add --save-dev @viamrobotics/prime-core
```

Install [Tailwind][]. In the `tailwind.config.js`, add the components to the content and include the theme:

```js
import { theme } from '@viamrobotics/prime-core/theme';
import { plugins } from '@viamrobotics/prime-core/plugins';

/** @type {import('tailwindcss').Config} */
export default {
  content: [
    './src/**/*.{html,js,svelte,ts}',
    './node_modules/@viamrobotics/prime-core/**/*.{ts,svelte}',
  ],
  theme,
  plugins,
};
```

Import the stylesheet. If you are using [SvelteKit][], you can do this in `src/routes/+layout.svelte`.

```js
import '@viamrobotics/prime-core/prime.css';
```

## Usage

Once installed, you can use the components in your app:

```html
<script lang="ts">
  import { Badge } from '@viamrobotics/prime-core';
</script>

<Badge
  variant="green"
  label="Active"
/>
```

[tailwind]: https://tailwindcss.com/
[sveltekit]: https://kit.svelte.dev/

### Testing components that use Prime

All Prime components have their own test suites, so in your application tests, you generally only need to test that the component itself is rendered rather than try to test that all the behaviors work - we've already written those tests.

#### Testing toasts

The `useToast` hook requires a Svelte context to render. In order to test a component that issues toasts, you can use the `createNoopToastContext` fixture. Before using this fixture, consider if you can re-structure your components to avoid the need for testing a component wired to `useToast` directly.

```ts
import { describe, expect, test, vi } from 'vitest';
import { render } from '@testing-library/svelte';

import { createNoopToastContext } from '@viamrobotics/prime-core/__fixtures__';

import Subject from '../cool-component.svelte';

const toast = vi.fn();

const renderSubject = () => {
  const toastContext = createNoopToastContext(toast);
  return render(Subject, {
    props: { message: 'hello' },
    context: new Map([toastContext]),
  });
};

describe('<CoolComponent>', () => {
  it('toasts `message` on mount', () => {
    renderSubject();
    expect(toast).toHaveBeenCalledWith({ message: 'hello' });
  });
});
```

## Playground

The playground can be used during development but is not used outside of the package.

```bash
pnpm install
pnpm -C packages/core dev
```

## Linting

To lint and typecheck:

```bash
pnpm -C packages/core check        # check svelte and lint
pnpm -C packages/core check-svelte # check svelte only
pnpm -C packages/core check-lint   # check lint only with prettier and eslint
pnpm -C packages/core format       # format with prettier
```

## Testing

To test with [vitest][]:

```bash
pnpm -C packages/core test        # run once
pnpm -C packages/core test:watch  # watch tests
```

[vitest]: https://vitest.dev/

## Anatomy of a Component

For easier readability, we try to use a standard ordering for component composition. These are not strict rules, but more a guideline to follow. Implementation specifics may force you to go outside this guideline.

```html
<!-- svelte options: https://svelte.dev/docs/special-elements#svelte-options -->
<svelte:options immutable />

<script
  lang="ts"
  context="module"
>
  // exported types
  export type MyType = 'thing' | 'other-thing';
</script>

<script lang="ts">
  // external imports
  import { onMount, createEventDispatcher } from 'svelte';

  // internal imports
  import { someLibraryFunction } from '../parent';
  import { someSiblingFunction } from './sibling';

  // prop declarations
  /** A doc string for prop explaining what it does. */
  export let prop: MyType | undefined = undefined;

  // event dispatchers and other hooks
  const dispatcher = createEventDispatcher<{
    /** A doc string for the event handler. */
    click: null; // void event
    /** A doc string for the event handler. */
    primitive: string | number | boolean; // simple primitive values
    /** A doc string for the event handler. */
    object: { id: string; next: number; }; // complex values
    /** A doc string for the event handler. */
    native: Event // native events (for pure atoms)
  }>()

  // internal fields
  let someString = '';

  // reactive variables
  $: isThing = prop === 'thing';

  // complex reactive variables
  let counter = 0;
  $: if (isThing) {
      counter = someString.length;
      if (counter > 10) {
        counter = 10;
      }
  }

  // single-line functions
  const doSomething = () => someLibraryFunction();

  // multi-line functions
  const doSomethingElse = () => {
    const shouldDoSomething = someString !== '';
    someSiblingFunction(shouldDoSomething);
  }

  // reactive statements
  $: {
    someString = prop ? 'whoa' : 'no';
  }

  // lifecycle hooks
  onMount(() => ...);
</script>

<!-- Your layout -->
<div class="border-black">
  <!--
    all slots should be named if there are multiple; otherwise a single slot
    can be the default `<slot />`
  -->
  <slot name="title" />
  <slot name="content" />
</div>

<style>
  /* custom styles */
</style>
```

## Tests and Test Components

We keep tests in a `__tests__` directory that is a sibling of the code being tested. These directories should only contain tests and test components.

Some components require test components to render slotted children, due to limitations with rendering slots using `@testing-library`.

See:

- https://sveltesociety.dev/recipes/testing-and-debugging/unit-testing-svelte-component
- https://github.com/testing-library/svelte-testing-library/issues/48

---
_Source: https://npm.io/package/@viamrobotics/prime-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
