@pantoken/tailwind 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 +52 -0
- package/dist/index.d.mts +45 -0
- package/dist/index.mjs +69 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @pantoken/tailwind
|
|
2
|
+
|
|
3
|
+
A Tailwind CSS preset that maps Instructure design tokens into the theme. Every token is exposed as a
|
|
4
|
+
`var(--instui-*)` reference — not a concrete value — so Tailwind utilities theme through the same CSS
|
|
5
|
+
custom properties `@pantoken/css` emits, and light, dark, and high-contrast all keep working.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i -D @pantoken/tailwind
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Also available as `pantoken/tailwind`.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// tailwind.config.ts
|
|
19
|
+
import { pantokenPreset } from "@pantoken/tailwind";
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
presets: [pantokenPreset()],
|
|
23
|
+
content: ["./src/**/*.{ts,tsx}"],
|
|
24
|
+
};
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then use utilities backed by the tokens:
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<div class="bg-color-background-base p-space-md font-lato">…</div>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Pair it with `@pantoken/css` (or `@pantoken/vite`) so the `--instui-*` custom properties are actually
|
|
34
|
+
defined. Pass `pantokenPreset({ includePrimitives: true })` to also expose the raw palette under a
|
|
35
|
+
`primitive-` prefix. `tailwindcss` is an optional peer dependency.
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
- **`pantokenPreset(options?): TailwindPreset`** — builds the preset, contributing `colors`,
|
|
40
|
+
`spacing`, and `fontFamily` under `theme.extend`. `options.includePrimitives` adds the primitive
|
|
41
|
+
palette. Also the default export.
|
|
42
|
+
- **`PantokenPresetOptions`** — options type.
|
|
43
|
+
- **`TailwindPreset`** — the shape of the config slice this preset contributes.
|
|
44
|
+
|
|
45
|
+
## Related
|
|
46
|
+
|
|
47
|
+
- Pairs with `@pantoken/css` or `@pantoken/vite`, which define the `--instui-*` custom properties the
|
|
48
|
+
utilities reference.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
/** A minimal shape for the slice of Tailwind config this preset contributes. */
|
|
3
|
+
interface TailwindPreset {
|
|
4
|
+
theme: {
|
|
5
|
+
extend: {
|
|
6
|
+
colors: Record<string, string>;
|
|
7
|
+
spacing: Record<string, string>;
|
|
8
|
+
fontFamily: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/** Options for {@link pantokenPreset}. */
|
|
13
|
+
interface PantokenPresetOptions {
|
|
14
|
+
/** Also expose the primitive colour palette under a `primitive-` prefix (default: false). */
|
|
15
|
+
includePrimitives?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Build the pantoken Tailwind preset.
|
|
19
|
+
*
|
|
20
|
+
* @param options - {@link PantokenPresetOptions}.
|
|
21
|
+
* @returns A Tailwind preset contributing `colors`, `spacing`, and `fontFamily`.
|
|
22
|
+
*
|
|
23
|
+
* @example Register the preset in tailwind.config.ts
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { pantokenPreset } from "@pantoken/tailwind";
|
|
26
|
+
*
|
|
27
|
+
* export default {
|
|
28
|
+
* presets: [pantokenPreset()],
|
|
29
|
+
* content: ["./src/**\/*.{ts,tsx}"],
|
|
30
|
+
* };
|
|
31
|
+
* // then use utilities like `bg-color-background-base p-space-md`
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example Also expose the primitive palette under a primitive- prefix
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { pantokenPreset } from "@pantoken/tailwind";
|
|
37
|
+
*
|
|
38
|
+
* export default {
|
|
39
|
+
* presets: [pantokenPreset({ includePrimitives: true })],
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare function pantokenPreset(options?: PantokenPresetOptions): TailwindPreset;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { PantokenPresetOptions, TailwindPreset, pantokenPreset as default, pantokenPreset };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { tokens } from "@pantoken/tokens";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* `@pantoken/tailwind` — a Tailwind CSS preset that maps Instructure design tokens into the theme.
|
|
5
|
+
*
|
|
6
|
+
* Every token is exposed as a `var(--instui-*)` reference (not a concrete value), so Tailwind
|
|
7
|
+
* utilities like `bg-color-background-base` theme through the same CSS custom properties that
|
|
8
|
+
* `@pantoken/css` emits — light/dark and high-contrast all keep working.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
13
|
+
function ref(name) {
|
|
14
|
+
return `var(${name})`;
|
|
15
|
+
}
|
|
16
|
+
function collect(source, prefix, keyFrom) {
|
|
17
|
+
const out = {};
|
|
18
|
+
for (const token of source) {
|
|
19
|
+
if (token.meta?.kind === "icon") continue;
|
|
20
|
+
if (!token.name.startsWith(prefix)) continue;
|
|
21
|
+
out[keyFrom(token.name)] = ref(token.name);
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build the pantoken Tailwind preset.
|
|
27
|
+
*
|
|
28
|
+
* @param options - {@link PantokenPresetOptions}.
|
|
29
|
+
* @returns A Tailwind preset contributing `colors`, `spacing`, and `fontFamily`.
|
|
30
|
+
*
|
|
31
|
+
* @example Register the preset in tailwind.config.ts
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { pantokenPreset } from "@pantoken/tailwind";
|
|
34
|
+
*
|
|
35
|
+
* export default {
|
|
36
|
+
* presets: [pantokenPreset()],
|
|
37
|
+
* content: ["./src/**\/*.{ts,tsx}"],
|
|
38
|
+
* };
|
|
39
|
+
* // then use utilities like `bg-color-background-base p-space-md`
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example Also expose the primitive palette under a primitive- prefix
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { pantokenPreset } from "@pantoken/tailwind";
|
|
45
|
+
*
|
|
46
|
+
* export default {
|
|
47
|
+
* presets: [pantokenPreset({ includePrimitives: true })],
|
|
48
|
+
* };
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
function pantokenPreset(options = {}) {
|
|
52
|
+
const colors = collect(tokens, "--instui-color-", (n) => n.slice(15));
|
|
53
|
+
if (options.includePrimitives) {
|
|
54
|
+
for (const token of tokens) if (token.name.startsWith("--instui-primitive-color-")) colors[`primitive-${token.name.slice(25)}`] = ref(token.name);
|
|
55
|
+
}
|
|
56
|
+
const spacing = collect(tokens, "--instui-spacing-", (n) => n.slice(17));
|
|
57
|
+
const fontFamily = {};
|
|
58
|
+
for (const token of tokens) {
|
|
59
|
+
const idx = token.name.indexOf("font-family-");
|
|
60
|
+
if (idx !== -1) fontFamily[token.name.slice(idx + 12)] = ref(token.name);
|
|
61
|
+
}
|
|
62
|
+
return { theme: { extend: {
|
|
63
|
+
colors,
|
|
64
|
+
spacing,
|
|
65
|
+
fontFamily
|
|
66
|
+
} } };
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { pantokenPreset as default, pantokenPreset };
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pantoken/tailwind",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tailwind CSS preset that maps Instructure design tokens into the theme as var(--instui-*) references.",
|
|
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
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^24.13.3",
|
|
23
|
+
"typescript": "^6.0.3",
|
|
24
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
|
|
25
|
+
"vite-plus": "0.2.4"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"tailwindcss": ">=3"
|
|
29
|
+
},
|
|
30
|
+
"peerDependenciesMeta": {
|
|
31
|
+
"tailwindcss": {
|
|
32
|
+
"optional": true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"pantoken": {
|
|
36
|
+
"key": "tailwind",
|
|
37
|
+
"kind": "subpath"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "vp pack",
|
|
41
|
+
"dev": "vp pack --watch",
|
|
42
|
+
"test": "vp test",
|
|
43
|
+
"check": "vp check"
|
|
44
|
+
}
|
|
45
|
+
}
|