@pantoken/swift
v0.1.28
Published
Emit Instructure design tokens as Swift, via Style Dictionary. The native proof for pantoken.
Downloads
710
Readme
@pantoken/swift
Emit Instructure design tokens as Swift, via Style Dictionary. This is pantoken's native proof: it
flattens the token IR to concrete, single-mode values, keeps the natively-typed tokens (colours,
dimensions, numbers), and hands them to @pantoken/sd-config.
Install
npm i @pantoken/swiftUsage
import { generateSwift } from "@pantoken/swift";
const file = await generateSwift({
outDir: "./Sources/Tokens",
theme: "rebrand",
className: "PanTokens", // the generated Swift class name (default)
icons: ["add", "check"], // optional: also emit an Icons.xcassets asset catalog
});
// writes Tokens.swift (class PanTokens { … })Or via the CLI:
pantoken generate swift --out ./MyTokensOutput
- A Swift file declaring a class (named after
className) ofColor,CGFloat, and numeric constants. - With
iconsset: anIcons.xcassetsasset catalog of vector-preserving imagesets for the requested glyphs.
The CLI wraps the same output in a Swift Package: it writes the source under
<out>/Sources/<className>/ and a Package.swift SwiftPM manifest stub at <out>/, so the
directory is publishable to SwiftPM as-is. This emitter uses UIKit and targets iOS, not macOS.
Swapping the platform (Flutter, Compose) reuses the same path through @pantoken/sd-config.
For repository contributors, mise run verify:swift:syntax parses a disposable generated package
with Command Line Tools. mise run verify:swift:host typechecks it against the iOS Simulator SDK;
mise run verify:swift:runtime builds and launches a disposable iOS app and compiles the optional
asset catalog. To generate a package in a chosen location, set SWIFT_PACKAGE_OUT and run
mise run scaffold:swift.
Compatibility
The generated UIKit app was built and run with Xcode 27.0 (Swift 6.4) on an iPhone 18 Pro iOS 27.0
Simulator, using an arm64 iOS 15 deployment target. The runtime check verifies a generated brand
color and compiles/loads the optional Icons.xcassets catalog. This does not establish an iOS 15
runtime floor; only iOS 27.0 was run. watchOS and tvOS aren't verified. See the
compatibility matrix for the tested environment.
API
generateSwift(options): Promise<string>— emit Swift for a named theme (from the vendored@pantoken/tokensIR). Returns the written file path.toSwift(tokens, options): Promise<string>— same, but for an explicit token IR. Returns the written file path.GenerateSwiftOptions— theoutDir,theme,mode,className, andiconsoptions both take.
Related
- Uses
@pantoken/tokensfor the vendored token IR and@pantoken/sd-configfor the Style Dictionary platforms. - Pairs with
@pantoken/composeand@pantoken/flutter, the same shape for other native targets.
License
MIT
