@pantoken/compose 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # @pantoken/compose
2
+
3
+ Emit Instructure design tokens as a Jetpack Compose (Kotlin) object, via Style Dictionary. It's the
4
+ modern Android counterpart to `@pantoken/android`'s resource XML: it flattens the token IR to
5
+ concrete, single-mode values and keeps the natively-typed tokens (colours, dimensions, numbers).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm i @pantoken/compose
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { generateCompose } from "@pantoken/compose";
17
+
18
+ const file = await generateCompose({
19
+ outDir: "./app/src/main/kotlin",
20
+ theme: "rebrand",
21
+ className: "PanTokens", // the generated Kotlin object name (default)
22
+ });
23
+ ```
24
+
25
+ Or via the CLI:
26
+
27
+ ```sh
28
+ pantoken generate compose --out ./app/src/main/kotlin
29
+ pantoken generate compose --out ./app/src/main/kotlin --theme canvas --class BrandTokens
30
+ ```
31
+
32
+ ## Output
33
+
34
+ A single Kotlin file (named after `className`) declaring a Compose object of `Color`, `Dp`, and
35
+ numeric constants. Reference them straight from composables. Use this for Compose UIs; for the
36
+ Android View-system (XML) resources, use `@pantoken/android`.
37
+
38
+ ## API
39
+
40
+ - **`generateCompose(options): Promise<string>`** — emit Kotlin for a named theme (from the vendored
41
+ `@pantoken/tokens` IR). Returns the written file path.
42
+ - **`toCompose(tokens, options): Promise<string>`** — same, but for an explicit token IR. Returns
43
+ the written file path.
44
+ - **`GenerateComposeOptions`** — the `outDir`, `theme`, `mode`, and `className` options both take.
45
+
46
+ ## Related
47
+
48
+ - Pairs with `@pantoken/android` for the Android View-system (XML) counterpart.
49
+ - Uses `@pantoken/tokens` for the vendored token IR and `@pantoken/sd-config` for the Style
50
+ Dictionary platforms.
51
+
52
+ ## License
53
+
54
+ MIT
@@ -0,0 +1,50 @@
1
+ import { Mode } from "@pantoken/core";
2
+ import { Theme, Token } from "@pantoken/model";
3
+
4
+ //#region src/index.d.ts
5
+ /** Options for {@link generateCompose} / {@link toCompose}. */
6
+ interface GenerateComposeOptions {
7
+ outDir: string;
8
+ theme?: Theme;
9
+ mode?: Mode;
10
+ /** The generated Kotlin object name (default `PanTokens`). */
11
+ className?: string;
12
+ }
13
+ /**
14
+ * Emit Compose Kotlin for an explicit token IR. Returns the written file path.
15
+ *
16
+ * @example Emit a specific theme's IR
17
+ * ```ts
18
+ * import { toCompose } from "@pantoken/compose";
19
+ * import { byTheme } from "@pantoken/tokens";
20
+ *
21
+ * const file = await toCompose(byTheme("canvas"), { outDir: "./ui/tokens" });
22
+ * // writes ./ui/tokens/PanTokens.kt (object PanTokens { … })
23
+ * ```
24
+ *
25
+ * @example Dark mode with a custom object name
26
+ * ```ts
27
+ * import { toCompose } from "@pantoken/compose";
28
+ * import { byTheme } from "@pantoken/tokens";
29
+ *
30
+ * await toCompose(byTheme("rebrand"), {
31
+ * outDir: "./ui/tokens",
32
+ * mode: "dark",
33
+ * className: "InstUITokens", // writes InstUITokens.kt
34
+ * });
35
+ * ```
36
+ */
37
+ declare function toCompose(tokens: readonly Token[], options: GenerateComposeOptions): Promise<string>;
38
+ /**
39
+ * Emit Compose Kotlin for a named theme. Returns the written file path.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { generateCompose } from "@pantoken/compose";
44
+ *
45
+ * const file = await generateCompose({ outDir: "./ui/tokens", theme: "rebrand" });
46
+ * ```
47
+ */
48
+ declare function generateCompose(options: GenerateComposeOptions): Promise<string>;
49
+ //#endregion
50
+ export { GenerateComposeOptions, generateCompose as default, generateCompose, toCompose };
package/dist/index.mjs ADDED
@@ -0,0 +1,68 @@
1
+ import { toStyleDictionary } from "@pantoken/core";
2
+ import { buildPlatform } from "@pantoken/sd-config";
3
+ import { byTheme } from "@pantoken/tokens";
4
+ //#region src/index.ts
5
+ /**
6
+ * `@pantoken/compose` — emit Instructure design tokens as Jetpack Compose (Kotlin), via Style
7
+ * Dictionary. It flattens the IR to concrete, single-mode values and keeps the natively-typed
8
+ * tokens (colours, dimensions, numbers).
9
+ *
10
+ * @module
11
+ * @experimental
12
+ */
13
+ const NATIVE_TYPES = /* @__PURE__ */ new Set([
14
+ "color",
15
+ "dimension",
16
+ "number"
17
+ ]);
18
+ /**
19
+ * Emit Compose Kotlin for an explicit token IR. Returns the written file path.
20
+ *
21
+ * @example Emit a specific theme's IR
22
+ * ```ts
23
+ * import { toCompose } from "@pantoken/compose";
24
+ * import { byTheme } from "@pantoken/tokens";
25
+ *
26
+ * const file = await toCompose(byTheme("canvas"), { outDir: "./ui/tokens" });
27
+ * // writes ./ui/tokens/PanTokens.kt (object PanTokens { … })
28
+ * ```
29
+ *
30
+ * @example Dark mode with a custom object name
31
+ * ```ts
32
+ * import { toCompose } from "@pantoken/compose";
33
+ * import { byTheme } from "@pantoken/tokens";
34
+ *
35
+ * await toCompose(byTheme("rebrand"), {
36
+ * outDir: "./ui/tokens",
37
+ * mode: "dark",
38
+ * className: "InstUITokens", // writes InstUITokens.kt
39
+ * });
40
+ * ```
41
+ */
42
+ async function toCompose(tokens, options) {
43
+ const dictionary = toStyleDictionary(tokens, options.mode ?? "light");
44
+ const native = Object.fromEntries(Object.entries(dictionary).filter(([, leaf]) => NATIVE_TYPES.has(leaf.type)));
45
+ const className = options.className ?? "PanTokens";
46
+ return buildPlatform({
47
+ dictionary: native,
48
+ platform: "compose",
49
+ outDir: options.outDir,
50
+ className,
51
+ fileName: className
52
+ });
53
+ }
54
+ /**
55
+ * Emit Compose Kotlin for a named theme. Returns the written file path.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { generateCompose } from "@pantoken/compose";
60
+ *
61
+ * const file = await generateCompose({ outDir: "./ui/tokens", theme: "rebrand" });
62
+ * ```
63
+ */
64
+ async function generateCompose(options) {
65
+ return toCompose(byTheme(options.theme ?? "rebrand"), options);
66
+ }
67
+ //#endregion
68
+ export { generateCompose as default, generateCompose, toCompose };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@pantoken/compose",
3
+ "version": "0.1.0",
4
+ "description": "Emit Instructure design tokens as Jetpack Compose (Kotlin) via Style Dictionary.",
5
+ "license": "MIT",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "type": "module",
10
+ "exports": {
11
+ ".": "./dist/index.mjs",
12
+ "./package.json": "./package.json"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "dependencies": {
18
+ "@pantoken/model": "0.1.0",
19
+ "@pantoken/tokens": "0.1.0",
20
+ "@pantoken/sd-config": "0.1.0",
21
+ "@pantoken/core": "0.1.0"
22
+ },
23
+ "devDependencies": {
24
+ "@types/node": "^24.13.3",
25
+ "typescript": "^6.0.3",
26
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
27
+ "vite-plus": "0.2.4"
28
+ },
29
+ "scripts": {
30
+ "build": "vp pack",
31
+ "dev": "vp pack --watch",
32
+ "test": "vp test",
33
+ "check": "vp check"
34
+ }
35
+ }