@pantoken/scss 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 +50 -0
- package/dist/index.d.mts +49 -0
- package/dist/index.mjs +67 -0
- package/generated/tokens.scss +2812 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @pantoken/scss
|
|
2
|
+
|
|
3
|
+
Instructure design tokens as SCSS variables, resolved to concrete single-mode values from the
|
|
4
|
+
pantoken IR — a self-contained SCSS token file (`$instui-color-brand: #0374b5;`). Icon tokens are
|
|
5
|
+
skipped; they belong in CSS.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @pantoken/scss
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Also available as `pantoken/scss`.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { toScss, scss } from "@pantoken/scss";
|
|
19
|
+
import { byTheme } from "@pantoken/tokens";
|
|
20
|
+
|
|
21
|
+
scss; // the ready-made rebrand variables
|
|
22
|
+
toScss(byTheme("canvas"), { mode: "dark" }); // convert any IR, picking the colour mode
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or `@use` the static file directly:
|
|
26
|
+
|
|
27
|
+
```scss
|
|
28
|
+
@use "@pantoken/scss/tokens.scss";
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`light-dark()` tokens collapse to the chosen `mode` (default `light`), since SCSS variables are
|
|
32
|
+
compile-time single values. For runtime theming, use `@pantoken/css` instead.
|
|
33
|
+
|
|
34
|
+
## API
|
|
35
|
+
|
|
36
|
+
- **`scss: string`** — the ready-made `rebrand` variable set (also the default export).
|
|
37
|
+
- **`toScss(tokens, options?): string`** — emit SCSS variables for any token IR. `options.mode`
|
|
38
|
+
picks the colour mode (default `"light"`).
|
|
39
|
+
- **`ToScssOptions`** — options for `toScss`.
|
|
40
|
+
- **`Mode`** — the colour mode to resolve (`"light"` or `"dark"`).
|
|
41
|
+
- **`./tokens.scss`** — the generated plain SCSS file, for a direct `@use` or `@import`.
|
|
42
|
+
|
|
43
|
+
## Related
|
|
44
|
+
|
|
45
|
+
- Built from the IR published by `@pantoken/tokens`.
|
|
46
|
+
- `@pantoken/less` and `@pantoken/stylus` emit the same tokens for other preprocessors.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Mode, Mode as Mode$1 } from "@pantoken/utils";
|
|
2
|
+
import { Token } from "@pantoken/model";
|
|
3
|
+
|
|
4
|
+
//#region src/to-scss.d.ts
|
|
5
|
+
/** Options for {@link toScss}. */
|
|
6
|
+
interface ToScssOptions {
|
|
7
|
+
/** Which colour mode to resolve (default `"light"`). */
|
|
8
|
+
mode?: Mode$1;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Emit SCSS variables for a token IR.
|
|
12
|
+
*
|
|
13
|
+
* @param tokens - The IR (e.g. from `@pantoken/tokens`).
|
|
14
|
+
* @param options - {@link ToScssOptions}.
|
|
15
|
+
* @returns The SCSS source string.
|
|
16
|
+
*
|
|
17
|
+
* @example Emit the default (light) variables
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { toScss } from "@pantoken/scss";
|
|
20
|
+
* import { tokens } from "@pantoken/tokens";
|
|
21
|
+
*
|
|
22
|
+
* toScss(tokens); // "$instui-color-brand: #0374b5;\n…"
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Resolve the dark mode of another theme
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { toScss } from "@pantoken/scss";
|
|
28
|
+
* import { byTheme } from "@pantoken/tokens";
|
|
29
|
+
*
|
|
30
|
+
* toScss(byTheme("canvas"), { mode: "dark" });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function toScss(tokens: readonly Token[], options?: ToScssOptions): string;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/index.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* The ready-made `rebrand` SCSS variable set.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { scss } from "@pantoken/scss";
|
|
42
|
+
* import { writeFileSync } from "node:fs";
|
|
43
|
+
*
|
|
44
|
+
* writeFileSync("tokens.scss", scss);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare const scss: string;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { type Mode, type ToScssOptions, scss as default, scss, toScss };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { tokens } from "@pantoken/tokens";
|
|
2
|
+
import { resolveTokens } from "@pantoken/utils";
|
|
3
|
+
//#region src/to-scss.ts
|
|
4
|
+
/**
|
|
5
|
+
* Emit the pantoken IR as SCSS variables. Values are resolved to concrete, single-mode values so
|
|
6
|
+
* the output is a self-contained SCSS token file (`$instui-color-brand: #0374b5;`). Icon tokens are
|
|
7
|
+
* skipped — they belong in CSS, not SCSS variables.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Emit SCSS variables for a token IR.
|
|
13
|
+
*
|
|
14
|
+
* @param tokens - The IR (e.g. from `@pantoken/tokens`).
|
|
15
|
+
* @param options - {@link ToScssOptions}.
|
|
16
|
+
* @returns The SCSS source string.
|
|
17
|
+
*
|
|
18
|
+
* @example Emit the default (light) variables
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { toScss } from "@pantoken/scss";
|
|
21
|
+
* import { tokens } from "@pantoken/tokens";
|
|
22
|
+
*
|
|
23
|
+
* toScss(tokens); // "$instui-color-brand: #0374b5;\n…"
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example Resolve the dark mode of another theme
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { toScss } from "@pantoken/scss";
|
|
29
|
+
* import { byTheme } from "@pantoken/tokens";
|
|
30
|
+
*
|
|
31
|
+
* toScss(byTheme("canvas"), { mode: "dark" });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function toScss(tokens, options = {}) {
|
|
35
|
+
const resolved = resolveTokens(tokens, { mode: options.mode ?? "light" });
|
|
36
|
+
const lines = ["// DO NOT EDIT — generated by @pantoken/scss", ""];
|
|
37
|
+
for (const token of tokens) {
|
|
38
|
+
if (token.meta?.kind === "icon") continue;
|
|
39
|
+
lines.push(`$${token.name.replace(/^--/, "")}: ${resolved.get(token.name) ?? token.value};`);
|
|
40
|
+
}
|
|
41
|
+
return `${lines.join("\n")}\n`;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/index.ts
|
|
45
|
+
/**
|
|
46
|
+
* `@pantoken/scss` — Instructure design tokens as SCSS variables.
|
|
47
|
+
*
|
|
48
|
+
* {@link toScss} converts any IR; {@link scss} is the ready-made `rebrand` variable set. A static
|
|
49
|
+
* file is published at `@pantoken/scss/tokens.scss`.
|
|
50
|
+
*
|
|
51
|
+
* @module
|
|
52
|
+
* @experimental
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* The ready-made `rebrand` SCSS variable set.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { scss } from "@pantoken/scss";
|
|
60
|
+
* import { writeFileSync } from "node:fs";
|
|
61
|
+
*
|
|
62
|
+
* writeFileSync("tokens.scss", scss);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
const scss = toScss(tokens);
|
|
66
|
+
//#endregion
|
|
67
|
+
export { scss as default, scss, toScss };
|