@pantoken/flutter 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 +57 -0
- package/dist/index.d.mts +53 -0
- package/dist/index.mjs +87 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @pantoken/flutter
|
|
2
|
+
|
|
3
|
+
Emit Instructure design tokens as a Flutter (Dart) class, via Style Dictionary. It flattens the
|
|
4
|
+
token IR to concrete, single-mode values and keeps the natively-typed tokens (colours, dimensions,
|
|
5
|
+
numbers).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @pantoken/flutter
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { generateFlutter } from "@pantoken/flutter";
|
|
17
|
+
|
|
18
|
+
const file = await generateFlutter({
|
|
19
|
+
outDir: "./lib/tokens",
|
|
20
|
+
theme: "rebrand",
|
|
21
|
+
className: "PanTokens", // the generated Dart class name (default)
|
|
22
|
+
icons: ["add", "check"], // optional: also copy SVG assets + a PanTokensIcons manifest
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or via the CLI:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
pantoken generate flutter --out ./lib/tokens
|
|
30
|
+
pantoken generate flutter --out ./lib/tokens --theme canvas --icons add,check
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Output
|
|
34
|
+
|
|
35
|
+
- A single Dart file (named after `className`, lower-cased) declaring a class of `Color`, `double`,
|
|
36
|
+
and numeric constants.
|
|
37
|
+
- With `icons` set: the requested glyphs copied to `assets/pantoken/icons/*.svg` plus a
|
|
38
|
+
`pantoken_icons.dart` manifest (a `PanTokensIcons` class) for use with `flutter_svg`. Register the
|
|
39
|
+
asset directory in your `pubspec.yaml`.
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
- **`generateFlutter(options): Promise<string>`** — emit Dart for a named theme (from the vendored
|
|
44
|
+
`@pantoken/tokens` IR). Returns the written file path.
|
|
45
|
+
- **`toFlutter(tokens, options): Promise<string>`** — same, but for an explicit token IR. Returns
|
|
46
|
+
the written file path.
|
|
47
|
+
- **`GenerateFlutterOptions`** — the `outDir`, `theme`, `mode`, `className`, and `icons` options
|
|
48
|
+
both take.
|
|
49
|
+
|
|
50
|
+
## Related
|
|
51
|
+
|
|
52
|
+
- Uses `@pantoken/tokens` for the vendored token IR and `@pantoken/sd-config` for the Style
|
|
53
|
+
Dictionary platforms.
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Mode } from "@pantoken/core";
|
|
2
|
+
import { Theme, Token } from "@pantoken/model";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
/** Options for {@link generateFlutter} / {@link toFlutter}. */
|
|
6
|
+
interface GenerateFlutterOptions {
|
|
7
|
+
outDir: string;
|
|
8
|
+
theme?: Theme;
|
|
9
|
+
mode?: Mode;
|
|
10
|
+
/** The generated Dart class name (default `PanTokens`). */
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Icon names to also copy as SVG assets + a `PanTokensIcons` Dart manifest (for `flutter_svg`). */
|
|
13
|
+
icons?: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Emit Flutter Dart for an explicit token IR. Returns the written file path.
|
|
17
|
+
*
|
|
18
|
+
* @example Emit a specific theme's IR
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { toFlutter } from "@pantoken/flutter";
|
|
21
|
+
* import { byTheme } from "@pantoken/tokens";
|
|
22
|
+
*
|
|
23
|
+
* const file = await toFlutter(byTheme("canvas"), { outDir: "./lib/tokens" });
|
|
24
|
+
* // writes ./lib/tokens/pantokens.dart (class PanTokens { … })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example Dark mode with SVG icon assets and manifest
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { toFlutter } from "@pantoken/flutter";
|
|
30
|
+
* import { byTheme } from "@pantoken/tokens";
|
|
31
|
+
*
|
|
32
|
+
* await toFlutter(byTheme("rebrand"), {
|
|
33
|
+
* outDir: "./lib/tokens",
|
|
34
|
+
* mode: "dark",
|
|
35
|
+
* className: "InstUITokens",
|
|
36
|
+
* icons: ["add", "check"], // copies SVGs + writes pantoken_icons.dart
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function toFlutter(tokens: readonly Token[], options: GenerateFlutterOptions): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Emit Flutter Dart for a named theme. Returns the written file path.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { generateFlutter } from "@pantoken/flutter";
|
|
47
|
+
*
|
|
48
|
+
* const file = await generateFlutter({ outDir: "./lib/tokens", theme: "rebrand" });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare function generateFlutter(options: GenerateFlutterOptions): Promise<string>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { GenerateFlutterOptions, generateFlutter as default, generateFlutter, toFlutter };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { flutterIconManifest, getIconSvgs, toStyleDictionary } from "@pantoken/core";
|
|
4
|
+
import { buildPlatform } from "@pantoken/sd-config";
|
|
5
|
+
import { byTheme } from "@pantoken/tokens";
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* `@pantoken/flutter` — emit Instructure design tokens as Flutter (Dart), via Style Dictionary. It
|
|
9
|
+
* flattens the IR to concrete, single-mode values and keeps the natively-typed tokens.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
* @experimental
|
|
13
|
+
*/
|
|
14
|
+
const NATIVE_TYPES = /* @__PURE__ */ new Set([
|
|
15
|
+
"color",
|
|
16
|
+
"dimension",
|
|
17
|
+
"number"
|
|
18
|
+
]);
|
|
19
|
+
const ICON_ASSET_DIR = "assets/pantoken/icons";
|
|
20
|
+
/** Copy the requested icon SVGs under `assets/pantoken/icons` and write a Dart manifest. */
|
|
21
|
+
function writeFlutterIcons(tokens, names, outDir) {
|
|
22
|
+
const svgs = getIconSvgs(tokens);
|
|
23
|
+
const dir = join(outDir, ICON_ASSET_DIR);
|
|
24
|
+
mkdirSync(dir, { recursive: true });
|
|
25
|
+
const written = [];
|
|
26
|
+
for (const name of names) {
|
|
27
|
+
const svg = svgs.get(name);
|
|
28
|
+
if (!svg) continue;
|
|
29
|
+
writeFileSync(join(dir, `${name}.svg`), svg);
|
|
30
|
+
written.push(name);
|
|
31
|
+
}
|
|
32
|
+
writeFileSync(join(outDir, "pantoken_icons.dart"), flutterIconManifest(written, ICON_ASSET_DIR));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Emit Flutter Dart for an explicit token IR. Returns the written file path.
|
|
36
|
+
*
|
|
37
|
+
* @example Emit a specific theme's IR
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { toFlutter } from "@pantoken/flutter";
|
|
40
|
+
* import { byTheme } from "@pantoken/tokens";
|
|
41
|
+
*
|
|
42
|
+
* const file = await toFlutter(byTheme("canvas"), { outDir: "./lib/tokens" });
|
|
43
|
+
* // writes ./lib/tokens/pantokens.dart (class PanTokens { … })
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example Dark mode with SVG icon assets and manifest
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { toFlutter } from "@pantoken/flutter";
|
|
49
|
+
* import { byTheme } from "@pantoken/tokens";
|
|
50
|
+
*
|
|
51
|
+
* await toFlutter(byTheme("rebrand"), {
|
|
52
|
+
* outDir: "./lib/tokens",
|
|
53
|
+
* mode: "dark",
|
|
54
|
+
* className: "InstUITokens",
|
|
55
|
+
* icons: ["add", "check"], // copies SVGs + writes pantoken_icons.dart
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
async function toFlutter(tokens, options) {
|
|
60
|
+
const dictionary = toStyleDictionary(tokens, options.mode ?? "light");
|
|
61
|
+
const native = Object.fromEntries(Object.entries(dictionary).filter(([, leaf]) => NATIVE_TYPES.has(leaf.type)));
|
|
62
|
+
const className = options.className ?? "PanTokens";
|
|
63
|
+
const file = await buildPlatform({
|
|
64
|
+
dictionary: native,
|
|
65
|
+
platform: "flutter",
|
|
66
|
+
outDir: options.outDir,
|
|
67
|
+
className,
|
|
68
|
+
fileName: className.toLowerCase()
|
|
69
|
+
});
|
|
70
|
+
if (options.icons?.length) writeFlutterIcons(tokens, options.icons, options.outDir);
|
|
71
|
+
return file;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Emit Flutter Dart for a named theme. Returns the written file path.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { generateFlutter } from "@pantoken/flutter";
|
|
79
|
+
*
|
|
80
|
+
* const file = await generateFlutter({ outDir: "./lib/tokens", theme: "rebrand" });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
async function generateFlutter(options) {
|
|
84
|
+
return toFlutter(byTheme(options.theme ?? "rebrand"), options);
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { generateFlutter as default, generateFlutter, toFlutter };
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pantoken/flutter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Emit Instructure design tokens as Flutter (Dart) 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/core": "0.1.0",
|
|
19
|
+
"@pantoken/tokens": "0.1.0",
|
|
20
|
+
"@pantoken/model": "0.1.0",
|
|
21
|
+
"@pantoken/sd-config": "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
|
+
}
|