@compiled/react 0.16.2 → 0.16.4

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.
Files changed (66) hide show
  1. package/dist/browser/class-names/index.d.ts +1 -1
  2. package/dist/browser/create-strict-api/index.d.ts +181 -0
  3. package/dist/browser/create-strict-api/index.js +65 -0
  4. package/dist/browser/create-strict-api/index.js.map +1 -0
  5. package/dist/browser/css/index.d.ts +1 -1
  6. package/dist/browser/css-map/index.d.ts +3 -5
  7. package/dist/browser/css-map/index.js +3 -5
  8. package/dist/browser/css-map/index.js.map +1 -1
  9. package/dist/browser/index.d.ts +1 -0
  10. package/dist/browser/index.js +1 -0
  11. package/dist/browser/index.js.map +1 -1
  12. package/dist/browser/types.d.ts +7 -2
  13. package/dist/browser/utils/error.d.ts +1 -0
  14. package/dist/browser/utils/error.js +19 -0
  15. package/dist/browser/utils/error.js.map +1 -1
  16. package/dist/browser/xcss-prop/index.d.ts +14 -10
  17. package/dist/browser/xcss-prop/index.js +1 -1
  18. package/dist/browser/xcss-prop/index.js.map +1 -1
  19. package/dist/cjs/class-names/index.d.ts +1 -1
  20. package/dist/cjs/create-strict-api/index.d.ts +181 -0
  21. package/dist/cjs/create-strict-api/index.js +69 -0
  22. package/dist/cjs/create-strict-api/index.js.map +1 -0
  23. package/dist/cjs/css/index.d.ts +1 -1
  24. package/dist/cjs/css-map/index.d.ts +3 -5
  25. package/dist/cjs/css-map/index.js +3 -5
  26. package/dist/cjs/css-map/index.js.map +1 -1
  27. package/dist/cjs/index.d.ts +1 -0
  28. package/dist/cjs/index.js +3 -1
  29. package/dist/cjs/index.js.map +1 -1
  30. package/dist/cjs/types.d.ts +7 -2
  31. package/dist/cjs/utils/error.d.ts +1 -0
  32. package/dist/cjs/utils/error.js +21 -1
  33. package/dist/cjs/utils/error.js.map +1 -1
  34. package/dist/cjs/xcss-prop/index.d.ts +14 -10
  35. package/dist/cjs/xcss-prop/index.js +1 -1
  36. package/dist/cjs/xcss-prop/index.js.map +1 -1
  37. package/dist/esm/class-names/index.d.ts +1 -1
  38. package/dist/esm/create-strict-api/index.d.ts +181 -0
  39. package/dist/esm/create-strict-api/index.js +65 -0
  40. package/dist/esm/create-strict-api/index.js.map +1 -0
  41. package/dist/esm/css/index.d.ts +1 -1
  42. package/dist/esm/css-map/index.d.ts +3 -5
  43. package/dist/esm/css-map/index.js +3 -5
  44. package/dist/esm/css-map/index.js.map +1 -1
  45. package/dist/esm/index.d.ts +1 -0
  46. package/dist/esm/index.js +1 -0
  47. package/dist/esm/index.js.map +1 -1
  48. package/dist/esm/types.d.ts +7 -2
  49. package/dist/esm/utils/error.d.ts +1 -0
  50. package/dist/esm/utils/error.js +19 -0
  51. package/dist/esm/utils/error.js.map +1 -1
  52. package/dist/esm/xcss-prop/index.d.ts +14 -10
  53. package/dist/esm/xcss-prop/index.js +1 -1
  54. package/dist/esm/xcss-prop/index.js.map +1 -1
  55. package/package.json +2 -1
  56. package/src/class-names/index.ts +1 -1
  57. package/src/create-strict-api/__tests__/__fixtures__/strict-api.ts +13 -0
  58. package/src/create-strict-api/__tests__/index.test.tsx +312 -0
  59. package/src/create-strict-api/__tests__/package.test.tsx +21 -0
  60. package/src/create-strict-api/index.ts +223 -0
  61. package/src/css/index.ts +1 -1
  62. package/src/css-map/index.ts +3 -5
  63. package/src/index.ts +1 -0
  64. package/src/types.ts +8 -2
  65. package/src/utils/error.ts +20 -0
  66. package/src/xcss-prop/index.ts +33 -10
@@ -13,7 +13,7 @@ export interface ClassNamesProps<TProps> {
13
13
  }) => ReactNode;
14
14
  }
15
15
  /**
16
- * ## Class names
16
+ * ## Class Names
17
17
  *
18
18
  * Use a component where styles are not necessarily used on a JSX element.
19
19
  * For further details [read the documentation](https://compiledcssinjs.com/docs/api-class-names).
@@ -0,0 +1,181 @@
1
+ import type { StrictCSSProperties, CSSPseudos } from '../types';
2
+ import { type CompiledStyles, cx, type Internal$XCSSProp } from '../xcss-prop';
3
+ type PseudosDeclarations = {
4
+ [Q in CSSPseudos]?: StrictCSSProperties;
5
+ };
6
+ type EnforceSchema<TObject> = {
7
+ [P in keyof TObject]?: P extends keyof CompiledSchema ? TObject[P] extends Record<string, unknown> ? EnforceSchema<TObject[P]> : TObject[P] : never;
8
+ };
9
+ type PickObjects<TObject> = {
10
+ [P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
11
+ };
12
+ interface CompiledAPI<TSchema> {
13
+ /**
14
+ * ## CSS
15
+ *
16
+ * Creates styles that are statically typed and useable with other Compiled APIs.
17
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-css).
18
+ *
19
+ * @example
20
+ * ```
21
+ * const redText = css({
22
+ * color: 'red',
23
+ * });
24
+ *
25
+ * <div css={redText} />
26
+ * ```
27
+ */
28
+ css(styles: StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>): StrictCSSProperties;
29
+ /**
30
+ * ## CSS Map
31
+ *
32
+ * Creates a collection of named styles that are statically typed and useable with other Compiled APIs.
33
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
34
+ *
35
+ * @example
36
+ * ```
37
+ * const styles = cssMap({
38
+ * none: { borderStyle: 'none' },
39
+ * solid: { borderStyle: 'solid' },
40
+ * });
41
+ *
42
+ * <div css={styles.solid} />
43
+ * ```
44
+ */
45
+ cssMap<TStyles extends Record<string, StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>>>(styles: TStyles): {
46
+ readonly [P in keyof TStyles]: CompiledStyles<TStyles[P]>;
47
+ };
48
+ /**
49
+ * ## CX
50
+ *
51
+ * Use in conjunction with the {@link XCSSProp} to concatenate and conditionally apply
52
+ * declared styles. Can only be used with the {@link cssMap} and {@link XCSSProp} APIs.
53
+ *
54
+ * @example
55
+ * ```
56
+ * const styles = cssMap({
57
+ * text: { color: 'var(--ds-text)' },
58
+ * primary: { color: 'var(--ds-text-brand)' },
59
+ * });
60
+ *
61
+ * <Component xcss={cx(isPrimary && styles.text, !isPrimary && styles.primary)} />
62
+ * ```
63
+ */
64
+ cx: typeof cx;
65
+ /**
66
+ * ## XCSSProp
67
+ *
68
+ * Declare styles your component takes with all other styles marked as violations
69
+ * by the TypeScript compiler. There are two primary use cases for xcss prop:
70
+ *
71
+ * - safe style overrides
72
+ * - inverting style declarations
73
+ *
74
+ * Interverting style declarations is interesting for platform teams as
75
+ * it means products only pay for styles they use as they're now the ones who declare
76
+ * the styles!
77
+ *
78
+ * The {@link XCSSProp} type has generics two of which must be defined — use to explicitly
79
+ * set want you to maintain as API. Use {@link XCSSAllProperties} and {@link XCSSAllPseudos}
80
+ * to enable all properties and pseudos.
81
+ *
82
+ * The third generic is used to declare what properties and pseudos should be required.
83
+ *
84
+ * ```tsx
85
+ * interface MyComponentProps {
86
+ * // Color is accepted, all other properties / pseudos are considered violations.
87
+ * xcss?: ReturnType<typeof XCSSProp<'color', never>>;
88
+ *
89
+ * // Only backgrond color and hover pseudo is accepted.
90
+ * xcss?: ReturnType<typeof XCSSProp<'backgroundColor', '&:hover'>>;
91
+ *
92
+ * // All properties are accepted, all pseudos are considered violations.
93
+ * xcss?: ReturnType<typeof XCSSProp<XCSSAllProperties, never>>;
94
+ *
95
+ * // All properties are accepted, only the hover pseudo is accepted.
96
+ * xcss?: ReturnType<typeof XCSSProp<XCSSAllProperties, '&:hover'>>;
97
+ *
98
+ * // The xcss prop is required as well as the color property. No pseudos are required.
99
+ * xcss: ReturnType<
100
+ * typeof XCSSProp<
101
+ * XCSSAllProperties,
102
+ * '&:hover',
103
+ * { requiredProperties: 'color', requiredPseudos: never }
104
+ * >
105
+ * >;
106
+ * }
107
+ *
108
+ * function MyComponent({ xcss }: MyComponentProps) {
109
+ * return <div css={{ color: 'var(--ds-text-danger)' }} className={xcss} />
110
+ * }
111
+ * ```
112
+ *
113
+ * The xcss prop works with static inline objects and the [cssMap](https://compiledcssinjs.com/docs/api-cssmap) API.
114
+ *
115
+ * ```jsx
116
+ * // Declared as an inline object
117
+ * <Component xcss={{ color: 'var(--ds-text)' }} />
118
+ *
119
+ * // Declared with the cssMap API
120
+ * const styles = cssMap({ text: { color: 'var(--ds-text)' } });
121
+ * <Component xcss={styles.text} />
122
+ * ```
123
+ *
124
+ * To concatenate and conditonally apply styles use the {@link cssMap} and {@link cx} functions.
125
+ */
126
+ XCSSProp<TAllowedProperties extends keyof StrictCSSProperties, TAllowedPseudos extends CSSPseudos, TRequiredProperties extends {
127
+ requiredProperties: TAllowedProperties;
128
+ requiredPseudos: TAllowedPseudos;
129
+ } = never>(): Internal$XCSSProp<TAllowedProperties, TAllowedPseudos, TSchema, PickObjects<TSchema>, TRequiredProperties>;
130
+ }
131
+ type CompiledSchema = StrictCSSProperties & PseudosDeclarations;
132
+ /**
133
+ * ## Create Strict API
134
+ *
135
+ * Returns a strict subset of Compiled APIs augmented by a type definition.
136
+ * This API does not change Compileds build time behavior — merely augmenting
137
+ * the returned API types which enforce:
138
+ *
139
+ * - all APIs use object types
140
+ * - property values declared in the type definition must be used (else fallback to defaults)
141
+ * - a strict subset of pseudo states/selectors
142
+ * - unknown properties to be a type violation
143
+ *
144
+ * To set up:
145
+ *
146
+ * 1. Declare the API in a module (either local or in a package):
147
+ *
148
+ * @example
149
+ * ```tsx
150
+ * // ./foo.ts
151
+ * const { css } = createStrictAPI<{
152
+ * color: 'var(--ds-text)',
153
+ * '&:hover': { color: 'var(--ds-text-hover)' }
154
+ * }>();
155
+ *
156
+ * export { css };
157
+ * ```
158
+ *
159
+ * 2. Configure Compiled to pick up this module:
160
+ *
161
+ * @example
162
+ * ```diff
163
+ * // .compiledcssrc
164
+ * {
165
+ * + "importSources": ["./foo.ts"]
166
+ * }
167
+ * ```
168
+ *
169
+ * 3. Use the module in your application code:
170
+ *
171
+ * @example
172
+ * ```tsx
173
+ * import { css } from './foo';
174
+ *
175
+ * const styles = css({ color: 'var(--ds-text)' });
176
+ *
177
+ * <div css={styles} />
178
+ * ```
179
+ */
180
+ export declare function createStrictAPI<TSchema extends CompiledSchema>(): CompiledAPI<TSchema>;
181
+ export {};
@@ -0,0 +1,65 @@
1
+ import { createStrictSetupError } from '../utils/error';
2
+ import { cx } from '../xcss-prop';
3
+ /**
4
+ * ## Create Strict API
5
+ *
6
+ * Returns a strict subset of Compiled APIs augmented by a type definition.
7
+ * This API does not change Compileds build time behavior — merely augmenting
8
+ * the returned API types which enforce:
9
+ *
10
+ * - all APIs use object types
11
+ * - property values declared in the type definition must be used (else fallback to defaults)
12
+ * - a strict subset of pseudo states/selectors
13
+ * - unknown properties to be a type violation
14
+ *
15
+ * To set up:
16
+ *
17
+ * 1. Declare the API in a module (either local or in a package):
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * // ./foo.ts
22
+ * const { css } = createStrictAPI<{
23
+ * color: 'var(--ds-text)',
24
+ * '&:hover': { color: 'var(--ds-text-hover)' }
25
+ * }>();
26
+ *
27
+ * export { css };
28
+ * ```
29
+ *
30
+ * 2. Configure Compiled to pick up this module:
31
+ *
32
+ * @example
33
+ * ```diff
34
+ * // .compiledcssrc
35
+ * {
36
+ * + "importSources": ["./foo.ts"]
37
+ * }
38
+ * ```
39
+ *
40
+ * 3. Use the module in your application code:
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * import { css } from './foo';
45
+ *
46
+ * const styles = css({ color: 'var(--ds-text)' });
47
+ *
48
+ * <div css={styles} />
49
+ * ```
50
+ */
51
+ export function createStrictAPI() {
52
+ return {
53
+ css() {
54
+ throw createStrictSetupError();
55
+ },
56
+ cssMap() {
57
+ throw createStrictSetupError();
58
+ },
59
+ cx,
60
+ XCSSProp() {
61
+ throw createStrictSetupError();
62
+ },
63
+ };
64
+ }
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create-strict-api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAuB,EAAE,EAA0B,MAAM,cAAc,CAAC;AA+J/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,GAAG;YACD,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,MAAM;YACJ,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;QACD,EAAE;QACF,QAAQ;YACN,MAAM,sBAAsB,EAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -2,7 +2,7 @@ import type { CSSProps, CssObject, CssFunction } from '../types';
2
2
  /**
3
3
  * ## CSS
4
4
  *
5
- * Define styles that are statically typed and useable with other Compiled APIs.
5
+ * Create styles that are statically typed and useable with other Compiled APIs.
6
6
  * For further details [read the documentation](https://compiledcssinjs.com/docs/api-css).
7
7
  *
8
8
  * ### Style with objects
@@ -78,9 +78,9 @@ type ExtendedSelectors = {
78
78
  selectors?: ExtendedSelector;
79
79
  };
80
80
  /**
81
- * ## cssMap
81
+ * ## CSS Map
82
82
  *
83
- * Creates a collection of named CSS rules that are statically typed and useable with other Compiled APIs.
83
+ * Creates a collection of named styles that are statically typed and useable with other Compiled APIs.
84
84
  * For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
85
85
  *
86
86
  * @example
@@ -90,9 +90,7 @@ type ExtendedSelectors = {
90
90
  * solid: { borderStyle: 'solid' },
91
91
  * });
92
92
  *
93
- * const Component = ({ borderStyle }) => <div css={styles[borderStyle]} />
94
- *
95
- * <Component borderStyle="solid" />
93
+ * <div css={styles.solid} />
96
94
  * ```
97
95
  */
98
96
  export default function cssMap<TStyles extends Record<string, CSSProperties & WhitelistedSelector & ExtendedSelectors>>(_styles: TStyles): {
@@ -1,8 +1,8 @@
1
1
  import { createSetupError } from '../utils/error';
2
2
  /**
3
- * ## cssMap
3
+ * ## CSS Map
4
4
  *
5
- * Creates a collection of named CSS rules that are statically typed and useable with other Compiled APIs.
5
+ * Creates a collection of named styles that are statically typed and useable with other Compiled APIs.
6
6
  * For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
7
7
  *
8
8
  * @example
@@ -12,9 +12,7 @@ import { createSetupError } from '../utils/error';
12
12
  * solid: { borderStyle: 'solid' },
13
13
  * });
14
14
  *
15
- * const Component = ({ borderStyle }) => <div css={styles[borderStyle]} />
16
- *
17
- * <Component borderStyle="solid" />
15
+ * <div css={styles.solid} />
18
16
  * ```
19
17
  */
20
18
  export default function cssMap(_styles) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css-map/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAkFlD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAG5B,OAAgB;IAIhB,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css-map/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAkFlD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAG5B,OAAgB;IAIhB,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
@@ -7,6 +7,7 @@ export { styled } from './styled';
7
7
  export { ClassNames } from './class-names';
8
8
  export { default as css } from './css';
9
9
  export { default as cssMap } from './css-map';
10
+ export { createStrictAPI } from './create-strict-api';
10
11
  export { type XCSSAllProperties, type XCSSAllPseudos, type XCSSProp, cx } from './xcss-prop';
11
12
  export declare const jsx: typeof createElement;
12
13
  export declare namespace jsx {
@@ -4,6 +4,7 @@ export { styled } from './styled';
4
4
  export { ClassNames } from './class-names';
5
5
  export { default as css } from './css';
6
6
  export { default as cssMap } from './css-map';
7
+ export { createStrictAPI } from './create-strict-api';
7
8
  export { cx } from './xcss-prop';
8
9
  // Pass through the (classic) jsx runtime.
9
10
  // Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAOtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAA8D,EAAE,EAAE,MAAM,aAAa,CAAC;AAE7F,0CAA0C;AAC1C,kGAAkG;AAClG,MAAM,CAAC,MAAM,GAAG,GAAG,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAOtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAA8D,EAAE,EAAE,MAAM,aAAa,CAAC;AAE7F,0CAA0C;AAC1C,kGAAkG;AAClG,MAAM,CAAC,MAAM,GAAG,GAAG,aAAa,CAAC"}
@@ -20,9 +20,14 @@ export type CssObject<TProps> = Readonly<{
20
20
  export type CssFunction<TProps = unknown> = CssType<TProps> | BasicTemplateInterpolations | null | boolean | undefined;
21
21
  export type CSSPseudos = '&::after' | '&::backdrop' | '&::before' | '&::cue' | '&::cue-region' | '&::first-letter' | '&::first-line' | '&::grammar-error' | '&::marker' | '&::placeholder' | '&::selection' | '&::spelling-error' | '&::target-text' | '&::view-transition' | '&:active' | '&:autofill' | '&:blank' | '&:checked' | '&:default' | '&:defined' | '&:disabled' | '&:empty' | '&:enabled' | '&:first' | '&:focus' | '&:focus-visible' | '&:focus-within' | '&:fullscreen' | '&:hover' | '&:in-range' | '&:indeterminate' | '&:invalid' | '&:left' | '&:link' | '&:local-link' | '&:optional' | '&:out-of-range' | '&:paused' | '&:picture-in-picture' | '&:placeholder-shown' | '&:playing' | '&:read-only' | '&:read-write' | '&:required' | '&:right' | '&:target' | '&:user-invalid' | '&:user-valid' | '&:valid' | '&:visited';
22
22
  /**
23
- * The xcss prop must be given all known available properties even
24
- * if it takes a subset of them. This is ensure the (lack-of an)
23
+ * The XCSSProp must be given all known available properties even
24
+ * if it takes a subset of them. This ensures the (lack-of an)
25
25
  * excess property check doesn't enable makers to circumvent the
26
26
  * system and pass in values they shouldn't.
27
27
  */
28
28
  export type CSSProperties = Readonly<CSS.Properties<string | number>>;
29
+ /**
30
+ * A stricter subset of the {@link CSSProperties} type that excludes
31
+ * vendor and obsolete properties.
32
+ */
33
+ export type StrictCSSProperties = Readonly<CSS.StandardProperties & CSS.SvgProperties>;
@@ -1 +1,2 @@
1
1
  export declare const createSetupError: () => Error;
2
+ export declare const createStrictSetupError: () => Error;
@@ -17,4 +17,23 @@ export const createSetupError = () => {
17
17
  Good luck!
18
18
  `);
19
19
  };
20
+ export const createStrictSetupError = () => {
21
+ return new Error(`
22
+ ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
23
+ ██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║██║ ██╔════╝██╔══██╗
24
+ ██║ ██║ ██║██╔████╔██║██████╔╝██║██║ █████╗ ██║ ██║
25
+ ██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║██║ ██╔══╝ ██║ ██║
26
+ ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗███████╗██████╔╝
27
+ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝
28
+
29
+ @compiled/react
30
+
31
+ Code was executed when it shouldn't have. To resolve make sure to:
32
+
33
+ 1. Set up Compiled.
34
+ 2. Configure importSources in your Compiled config to point to the module that exports the output of createStrictAPI().
35
+
36
+ For more information visit https://compiledcssinjs.com/docs/installation and follow the instructions.
37
+ `);
38
+ };
20
39
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/utils/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAU,EAAE;IAC1C,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAU,EAAE;IAChD,OAAO,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;CAgBlB,CAAC,CAAC;AACH,CAAC,CAAC"}
@@ -1,12 +1,15 @@
1
1
  import type * as CSS from 'csstype';
2
2
  import type { CSSPseudos, CSSProperties } from '../types';
3
- type XCSSItem<TStyleDecl extends keyof CSSProperties> = {
4
- [Q in keyof CSSProperties]: Q extends TStyleDecl ? CompiledPropertyDeclarationReference | string | number : never;
3
+ type MarkAsRequired<T, K extends keyof T> = T & {
4
+ [P in K]-?: T[P];
5
+ };
6
+ type XCSSItem<TStyleDecl extends keyof CSSProperties, TCompiledTypedProperty> = {
7
+ [Q in keyof CSSProperties]: Q extends TStyleDecl ? CompiledPropertyDeclarationReference | (Q extends keyof TCompiledTypedProperty ? TCompiledTypedProperty[Q] : CSSProperties[Q]) : never;
5
8
  };
6
9
  type XCSSPseudos<TAllowedProperties extends keyof CSSProperties, TAllowedPseudos extends CSSPseudos, TRequiredProperties extends {
7
10
  requiredProperties: TAllowedProperties;
8
- }> = {
9
- [Q in CSSPseudos]?: Q extends TAllowedPseudos ? MarkAsRequired<XCSSItem<TAllowedProperties>, TRequiredProperties['requiredProperties']> : never;
11
+ }, TCompiledTypedPseudo> = {
12
+ [Q in CSSPseudos]?: Q extends TAllowedPseudos ? MarkAsRequired<XCSSItem<TAllowedProperties, Q extends keyof TCompiledTypedPseudo ? TCompiledTypedPseudo[Q] : object>, TRequiredProperties['requiredProperties']> : never;
10
13
  };
11
14
  /**
12
15
  * These APIs we don't want to allow to be passed through the `xcss` prop but we also
@@ -47,7 +50,7 @@ export type XCSSAllProperties = keyof CSSProperties;
47
50
  */
48
51
  export type XCSSAllPseudos = CSSPseudos;
49
52
  /**
50
- * ## xcss prop
53
+ * ## XCSSProp
51
54
  *
52
55
  * Declare styles your component takes with all other styles marked as violations
53
56
  * by the TypeScript compiler. There are two primary use cases for xcss prop:
@@ -106,12 +109,13 @@ export type XCSSAllPseudos = CSSPseudos;
106
109
  export type XCSSProp<TAllowedProperties extends keyof CSSProperties, TAllowedPseudos extends CSSPseudos, TRequiredProperties extends {
107
110
  requiredProperties: TAllowedProperties;
108
111
  requiredPseudos: TAllowedPseudos;
109
- } = never> = (MarkAsRequired<XCSSItem<TAllowedProperties>, TRequiredProperties['requiredProperties']> & MarkAsRequired<XCSSPseudos<TAllowedProperties, TAllowedPseudos, TRequiredProperties>, TRequiredProperties['requiredPseudos']> & BlockedRules) | false | null | undefined;
110
- type MarkAsRequired<T, K extends keyof T> = T & {
111
- [P in K]-?: T[P];
112
- };
112
+ } = never> = Internal$XCSSProp<TAllowedProperties, TAllowedPseudos, object, object, TRequiredProperties>;
113
+ export type Internal$XCSSProp<TAllowedProperties extends keyof CSSProperties, TAllowedPseudos extends CSSPseudos, TCompiledTypedProperty, TCompiledTypedPseudo, TRequiredProperties extends {
114
+ requiredProperties: TAllowedProperties;
115
+ requiredPseudos: TAllowedPseudos;
116
+ }> = (MarkAsRequired<XCSSItem<TAllowedProperties, TCompiledTypedProperty>, TRequiredProperties['requiredProperties']> & MarkAsRequired<XCSSPseudos<TAllowedProperties, TAllowedPseudos, TRequiredProperties, TCompiledTypedPseudo>, TRequiredProperties['requiredPseudos']> & BlockedRules) | false | null | undefined;
113
117
  /**
114
- * ## cx
118
+ * ## CX
115
119
  *
116
120
  * Use in conjunction with the {@link XCSSProp} to concatenate and conditionally apply
117
121
  * declared styles. Can only be used with the `cssMap()` and {@link XCSSProp} APIs.
@@ -1,6 +1,6 @@
1
1
  import { ac } from '../runtime';
2
2
  /**
3
- * ## cx
3
+ * ## CX
4
4
  *
5
5
  * Use in conjunction with the {@link XCSSProp} to concatenate and conditionally apply
6
6
  * declared styles. Can only be used with the `cssMap()` and {@link XCSSProp} APIs.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/xcss-prop/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAiJhC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAChB,GAAG,MAAe,EACD,EAAE;IACnB,2EAA2E;IAC3E,sDAAsD;IACtD,MAAM,YAAY,GAAG,MAA6B,CAAC;IAEnD,+EAA+E;IAC/E,kFAAkF;IAClF,OAAO,EAAE,CAAC,YAAY,CAAoB,CAAC;AAC7C,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/xcss-prop/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAwKhC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAChB,GAAG,MAAe,EACD,EAAE;IACnB,2EAA2E;IAC3E,sDAAsD;IACtD,MAAM,YAAY,GAAG,MAA6B,CAAC;IAEnD,+EAA+E;IAC/E,kFAAkF;IAClF,OAAO,EAAE,CAAC,YAAY,CAAoB,CAAC;AAC7C,CAAC,CAAC"}
@@ -13,7 +13,7 @@ export interface ClassNamesProps<TProps> {
13
13
  }) => ReactNode;
14
14
  }
15
15
  /**
16
- * ## Class names
16
+ * ## Class Names
17
17
  *
18
18
  * Use a component where styles are not necessarily used on a JSX element.
19
19
  * For further details [read the documentation](https://compiledcssinjs.com/docs/api-class-names).
@@ -0,0 +1,181 @@
1
+ import type { StrictCSSProperties, CSSPseudos } from '../types';
2
+ import { type CompiledStyles, cx, type Internal$XCSSProp } from '../xcss-prop';
3
+ type PseudosDeclarations = {
4
+ [Q in CSSPseudos]?: StrictCSSProperties;
5
+ };
6
+ type EnforceSchema<TObject> = {
7
+ [P in keyof TObject]?: P extends keyof CompiledSchema ? TObject[P] extends Record<string, unknown> ? EnforceSchema<TObject[P]> : TObject[P] : never;
8
+ };
9
+ type PickObjects<TObject> = {
10
+ [P in keyof TObject]: TObject[P] extends Record<string, unknown> ? TObject[P] : never;
11
+ };
12
+ interface CompiledAPI<TSchema> {
13
+ /**
14
+ * ## CSS
15
+ *
16
+ * Creates styles that are statically typed and useable with other Compiled APIs.
17
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-css).
18
+ *
19
+ * @example
20
+ * ```
21
+ * const redText = css({
22
+ * color: 'red',
23
+ * });
24
+ *
25
+ * <div css={redText} />
26
+ * ```
27
+ */
28
+ css(styles: StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>): StrictCSSProperties;
29
+ /**
30
+ * ## CSS Map
31
+ *
32
+ * Creates a collection of named styles that are statically typed and useable with other Compiled APIs.
33
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
34
+ *
35
+ * @example
36
+ * ```
37
+ * const styles = cssMap({
38
+ * none: { borderStyle: 'none' },
39
+ * solid: { borderStyle: 'solid' },
40
+ * });
41
+ *
42
+ * <div css={styles.solid} />
43
+ * ```
44
+ */
45
+ cssMap<TStyles extends Record<string, StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>>>(styles: TStyles): {
46
+ readonly [P in keyof TStyles]: CompiledStyles<TStyles[P]>;
47
+ };
48
+ /**
49
+ * ## CX
50
+ *
51
+ * Use in conjunction with the {@link XCSSProp} to concatenate and conditionally apply
52
+ * declared styles. Can only be used with the {@link cssMap} and {@link XCSSProp} APIs.
53
+ *
54
+ * @example
55
+ * ```
56
+ * const styles = cssMap({
57
+ * text: { color: 'var(--ds-text)' },
58
+ * primary: { color: 'var(--ds-text-brand)' },
59
+ * });
60
+ *
61
+ * <Component xcss={cx(isPrimary && styles.text, !isPrimary && styles.primary)} />
62
+ * ```
63
+ */
64
+ cx: typeof cx;
65
+ /**
66
+ * ## XCSSProp
67
+ *
68
+ * Declare styles your component takes with all other styles marked as violations
69
+ * by the TypeScript compiler. There are two primary use cases for xcss prop:
70
+ *
71
+ * - safe style overrides
72
+ * - inverting style declarations
73
+ *
74
+ * Interverting style declarations is interesting for platform teams as
75
+ * it means products only pay for styles they use as they're now the ones who declare
76
+ * the styles!
77
+ *
78
+ * The {@link XCSSProp} type has generics two of which must be defined — use to explicitly
79
+ * set want you to maintain as API. Use {@link XCSSAllProperties} and {@link XCSSAllPseudos}
80
+ * to enable all properties and pseudos.
81
+ *
82
+ * The third generic is used to declare what properties and pseudos should be required.
83
+ *
84
+ * ```tsx
85
+ * interface MyComponentProps {
86
+ * // Color is accepted, all other properties / pseudos are considered violations.
87
+ * xcss?: ReturnType<typeof XCSSProp<'color', never>>;
88
+ *
89
+ * // Only backgrond color and hover pseudo is accepted.
90
+ * xcss?: ReturnType<typeof XCSSProp<'backgroundColor', '&:hover'>>;
91
+ *
92
+ * // All properties are accepted, all pseudos are considered violations.
93
+ * xcss?: ReturnType<typeof XCSSProp<XCSSAllProperties, never>>;
94
+ *
95
+ * // All properties are accepted, only the hover pseudo is accepted.
96
+ * xcss?: ReturnType<typeof XCSSProp<XCSSAllProperties, '&:hover'>>;
97
+ *
98
+ * // The xcss prop is required as well as the color property. No pseudos are required.
99
+ * xcss: ReturnType<
100
+ * typeof XCSSProp<
101
+ * XCSSAllProperties,
102
+ * '&:hover',
103
+ * { requiredProperties: 'color', requiredPseudos: never }
104
+ * >
105
+ * >;
106
+ * }
107
+ *
108
+ * function MyComponent({ xcss }: MyComponentProps) {
109
+ * return <div css={{ color: 'var(--ds-text-danger)' }} className={xcss} />
110
+ * }
111
+ * ```
112
+ *
113
+ * The xcss prop works with static inline objects and the [cssMap](https://compiledcssinjs.com/docs/api-cssmap) API.
114
+ *
115
+ * ```jsx
116
+ * // Declared as an inline object
117
+ * <Component xcss={{ color: 'var(--ds-text)' }} />
118
+ *
119
+ * // Declared with the cssMap API
120
+ * const styles = cssMap({ text: { color: 'var(--ds-text)' } });
121
+ * <Component xcss={styles.text} />
122
+ * ```
123
+ *
124
+ * To concatenate and conditonally apply styles use the {@link cssMap} and {@link cx} functions.
125
+ */
126
+ XCSSProp<TAllowedProperties extends keyof StrictCSSProperties, TAllowedPseudos extends CSSPseudos, TRequiredProperties extends {
127
+ requiredProperties: TAllowedProperties;
128
+ requiredPseudos: TAllowedPseudos;
129
+ } = never>(): Internal$XCSSProp<TAllowedProperties, TAllowedPseudos, TSchema, PickObjects<TSchema>, TRequiredProperties>;
130
+ }
131
+ type CompiledSchema = StrictCSSProperties & PseudosDeclarations;
132
+ /**
133
+ * ## Create Strict API
134
+ *
135
+ * Returns a strict subset of Compiled APIs augmented by a type definition.
136
+ * This API does not change Compileds build time behavior — merely augmenting
137
+ * the returned API types which enforce:
138
+ *
139
+ * - all APIs use object types
140
+ * - property values declared in the type definition must be used (else fallback to defaults)
141
+ * - a strict subset of pseudo states/selectors
142
+ * - unknown properties to be a type violation
143
+ *
144
+ * To set up:
145
+ *
146
+ * 1. Declare the API in a module (either local or in a package):
147
+ *
148
+ * @example
149
+ * ```tsx
150
+ * // ./foo.ts
151
+ * const { css } = createStrictAPI<{
152
+ * color: 'var(--ds-text)',
153
+ * '&:hover': { color: 'var(--ds-text-hover)' }
154
+ * }>();
155
+ *
156
+ * export { css };
157
+ * ```
158
+ *
159
+ * 2. Configure Compiled to pick up this module:
160
+ *
161
+ * @example
162
+ * ```diff
163
+ * // .compiledcssrc
164
+ * {
165
+ * + "importSources": ["./foo.ts"]
166
+ * }
167
+ * ```
168
+ *
169
+ * 3. Use the module in your application code:
170
+ *
171
+ * @example
172
+ * ```tsx
173
+ * import { css } from './foo';
174
+ *
175
+ * const styles = css({ color: 'var(--ds-text)' });
176
+ *
177
+ * <div css={styles} />
178
+ * ```
179
+ */
180
+ export declare function createStrictAPI<TSchema extends CompiledSchema>(): CompiledAPI<TSchema>;
181
+ export {};