@kiva/kv-tokens 2.16.0 → 3.0.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/.eslintrc.cjs ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ extends: [
3
+ '../../.eslintrc.cjs',
4
+ ],
5
+ rules: {
6
+ 'import/extensions': ['error', 'always'],
7
+ },
8
+ };
package/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-tokens@2.16.1...@kiva/kv-tokens@3.0.0) (2025-01-17)
7
+
8
+
9
+ * refactor(kv-tokens)!: convert all modules to esm ([f09dd82](https://github.com/kiva/kv-ui-elements/commit/f09dd821e4060570767abb490db45836ecd9b80a))
10
+
11
+
12
+ ### BREAKING CHANGES
13
+
14
+ * modules now use import/export and .js extensions
15
+
16
+
17
+
18
+
19
+
20
+ ## [2.16.1](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-tokens@2.16.0...@kiva/kv-tokens@2.16.1) (2025-01-04)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * update font cdn url ([b0e3d37](https://github.com/kiva/kv-ui-elements/commit/b0e3d37694064aa372b5776e311d1109f552ff5a))
26
+
27
+
28
+
29
+
30
+
6
31
  # [2.16.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-tokens@2.15.0...@kiva/kv-tokens@2.16.0) (2024-11-20)
7
32
 
8
33
 
package/README.md CHANGED
@@ -12,7 +12,7 @@ The package contains
12
12
  ## Using the Design Definitions
13
13
 
14
14
  ```js
15
- const designTokens = require("@kiva/kv-tokens/primitives.json");
15
+ import designTokens from '@kiva/kv-tokens';
16
16
 
17
17
  const primaryTextColor = designTokens.colors.theme.DEFAULT.text.primary;
18
18
  ```
@@ -1,7 +1,7 @@
1
- const fs = require('node:fs');
2
- const primitives = require('../primitives.json');
3
- const { generateExternalSVG } = require('../configs/kivaHeadingUnderline.cjs');
4
- const { flattenJSON } = require('../configs/util.cjs');
1
+ import fs from 'node:fs';
2
+ import designTokens from '../primitives.js';
3
+ import { generateExternalSVG } from '../configs/kivaHeadingUnderline.js';
4
+ import { flattenJSON } from '../configs/util.js';
5
5
 
6
6
  // Note: dir is relative to the root of the kv-tokens package
7
7
  const dir = '../../dist/kvui';
@@ -17,7 +17,7 @@ fs.writeFileSync(`${dir}/heading-underline.svg`, svg);
17
17
 
18
18
  // Generate SCSS variables
19
19
  const today = new Date().toUTCString();
20
- const variables = flattenJSON(primitives);
20
+ const variables = flattenJSON(designTokens);
21
21
  const scss = Object.keys(variables)
22
22
  .map((key) => `$${key.toLowerCase().replace('.', '-')}: ${variables[key]};`)
23
23
  .join('\n');
@@ -1,5 +1,5 @@
1
- const { hexToRGB } = require('./util.cjs');
2
- const designtokens = require('../primitives.json');
1
+ import { hexToRGB } from './util.js';
2
+ import designTokens from '../primitives.js';
3
3
 
4
4
  const {
5
5
  DEFAULT: defaultThemeTokens,
@@ -13,7 +13,7 @@ const {
13
13
  mint: mintThemeTokens,
14
14
  'dark-mint': darkMintThemeTokens,
15
15
  'dark-stone': darkStoneThemeTokens,
16
- } = designtokens.colors.theme;
16
+ } = designTokens.colors.theme;
17
17
 
18
18
  /**
19
19
  * Loops through a theme object and builds a set of CSS custom properties
@@ -42,17 +42,17 @@ const buildCSSVarsFromTokens = (theme) => {
42
42
  return customProperties;
43
43
  };
44
44
 
45
- const defaultTheme = buildCSSVarsFromTokens(defaultThemeTokens);
46
- const greenLightTheme = buildCSSVarsFromTokens(greenLightThemeTokens);
47
- const greenDarkTheme = buildCSSVarsFromTokens(greenDarkThemeTokens);
48
- const marigoldLightTheme = buildCSSVarsFromTokens(marigoldLightThemeTokens);
49
- const stoneLightTheme = buildCSSVarsFromTokens(stoneLightThemeTokens);
50
- const stoneDarkTheme = buildCSSVarsFromTokens(stoneDarkThemeTokens);
51
- const darkTheme = buildCSSVarsFromTokens(darkThemeTokens);
52
- const mintTheme = buildCSSVarsFromTokens(mintThemeTokens);
53
- const darkGreenTheme = buildCSSVarsFromTokens(darkGreenThemeTokens);
54
- const darkMintTheme = buildCSSVarsFromTokens(darkMintThemeTokens);
55
- const darkStoneTheme = buildCSSVarsFromTokens(darkStoneThemeTokens);
45
+ export const defaultTheme = buildCSSVarsFromTokens(defaultThemeTokens);
46
+ export const greenLightTheme = buildCSSVarsFromTokens(greenLightThemeTokens);
47
+ export const greenDarkTheme = buildCSSVarsFromTokens(greenDarkThemeTokens);
48
+ export const marigoldLightTheme = buildCSSVarsFromTokens(marigoldLightThemeTokens);
49
+ export const stoneLightTheme = buildCSSVarsFromTokens(stoneLightThemeTokens);
50
+ export const stoneDarkTheme = buildCSSVarsFromTokens(stoneDarkThemeTokens);
51
+ export const darkTheme = buildCSSVarsFromTokens(darkThemeTokens);
52
+ export const mintTheme = buildCSSVarsFromTokens(mintThemeTokens);
53
+ export const darkGreenTheme = buildCSSVarsFromTokens(darkGreenThemeTokens);
54
+ export const darkMintTheme = buildCSSVarsFromTokens(darkMintThemeTokens);
55
+ export const darkStoneTheme = buildCSSVarsFromTokens(darkStoneThemeTokens);
56
56
 
57
57
  // function to allow background opacity and text opacity with tailwind colors
58
58
  // https://www.youtube.com/watch?v=MAtaT8BZEAo
@@ -82,7 +82,7 @@ const withOpacity = (variableName) => ({ opacityValue }) => {
82
82
  * ...
83
83
  * }
84
84
  */
85
- const buildColorChoices = (themeProperty) => {
85
+ export const buildColorChoices = (themeProperty) => {
86
86
  let twPrefix = themeProperty;
87
87
  if (themeProperty === 'background') {
88
88
  twPrefix = 'bg';
@@ -96,18 +96,3 @@ const buildColorChoices = (themeProperty) => {
96
96
  });
97
97
  return property;
98
98
  };
99
-
100
- module.exports = {
101
- buildColorChoices,
102
- defaultTheme,
103
- greenLightTheme,
104
- greenDarkTheme,
105
- marigoldLightTheme,
106
- stoneLightTheme,
107
- stoneDarkTheme,
108
- darkTheme,
109
- darkGreenTheme,
110
- mintTheme,
111
- darkMintTheme,
112
- darkStoneTheme,
113
- };
@@ -0,0 +1,55 @@
1
+ import designTokens from '../primitives.js';
2
+ import { base64 } from './util.js';
3
+ import underlinePath from './underlinePath.js';
4
+
5
+ const { colors } = designTokens;
6
+ const svgOpenTag = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 921 16" preserveAspectRatio="none">';
7
+
8
+ /*
9
+ * Generates an SVG string for brush-stroke underlines, with colors from each theme. This is
10
+ * achieved by creating one path for the brush stroke, and then using multiple <use> elements to
11
+ * reference the path and fill it with the desired color (a sprite sheet technique from
12
+ * https://css-tricks.com/svg-fragment-identifiers-work/). The SVG is then used as a background
13
+ * image, and can be referenced by the color hex code, e.g. `url('/kvui/heading-underline.svg#2AA967')`.
14
+ * This allows us to use the same SVG for all themes, and change the color with CSS custom
15
+ * properties, rather than having to generate a new SVG for each color.
16
+ */
17
+ export function generateExternalSVG() {
18
+ const { theme } = colors;
19
+ const themeColors = Object.keys(theme)
20
+ .filter((key) => theme[key]['heading-underline'])
21
+ .flatMap((key) => Object.values(theme[key]['heading-underline']));
22
+ const colorList = [...new Set(themeColors)];
23
+
24
+ const colorDefs = colorList.map((color) => {
25
+ return `<g id="${color.replace('#', '')}"><use href="#hu-path" fill="${color}" /></g>`;
26
+ });
27
+ return `${svgOpenTag}
28
+ <defs>
29
+ <style>
30
+ g { display: none; }
31
+ g:target { display: inline; }
32
+ </style>
33
+ </defs>
34
+ ${colorDefs.join('')}
35
+ <symbol id="hu-path">
36
+ ${underlinePath}
37
+ </symbol>
38
+ </svg>`;
39
+ }
40
+
41
+ /*
42
+ * Generates an inline-style SVG string for brush-stroke underlines, in one color only, to be used as a background image in css.
43
+ *
44
+ * THIS SHOULD ONLY BE USED FOR DEMO PURPOSES.
45
+ *
46
+ * This will greatly increase the size of your css file if used in production with multiple colors.
47
+ */
48
+ export function generateInlineSVG(color) {
49
+ const svg = `${svgOpenTag}
50
+ <g fill="${color}">
51
+ ${underlinePath}
52
+ </g>
53
+ </svg>`;
54
+ return `url('data:image/svg+xml;base64,${base64(svg)}')`;
55
+ }
@@ -1,5 +1,5 @@
1
- const { rem, em } = require('./util.cjs');
2
- const designtokens = require('../primitives.json');
1
+ import { rem, em } from './util.js';
2
+ import designTokens from '../primitives.js';
3
3
 
4
4
  const {
5
5
  fonts,
@@ -9,12 +9,12 @@ const {
9
9
  lineHeights,
10
10
  radii,
11
11
  space,
12
- } = designtokens;
12
+ } = designTokens;
13
13
 
14
14
  /**
15
15
  WEB FONT DEFINITIONS
16
16
  */
17
- const webFonts = [
17
+ export const webFonts = [
18
18
  // Note corresponding font weight in Tailwind is "normal"
19
19
  {
20
20
  '@font-face': {
@@ -23,7 +23,7 @@ const webFonts = [
23
23
  fontStyle: 'normal',
24
24
  fontDisplay: 'swap',
25
25
  // eslint-disable-next-line max-len
26
- src: 'url(//www-kiva-org.freetls.fastly.net/static/fonts/PostGrotesk-Medium.8c8a585.woff2) format(\'woff2\')',
26
+ src: 'url(//www.kiva.org/static/fonts/PostGrotesk-Medium.8c8a585.woff2) format(\'woff2\')',
27
27
  },
28
28
  },
29
29
  // Note corresponding font weight in Tailwind is "normal"
@@ -34,7 +34,7 @@ const webFonts = [
34
34
  fontStyle: 'italic',
35
35
  fontDisplay: 'swap',
36
36
  // eslint-disable-next-line max-len
37
- src: 'url(//www-kiva-org.freetls.fastly.net/static/fonts/PostGrotesk-MediumItalic.133f41d.woff2) format(\'woff2\')',
37
+ src: 'url(//www.kiva.org/static/fonts/PostGrotesk-MediumItalic.133f41d.woff2) format(\'woff2\')',
38
38
  },
39
39
  },
40
40
  // Note corresponding font weight in Tailwind is "light"
@@ -44,7 +44,7 @@ const webFonts = [
44
44
  fontWeight: '300',
45
45
  fontStyle: 'normal',
46
46
  fontDisplay: 'swap',
47
- src: 'url(//www-kiva-org.freetls.fastly.net/static/fonts/PostGrotesk-Book.246fc8e.woff2) format(\'woff2\')',
47
+ src: 'url(//www.kiva.org/static/fonts/PostGrotesk-Book.246fc8e.woff2) format(\'woff2\')',
48
48
  },
49
49
  },
50
50
  // Note corresponding font weight in Tailwind is "light"
@@ -55,18 +55,18 @@ const webFonts = [
55
55
  fontStyle: 'italic',
56
56
  fontDisplay: 'swap',
57
57
  // eslint-disable-next-line max-len
58
- src: 'url(//www-kiva-org.freetls.fastly.net/static/fonts/PostGrotesk-BookItalic.4d06d39.woff2) format(\'woff2\')',
58
+ src: 'url(//www.kiva.org/static/fonts/PostGrotesk-BookItalic.4d06d39.woff2) format(\'woff2\')',
59
59
  },
60
60
  },
61
61
  ];
62
62
 
63
63
  /** BASE TEXT COLOR */
64
- const textBaseColor = 'rgb(var(--text-primary))';
64
+ export const textBaseColor = 'rgb(var(--text-primary))';
65
65
 
66
66
  /**
67
67
  REUSABLE TYPE STYLES
68
68
  */
69
- const textStyles = (() => {
69
+ export const textStyles = (() => {
70
70
  const textJumbo = {
71
71
  fontFamily: fonts.serif,
72
72
  fontWeight: fontWeights.medium,
@@ -234,7 +234,7 @@ See plugin styling here:
234
234
  https://github.com/tailwindlabs/tailwindcss-typography/blob/master/src/styles.js
235
235
  */
236
236
 
237
- const proseOverrides = () => ({
237
+ export const proseOverrides = () => ({
238
238
  DEFAULT: {
239
239
  css: [{
240
240
  color: false,
@@ -448,10 +448,3 @@ const proseOverrides = () => ({
448
448
  xl: false,
449
449
  '2xl': false,
450
450
  });
451
-
452
- module.exports = {
453
- webFonts,
454
- textBaseColor,
455
- textStyles,
456
- proseOverrides,
457
- };
@@ -1,9 +1,14 @@
1
- const plugin = require('tailwindcss/plugin');
2
- const typographyPlugin = require('@tailwindcss/typography');
3
- const kivaTypography = require('./kivaTypography.cjs');
4
- const { defaultTheme, buildColorChoices } = require('./kivaColors.cjs');
5
- const designtokens = require('../primitives.json');
6
- const { rem } = require('./util.cjs');
1
+ import plugin from 'tailwindcss/plugin.js';
2
+ import typographyPlugin from '@tailwindcss/typography';
3
+ import {
4
+ proseOverrides,
5
+ textBaseColor,
6
+ textStyles,
7
+ webFonts,
8
+ } from './kivaTypography.js';
9
+ import { defaultTheme, buildColorChoices } from './kivaColors.js';
10
+ import designTokens from '../primitives.js';
11
+ import { rem } from './util.js';
7
12
 
8
13
  const {
9
14
  fonts,
@@ -15,9 +20,9 @@ const {
15
20
  space,
16
21
  radii,
17
22
  zIndices,
18
- } = designtokens;
23
+ } = designTokens;
19
24
 
20
- module.exports = {
25
+ export default {
21
26
  content: ['./**.*.js'],
22
27
  prefix: 'tw-', // prefixes all tailwinds classes with tw. e.g., 'tw-flex tw-mb-2'
23
28
  corePlugins: {
@@ -136,7 +141,7 @@ module.exports = {
136
141
  lg: '0 4px 12px rgba(0, 0, 0, 0.08)',
137
142
  },
138
143
  extend: {
139
- typography: kivaTypography.proseOverrides, // prose plugin overrides
144
+ typography: proseOverrides, // prose plugin overrides
140
145
  height: {
141
146
  40: rem(320),
142
147
  57.5: rem(460),
@@ -182,7 +187,6 @@ module.exports = {
182
187
  plugins: [
183
188
  typographyPlugin, // prose plugin. See overrides in theme.extend.typography
184
189
  plugin(({ addBase, addUtilities }) => {
185
- const { webFonts, textStyles, textBaseColor } = kivaTypography;
186
190
  addBase(webFonts);
187
191
  addBase({
188
192
  body: {