@datalayer/primer-addons 1.0.38 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -20
- package/lib/components/appearance/AppearanceControls.d.ts +6 -1
- package/lib/components/appearance/AppearanceControls.js +7 -3
- package/lib/components/appearance/AppearanceControlsWithStore.d.ts +4 -0
- package/lib/components/appearance/AppearanceControlsWithStore.js +4 -4
- package/lib/components/appearance/CollaboratorPalette.js +7 -20
- package/lib/components/box/Box.d.ts +103 -16
- package/lib/components/box/Box.js +157 -2
- package/lib/components/box/boxCss.d.ts +805 -0
- package/lib/components/box/boxCss.js +508 -0
- package/lib/components/box/boxTokens.d.ts +130 -0
- package/lib/components/box/boxTokens.js +125 -0
- package/lib/components/calendar-picker/CalendarPicker.js +2 -1
- package/lib/components/card/Card.d.ts +119 -5
- package/lib/components/card/Card.js +64 -41
- package/lib/components/card/Card.stories.d.ts +6 -0
- package/lib/components/card/Card.stories.js +26 -0
- package/lib/components/color/ColorSwatch.js +2 -1
- package/lib/components/color-picker/ColorPicker.js +8 -4
- package/lib/components/date-picker/DatePicker.d.ts +12 -3
- package/lib/components/date-picker/DatePicker.js +24 -8
- package/lib/components/entity-avatar/EntityAvatar.d.ts +73 -0
- package/lib/components/entity-avatar/EntityAvatar.js +63 -0
- package/lib/components/entity-avatar/index.d.ts +1 -0
- package/lib/components/entity-avatar/index.js +5 -0
- package/lib/components/hover-card/HoverCard.d.ts +63 -0
- package/lib/components/hover-card/HoverCard.js +55 -0
- package/lib/components/hover-card/HoverCardAnchor.d.ts +33 -0
- package/lib/components/hover-card/HoverCardAnchor.js +26 -0
- package/lib/components/hover-card/HoverCardDetails.d.ts +36 -0
- package/lib/components/hover-card/HoverCardDetails.js +65 -0
- package/lib/components/hover-card/HoverCardLayer.d.ts +34 -0
- package/lib/components/hover-card/HoverCardLayer.js +57 -0
- package/lib/components/hover-card/index.d.ts +12 -0
- package/lib/components/hover-card/index.js +16 -0
- package/lib/components/hover-card/useHoverCard.d.ts +57 -0
- package/lib/components/hover-card/useHoverCard.js +200 -0
- package/lib/components/hover-card/usePrefersReducedMotion.d.ts +10 -0
- package/lib/components/hover-card/usePrefersReducedMotion.js +28 -0
- package/lib/components/index.d.ts +3 -0
- package/lib/components/index.js +3 -0
- package/lib/components/sheet/Sheet.d.ts +15 -0
- package/lib/components/sheet/Sheet.js +21 -0
- package/lib/reactor/page-layout/PageLayout.js +4 -6
- package/lib/story-helpers.d.ts +2 -2
- package/lib/theme/DatalayerThemeProvider.d.ts +21 -0
- package/lib/theme/DatalayerThemeProvider.js +8 -2
- package/lib/theme/colors/index.d.ts +2 -1
- package/lib/theme/colors/index.js +2 -1
- package/lib/theme/colors/loopColors.d.ts +2 -48
- package/lib/theme/colors/loopColors.js +2 -98
- package/lib/theme/colors/themeAccents.d.ts +81 -0
- package/lib/theme/colors/themeAccents.js +139 -0
- package/lib/theme/css/createThemeCSSVars.d.ts +18 -1
- package/lib/theme/css/createThemeCSSVars.js +20 -1
- package/lib/theme/css/primerBaseVars.d.ts +1 -0
- package/lib/theme/css/primerBaseVars.js +72 -0
- package/lib/theme/css/primerComponentsCss.d.ts +47 -0
- package/lib/theme/css/primerComponentsCss.js +72 -0
- package/lib/theme/index.d.ts +2 -0
- package/lib/theme/index.js +2 -0
- package/lib/theme/themes/loopThemeStyles.d.ts +4 -37
- package/lib/theme/themes/loopThemeStyles.js +39 -56
- package/package.json +1 -1
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* What `Box` draws with: its style props resolved to CSS, one class per
|
|
7
|
+
* style, and the stylesheet the classes go into. No styled-components; see
|
|
8
|
+
* `Box.tsx` for the design.
|
|
9
|
+
*/
|
|
10
|
+
import { BOX_BORDER_WIDTHS, BOX_BREAKPOINTS, BOX_COLOR_VARS, BOX_FONT_SIZES, BOX_FONT_VARS, BOX_FONT_WEIGHT_VARS, BOX_LINE_HEIGHTS, BOX_RADII, BOX_RADIUS_VARS, BOX_SHADOW_VARS, BOX_SIZES, BOX_SPACE, } from './boxTokens';
|
|
11
|
+
const prop = (css, scale) => ({
|
|
12
|
+
css: Array.isArray(css) ? css : [css],
|
|
13
|
+
scale: (scale ?? 'raw'),
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Every style prop: its CSS properties and its scale. The names are
|
|
17
|
+
* Primer's (styled-system's), so `<Box p={3} bg="canvas.subtle">` reads as
|
|
18
|
+
* it always did; an `sx` key of the same name moves to the prop unchanged.
|
|
19
|
+
*/
|
|
20
|
+
export const BOX_STYLE_PROPS = {
|
|
21
|
+
/* Space */
|
|
22
|
+
m: prop('margin', 'signedSpace'),
|
|
23
|
+
mt: prop('margin-top', 'signedSpace'),
|
|
24
|
+
mr: prop('margin-right', 'signedSpace'),
|
|
25
|
+
mb: prop('margin-bottom', 'signedSpace'),
|
|
26
|
+
ml: prop('margin-left', 'signedSpace'),
|
|
27
|
+
mx: prop(['margin-left', 'margin-right'], 'signedSpace'),
|
|
28
|
+
my: prop(['margin-top', 'margin-bottom'], 'signedSpace'),
|
|
29
|
+
margin: prop('margin', 'signedSpace'),
|
|
30
|
+
marginTop: prop('margin-top', 'signedSpace'),
|
|
31
|
+
marginRight: prop('margin-right', 'signedSpace'),
|
|
32
|
+
marginBottom: prop('margin-bottom', 'signedSpace'),
|
|
33
|
+
marginLeft: prop('margin-left', 'signedSpace'),
|
|
34
|
+
marginX: prop(['margin-left', 'margin-right'], 'signedSpace'),
|
|
35
|
+
marginY: prop(['margin-top', 'margin-bottom'], 'signedSpace'),
|
|
36
|
+
p: prop('padding', 'space'),
|
|
37
|
+
pt: prop('padding-top', 'space'),
|
|
38
|
+
pr: prop('padding-right', 'space'),
|
|
39
|
+
pb: prop('padding-bottom', 'space'),
|
|
40
|
+
pl: prop('padding-left', 'space'),
|
|
41
|
+
px: prop(['padding-left', 'padding-right'], 'space'),
|
|
42
|
+
py: prop(['padding-top', 'padding-bottom'], 'space'),
|
|
43
|
+
padding: prop('padding', 'space'),
|
|
44
|
+
paddingTop: prop('padding-top', 'space'),
|
|
45
|
+
paddingRight: prop('padding-right', 'space'),
|
|
46
|
+
paddingBottom: prop('padding-bottom', 'space'),
|
|
47
|
+
paddingLeft: prop('padding-left', 'space'),
|
|
48
|
+
paddingX: prop(['padding-left', 'padding-right'], 'space'),
|
|
49
|
+
paddingY: prop(['padding-top', 'padding-bottom'], 'space'),
|
|
50
|
+
paddingBlock: prop('padding-block', 'space'),
|
|
51
|
+
paddingInline: prop('padding-inline', 'space'),
|
|
52
|
+
gap: prop('gap', 'space'),
|
|
53
|
+
rowGap: prop('row-gap', 'space'),
|
|
54
|
+
columnGap: prop('column-gap', 'space'),
|
|
55
|
+
gridGap: prop('gap', 'space'),
|
|
56
|
+
gridRowGap: prop('row-gap', 'space'),
|
|
57
|
+
gridColumnGap: prop('column-gap', 'space'),
|
|
58
|
+
scrollMarginTop: prop('scroll-margin-top'),
|
|
59
|
+
/* Colour */
|
|
60
|
+
color: prop('color', 'color'),
|
|
61
|
+
bg: prop('background-color', 'color'),
|
|
62
|
+
backgroundColor: prop('background-color', 'color'),
|
|
63
|
+
fill: prop('fill', 'color'),
|
|
64
|
+
stroke: prop('stroke', 'color'),
|
|
65
|
+
outlineColor: prop('outline-color', 'color'),
|
|
66
|
+
opacity: prop('opacity', 'unitless'),
|
|
67
|
+
background: prop('background'),
|
|
68
|
+
backgroundImage: prop('background-image'),
|
|
69
|
+
backgroundSize: prop('background-size'),
|
|
70
|
+
backgroundPosition: prop('background-position'),
|
|
71
|
+
backgroundRepeat: prop('background-repeat'),
|
|
72
|
+
/* Border */
|
|
73
|
+
border: prop('border'),
|
|
74
|
+
borderTop: prop('border-top'),
|
|
75
|
+
borderRight: prop('border-right'),
|
|
76
|
+
borderBottom: prop('border-bottom'),
|
|
77
|
+
borderLeft: prop('border-left'),
|
|
78
|
+
borderX: prop(['border-left', 'border-right']),
|
|
79
|
+
borderY: prop(['border-top', 'border-bottom']),
|
|
80
|
+
borderColor: prop('border-color', 'color'),
|
|
81
|
+
borderTopColor: prop('border-top-color', 'color'),
|
|
82
|
+
borderRightColor: prop('border-right-color', 'color'),
|
|
83
|
+
borderBottomColor: prop('border-bottom-color', 'color'),
|
|
84
|
+
borderLeftColor: prop('border-left-color', 'color'),
|
|
85
|
+
borderWidth: prop('border-width', 'borderWidth'),
|
|
86
|
+
borderTopWidth: prop('border-top-width', 'borderWidth'),
|
|
87
|
+
borderRightWidth: prop('border-right-width', 'borderWidth'),
|
|
88
|
+
borderBottomWidth: prop('border-bottom-width', 'borderWidth'),
|
|
89
|
+
borderLeftWidth: prop('border-left-width', 'borderWidth'),
|
|
90
|
+
borderStyle: prop('border-style'),
|
|
91
|
+
borderTopStyle: prop('border-top-style'),
|
|
92
|
+
borderRightStyle: prop('border-right-style'),
|
|
93
|
+
borderBottomStyle: prop('border-bottom-style'),
|
|
94
|
+
borderLeftStyle: prop('border-left-style'),
|
|
95
|
+
borderRadius: prop('border-radius', 'radius'),
|
|
96
|
+
borderTopLeftRadius: prop('border-top-left-radius', 'radius'),
|
|
97
|
+
borderTopRightRadius: prop('border-top-right-radius', 'radius'),
|
|
98
|
+
borderBottomLeftRadius: prop('border-bottom-left-radius', 'radius'),
|
|
99
|
+
borderBottomRightRadius: prop('border-bottom-right-radius', 'radius'),
|
|
100
|
+
borderCollapse: prop('border-collapse'),
|
|
101
|
+
borderSpacing: prop('border-spacing'),
|
|
102
|
+
outline: prop('outline'),
|
|
103
|
+
outlineOffset: prop('outline-offset'),
|
|
104
|
+
boxShadow: prop('box-shadow', 'shadow'),
|
|
105
|
+
textShadow: prop('text-shadow', 'shadow'),
|
|
106
|
+
/* Layout */
|
|
107
|
+
display: prop('display'),
|
|
108
|
+
width: prop('width', 'size'),
|
|
109
|
+
height: prop('height', 'size'),
|
|
110
|
+
minWidth: prop('min-width', 'size'),
|
|
111
|
+
maxWidth: prop('max-width', 'size'),
|
|
112
|
+
minHeight: prop('min-height', 'size'),
|
|
113
|
+
maxHeight: prop('max-height', 'size'),
|
|
114
|
+
size: prop(['width', 'height'], 'size'),
|
|
115
|
+
overflow: prop('overflow'),
|
|
116
|
+
overflowX: prop('overflow-x'),
|
|
117
|
+
overflowY: prop('overflow-y'),
|
|
118
|
+
overscrollBehavior: prop('overscroll-behavior'),
|
|
119
|
+
overscrollBehaviorY: prop('overscroll-behavior-y'),
|
|
120
|
+
scrollbarWidth: prop('scrollbar-width'),
|
|
121
|
+
scrollbarGutter: prop('scrollbar-gutter'),
|
|
122
|
+
verticalAlign: prop('vertical-align'),
|
|
123
|
+
boxSizing: prop('box-sizing'),
|
|
124
|
+
aspectRatio: prop('aspect-ratio', 'unitless'),
|
|
125
|
+
visibility: prop('visibility'),
|
|
126
|
+
objectFit: prop('object-fit'),
|
|
127
|
+
objectPosition: prop('object-position'),
|
|
128
|
+
float: prop('float'),
|
|
129
|
+
isolation: prop('isolation'),
|
|
130
|
+
tableLayout: prop('table-layout'),
|
|
131
|
+
/* Flex */
|
|
132
|
+
flex: prop('flex', 'unitless'),
|
|
133
|
+
flexDirection: prop('flex-direction'),
|
|
134
|
+
flexWrap: prop('flex-wrap'),
|
|
135
|
+
flexFlow: prop('flex-flow'),
|
|
136
|
+
flexGrow: prop('flex-grow', 'unitless'),
|
|
137
|
+
flexShrink: prop('flex-shrink', 'unitless'),
|
|
138
|
+
flexBasis: prop('flex-basis', 'size'),
|
|
139
|
+
alignItems: prop('align-items'),
|
|
140
|
+
alignContent: prop('align-content'),
|
|
141
|
+
alignSelf: prop('align-self'),
|
|
142
|
+
justifyContent: prop('justify-content'),
|
|
143
|
+
justifyItems: prop('justify-items'),
|
|
144
|
+
justifySelf: prop('justify-self'),
|
|
145
|
+
placeItems: prop('place-items'),
|
|
146
|
+
placeContent: prop('place-content'),
|
|
147
|
+
placeSelf: prop('place-self'),
|
|
148
|
+
order: prop('order', 'unitless'),
|
|
149
|
+
/* Grid */
|
|
150
|
+
gridTemplate: prop('grid-template'),
|
|
151
|
+
gridTemplateColumns: prop('grid-template-columns'),
|
|
152
|
+
gridTemplateRows: prop('grid-template-rows'),
|
|
153
|
+
gridTemplateAreas: prop('grid-template-areas'),
|
|
154
|
+
gridColumn: prop('grid-column', 'unitless'),
|
|
155
|
+
gridRow: prop('grid-row', 'unitless'),
|
|
156
|
+
gridColumnStart: prop('grid-column-start', 'unitless'),
|
|
157
|
+
gridColumnEnd: prop('grid-column-end', 'unitless'),
|
|
158
|
+
gridRowStart: prop('grid-row-start', 'unitless'),
|
|
159
|
+
gridRowEnd: prop('grid-row-end', 'unitless'),
|
|
160
|
+
gridArea: prop('grid-area', 'unitless'),
|
|
161
|
+
gridAutoFlow: prop('grid-auto-flow'),
|
|
162
|
+
gridAutoColumns: prop('grid-auto-columns'),
|
|
163
|
+
gridAutoRows: prop('grid-auto-rows'),
|
|
164
|
+
/* Position */
|
|
165
|
+
position: prop('position'),
|
|
166
|
+
zIndex: prop('z-index', 'unitless'),
|
|
167
|
+
top: prop('top', 'signedSpace'),
|
|
168
|
+
right: prop('right', 'signedSpace'),
|
|
169
|
+
bottom: prop('bottom', 'signedSpace'),
|
|
170
|
+
left: prop('left', 'signedSpace'),
|
|
171
|
+
inset: prop('inset'),
|
|
172
|
+
/* Typography */
|
|
173
|
+
font: prop('font'),
|
|
174
|
+
fontFamily: prop('font-family', 'font'),
|
|
175
|
+
fontSize: prop('font-size', 'fontSize'),
|
|
176
|
+
fontWeight: prop('font-weight', 'fontWeight'),
|
|
177
|
+
fontStyle: prop('font-style'),
|
|
178
|
+
fontVariantNumeric: prop('font-variant-numeric'),
|
|
179
|
+
lineHeight: prop('line-height', 'lineHeight'),
|
|
180
|
+
letterSpacing: prop('letter-spacing'),
|
|
181
|
+
textAlign: prop('text-align'),
|
|
182
|
+
whiteSpace: prop('white-space'),
|
|
183
|
+
textDecoration: prop('text-decoration'),
|
|
184
|
+
textUnderlineOffset: prop('text-underline-offset'),
|
|
185
|
+
textTransform: prop('text-transform'),
|
|
186
|
+
textOverflow: prop('text-overflow'),
|
|
187
|
+
textWrap: prop('text-wrap'),
|
|
188
|
+
wordBreak: prop('word-break'),
|
|
189
|
+
overflowWrap: prop('overflow-wrap'),
|
|
190
|
+
wordWrap: prop('word-wrap'),
|
|
191
|
+
WebkitLineClamp: prop('-webkit-line-clamp', 'unitless'),
|
|
192
|
+
WebkitBoxOrient: prop('-webkit-box-orient'),
|
|
193
|
+
listStyle: prop('list-style'),
|
|
194
|
+
listStyleType: prop('list-style-type'),
|
|
195
|
+
listStylePosition: prop('list-style-position'),
|
|
196
|
+
/* Effects and interaction */
|
|
197
|
+
cursor: prop('cursor'),
|
|
198
|
+
pointerEvents: prop('pointer-events'),
|
|
199
|
+
touchAction: prop('touch-action'),
|
|
200
|
+
all: prop('all'),
|
|
201
|
+
userSelect: prop('user-select'),
|
|
202
|
+
appearance: prop('appearance'),
|
|
203
|
+
transition: prop('transition'),
|
|
204
|
+
transform: prop('transform'),
|
|
205
|
+
transformOrigin: prop('transform-origin'),
|
|
206
|
+
animation: prop('animation'),
|
|
207
|
+
animationDelay: prop('animation-delay'),
|
|
208
|
+
filter: prop('filter'),
|
|
209
|
+
backdropFilter: prop('backdrop-filter'),
|
|
210
|
+
mixBlendMode: prop('mix-blend-mode'),
|
|
211
|
+
willChange: prop('will-change'),
|
|
212
|
+
clipPath: prop('clip-path'),
|
|
213
|
+
clip: prop('clip'),
|
|
214
|
+
resize: prop('resize'),
|
|
215
|
+
};
|
|
216
|
+
/** The pseudo-state props: each takes a style object of the style props. */
|
|
217
|
+
export const BOX_PSEUDO_PROPS = {
|
|
218
|
+
hover: ':hover',
|
|
219
|
+
focus: ':focus',
|
|
220
|
+
focusVisible: ':focus-visible',
|
|
221
|
+
focusWithin: ':focus-within',
|
|
222
|
+
active: ':active',
|
|
223
|
+
};
|
|
224
|
+
/** Styles for the reader who asked for less motion. */
|
|
225
|
+
export const BOX_REDUCED_MOTION = '@media (prefers-reduced-motion: reduce)';
|
|
226
|
+
/* ── Resolving a value ───────────────────────────────────────────────── */
|
|
227
|
+
const px = (n) => (n === 0 ? '0' : `${n}px`);
|
|
228
|
+
const fromList = (list, n) => (Number.isInteger(n) && n >= 0 && n < list.length ? list[n] : px(n));
|
|
229
|
+
const varOf = (name) => `var(${name})`;
|
|
230
|
+
/**
|
|
231
|
+
* One value of one prop, as CSS. Numbers index Primer's scale where the prop
|
|
232
|
+
* has one, and are pixels past its end (as `sx` reads them); a token name
|
|
233
|
+
* is its CSS variable, with no fallback; anything else is CSS as written.
|
|
234
|
+
*/
|
|
235
|
+
export function resolveBoxValue(scale, value) {
|
|
236
|
+
if (typeof value === 'number') {
|
|
237
|
+
switch (scale) {
|
|
238
|
+
case 'space':
|
|
239
|
+
return fromList(BOX_SPACE, value);
|
|
240
|
+
case 'signedSpace':
|
|
241
|
+
if (value < 0) {
|
|
242
|
+
const positive = fromList(BOX_SPACE, -value);
|
|
243
|
+
return positive === '0' ? '0' : `-${positive}`;
|
|
244
|
+
}
|
|
245
|
+
return fromList(BOX_SPACE, value);
|
|
246
|
+
case 'fontSize':
|
|
247
|
+
return fromList(BOX_FONT_SIZES, value);
|
|
248
|
+
case 'radius':
|
|
249
|
+
return fromList(BOX_RADII, value);
|
|
250
|
+
case 'borderWidth':
|
|
251
|
+
return fromList(BOX_BORDER_WIDTHS, value);
|
|
252
|
+
case 'unitless':
|
|
253
|
+
case 'fontWeight':
|
|
254
|
+
case 'lineHeight':
|
|
255
|
+
return String(value);
|
|
256
|
+
default:
|
|
257
|
+
return px(value);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
switch (scale) {
|
|
261
|
+
case 'color':
|
|
262
|
+
return value in BOX_COLOR_VARS ? varOf(BOX_COLOR_VARS[value]) : value;
|
|
263
|
+
case 'shadow':
|
|
264
|
+
return value in BOX_SHADOW_VARS ? varOf(BOX_SHADOW_VARS[value]) : value;
|
|
265
|
+
case 'radius':
|
|
266
|
+
return value in BOX_RADIUS_VARS ? varOf(BOX_RADIUS_VARS[value]) : value;
|
|
267
|
+
case 'fontWeight':
|
|
268
|
+
return value in BOX_FONT_WEIGHT_VARS
|
|
269
|
+
? varOf(BOX_FONT_WEIGHT_VARS[value])
|
|
270
|
+
: value;
|
|
271
|
+
case 'lineHeight':
|
|
272
|
+
return value in BOX_LINE_HEIGHTS ? BOX_LINE_HEIGHTS[value] : value;
|
|
273
|
+
case 'font':
|
|
274
|
+
return value in BOX_FONT_VARS ? varOf(BOX_FONT_VARS[value]) : value;
|
|
275
|
+
case 'size':
|
|
276
|
+
return value in BOX_SIZES ? BOX_SIZES[value] : value;
|
|
277
|
+
default:
|
|
278
|
+
return value;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const isSet = (value) => value !== null && value !== undefined && value !== false && value !== '' && (typeof value === 'string' || typeof value === 'number');
|
|
282
|
+
function addDeclarations(block, key, value) {
|
|
283
|
+
const { css, scale } = BOX_STYLE_PROPS[key];
|
|
284
|
+
const values = Array.isArray(value) ? value.slice(0, BOX_BREAKPOINTS.length + 1) : [value];
|
|
285
|
+
values.forEach((one, index) => {
|
|
286
|
+
if (!isSet(one)) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const resolved = resolveBoxValue(scale, one);
|
|
290
|
+
(block[index] ??= []).push(...css.map(property => [property, resolved]));
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/** CSS properties whose numbers have no unit (React's list, in short). */
|
|
294
|
+
const UNITLESS = new Set([
|
|
295
|
+
'animationIterationCount', 'aspectRatio', 'columnCount', 'columns', 'fillOpacity', 'flex', 'flexGrow',
|
|
296
|
+
'flexShrink', 'fontWeight', 'gridArea', 'gridColumn', 'gridColumnEnd', 'gridColumnStart', 'gridRow',
|
|
297
|
+
'gridRowEnd', 'gridRowStart', 'lineClamp', 'lineHeight', 'opacity', 'order', 'orphans', 'scale',
|
|
298
|
+
'stopOpacity', 'strokeDashoffset', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'tabSize',
|
|
299
|
+
'widows', 'zIndex', 'zoom', 'WebkitLineClamp',
|
|
300
|
+
]);
|
|
301
|
+
/** A camelCased property as CSS: `WebkitLineClamp` is `-webkit-line-clamp`; `--x` stays. */
|
|
302
|
+
const kebab = (key) => key.startsWith('--') ? key : key.replace(/^(Webkit|Moz|ms)(?=[A-Z])/, m => `-${m.toLowerCase()}`).replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
|
|
303
|
+
/**
|
|
304
|
+
* The keys of a style, with the resets first.
|
|
305
|
+
*
|
|
306
|
+
* `all` is a shorthand that sets *every* property: written after `width` it
|
|
307
|
+
* undoes it, whatever the author meant. A grown card's picture collapsed to
|
|
308
|
+
* 40px that way — `<Box as="button" display="block" width="100%" all="unset">`
|
|
309
|
+
* — and the artwork of the Library's hover card was a sliver at its left
|
|
310
|
+
* (seen 2026-10-09). An author may write the props in any order; a reset is
|
|
311
|
+
* emitted before what it would reset.
|
|
312
|
+
*/
|
|
313
|
+
const RESETS = ['all'];
|
|
314
|
+
const keysOf = (style) => {
|
|
315
|
+
const keys = Object.keys(style);
|
|
316
|
+
const resets = keys.filter(key => RESETS.includes(key));
|
|
317
|
+
return resets.length === 0 ? keys : [...resets, ...keys.filter(key => !resets.includes(key))];
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* A style's declarations. With `raw` (an `sx` object), a key that is no
|
|
321
|
+
* style prop is CSS as written — its number in pixels unless the property
|
|
322
|
+
* has no unit — as Primer's `sx` read it.
|
|
323
|
+
*/
|
|
324
|
+
function blockOf(style, raw = false) {
|
|
325
|
+
const block = [];
|
|
326
|
+
for (const key of keysOf(style)) {
|
|
327
|
+
const value = style[key];
|
|
328
|
+
if (key in BOX_STYLE_PROPS) {
|
|
329
|
+
addDeclarations(block, key, value);
|
|
330
|
+
}
|
|
331
|
+
else if (raw && (isSet(value) || Array.isArray(value))) {
|
|
332
|
+
const values = Array.isArray(value) ? value.slice(0, BOX_BREAKPOINTS.length + 1) : [value];
|
|
333
|
+
values.forEach((one, index) => {
|
|
334
|
+
if (!isSet(one)) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const css = typeof one === 'number' && !UNITLESS.has(key) && !key.startsWith('--') ? px(one) : String(one);
|
|
338
|
+
(block[index] ??= []).push([kebab(key), css]);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return block;
|
|
343
|
+
}
|
|
344
|
+
const MEDIA = (index) => `@media screen and (min-width: ${BOX_BREAKPOINTS[index - 1]})`;
|
|
345
|
+
const PLACEHOLDER = '\u0000';
|
|
346
|
+
function rulesOf(block, selector, wraps = []) {
|
|
347
|
+
const rules = [];
|
|
348
|
+
block.forEach((declarations, index) => {
|
|
349
|
+
if (!declarations || declarations.length === 0) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const body = declarations.map(([property, value]) => `${property}:${value}`).join(';');
|
|
353
|
+
let rule = `${selector}{${body}}`;
|
|
354
|
+
if (index > 0) {
|
|
355
|
+
rule = `${MEDIA(index)}{${rule}}`;
|
|
356
|
+
}
|
|
357
|
+
for (const wrap of [...wraps].reverse()) {
|
|
358
|
+
rule = `${wrap}{${rule}}`;
|
|
359
|
+
}
|
|
360
|
+
rules.push(rule);
|
|
361
|
+
});
|
|
362
|
+
return rules;
|
|
363
|
+
}
|
|
364
|
+
/** A selector list split at its top-level commas (not those in `:is(a, b)`). */
|
|
365
|
+
function splitSelectors(selector) {
|
|
366
|
+
const parts = [];
|
|
367
|
+
let depth = 0;
|
|
368
|
+
let start = 0;
|
|
369
|
+
for (let i = 0; i < selector.length; i++) {
|
|
370
|
+
const c = selector[i];
|
|
371
|
+
if (c === '(' || c === '[')
|
|
372
|
+
depth++;
|
|
373
|
+
else if (c === ')' || c === ']')
|
|
374
|
+
depth--;
|
|
375
|
+
else if (c === ',' && depth === 0) {
|
|
376
|
+
parts.push(selector.slice(start, i).trim());
|
|
377
|
+
start = i + 1;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
parts.push(selector.slice(start).trim());
|
|
381
|
+
return parts.filter(Boolean);
|
|
382
|
+
}
|
|
383
|
+
/** A nested key's selectors under its parents': `&` is the parent, a `:state` follows it, anything else is inside it. */
|
|
384
|
+
function nestSelectors(parents, key) {
|
|
385
|
+
return parents.flatMap(parent => splitSelectors(key).map(part => part.includes('&') ? part.split('&').join(parent) : part.startsWith(':') ? `${parent}${part}` : `${parent} ${part}`));
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* An `sx` object as rules: its own declarations, then each nested block —
|
|
389
|
+
* a selector (`'&:hover'`, `':focus-visible'`, `'& svg'`, `label`), an
|
|
390
|
+
* at-rule wrapping it (`'@media (max-width: 768px)'`), or a `@keyframes`,
|
|
391
|
+
* which is global.
|
|
392
|
+
*/
|
|
393
|
+
function sxRules(sx, selectors, wraps) {
|
|
394
|
+
const rules = rulesOf(blockOf(sx, true), selectors.join(','), wraps);
|
|
395
|
+
for (const [key, value] of Object.entries(sx)) {
|
|
396
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
const nested = value;
|
|
400
|
+
if (key.startsWith('@keyframes')) {
|
|
401
|
+
const frames = Object.entries(nested)
|
|
402
|
+
.map(([stop, frame]) => {
|
|
403
|
+
const declarations = blockOf((frame ?? {}), true)[0] ?? [];
|
|
404
|
+
return `${stop}{${declarations.map(([property, css]) => `${property}:${css}`).join(';')}}`;
|
|
405
|
+
})
|
|
406
|
+
.join('');
|
|
407
|
+
rules.push(`${key}{${frames}}`);
|
|
408
|
+
}
|
|
409
|
+
else if (key.startsWith('@')) {
|
|
410
|
+
rules.push(...sxRules(nested, selectors, [...wraps, key]));
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
rules.push(...sxRules(nested, nestSelectors(selectors, key), wraps));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return rules;
|
|
417
|
+
}
|
|
418
|
+
/** FNV-1a, 32 bits, in base 36. */
|
|
419
|
+
function hash(text) {
|
|
420
|
+
let h = 0x811c9dc5;
|
|
421
|
+
for (let i = 0; i < text.length; i++) {
|
|
422
|
+
h ^= text.charCodeAt(i);
|
|
423
|
+
h = Math.imul(h, 0x01000193);
|
|
424
|
+
}
|
|
425
|
+
return (h >>> 0).toString(36);
|
|
426
|
+
}
|
|
427
|
+
/** Every style resolved in this page, by class (for SSR and tests). */
|
|
428
|
+
const registry = new Map();
|
|
429
|
+
/**
|
|
430
|
+
* A style — the style props, the pseudo-state props, `reducedMotion`, and
|
|
431
|
+
* an `sx` object read the way Primer's `sx` read it — as one class and its
|
|
432
|
+
* rules. `undefined` when the style sets nothing.
|
|
433
|
+
*/
|
|
434
|
+
export function boxClassOf(style, sx) {
|
|
435
|
+
const P = `.${PLACEHOLDER}`;
|
|
436
|
+
const template = rulesOf(blockOf(style), P);
|
|
437
|
+
for (const [key, pseudo] of Object.entries(BOX_PSEUDO_PROPS)) {
|
|
438
|
+
const nested = style[key];
|
|
439
|
+
if (nested && typeof nested === 'object') {
|
|
440
|
+
template.push(...rulesOf(blockOf(nested), `${P}${pseudo}`));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const reduced = style.reducedMotion;
|
|
444
|
+
if (reduced && typeof reduced === 'object') {
|
|
445
|
+
template.push(...rulesOf(blockOf(reduced), P, [BOX_REDUCED_MOTION]));
|
|
446
|
+
}
|
|
447
|
+
// `sx` last: it wins over the props, as it did on Primer's Box.
|
|
448
|
+
if (sx && typeof sx === 'object') {
|
|
449
|
+
template.push(...sxRules(sx, [P], []));
|
|
450
|
+
}
|
|
451
|
+
if (template.length === 0) {
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
|
454
|
+
const text = template.join('');
|
|
455
|
+
const className = `bx-${hash(text)}${text.length.toString(36)}`;
|
|
456
|
+
let box = registry.get(className);
|
|
457
|
+
if (!box) {
|
|
458
|
+
// One object per class: a stable dependency for the effects that insert it.
|
|
459
|
+
box = { className, rules: template.map(rule => rule.split(PLACEHOLDER).join(className)) };
|
|
460
|
+
registry.set(className, box);
|
|
461
|
+
}
|
|
462
|
+
return box;
|
|
463
|
+
}
|
|
464
|
+
/** Every rule resolved so far, as one stylesheet: for server rendering and tests. */
|
|
465
|
+
export function getBoxCss() {
|
|
466
|
+
return [...registry.values()].map(box => box.rules.join('\n')).join('\n');
|
|
467
|
+
}
|
|
468
|
+
/* ── The stylesheet ──────────────────────────────────────────────────── */
|
|
469
|
+
const STYLE_ATTRIBUTE = 'data-primer-addons-box';
|
|
470
|
+
const sheets = new WeakMap();
|
|
471
|
+
function sheetOf(root) {
|
|
472
|
+
let entry = sheets.get(root);
|
|
473
|
+
if (!entry || !entry.element.isConnected) {
|
|
474
|
+
const doc = root instanceof Document ? root : root.ownerDocument;
|
|
475
|
+
const element = doc.createElement('style');
|
|
476
|
+
element.setAttribute(STYLE_ATTRIBUTE, '');
|
|
477
|
+
(root instanceof Document ? root.head : root).appendChild(element);
|
|
478
|
+
entry = { element, inserted: new Set() };
|
|
479
|
+
sheets.set(root, entry);
|
|
480
|
+
}
|
|
481
|
+
return entry;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Puts a class's rules in the stylesheet of a document or a shadow root,
|
|
485
|
+
* once. With `insertRule`: no reparsing of the sheet as classes are added.
|
|
486
|
+
*/
|
|
487
|
+
export function injectBoxClass(root, box) {
|
|
488
|
+
const entry = sheetOf(root);
|
|
489
|
+
if (entry.inserted.has(box.className)) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
entry.inserted.add(box.className);
|
|
493
|
+
const sheet = entry.element.sheet;
|
|
494
|
+
for (const rule of box.rules) {
|
|
495
|
+
try {
|
|
496
|
+
if (sheet) {
|
|
497
|
+
sheet.insertRule(rule, sheet.cssRules.length);
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
entry.element.appendChild(entry.element.ownerDocument.createTextNode(rule));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
catch {
|
|
504
|
+
// A rule the browser cannot parse (a typo in a value): skipped, as a
|
|
505
|
+
// stylesheet would.
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tokens `Box` resolves, taken from Primer React's own theme
|
|
3
|
+
* (`@primer/react` 37, `legacy-theme/ts/color-schemes.js`): each colour or
|
|
4
|
+
* shadow path is mapped to the first CSS variable Primer's theme object
|
|
5
|
+
* gives it — the variable Primer itself reads first — and emitted without
|
|
6
|
+
* the fallback chain that follows it. The scales are Primer's theme scales.
|
|
7
|
+
*
|
|
8
|
+
* Generated from Primer's color schemes; regenerate when `@primer/react`
|
|
9
|
+
* changes its theme.
|
|
10
|
+
*/
|
|
11
|
+
export declare const BOX_COLOR_VARS: {
|
|
12
|
+
readonly 'fg.default': "--fgColor-default";
|
|
13
|
+
readonly 'fg.muted': "--fgColor-muted";
|
|
14
|
+
readonly 'fg.subtle': "--fgColor-muted";
|
|
15
|
+
readonly 'fg.onEmphasis': "--fgColor-onEmphasis";
|
|
16
|
+
readonly 'canvas.default': "--bgColor-default";
|
|
17
|
+
readonly 'canvas.overlay': "--overlay-bgColor";
|
|
18
|
+
readonly 'canvas.inset': "--bgColor-inset";
|
|
19
|
+
readonly 'canvas.subtle': "--bgColor-muted";
|
|
20
|
+
readonly 'border.default': "--borderColor-default";
|
|
21
|
+
readonly 'border.muted': "--borderColor-muted";
|
|
22
|
+
readonly 'border.subtle': "--borderColor-muted";
|
|
23
|
+
readonly 'neutral.emphasisPlus': "--bgColor-emphasis";
|
|
24
|
+
readonly 'neutral.emphasis': "--bgColor-neutral-emphasis";
|
|
25
|
+
readonly 'neutral.muted': "--bgColor-neutral-muted";
|
|
26
|
+
readonly 'neutral.subtle': "--bgColor-neutral-muted";
|
|
27
|
+
readonly 'accent.fg': "--fgColor-accent";
|
|
28
|
+
readonly 'accent.emphasis': "--bgColor-accent-emphasis";
|
|
29
|
+
readonly 'accent.muted': "--borderColor-accent-muted";
|
|
30
|
+
readonly 'accent.subtle': "--bgColor-accent-muted";
|
|
31
|
+
readonly 'success.fg': "--fgColor-success";
|
|
32
|
+
readonly 'success.emphasis': "--bgColor-success-emphasis";
|
|
33
|
+
readonly 'success.muted': "--borderColor-success-muted";
|
|
34
|
+
readonly 'success.subtle': "--bgColor-success-muted";
|
|
35
|
+
readonly 'attention.fg': "--fgColor-attention";
|
|
36
|
+
readonly 'attention.emphasis': "--bgColor-attention-emphasis";
|
|
37
|
+
readonly 'attention.muted': "--borderColor-attention-muted";
|
|
38
|
+
readonly 'attention.subtle': "--bgColor-attention-muted";
|
|
39
|
+
readonly 'severe.fg': "--fgColor-severe";
|
|
40
|
+
readonly 'severe.emphasis': "--bgColor-severe-emphasis";
|
|
41
|
+
readonly 'severe.muted': "--borderColor-severe-muted";
|
|
42
|
+
readonly 'severe.subtle': "--bgColor-severe-muted";
|
|
43
|
+
readonly 'danger.fg': "--fgColor-danger";
|
|
44
|
+
readonly 'danger.emphasis': "--borderColor-danger-emphasis";
|
|
45
|
+
readonly 'danger.muted': "--borderColor-danger-muted";
|
|
46
|
+
readonly 'danger.subtle': "--bgColor-danger-muted";
|
|
47
|
+
readonly 'open.fg': "--fgColor-open";
|
|
48
|
+
readonly 'open.emphasis': "--bgColor-open-emphasis";
|
|
49
|
+
readonly 'open.muted': "--borderColor-open-muted";
|
|
50
|
+
readonly 'open.subtle': "--bgColor-open-muted";
|
|
51
|
+
readonly 'closed.fg': "--fgColor-closed";
|
|
52
|
+
readonly 'closed.emphasis': "--bgColor-closed-emphasis";
|
|
53
|
+
readonly 'closed.muted': "--borderColor-closed-muted";
|
|
54
|
+
readonly 'closed.subtle': "--bgColor-closed-muted";
|
|
55
|
+
readonly 'done.fg': "--fgColor-done";
|
|
56
|
+
readonly 'done.emphasis': "--bgColor-done-emphasis";
|
|
57
|
+
readonly 'done.muted': "--borderColor-done-muted";
|
|
58
|
+
readonly 'done.subtle': "--bgColor-done-muted";
|
|
59
|
+
readonly 'sponsors.fg': "--fgColor-sponsors";
|
|
60
|
+
readonly 'sponsors.emphasis': "--bgColor-sponsors-emphasis";
|
|
61
|
+
readonly 'sponsors.muted': "--borderColor-sponsors-muted";
|
|
62
|
+
readonly 'sponsors.subtle': "--bgColor-sponsors-muted";
|
|
63
|
+
readonly 'actionListItem.default.hoverBg': "--control-transparent-bgColor-hover";
|
|
64
|
+
readonly 'actionListItem.default.activeBg': "--control-transparent-bgColor-active";
|
|
65
|
+
};
|
|
66
|
+
export declare const BOX_SHADOW_VARS: {
|
|
67
|
+
readonly 'shadow.small': "--shadow-resting-small";
|
|
68
|
+
readonly 'shadow.medium': "--shadow-resting-medium";
|
|
69
|
+
readonly 'shadow.large': "--shadow-floating-large";
|
|
70
|
+
readonly 'shadow.extraLarge': "--shadow-floating-xlarge";
|
|
71
|
+
};
|
|
72
|
+
export type BoxColorToken = keyof typeof BOX_COLOR_VARS;
|
|
73
|
+
export type BoxShadowToken = keyof typeof BOX_SHADOW_VARS;
|
|
74
|
+
/** Primer's breakpoints: a responsive array's second value from 544px, … */
|
|
75
|
+
export declare const BOX_BREAKPOINTS: readonly ["544px", "768px", "1012px", "1280px"];
|
|
76
|
+
/** Primer's space scale: `p={3}` is 16px. */
|
|
77
|
+
export declare const BOX_SPACE: readonly ["0", "4px", "8px", "16px", "24px", "32px", "40px", "48px", "64px", "80px", "96px", "112px", "128px"];
|
|
78
|
+
/** Primer's font sizes: `fontSize={1}` is 14px. */
|
|
79
|
+
export declare const BOX_FONT_SIZES: readonly ["12px", "14px", "16px", "20px", "24px", "32px", "40px", "48px", "56px"];
|
|
80
|
+
/** Primer's radii by index (`borderRadius={2}` is 6px). */
|
|
81
|
+
export declare const BOX_RADII: readonly ["0", "3px", "6px", "100px"];
|
|
82
|
+
/** Radii by name: Primer's, and the theme's shapes (LOOP T-03), an overlay's among them. */
|
|
83
|
+
export declare const BOX_RADIUS_VARS: {
|
|
84
|
+
readonly small: "--borderRadius-small";
|
|
85
|
+
readonly medium: "--borderRadius-medium";
|
|
86
|
+
readonly large: "--borderRadius-large";
|
|
87
|
+
readonly full: "--borderRadius-full";
|
|
88
|
+
readonly control: "--theme-radius-control";
|
|
89
|
+
readonly card: "--theme-radius-card";
|
|
90
|
+
readonly bubble: "--theme-radius-bubble";
|
|
91
|
+
readonly frame: "--theme-radius-frame";
|
|
92
|
+
readonly overlay: "--theme-radius-overlay";
|
|
93
|
+
};
|
|
94
|
+
export type BoxRadiusToken = keyof typeof BOX_RADIUS_VARS;
|
|
95
|
+
/** Primer's border widths by index. */
|
|
96
|
+
export declare const BOX_BORDER_WIDTHS: readonly ["0", "1px"];
|
|
97
|
+
/** Primer's sizes by name (`maxWidth="large"` is 1012px). */
|
|
98
|
+
export declare const BOX_SIZES: {
|
|
99
|
+
readonly small: "544px";
|
|
100
|
+
readonly medium: "768px";
|
|
101
|
+
readonly large: "1012px";
|
|
102
|
+
readonly xlarge: "1280px";
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Font weights by name, as the theme's weight variables. Primer's theme
|
|
106
|
+
* names its weights 300, 400, 500, 600 — `light`, `normal`, `semibold`,
|
|
107
|
+
* `bold` — which are the primitives' `light`, `normal`, `medium` and
|
|
108
|
+
* `semibold`: so `semibold` is `--base-text-weight-medium` (500, and 600 in
|
|
109
|
+
* the `loop` theme, which has two weights), as it reads today.
|
|
110
|
+
*/
|
|
111
|
+
export declare const BOX_FONT_WEIGHT_VARS: {
|
|
112
|
+
readonly light: "--base-text-weight-light";
|
|
113
|
+
readonly normal: "--base-text-weight-normal";
|
|
114
|
+
readonly medium: "--base-text-weight-medium";
|
|
115
|
+
readonly semibold: "--base-text-weight-medium";
|
|
116
|
+
readonly bold: "--base-text-weight-semibold";
|
|
117
|
+
};
|
|
118
|
+
/** Primer's line heights by name. */
|
|
119
|
+
export declare const BOX_LINE_HEIGHTS: {
|
|
120
|
+
readonly condensedUltra: "1";
|
|
121
|
+
readonly condensed: "1.25";
|
|
122
|
+
readonly default: "1.5";
|
|
123
|
+
};
|
|
124
|
+
/** Font families by name. */
|
|
125
|
+
export declare const BOX_FONT_VARS: {
|
|
126
|
+
readonly normal: "--fontStack-system";
|
|
127
|
+
readonly mono: "--fontStack-monospace";
|
|
128
|
+
};
|
|
129
|
+
/** Every CSS variable `Box` can emit: the theme provider must set them all. */
|
|
130
|
+
export declare const BOX_EMITTED_VARS: readonly string[];
|