@codecademy/gamut-styles 17.13.2-alpha.e9e7f4.0 → 17.13.2-alpha.eb3f22.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/dist/AssetProvider.d.ts +1 -1
- package/dist/AssetProvider.js +1 -1
- package/dist/globals/Typography.js +2 -2
- package/dist/remoteAssets/fonts.d.ts +1 -1
- package/dist/utilities/elementDir.d.ts +32 -0
- package/dist/utilities/elementDir.js +69 -0
- package/dist/utilities/index.d.ts +2 -0
- package/dist/utilities/index.js +3 -1
- package/dist/utilities/useLogicalProperties.d.ts +7 -0
- package/dist/utilities/useLogicalProperties.js +12 -0
- package/package.json +2 -2
- /package/dist/{utils → utilities}/fontUtils.d.ts +0 -0
- /package/dist/{utils → utilities}/fontUtils.js +0 -0
package/dist/AssetProvider.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Theme } from '@emotion/react';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { FontConfig } from './
|
|
3
|
+
import { FontConfig } from './utilities/fontUtils';
|
|
4
4
|
export declare const createFontLinks: (fonts?: readonly FontConfig[]) => import("react/jsx-runtime").JSX.Element[];
|
|
5
5
|
export declare const AssetProvider: React.FC<{
|
|
6
6
|
theme?: Theme;
|
package/dist/AssetProvider.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { webFonts } from './remoteAssets/fonts';
|
|
3
3
|
import { coreTheme } from './themes';
|
|
4
|
-
import { getFonts } from './
|
|
4
|
+
import { getFonts } from './utilities/fontUtils';
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* Only preload woff2 fonts, since woff1 are only included as fallbacks.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { css, Global } from '@emotion/react';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { getFonts } from '../
|
|
3
|
+
import { getFonts } from '../utilities/fontUtils';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Typography component that applies global typography styles to the application.
|
|
@@ -37,7 +37,7 @@ export const Typography = ({
|
|
|
37
37
|
weight = 'normal',
|
|
38
38
|
extensions,
|
|
39
39
|
filePath
|
|
40
|
-
}) => /*#__PURE__*/css("@font-face{font-display:swap;font-family:'", name, "';font-style:", style, ";font-weight:", weight, ";src:", extensions.map(ext => `url("${filePath}.${ext}") format("${ext}")`).join(', '), ";};label:typographyGlobals;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
40
|
+
}) => /*#__PURE__*/css("@font-face{font-display:swap;font-family:'", name, "';font-style:", style, ";font-weight:", weight, ";src:", extensions.map(ext => `url("${filePath}.${ext}") format("${ext}")`).join(', '), ";};label:typographyGlobals;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9nbG9iYWxzL1R5cG9ncmFwaHkudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQTZDNkIiLCJmaWxlIjoiLi4vLi4vc3JjL2dsb2JhbHMvVHlwb2dyYXBoeS50c3giLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBjc3MsIEdsb2JhbCB9IGZyb20gJ0BlbW90aW9uL3JlYWN0JztcbmltcG9ydCAqIGFzIFJlYWN0IGZyb20gJ3JlYWN0JztcblxuaW1wb3J0IHsgY29yZVRoZW1lIH0gZnJvbSAnLi4vdGhlbWVzJztcbmltcG9ydCB7IEZvbnRDb25maWcsIGdldEZvbnRzIH0gZnJvbSAnLi4vdXRpbGl0aWVzL2ZvbnRVdGlscyc7XG5cbi8qKlxuICogVHlwb2dyYXBoeSBjb21wb25lbnQgdGhhdCBhcHBsaWVzIGdsb2JhbCB0eXBvZ3JhcGh5IHN0eWxlcyB0byB0aGUgYXBwbGljYXRpb24u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lZCcpO1xuICAgICAgcmV0dXJuIG51bGw7XG4gICAgfVxuXG4gICAgY29uc3QgdHlwb2dyYXBoeUdsb2JhbHMgPSBjc3NgXG4gICAgICAke2ZvbnRzLm1hcChcbiAgICAgICAgKHtcbiAgICAgICAgICBuYW1lLFxuICAgICAgICAgIHN0eWxlID0gJ25vcm1hbCcsXG4gICAgICAgICAgd2VpZ2h0ID0gJ25vcm1hbCcsXG4gICAgICAgICAgZXh0ZW5zaW9ucyxcbiAgICAgICAgICBmaWxlUGF0aCxcbiAgICAgICAgfTogRm9udENvbmZpZykgPT4gY3NzYFxuICAgICAgICAgIEBmb250LWZhY2Uge1xuICAgICAgICAgICAgZm9udC1kaXNwbGF5OiBzd2FwO1xuICAgICAgICAgICAgZm9udC1mYW1pbHk6ICcke25hbWV9JztcbiAgICAgICAgICAgIGZvbnQtc3R5bGU6ICR7c3R5bGV9O1xuICAgICAgICAgICAgZm9udC13ZWlnaHQ6ICR7d2VpZ2h0fTtcbiAgICAgICAgICAgIHNyYzogJHtleHRlbnNpb25zXG4gICAgICAgICAgICAgIC5tYXAoKGV4dCkgPT4gYHVybChcIiR7ZmlsZVBhdGh9LiR7ZXh0fVwiKSBmb3JtYXQoXCIke2V4dH1cIilgKVxuICAgICAgICAgICAgICAuam9pbignLCAnKX07XG4gICAgICAgICAgfVxuICAgICAgICBgXG4gICAgICApfVxuXG4gICAgICBoMSxcbiAgICBoMixcbiAgICBoMyxcbiAgICBoNCxcbiAgICBoNSxcbiAgICBoNiB7XG4gICAgICAgIG1hcmdpbi1ib3R0b206ICR7dGhlbWUuc3BhY2luZ1sxNl19O1xuICAgICAgICBmb250LXdlaWdodDogJHt0aGVtZS5mb250V2VpZ2h0LnRpdGxlfTtcbiAgICAgICAgbGluZS1oZWlnaHQ6ICR7dGhlbWUubGluZUhlaWdodC50aXRsZX07XG4gICAgICB9XG5cbiAgICAgIGgxIHtcbiAgICAgICAgZm9udC1zaXplOiAke3RoZW1lLmZvbnRTaXplWzY0XX07XG4gICAgICB9XG4gICAgICBoMiB7XG4gICAgICAgIGZvbnQtc2l6ZTogJHt0aGVtZS5mb250U2l6ZVs0NF19O1xuICAgICAgfVxuICAgICAgaDMge1xuICAgICAgICBmb250LXNpemU6ICR7dGhlbWUuZm9udFNpemVbMzRdfTtcbiAgICAgIH1cbiAgICAgIGg0IHtcbiAgICAgICAgZm9udC1zaXplOiAke3RoZW1lLmZvbnRTaXplWzI2XX07XG4gICAgICB9XG4gICAgICBoNSB7XG4gICAgICAgIGZvbnQtc2l6ZTogJHt0aGVtZS5mb250U2l6ZVsyMl19O1xuICAgICAgfVxuICAgICAgaDYge1xuICAgICAgICBmb250LXNpemU6ICR7dGhlbWUuZm9udFNpemVbMjBdfTtcbiAgICAgIH1cblxuICAgICAgc21hbGwge1xuICAgICAgICBmb250LXNpemU6ICR7dGhlbWUuZm9udFNpemVbMTRdfTtcbiAgICAgICAgZm9udC13ZWlnaHQ6ICR7dGhlbWUuZm9udFdlaWdodC5iYXNlfTtcbiAgICAgIH1cbiAgICBgO1xuXG4gICAgcmV0dXJuIDxHbG9iYWwgc3R5bGVzPXt0eXBvZ3JhcGh5R2xvYmFsc30gLz47XG4gIH0gY2F0Y2ggKGVycm9yKSB7XG4gICAgLy8gSGFuZGxlIGZvbnQgbG9hZGluZyBlcnJvcnMgZ3JhY2VmdWxseVxuICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBuby1jb25zb2xlXG4gICAgY29uc29sZS53YXJuKCdUeXBvZ3JhcGh5OiBGb250IGxvYWRpbmcgZmFpbGVkOicsIGVycm9yKTtcbiAgICByZXR1cm4gbnVsbDtcbiAgfVxufTtcbiJdfQ== */"))), " h1,h2,h3,h4,h5,h6{margin-bottom:", theme.spacing[16], ";font-weight:", theme.fontWeight.title, ";line-height:", theme.lineHeight.title, ";}h1{font-size:", theme.fontSize[64], ";}h2{font-size:", theme.fontSize[44], ";}h3{font-size:", theme.fontSize[34], ";}h4{font-size:", theme.fontSize[26], ";}h5{font-size:", theme.fontSize[22], ";}h6{font-size:", theme.fontSize[20], ";}small{font-size:", theme.fontSize[14], ";font-weight:", theme.fontWeight.base, ";};label:typographyGlobals;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9nbG9iYWxzL1R5cG9ncmFwaHkudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXFDaUMiLCJmaWxlIjoiLi4vLi4vc3JjL2dsb2JhbHMvVHlwb2dyYXBoeS50c3giLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBjc3MsIEdsb2JhbCB9IGZyb20gJ0BlbW90aW9uL3JlYWN0JztcbmltcG9ydCAqIGFzIFJlYWN0IGZyb20gJ3JlYWN0JztcblxuaW1wb3J0IHsgY29yZVRoZW1lIH0gZnJvbSAnLi4vdGhlbWVzJztcbmltcG9ydCB7IEZvbnRDb25maWcsIGdldEZvbnRzIH0gZnJvbSAnLi4vdXRpbGl0aWVzL2ZvbnRVdGlscyc7XG5cbi8qKlxuICogVHlwb2dyYXBoeSBjb21wb25lbnQgdGhhdCBhcHBsaWVzIGdsb2JhbCB0eXBvZ3JhcGh5IHN0eWxlcyB0byB0aGUgYXBwbGljYXRpb24uXG4gKlxuICogVGhpcyBjb21wb25lbnQgZ2VuZXJhdGVzIENTUy1pbi1KUyBzdHlsZXMgZm9yOlxuICogLSBGb250IGZhY2UgZGVjbGFyYXRpb25zIGZvciBhbGwgY29uZmlndXJlZCBmb250c1xuICogLSBHbG9iYWwgaGVhZGluZyBzdHlsZXMgKGgxLWg2KSB3aXRoIHRoZW1lLWJhc2VkIHNpemluZyBhbmQgc3BhY2luZ1xuICogLSBTbWFsbCB0ZXh0IHN0eWxpbmdcbiAqXG4gKiBAcGFyYW0gcHJvcHMgLSBDb21wb25lbnQgcHJvcHNcbiAqIEBwYXJhbSBwcm9wcy50aGV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uge1xuICAgICAgICAgICAgZm9udC1kaXNwbGF5OiBzd2FwO1xuICAgICAgICAgICAgZm9udC1mYW1pbHk6ICcke25hbWV9JztcbiAgICAgICAgICAgIGZvbnQtc3R5bGU6ICR7c3R5bGV9O1xuICAgICAgICAgICAgZm9udC13ZWlnaHQ6ICR7d2VpZ2h0fTtcbiAgICAgICAgICAgIHNyYzogJHtleHRlbnNpb25zXG4gICAgICAgICAgICAgIC5tYXAoKGV4dCkgPT4gYHVybChcIiR7ZmlsZVBhdGh9LiR7ZXh0fVwiKSBmb3JtYXQoXCIke2V4dH1cIilgKVxuICAgICAgICAgICAgICAuam9pbignLCAnKX07XG4gICAgICAgICAgfVxuICAgICAgICBgXG4gICAgICApfVxuXG4gICAgICBoMSxcbiAgICBoMixcbiAgICBoMyxcbiAgICBoNCxcbiAgICBoNSxcbiAgICBoNiB7XG4gICAgICAgIG1hcmdpbi1ib3R0b206ICR7dGhlbWUuc3BhY2luZ1sxNl19O1xuICAgICAgICBmb250LXdlaWdodDogJHt0aGVtZS5mb250V2VpZ2h0LnRpdGxlfTtcbiAgICAgICAgbGluZS1oZWlnaHQ6ICR7dGhlbWUubGluZUhlaWdodC50aXRsZX07XG4gICAgICB9XG5cbiAgICAgIGgxIHtcbiAgICAgICAgZm9udC1zaXplOiAke3RoZW1lLmZvbnRTaXplWzY0XX07XG4gICAgICB9XG4gICAgICBoMiB7XG4gICAgICAgIGZvbnQtc2l6ZTogJHt0aGVtZS5mb250U2l6ZVs0NF19O1xuICAgICAgfVxuICAgICAgaDMge1xuICAgICAgICBmb250LXNpemU6ICR7dGhlbWUuZm9udFNpemVbMzRdfTtcbiAgICAgIH1cbiAgICAgIGg0IHtcbiAgICAgICAgZm9udC1zaXplOiAke3RoZW1lLmZvbnRTaXplWzI2XX07XG4gICAgICB9XG4gICAgICBoNSB7XG4gICAgICAgIGZvbnQtc2l6ZTogJHt0aGVtZS5mb250U2l6ZVsyMl19O1xuICAgICAgfVxuICAgICAgaDYge1xuICAgICAgICBmb250LXNpemU6ICR7dGhlbWUuZm9udFNpemVbMjBdfTtcbiAgICAgIH1cblxuICAgICAgc21hbGwge1xuICAgICAgICBmb250LXNpemU6ICR7dGhlbWUuZm9udFNpemVbMTRdfTtcbiAgICAgICAgZm9udC13ZWlnaHQ6ICR7dGhlbWUuZm9udFdlaWdodC5iYXNlfTtcbiAgICAgIH1cbiAgICBgO1xuXG4gICAgcmV0dXJuIDxHbG9iYWwgc3R5bGVzPXt0eXBvZ3JhcGh5R2xvYmFsc30gLz47XG4gIH0gY2F0Y2ggKGVycm9yKSB7XG4gICAgLy8gSGFuZGxlIGZvbnQgbG9hZGluZyBlcnJvcnMgZ3JhY2VmdWxseVxuICAgIC8vIGVzbGludC1kaXNhYmxlLW5leHQtbGluZSBuby1jb25zb2xlXG4gICAgY29uc29sZS53YXJuKCdUeXBvZ3JhcGh5OiBGb250IGxvYWRpbmcgZmFpbGVkOicsIGVycm9yKTtcbiAgICByZXR1cm4gbnVsbDtcbiAgfVxufTtcbiJdfQ== */"));
|
|
41
41
|
return /*#__PURE__*/_jsx(Global, {
|
|
42
42
|
styles: typographyGlobals
|
|
43
43
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FontConfig } from '../
|
|
1
|
+
import { FontConfig } from '../utilities/fontUtils';
|
|
2
2
|
export declare const FONT_ASSET_PATH = "https://www.codecademy.com/gamut";
|
|
3
3
|
export declare const core: readonly FontConfig[];
|
|
4
4
|
export declare const percipio: readonly FontConfig[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Resolved HTML `dir` keyword: effective writing direction after `dir`, then CSS
|
|
4
|
+
* `direction`, then document root.
|
|
5
|
+
*/
|
|
6
|
+
export type DirValue = 'rtl' | 'ltr';
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the effective `dir` for an element (`rtl` or `ltr`), including JSDOM where
|
|
9
|
+
* `getComputedStyle(el).direction` is often empty while `dir` is set on the root.
|
|
10
|
+
*
|
|
11
|
+
* @param el - DOM node whose effective direction is resolved.
|
|
12
|
+
* @returns `rtl` or `ltr`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function elementDir(el: Element): DirValue;
|
|
15
|
+
/**
|
|
16
|
+
* Ref whose `current` may be any DOM {@link Element} subclass (`HTMLElement`, `SVGElement`,
|
|
17
|
+
* `HTMLButtonElement`, etc.). For structural/minimal types (e.g. tests), intersect with
|
|
18
|
+
* `Element` so `current` is still typed as an `Element` (e.g. `Pick<HTMLAnchorElement, 'id'> & Element`).
|
|
19
|
+
*
|
|
20
|
+
* @template T - DOM element type for `current`; defaults to {@link Element}.
|
|
21
|
+
*/
|
|
22
|
+
export type ElementDirRef<T extends Element = Element> = RefObject<T | null>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the effective `dir` for the resolved element (`rtl` or `ltr`), and updates when `dir`
|
|
25
|
+
* changes on the document subtree or after layout (so `ref.current` is current).
|
|
26
|
+
* Resolution uses {@link elementDir}.
|
|
27
|
+
*
|
|
28
|
+
* @template T - DOM element type for the optional ref; defaults to {@link Element}.
|
|
29
|
+
* @param elementRef - Optional ref; when missing or `current` is not an `Element`, uses `document.documentElement`.
|
|
30
|
+
* @returns Effective direction for the resolved element, or `ltr` when `document` is undefined (SSR).
|
|
31
|
+
*/
|
|
32
|
+
export declare function useElementDir<T extends Element = Element>(elementRef?: ElementDirRef<T>): DirValue;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useReducer } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolved HTML `dir` keyword: effective writing direction after `dir`, then CSS
|
|
5
|
+
* `direction`, then document root.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the effective `dir` for an element (`rtl` or `ltr`), including JSDOM where
|
|
10
|
+
* `getComputedStyle(el).direction` is often empty while `dir` is set on the root.
|
|
11
|
+
*
|
|
12
|
+
* @param el - DOM node whose effective direction is resolved.
|
|
13
|
+
* @returns `rtl` or `ltr`.
|
|
14
|
+
*/
|
|
15
|
+
export function elementDir(el) {
|
|
16
|
+
const ownDir = el.getAttribute('dir');
|
|
17
|
+
if (ownDir === 'rtl') return 'rtl';
|
|
18
|
+
if (ownDir === 'ltr') return 'ltr';
|
|
19
|
+
const {
|
|
20
|
+
direction
|
|
21
|
+
} = getComputedStyle(el);
|
|
22
|
+
if (direction === 'rtl' || direction === 'ltr') {
|
|
23
|
+
return direction;
|
|
24
|
+
}
|
|
25
|
+
return document.documentElement.getAttribute('dir') === 'rtl' ? 'rtl' : 'ltr';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Ref whose `current` may be any DOM {@link Element} subclass (`HTMLElement`, `SVGElement`,
|
|
30
|
+
* `HTMLButtonElement`, etc.). For structural/minimal types (e.g. tests), intersect with
|
|
31
|
+
* `Element` so `current` is still typed as an `Element` (e.g. `Pick<HTMLAnchorElement, 'id'> & Element`).
|
|
32
|
+
*
|
|
33
|
+
* @template T - DOM element type for `current`; defaults to {@link Element}.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
function resolveElement(elementRef) {
|
|
37
|
+
return elementRef?.current instanceof Element ? elementRef.current : document.documentElement;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns the effective `dir` for the resolved element (`rtl` or `ltr`), and updates when `dir`
|
|
42
|
+
* changes on the document subtree or after layout (so `ref.current` is current).
|
|
43
|
+
* Resolution uses {@link elementDir}.
|
|
44
|
+
*
|
|
45
|
+
* @template T - DOM element type for the optional ref; defaults to {@link Element}.
|
|
46
|
+
* @param elementRef - Optional ref; when missing or `current` is not an `Element`, uses `document.documentElement`.
|
|
47
|
+
* @returns Effective direction for the resolved element, or `ltr` when `document` is undefined (SSR).
|
|
48
|
+
*/
|
|
49
|
+
export function useElementDir(elementRef) {
|
|
50
|
+
const [, bump] = useReducer(n => n + 1, 0);
|
|
51
|
+
useLayoutEffect(() => {
|
|
52
|
+
bump();
|
|
53
|
+
}, [elementRef]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const observer = new MutationObserver(() => {
|
|
56
|
+
bump();
|
|
57
|
+
});
|
|
58
|
+
observer.observe(document.documentElement, {
|
|
59
|
+
attributeFilter: ['dir'],
|
|
60
|
+
attributes: true,
|
|
61
|
+
subtree: true
|
|
62
|
+
});
|
|
63
|
+
return () => observer.disconnect();
|
|
64
|
+
}, []);
|
|
65
|
+
if (typeof document === 'undefined') {
|
|
66
|
+
return 'ltr';
|
|
67
|
+
}
|
|
68
|
+
return elementDir(resolveElement(elementRef));
|
|
69
|
+
}
|
package/dist/utilities/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether Gamut system props map to logical CSS properties (`marginInlineStart`, etc.)
|
|
3
|
+
* vs physical (`marginLeft`, etc.).
|
|
4
|
+
*
|
|
5
|
+
* `GamutProvider` always merges an explicit boolean (default `false`).
|
|
6
|
+
*/
|
|
7
|
+
export declare function useLogicalProperties(): boolean | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useTheme } from '@emotion/react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether Gamut system props map to logical CSS properties (`marginInlineStart`, etc.)
|
|
5
|
+
* vs physical (`marginLeft`, etc.).
|
|
6
|
+
*
|
|
7
|
+
* `GamutProvider` always merges an explicit boolean (default `false`).
|
|
8
|
+
*/
|
|
9
|
+
export function useLogicalProperties() {
|
|
10
|
+
const theme = useTheme();
|
|
11
|
+
return theme?.useLogicalProperties;
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/gamut-styles",
|
|
3
3
|
"description": "Styleguide & Component library for codecademy.com",
|
|
4
|
-
"version": "17.13.2-alpha.
|
|
4
|
+
"version": "17.13.2-alpha.eb3f22.0",
|
|
5
5
|
"author": "Jake Hiller <jake@codecademy.com>",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@codecademy/variance": "0.26.2-alpha.
|
|
7
|
+
"@codecademy/variance": "0.26.2-alpha.eb3f22.0",
|
|
8
8
|
"@emotion/is-prop-valid": "^1.1.0",
|
|
9
9
|
"framer-motion": "^11.18.0",
|
|
10
10
|
"get-nonce": "^1.0.0",
|
|
File without changes
|
|
File without changes
|