@metamorph-labs/polymorph-angular
v1.0.19
Published
The Angular foundation of the Polymorph design system, which a consumer installs: the engine re-exported, a Zag adapter driven by signals, the icon gateway, the presence and control-ref primitives, the slot conventions, the toast store and the page-transi
Maintainers
Readme
@polymorph/angular
The Angular foundation. It re-exports @polymorph/engine whole and adds the
parts that exist only in Angular: a Zag adapter driven by signals, the member's context, the slot
directives, the cells a member's scope is written in, the icon gateway, the toast store, the
page-transition convention and the states fixture's types. It is the counterpart of
@polymorph/react and @polymorph/vue. The Angular
vocabulary, @polymorph/angular-ui, is built on it, and an application
that vendors Angular 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.devWarningis the foundation's own: it readsngDevMode, because the Angular CLI does not defineprocess.env.NODE_ENVin the browser. - The Zag adapter (
src/zag/):useMachine, a machine whose context and state are signals;normalizePropsandmergeParts; and theSpreaddirective ([pmSpread]), which writes a machine's props onto an element. Zag ships no Angular binding, sosrc/zag/is one. - The member's context:
useMember,MemberContext,MEMBER_PROVIDERS,setupand the identity a member lends (lend,lentIdentity,ownerOf,provideOwner). - Slots and nodes:
SlotTemplate(pmSlot),SlotOutlet(pmSlotOutlet),Render(pmRender),Portal(pmPortal),bindTemplate,bindSlotandNodeTemplate. - Cells and effects:
cell,derived,measured,elementRef,elementList,Ref(pmRef),hostRef,useControlRef;mountEffect,watchEffect,watchMeasured,useDepartureanduseMediaQuery. - The icon gateway:
Glyph(svg[pmGlyph]),BrandMark(svg[pmBrandMark]) and theIconmember, which@polymorph/angular-uire-exports. - The toast store, the page-transition convention (
PageTransition,PageTransitions,usePageTransitionPending) and the states fixture's types and helpers (ComponentStates,StateEntry,Overrides,typeInto). - The presences (
@polymorph/angular/motion):usePresence,useKeyedPresenceanduseListPresence. The subpath is for member internals, so it is not a root export.
src/icon/Icon.ts, 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
| Import | In-repo (exports) | Built (publishConfig.exports) |
| --------------------------- | --------------------- | --------------------------------------------------------------------------------------- |
| @polymorph/angular | src/index.ts | types: dist/index.d.ts; default: dist/fesm2022/polymorph-angular.mjs |
| @polymorph/angular/motion | src/motion/index.ts | types: dist/motion/index.d.ts; default: dist/fesm2022/polymorph-angular-motion.mjs |
Each entry point is one flat ES module under dist/fesm2022/, as the Angular package format ships
one. A build that links only that format's flat modules, as Analog's Vite plugin does, links these,
and the Angular CLI links any. The package has no stylesheet export: the build compiles Icon's
stylesheet into the Icon component's styles, so no module imports a stylesheet and plain Node
loads every one.
Build
pnpm --filter @polymorph/angular build runs node scripts/package.mjs, the script the
vocabulary's build runs too. It stages the shipped source, compiles each CSS Module a component
imports into that component's styles, compiles with ngc in partial mode (with declarations),
writes every relative import fully specified, and bundles each entry point into its flat module,
every package import external. The application's Angular links the partial declarations to the
Angular it runs. The script reads @polymorph/engine from its built declarations
(packages/engine/dist/types), so the engine is built first; pnpm build:packages runs the builds
in that order.
Dependencies and peers
| Peer | Range |
| --------------- | --------- |
| @angular/core | ^22.0.0 |
Dependencies: @polymorph/engine (workspace:* here, published as an npm: alias of
@metamorph-labs/polymorph-engine), @zag-js/core, @zag-js/dom-query, @zag-js/types and
@zag-js/utils (each ^1.46.0), and tslib ^2.8.1.
The package is published as @metamorph-labs/polymorph-angular and installed as
@polymorph/angular through an npm alias
("@polymorph/angular": "npm:@metamorph-labs/polymorph-angular@^1.0.0").
docs/consuming.md has the application's side.
Tests
pnpm exec vitest run packages/angular/packaging.test.ts # node: runs the real build
pnpm exec vitest run packages/angular/src/zag/zag.test.ts # the adapter, in chromiumpackaging.test.ts runs in the logic project. It checks that every export target exists, each
entry point is one flat module and every shipped module keeps its declarations, every component is
a partial declaration, Icon's rules are in its component, every relative import names a shipped
file, the engine and Angular stay external and are declared, and the presences stay on ./motion.
src/zag/zag.test.ts runs in the angular project and holds the adapter to a checkbox, a dialog
and a menu in a browser.
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 Angular.
