Skip to content

About

Svelte 5 components for the Crossly embeddable storefront: catalog, buy button, Vault Markets widgets. Typed, SSR-safe.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@crossly/svelte

npm CI Svelte 5 types license

Svelte 5 components for the Crossly embeddable storefront. Put your Crossly listings, a buy button and Vault Markets price widgets on your own Svelte or SvelteKit site, with typed props and callback props.

They wrap the custom elements from @crossly/embed (<crossly-catalog>, <crossly-buy-button>, <crossly-index>, <crossly-mark>). Every prop, event and default below comes from that package's source.

  • SSR-safe. Nothing touches window at import. The elements are registered in onMount. No browser guards and no ssr = false.
  • One request per mount. Each element is created with all its attributes before it's connected.
  • No payments on your page. The buy button sends the buyer to a Crossly-hosted checkout.
  • Public key only. Uses a publishable key (crossly_pk_live_…). It is built to sit in page source.

Install

npm install @crossly/svelte
# pnpm add @crossly/svelte · yarn add @crossly/svelte · bun add @crossly/svelte

svelte 5 is a peer dependency. @crossly/embed is installed with this package (see Why @crossly/embed is a dependency).

Quick start

Mint a publishable key in Crossly → Settings → Embeds.

<!-- src/routes/+layout.svelte -->
<script lang="ts">
  import { CrosslyProvider } from '@crossly/svelte';
  import { PUBLIC_CROSSLY_PK } from '$env/static/public';
  let { children } = $props();
</script>

<CrosslyProvider pk={PUBLIC_CROSSLY_PK}>
  {@render children()}
</CrosslyProvider>
<!-- src/routes/+page.svelte -->
<script lang="ts">
  import { BuyButton, Catalog } from '@crossly/svelte';
</script>

<Catalog
  limit={24}
  onloaded={({ listings }) => console.log(`${listings.length} listings`)}
  onerror={({ message }) => console.warn(message)}
>
  {#snippet fallback()}<p>Loading the shop…</p>{/snippet}
</Catalog>

<BuyButton listing="lst_123" label="Buy now" />

More in examples/sveltekit.

Components

Every component accepts:

prop type
pk string Your publishable key. Required here, on <CrosslyProvider>, or through setCrosslyConfig(). The prop wins. Without it the element shows "Missing pk".
api string Overrides the API base (default https://crossly.net/api). For testing.
class, style, id string Set on the custom element. style="--crossly-accent: #ff5a5f" works.
fallback Snippet Rendered on the server and until the elements are registered.
onerror (detail: { message: string }, event: CustomEvent) => void crossly:error: the API rejected the request, or the embed script failed to load.

Callbacks get the event's detail first and the raw CustomEvent second.

<Catalog> (<crossly-catalog>)

Your active listings as a responsive grid. Sold items show "Sold" in place of a price.

prop type default
limit number 12 How many to show, 1–48.
q string Free-text filter over title and brand. See Known limitations.
onloaded (detail: { listings: EmbedListing[] }, event) => void crossly:loaded: the listings that were rendered. Not fired for an empty catalog (the element shows "Nothing listed right now.").

EmbedListing is { id, title, description, priceCents, imageUrl, brand, size, condition, available }. Money is always integer cents.

<BuyButton> (<crossly-buy-button>)

Starts a checkout. It POSTs { items: [{ listingId, quantity }], returnUrl: location.href } and sends the buyer to the returned Crossly-hosted URL.

prop type default
listing string Required. The listing id. The button is disabled without it.
quantity number 1 Units (the API accepts 1–10).
label string "Buy now" Button text. Shows "Starting checkout…" while the request runs.
target '_self' | '_blank' | string '_self' _self navigates this tab. Any other value goes to window.open(url, target, 'noopener,noreferrer').
oncheckout (detail: { checkoutUrl: string }, event) => void crossly:checkout: the checkout URL was issued, just before navigation.

<PriceIndex> (<crossly-index>)

A Crossly Vault Markets index level, its move, a sparkline, and what it rests on (quality letter, n markets, as-of date). Shows Insufficient data when the data is too thin.

prop type default
slug string Required. The index slug, e.g. crossly-50.
range '1m' | '3m' | '6m' | '1y' | '5y' '1y' Sparkline history.
onloaded (detail: { index: EmbedIndexWidget }, event) => void crossly:loaded.

<PriceMark> (<crossly-mark>)

One vault market's mark, with its quality letter, trades in the last 30 days and as-of date. Shows No market yet when there isn't one.

prop type default
bookKey string Required. The market's book key, <variantId>:<condition>:<grade>. Set as the element's key attribute.
range '1m' | '3m' | '6m' | '1y' | '5y' '1y' Sparkline history.
onloaded (detail: { mark: EmbedMarkWidget }, event) => void crossly:loaded.

Context and helpers

export
<CrosslyProvider pk api> Sets the default pk / api for its children. It stays reactive when its props change.
setCrosslyConfig(config) / getCrosslyConfig() The same, as context functions. Call them during component init. Use getters or $state for live values.
loadCrosslyElements() Registers the four elements. Browser only (rejects on a server). Shared and idempotent.
isCrosslyDefined() true once all four tags are registered, by this package or by the hosted embed.js.
mountCrosslyElement(options) The primitive the components use: create an element with complete attributes, then connect it. Returns a cleanup function.
types EmbedListing, EmbedIndexWidget, EmbedMarkWidget, CrosslyRange, CatalogLoadedDetail, CheckoutDetail, IndexLoadedDetail, MarkLoadedDetail, ErrorDetail, CrosslyEventMap, CrosslyConfig.

Each component renders the element inside a <div style="display: contents">, so it adds no box to your layout.

Theming

The elements use Shadow DOM, so your CSS can't break their layout. They expose CSS custom properties and ::parts. Set the variables on the element (class/style props, or a global selector), not on a parent: each element declares its own defaults on :host, and those override inherited values. Svelte's scoped styles don't reach the element, which is created at runtime, so use :global(...):

<Catalog class="shop" />

<style>
  :global(crossly-catalog.shop) {
    --crossly-accent: #ff5a5f;
    --crossly-min-col: 260px;
  }
  :global(crossly-catalog.shop::part(card)) {
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.08);
  }
</style>
variable default (light) dark (prefers-color-scheme)
--crossly-gap 16px
--crossly-radius 10px
--crossly-fg #111 #f3f4f6
--crossly-muted #666 #9ca3af
--crossly-accent #10b981
--crossly-card-bg #fff #111827
--crossly-border #e5e7eb #374151
--crossly-min-col 200px
element parts
crossly-catalog grid, card, image, title, meta, price
crossly-buy-button button
crossly-index, crossly-mark widget, title, value, change (index), image (mark), sparkline, meta

SSR (SvelteKit)

  • @crossly/embed declares class … extends HTMLElement at module scope, so importing it on a server throws. This package never imports it statically.
  • On the server, each component renders its fallback snippet (CI checks this with svelte/server). In the browser, onMount runs one shared dynamic import('@crossly/embed'). Then the component creates the element with every attribute set and connects it.
  • If your page already loads https://crossly.net/embed.js, that's fine. Registration is guarded.

Known limitations

These come from @crossly/embed 0.1.0 and the live API. The wrapper does not hide them:

  • crossly:checkout can't be cancelled yet. The event is dispatched as cancelable, but 0.1.0 navigates even if you call preventDefault().
  • q (text search). For a fresh search (q of 2+ characters), the API requires a proof-of-work header. The 0.1.0 element doesn't send one, so a q search surfaces through onerror.
  • Origin allowlist. If your key has an allowlist (Settings → Embeds), the page origin must be on it. That covers both the requests and the checkout returnUrl, which is always the current page.

Why @crossly/embed is a dependency

It's a regular dependency, not a peer. These components are a typed facade over one exact contract (attribute names, event names, detail shapes), so this package states which embed range it was written against and installs it with itself. If your page also loads the hosted embed.js, nothing breaks.

Compatibility

Svelte 5 (runes). CI runs the latest 5.x.
SvelteKit any version on Svelte 5
Browsers anything with Custom Elements v1 and Shadow DOM

Links

License

MIT

About

Svelte 5 components for the Crossly embeddable storefront: catalog, buy button, Vault Markets widgets. Typed, SSR-safe.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages