total quantity across all lines.
Σ qty·priceCents — the cart subtotal in cents (pre-discount, pre-tax).
the lines as an array, in insertion order — the canonical render source.
the line for a product (+ optional variant), or undefined.
OptionalvariantId: string | numberadd item.qty of a product/variant (merges onto an existing line by product+variant; refreshes name/price/image).
set a line's quantity; qty <= 0 removes the line. Pass variantId to target a specific variant line.
OptionalvariantId: string | numberremove a line entirely (optionally a specific variant line).
OptionalvariantId: string | numberempty the cart.
re-read from storage (auto-invoked on the storage/change events; exposed for manual refresh).
detach the sync listeners (for teardown/tests).
lines keyed by an OPAQUE prefixed id — subscribe for reactive UI, but render from
lines()(insertion order) and look lines up withget(productId). (Keys are prefixed so the JS engine preserves insertion order even for numeric product ids, which it would otherwise hoist ahead of string ids.)