@metamorph-labs/polymorph-svelte
v1.0.19
Published
The Svelte foundation of the Polymorph design system, which a consumer installs: the engine re-exported, the icon gateway, the motion presence, the control ref, the toast store and the page-transition convention. Svelte members import this and nothing dee
Maintainers
Readme
@polymorph/svelte
The Svelte foundation. It re-exports @polymorph/engine whole and adds the
parts that exist only in Svelte 5: the icon gateway, the slot conventions, the machine-prop
spelling, the toast store, the page-transition convention and the states fixture's types. It is
the counterpart of @polymorph/react and @polymorph/vue.
The Svelte vocabulary, @polymorph/svelte-ui, is built on it, and an
application that vendors Svelte members installs it. A member imports this package and nothing
deeper.
It contains:
- The engine, whole. The root is
export * from '@polymorph/engine', plus the engine'scharts,markdownandqrsubpaths, so a member reaches every framework-free helper here. - The icon gateway:
Glyph, which draws a role's glyph fromsrc/icon/glyphs.ts;BrandMark, a third-party mark from the engine'sBRAND_DRAWINGS; and theIconmember, which@polymorph/svelte-uire-exports. - A machine's props in Svelte:
normalizeProps,attributes,mergeParts,chainHandlersandstyleText, over@zag-js/types. - The slot conventions:
joinSlot,SlotScope,SlotOutletandSlotText, through which a member reads what a caller put in a snippet and hands it props, andRender,bindSnippet,isBoundandPortal. Under Vite, a server render reads a slot throughsvelte/server(src/conventions/server.ts). - Effects and refs:
watchEffect,afterRender,refList,useDeparture,useControlRef,useMediaQueryandMEDIA_QUERIES. - The toast store (
toast,useToasts,getToasts,subscribeToasts,removeToast), the page-transition convention (PageTransition,PageTransitions,usePageTransitionPending) and the states fixture's types and holder (ComponentStates,StateEntry,Overrides,Held). - The presences (
@polymorph/svelte/motion):usePresence,useKeyedPresenceanduseListPresence, with the engine's motion environment, patterns and values re-exported by name. The subpath is for member internals, so it is not a root export.
src/icon/Icon.svelte, src/icon/glyphs.ts and src/icon/icon.module.css are generated by
pnpm shells; never edit them by hand. The rest of src/ is written by hand.
docs/shells.md describes every
export.
Entry points
Both entries publish under the svelte export condition, with types and default beside it:
| Import | In-repo (exports): types, svelte, default | Built (publishConfig.exports) |
| -------------------------- | ------------------------------------------------- | ----------------------------------------------------------------- |
| @polymorph/svelte | src/index.ts | types: dist/index.d.ts; svelte, default: dist/index.js |
| @polymorph/svelte/motion | src/motion/index.ts | types: dist/motion/index.d.ts; svelte, default: dist/motion/index.js |
Build
pnpm --filter @polymorph/svelte build runs node scripts/package.mjs ., which the vocabulary's
build runs too. A Svelte library ships its components as source, because the consumer's Svelte
compiles them for the browser and for a server render. So dist/ holds every component as it is,
each TypeScript module as JavaScript (a rune module as *.svelte.js), every stylesheet as it is,
every relative import fully specified, and the declarations from svelte2tsx. Icon's stylesheet
ships beside Icon.svelte, and the consumer's bundler compiles it. There is no node copy: Node
cannot load a component.
Dependencies and peers
| Peer | Range |
| -------- | --------- |
| svelte | ^5.46.4 |
Dependencies: @polymorph/engine (workspace:* here, published as an npm: alias of
@metamorph-labs/polymorph-engine) and @zag-js/types ^1.46.0.
The package is published as @metamorph-labs/polymorph-svelte and installed as
@polymorph/svelte through an npm alias
("@polymorph/svelte": "npm:@metamorph-labs/polymorph-svelte@^1.0.0").
docs/consuming.md has the application's side.
Tests
pnpm exec vitest run packages/svelte/packaging.test.ts # node: runs the real buildpackaging.test.ts runs in the logic project. It builds dist/ and checks that every export
target exists, every shipped file mirrors a source file, every relative import names a shipped
file, every component and rune module compiles for the browser and for a server render, the
presences stay on ./motion, every imported package is declared, and the declarations typecheck
under a strict consumer. The presences and the slot conventions have browser tests in the
vocabulary (packages/svelte-ui/src/conventions/presence.test.ts,
packages/svelte-ui/src/conventions/slotted.test.ts, the svelte project).
See docs/shells.md for how the members built on this package are generated, and docs/frameworks.md for how a React prop reads in Svelte.
