@telegraph/style-engine 0.2.2 → 0.3.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/CHANGELOG.md +6 -0
- package/README.md +104 -108
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/postcss.js +1 -1
- package/dist/cjs/postcss.js.map +1 -1
- package/dist/esm/index.mjs +115 -83
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/postcss.mjs +1 -1
- package/dist/esm/postcss.mjs.map +1 -1
- package/dist/types/helpers/getStyleProp/getStyleProp.d.ts +24 -1
- package/dist/types/helpers/getStyleProp/getStyleProp.d.ts.map +1 -1
- package/dist/types/helpers/getStyleProp/index.d.ts +2 -2
- package/dist/types/helpers/getStyleProp/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @telegraph/style-engine
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#714](https://github.com/knocklabs/telegraph/pull/714) [`627e61c`](https://github.com/knocklabs/telegraph/commit/627e61c3b17ccfc36f5fb835bb5f21a092efca95) Thanks [@kylemcd](https://github.com/kylemcd)! - feat: hover, focus, etc states as component props
|
|
8
|
+
|
|
3
9
|
## 0.2.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ import { getStyleProp, useStyleEngine } from "@telegraph/style-engine";
|
|
|
48
48
|
const cssVars = {
|
|
49
49
|
p: {
|
|
50
50
|
cssVar: "--tgph-padding",
|
|
51
|
-
value: "var(--tgph-
|
|
51
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
52
52
|
direction: "all",
|
|
53
53
|
},
|
|
54
54
|
bg: {
|
|
@@ -79,6 +79,7 @@ The Style Engine is the foundational CSS-in-JS system that enables Telegraph's d
|
|
|
79
79
|
|
|
80
80
|
- **Prop-to-CSS Mapping**: Converts React props to CSS custom properties
|
|
81
81
|
- **Type Safety**: Full TypeScript support for style props
|
|
82
|
+
- **Pseudo-Class Support**: Object-based pseudo-class styling (hover, focus, active, etc.)
|
|
82
83
|
- **Design Token Integration**: Seamless integration with Telegraph tokens
|
|
83
84
|
- **Build-time Optimization**: PostCSS plugin for automatic CSS bundling
|
|
84
85
|
- **Responsive Support**: Built-in responsive breakpoint system
|
|
@@ -99,9 +100,9 @@ Core function that processes style props and returns CSS variables.
|
|
|
99
100
|
|
|
100
101
|
```tsx
|
|
101
102
|
{
|
|
102
|
-
styleProp: Record<string, string>; // CSS custom properties
|
|
103
|
-
otherProps: Record<string, unknown>; // Non-style props
|
|
104
|
-
interactive: boolean; // Whether
|
|
103
|
+
styleProp: Record<string, string>; // CSS custom properties (including pseudo-class vars)
|
|
104
|
+
otherProps: Record<string, unknown>; // Non-style props (including unmatched pseudo sub-props)
|
|
105
|
+
interactive: boolean; // Whether pseudo-class props were resolved (for scoping CSS rules)
|
|
105
106
|
}
|
|
106
107
|
```
|
|
107
108
|
|
|
@@ -135,7 +136,6 @@ type CssVarProp = {
|
|
|
135
136
|
cssVar: string; // CSS custom property name
|
|
136
137
|
value: string; // Value template (use VARIABLE for prop value)
|
|
137
138
|
direction?: Direction; // For directional properties
|
|
138
|
-
interactive?: boolean; // Mark as interactive style
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
type Direction =
|
|
@@ -152,18 +152,57 @@ type Direction =
|
|
|
152
152
|
| "side-right"; // Corner sides
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
+
### Pseudo-Class Support
|
|
156
|
+
|
|
157
|
+
Any style prop can be used inside pseudo-class objects. The style engine automatically handles `_hover`, `_focus`, `_active`, `_focusWithin`, and `_disabled` props:
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
// Pseudo-class props accept objects containing any style props
|
|
161
|
+
// Prefixed with _ to avoid collisions with native HTML attributes (e.g. disabled)
|
|
162
|
+
<StyledBox
|
|
163
|
+
bg="gray-2"
|
|
164
|
+
_hover={{ bg: "gray-3", shadow: "1" }}
|
|
165
|
+
_focus={{ borderColor: "blue-8" }}
|
|
166
|
+
_active={{ bg: "gray-4" }}
|
|
167
|
+
_focusWithin={{ borderColor: "accent-6" }}
|
|
168
|
+
_disabled={{ bg: "gray-1" }}
|
|
169
|
+
/>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**How it works:**
|
|
173
|
+
|
|
174
|
+
1. When `getStyleProp` encounters a pseudo-class object (e.g., `_hover={{ bg: "gray-3" }}`), it resolves each sub-prop against the `cssVars` config
|
|
175
|
+
2. Matched sub-props generate CSS variables prefixed with the pseudo state (e.g., `--hover--background-color: var(--tgph-gray-3)`)
|
|
176
|
+
3. Unmatched sub-props are collected in `otherProps` for pass-through to child components
|
|
177
|
+
4. If any pseudo-class props are resolved, `interactive` returns `true` — the component should add an `--interactive` modifier class to scope the CSS pseudo-class rules and prevent them from cascading into nested child elements
|
|
178
|
+
|
|
179
|
+
**Type helper:**
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import { type WithPseudo } from "@telegraph/style-engine";
|
|
183
|
+
|
|
184
|
+
// Wraps a style props type to include pseudo-class object variants
|
|
185
|
+
type MyComponentProps = WithPseudo<{
|
|
186
|
+
bg?: ColorToken;
|
|
187
|
+
p?: SpacingToken;
|
|
188
|
+
// ... other style props
|
|
189
|
+
}>;
|
|
190
|
+
// Result includes: _hover?: { bg?: ColorToken; p?: SpacingToken; ... }, _focus?: { ... }, etc.
|
|
191
|
+
```
|
|
192
|
+
|
|
155
193
|
## PostCSS Plugin
|
|
156
194
|
|
|
157
195
|
The PostCSS plugin automatically includes CSS from Telegraph packages.
|
|
158
196
|
|
|
159
197
|
### At-Rules
|
|
160
198
|
|
|
161
|
-
| Rule
|
|
162
|
-
|
|
|
163
|
-
| `@telegraph tokens`
|
|
164
|
-
| `@telegraph tokens-light`
|
|
165
|
-
| `@telegraph tokens-dark`
|
|
166
|
-
| `@telegraph components`
|
|
199
|
+
| Rule | Description |
|
|
200
|
+
| ------------------------------------ | ----------------------------------------------------------------- |
|
|
201
|
+
| `@telegraph tokens` | Include default design tokens CSS |
|
|
202
|
+
| `@telegraph tokens-light` | Include light theme tokens |
|
|
203
|
+
| `@telegraph tokens-dark` | Include dark theme tokens |
|
|
204
|
+
| `@telegraph components` | Include all component stylesheets |
|
|
205
|
+
| `@telegraph interactive(<selector>)` | Auto-generate pseudo-class CSS rules for a component (build-time) |
|
|
167
206
|
|
|
168
207
|
### Configuration
|
|
169
208
|
|
|
@@ -196,7 +235,7 @@ module.exports = {
|
|
|
196
235
|
/* Your custom styles */
|
|
197
236
|
.my-component {
|
|
198
237
|
background: var(--tgph-gray-2);
|
|
199
|
-
padding: var(--tgph-
|
|
238
|
+
padding: var(--tgph-spacing-3);
|
|
200
239
|
border-radius: var(--tgph-radius-2);
|
|
201
240
|
}
|
|
202
241
|
```
|
|
@@ -206,56 +245,60 @@ module.exports = {
|
|
|
206
245
|
### Building Custom Components
|
|
207
246
|
|
|
208
247
|
```tsx
|
|
209
|
-
import {
|
|
248
|
+
import {
|
|
249
|
+
type CssVarProp,
|
|
250
|
+
type WithPseudo,
|
|
251
|
+
useStyleEngine,
|
|
252
|
+
} from "@telegraph/style-engine";
|
|
210
253
|
|
|
211
254
|
// Define comprehensive CSS variable mappings
|
|
212
255
|
const cssVars = {
|
|
213
256
|
// Spacing
|
|
214
257
|
p: {
|
|
215
258
|
cssVar: "--tgph-padding",
|
|
216
|
-
value: "var(--tgph-
|
|
259
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
217
260
|
direction: "all",
|
|
218
261
|
},
|
|
219
262
|
pt: {
|
|
220
263
|
cssVar: "--tgph-padding",
|
|
221
|
-
value: "var(--tgph-
|
|
264
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
222
265
|
direction: "top",
|
|
223
266
|
},
|
|
224
267
|
pr: {
|
|
225
268
|
cssVar: "--tgph-padding",
|
|
226
|
-
value: "var(--tgph-
|
|
269
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
227
270
|
direction: "right",
|
|
228
271
|
},
|
|
229
272
|
pb: {
|
|
230
273
|
cssVar: "--tgph-padding",
|
|
231
|
-
value: "var(--tgph-
|
|
274
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
232
275
|
direction: "bottom",
|
|
233
276
|
},
|
|
234
277
|
pl: {
|
|
235
278
|
cssVar: "--tgph-padding",
|
|
236
|
-
value: "var(--tgph-
|
|
279
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
237
280
|
direction: "left",
|
|
238
281
|
},
|
|
239
282
|
px: {
|
|
240
283
|
cssVar: "--tgph-padding",
|
|
241
|
-
value: "var(--tgph-
|
|
284
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
242
285
|
direction: "x",
|
|
243
286
|
},
|
|
244
287
|
py: {
|
|
245
288
|
cssVar: "--tgph-padding",
|
|
246
|
-
value: "var(--tgph-
|
|
289
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
247
290
|
direction: "y",
|
|
248
291
|
},
|
|
249
292
|
|
|
250
293
|
// Margin
|
|
251
294
|
m: {
|
|
252
295
|
cssVar: "--tgph-margin",
|
|
253
|
-
value: "var(--tgph-
|
|
296
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
254
297
|
direction: "all",
|
|
255
298
|
},
|
|
256
299
|
mt: {
|
|
257
300
|
cssVar: "--tgph-margin",
|
|
258
|
-
value: "var(--tgph-
|
|
301
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
259
302
|
direction: "top",
|
|
260
303
|
},
|
|
261
304
|
// ... more margin variants
|
|
@@ -267,16 +310,9 @@ const cssVars = {
|
|
|
267
310
|
// Layout
|
|
268
311
|
w: { cssVar: "--tgph-width", value: "VARIABLE" },
|
|
269
312
|
h: { cssVar: "--tgph-height", value: "VARIABLE" },
|
|
270
|
-
|
|
271
|
-
// Interactive states
|
|
272
|
-
hoverBg: {
|
|
273
|
-
cssVar: "--tgph-hover-background",
|
|
274
|
-
value: "var(--tgph-color-VARIABLE)",
|
|
275
|
-
interactive: true,
|
|
276
|
-
},
|
|
277
313
|
} as const;
|
|
278
314
|
|
|
279
|
-
type
|
|
315
|
+
type StyleProps = {
|
|
280
316
|
p?: string;
|
|
281
317
|
pt?: string;
|
|
282
318
|
pr?: string;
|
|
@@ -290,9 +326,12 @@ type StyledBoxProps = {
|
|
|
290
326
|
color?: string;
|
|
291
327
|
w?: string;
|
|
292
328
|
h?: string;
|
|
293
|
-
hoverBg?: string;
|
|
294
329
|
children?: React.ReactNode;
|
|
295
|
-
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// WithPseudo adds hover, focus, active, focusWithin, disabled object props
|
|
333
|
+
type StyledBoxProps = WithPseudo<StyleProps> &
|
|
334
|
+
React.HTMLAttributes<HTMLDivElement>;
|
|
296
335
|
|
|
297
336
|
export const StyledBox = ({ children, ...props }: StyledBoxProps) => {
|
|
298
337
|
const { styleProp, otherProps, interactive } = useStyleEngine({
|
|
@@ -302,7 +341,7 @@ export const StyledBox = ({ children, ...props }: StyledBoxProps) => {
|
|
|
302
341
|
|
|
303
342
|
return (
|
|
304
343
|
<div
|
|
305
|
-
className={interactive ? "tgph-interactive" :
|
|
344
|
+
className={`tgph-styled-box${interactive ? " tgph-styled-box--interactive" : ""}`}
|
|
306
345
|
style={styleProp}
|
|
307
346
|
{...otherProps}
|
|
308
347
|
>
|
|
@@ -312,51 +351,13 @@ export const StyledBox = ({ children, ...props }: StyledBoxProps) => {
|
|
|
312
351
|
};
|
|
313
352
|
```
|
|
314
353
|
|
|
315
|
-
### Responsive Styles
|
|
316
|
-
|
|
317
|
-
```tsx
|
|
318
|
-
import { RESPONSIVE_STYLE_PROPS } from "@telegraph/style-engine";
|
|
319
|
-
|
|
320
|
-
// Define responsive CSS variables
|
|
321
|
-
const responsiveCssVars = {
|
|
322
|
-
p: {
|
|
323
|
-
cssVar: "--tgph-padding",
|
|
324
|
-
value: "var(--tgph-space-VARIABLE)",
|
|
325
|
-
direction: "all",
|
|
326
|
-
},
|
|
327
|
-
} as const;
|
|
328
|
-
|
|
329
|
-
// Responsive component
|
|
330
|
-
export const ResponsiveBox = ({ children, ...props }) => {
|
|
331
|
-
const { styleProp, otherProps } = useStyleEngine({
|
|
332
|
-
props,
|
|
333
|
-
cssVars: responsiveCssVars,
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
return (
|
|
337
|
-
<div
|
|
338
|
-
style={{
|
|
339
|
-
...styleProp,
|
|
340
|
-
// Add responsive overrides
|
|
341
|
-
[`@media ${RESPONSIVE_STYLE_PROPS.conditions.md["@media"]}`]: {
|
|
342
|
-
"--tgph-padding": "var(--tgph-space-6)",
|
|
343
|
-
},
|
|
344
|
-
}}
|
|
345
|
-
{...otherProps}
|
|
346
|
-
>
|
|
347
|
-
{children}
|
|
348
|
-
</div>
|
|
349
|
-
);
|
|
350
|
-
};
|
|
351
|
-
```
|
|
352
|
-
|
|
353
354
|
### Performance Optimization
|
|
354
355
|
|
|
355
356
|
```tsx
|
|
356
357
|
// Memoize CSS variable definitions
|
|
357
358
|
const cssVars = useMemo(
|
|
358
359
|
() => ({
|
|
359
|
-
p: { cssVar: "--tgph-padding", value: "var(--tgph-
|
|
360
|
+
p: { cssVar: "--tgph-padding", value: "var(--tgph-spacing-VARIABLE)" },
|
|
360
361
|
bg: { cssVar: "--tgph-background", value: "var(--tgph-color-VARIABLE)" },
|
|
361
362
|
}),
|
|
362
363
|
[],
|
|
@@ -394,7 +395,7 @@ const customCssVars = {
|
|
|
394
395
|
The Style Engine integrates deeply with Telegraph design tokens:
|
|
395
396
|
|
|
396
397
|
- **Color System**: `var(--tgph-blue-9)`, `var(--tgph-gray-3)`, etc.
|
|
397
|
-
- **Spacing Scale**: `var(--tgph-
|
|
398
|
+
- **Spacing Scale**: `var(--tgph-spacing-1)` through `var(--tgph-spacing-12)`
|
|
398
399
|
- **Typography**: Font sizes, weights, and line heights
|
|
399
400
|
- **Radius Scale**: Border radius values
|
|
400
401
|
- **Shadows**: Box shadow definitions
|
|
@@ -405,8 +406,8 @@ The Style Engine integrates deeply with Telegraph design tokens:
|
|
|
405
406
|
```css
|
|
406
407
|
.custom-component {
|
|
407
408
|
/* Spacing tokens */
|
|
408
|
-
padding: var(--tgph-
|
|
409
|
-
margin: var(--tgph-
|
|
409
|
+
padding: var(--tgph-spacing-4);
|
|
410
|
+
margin: var(--tgph-spacing-2) var(--tgph-spacing-3);
|
|
410
411
|
|
|
411
412
|
/* Color tokens */
|
|
412
413
|
background: var(--tgph-blue-3);
|
|
@@ -459,7 +460,7 @@ npm ls @telegraph/tokens @telegraph/button
|
|
|
459
460
|
```tsx
|
|
460
461
|
// Ensure cssVars object uses 'as const'
|
|
461
462
|
const cssVars = {
|
|
462
|
-
p: { cssVar: "--tgph-padding", value: "var(--tgph-
|
|
463
|
+
p: { cssVar: "--tgph-padding", value: "var(--tgph-spacing-VARIABLE)" },
|
|
463
464
|
} as const; // <- Important!
|
|
464
465
|
```
|
|
465
466
|
|
|
@@ -471,7 +472,7 @@ const cssVars = {
|
|
|
471
472
|
import { useStyleEngine } from "@telegraph/style-engine";
|
|
472
473
|
|
|
473
474
|
const cssVars = {
|
|
474
|
-
p: { cssVar: "--tgph-padding", value: "var(--tgph-
|
|
475
|
+
p: { cssVar: "--tgph-padding", value: "var(--tgph-spacing-VARIABLE)" },
|
|
475
476
|
bg: { cssVar: "--tgph-background", value: "var(--tgph-color-VARIABLE)" },
|
|
476
477
|
} as const;
|
|
477
478
|
|
|
@@ -490,56 +491,48 @@ export const SimpleBox = (props) => {
|
|
|
490
491
|
### Advanced Example
|
|
491
492
|
|
|
492
493
|
```tsx
|
|
493
|
-
import {
|
|
494
|
-
RESPONSIVE_STYLE_PROPS,
|
|
495
|
-
useStyleEngine,
|
|
496
|
-
} from "@telegraph/style-engine";
|
|
494
|
+
import { useStyleEngine } from "@telegraph/style-engine";
|
|
497
495
|
|
|
498
496
|
const advancedCssVars = {
|
|
499
497
|
// Spacing
|
|
500
498
|
p: {
|
|
501
499
|
cssVar: "--tgph-padding",
|
|
502
|
-
value: "var(--tgph-
|
|
500
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
503
501
|
direction: "all",
|
|
504
502
|
},
|
|
505
503
|
pt: {
|
|
506
504
|
cssVar: "--tgph-padding",
|
|
507
|
-
value: "var(--tgph-
|
|
505
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
508
506
|
direction: "top",
|
|
509
507
|
},
|
|
510
508
|
pr: {
|
|
511
509
|
cssVar: "--tgph-padding",
|
|
512
|
-
value: "var(--tgph-
|
|
510
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
513
511
|
direction: "right",
|
|
514
512
|
},
|
|
515
513
|
pb: {
|
|
516
514
|
cssVar: "--tgph-padding",
|
|
517
|
-
value: "var(--tgph-
|
|
515
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
518
516
|
direction: "bottom",
|
|
519
517
|
},
|
|
520
518
|
pl: {
|
|
521
519
|
cssVar: "--tgph-padding",
|
|
522
|
-
value: "var(--tgph-
|
|
520
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
523
521
|
direction: "left",
|
|
524
522
|
},
|
|
525
523
|
px: {
|
|
526
524
|
cssVar: "--tgph-padding",
|
|
527
|
-
value: "var(--tgph-
|
|
525
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
528
526
|
direction: "x",
|
|
529
527
|
},
|
|
530
528
|
py: {
|
|
531
529
|
cssVar: "--tgph-padding",
|
|
532
|
-
value: "var(--tgph-
|
|
530
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
533
531
|
direction: "y",
|
|
534
532
|
},
|
|
535
533
|
|
|
536
|
-
// Colors
|
|
534
|
+
// Colors
|
|
537
535
|
bg: { cssVar: "--tgph-background", value: "var(--tgph-color-VARIABLE)" },
|
|
538
|
-
hoverBg: {
|
|
539
|
-
cssVar: "--tgph-hover-bg",
|
|
540
|
-
value: "var(--tgph-color-VARIABLE)",
|
|
541
|
-
interactive: true,
|
|
542
|
-
},
|
|
543
536
|
|
|
544
537
|
// Layout
|
|
545
538
|
w: { cssVar: "--tgph-width", value: "VARIABLE" },
|
|
@@ -558,11 +551,8 @@ export const AdvancedBox = ({ children, ...props }) => {
|
|
|
558
551
|
|
|
559
552
|
return (
|
|
560
553
|
<div
|
|
561
|
-
className={interactive ? "tgph-interactive" :
|
|
562
|
-
style={
|
|
563
|
-
...styleProp,
|
|
564
|
-
transition: interactive ? "all 0.2s ease" : undefined,
|
|
565
|
-
}}
|
|
554
|
+
className={`tgph-advanced-box${interactive ? " tgph-advanced-box--interactive" : ""}`}
|
|
555
|
+
style={styleProp}
|
|
566
556
|
{...otherProps}
|
|
567
557
|
>
|
|
568
558
|
{children}
|
|
@@ -570,8 +560,15 @@ export const AdvancedBox = ({ children, ...props }) => {
|
|
|
570
560
|
);
|
|
571
561
|
};
|
|
572
562
|
|
|
573
|
-
// Usage
|
|
574
|
-
<AdvancedBox
|
|
563
|
+
// Usage — pseudo-class styles use object syntax
|
|
564
|
+
<AdvancedBox
|
|
565
|
+
p="4"
|
|
566
|
+
px="6"
|
|
567
|
+
bg="blue-3"
|
|
568
|
+
_hover={{ bg: "blue-4" }}
|
|
569
|
+
rounded="2"
|
|
570
|
+
w="200px"
|
|
571
|
+
>
|
|
575
572
|
Interactive Content
|
|
576
573
|
</AdvancedBox>;
|
|
577
574
|
```
|
|
@@ -594,7 +591,7 @@ const buttonCssVars = {
|
|
|
594
591
|
},
|
|
595
592
|
p: {
|
|
596
593
|
cssVar: "--tgph-padding",
|
|
597
|
-
value: "var(--tgph-
|
|
594
|
+
value: "var(--tgph-spacing-VARIABLE)",
|
|
598
595
|
direction: "all"
|
|
599
596
|
}
|
|
600
597
|
} as const;
|
|
@@ -616,7 +613,7 @@ export const CustomButton = forwardRef<HTMLButtonElement, CustomButtonProps>(
|
|
|
616
613
|
return (
|
|
617
614
|
<button
|
|
618
615
|
ref={ref}
|
|
619
|
-
className={`custom-button
|
|
616
|
+
className={`custom-button${interactive ? " custom-button--interactive" : ""}`}
|
|
620
617
|
style={styleProp}
|
|
621
618
|
{...otherProps}
|
|
622
619
|
>
|
|
@@ -626,13 +623,13 @@ export const CustomButton = forwardRef<HTMLButtonElement, CustomButtonProps>(
|
|
|
626
623
|
}
|
|
627
624
|
);
|
|
628
625
|
|
|
629
|
-
// Corresponding CSS
|
|
626
|
+
// Corresponding CSS — use @telegraph interactive() to auto-generate pseudo rules
|
|
630
627
|
/* button.css */
|
|
631
628
|
@telegraph tokens;
|
|
632
629
|
|
|
633
630
|
.custom-button {
|
|
634
631
|
background: var(--tgph-button-variant, var(--tgph-blue-9));
|
|
635
|
-
padding: var(--tgph-padding, var(--tgph-
|
|
632
|
+
padding: var(--tgph-padding, var(--tgph-spacing-2) var(--tgph-spacing-3));
|
|
636
633
|
font-size: var(--tgph-button-size, var(--tgph-font-size-1));
|
|
637
634
|
border-radius: var(--tgph-radius-2);
|
|
638
635
|
border: none;
|
|
@@ -640,9 +637,8 @@ export const CustomButton = forwardRef<HTMLButtonElement, CustomButtonProps>(
|
|
|
640
637
|
transition: all 0.2s ease;
|
|
641
638
|
}
|
|
642
639
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
}
|
|
640
|
+
/* Auto-generates :hover, :focus-visible, :active, :has(:focus-visible), :disabled rules */
|
|
641
|
+
@telegraph interactive(.custom-button);
|
|
646
642
|
```
|
|
647
643
|
|
|
648
644
|
## References
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),w={transparent:"var(--tgph-transparent)",white:"var(--tgph-white)",black:"var(--tgph-black)","surface-1":"var(--tgph-surface-1)","surface-2":"var(--tgph-surface-2)","alpha-white-1":"var(--tgph-alpha-white-1)","alpha-white-2":"var(--tgph-alpha-white-2)","alpha-white-3":"var(--tgph-alpha-white-3)","alpha-white-4":"var(--tgph-alpha-white-4)","alpha-white-5":"var(--tgph-alpha-white-5)","alpha-white-6":"var(--tgph-alpha-white-6)","alpha-white-7":"var(--tgph-alpha-white-7)","alpha-white-8":"var(--tgph-alpha-white-8)","alpha-white-9":"var(--tgph-alpha-white-9)","alpha-white-10":"var(--tgph-alpha-white-10)","alpha-white-11":"var(--tgph-alpha-white-11)","alpha-white-12":"var(--tgph-alpha-white-12)","alpha-black-1":"var(--tgph-alpha-black-1)","alpha-black-2":"var(--tgph-alpha-black-2)","alpha-black-3":"var(--tgph-alpha-black-3)","alpha-black-4":"var(--tgph-alpha-black-4)","alpha-black-5":"var(--tgph-alpha-black-5)","alpha-black-6":"var(--tgph-alpha-black-6)","alpha-black-7":"var(--tgph-alpha-black-7)","alpha-black-8":"var(--tgph-alpha-black-8)","alpha-black-9":"var(--tgph-alpha-black-9)","alpha-black-10":"var(--tgph-alpha-black-10)","alpha-black-11":"var(--tgph-alpha-black-11)","alpha-black-12":"var(--tgph-alpha-black-12)","gray-1":"var(--tgph-gray-1)","gray-2":"var(--tgph-gray-2)","gray-3":"var(--tgph-gray-3)","gray-4":"var(--tgph-gray-4)","gray-5":"var(--tgph-gray-5)","gray-6":"var(--tgph-gray-6)","gray-7":"var(--tgph-gray-7)","gray-8":"var(--tgph-gray-8)","gray-9":"var(--tgph-gray-9)","gray-10":"var(--tgph-gray-10)","gray-11":"var(--tgph-gray-11)","gray-12":"var(--tgph-gray-12)","beige-1":"var(--tgph-beige-1)","beige-2":"var(--tgph-beige-2)","beige-3":"var(--tgph-beige-3)","beige-4":"var(--tgph-beige-4)","beige-5":"var(--tgph-beige-5)","beige-6":"var(--tgph-beige-6)","beige-7":"var(--tgph-beige-7)","beige-8":"var(--tgph-beige-8)","beige-9":"var(--tgph-beige-9)","beige-10":"var(--tgph-beige-10)","beige-11":"var(--tgph-beige-11)","beige-12":"var(--tgph-beige-12)","accent-1":"var(--tgph-accent-1)","accent-2":"var(--tgph-accent-2)","accent-3":"var(--tgph-accent-3)","accent-4":"var(--tgph-accent-4)","accent-5":"var(--tgph-accent-5)","accent-6":"var(--tgph-accent-6)","accent-7":"var(--tgph-accent-7)","accent-8":"var(--tgph-accent-8)","accent-9":"var(--tgph-accent-9)","accent-10":"var(--tgph-accent-10)","accent-11":"var(--tgph-accent-11)","accent-12":"var(--tgph-accent-12)","green-1":"var(--tgph-green-1)","green-2":"var(--tgph-green-2)","green-3":"var(--tgph-green-3)","green-4":"var(--tgph-green-4)","green-5":"var(--tgph-green-5)","green-6":"var(--tgph-green-6)","green-7":"var(--tgph-green-7)","green-8":"var(--tgph-green-8)","green-9":"var(--tgph-green-9)","green-10":"var(--tgph-green-10)","green-11":"var(--tgph-green-11)","green-12":"var(--tgph-green-12)","yellow-1":"var(--tgph-yellow-1)","yellow-2":"var(--tgph-yellow-2)","yellow-3":"var(--tgph-yellow-3)","yellow-4":"var(--tgph-yellow-4)","yellow-5":"var(--tgph-yellow-5)","yellow-6":"var(--tgph-yellow-6)","yellow-7":"var(--tgph-yellow-7)","yellow-8":"var(--tgph-yellow-8)","yellow-9":"var(--tgph-yellow-9)","yellow-10":"var(--tgph-yellow-10)","yellow-11":"var(--tgph-yellow-11)","yellow-12":"var(--tgph-yellow-12)","blue-1":"var(--tgph-blue-1)","blue-2":"var(--tgph-blue-2)","blue-3":"var(--tgph-blue-3)","blue-4":"var(--tgph-blue-4)","blue-5":"var(--tgph-blue-5)","blue-6":"var(--tgph-blue-6)","blue-7":"var(--tgph-blue-7)","blue-8":"var(--tgph-blue-8)","blue-9":"var(--tgph-blue-9)","blue-10":"var(--tgph-blue-10)","blue-11":"var(--tgph-blue-11)","blue-12":"var(--tgph-blue-12)","red-1":"var(--tgph-red-1)","red-2":"var(--tgph-red-2)","red-3":"var(--tgph-red-3)","red-4":"var(--tgph-red-4)","red-5":"var(--tgph-red-5)","red-6":"var(--tgph-red-6)","red-7":"var(--tgph-red-7)","red-8":"var(--tgph-red-8)","red-9":"var(--tgph-red-9)","red-10":"var(--tgph-red-10)","red-11":"var(--tgph-red-11)","red-12":"var(--tgph-red-12)","purple-1":"var(--tgph-purple-1)","purple-2":"var(--tgph-purple-2)","purple-3":"var(--tgph-purple-3)","purple-4":"var(--tgph-purple-4)","purple-5":"var(--tgph-purple-5)","purple-6":"var(--tgph-purple-6)","purple-7":"var(--tgph-purple-7)","purple-8":"var(--tgph-purple-8)","purple-9":"var(--tgph-purple-9)","purple-10":"var(--tgph-purple-10)","purple-11":"var(--tgph-purple-11)","purple-12":"var(--tgph-purple-12)"},k={0:"var(--tgph-rounded-0)",1:"var(--tgph-rounded-1)",2:"var(--tgph-rounded-2)",3:"var(--tgph-rounded-3)",4:"var(--tgph-rounded-4)",5:"var(--tgph-rounded-5)",6:"var(--tgph-rounded-6)",full:"var(--tgph-rounded-full)"},f={0:"var(--tgph-shadow-0)",1:"var(--tgph-shadow-1)",2:"var(--tgph-shadow-2)",3:"var(--tgph-shadow-3)",inner:"var(--tgph-shadow-inner)"},x={0:"var(--tgph-spacing-0)",1:"var(--tgph-spacing-1)",2:"var(--tgph-spacing-2)",3:"var(--tgph-spacing-3)",4:"var(--tgph-spacing-4)",5:"var(--tgph-spacing-5)",6:"var(--tgph-spacing-6)",7:"var(--tgph-spacing-7)",8:"var(--tgph-spacing-8)",9:"var(--tgph-spacing-9)",10:"var(--tgph-spacing-10)",11:"var(--tgph-spacing-11)",12:"var(--tgph-spacing-12)",14:"var(--tgph-spacing-14)",16:"var(--tgph-spacing-16)",20:"var(--tgph-spacing-20)",24:"var(--tgph-spacing-24)",28:"var(--tgph-spacing-28)",32:"var(--tgph-spacing-32)",36:"var(--tgph-spacing-36)",40:"var(--tgph-spacing-40)",44:"var(--tgph-spacing-44)",48:"var(--tgph-spacing-48)",52:"var(--tgph-spacing-52)",56:"var(--tgph-spacing-56)",60:"var(--tgph-spacing-60)",64:"var(--tgph-spacing-64)",72:"var(--tgph-spacing-72)",80:"var(--tgph-spacing-80)",96:"var(--tgph-spacing-96)",120:"var(--tgph-spacing-120)",140:"var(--tgph-spacing-140)",160:"var(--tgph-spacing-160)",px:"var(--tgph-spacing-px)","0_5":"var(--tgph-spacing-0_5)","1_5":"var(--tgph-spacing-1_5)","2_5":"var(--tgph-spacing-2_5)","3_5":"var(--tgph-spacing-3_5)",full:"var(--tgph-spacing-full)",auto:"var(--tgph-spacing-auto)"},m={sans:"var(--tgph-family-sans)",mono:"var(--tgph-family-mono)"},V={0:"var(--tgph-leading-0)",1:"var(--tgph-leading-1)",2:"var(--tgph-leading-2)",3:"var(--tgph-leading-3)",4:"var(--tgph-leading-4)",5:"var(--tgph-leading-5)",6:"var(--tgph-leading-6)",7:"var(--tgph-leading-7)",8:"var(--tgph-leading-8)",9:"var(--tgph-leading-9)","code-0":"var(--tgph-leading-code-0)","code-1":"var(--tgph-leading-code-1)","code-2":"var(--tgph-leading-code-2)","code-3":"var(--tgph-leading-code-3)","code-4":"var(--tgph-leading-code-4)","code-5":"var(--tgph-leading-code-5)","code-6":"var(--tgph-leading-code-6)","code-7":"var(--tgph-leading-code-7)","code-8":"var(--tgph-leading-code-8)","code-9":"var(--tgph-leading-code-9)"},I={0:"var(--tgph-tracking-0)",1:"var(--tgph-tracking-1)",2:"var(--tgph-tracking-2)",3:"var(--tgph-tracking-3)",4:"var(--tgph-tracking-4)",5:"var(--tgph-tracking-5)",6:"var(--tgph-tracking-6)",7:"var(--tgph-tracking-7)",8:"var(--tgph-tracking-8)",9:"var(--tgph-tracking-9)"},z={0:"var(--tgph-text-0)",1:"var(--tgph-text-1)",2:"var(--tgph-text-2)",3:"var(--tgph-text-3)",4:"var(--tgph-text-4)",5:"var(--tgph-text-5)",6:"var(--tgph-text-6)",7:"var(--tgph-text-7)",8:"var(--tgph-text-8)",9:"var(--tgph-text-9)","code-0":"var(--tgph-text-code-0)","code-1":"var(--tgph-text-code-1)","code-2":"var(--tgph-text-code-2)","code-4":"var(--tgph-text-code-4)","code-5":"var(--tgph-text-code-5)","code-6":"var(--tgph-text-code-6)","code-7":"var(--tgph-text-code-7)","code-8":"var(--tgph-text-code-8)","code-9":"var(--tgph-text-code-9)"},O={regular:"var(--tgph-weight-regular)",medium:"var(--tgph-weight-medium)","semi-bold":"var(--tgph-weight-semi-bold)"},S={sm:"var(--tgph-breakpoint-sm)",md:"var(--tgph-breakpoint-md)",lg:"var(--tgph-breakpoint-lg)",xl:"var(--tgph-breakpoint-xl)","2xl":"var(--tgph-breakpoint-2xl)"},_={hidden:"var(--tgph-zIndex-hidden)",base:"var(--tgph-zIndex-base)",auto:"var(--tgph-zIndex-auto)",dropdown:"var(--tgph-zIndex-dropdown)",sticky:"var(--tgph-zIndex-sticky)",banner:"var(--tgph-zIndex-banner)",overlay:"var(--tgph-zIndex-overlay)",modal:"var(--tgph-zIndex-modal)",popover:"var(--tgph-zIndex-popover)",skipLink:"var(--tgph-zIndex-skipLink)",toast:"var(--tgph-zIndex-toast)",tooltip:"var(--tgph-zIndex-tooltip)"},j={"border-style":{solid:"var(--tgph-border-style-solid)",dashed:"var(--tgph-border-style-dashed)"},color:w,rounded:k,shadow:f,spacing:x,family:m,leading:V,tracking:I,text:z,weight:O,breakpoint:S,zIndex:_},$=p=>{const a=[];let t="",g=0;for(let r=0;r<p.length;r++){const h=p[r];h==="("?(g++,t+=h):h===")"?(g--,t+=h):h===" "&&g===0?t&&(a.push(t),t=""):t+=h}for(t&&a.push(t);a.length<4;)a.push("0");return[a[0]||"0",a[1]||"0",a[2]||"0",a[3]||"0"]},A=({currentValueOfCssVar:p="0 0 0 0",value:a,direction:t})=>{const[g,r,h,s]=$(p),e={top:g,right:r,bottom:h,left:s};return t==="top"&&(e.top=a),t==="right"&&(e.right=a),t==="bottom"&&(e.bottom=a),t==="left"&&(e.left=a),t==="all"&&(e.top=a,e.right=a,e.bottom=a,e.left=a),t==="x"&&(e.left=a,e.right=a),t==="y"&&(e.top=a,e.bottom=a),t==="side-top"&&(e.top=a,e.right=a),t==="side-bottom"&&(e.bottom=a,e.left=a),t==="side-left"&&(e.top=a,e.left=a),t==="side-right"&&(e.right=a,e.bottom=a),Object.values(e).join(" ")},E=({currentValueOfCssVar:p="visible visible",value:a,axis:t})=>{const[g,r]=p.split(" ");return t==="x"?`${a} ${r}`:t==="y"?`${g} ${a}`:`${a} ${a}`},b=p=>{const{cssVars:a}=p;if(!(p!=null&&p.props)||Object.keys(p.props).length===0)return{styleProp:{},otherProps:{},interactive:!1};const{style:t={},...g}=p.props;let r=t;const h={};let s=!1;return Object.keys(g).forEach(e=>{const v=e,u=v,l=a==null?void 0:a[u];if(!l){Object.assign(h,{[v]:g[v]});return}const n=g==null?void 0:g[v];if(!n){Object.assign(r,{[v]:g[v]});return}let c;if(typeof n=="string"&&n.startsWith("-")){const o=n.slice(1);c=`calc(-1 * ${l.value.replace("VARIABLE",o)})`}else c=l.value.replace("VARIABLE",n);const i=l.cssVar;if(l.interactive&&(s=!0),l.direction){const o=r==null?void 0:r[i],d=A({currentValueOfCssVar:o,value:c,direction:l.direction});r={...r,[i]:d};return}if(l.axis){const o=r==null?void 0:r[i],d=E({currentValueOfCssVar:o,value:c,axis:l.axis});r={...r,[i]:d};return}r={...r,[i]:c}}),{styleProp:r,otherProps:h,interactive:s}},C=p=>y.useMemo(()=>b(p),[p]);exports.getStyleProp=b;exports.tokens=j;exports.useStyleEngine=C;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("react"),I={transparent:"var(--tgph-transparent)",white:"var(--tgph-white)",black:"var(--tgph-black)","surface-1":"var(--tgph-surface-1)","surface-2":"var(--tgph-surface-2)","surface-3":"var(--tgph-surface-3)","alpha-white-1":"var(--tgph-alpha-white-1)","alpha-white-2":"var(--tgph-alpha-white-2)","alpha-white-3":"var(--tgph-alpha-white-3)","alpha-white-4":"var(--tgph-alpha-white-4)","alpha-white-5":"var(--tgph-alpha-white-5)","alpha-white-6":"var(--tgph-alpha-white-6)","alpha-white-7":"var(--tgph-alpha-white-7)","alpha-white-8":"var(--tgph-alpha-white-8)","alpha-white-9":"var(--tgph-alpha-white-9)","alpha-white-10":"var(--tgph-alpha-white-10)","alpha-white-11":"var(--tgph-alpha-white-11)","alpha-white-12":"var(--tgph-alpha-white-12)","alpha-black-1":"var(--tgph-alpha-black-1)","alpha-black-2":"var(--tgph-alpha-black-2)","alpha-black-3":"var(--tgph-alpha-black-3)","alpha-black-4":"var(--tgph-alpha-black-4)","alpha-black-5":"var(--tgph-alpha-black-5)","alpha-black-6":"var(--tgph-alpha-black-6)","alpha-black-7":"var(--tgph-alpha-black-7)","alpha-black-8":"var(--tgph-alpha-black-8)","alpha-black-9":"var(--tgph-alpha-black-9)","alpha-black-10":"var(--tgph-alpha-black-10)","alpha-black-11":"var(--tgph-alpha-black-11)","alpha-black-12":"var(--tgph-alpha-black-12)","gray-1":"var(--tgph-gray-1)","gray-2":"var(--tgph-gray-2)","gray-3":"var(--tgph-gray-3)","gray-4":"var(--tgph-gray-4)","gray-5":"var(--tgph-gray-5)","gray-6":"var(--tgph-gray-6)","gray-7":"var(--tgph-gray-7)","gray-8":"var(--tgph-gray-8)","gray-9":"var(--tgph-gray-9)","gray-10":"var(--tgph-gray-10)","gray-11":"var(--tgph-gray-11)","gray-12":"var(--tgph-gray-12)","beige-1":"var(--tgph-beige-1)","beige-2":"var(--tgph-beige-2)","beige-3":"var(--tgph-beige-3)","beige-4":"var(--tgph-beige-4)","beige-5":"var(--tgph-beige-5)","beige-6":"var(--tgph-beige-6)","beige-7":"var(--tgph-beige-7)","beige-8":"var(--tgph-beige-8)","beige-9":"var(--tgph-beige-9)","beige-10":"var(--tgph-beige-10)","beige-11":"var(--tgph-beige-11)","beige-12":"var(--tgph-beige-12)","accent-1":"var(--tgph-accent-1)","accent-2":"var(--tgph-accent-2)","accent-3":"var(--tgph-accent-3)","accent-4":"var(--tgph-accent-4)","accent-5":"var(--tgph-accent-5)","accent-6":"var(--tgph-accent-6)","accent-7":"var(--tgph-accent-7)","accent-8":"var(--tgph-accent-8)","accent-9":"var(--tgph-accent-9)","accent-10":"var(--tgph-accent-10)","accent-11":"var(--tgph-accent-11)","accent-12":"var(--tgph-accent-12)","green-1":"var(--tgph-green-1)","green-2":"var(--tgph-green-2)","green-3":"var(--tgph-green-3)","green-4":"var(--tgph-green-4)","green-5":"var(--tgph-green-5)","green-6":"var(--tgph-green-6)","green-7":"var(--tgph-green-7)","green-8":"var(--tgph-green-8)","green-9":"var(--tgph-green-9)","green-10":"var(--tgph-green-10)","green-11":"var(--tgph-green-11)","green-12":"var(--tgph-green-12)","yellow-1":"var(--tgph-yellow-1)","yellow-2":"var(--tgph-yellow-2)","yellow-3":"var(--tgph-yellow-3)","yellow-4":"var(--tgph-yellow-4)","yellow-5":"var(--tgph-yellow-5)","yellow-6":"var(--tgph-yellow-6)","yellow-7":"var(--tgph-yellow-7)","yellow-8":"var(--tgph-yellow-8)","yellow-9":"var(--tgph-yellow-9)","yellow-10":"var(--tgph-yellow-10)","yellow-11":"var(--tgph-yellow-11)","yellow-12":"var(--tgph-yellow-12)","blue-1":"var(--tgph-blue-1)","blue-2":"var(--tgph-blue-2)","blue-3":"var(--tgph-blue-3)","blue-4":"var(--tgph-blue-4)","blue-5":"var(--tgph-blue-5)","blue-6":"var(--tgph-blue-6)","blue-7":"var(--tgph-blue-7)","blue-8":"var(--tgph-blue-8)","blue-9":"var(--tgph-blue-9)","blue-10":"var(--tgph-blue-10)","blue-11":"var(--tgph-blue-11)","blue-12":"var(--tgph-blue-12)","red-1":"var(--tgph-red-1)","red-2":"var(--tgph-red-2)","red-3":"var(--tgph-red-3)","red-4":"var(--tgph-red-4)","red-5":"var(--tgph-red-5)","red-6":"var(--tgph-red-6)","red-7":"var(--tgph-red-7)","red-8":"var(--tgph-red-8)","red-9":"var(--tgph-red-9)","red-10":"var(--tgph-red-10)","red-11":"var(--tgph-red-11)","red-12":"var(--tgph-red-12)","purple-1":"var(--tgph-purple-1)","purple-2":"var(--tgph-purple-2)","purple-3":"var(--tgph-purple-3)","purple-4":"var(--tgph-purple-4)","purple-5":"var(--tgph-purple-5)","purple-6":"var(--tgph-purple-6)","purple-7":"var(--tgph-purple-7)","purple-8":"var(--tgph-purple-8)","purple-9":"var(--tgph-purple-9)","purple-10":"var(--tgph-purple-10)","purple-11":"var(--tgph-purple-11)","purple-12":"var(--tgph-purple-12)"},j={0:"var(--tgph-rounded-0)",1:"var(--tgph-rounded-1)",2:"var(--tgph-rounded-2)",3:"var(--tgph-rounded-3)",4:"var(--tgph-rounded-4)",5:"var(--tgph-rounded-5)",6:"var(--tgph-rounded-6)",full:"var(--tgph-rounded-full)"},z={0:"var(--tgph-shadow-0)",1:"var(--tgph-shadow-1)",2:"var(--tgph-shadow-2)",3:"var(--tgph-shadow-3)",inner:"var(--tgph-shadow-inner)"},E={0:"var(--tgph-spacing-0)",1:"var(--tgph-spacing-1)",2:"var(--tgph-spacing-2)",3:"var(--tgph-spacing-3)",4:"var(--tgph-spacing-4)",5:"var(--tgph-spacing-5)",6:"var(--tgph-spacing-6)",7:"var(--tgph-spacing-7)",8:"var(--tgph-spacing-8)",9:"var(--tgph-spacing-9)",10:"var(--tgph-spacing-10)",11:"var(--tgph-spacing-11)",12:"var(--tgph-spacing-12)",14:"var(--tgph-spacing-14)",16:"var(--tgph-spacing-16)",20:"var(--tgph-spacing-20)",24:"var(--tgph-spacing-24)",28:"var(--tgph-spacing-28)",32:"var(--tgph-spacing-32)",36:"var(--tgph-spacing-36)",40:"var(--tgph-spacing-40)",44:"var(--tgph-spacing-44)",48:"var(--tgph-spacing-48)",52:"var(--tgph-spacing-52)",56:"var(--tgph-spacing-56)",60:"var(--tgph-spacing-60)",64:"var(--tgph-spacing-64)",72:"var(--tgph-spacing-72)",80:"var(--tgph-spacing-80)",96:"var(--tgph-spacing-96)",120:"var(--tgph-spacing-120)",140:"var(--tgph-spacing-140)",160:"var(--tgph-spacing-160)",px:"var(--tgph-spacing-px)","0_5":"var(--tgph-spacing-0_5)","1_5":"var(--tgph-spacing-1_5)","2_5":"var(--tgph-spacing-2_5)","3_5":"var(--tgph-spacing-3_5)",full:"var(--tgph-spacing-full)",auto:"var(--tgph-spacing-auto)"},$={sans:"var(--tgph-family-sans)",mono:"var(--tgph-family-mono)"},A={0:"var(--tgph-leading-0)",1:"var(--tgph-leading-1)",2:"var(--tgph-leading-2)",3:"var(--tgph-leading-3)",4:"var(--tgph-leading-4)",5:"var(--tgph-leading-5)",6:"var(--tgph-leading-6)",7:"var(--tgph-leading-7)",8:"var(--tgph-leading-8)",9:"var(--tgph-leading-9)","code-0":"var(--tgph-leading-code-0)","code-1":"var(--tgph-leading-code-1)","code-2":"var(--tgph-leading-code-2)","code-3":"var(--tgph-leading-code-3)","code-4":"var(--tgph-leading-code-4)","code-5":"var(--tgph-leading-code-5)","code-6":"var(--tgph-leading-code-6)","code-7":"var(--tgph-leading-code-7)","code-8":"var(--tgph-leading-code-8)","code-9":"var(--tgph-leading-code-9)"},N={0:"var(--tgph-tracking-0)",1:"var(--tgph-tracking-1)",2:"var(--tgph-tracking-2)",3:"var(--tgph-tracking-3)",4:"var(--tgph-tracking-4)",5:"var(--tgph-tracking-5)",6:"var(--tgph-tracking-6)",7:"var(--tgph-tracking-7)",8:"var(--tgph-tracking-8)",9:"var(--tgph-tracking-9)"},D={0:"var(--tgph-text-0)",1:"var(--tgph-text-1)",2:"var(--tgph-text-2)",3:"var(--tgph-text-3)",4:"var(--tgph-text-4)",5:"var(--tgph-text-5)",6:"var(--tgph-text-6)",7:"var(--tgph-text-7)",8:"var(--tgph-text-8)",9:"var(--tgph-text-9)","code-0":"var(--tgph-text-code-0)","code-1":"var(--tgph-text-code-1)","code-2":"var(--tgph-text-code-2)","code-4":"var(--tgph-text-code-4)","code-5":"var(--tgph-text-code-5)","code-6":"var(--tgph-text-code-6)","code-7":"var(--tgph-text-code-7)","code-8":"var(--tgph-text-code-8)","code-9":"var(--tgph-text-code-9)"},T={regular:"var(--tgph-weight-regular)",medium:"var(--tgph-weight-medium)","semi-bold":"var(--tgph-weight-semi-bold)"},C={sm:"var(--tgph-breakpoint-sm)",md:"var(--tgph-breakpoint-md)",lg:"var(--tgph-breakpoint-lg)",xl:"var(--tgph-breakpoint-xl)","2xl":"var(--tgph-breakpoint-2xl)"},L={hidden:"var(--tgph-zIndex-hidden)",base:"var(--tgph-zIndex-base)",auto:"var(--tgph-zIndex-auto)",dropdown:"var(--tgph-zIndex-dropdown)",sticky:"var(--tgph-zIndex-sticky)",banner:"var(--tgph-zIndex-banner)",overlay:"var(--tgph-zIndex-overlay)",modal:"var(--tgph-zIndex-modal)",popover:"var(--tgph-zIndex-popover)",skipLink:"var(--tgph-zIndex-skipLink)",toast:"var(--tgph-zIndex-toast)",tooltip:"var(--tgph-zIndex-tooltip)"},R={"border-style":{solid:"var(--tgph-border-style-solid)",dashed:"var(--tgph-border-style-dashed)"},color:I,rounded:j,shadow:z,spacing:E,family:$,leading:A,tracking:N,text:D,weight:T,breakpoint:C,zIndex:L},w=["_hover","_focus","_active","_focusWithin","_disabled"],P={_hover:"hover",_focus:"focus",_active:"active",_focusWithin:"focus-within",_disabled:"disabled"},U=e=>{const a=[];let t="",g=0;for(let p=0;p<e.length;p++){const h=e[p];h==="("?(g++,t+=h):h===")"?(g--,t+=h):h===" "&&g===0?t&&(a.push(t),t=""):t+=h}for(t&&a.push(t);a.length<4;)a.push("0");return[a[0]||"0",a[1]||"0",a[2]||"0",a[3]||"0"]},W=({currentValueOfCssVar:e="0 0 0 0",value:a,direction:t})=>{const[g,p,h,c]=U(e),r={top:g,right:p,bottom:h,left:c};return t==="top"&&(r.top=a),t==="right"&&(r.right=a),t==="bottom"&&(r.bottom=a),t==="left"&&(r.left=a),t==="all"&&(r.top=a,r.right=a,r.bottom=a,r.left=a),t==="x"&&(r.left=a,r.right=a),t==="y"&&(r.top=a,r.bottom=a),t==="side-top"&&(r.top=a,r.right=a),t==="side-bottom"&&(r.bottom=a,r.left=a),t==="side-left"&&(r.top=a,r.left=a),t==="side-right"&&(r.right=a,r.bottom=a),Object.values(r).join(" ")},B=({currentValueOfCssVar:e="visible visible",value:a,axis:t})=>{const[g,p]=e.split(" ");return t==="x"?`${a} ${p}`:t==="y"?`${g} ${a}`:`${a} ${a}`},u=(e,a)=>{if(typeof a=="string"&&a.startsWith("-")){const g=a.slice(1);return`calc(-1 * ${e.value.replace("VARIABLE",g)})`}return e.value.replace("VARIABLE",a)},f=(e,a,t,g)=>{const p=g??a.cssVar;if(a.direction){const h=e==null?void 0:e[p],c=W({currentValueOfCssVar:h,value:t,direction:a.direction});return{...e,[p]:c}}if(a.axis){const h=e==null?void 0:e[p],c=B({currentValueOfCssVar:h,value:t,axis:a.axis});return{...e,[p]:c}}return{...e,[p]:t}},M=(e,a)=>{const t=P[a],g=e.replace(/^--/,"");return`--${t}--${g}`},y=e=>{const{cssVars:a}=e;if(!(e!=null&&e.props)||Object.keys(e.props).length===0)return{styleProp:{},otherProps:{},interactive:!1};const{style:t={},...g}=e.props;let p=t;const h={};let c=!1;return Object.keys(g).forEach(r=>{const n=r;if(w.includes(r)&&typeof g[n]=="object"&&g[n]!==null){const m=r,s=g[n],v={};if(Object.keys(s).forEach(l=>{const d=s[l];if(!d)return;const V=l,i=a==null?void 0:a[V];if(!i){v[l]=d;return}const S=u(i,d),_=M(i.cssVar,m);p=f(p,i,S,_)}),Object.keys(v).length>0){const l=h[r]||{};Object.assign(h,{[r]:{...l,...v}})}Object.keys(s).length>Object.keys(v).length&&(c=!0);return}const k=n,o=a==null?void 0:a[k];if(!o){Object.assign(h,{[n]:g[n]});return}const b=g==null?void 0:g[n];if(!b){Object.assign(p,{[n]:g[n]});return}const x=u(o,b);p=f(p,o,x)}),{styleProp:p,otherProps:h,interactive:c}},q=e=>O.useMemo(()=>y(e),[e]);exports.PSEUDO_STATES=w;exports.getStyleProp=y;exports.tokens=R;exports.useStyleEngine=q;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/helpers/getStyleProp/getStyleProp.ts","../../src/hooks/useStyleEngine.ts"],"sourcesContent":["type Direction =\n | \"x\"\n | \"y\"\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"all\"\n | \"side-top\"\n | \"side-bottom\"\n | \"side-left\"\n | \"side-right\";\n\ntype Axis = \"x\" | \"y\" | \"both\";\n\nexport type CssVarProp = {\n cssVar: string;\n value: string;\n direction?: Direction;\n axis?: Axis;\n interactive?: boolean;\n};\n\n// Helper type to create negative spacing values\n// This distributes over union types for proper type expansion\nexport type NegativeSpacing<T extends string | number | symbol> =\n T extends string ? `-${T}` : never;\n\n// Type that allows both positive and negative spacing values for a given token type\n// Using direct template literal for better TypeScript inference and autocomplete\nexport type WithNegativeSpacing<T extends string | number | symbol> =\n T extends string ? T | `-${T}` : T;\n\ntype ApplyDirectionProps = {\n currentValueOfCssVar: string | undefined;\n value: string;\n direction?: Direction;\n};\n\n// Helper function to parse directional values (handles calc() expressions)\nconst parseDirectionalValues = (\n value: string,\n): [string, string, string, string] => {\n const matches: string[] = [];\n let current = \"\";\n let depth = 0;\n\n for (let i = 0; i < value.length; i++) {\n const char = value[i];\n\n if (char === \"(\") {\n depth++;\n current += char;\n } else if (char === \")\") {\n depth--;\n current += char;\n } else if (char === \" \" && depth === 0) {\n // Space at depth 0 means we're between values\n if (current) {\n matches.push(current);\n current = \"\";\n }\n } else {\n current += char;\n }\n }\n\n // Push the last value\n if (current) {\n matches.push(current);\n }\n\n // Ensure we always have 4 values\n while (matches.length < 4) {\n matches.push(\"0\");\n }\n\n return [\n matches[0] || \"0\",\n matches[1] || \"0\",\n matches[2] || \"0\",\n matches[3] || \"0\",\n ];\n};\n\n// For values like margin and padding that require 4 values\nconst applyDirectionalValues = ({\n currentValueOfCssVar = \"0 0 0 0\",\n value,\n direction,\n}: ApplyDirectionProps) => {\n const [top, right, bottom, left] =\n parseDirectionalValues(currentValueOfCssVar);\n\n const newValues = {\n top,\n right,\n bottom,\n left,\n };\n\n if (direction === \"top\") {\n newValues.top = value;\n }\n\n if (direction === \"right\") {\n newValues.right = value;\n }\n\n if (direction === \"bottom\") {\n newValues.bottom = value;\n }\n\n if (direction === \"left\") {\n newValues.left = value;\n }\n\n if (direction === \"all\") {\n newValues.top = value;\n newValues.right = value;\n newValues.bottom = value;\n newValues.left = value;\n }\n\n if (direction === \"x\") {\n newValues.left = value;\n newValues.right = value;\n }\n\n if (direction === \"y\") {\n newValues.top = value;\n newValues.bottom = value;\n }\n\n // \"side\" direction is used for things like border-radius\n // where we are settings values on corners instead of sides\n // entire sides like padding and margin provide.\n if (direction === \"side-top\") {\n newValues.top = value;\n newValues.right = value;\n }\n\n if (direction === \"side-bottom\") {\n newValues.bottom = value;\n newValues.left = value;\n }\n\n if (direction === \"side-left\") {\n newValues.top = value;\n newValues.left = value;\n }\n\n if (direction === \"side-right\") {\n newValues.right = value;\n newValues.bottom = value;\n }\n\n const newValuesString = Object.values(newValues).join(\" \");\n\n return newValuesString;\n};\n\ntype ApplyAxisValuesProps = {\n currentValueOfCssVar: string | undefined;\n value: string;\n axis: Axis;\n};\n\nconst applyAxisValues = ({\n currentValueOfCssVar = \"visible visible\",\n value,\n axis,\n}: ApplyAxisValuesProps) => {\n const [x, y] = currentValueOfCssVar.split(\" \");\n\n // If the axis is x, we need to set the x value and keep the y value.\n if (axis === \"x\") {\n return `${value} ${y}`;\n }\n\n // If the axis is y, we need to set the y value and keep the x value.\n if (axis === \"y\") {\n return `${x} ${value}`;\n }\n\n // If the axis is both, we need to set the x and y values.\n return `${value} ${value}`;\n};\n\nexport type CssVarsPropObject<CssVars extends CssVarsPropObject<CssVars>> =\n Record<keyof CssVars, CssVarProp>;\n\ntype CssVarPropKey<CssVars extends CssVarsPropObject<CssVars>> = keyof CssVars;\n\n// Allow for explicitly defined props that are not css vars to end to end typesafe\ntype OtherProps<CssVars extends CssVarsPropObject<CssVars>, Props> =\n | Omit<\n {\n [key in keyof Props]: Props[key];\n },\n CssVarPropKey<CssVars>\n >\n | object;\n\n// Allow for explicitly defined css vars return css variables object created\n// by this function and be end to end typesafe\ntype StyleProp<CssVars extends CssVarsPropObject<CssVars>> =\n | {\n [key in CssVars[keyof CssVars][\"cssVar\"]]: string;\n }\n | object;\n\ntype GetStylePropParams<CssVars, Props> = {\n props: Props & { style?: Record<string, string> };\n cssVars: CssVars;\n};\n\nexport const getStyleProp = <\n CssVars extends CssVarsPropObject<CssVars>,\n Props extends Record<string, unknown>,\n>(\n params: GetStylePropParams<CssVars, Props>,\n): {\n styleProp: StyleProp<CssVars>;\n otherProps: OtherProps<CssVars, Props>;\n interactive: boolean;\n} => {\n const { cssVars } = params;\n\n if (!params?.props || Object.keys(params.props).length === 0) {\n return { styleProp: {}, otherProps: {}, interactive: false };\n }\n\n // Assign the additional styles to the style object so that it can be passed\n // to the component as a prop.\n const { style = {}, ...props } = params.props;\n\n let styleProp: StyleProp<CssVars> = style;\n const otherProps: OtherProps<CssVars, Props> = {};\n let interactive = false;\n\n Object.keys(props).forEach((_key) => {\n const key = _key as keyof typeof props;\n const cssVarsKey = key as unknown as keyof typeof cssVars;\n const matchingCssVar = cssVars?.[cssVarsKey];\n\n // If the prop is not a css var, just add it to the otherProps\n if (!matchingCssVar) {\n Object.assign(otherProps, { [key]: props[key] });\n return;\n }\n\n const matchingPropValue = props?.[key] as string | undefined;\n\n if (!matchingPropValue) {\n Object.assign(styleProp, { [key]: props[key] });\n return;\n }\n\n // Handle negative spacing values\n let mappedValueOfCssVar: string;\n const isNegative =\n typeof matchingPropValue === \"string\" &&\n matchingPropValue.startsWith(\"-\");\n\n if (isNegative) {\n // Remove the \"-\" prefix to get the actual token key\n const positiveValue = matchingPropValue.slice(1);\n // Replace VARIABLE with the positive token and wrap in calc()\n const positiveVar = matchingCssVar.value.replace(\n \"VARIABLE\",\n positiveValue,\n );\n mappedValueOfCssVar = `calc(-1 * ${positiveVar})`;\n } else {\n // Replace the VARIABLE placeholder with the actual value of the prop\n mappedValueOfCssVar = matchingCssVar.value.replace(\n \"VARIABLE\",\n matchingPropValue,\n );\n }\n\n const cssVarName = matchingCssVar.cssVar as keyof StyleProp<CssVars>;\n\n // If the style contains an interactive prop, set the interactive flag to true\n // so that the component can include the interactive class\n if (matchingCssVar.interactive) {\n interactive = true;\n }\n\n if (matchingCssVar.direction) {\n const currentValueOfCssVar = styleProp?.[cssVarName];\n\n const directionalValue = applyDirectionalValues({\n currentValueOfCssVar,\n value: mappedValueOfCssVar,\n direction: matchingCssVar.direction,\n });\n\n styleProp = {\n ...styleProp,\n [cssVarName]: directionalValue,\n };\n return;\n }\n\n if (matchingCssVar.axis) {\n const currentValueOfCssVar = styleProp?.[cssVarName];\n const axisValue = applyAxisValues({\n currentValueOfCssVar,\n value: mappedValueOfCssVar,\n axis: matchingCssVar.axis,\n });\n\n styleProp = {\n ...styleProp,\n [cssVarName]: axisValue,\n };\n return;\n }\n\n styleProp = {\n ...styleProp,\n [cssVarName]: mappedValueOfCssVar,\n };\n });\n\n return { styleProp, otherProps, interactive };\n};\n","import React from \"react\";\n\nimport { type CssVarProp, getStyleProp } from \"../helpers/getStyleProp\";\n\ntype CssVarsPropObject<CssVars> = Record<keyof CssVars, CssVarProp>;\n\nexport const useStyleEngine = <\n CssVars extends CssVarsPropObject<CssVars>,\n Props extends Record<string, unknown>,\n>(\n params: Parameters<typeof getStyleProp<CssVars, Props>>[0],\n) => {\n return React.useMemo(() => getStyleProp(params), [params]);\n};\n"],"names":["parseDirectionalValues","value","matches","current","depth","i","char","applyDirectionalValues","currentValueOfCssVar","direction","top","right","bottom","left","newValues","applyAxisValues","axis","x","y","getStyleProp","params","cssVars","style","props","styleProp","otherProps","interactive","_key","key","cssVarsKey","matchingCssVar","matchingPropValue","mappedValueOfCssVar","positiveValue","cssVarName","directionalValue","axisValue","useStyleEngine","React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,EAElB,CAEd,MAAME,EAAgBF,EAAkB,MAAM,CAAC,EAM/CC,EAAsB,aAJFF,EAAe,MAAM,QACvC,WACAG,CAAA,CAE4C,GAChD,MAEED,EAAsBF,EAAe,MAAM,QACzC,WACAC,CAAA,EAIJ,MAAMG,EAAaJ,EAAe,OAQlC,GAJIA,EAAe,cACjBJ,EAAc,IAGZI,EAAe,UAAW,CAC5B,MAAMtB,EAAuBgB,GAAA,YAAAA,EAAYU,GAEnCC,EAAmB5B,EAAuB,CAC9C,qBAAAC,EACA,MAAOwB,EACP,UAAWF,EAAe,SAAA,CAC3B,EAEDN,EAAY,CACV,GAAGA,EACH,CAACU,CAAU,EAAGC,CAAA,EAEhB,MACF,CAEA,GAAIL,EAAe,KAAM,CACvB,MAAMtB,EAAuBgB,GAAA,YAAAA,EAAYU,GACnCE,EAAYrB,EAAgB,CAChC,qBAAAP,EACA,MAAOwB,EACP,KAAMF,EAAe,IAAA,CACtB,EAEDN,EAAY,CACV,GAAGA,EACH,CAACU,CAAU,EAAGE,CAAA,EAEhB,MACF,CAEAZ,EAAY,CACV,GAAGA,EACH,CAACU,CAAU,EAAGF,CAAA,CAElB,CAAC,EAEM,CAAE,UAAAR,EAAW,WAAAC,EAAY,YAAAC,CAAA,CAClC,EClUaW,EAIXjB,GAEOkB,EAAM,QAAQ,IAAMnB,EAAaC,CAAM,EAAG,CAACA,CAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/helpers/getStyleProp/getStyleProp.ts","../../src/hooks/useStyleEngine.ts"],"sourcesContent":["type Direction =\n | \"x\"\n | \"y\"\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"all\"\n | \"side-top\"\n | \"side-bottom\"\n | \"side-left\"\n | \"side-right\";\n\ntype Axis = \"x\" | \"y\" | \"both\";\n\nexport type CssVarProp = {\n cssVar: string;\n value: string;\n direction?: Direction;\n axis?: Axis;\n};\n\n// Supported pseudo-class states for the object syntax\n// Prefixed with underscore to avoid collisions with native HTML attributes\n// (e.g. `disabled`) and common component props (e.g. `active`).\nexport const PSEUDO_STATES = [\n \"_hover\",\n \"_focus\",\n \"_active\",\n \"_focusWithin\",\n \"_disabled\",\n] as const;\n\nexport type PseudoState = (typeof PSEUDO_STATES)[number];\n\n// Maps pseudo state names to CSS variable prefixes\nconst PSEUDO_CSS_PREFIX: Record<PseudoState, string> = {\n _hover: \"hover\",\n _focus: \"focus\",\n _active: \"active\",\n _focusWithin: \"focus-within\",\n _disabled: \"disabled\",\n};\n\n/**\n * Adds pseudo-class variant props to a style props type.\n *\n * Given a base style props type, this creates a new type that also\n * accepts `_hover`, `_focus`, `_active`, `_focusWithin`, and `_disabled`\n * props as objects containing any of the base style props.\n *\n * Prefixed with underscore to avoid collisions with native HTML attributes\n * (e.g. `disabled`) and common component props (e.g. `active`).\n *\n * @example\n * type BoxStyle = { bg: ColorToken; p: SpacingToken };\n * type BoxStyleWithPseudo = WithPseudo<BoxStyle>;\n * // Allows: { bg: \"gray-2\", _hover: { bg: \"gray-3\" }, _focus: { p: \"4\" } }\n */\nexport type WithPseudo<Props> = Props & {\n _hover?: Partial<Props>;\n _focus?: Partial<Props>;\n _active?: Partial<Props>;\n _focusWithin?: Partial<Props>;\n _disabled?: Partial<Props>;\n};\n\n// Helper type to create negative spacing values\n// This distributes over union types for proper type expansion\nexport type NegativeSpacing<T extends string | number | symbol> =\n T extends string ? `-${T}` : never;\n\n// Type that allows both positive and negative spacing values for a given token type\n// Using direct template literal for better TypeScript inference and autocomplete\nexport type WithNegativeSpacing<T extends string | number | symbol> =\n T extends string ? T | `-${T}` : T;\n\ntype ApplyDirectionProps = {\n currentValueOfCssVar: string | undefined;\n value: string;\n direction?: Direction;\n};\n\n// Helper function to parse directional values (handles calc() expressions)\nconst parseDirectionalValues = (\n value: string,\n): [string, string, string, string] => {\n const matches: string[] = [];\n let current = \"\";\n let depth = 0;\n\n for (let i = 0; i < value.length; i++) {\n const char = value[i];\n\n if (char === \"(\") {\n depth++;\n current += char;\n } else if (char === \")\") {\n depth--;\n current += char;\n } else if (char === \" \" && depth === 0) {\n // Space at depth 0 means we're between values\n if (current) {\n matches.push(current);\n current = \"\";\n }\n } else {\n current += char;\n }\n }\n\n // Push the last value\n if (current) {\n matches.push(current);\n }\n\n // Ensure we always have 4 values\n while (matches.length < 4) {\n matches.push(\"0\");\n }\n\n return [\n matches[0] || \"0\",\n matches[1] || \"0\",\n matches[2] || \"0\",\n matches[3] || \"0\",\n ];\n};\n\n// For values like margin and padding that require 4 values\nconst applyDirectionalValues = ({\n currentValueOfCssVar = \"0 0 0 0\",\n value,\n direction,\n}: ApplyDirectionProps) => {\n const [top, right, bottom, left] =\n parseDirectionalValues(currentValueOfCssVar);\n\n const newValues = {\n top,\n right,\n bottom,\n left,\n };\n\n if (direction === \"top\") {\n newValues.top = value;\n }\n\n if (direction === \"right\") {\n newValues.right = value;\n }\n\n if (direction === \"bottom\") {\n newValues.bottom = value;\n }\n\n if (direction === \"left\") {\n newValues.left = value;\n }\n\n if (direction === \"all\") {\n newValues.top = value;\n newValues.right = value;\n newValues.bottom = value;\n newValues.left = value;\n }\n\n if (direction === \"x\") {\n newValues.left = value;\n newValues.right = value;\n }\n\n if (direction === \"y\") {\n newValues.top = value;\n newValues.bottom = value;\n }\n\n // \"side\" direction is used for things like border-radius\n // where we are settings values on corners instead of sides\n // entire sides like padding and margin provide.\n if (direction === \"side-top\") {\n newValues.top = value;\n newValues.right = value;\n }\n\n if (direction === \"side-bottom\") {\n newValues.bottom = value;\n newValues.left = value;\n }\n\n if (direction === \"side-left\") {\n newValues.top = value;\n newValues.left = value;\n }\n\n if (direction === \"side-right\") {\n newValues.right = value;\n newValues.bottom = value;\n }\n\n const newValuesString = Object.values(newValues).join(\" \");\n\n return newValuesString;\n};\n\ntype ApplyAxisValuesProps = {\n currentValueOfCssVar: string | undefined;\n value: string;\n axis: Axis;\n};\n\nconst applyAxisValues = ({\n currentValueOfCssVar = \"visible visible\",\n value,\n axis,\n}: ApplyAxisValuesProps) => {\n const [x, y] = currentValueOfCssVar.split(\" \");\n\n // If the axis is x, we need to set the x value and keep the y value.\n if (axis === \"x\") {\n return `${value} ${y}`;\n }\n\n // If the axis is y, we need to set the y value and keep the x value.\n if (axis === \"y\") {\n return `${x} ${value}`;\n }\n\n // If the axis is both, we need to set the x and y values.\n return `${value} ${value}`;\n};\n\nexport type CssVarsPropObject<CssVars extends CssVarsPropObject<CssVars>> =\n Record<keyof CssVars, CssVarProp>;\n\ntype CssVarPropKey<CssVars extends CssVarsPropObject<CssVars>> = keyof CssVars;\n\n// Allow for explicitly defined props that are not css vars to end to end typesafe\ntype OtherProps<CssVars extends CssVarsPropObject<CssVars>, Props> =\n | Omit<\n {\n [key in keyof Props]: Props[key];\n },\n CssVarPropKey<CssVars>\n >\n | object;\n\n// Allow for explicitly defined css vars return css variables object created\n// by this function and be end to end typesafe\ntype StyleProp<CssVars extends CssVarsPropObject<CssVars>> =\n | {\n [key in CssVars[keyof CssVars][\"cssVar\"]]: string;\n }\n | object;\n\ntype GetStylePropParams<CssVars, Props> = {\n props: Props & { style?: Record<string, string> };\n cssVars: CssVars;\n};\n\n// Resolves a single prop value against its matching CssVarProp definition.\n// Returns the mapped CSS variable value string, handling negative spacing.\nconst resolveValue = (\n matchingCssVar: CssVarProp,\n propValue: string,\n): string => {\n const isNegative = typeof propValue === \"string\" && propValue.startsWith(\"-\");\n\n if (isNegative) {\n const positiveValue = propValue.slice(1);\n const positiveVar = matchingCssVar.value.replace(\"VARIABLE\", positiveValue);\n return `calc(-1 * ${positiveVar})`;\n }\n\n return matchingCssVar.value.replace(\"VARIABLE\", propValue);\n};\n\n// Applies a resolved CSS variable value to the styleProp object,\n// handling directional and axis properties.\nconst applyCssVar = <CssVars extends CssVarsPropObject<CssVars>>(\n styleProp: StyleProp<CssVars>,\n matchingCssVar: CssVarProp,\n mappedValue: string,\n cssVarNameOverride?: string,\n): StyleProp<CssVars> => {\n const cssVarName = (cssVarNameOverride ??\n matchingCssVar.cssVar) as keyof StyleProp<CssVars>;\n\n if (matchingCssVar.direction) {\n const currentValueOfCssVar = styleProp?.[cssVarName];\n const directionalValue = applyDirectionalValues({\n currentValueOfCssVar,\n value: mappedValue,\n direction: matchingCssVar.direction,\n });\n return { ...styleProp, [cssVarName]: directionalValue };\n }\n\n if (matchingCssVar.axis) {\n const currentValueOfCssVar = styleProp?.[cssVarName];\n const axisValue = applyAxisValues({\n currentValueOfCssVar,\n value: mappedValue,\n axis: matchingCssVar.axis,\n });\n return { ...styleProp, [cssVarName]: axisValue };\n }\n\n return { ...styleProp, [cssVarName]: mappedValue };\n};\n\n// Creates a state-prefixed CSS variable name from a base CSS variable.\n// e.g. (\"--background-color\", \"hover\") => \"--hover--background-color\"\nconst createPseudoCssVarName = (\n baseCssVar: string,\n pseudoState: PseudoState,\n): string => {\n const prefix = PSEUDO_CSS_PREFIX[pseudoState];\n const baseName = baseCssVar.replace(/^--/, \"\");\n return `--${prefix}--${baseName}`;\n};\n\nexport const getStyleProp = <\n CssVars extends CssVarsPropObject<CssVars>,\n Props extends Record<string, unknown>,\n>(\n params: GetStylePropParams<CssVars, Props>,\n): {\n styleProp: StyleProp<CssVars>;\n otherProps: OtherProps<CssVars, Props>;\n interactive: boolean;\n} => {\n const { cssVars } = params;\n\n if (!params?.props || Object.keys(params.props).length === 0) {\n return { styleProp: {}, otherProps: {}, interactive: false };\n }\n\n // Assign the additional styles to the style object so that it can be passed\n // to the component as a prop.\n const { style = {}, ...props } = params.props;\n\n let styleProp: StyleProp<CssVars> = style;\n const otherProps: OtherProps<CssVars, Props> = {};\n let interactive = false;\n\n Object.keys(props).forEach((_key) => {\n const key = _key as keyof typeof props;\n\n // Check if this is a pseudo-class object prop (hover, focus, active, etc.)\n if (\n PSEUDO_STATES.includes(_key as PseudoState) &&\n typeof props[key] === \"object\" &&\n props[key] !== null\n ) {\n const pseudoState = _key as PseudoState;\n const pseudoProps = props[key] as Record<string, string | undefined>;\n const unmatchedPseudoProps: Record<string, string> = {};\n\n Object.keys(pseudoProps).forEach((pseudoPropKey) => {\n const propValue = pseudoProps[pseudoPropKey];\n if (!propValue) return;\n\n const cssVarsKey = pseudoPropKey as unknown as keyof typeof cssVars;\n const matchingCssVar = cssVars?.[cssVarsKey];\n\n if (!matchingCssVar) {\n // Collect unmatched pseudo props to pass through to otherProps\n unmatchedPseudoProps[pseudoPropKey] = propValue;\n return;\n }\n\n const mappedValue = resolveValue(matchingCssVar, propValue);\n const pseudoCssVarName = createPseudoCssVarName(\n matchingCssVar.cssVar,\n pseudoState,\n );\n\n styleProp = applyCssVar(\n styleProp,\n matchingCssVar,\n mappedValue,\n pseudoCssVarName,\n );\n });\n\n // Pass through any unmatched pseudo props so downstream components\n // can process them (e.g. Button passes hover.backgroundColor to Box)\n if (Object.keys(unmatchedPseudoProps).length > 0) {\n const existingPseudo =\n (otherProps as Record<string, unknown>)[_key] || {};\n Object.assign(otherProps, {\n [_key]: { ...existingPseudo, ...unmatchedPseudoProps },\n });\n }\n\n // If any pseudo sub-props were matched against cssVars at this level,\n // mark as interactive so the component adds the scoping class.\n // This prevents pseudo-class CSS rules from cascading into child elements.\n if (\n Object.keys(pseudoProps).length >\n Object.keys(unmatchedPseudoProps).length\n ) {\n interactive = true;\n }\n\n return;\n }\n\n const cssVarsKey = key as unknown as keyof typeof cssVars;\n const matchingCssVar = cssVars?.[cssVarsKey];\n\n // If the prop is not a css var, just add it to the otherProps\n if (!matchingCssVar) {\n Object.assign(otherProps, { [key]: props[key] });\n return;\n }\n\n const matchingPropValue = props?.[key] as string | undefined;\n\n if (!matchingPropValue) {\n Object.assign(styleProp, { [key]: props[key] });\n return;\n }\n\n const mappedValueOfCssVar = resolveValue(matchingCssVar, matchingPropValue);\n\n styleProp = applyCssVar(styleProp, matchingCssVar, mappedValueOfCssVar);\n });\n\n return { styleProp, otherProps, interactive };\n};\n","import React from \"react\";\n\nimport { type CssVarProp, getStyleProp } from \"../helpers/getStyleProp\";\n\ntype CssVarsPropObject<CssVars> = Record<keyof CssVars, CssVarProp>;\n\nexport const useStyleEngine = <\n CssVars extends CssVarsPropObject<CssVars>,\n Props extends Record<string, unknown>,\n>(\n params: Parameters<typeof getStyleProp<CssVars, Props>>[0],\n) => {\n return React.useMemo(() => getStyleProp(params), [params]);\n};\n"],"names":["PSEUDO_STATES","PSEUDO_CSS_PREFIX","parseDirectionalValues","value","matches","current","depth","i","char","applyDirectionalValues","currentValueOfCssVar","direction","top","right","bottom","left","newValues","applyAxisValues","axis","x","y","resolveValue","matchingCssVar","propValue","positiveValue","applyCssVar","styleProp","mappedValue","cssVarNameOverride","cssVarName","directionalValue","axisValue","createPseudoCssVarName","baseCssVar","pseudoState","prefix","baseName","getStyleProp","params","cssVars","style","props","otherProps","interactive","_key","key","pseudoProps","unmatchedPseudoProps","pseudoPropKey","cssVarsKey","pseudoCssVarName","existingPseudo","matchingPropValue","mappedValueOfCssVar","useStyleEngine","React"],"mappings":"utQAyBaA,EAAgB,CAC3B,SACA,SACA,UACA,eACA,WACF,EAKMC,EAAiD,CACrD,OAAQ,QACR,OAAQ,QACR,QAAS,SACT,aAAc,eACd,UAAW,UACb,EA0CMC,EACJC,GACqC,CACrC,MAAMC,EAAoB,CAAA,EAC1B,IAAIC,EAAU,GACVC,EAAQ,EAEZ,QAASC,EAAI,EAAGA,EAAIJ,EAAM,OAAQI,IAAK,CACrC,MAAMC,EAAOL,EAAMI,CAAC,EAEhBC,IAAS,KACXF,IACAD,GAAWG,GACFA,IAAS,KAClBF,IACAD,GAAWG,GACFA,IAAS,KAAOF,IAAU,EAE/BD,IACFD,EAAQ,KAAKC,CAAO,EACpBA,EAAU,IAGZA,GAAWG,CAEf,CAQA,IALIH,GACFD,EAAQ,KAAKC,CAAO,EAIfD,EAAQ,OAAS,GACtBA,EAAQ,KAAK,GAAG,EAGlB,MAAO,CACLA,EAAQ,CAAC,GAAK,IACdA,EAAQ,CAAC,GAAK,IACdA,EAAQ,CAAC,GAAK,IACdA,EAAQ,CAAC,GA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AEA,MAAMQ,EAAsBhC,EAAaC,EAAgB8B,CAAiB,EAE1E1B,EAAYD,EAAYC,EAAWJ,EAAgB+B,CAAmB,CACxE,CAAC,EAEM,CAAE,UAAA3B,EAAW,WAAAgB,EAAY,YAAAC,CAAA,CAClC,EC1aaW,EAIXhB,GAEOiB,EAAM,QAAQ,IAAMlB,EAAaC,CAAM,EAAG,CAACA,CAAM,CAAC"}
|
package/dist/cjs/postcss.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const a=require("path"),l=require("fs"),m=require("postcss");function y(t=process.cwd()){let e=t,s=!0;for(;s;){const n=a.join(e,"package.json");if(l.existsSync(n))try{if(JSON.parse(l.readFileSync(n,"utf8")).workspaces)return e}catch{}const r=a.dirname(e);r===e&&(s=!1),e=r}}const d=(t,e)=>{var s;if(!(!t.dependencies||((s=Object.keys(t.dependencies))==null?void 0:s.length)===0))return Object.entries(t.dependencies).reduce((n,[r,c])=>(r.startsWith("@telegraph/")&&(n[r]={name:r,version:c,path:a.resolve(e,"node_modules",r)}),n),{})};function v(){const t=a.resolve(process.cwd(),"package.json"),e=JSON.parse(l.readFileSync(t,"utf8")),s=d(e,process.cwd()),n=y(),r=c=>{if(!c||Object.keys(c).length===0)return c;const i={...c};for(const u of Object.values(c)){let o,p;u.version.includes("workspace:")&&n?(o=a.resolve(n,"node_modules",u.name,"package.json"),p=n):(o=a.resolve(process.cwd(),"node_modules",u.name,"package.json"),p=process.cwd());try{const g=JSON.parse(l.readFileSync(o,"utf8")),h=d(g,p);if(Object.assign(i,h),h){const k=r(h);Object.assign(i,k)}}catch{continue}}return i};return s?r(s):{}}function f({fileName:t="default.css",path:e}){try{const s=`${e}/dist/css/${t}`,n=a.resolve(s);return l.existsSync(n)?l.readFileSync(n,"utf8"):null}catch{return null}}const j=async({root:t,config:e})=>{const s=v(),n=e.components===!0?Object.values(s).filter(o=>!o.name.includes("@telegraph/tokens")):[],r=e.tokens.length>0?Object.values(s).filter(o=>o.name.includes("@telegraph/tokens")):[],c=n.map(o=>f({path:o.path})).filter(Boolean),i=e.tokens.map(o=>r.map(g=>f({path:g.path,fileName:`${o}.css`})).filter(Boolean)).filter(Boolean),u=[...c,...i];for(const o of u){const p=m.parse(o);t.append(p)}},O=()=>({postcssPlugin:"@telegraph/style-engine",plugins:[{postcssPlugin:"telegraph",AtRule:{telegraph(){}},async Once(t){const e={tokens:[],components:!1};t.walkAtRules("telegraph",s=>{s.params==="components"&&(e.components=!0,s.remove()),s.params==="tokens-light"&&(e.tokens.push("light"),s.remove()),s.params==="tokens-dark"&&(e.tokens.push("dark"),s.remove()),s.params==="tokens"&&(e.tokens.push("default"),s.remove())}),await j({root:t,config:{tokens:e.tokens,components:e.components}})}}]}),P=Object.assign(O,{postcss:!0});module.exports=P;
|
|
1
|
+
"use strict";const a=require("node:path"),l=require("node:fs"),m=require("postcss");function y(t=process.cwd()){let e=t,s=!0;for(;s;){const n=a.join(e,"package.json");if(l.existsSync(n))try{if(JSON.parse(l.readFileSync(n,"utf8")).workspaces)return e}catch{}const r=a.dirname(e);r===e&&(s=!1),e=r}}const d=(t,e)=>{var s;if(!(!t.dependencies||((s=Object.keys(t.dependencies))==null?void 0:s.length)===0))return Object.entries(t.dependencies).reduce((n,[r,c])=>(r.startsWith("@telegraph/")&&(n[r]={name:r,version:c,path:a.resolve(e,"node_modules",r)}),n),{})};function v(){const t=a.resolve(process.cwd(),"package.json"),e=JSON.parse(l.readFileSync(t,"utf8")),s=d(e,process.cwd()),n=y(),r=c=>{if(!c||Object.keys(c).length===0)return c;const i={...c};for(const u of Object.values(c)){let o,p;u.version.includes("workspace:")&&n?(o=a.resolve(n,"node_modules",u.name,"package.json"),p=n):(o=a.resolve(process.cwd(),"node_modules",u.name,"package.json"),p=process.cwd());try{const g=JSON.parse(l.readFileSync(o,"utf8")),h=d(g,p);if(Object.assign(i,h),h){const k=r(h);Object.assign(i,k)}}catch{continue}}return i};return s?r(s):{}}function f({fileName:t="default.css",path:e}){try{const s=`${e}/dist/css/${t}`,n=a.resolve(s);return l.existsSync(n)?l.readFileSync(n,"utf8"):null}catch{return null}}const j=async({root:t,config:e})=>{const s=v(),n=e.components===!0?Object.values(s).filter(o=>!o.name.includes("@telegraph/tokens")):[],r=e.tokens.length>0?Object.values(s).filter(o=>o.name.includes("@telegraph/tokens")):[],c=n.map(o=>f({path:o.path})).filter(Boolean),i=e.tokens.map(o=>r.map(g=>f({path:g.path,fileName:`${o}.css`})).filter(Boolean)).filter(Boolean),u=[...c,...i];for(const o of u){const p=m.parse(o);t.append(p)}},O=()=>({postcssPlugin:"@telegraph/style-engine",plugins:[{postcssPlugin:"telegraph",AtRule:{telegraph(){}},async Once(t){const e={tokens:[],components:!1};t.walkAtRules("telegraph",s=>{s.params==="components"&&(e.components=!0,s.remove()),s.params==="tokens-light"&&(e.tokens.push("light"),s.remove()),s.params==="tokens-dark"&&(e.tokens.push("dark"),s.remove()),s.params==="tokens"&&(e.tokens.push("default"),s.remove())}),await j({root:t,config:{tokens:e.tokens,components:e.components}})}}]}),P=Object.assign(O,{postcss:!0});module.exports=P;
|
|
2
2
|
//# sourceMappingURL=postcss.js.map
|
package/dist/cjs/postcss.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postcss.js","sources":["../../src/plugins/postcss.ts"],"sourcesContent":["import { type AcceptedPlugin, type PluginCreator, type Root } from \"postcss\";\n\n// Using require() instead of import to prevent ESM-related bugs in PostCSS.\n// ESM = ECMAScript Modules (the import/export syntax)\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst nodePath = require(\"path\");\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst nodeFs = require(\"fs\");\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst postcss = require(\"postcss\");\n\ntype PkgJson = {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n};\n\ntype DepObject = Record<\n string,\n {\n name: string;\n version: string;\n path: string;\n }\n>;\n\n/**\n * Traverses up the directory tree to find the root of the monorepo by looking for a package.json with workspaces.\n * This is needed to properly resolve workspace dependencies in a monorepo setup.\n */\nfunction findMonorepoRoot(start = process.cwd()): string | undefined {\n let current = start;\n let run = true;\n\n while (run) {\n const pkgJsonPath = nodePath.join(current, \"package.json\");\n if (nodeFs.existsSync(pkgJsonPath)) {\n try {\n const pkg = JSON.parse(nodeFs.readFileSync(pkgJsonPath, \"utf8\"));\n if (pkg.workspaces) {\n return current;\n }\n } catch {\n // malformed package.json, skip\n }\n }\n\n const parent = nodePath.dirname(current);\n if (parent === current) run = false;\n current = parent;\n }\n\n return undefined;\n}\n\n/**\n * Extracts all @telegraph/* dependencies from a package.json file and returns them with their paths.\n * This is used to find all Telegraph packages that might contain CSS we need to include.\n */\nconst getTelegraphDepsFromPackageJson = (\n pkg: PkgJson,\n pkgPath: string,\n): DepObject | undefined => {\n if (!pkg.dependencies || Object.keys(pkg.dependencies)?.length === 0) return;\n\n return Object.entries(pkg.dependencies).reduce((acc, [dep, version]) => {\n if (dep.startsWith(\"@telegraph/\")) {\n acc[dep] = {\n name: dep,\n version,\n path: nodePath.resolve(pkgPath, \"node_modules\", dep),\n };\n }\n return acc;\n }, {} as DepObject);\n};\n\n/**\n * Gets all Telegraph dependencies recursively, including dependencies of dependencies.\n * Handles both normal npm dependencies and workspace dependencies in a monorepo.\n */\nfunction getTelegraphDeps(): DepObject {\n const pkgPath = nodePath.resolve(process.cwd(), \"package.json\");\n const pkg = JSON.parse(nodeFs.readFileSync(pkgPath, \"utf8\"));\n const topLevelDeps = getTelegraphDepsFromPackageJson(pkg, process.cwd());\n const monorepoRoot = findMonorepoRoot();\n\n const recursivelyGetTelegraphDeps = (deps: DepObject): DepObject => {\n if (!deps || Object.keys(deps).length === 0) {\n return deps;\n }\n\n const allDeps = { ...deps };\n\n for (const dep of Object.values(deps)) {\n let pkgJsonPath: string;\n let searchPath: string;\n\n if (dep.version.includes(\"workspace:\") && monorepoRoot) {\n pkgJsonPath = nodePath.resolve(\n monorepoRoot,\n \"node_modules\",\n dep.name,\n \"package.json\",\n );\n searchPath = monorepoRoot;\n } else {\n pkgJsonPath = nodePath.resolve(\n process.cwd(),\n \"node_modules\",\n dep.name,\n \"package.json\",\n );\n searchPath = process.cwd();\n }\n\n try {\n const pkgJson = JSON.parse(nodeFs.readFileSync(pkgJsonPath, \"utf8\"));\n const deps = getTelegraphDepsFromPackageJson(pkgJson, searchPath);\n\n // Merge new dependencies into allDeps\n Object.assign(allDeps, deps);\n\n if (deps) {\n // Recursively get dependencies of dependencies\n const nestedDeps = recursivelyGetTelegraphDeps(deps);\n Object.assign(allDeps, nestedDeps);\n }\n } catch (_err) {\n // Skip if package.json cannot be read\n continue;\n }\n }\n\n return allDeps;\n };\n\n if (topLevelDeps) {\n return recursivelyGetTelegraphDeps(topLevelDeps);\n }\n\n return {};\n}\n\ntype GetCssStylesParams = {\n fileName?: string;\n path: string;\n};\n\n/**\n * Reads CSS file content from a Telegraph package's dist/css directory.\n * Returns null if the file doesn't exist or can't be read.\n */\nfunction getCssStyles({\n fileName = \"default.css\",\n path,\n}: GetCssStylesParams): string | null {\n try {\n const cssPath = `${path}/dist/css/${fileName}`;\n const pkgPath = nodePath.resolve(cssPath);\n\n if (nodeFs.existsSync(pkgPath)) {\n return nodeFs.readFileSync(pkgPath, \"utf8\");\n }\n\n return null;\n } catch {\n return null;\n }\n}\n\ntype BuildTelegraphCssParams = {\n root: Root;\n config: {\n tokens: Array<\"light\" | \"dark\" | \"default\">;\n components: boolean;\n };\n};\n\n/**\n * Main function that builds the final CSS by:\n * 1. Getting all Telegraph dependencies\n * 2. Filtering for either token packages or component packages based on config\n * 3. Reading their CSS files\n * 4. Appending all CSS to the PostCSS Root node\n */\nconst buildTelegraphCss = async ({ root, config }: BuildTelegraphCssParams) => {\n const deps = getTelegraphDeps();\n\n const depsWithoutTokens =\n config.components === true\n ? Object.values(deps).filter(\n (dep) => !dep.name.includes(\"@telegraph/tokens\"),\n )\n : [];\n\n const tokensDeps =\n config.tokens.length > 0\n ? Object.values(deps).filter((dep) =>\n dep.name.includes(\"@telegraph/tokens\"),\n )\n : [];\n\n const cssFiles = depsWithoutTokens\n .map((dep) => getCssStyles({ path: dep.path }))\n .filter(Boolean) as Array<string>;\n\n const tokensCssFiles = config.tokens\n .map((token) => {\n const cssFile = tokensDeps.map((dep) =>\n getCssStyles({ path: dep.path, fileName: `${token}.css` }),\n );\n\n return cssFile.filter(Boolean) as Array<string>;\n })\n .filter(Boolean);\n\n const allCssFiles = [...cssFiles, ...tokensCssFiles];\n\n for (const content of allCssFiles) {\n const parsed = postcss.parse(content);\n root.append(parsed);\n }\n};\n\n/**\n * PostCSS plugin that processes @telegraph rules in CSS files.\n * It looks for @telegraph tokens, @telegraph tokens-light, @telegraph tokens-dark,\n * and @telegraph components rules and includes the appropriate CSS from Telegraph packages.\n */\nconst styleEnginePostCssPlugin = (): AcceptedPlugin => {\n return {\n postcssPlugin: \"@telegraph/style-engine\",\n plugins: [\n {\n postcssPlugin: \"telegraph\",\n AtRule: {\n telegraph() {},\n },\n async Once(root) {\n const run = {\n tokens: [] as BuildTelegraphCssParams[\"config\"][\"tokens\"],\n components: false,\n };\n root.walkAtRules(\"telegraph\", (atRule) => {\n if (atRule.params === \"components\") {\n run.components = true;\n atRule.remove();\n }\n\n if (atRule.params === \"tokens-light\") {\n run.tokens.push(\"light\");\n atRule.remove();\n }\n\n if (atRule.params === \"tokens-dark\") {\n run.tokens.push(\"dark\");\n atRule.remove();\n }\n\n if (atRule.params === \"tokens\") {\n run.tokens.push(\"default\");\n atRule.remove();\n }\n });\n\n await buildTelegraphCss({\n root,\n config: {\n tokens: run.tokens,\n components: run.components,\n },\n });\n },\n },\n ],\n };\n};\n\nexport default Object.assign(styleEnginePostCssPlugin, {\n postcss: true,\n}) as PluginCreator<Record<string, never>>;\n"],"names":["nodePath","nodeFs","postcss","findMonorepoRoot","start","current","run","pkgJsonPath","parent","getTelegraphDepsFromPackageJson","pkg","pkgPath","_a","acc","dep","version","getTelegraphDeps","topLevelDeps","monorepoRoot","recursivelyGetTelegraphDeps","deps","allDeps","searchPath","pkgJson","nestedDeps","getCssStyles","fileName","path","cssPath","buildTelegraphCss","root","config","depsWithoutTokens","tokensDeps","cssFiles","tokensCssFiles","token","allCssFiles","content","parsed","styleEnginePostCssPlugin","atRule","postcss$1"],"mappings":"aAKA,MAAMA,EAAW,QAAQ,MAAM,EAEzBC,EAAS,QAAQ,IAAI,EAErBC,EAAU,QAAQ,SAAS,EAoBjC,SAASC,EAAiBC,EAAQ,QAAQ,MAA2B,CACnE,IAAIC,EAAUD,EACVE,EAAM,GAEV,KAAOA,GAAK,CACV,MAAMC,EAAcP,EAAS,KAAKK,EAAS,cAAc,EACzD,GAAIJ,EAAO,WAAWM,CAAW,EAC/B,GAAI,CAEF,GADY,KAAK,MAAMN,EAAO,aAAaM,EAAa,MAAM,CAAC,EACvD,WACN,OAAOF,CAEX,MAAQ,CAER,CAGF,MAAMG,EAASR,EAAS,QAAQK,CAAO,EACnCG,IAAWH,IAASC,EAAM,IAC9BD,EAAUG,CACZ,CAGF,CAMA,MAAMC,EAAkC,CACtCC,EACAC,IAC0B,OAC1B,GAAI,GAACD,EAAI,gBAAgBE,EAAA,OAAO,KAAKF,EAAI,YAAY,IAA5B,YAAAE,EAA+B,UAAW,GAEnE,OAAO,OAAO,QAAQF,EAAI,YAAY,EAAE,OAAO,CAACG,EAAK,CAACC,EAAKC,CAAO,KAC5DD,EAAI,WAAW,aAAa,IAC9BD,EAAIC,CAAG,EAAI,CACT,KAAMA,EACN,QAAAC,EACA,KAAMf,EAAS,QAAQW,EAAS,eAAgBG,CAAG,CAAA,GAGhDD,GACN,CAAA,CAAe,CACpB,EAMA,SAASG,GAA8B,CACrC,MAAML,EAAUX,EAAS,QAAQ,QAAQ,IAAA,EAAO,cAAc,EACxDU,EAAM,KAAK,MAAMT,EAAO,aAAaU,EAAS,MAAM,CAAC,EACrDM,EAAeR,EAAgCC,EAAK,QAAQ,KAAK,EACj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,CAAC"}
|
|
1
|
+
{"version":3,"file":"postcss.js","sources":["../../src/plugins/postcss.ts"],"sourcesContent":["import { type AcceptedPlugin, type PluginCreator, type Root } from \"postcss\";\n\n// Using require() instead of import to prevent ESM-related bugs in PostCSS.\n// ESM = ECMAScript Modules (the import/export syntax)\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst nodePath = require(\"node:path\");\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst nodeFs = require(\"node:fs\");\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst postcss = require(\"postcss\");\n\ntype PkgJson = {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n};\n\ntype DepObject = Record<\n string,\n {\n name: string;\n version: string;\n path: string;\n }\n>;\n\n/**\n * Traverses up the directory tree to find the root of the monorepo by looking for a package.json with workspaces.\n * This is needed to properly resolve workspace dependencies in a monorepo setup.\n */\nfunction findMonorepoRoot(start = process.cwd()): string | undefined {\n let current = start;\n let run = true;\n\n while (run) {\n const pkgJsonPath = nodePath.join(current, \"package.json\");\n if (nodeFs.existsSync(pkgJsonPath)) {\n try {\n const pkg = JSON.parse(nodeFs.readFileSync(pkgJsonPath, \"utf8\"));\n if (pkg.workspaces) {\n return current;\n }\n } catch {\n // malformed package.json, skip\n }\n }\n\n const parent = nodePath.dirname(current);\n if (parent === current) run = false;\n current = parent;\n }\n\n return undefined;\n}\n\n/**\n * Extracts all @telegraph/* dependencies from a package.json file and returns them with their paths.\n * This is used to find all Telegraph packages that might contain CSS we need to include.\n */\nconst getTelegraphDepsFromPackageJson = (\n pkg: PkgJson,\n pkgPath: string,\n): DepObject | undefined => {\n if (!pkg.dependencies || Object.keys(pkg.dependencies)?.length === 0) return;\n\n return Object.entries(pkg.dependencies).reduce((acc, [dep, version]) => {\n if (dep.startsWith(\"@telegraph/\")) {\n acc[dep] = {\n name: dep,\n version,\n path: nodePath.resolve(pkgPath, \"node_modules\", dep),\n };\n }\n return acc;\n }, {} as DepObject);\n};\n\n/**\n * Gets all Telegraph dependencies recursively, including dependencies of dependencies.\n * Handles both normal npm dependencies and workspace dependencies in a monorepo.\n */\nfunction getTelegraphDeps(): DepObject {\n const pkgPath = nodePath.resolve(process.cwd(), \"package.json\");\n const pkg = JSON.parse(nodeFs.readFileSync(pkgPath, \"utf8\"));\n const topLevelDeps = getTelegraphDepsFromPackageJson(pkg, process.cwd());\n const monorepoRoot = findMonorepoRoot();\n\n const recursivelyGetTelegraphDeps = (deps: DepObject): DepObject => {\n if (!deps || Object.keys(deps).length === 0) {\n return deps;\n }\n\n const allDeps = { ...deps };\n\n for (const dep of Object.values(deps)) {\n let pkgJsonPath: string;\n let searchPath: string;\n\n if (dep.version.includes(\"workspace:\") && monorepoRoot) {\n pkgJsonPath = nodePath.resolve(\n monorepoRoot,\n \"node_modules\",\n dep.name,\n \"package.json\",\n );\n searchPath = monorepoRoot;\n } else {\n pkgJsonPath = nodePath.resolve(\n process.cwd(),\n \"node_modules\",\n dep.name,\n \"package.json\",\n );\n searchPath = process.cwd();\n }\n\n try {\n const pkgJson = JSON.parse(nodeFs.readFileSync(pkgJsonPath, \"utf8\"));\n const deps = getTelegraphDepsFromPackageJson(pkgJson, searchPath);\n\n // Merge new dependencies into allDeps\n Object.assign(allDeps, deps);\n\n if (deps) {\n // Recursively get dependencies of dependencies\n const nestedDeps = recursivelyGetTelegraphDeps(deps);\n Object.assign(allDeps, nestedDeps);\n }\n } catch (_err) {\n // Skip if package.json cannot be read\n continue;\n }\n }\n\n return allDeps;\n };\n\n if (topLevelDeps) {\n return recursivelyGetTelegraphDeps(topLevelDeps);\n }\n\n return {};\n}\n\ntype GetCssStylesParams = {\n fileName?: string;\n path: string;\n};\n\n/**\n * Reads CSS file content from a Telegraph package's dist/css directory.\n * Returns null if the file doesn't exist or can't be read.\n */\nfunction getCssStyles({\n fileName = \"default.css\",\n path,\n}: GetCssStylesParams): string | null {\n try {\n const cssPath = `${path}/dist/css/${fileName}`;\n const pkgPath = nodePath.resolve(cssPath);\n\n if (nodeFs.existsSync(pkgPath)) {\n return nodeFs.readFileSync(pkgPath, \"utf8\");\n }\n\n return null;\n } catch {\n return null;\n }\n}\n\ntype BuildTelegraphCssParams = {\n root: Root;\n config: {\n tokens: Array<\"light\" | \"dark\" | \"default\">;\n components: boolean;\n };\n};\n\n/**\n * Main function that builds the final CSS by:\n * 1. Getting all Telegraph dependencies\n * 2. Filtering for either token packages or component packages based on config\n * 3. Reading their CSS files\n * 4. Appending all CSS to the PostCSS Root node\n */\nconst buildTelegraphCss = async ({ root, config }: BuildTelegraphCssParams) => {\n const deps = getTelegraphDeps();\n\n const depsWithoutTokens =\n config.components === true\n ? Object.values(deps).filter(\n (dep) => !dep.name.includes(\"@telegraph/tokens\"),\n )\n : [];\n\n const tokensDeps =\n config.tokens.length > 0\n ? Object.values(deps).filter((dep) =>\n dep.name.includes(\"@telegraph/tokens\"),\n )\n : [];\n\n const cssFiles = depsWithoutTokens\n .map((dep) => getCssStyles({ path: dep.path }))\n .filter(Boolean) as Array<string>;\n\n const tokensCssFiles = config.tokens\n .map((token) => {\n const cssFile = tokensDeps.map((dep) =>\n getCssStyles({ path: dep.path, fileName: `${token}.css` }),\n );\n\n return cssFile.filter(Boolean) as Array<string>;\n })\n .filter(Boolean);\n\n const allCssFiles = [...cssFiles, ...tokensCssFiles];\n\n for (const content of allCssFiles) {\n const parsed = postcss.parse(content);\n root.append(parsed);\n }\n};\n\n/**\n * PostCSS plugin that processes @telegraph rules in CSS files.\n * It looks for @telegraph tokens, @telegraph tokens-light, @telegraph tokens-dark,\n * and @telegraph components rules and includes the appropriate CSS from Telegraph packages.\n */\nconst styleEnginePostCssPlugin = (): AcceptedPlugin => {\n return {\n postcssPlugin: \"@telegraph/style-engine\",\n plugins: [\n {\n postcssPlugin: \"telegraph\",\n AtRule: {\n telegraph() {},\n },\n async Once(root) {\n const run = {\n tokens: [] as BuildTelegraphCssParams[\"config\"][\"tokens\"],\n components: false,\n };\n root.walkAtRules(\"telegraph\", (atRule) => {\n if (atRule.params === \"components\") {\n run.components = true;\n atRule.remove();\n }\n\n if (atRule.params === \"tokens-light\") {\n run.tokens.push(\"light\");\n atRule.remove();\n }\n\n if (atRule.params === \"tokens-dark\") {\n run.tokens.push(\"dark\");\n atRule.remove();\n }\n\n if (atRule.params === \"tokens\") {\n run.tokens.push(\"default\");\n atRule.remove();\n }\n });\n\n await buildTelegraphCss({\n root,\n config: {\n tokens: run.tokens,\n components: run.components,\n },\n });\n },\n },\n ],\n };\n};\n\nexport default Object.assign(styleEnginePostCssPlugin, {\n postcss: true,\n}) as PluginCreator<Record<string, never>>;\n"],"names":["nodePath","nodeFs","postcss","findMonorepoRoot","start","current","run","pkgJsonPath","parent","getTelegraphDepsFromPackageJson","pkg","pkgPath","_a","acc","dep","version","getTelegraphDeps","topLevelDeps","monorepoRoot","recursivelyGetTelegraphDeps","deps","allDeps","searchPath","pkgJson","nestedDeps","getCssStyles","fileName","path","cssPath","buildTelegraphCss","root","config","depsWithoutTokens","tokensDeps","cssFiles","tokensCssFiles","token","allCssFiles","content","parsed","styleEnginePostCssPlugin","atRule","postcss$1"],"mappings":"aAKA,MAAMA,EAAW,QAAQ,WAAW,EAE9BC,EAAS,QAAQ,SAAS,EAE1BC,EAAU,QAAQ,SAAS,EAoBjC,SAASC,EAAiBC,EAAQ,QAAQ,MAA2B,CACnE,IAAIC,EAAUD,EACVE,EAAM,GAEV,KAAOA,GAAK,CACV,MAAMC,EAAcP,EAAS,KAAKK,EAAS,cAAc,EACzD,GAAIJ,EAAO,WAAWM,CAAW,EAC/B,GAAI,CAEF,GADY,KAAK,MAAMN,EAAO,aAAaM,EAAa,MAAM,CAAC,EACvD,WACN,OAAOF,CAEX,MAAQ,CAER,CAGF,MAAMG,EAASR,EAAS,QAAQK,CAAO,EACnCG,IAAWH,IAASC,EAAM,IAC9BD,EAAUG,CACZ,CAGF,CAMA,MAAMC,EAAkC,CACtCC,EACAC,IAC0B,OAC1B,GAAI,GAACD,EAAI,gBAAgBE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,YAAY,YAAcW,GAAW,CACpCA,EAAO,SAAW,eACpBnC,EAAI,WAAa,GACjBmC,EAAO,OAAA,GAGLA,EAAO,SAAW,iBACpBnC,EAAI,OAAO,KAAK,OAAO,EACvBmC,EAAO,OAAA,GAGLA,EAAO,SAAW,gBACpBnC,EAAI,OAAO,KAAK,MAAM,EACtBmC,EAAO,OAAA,GAGLA,EAAO,SAAW,WACpBnC,EAAI,OAAO,KAAK,SAAS,EACzBmC,EAAO,OAAA,EAEX,CAAC,EAED,MAAMZ,EAAkB,CACtB,KAAAC,EACA,OAAQ,CACN,OAAQxB,EAAI,OACZ,WAAYA,EAAI,UAAA,CAClB,CACD,CACH,CAAA,CACF,CACF,GAIJoC,EAAe,OAAO,OAAOF,EAA0B,CACrD,QAAS,EACX,CAAC"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
1
|
+
import _ from "react";
|
|
2
|
+
const I = { transparent: "var(--tgph-transparent)", white: "var(--tgph-white)", black: "var(--tgph-black)", "surface-1": "var(--tgph-surface-1)", "surface-2": "var(--tgph-surface-2)", "surface-3": "var(--tgph-surface-3)", "alpha-white-1": "var(--tgph-alpha-white-1)", "alpha-white-2": "var(--tgph-alpha-white-2)", "alpha-white-3": "var(--tgph-alpha-white-3)", "alpha-white-4": "var(--tgph-alpha-white-4)", "alpha-white-5": "var(--tgph-alpha-white-5)", "alpha-white-6": "var(--tgph-alpha-white-6)", "alpha-white-7": "var(--tgph-alpha-white-7)", "alpha-white-8": "var(--tgph-alpha-white-8)", "alpha-white-9": "var(--tgph-alpha-white-9)", "alpha-white-10": "var(--tgph-alpha-white-10)", "alpha-white-11": "var(--tgph-alpha-white-11)", "alpha-white-12": "var(--tgph-alpha-white-12)", "alpha-black-1": "var(--tgph-alpha-black-1)", "alpha-black-2": "var(--tgph-alpha-black-2)", "alpha-black-3": "var(--tgph-alpha-black-3)", "alpha-black-4": "var(--tgph-alpha-black-4)", "alpha-black-5": "var(--tgph-alpha-black-5)", "alpha-black-6": "var(--tgph-alpha-black-6)", "alpha-black-7": "var(--tgph-alpha-black-7)", "alpha-black-8": "var(--tgph-alpha-black-8)", "alpha-black-9": "var(--tgph-alpha-black-9)", "alpha-black-10": "var(--tgph-alpha-black-10)", "alpha-black-11": "var(--tgph-alpha-black-11)", "alpha-black-12": "var(--tgph-alpha-black-12)", "gray-1": "var(--tgph-gray-1)", "gray-2": "var(--tgph-gray-2)", "gray-3": "var(--tgph-gray-3)", "gray-4": "var(--tgph-gray-4)", "gray-5": "var(--tgph-gray-5)", "gray-6": "var(--tgph-gray-6)", "gray-7": "var(--tgph-gray-7)", "gray-8": "var(--tgph-gray-8)", "gray-9": "var(--tgph-gray-9)", "gray-10": "var(--tgph-gray-10)", "gray-11": "var(--tgph-gray-11)", "gray-12": "var(--tgph-gray-12)", "beige-1": "var(--tgph-beige-1)", "beige-2": "var(--tgph-beige-2)", "beige-3": "var(--tgph-beige-3)", "beige-4": "var(--tgph-beige-4)", "beige-5": "var(--tgph-beige-5)", "beige-6": "var(--tgph-beige-6)", "beige-7": "var(--tgph-beige-7)", "beige-8": "var(--tgph-beige-8)", "beige-9": "var(--tgph-beige-9)", "beige-10": "var(--tgph-beige-10)", "beige-11": "var(--tgph-beige-11)", "beige-12": "var(--tgph-beige-12)", "accent-1": "var(--tgph-accent-1)", "accent-2": "var(--tgph-accent-2)", "accent-3": "var(--tgph-accent-3)", "accent-4": "var(--tgph-accent-4)", "accent-5": "var(--tgph-accent-5)", "accent-6": "var(--tgph-accent-6)", "accent-7": "var(--tgph-accent-7)", "accent-8": "var(--tgph-accent-8)", "accent-9": "var(--tgph-accent-9)", "accent-10": "var(--tgph-accent-10)", "accent-11": "var(--tgph-accent-11)", "accent-12": "var(--tgph-accent-12)", "green-1": "var(--tgph-green-1)", "green-2": "var(--tgph-green-2)", "green-3": "var(--tgph-green-3)", "green-4": "var(--tgph-green-4)", "green-5": "var(--tgph-green-5)", "green-6": "var(--tgph-green-6)", "green-7": "var(--tgph-green-7)", "green-8": "var(--tgph-green-8)", "green-9": "var(--tgph-green-9)", "green-10": "var(--tgph-green-10)", "green-11": "var(--tgph-green-11)", "green-12": "var(--tgph-green-12)", "yellow-1": "var(--tgph-yellow-1)", "yellow-2": "var(--tgph-yellow-2)", "yellow-3": "var(--tgph-yellow-3)", "yellow-4": "var(--tgph-yellow-4)", "yellow-5": "var(--tgph-yellow-5)", "yellow-6": "var(--tgph-yellow-6)", "yellow-7": "var(--tgph-yellow-7)", "yellow-8": "var(--tgph-yellow-8)", "yellow-9": "var(--tgph-yellow-9)", "yellow-10": "var(--tgph-yellow-10)", "yellow-11": "var(--tgph-yellow-11)", "yellow-12": "var(--tgph-yellow-12)", "blue-1": "var(--tgph-blue-1)", "blue-2": "var(--tgph-blue-2)", "blue-3": "var(--tgph-blue-3)", "blue-4": "var(--tgph-blue-4)", "blue-5": "var(--tgph-blue-5)", "blue-6": "var(--tgph-blue-6)", "blue-7": "var(--tgph-blue-7)", "blue-8": "var(--tgph-blue-8)", "blue-9": "var(--tgph-blue-9)", "blue-10": "var(--tgph-blue-10)", "blue-11": "var(--tgph-blue-11)", "blue-12": "var(--tgph-blue-12)", "red-1": "var(--tgph-red-1)", "red-2": "var(--tgph-red-2)", "red-3": "var(--tgph-red-3)", "red-4": "var(--tgph-red-4)", "red-5": "var(--tgph-red-5)", "red-6": "var(--tgph-red-6)", "red-7": "var(--tgph-red-7)", "red-8": "var(--tgph-red-8)", "red-9": "var(--tgph-red-9)", "red-10": "var(--tgph-red-10)", "red-11": "var(--tgph-red-11)", "red-12": "var(--tgph-red-12)", "purple-1": "var(--tgph-purple-1)", "purple-2": "var(--tgph-purple-2)", "purple-3": "var(--tgph-purple-3)", "purple-4": "var(--tgph-purple-4)", "purple-5": "var(--tgph-purple-5)", "purple-6": "var(--tgph-purple-6)", "purple-7": "var(--tgph-purple-7)", "purple-8": "var(--tgph-purple-8)", "purple-9": "var(--tgph-purple-9)", "purple-10": "var(--tgph-purple-10)", "purple-11": "var(--tgph-purple-11)", "purple-12": "var(--tgph-purple-12)" }, O = { 0: "var(--tgph-rounded-0)", 1: "var(--tgph-rounded-1)", 2: "var(--tgph-rounded-2)", 3: "var(--tgph-rounded-3)", 4: "var(--tgph-rounded-4)", 5: "var(--tgph-rounded-5)", 6: "var(--tgph-rounded-6)", full: "var(--tgph-rounded-full)" }, z = { 0: "var(--tgph-shadow-0)", 1: "var(--tgph-shadow-1)", 2: "var(--tgph-shadow-2)", 3: "var(--tgph-shadow-3)", inner: "var(--tgph-shadow-inner)" }, j = { 0: "var(--tgph-spacing-0)", 1: "var(--tgph-spacing-1)", 2: "var(--tgph-spacing-2)", 3: "var(--tgph-spacing-3)", 4: "var(--tgph-spacing-4)", 5: "var(--tgph-spacing-5)", 6: "var(--tgph-spacing-6)", 7: "var(--tgph-spacing-7)", 8: "var(--tgph-spacing-8)", 9: "var(--tgph-spacing-9)", 10: "var(--tgph-spacing-10)", 11: "var(--tgph-spacing-11)", 12: "var(--tgph-spacing-12)", 14: "var(--tgph-spacing-14)", 16: "var(--tgph-spacing-16)", 20: "var(--tgph-spacing-20)", 24: "var(--tgph-spacing-24)", 28: "var(--tgph-spacing-28)", 32: "var(--tgph-spacing-32)", 36: "var(--tgph-spacing-36)", 40: "var(--tgph-spacing-40)", 44: "var(--tgph-spacing-44)", 48: "var(--tgph-spacing-48)", 52: "var(--tgph-spacing-52)", 56: "var(--tgph-spacing-56)", 60: "var(--tgph-spacing-60)", 64: "var(--tgph-spacing-64)", 72: "var(--tgph-spacing-72)", 80: "var(--tgph-spacing-80)", 96: "var(--tgph-spacing-96)", 120: "var(--tgph-spacing-120)", 140: "var(--tgph-spacing-140)", 160: "var(--tgph-spacing-160)", px: "var(--tgph-spacing-px)", "0_5": "var(--tgph-spacing-0_5)", "1_5": "var(--tgph-spacing-1_5)", "2_5": "var(--tgph-spacing-2_5)", "3_5": "var(--tgph-spacing-3_5)", full: "var(--tgph-spacing-full)", auto: "var(--tgph-spacing-auto)" }, S = { sans: "var(--tgph-family-sans)", mono: "var(--tgph-family-mono)" }, E = { 0: "var(--tgph-leading-0)", 1: "var(--tgph-leading-1)", 2: "var(--tgph-leading-2)", 3: "var(--tgph-leading-3)", 4: "var(--tgph-leading-4)", 5: "var(--tgph-leading-5)", 6: "var(--tgph-leading-6)", 7: "var(--tgph-leading-7)", 8: "var(--tgph-leading-8)", 9: "var(--tgph-leading-9)", "code-0": "var(--tgph-leading-code-0)", "code-1": "var(--tgph-leading-code-1)", "code-2": "var(--tgph-leading-code-2)", "code-3": "var(--tgph-leading-code-3)", "code-4": "var(--tgph-leading-code-4)", "code-5": "var(--tgph-leading-code-5)", "code-6": "var(--tgph-leading-code-6)", "code-7": "var(--tgph-leading-code-7)", "code-8": "var(--tgph-leading-code-8)", "code-9": "var(--tgph-leading-code-9)" }, $ = { 0: "var(--tgph-tracking-0)", 1: "var(--tgph-tracking-1)", 2: "var(--tgph-tracking-2)", 3: "var(--tgph-tracking-3)", 4: "var(--tgph-tracking-4)", 5: "var(--tgph-tracking-5)", 6: "var(--tgph-tracking-6)", 7: "var(--tgph-tracking-7)", 8: "var(--tgph-tracking-8)", 9: "var(--tgph-tracking-9)" }, A = { 0: "var(--tgph-text-0)", 1: "var(--tgph-text-1)", 2: "var(--tgph-text-2)", 3: "var(--tgph-text-3)", 4: "var(--tgph-text-4)", 5: "var(--tgph-text-5)", 6: "var(--tgph-text-6)", 7: "var(--tgph-text-7)", 8: "var(--tgph-text-8)", 9: "var(--tgph-text-9)", "code-0": "var(--tgph-text-code-0)", "code-1": "var(--tgph-text-code-1)", "code-2": "var(--tgph-text-code-2)", "code-4": "var(--tgph-text-code-4)", "code-5": "var(--tgph-text-code-5)", "code-6": "var(--tgph-text-code-6)", "code-7": "var(--tgph-text-code-7)", "code-8": "var(--tgph-text-code-8)", "code-9": "var(--tgph-text-code-9)" }, N = { regular: "var(--tgph-weight-regular)", medium: "var(--tgph-weight-medium)", "semi-bold": "var(--tgph-weight-semi-bold)" }, C = { sm: "var(--tgph-breakpoint-sm)", md: "var(--tgph-breakpoint-md)", lg: "var(--tgph-breakpoint-lg)", xl: "var(--tgph-breakpoint-xl)", "2xl": "var(--tgph-breakpoint-2xl)" }, D = { hidden: "var(--tgph-zIndex-hidden)", base: "var(--tgph-zIndex-base)", auto: "var(--tgph-zIndex-auto)", dropdown: "var(--tgph-zIndex-dropdown)", sticky: "var(--tgph-zIndex-sticky)", banner: "var(--tgph-zIndex-banner)", overlay: "var(--tgph-zIndex-overlay)", modal: "var(--tgph-zIndex-modal)", popover: "var(--tgph-zIndex-popover)", skipLink: "var(--tgph-zIndex-skipLink)", toast: "var(--tgph-zIndex-toast)", tooltip: "var(--tgph-zIndex-tooltip)" }, X = {
|
|
3
3
|
"border-style": { solid: "var(--tgph-border-style-solid)", dashed: "var(--tgph-border-style-dashed)" },
|
|
4
|
-
color:
|
|
5
|
-
rounded:
|
|
6
|
-
shadow:
|
|
7
|
-
spacing:
|
|
8
|
-
family:
|
|
9
|
-
leading:
|
|
10
|
-
tracking:
|
|
11
|
-
text:
|
|
12
|
-
weight:
|
|
13
|
-
breakpoint:
|
|
14
|
-
zIndex:
|
|
15
|
-
},
|
|
4
|
+
color: I,
|
|
5
|
+
rounded: O,
|
|
6
|
+
shadow: z,
|
|
7
|
+
spacing: j,
|
|
8
|
+
family: S,
|
|
9
|
+
leading: E,
|
|
10
|
+
tracking: $,
|
|
11
|
+
text: A,
|
|
12
|
+
weight: N,
|
|
13
|
+
breakpoint: C,
|
|
14
|
+
zIndex: D
|
|
15
|
+
}, L = [
|
|
16
|
+
"_hover",
|
|
17
|
+
"_focus",
|
|
18
|
+
"_active",
|
|
19
|
+
"_focusWithin",
|
|
20
|
+
"_disabled"
|
|
21
|
+
], R = {
|
|
22
|
+
_hover: "hover",
|
|
23
|
+
_focus: "focus",
|
|
24
|
+
_active: "active",
|
|
25
|
+
_focusWithin: "focus-within",
|
|
26
|
+
_disabled: "disabled"
|
|
27
|
+
}, W = (e) => {
|
|
16
28
|
const a = [];
|
|
17
29
|
let t = "", g = 0;
|
|
18
|
-
for (let
|
|
19
|
-
const h = p
|
|
30
|
+
for (let p = 0; p < e.length; p++) {
|
|
31
|
+
const h = e[p];
|
|
20
32
|
h === "(" ? (g++, t += h) : h === ")" ? (g--, t += h) : h === " " && g === 0 ? t && (a.push(t), t = "") : t += h;
|
|
21
33
|
}
|
|
22
34
|
for (t && a.push(t); a.length < 4; )
|
|
@@ -27,90 +39,110 @@ const y = { transparent: "var(--tgph-transparent)", white: "var(--tgph-white)",
|
|
|
27
39
|
a[2] || "0",
|
|
28
40
|
a[3] || "0"
|
|
29
41
|
];
|
|
30
|
-
},
|
|
31
|
-
currentValueOfCssVar:
|
|
42
|
+
}, B = ({
|
|
43
|
+
currentValueOfCssVar: e = "0 0 0 0",
|
|
32
44
|
value: a,
|
|
33
45
|
direction: t
|
|
34
46
|
}) => {
|
|
35
|
-
const [g,
|
|
47
|
+
const [g, p, h, c] = W(e), r = {
|
|
36
48
|
top: g,
|
|
37
|
-
right:
|
|
49
|
+
right: p,
|
|
38
50
|
bottom: h,
|
|
39
|
-
left:
|
|
51
|
+
left: c
|
|
40
52
|
};
|
|
41
|
-
return t === "top" && (
|
|
42
|
-
},
|
|
43
|
-
currentValueOfCssVar:
|
|
53
|
+
return t === "top" && (r.top = a), t === "right" && (r.right = a), t === "bottom" && (r.bottom = a), t === "left" && (r.left = a), t === "all" && (r.top = a, r.right = a, r.bottom = a, r.left = a), t === "x" && (r.left = a, r.right = a), t === "y" && (r.top = a, r.bottom = a), t === "side-top" && (r.top = a, r.right = a), t === "side-bottom" && (r.bottom = a, r.left = a), t === "side-left" && (r.top = a, r.left = a), t === "side-right" && (r.right = a, r.bottom = a), Object.values(r).join(" ");
|
|
54
|
+
}, T = ({
|
|
55
|
+
currentValueOfCssVar: e = "visible visible",
|
|
44
56
|
value: a,
|
|
45
57
|
axis: t
|
|
46
58
|
}) => {
|
|
47
|
-
const [g,
|
|
48
|
-
return t === "x" ? `${a} ${
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
const [g, p] = e.split(" ");
|
|
60
|
+
return t === "x" ? `${a} ${p}` : t === "y" ? `${g} ${a}` : `${a} ${a}`;
|
|
61
|
+
}, u = (e, a) => {
|
|
62
|
+
if (typeof a == "string" && a.startsWith("-")) {
|
|
63
|
+
const g = a.slice(1);
|
|
64
|
+
return `calc(-1 * ${e.value.replace("VARIABLE", g)})`;
|
|
65
|
+
}
|
|
66
|
+
return e.value.replace("VARIABLE", a);
|
|
67
|
+
}, f = (e, a, t, g) => {
|
|
68
|
+
const p = g ?? a.cssVar;
|
|
69
|
+
if (a.direction) {
|
|
70
|
+
const h = e == null ? void 0 : e[p], c = B({
|
|
71
|
+
currentValueOfCssVar: h,
|
|
72
|
+
value: t,
|
|
73
|
+
direction: a.direction
|
|
74
|
+
});
|
|
75
|
+
return { ...e, [p]: c };
|
|
76
|
+
}
|
|
77
|
+
if (a.axis) {
|
|
78
|
+
const h = e == null ? void 0 : e[p], c = T({
|
|
79
|
+
currentValueOfCssVar: h,
|
|
80
|
+
value: t,
|
|
81
|
+
axis: a.axis
|
|
82
|
+
});
|
|
83
|
+
return { ...e, [p]: c };
|
|
84
|
+
}
|
|
85
|
+
return { ...e, [p]: t };
|
|
86
|
+
}, U = (e, a) => {
|
|
87
|
+
const t = R[a], g = e.replace(/^--/, "");
|
|
88
|
+
return `--${t}--${g}`;
|
|
89
|
+
}, F = (e) => {
|
|
90
|
+
const { cssVars: a } = e;
|
|
91
|
+
if (!(e != null && e.props) || Object.keys(e.props).length === 0)
|
|
52
92
|
return { styleProp: {}, otherProps: {}, interactive: !1 };
|
|
53
|
-
const { style: t = {}, ...g } =
|
|
54
|
-
let
|
|
93
|
+
const { style: t = {}, ...g } = e.props;
|
|
94
|
+
let p = t;
|
|
55
95
|
const h = {};
|
|
56
|
-
let
|
|
57
|
-
return Object.keys(g).forEach((
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
96
|
+
let c = !1;
|
|
97
|
+
return Object.keys(g).forEach((r) => {
|
|
98
|
+
const n = r;
|
|
99
|
+
if (L.includes(r) && typeof g[n] == "object" && g[n] !== null) {
|
|
100
|
+
const k = r, s = g[n], v = {};
|
|
101
|
+
if (Object.keys(s).forEach((l) => {
|
|
102
|
+
const d = s[l];
|
|
103
|
+
if (!d) return;
|
|
104
|
+
const x = l, i = a == null ? void 0 : a[x];
|
|
105
|
+
if (!i) {
|
|
106
|
+
v[l] = d;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const m = u(i, d), V = U(
|
|
110
|
+
i.cssVar,
|
|
111
|
+
k
|
|
112
|
+
);
|
|
113
|
+
p = f(
|
|
114
|
+
p,
|
|
115
|
+
i,
|
|
116
|
+
m,
|
|
117
|
+
V
|
|
118
|
+
);
|
|
119
|
+
}), Object.keys(v).length > 0) {
|
|
120
|
+
const l = h[r] || {};
|
|
121
|
+
Object.assign(h, {
|
|
122
|
+
[r]: { ...l, ...v }
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
Object.keys(s).length > Object.keys(v).length && (c = !0);
|
|
66
126
|
return;
|
|
67
127
|
}
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
c = `calc(-1 * ${l.value.replace(
|
|
72
|
-
"VARIABLE",
|
|
73
|
-
o
|
|
74
|
-
)})`;
|
|
75
|
-
} else
|
|
76
|
-
c = l.value.replace(
|
|
77
|
-
"VARIABLE",
|
|
78
|
-
n
|
|
79
|
-
);
|
|
80
|
-
const i = l.cssVar;
|
|
81
|
-
if (l.interactive && (s = !0), l.direction) {
|
|
82
|
-
const o = r == null ? void 0 : r[i], d = j({
|
|
83
|
-
currentValueOfCssVar: o,
|
|
84
|
-
value: c,
|
|
85
|
-
direction: l.direction
|
|
86
|
-
});
|
|
87
|
-
r = {
|
|
88
|
-
...r,
|
|
89
|
-
[i]: d
|
|
90
|
-
};
|
|
128
|
+
const w = n, o = a == null ? void 0 : a[w];
|
|
129
|
+
if (!o) {
|
|
130
|
+
Object.assign(h, { [n]: g[n] });
|
|
91
131
|
return;
|
|
92
132
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
value: c,
|
|
97
|
-
axis: l.axis
|
|
98
|
-
});
|
|
99
|
-
r = {
|
|
100
|
-
...r,
|
|
101
|
-
[i]: d
|
|
102
|
-
};
|
|
133
|
+
const b = g == null ? void 0 : g[n];
|
|
134
|
+
if (!b) {
|
|
135
|
+
Object.assign(p, { [n]: g[n] });
|
|
103
136
|
return;
|
|
104
137
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}), { styleProp: r, otherProps: h, interactive: s };
|
|
110
|
-
}, N = (p) => u.useMemo(() => C(p), [p]);
|
|
138
|
+
const y = u(o, b);
|
|
139
|
+
p = f(p, o, y);
|
|
140
|
+
}), { styleProp: p, otherProps: h, interactive: c };
|
|
141
|
+
}, q = (e) => _.useMemo(() => F(e), [e]);
|
|
111
142
|
export {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
143
|
+
L as PSEUDO_STATES,
|
|
144
|
+
F as getStyleProp,
|
|
145
|
+
X as tokens,
|
|
146
|
+
q as useStyleEngine
|
|
115
147
|
};
|
|
116
148
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/helpers/getStyleProp/getStyleProp.ts","../../src/hooks/useStyleEngine.ts"],"sourcesContent":["type Direction =\n | \"x\"\n | \"y\"\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"all\"\n | \"side-top\"\n | \"side-bottom\"\n | \"side-left\"\n | \"side-right\";\n\ntype Axis = \"x\" | \"y\" | \"both\";\n\nexport type CssVarProp = {\n cssVar: string;\n value: string;\n direction?: Direction;\n axis?: Axis;\n interactive?: boolean;\n};\n\n// Helper type to create negative spacing values\n// This distributes over union types for proper type expansion\nexport type NegativeSpacing<T extends string | number | symbol> =\n T extends string ? `-${T}` : never;\n\n// Type that allows both positive and negative spacing values for a given token type\n// Using direct template literal for better TypeScript inference and autocomplete\nexport type WithNegativeSpacing<T extends string | number | symbol> =\n T extends string ? T | `-${T}` : T;\n\ntype ApplyDirectionProps = {\n currentValueOfCssVar: string | undefined;\n value: string;\n direction?: Direction;\n};\n\n// Helper function to parse directional values (handles calc() expressions)\nconst parseDirectionalValues = (\n value: string,\n): [string, string, string, string] => {\n const matches: string[] = [];\n let current = \"\";\n let depth = 0;\n\n for (let i = 0; i < value.length; i++) {\n const char = value[i];\n\n if (char === \"(\") {\n depth++;\n current += char;\n } else if (char === \")\") {\n depth--;\n current += char;\n } else if (char === \" \" && depth === 0) {\n // Space at depth 0 means we're between values\n if (current) {\n matches.push(current);\n current = \"\";\n }\n } else {\n current += char;\n }\n }\n\n // Push the last value\n if (current) {\n matches.push(current);\n }\n\n // Ensure we always have 4 values\n while (matches.length < 4) {\n matches.push(\"0\");\n }\n\n return [\n matches[0] || \"0\",\n matches[1] || \"0\",\n matches[2] || \"0\",\n matches[3] || \"0\",\n ];\n};\n\n// For values like margin and padding that require 4 values\nconst applyDirectionalValues = ({\n currentValueOfCssVar = \"0 0 0 0\",\n value,\n direction,\n}: ApplyDirectionProps) => {\n const [top, right, bottom, left] =\n parseDirectionalValues(currentValueOfCssVar);\n\n const newValues = {\n top,\n right,\n bottom,\n left,\n };\n\n if (direction === \"top\") {\n newValues.top = value;\n }\n\n if (direction === \"right\") {\n newValues.right = value;\n }\n\n if (direction === \"bottom\") {\n newValues.bottom = value;\n }\n\n if (direction === \"left\") {\n newValues.left = value;\n }\n\n if (direction === \"all\") {\n newValues.top = value;\n newValues.right = value;\n newValues.bottom = value;\n newValues.left = value;\n }\n\n if (direction === \"x\") {\n newValues.left = value;\n newValues.right = value;\n }\n\n if (direction === \"y\") {\n newValues.top = value;\n newValues.bottom = value;\n }\n\n // \"side\" direction is used for things like border-radius\n // where we are settings values on corners instead of sides\n // entire sides like padding and margin provide.\n if (direction === \"side-top\") {\n newValues.top = value;\n newValues.right = value;\n }\n\n if (direction === \"side-bottom\") {\n newValues.bottom = value;\n newValues.left = value;\n }\n\n if (direction === \"side-left\") {\n newValues.top = value;\n newValues.left = value;\n }\n\n if (direction === \"side-right\") {\n newValues.right = value;\n newValues.bottom = value;\n }\n\n const newValuesString = Object.values(newValues).join(\" \");\n\n return newValuesString;\n};\n\ntype ApplyAxisValuesProps = {\n currentValueOfCssVar: string | undefined;\n value: string;\n axis: Axis;\n};\n\nconst applyAxisValues = ({\n currentValueOfCssVar = \"visible visible\",\n value,\n axis,\n}: ApplyAxisValuesProps) => {\n const [x, y] = currentValueOfCssVar.split(\" \");\n\n // If the axis is x, we need to set the x value and keep the y value.\n if (axis === \"x\") {\n return `${value} ${y}`;\n }\n\n // If the axis is y, we need to set the y value and keep the x value.\n if (axis === \"y\") {\n return `${x} ${value}`;\n }\n\n // If the axis is both, we need to set the x and y values.\n return `${value} ${value}`;\n};\n\nexport type CssVarsPropObject<CssVars extends CssVarsPropObject<CssVars>> =\n Record<keyof CssVars, CssVarProp>;\n\ntype CssVarPropKey<CssVars extends CssVarsPropObject<CssVars>> = keyof CssVars;\n\n// Allow for explicitly defined props that are not css vars to end to end typesafe\ntype OtherProps<CssVars extends CssVarsPropObject<CssVars>, Props> =\n | Omit<\n {\n [key in keyof Props]: Props[key];\n },\n CssVarPropKey<CssVars>\n >\n | object;\n\n// Allow for explicitly defined css vars return css variables object created\n// by this function and be end to end typesafe\ntype StyleProp<CssVars extends CssVarsPropObject<CssVars>> =\n | {\n [key in CssVars[keyof CssVars][\"cssVar\"]]: string;\n }\n | object;\n\ntype GetStylePropParams<CssVars, Props> = {\n props: Props & { style?: Record<string, string> };\n cssVars: CssVars;\n};\n\nexport const getStyleProp = <\n CssVars extends CssVarsPropObject<CssVars>,\n Props extends Record<string, unknown>,\n>(\n params: GetStylePropParams<CssVars, Props>,\n): {\n styleProp: StyleProp<CssVars>;\n otherProps: OtherProps<CssVars, Props>;\n interactive: boolean;\n} => {\n const { cssVars } = params;\n\n if (!params?.props || Object.keys(params.props).length === 0) {\n return { styleProp: {}, otherProps: {}, interactive: false };\n }\n\n // Assign the additional styles to the style object so that it can be passed\n // to the component as a prop.\n const { style = {}, ...props } = params.props;\n\n let styleProp: StyleProp<CssVars> = style;\n const otherProps: OtherProps<CssVars, Props> = {};\n let interactive = false;\n\n Object.keys(props).forEach((_key) => {\n const key = _key as keyof typeof props;\n const cssVarsKey = key as unknown as keyof typeof cssVars;\n const matchingCssVar = cssVars?.[cssVarsKey];\n\n // If the prop is not a css var, just add it to the otherProps\n if (!matchingCssVar) {\n Object.assign(otherProps, { [key]: props[key] });\n return;\n }\n\n const matchingPropValue = props?.[key] as string | undefined;\n\n if (!matchingPropValue) {\n Object.assign(styleProp, { [key]: props[key] });\n return;\n }\n\n // Handle negative spacing values\n let mappedValueOfCssVar: string;\n const isNegative =\n typeof matchingPropValue === \"string\" &&\n matchingPropValue.startsWith(\"-\");\n\n if (isNegative) {\n // Remove the \"-\" prefix to get the actual token key\n const positiveValue = matchingPropValue.slice(1);\n // Replace VARIABLE with the positive token and wrap in calc()\n const positiveVar = matchingCssVar.value.replace(\n \"VARIABLE\",\n positiveValue,\n );\n mappedValueOfCssVar = `calc(-1 * ${positiveVar})`;\n } else {\n // Replace the VARIABLE placeholder with the actual value of the prop\n mappedValueOfCssVar = matchingCssVar.value.replace(\n \"VARIABLE\",\n matchingPropValue,\n );\n }\n\n const cssVarName = matchingCssVar.cssVar as keyof StyleProp<CssVars>;\n\n // If the style contains an interactive prop, set the interactive flag to true\n // so that the component can include the interactive class\n if (matchingCssVar.interactive) {\n interactive = true;\n }\n\n if (matchingCssVar.direction) {\n const currentValueOfCssVar = styleProp?.[cssVarName];\n\n const directionalValue = applyDirectionalValues({\n currentValueOfCssVar,\n value: mappedValueOfCssVar,\n direction: matchingCssVar.direction,\n });\n\n styleProp = {\n ...styleProp,\n [cssVarName]: directionalValue,\n };\n return;\n }\n\n if (matchingCssVar.axis) {\n const currentValueOfCssVar = styleProp?.[cssVarName];\n const axisValue = applyAxisValues({\n currentValueOfCssVar,\n value: mappedValueOfCssVar,\n axis: matchingCssVar.axis,\n });\n\n styleProp = {\n ...styleProp,\n [cssVarName]: axisValue,\n };\n return;\n }\n\n styleProp = {\n ...styleProp,\n [cssVarName]: mappedValueOfCssVar,\n };\n });\n\n return { styleProp, otherProps, interactive };\n};\n","import React from \"react\";\n\nimport { type CssVarProp, getStyleProp } from \"../helpers/getStyleProp\";\n\ntype CssVarsPropObject<CssVars> = Record<keyof CssVars, CssVarProp>;\n\nexport const useStyleEngine = <\n CssVars extends CssVarsPropObject<CssVars>,\n Props extends Record<string, unknown>,\n>(\n params: Parameters<typeof getStyleProp<CssVars, Props>>[0],\n) => {\n return React.useMemo(() => getStyleProp(params), [params]);\n};\n"],"names":["parseDirectionalValues","value","matches","current","depth","i","char","applyDirectionalValues","currentValueOfCssVar","direction","top","right","bottom","left","newValues","applyAxisValues","axis","x","y","getStyleProp","params","cssVars","style","props","styleProp","otherProps","interactive","_key","key","cssVarsKey","matchingCssVar","matchingPropValue","mappedValueOfCssVar","positiveValue","cssVarName","directionalValue","axisValue","useStyleEngine","React"],"mappings":";;;;;;;;;;;;;;GAwCMA,IAAyB,CAC7BC,MACqC;AACrC,QAAMC,IAAoB,CAAA;AAC1B,MAAIC,IAAU,IACVC,IAAQ;AAEZ,WAASC,IAAI,GAAGA,IAAIJ,EAAM,QAAQI,KAAK;AACrC,UAAMC,IAAOL,EAAMI,CAAC;AAEpB,IAAIC,MAAS,OACXF,KACAD,KAAWG,KACFA,MAAS,OAClBF,KACAD,KAAWG,KACFA,MAAS,OAAOF,MAAU,IAE/BD,MACFD,EAAQ,KAAKC,CAAO,GACp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MAAM;AAAA,QACzC;AAAA,QACAC;AAAA,MAAA;AAIJ,UAAMG,IAAaJ,EAAe;AAQlC,QAJIA,EAAe,gBACjBJ,IAAc,KAGZI,EAAe,WAAW;AAC5B,YAAMtB,IAAuBgB,KAAA,gBAAAA,EAAYU,IAEnCC,IAAmB5B,EAAuB;AAAA,QAC9C,sBAAAC;AAAA,QACA,OAAOwB;AAAA,QACP,WAAWF,EAAe;AAAA,MAAA,CAC3B;AAED,MAAAN,IAAY;AAAA,QACV,GAAGA;AAAA,QACH,CAACU,CAAU,GAAGC;AAAA,MAAA;AAEhB;AAAA,IACF;AAEA,QAAIL,EAAe,MAAM;AACvB,YAAMtB,IAAuBgB,KAAA,gBAAAA,EAAYU,IACnCE,IAAYrB,EAAgB;AAAA,QAChC,sBAAAP;AAAA,QACA,OAAOwB;AAAA,QACP,MAAMF,EAAe;AAAA,MAAA,CACtB;AAED,MAAAN,IAAY;AAAA,QACV,GAAGA;AAAA,QACH,CAACU,CAAU,GAAGE;AAAA,MAAA;AAEhB;AAAA,IACF;AAEA,IAAAZ,IAAY;AAAA,MACV,GAAGA;AAAA,MACH,CAACU,CAAU,GAAGF;AAAA,IAAA;AAAA,EAElB,CAAC,GAEM,EAAE,WAAAR,GAAW,YAAAC,GAAY,aAAAC,EAAA;AAClC,GClUaW,IAAiB,CAI5BjB,MAEOkB,EAAM,QAAQ,MAAMnB,EAAaC,CAAM,GAAG,CAACA,CAAM,CAAC;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/helpers/getStyleProp/getStyleProp.ts","../../src/hooks/useStyleEngine.ts"],"sourcesContent":["type Direction =\n | \"x\"\n | \"y\"\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"all\"\n | \"side-top\"\n | \"side-bottom\"\n | \"side-left\"\n | \"side-right\";\n\ntype Axis = \"x\" | \"y\" | \"both\";\n\nexport type CssVarProp = {\n cssVar: string;\n value: string;\n direction?: Direction;\n axis?: Axis;\n};\n\n// Supported pseudo-class states for the object syntax\n// Prefixed with underscore to avoid collisions with native HTML attributes\n// (e.g. `disabled`) and common component props (e.g. `active`).\nexport const PSEUDO_STATES = [\n \"_hover\",\n \"_focus\",\n \"_active\",\n \"_focusWithin\",\n \"_disabled\",\n] as const;\n\nexport type PseudoState = (typeof PSEUDO_STATES)[number];\n\n// Maps pseudo state names to CSS variable prefixes\nconst PSEUDO_CSS_PREFIX: Record<PseudoState, string> = {\n _hover: \"hover\",\n _focus: \"focus\",\n _active: \"active\",\n _focusWithin: \"focus-within\",\n _disabled: \"disabled\",\n};\n\n/**\n * Adds pseudo-class variant props to a style props type.\n *\n * Given a base style props type, this creates a new type that also\n * accepts `_hover`, `_focus`, `_active`, `_focusWithin`, and `_disabled`\n * props as objects containing any of the base style props.\n *\n * Prefixed with underscore to avoid collisions with native HTML attributes\n * (e.g. `disabled`) and common component props (e.g. `active`).\n *\n * @example\n * type BoxStyle = { bg: ColorToken; p: SpacingToken };\n * type BoxStyleWithPseudo = WithPseudo<BoxStyle>;\n * // Allows: { bg: \"gray-2\", _hover: { bg: \"gray-3\" }, _focus: { p: \"4\" } }\n */\nexport type WithPseudo<Props> = Props & {\n _hover?: Partial<Props>;\n _focus?: Partial<Props>;\n _active?: Partial<Props>;\n _focusWithin?: Partial<Props>;\n _disabled?: Partial<Props>;\n};\n\n// Helper type to create negative spacing values\n// This distributes over union types for proper type expansion\nexport type NegativeSpacing<T extends string | number | symbol> =\n T extends string ? `-${T}` : never;\n\n// Type that allows both positive and negative spacing values for a given token type\n// Using direct template literal for better TypeScript inference and autocomplete\nexport type WithNegativeSpacing<T extends string | number | symbol> =\n T extends string ? T | `-${T}` : T;\n\ntype ApplyDirectionProps = {\n currentValueOfCssVar: string | undefined;\n value: string;\n direction?: Direction;\n};\n\n// Helper function to parse directional values (handles calc() expressions)\nconst parseDirectionalValues = (\n value: string,\n): [string, string, string, string] => {\n const matches: string[] = [];\n let current = \"\";\n let depth = 0;\n\n for (let i = 0; i < value.length; i++) {\n const char = value[i];\n\n if (char === \"(\") {\n depth++;\n current += char;\n } else if (char === \")\") {\n depth--;\n current += char;\n } else if (char === \" \" && depth === 0) {\n // Space at depth 0 means we're between values\n if (current) {\n matches.push(current);\n current = \"\";\n }\n } else {\n current += char;\n }\n }\n\n // Push the last value\n if (current) {\n matches.push(current);\n }\n\n // Ensure we always have 4 values\n while (matches.length < 4) {\n matches.push(\"0\");\n }\n\n return [\n matches[0] || \"0\",\n matches[1] || \"0\",\n matches[2] || \"0\",\n matches[3] || \"0\",\n ];\n};\n\n// For values like margin and padding that require 4 values\nconst applyDirectionalValues = ({\n currentValueOfCssVar = \"0 0 0 0\",\n value,\n direction,\n}: ApplyDirectionProps) => {\n const [top, right, bottom, left] =\n parseDirectionalValues(currentValueOfCssVar);\n\n const newValues = {\n top,\n right,\n bottom,\n left,\n };\n\n if (direction === \"top\") {\n newValues.top = value;\n }\n\n if (direction === \"right\") {\n newValues.right = value;\n }\n\n if (direction === \"bottom\") {\n newValues.bottom = value;\n }\n\n if (direction === \"left\") {\n newValues.left = value;\n }\n\n if (direction === \"all\") {\n newValues.top = value;\n newValues.right = value;\n newValues.bottom = value;\n newValues.left = value;\n }\n\n if (direction === \"x\") {\n newValues.left = value;\n newValues.right = value;\n }\n\n if (direction === \"y\") {\n newValues.top = value;\n newValues.bottom = value;\n }\n\n // \"side\" direction is used for things like border-radius\n // where we are settings values on corners instead of sides\n // entire sides like padding and margin provide.\n if (direction === \"side-top\") {\n newValues.top = value;\n newValues.right = value;\n }\n\n if (direction === \"side-bottom\") {\n newValues.bottom = value;\n newValues.left = value;\n }\n\n if (direction === \"side-left\") {\n newValues.top = value;\n newValues.left = value;\n }\n\n if (direction === \"side-right\") {\n newValues.right = value;\n newValues.bottom = value;\n }\n\n const newValuesString = Object.values(newValues).join(\" \");\n\n return newValuesString;\n};\n\ntype ApplyAxisValuesProps = {\n currentValueOfCssVar: string | undefined;\n value: string;\n axis: Axis;\n};\n\nconst applyAxisValues = ({\n currentValueOfCssVar = \"visible visible\",\n value,\n axis,\n}: ApplyAxisValuesProps) => {\n const [x, y] = currentValueOfCssVar.split(\" \");\n\n // If the axis is x, we need to set the x value and keep the y value.\n if (axis === \"x\") {\n return `${value} ${y}`;\n }\n\n // If the axis is y, we need to set the y value and keep the x value.\n if (axis === \"y\") {\n return `${x} ${value}`;\n }\n\n // If the axis is both, we need to set the x and y values.\n return `${value} ${value}`;\n};\n\nexport type CssVarsPropObject<CssVars extends CssVarsPropObject<CssVars>> =\n Record<keyof CssVars, CssVarProp>;\n\ntype CssVarPropKey<CssVars extends CssVarsPropObject<CssVars>> = keyof CssVars;\n\n// Allow for explicitly defined props that are not css vars to end to end typesafe\ntype OtherProps<CssVars extends CssVarsPropObject<CssVars>, Props> =\n | Omit<\n {\n [key in keyof Props]: Props[key];\n },\n CssVarPropKey<CssVars>\n >\n | object;\n\n// Allow for explicitly defined css vars return css variables object created\n// by this function and be end to end typesafe\ntype StyleProp<CssVars extends CssVarsPropObject<CssVars>> =\n | {\n [key in CssVars[keyof CssVars][\"cssVar\"]]: string;\n }\n | object;\n\ntype GetStylePropParams<CssVars, Props> = {\n props: Props & { style?: Record<string, string> };\n cssVars: CssVars;\n};\n\n// Resolves a single prop value against its matching CssVarProp definition.\n// Returns the mapped CSS variable value string, handling negative spacing.\nconst resolveValue = (\n matchingCssVar: CssVarProp,\n propValue: string,\n): string => {\n const isNegative = typeof propValue === \"string\" && propValue.startsWith(\"-\");\n\n if (isNegative) {\n const positiveValue = propValue.slice(1);\n const positiveVar = matchingCssVar.value.replace(\"VARIABLE\", positiveValue);\n return `calc(-1 * ${positiveVar})`;\n }\n\n return matchingCssVar.value.replace(\"VARIABLE\", propValue);\n};\n\n// Applies a resolved CSS variable value to the styleProp object,\n// handling directional and axis properties.\nconst applyCssVar = <CssVars extends CssVarsPropObject<CssVars>>(\n styleProp: StyleProp<CssVars>,\n matchingCssVar: CssVarProp,\n mappedValue: string,\n cssVarNameOverride?: string,\n): StyleProp<CssVars> => {\n const cssVarName = (cssVarNameOverride ??\n matchingCssVar.cssVar) as keyof StyleProp<CssVars>;\n\n if (matchingCssVar.direction) {\n const currentValueOfCssVar = styleProp?.[cssVarName];\n const directionalValue = applyDirectionalValues({\n currentValueOfCssVar,\n value: mappedValue,\n direction: matchingCssVar.direction,\n });\n return { ...styleProp, [cssVarName]: directionalValue };\n }\n\n if (matchingCssVar.axis) {\n const currentValueOfCssVar = styleProp?.[cssVarName];\n const axisValue = applyAxisValues({\n currentValueOfCssVar,\n value: mappedValue,\n axis: matchingCssVar.axis,\n });\n return { ...styleProp, [cssVarName]: axisValue };\n }\n\n return { ...styleProp, [cssVarName]: mappedValue };\n};\n\n// Creates a state-prefixed CSS variable name from a base CSS variable.\n// e.g. (\"--background-color\", \"hover\") => \"--hover--background-color\"\nconst createPseudoCssVarName = (\n baseCssVar: string,\n pseudoState: PseudoState,\n): string => {\n const prefix = PSEUDO_CSS_PREFIX[pseudoState];\n const baseName = baseCssVar.replace(/^--/, \"\");\n return `--${prefix}--${baseName}`;\n};\n\nexport const getStyleProp = <\n CssVars extends CssVarsPropObject<CssVars>,\n Props extends Record<string, unknown>,\n>(\n params: GetStylePropParams<CssVars, Props>,\n): {\n styleProp: StyleProp<CssVars>;\n otherProps: OtherProps<CssVars, Props>;\n interactive: boolean;\n} => {\n const { cssVars } = params;\n\n if (!params?.props || Object.keys(params.props).length === 0) {\n return { styleProp: {}, otherProps: {}, interactive: false };\n }\n\n // Assign the additional styles to the style object so that it can be passed\n // to the component as a prop.\n const { style = {}, ...props } = params.props;\n\n let styleProp: StyleProp<CssVars> = style;\n const otherProps: OtherProps<CssVars, Props> = {};\n let interactive = false;\n\n Object.keys(props).forEach((_key) => {\n const key = _key as keyof typeof props;\n\n // Check if this is a pseudo-class object prop (hover, focus, active, etc.)\n if (\n PSEUDO_STATES.includes(_key as PseudoState) &&\n typeof props[key] === \"object\" &&\n props[key] !== null\n ) {\n const pseudoState = _key as PseudoState;\n const pseudoProps = props[key] as Record<string, string | undefined>;\n const unmatchedPseudoProps: Record<string, string> = {};\n\n Object.keys(pseudoProps).forEach((pseudoPropKey) => {\n const propValue = pseudoProps[pseudoPropKey];\n if (!propValue) return;\n\n const cssVarsKey = pseudoPropKey as unknown as keyof typeof cssVars;\n const matchingCssVar = cssVars?.[cssVarsKey];\n\n if (!matchingCssVar) {\n // Collect unmatched pseudo props to pass through to otherProps\n unmatchedPseudoProps[pseudoPropKey] = propValue;\n return;\n }\n\n const mappedValue = resolveValue(matchingCssVar, propValue);\n const pseudoCssVarName = createPseudoCssVarName(\n matchingCssVar.cssVar,\n pseudoState,\n );\n\n styleProp = applyCssVar(\n styleProp,\n matchingCssVar,\n mappedValue,\n pseudoCssVarName,\n );\n });\n\n // Pass through any unmatched pseudo props so downstream components\n // can process them (e.g. Button passes hover.backgroundColor to Box)\n if (Object.keys(unmatchedPseudoProps).length > 0) {\n const existingPseudo =\n (otherProps as Record<string, unknown>)[_key] || {};\n Object.assign(otherProps, {\n [_key]: { ...existingPseudo, ...unmatchedPseudoProps },\n });\n }\n\n // If any pseudo sub-props were matched against cssVars at this level,\n // mark as interactive so the component adds the scoping class.\n // This prevents pseudo-class CSS rules from cascading into child elements.\n if (\n Object.keys(pseudoProps).length >\n Object.keys(unmatchedPseudoProps).length\n ) {\n interactive = true;\n }\n\n return;\n }\n\n const cssVarsKey = key as unknown as keyof typeof cssVars;\n const matchingCssVar = cssVars?.[cssVarsKey];\n\n // If the prop is not a css var, just add it to the otherProps\n if (!matchingCssVar) {\n Object.assign(otherProps, { [key]: props[key] });\n return;\n }\n\n const matchingPropValue = props?.[key] as string | undefined;\n\n if (!matchingPropValue) {\n Object.assign(styleProp, { [key]: props[key] });\n return;\n }\n\n const mappedValueOfCssVar = resolveValue(matchingCssVar, matchingPropValue);\n\n styleProp = applyCssVar(styleProp, matchingCssVar, mappedValueOfCssVar);\n });\n\n return { styleProp, otherProps, interactive };\n};\n","import React from \"react\";\n\nimport { type CssVarProp, getStyleProp } from \"../helpers/getStyleProp\";\n\ntype CssVarsPropObject<CssVars> = Record<keyof CssVars, CssVarProp>;\n\nexport const useStyleEngine = <\n CssVars extends CssVarsPropObject<CssVars>,\n Props extends Record<string, unknown>,\n>(\n params: Parameters<typeof getStyleProp<CssVars, Props>>[0],\n) => {\n return React.useMemo(() => getStyleProp(params), [params]);\n};\n"],"names":["PSEUDO_STATES","PSEUDO_CSS_PREFIX","parseDirectionalValues","value","matches","current","depth","i","char","applyDirectionalValues","currentValueOfCssVar","direction","top","right","bottom","left","newValues","applyAxisValues","axis","x","y","resolveValue","matchingCssVar","propValue","positiveValue","applyCssVar","styleProp","mappedValue","cssVarNameOverride","cssVarName","directionalValue","axisValue","createPseudoCssVarName","baseCssVar","pseudoState","prefix","baseName","getStyleProp","params","cssVars","style","props","otherProps","interactive","_key","key","pseudoProps","unmatchedPseudoProps","pseudoPropKey","cssVarsKey","pseudoCssVarName","existingPseudo","matchingPropValue","mappedValueOfCssVar","useStyleEngine","React"],"mappings":";;;;;;;;;;;;;;GAyBaA,IAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKMC,IAAiD;AAAA,EACrD,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,cAAc;AAAA,EACd,WAAW;AACb,GA0CMC,IAAyB,CAC7BC,MACqC;AACrC,QAAMC,IAAoB,CAAA;AAC1B,MAAIC,IAAU,IACVC,IAAQ;AAEZ,WAASC,IAAI,GAAGA,IAAIJ,EAAM,QAAQI,KAAK;AACrC,UAAMC,IAAOL,EAAMI,CAAC;AAEpB,IAAIC,MAAS,OACXF,KACAD,KAAWG,KACFA,MAAS,OAClBF,KACAD,KAAWG,KACFA,MAAS,OAAOF,MAAU,IAE/BD,MACFD,EAAQ,KAAKC,CAAO,GACpBA,IAAU,MAGZA,KAAWG;AAAA,EAEf;AAQA,OALIH,KACFD,EAAQ,KAAKC,CAAO,GAIfD,EAAQ,SAAS;AACtB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,MACH;AAKA,MACE,OAAO,KAAKD,CAAW,EAAE,SACzB,OAAO,KAAKC,CAAoB,EAAE,WAElCJ,IAAc;AAGhB;AAAA,IACF;AAEA,UAAMM,IAAaJ,GACbvB,IAAiBiB,KAAA,gBAAAA,EAAUU;AAGjC,QAAI,CAAC3B,GAAgB;AACnB,aAAO,OAAOoB,GAAY,EAAE,CAACG,CAAG,GAAGJ,EAAMI,CAAG,GAAG;AAC/C;AAAA,IACF;AAEA,UAAMO,IAAoBX,KAAA,gBAAAA,EAAQI;AAElC,QAAI,CAACO,GAAmB;AACtB,aAAO,OAAO1B,GAAW,EAAE,CAACmB,CAAG,GAAGJ,EAAMI,CAAG,GAAG;AAC9C;AAAA,IACF;AAEA,UAAMQ,IAAsBhC,EAAaC,GAAgB8B,CAAiB;AAE1E,IAAA1B,IAAYD,EAAYC,GAAWJ,GAAgB+B,CAAmB;AAAA,EACxE,CAAC,GAEM,EAAE,WAAA3B,GAAW,YAAAgB,GAAY,aAAAC,EAAA;AAClC,GC1aaW,IAAiB,CAI5BhB,MAEOiB,EAAM,QAAQ,MAAMlB,EAAaC,CAAM,GAAG,CAACA,CAAM,CAAC;"}
|
package/dist/esm/postcss.mjs
CHANGED
package/dist/esm/postcss.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postcss.mjs","sources":["../../src/plugins/postcss.ts"],"sourcesContent":["import { type AcceptedPlugin, type PluginCreator, type Root } from \"postcss\";\n\n// Using require() instead of import to prevent ESM-related bugs in PostCSS.\n// ESM = ECMAScript Modules (the import/export syntax)\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst nodePath = require(\"path\");\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst nodeFs = require(\"fs\");\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst postcss = require(\"postcss\");\n\ntype PkgJson = {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n};\n\ntype DepObject = Record<\n string,\n {\n name: string;\n version: string;\n path: string;\n }\n>;\n\n/**\n * Traverses up the directory tree to find the root of the monorepo by looking for a package.json with workspaces.\n * This is needed to properly resolve workspace dependencies in a monorepo setup.\n */\nfunction findMonorepoRoot(start = process.cwd()): string | undefined {\n let current = start;\n let run = true;\n\n while (run) {\n const pkgJsonPath = nodePath.join(current, \"package.json\");\n if (nodeFs.existsSync(pkgJsonPath)) {\n try {\n const pkg = JSON.parse(nodeFs.readFileSync(pkgJsonPath, \"utf8\"));\n if (pkg.workspaces) {\n return current;\n }\n } catch {\n // malformed package.json, skip\n }\n }\n\n const parent = nodePath.dirname(current);\n if (parent === current) run = false;\n current = parent;\n }\n\n return undefined;\n}\n\n/**\n * Extracts all @telegraph/* dependencies from a package.json file and returns them with their paths.\n * This is used to find all Telegraph packages that might contain CSS we need to include.\n */\nconst getTelegraphDepsFromPackageJson = (\n pkg: PkgJson,\n pkgPath: string,\n): DepObject | undefined => {\n if (!pkg.dependencies || Object.keys(pkg.dependencies)?.length === 0) return;\n\n return Object.entries(pkg.dependencies).reduce((acc, [dep, version]) => {\n if (dep.startsWith(\"@telegraph/\")) {\n acc[dep] = {\n name: dep,\n version,\n path: nodePath.resolve(pkgPath, \"node_modules\", dep),\n };\n }\n return acc;\n }, {} as DepObject);\n};\n\n/**\n * Gets all Telegraph dependencies recursively, including dependencies of dependencies.\n * Handles both normal npm dependencies and workspace dependencies in a monorepo.\n */\nfunction getTelegraphDeps(): DepObject {\n const pkgPath = nodePath.resolve(process.cwd(), \"package.json\");\n const pkg = JSON.parse(nodeFs.readFileSync(pkgPath, \"utf8\"));\n const topLevelDeps = getTelegraphDepsFromPackageJson(pkg, process.cwd());\n const monorepoRoot = findMonorepoRoot();\n\n const recursivelyGetTelegraphDeps = (deps: DepObject): DepObject => {\n if (!deps || Object.keys(deps).length === 0) {\n return deps;\n }\n\n const allDeps = { ...deps };\n\n for (const dep of Object.values(deps)) {\n let pkgJsonPath: string;\n let searchPath: string;\n\n if (dep.version.includes(\"workspace:\") && monorepoRoot) {\n pkgJsonPath = nodePath.resolve(\n monorepoRoot,\n \"node_modules\",\n dep.name,\n \"package.json\",\n );\n searchPath = monorepoRoot;\n } else {\n pkgJsonPath = nodePath.resolve(\n process.cwd(),\n \"node_modules\",\n dep.name,\n \"package.json\",\n );\n searchPath = process.cwd();\n }\n\n try {\n const pkgJson = JSON.parse(nodeFs.readFileSync(pkgJsonPath, \"utf8\"));\n const deps = getTelegraphDepsFromPackageJson(pkgJson, searchPath);\n\n // Merge new dependencies into allDeps\n Object.assign(allDeps, deps);\n\n if (deps) {\n // Recursively get dependencies of dependencies\n const nestedDeps = recursivelyGetTelegraphDeps(deps);\n Object.assign(allDeps, nestedDeps);\n }\n } catch (_err) {\n // Skip if package.json cannot be read\n continue;\n }\n }\n\n return allDeps;\n };\n\n if (topLevelDeps) {\n return recursivelyGetTelegraphDeps(topLevelDeps);\n }\n\n return {};\n}\n\ntype GetCssStylesParams = {\n fileName?: string;\n path: string;\n};\n\n/**\n * Reads CSS file content from a Telegraph package's dist/css directory.\n * Returns null if the file doesn't exist or can't be read.\n */\nfunction getCssStyles({\n fileName = \"default.css\",\n path,\n}: GetCssStylesParams): string | null {\n try {\n const cssPath = `${path}/dist/css/${fileName}`;\n const pkgPath = nodePath.resolve(cssPath);\n\n if (nodeFs.existsSync(pkgPath)) {\n return nodeFs.readFileSync(pkgPath, \"utf8\");\n }\n\n return null;\n } catch {\n return null;\n }\n}\n\ntype BuildTelegraphCssParams = {\n root: Root;\n config: {\n tokens: Array<\"light\" | \"dark\" | \"default\">;\n components: boolean;\n };\n};\n\n/**\n * Main function that builds the final CSS by:\n * 1. Getting all Telegraph dependencies\n * 2. Filtering for either token packages or component packages based on config\n * 3. Reading their CSS files\n * 4. Appending all CSS to the PostCSS Root node\n */\nconst buildTelegraphCss = async ({ root, config }: BuildTelegraphCssParams) => {\n const deps = getTelegraphDeps();\n\n const depsWithoutTokens =\n config.components === true\n ? Object.values(deps).filter(\n (dep) => !dep.name.includes(\"@telegraph/tokens\"),\n )\n : [];\n\n const tokensDeps =\n config.tokens.length > 0\n ? Object.values(deps).filter((dep) =>\n dep.name.includes(\"@telegraph/tokens\"),\n )\n : [];\n\n const cssFiles = depsWithoutTokens\n .map((dep) => getCssStyles({ path: dep.path }))\n .filter(Boolean) as Array<string>;\n\n const tokensCssFiles = config.tokens\n .map((token) => {\n const cssFile = tokensDeps.map((dep) =>\n getCssStyles({ path: dep.path, fileName: `${token}.css` }),\n );\n\n return cssFile.filter(Boolean) as Array<string>;\n })\n .filter(Boolean);\n\n const allCssFiles = [...cssFiles, ...tokensCssFiles];\n\n for (const content of allCssFiles) {\n const parsed = postcss.parse(content);\n root.append(parsed);\n }\n};\n\n/**\n * PostCSS plugin that processes @telegraph rules in CSS files.\n * It looks for @telegraph tokens, @telegraph tokens-light, @telegraph tokens-dark,\n * and @telegraph components rules and includes the appropriate CSS from Telegraph packages.\n */\nconst styleEnginePostCssPlugin = (): AcceptedPlugin => {\n return {\n postcssPlugin: \"@telegraph/style-engine\",\n plugins: [\n {\n postcssPlugin: \"telegraph\",\n AtRule: {\n telegraph() {},\n },\n async Once(root) {\n const run = {\n tokens: [] as BuildTelegraphCssParams[\"config\"][\"tokens\"],\n components: false,\n };\n root.walkAtRules(\"telegraph\", (atRule) => {\n if (atRule.params === \"components\") {\n run.components = true;\n atRule.remove();\n }\n\n if (atRule.params === \"tokens-light\") {\n run.tokens.push(\"light\");\n atRule.remove();\n }\n\n if (atRule.params === \"tokens-dark\") {\n run.tokens.push(\"dark\");\n atRule.remove();\n }\n\n if (atRule.params === \"tokens\") {\n run.tokens.push(\"default\");\n atRule.remove();\n }\n });\n\n await buildTelegraphCss({\n root,\n config: {\n tokens: run.tokens,\n components: run.components,\n },\n });\n },\n },\n ],\n };\n};\n\nexport default Object.assign(styleEnginePostCssPlugin, {\n postcss: true,\n}) as PluginCreator<Record<string, never>>;\n"],"names":["nodePath","nodeFs","postcss","findMonorepoRoot","start","current","run","pkgJsonPath","parent","getTelegraphDepsFromPackageJson","pkg","pkgPath","_a","acc","dep","version","getTelegraphDeps","topLevelDeps","monorepoRoot","recursivelyGetTelegraphDeps","deps","allDeps","searchPath","pkgJson","nestedDeps","getCssStyles","fileName","path","cssPath","buildTelegraphCss","root","config","depsWithoutTokens","tokensDeps","cssFiles","tokensCssFiles","token","allCssFiles","content","parsed","styleEnginePostCssPlugin","atRule","postcss$1"],"mappings":"AAKA,MAAMA,IAAW,QAAQ,MAAM,GAEzBC,IAAS,QAAQ,IAAI,GAErBC,IAAU,QAAQ,SAAS;AAoBjC,SAASC,EAAiBC,IAAQ,QAAQ,OAA2B;AACnE,MAAIC,IAAUD,GACVE,IAAM;AAEV,SAAOA,KAAK;AACV,UAAMC,IAAcP,EAAS,KAAKK,GAAS,cAAc;AACzD,QAAIJ,EAAO,WAAWM,CAAW;AAC/B,UAAI;AAEF,YADY,KAAK,MAAMN,EAAO,aAAaM,GAAa,MAAM,CAAC,EACvD;AACN,iBAAOF;AAAA,MAEX,QAAQ;AAAA,MAER;AAGF,UAAMG,IAASR,EAAS,QAAQK,CAAO;AACvC,IAAIG,MAAWH,MAASC,IAAM,KAC9BD,IAAUG;AAAA,EACZ;AAGF;AAMA,MAAMC,IAAkC,CACtCC,GACAC,MAC0B;AAxD5B,MAAAC;AAyDE,MAAI,GAACF,EAAI,kBAAgBE,IAAA,OAAO,KAAKF,EAAI,YAAY,MAA5B,gBAAAE,EAA+B,YAAW;AAEnE,WAAO,OAAO,QAAQF,EAAI,YAAY,EAAE,OAAO,CAACG,GAAK,CAACC,GAAKC,CAAO,OAC5DD,EAAI,WAAW,aAAa,MAC9BD,EAAIC,CAAG,IAAI;AAAA,MACT,MAAMA;AAAA,MACN,SAAAC;AAAA,MACA,MAAMf,EAAS,QAAQW,GAAS,gBAAgBG,CAAG;AAAA,IAAA,IAGhDD,IACN,CAAA,CAAe;AACpB;AAMA,SAASG,IAA8B;AACrC,QAAML,IAAUX,EAAS,QAAQ,QAAQ,IAAA,GAAO,cA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,EAAO,WAAW,mBACpBnC,EAAI,OAAO,KAAK,OAAO,GACvBmC,EAAO,OAAA,IAGLA,EAAO,WAAW,kBACpBnC,EAAI,OAAO,KAAK,MAAM,GACtBmC,EAAO,OAAA,IAGLA,EAAO,WAAW,aACpBnC,EAAI,OAAO,KAAK,SAAS,GACzBmC,EAAO,OAAA;AAAA,QAEX,CAAC,GAED,MAAMZ,EAAkB;AAAA,UACtB,MAAAC;AAAA,UACA,QAAQ;AAAA,YACN,QAAQxB,EAAI;AAAA,YACZ,YAAYA,EAAI;AAAA,UAAA;AAAA,QAClB,CACD;AAAA,MACH;AAAA,IAAA;AAAA,EACF;AACF,IAIJoC,IAAe,OAAO,OAAOF,GAA0B;AAAA,EACrD,SAAS;AACX,CAAC;"}
|
|
1
|
+
{"version":3,"file":"postcss.mjs","sources":["../../src/plugins/postcss.ts"],"sourcesContent":["import { type AcceptedPlugin, type PluginCreator, type Root } from \"postcss\";\n\n// Using require() instead of import to prevent ESM-related bugs in PostCSS.\n// ESM = ECMAScript Modules (the import/export syntax)\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst nodePath = require(\"node:path\");\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst nodeFs = require(\"node:fs\");\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst postcss = require(\"postcss\");\n\ntype PkgJson = {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n};\n\ntype DepObject = Record<\n string,\n {\n name: string;\n version: string;\n path: string;\n }\n>;\n\n/**\n * Traverses up the directory tree to find the root of the monorepo by looking for a package.json with workspaces.\n * This is needed to properly resolve workspace dependencies in a monorepo setup.\n */\nfunction findMonorepoRoot(start = process.cwd()): string | undefined {\n let current = start;\n let run = true;\n\n while (run) {\n const pkgJsonPath = nodePath.join(current, \"package.json\");\n if (nodeFs.existsSync(pkgJsonPath)) {\n try {\n const pkg = JSON.parse(nodeFs.readFileSync(pkgJsonPath, \"utf8\"));\n if (pkg.workspaces) {\n return current;\n }\n } catch {\n // malformed package.json, skip\n }\n }\n\n const parent = nodePath.dirname(current);\n if (parent === current) run = false;\n current = parent;\n }\n\n return undefined;\n}\n\n/**\n * Extracts all @telegraph/* dependencies from a package.json file and returns them with their paths.\n * This is used to find all Telegraph packages that might contain CSS we need to include.\n */\nconst getTelegraphDepsFromPackageJson = (\n pkg: PkgJson,\n pkgPath: string,\n): DepObject | undefined => {\n if (!pkg.dependencies || Object.keys(pkg.dependencies)?.length === 0) return;\n\n return Object.entries(pkg.dependencies).reduce((acc, [dep, version]) => {\n if (dep.startsWith(\"@telegraph/\")) {\n acc[dep] = {\n name: dep,\n version,\n path: nodePath.resolve(pkgPath, \"node_modules\", dep),\n };\n }\n return acc;\n }, {} as DepObject);\n};\n\n/**\n * Gets all Telegraph dependencies recursively, including dependencies of dependencies.\n * Handles both normal npm dependencies and workspace dependencies in a monorepo.\n */\nfunction getTelegraphDeps(): DepObject {\n const pkgPath = nodePath.resolve(process.cwd(), \"package.json\");\n const pkg = JSON.parse(nodeFs.readFileSync(pkgPath, \"utf8\"));\n const topLevelDeps = getTelegraphDepsFromPackageJson(pkg, process.cwd());\n const monorepoRoot = findMonorepoRoot();\n\n const recursivelyGetTelegraphDeps = (deps: DepObject): DepObject => {\n if (!deps || Object.keys(deps).length === 0) {\n return deps;\n }\n\n const allDeps = { ...deps };\n\n for (const dep of Object.values(deps)) {\n let pkgJsonPath: string;\n let searchPath: string;\n\n if (dep.version.includes(\"workspace:\") && monorepoRoot) {\n pkgJsonPath = nodePath.resolve(\n monorepoRoot,\n \"node_modules\",\n dep.name,\n \"package.json\",\n );\n searchPath = monorepoRoot;\n } else {\n pkgJsonPath = nodePath.resolve(\n process.cwd(),\n \"node_modules\",\n dep.name,\n \"package.json\",\n );\n searchPath = process.cwd();\n }\n\n try {\n const pkgJson = JSON.parse(nodeFs.readFileSync(pkgJsonPath, \"utf8\"));\n const deps = getTelegraphDepsFromPackageJson(pkgJson, searchPath);\n\n // Merge new dependencies into allDeps\n Object.assign(allDeps, deps);\n\n if (deps) {\n // Recursively get dependencies of dependencies\n const nestedDeps = recursivelyGetTelegraphDeps(deps);\n Object.assign(allDeps, nestedDeps);\n }\n } catch (_err) {\n // Skip if package.json cannot be read\n continue;\n }\n }\n\n return allDeps;\n };\n\n if (topLevelDeps) {\n return recursivelyGetTelegraphDeps(topLevelDeps);\n }\n\n return {};\n}\n\ntype GetCssStylesParams = {\n fileName?: string;\n path: string;\n};\n\n/**\n * Reads CSS file content from a Telegraph package's dist/css directory.\n * Returns null if the file doesn't exist or can't be read.\n */\nfunction getCssStyles({\n fileName = \"default.css\",\n path,\n}: GetCssStylesParams): string | null {\n try {\n const cssPath = `${path}/dist/css/${fileName}`;\n const pkgPath = nodePath.resolve(cssPath);\n\n if (nodeFs.existsSync(pkgPath)) {\n return nodeFs.readFileSync(pkgPath, \"utf8\");\n }\n\n return null;\n } catch {\n return null;\n }\n}\n\ntype BuildTelegraphCssParams = {\n root: Root;\n config: {\n tokens: Array<\"light\" | \"dark\" | \"default\">;\n components: boolean;\n };\n};\n\n/**\n * Main function that builds the final CSS by:\n * 1. Getting all Telegraph dependencies\n * 2. Filtering for either token packages or component packages based on config\n * 3. Reading their CSS files\n * 4. Appending all CSS to the PostCSS Root node\n */\nconst buildTelegraphCss = async ({ root, config }: BuildTelegraphCssParams) => {\n const deps = getTelegraphDeps();\n\n const depsWithoutTokens =\n config.components === true\n ? Object.values(deps).filter(\n (dep) => !dep.name.includes(\"@telegraph/tokens\"),\n )\n : [];\n\n const tokensDeps =\n config.tokens.length > 0\n ? Object.values(deps).filter((dep) =>\n dep.name.includes(\"@telegraph/tokens\"),\n )\n : [];\n\n const cssFiles = depsWithoutTokens\n .map((dep) => getCssStyles({ path: dep.path }))\n .filter(Boolean) as Array<string>;\n\n const tokensCssFiles = config.tokens\n .map((token) => {\n const cssFile = tokensDeps.map((dep) =>\n getCssStyles({ path: dep.path, fileName: `${token}.css` }),\n );\n\n return cssFile.filter(Boolean) as Array<string>;\n })\n .filter(Boolean);\n\n const allCssFiles = [...cssFiles, ...tokensCssFiles];\n\n for (const content of allCssFiles) {\n const parsed = postcss.parse(content);\n root.append(parsed);\n }\n};\n\n/**\n * PostCSS plugin that processes @telegraph rules in CSS files.\n * It looks for @telegraph tokens, @telegraph tokens-light, @telegraph tokens-dark,\n * and @telegraph components rules and includes the appropriate CSS from Telegraph packages.\n */\nconst styleEnginePostCssPlugin = (): AcceptedPlugin => {\n return {\n postcssPlugin: \"@telegraph/style-engine\",\n plugins: [\n {\n postcssPlugin: \"telegraph\",\n AtRule: {\n telegraph() {},\n },\n async Once(root) {\n const run = {\n tokens: [] as BuildTelegraphCssParams[\"config\"][\"tokens\"],\n components: false,\n };\n root.walkAtRules(\"telegraph\", (atRule) => {\n if (atRule.params === \"components\") {\n run.components = true;\n atRule.remove();\n }\n\n if (atRule.params === \"tokens-light\") {\n run.tokens.push(\"light\");\n atRule.remove();\n }\n\n if (atRule.params === \"tokens-dark\") {\n run.tokens.push(\"dark\");\n atRule.remove();\n }\n\n if (atRule.params === \"tokens\") {\n run.tokens.push(\"default\");\n atRule.remove();\n }\n });\n\n await buildTelegraphCss({\n root,\n config: {\n tokens: run.tokens,\n components: run.components,\n },\n });\n },\n },\n ],\n };\n};\n\nexport default Object.assign(styleEnginePostCssPlugin, {\n postcss: true,\n}) as PluginCreator<Record<string, never>>;\n"],"names":["nodePath","nodeFs","postcss","findMonorepoRoot","start","current","run","pkgJsonPath","parent","getTelegraphDepsFromPackageJson","pkg","pkgPath","_a","acc","dep","version","getTelegraphDeps","topLevelDeps","monorepoRoot","recursivelyGetTelegraphDeps","deps","allDeps","searchPath","pkgJson","nestedDeps","getCssStyles","fileName","path","cssPath","buildTelegraphCss","root","config","depsWithoutTokens","tokensDeps","cssFiles","tokensCssFiles","token","allCssFiles","content","parsed","styleEnginePostCssPlugin","atRule","postcss$1"],"mappings":"AAKA,MAAMA,IAAW,QAAQ,WAAW,GAE9BC,IAAS,QAAQ,SAAS,GAE1BC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ACZ,YAAYA,EAAI;AAAA,UAAA;AAAA,QAClB,CACD;AAAA,MACH;AAAA,IAAA;AAAA,EACF;AACF,IAIJoC,IAAe,OAAO,OAAOF,GAA0B;AAAA,EACrD,SAAS;AACX,CAAC;"}
|
|
@@ -5,7 +5,30 @@ export type CssVarProp = {
|
|
|
5
5
|
value: string;
|
|
6
6
|
direction?: Direction;
|
|
7
7
|
axis?: Axis;
|
|
8
|
-
|
|
8
|
+
};
|
|
9
|
+
export declare const PSEUDO_STATES: readonly ["_hover", "_focus", "_active", "_focusWithin", "_disabled"];
|
|
10
|
+
export type PseudoState = (typeof PSEUDO_STATES)[number];
|
|
11
|
+
/**
|
|
12
|
+
* Adds pseudo-class variant props to a style props type.
|
|
13
|
+
*
|
|
14
|
+
* Given a base style props type, this creates a new type that also
|
|
15
|
+
* accepts `_hover`, `_focus`, `_active`, `_focusWithin`, and `_disabled`
|
|
16
|
+
* props as objects containing any of the base style props.
|
|
17
|
+
*
|
|
18
|
+
* Prefixed with underscore to avoid collisions with native HTML attributes
|
|
19
|
+
* (e.g. `disabled`) and common component props (e.g. `active`).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* type BoxStyle = { bg: ColorToken; p: SpacingToken };
|
|
23
|
+
* type BoxStyleWithPseudo = WithPseudo<BoxStyle>;
|
|
24
|
+
* // Allows: { bg: "gray-2", _hover: { bg: "gray-3" }, _focus: { p: "4" } }
|
|
25
|
+
*/
|
|
26
|
+
export type WithPseudo<Props> = Props & {
|
|
27
|
+
_hover?: Partial<Props>;
|
|
28
|
+
_focus?: Partial<Props>;
|
|
29
|
+
_active?: Partial<Props>;
|
|
30
|
+
_focusWithin?: Partial<Props>;
|
|
31
|
+
_disabled?: Partial<Props>;
|
|
9
32
|
};
|
|
10
33
|
export type NegativeSpacing<T extends string | number | symbol> = T extends string ? `-${T}` : never;
|
|
11
34
|
export type WithNegativeSpacing<T extends string | number | symbol> = T extends string ? T | `-${T}` : T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStyleProp.d.ts","sourceRoot":"","sources":["../../../../src/helpers/getStyleProp/getStyleProp.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GACV,GAAG,GACH,GAAG,GACH,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,GACP,KAAK,GACL,UAAU,GACV,aAAa,GACb,WAAW,GACX,YAAY,CAAC;AAEjB,KAAK,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC;AAE/B,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"getStyleProp.d.ts","sourceRoot":"","sources":["../../../../src/helpers/getStyleProp/getStyleProp.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GACV,GAAG,GACH,GAAG,GACH,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,GACP,KAAK,GACL,UAAU,GACV,aAAa,GACb,WAAW,GACX,YAAY,CAAC;AAEjB,KAAK,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC;AAE/B,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,CAAC;AAKF,eAAO,MAAM,aAAa,uEAMhB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAWzD;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,UAAU,CAAC,KAAK,IAAI,KAAK,GAAG;IACtC,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACxB,MAAM,CAAC,EAAE,OA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C,CAAA;KAAE,CAAC;IAClD,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAgEF,eAAO,MAAM,YAAY,GACvB,OAAO,SAAS,iBAAiB,CAAC,OAAO,CAAC,EAC1C,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAErC,QAAQ,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,KACzC;IACD,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC9B,UAAU,EAAE,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACvC,WAAW,EAAE,OAAO,CAAC;CAqGtB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { getStyleProp } from './getStyleProp';
|
|
2
|
-
export type { CssVarProp, NegativeSpacing, WithNegativeSpacing, } from './getStyleProp';
|
|
1
|
+
export { getStyleProp, PSEUDO_STATES } from './getStyleProp';
|
|
2
|
+
export type { CssVarProp, NegativeSpacing, WithNegativeSpacing, PseudoState, WithPseudo, } from './getStyleProp';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/helpers/getStyleProp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/helpers/getStyleProp/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC7D,YAAY,EACV,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,UAAU,GACX,MAAM,gBAAgB,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as tokens } from '@telegraph/tokens/css-variables-map';
|
|
2
|
-
export { getStyleProp, type CssVarProp, type NegativeSpacing, type WithNegativeSpacing, } from './helpers/getStyleProp';
|
|
2
|
+
export { getStyleProp, PSEUDO_STATES, type CssVarProp, type NegativeSpacing, type WithNegativeSpacing, type PseudoState, type WithPseudo, } from './helpers/getStyleProp';
|
|
3
3
|
export { useStyleEngine } from './hooks/useStyleEngine';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAGxE,OAAO,EACL,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAGxE,OAAO,EACL,YAAY,EACZ,aAAa,EACb,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,UAAU,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telegraph/style-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A wrappar around vanilla extract to style telegraph",
|
|
5
5
|
"repository": "https://github.com/knocklabs/telegraph/tree/main/packages/style-engine",
|
|
6
6
|
"author": "@knocklabs",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"preview": "vite preview"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@telegraph/tokens": "^0.1.
|
|
40
|
+
"@telegraph/tokens": "^0.1.4",
|
|
41
41
|
"postcss": "^8.5.6"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
"@knocklabs/typescript-config": "^0.0.2",
|
|
46
46
|
"@telegraph/prettier-config": "^0.0.7",
|
|
47
47
|
"@telegraph/vite-config": "^0.0.15",
|
|
48
|
-
"@types/node": "^
|
|
48
|
+
"@types/node": "^25.3.3",
|
|
49
49
|
"@types/postcss-import": "^14.0.3",
|
|
50
50
|
"@types/react": "^19.2.9",
|
|
51
|
-
"eslint": "^
|
|
52
|
-
"globby": "^
|
|
53
|
-
"lightningcss": "^1.
|
|
54
|
-
"react": "^19.2.
|
|
55
|
-
"react-dom": "^19.2.
|
|
51
|
+
"eslint": "^10.0.2",
|
|
52
|
+
"globby": "^16.1.1",
|
|
53
|
+
"lightningcss": "^1.31.1",
|
|
54
|
+
"react": "^19.2.4",
|
|
55
|
+
"react-dom": "^19.2.4",
|
|
56
56
|
"typescript": "^5.9.3",
|
|
57
57
|
"vite": "^6.4.1"
|
|
58
58
|
},
|