@atom63/widgets 0.1.0-beta.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/LICENSE +27 -0
- package/README.md +29 -0
- package/dist/chunk-F5NV6XJ5.js +418 -0
- package/dist/chunk-F5NV6XJ5.js.map +1 -0
- package/dist/chunk-US2CE3BV.js +222 -0
- package/dist/chunk-US2CE3BV.js.map +1 -0
- package/dist/index.d.ts +714 -0
- package/dist/index.js +206 -0
- package/dist/index.js.map +1 -0
- package/dist/primitives/index.d.ts +123 -0
- package/dist/primitives/index.js +4 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/runtime/index.d.ts +129 -0
- package/dist/runtime/index.js +236 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/state/index.d.ts +90 -0
- package/dist/state/index.js +158 -0
- package/dist/state/index.js.map +1 -0
- package/dist/types-C0zDKyo1.d.ts +3 -0
- package/dist/widget-card-BckLTmBY.d.ts +112 -0
- package/package.json +98 -0
- package/src/layout/widget-layout.css +76 -0
- package/src/primitives/widget-avatar.css +153 -0
- package/src/primitives/widget-card.css +128 -0
- package/src/primitives/widget-surface.css +75 -0
- package/src/runtime/widget-runtime.css +136 -0
- package/src/state/widget-state-feedback.css +149 -0
- package/src/styles.css +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 You Zhang (ATOM63)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
The MIT license above covers the code and documentation in this repository. It does not grant
|
|
26
|
+
any right to use the ATOM63 name, the ATOM63 logo or other ATOM63 brand marks, including the
|
|
27
|
+
artwork in packages/brand. All rights to them are reserved.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @atom63/widgets
|
|
2
|
+
|
|
3
|
+
The Atom63 widget foundation: the unit model that sizes and scales widgets, the card and surface
|
|
4
|
+
they are drawn on, the loading, empty and error states, and the hosted shell.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add @atom63/widgets @atom63/ui-react
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```css
|
|
11
|
+
@import '@atom63/styles';
|
|
12
|
+
@import '@atom63/ui-react/recipes.css';
|
|
13
|
+
@import '@atom63/widgets/styles.css';
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The components ship their own stylesheet (`.a63-Widget*` classes on `--a63-*` tokens and the
|
|
17
|
+
`--a63-widget-*` contract) and need no Tailwind.
|
|
18
|
+
|
|
19
|
+
- `@atom63/widgets` — widget units and spans, presentation scale, type ramp, insets, `WidgetGrid`,
|
|
20
|
+
`WidgetViewport`, `WidgetImage`, the link and destination helpers, and `WidgetSize`.
|
|
21
|
+
- `@atom63/widgets/primitives` — `WidgetSurface`, `WidgetCard` and its parts, `WidgetShell`,
|
|
22
|
+
`WidgetBlock`, `WidgetAvatar`, and the surface class constants.
|
|
23
|
+
- `@atom63/widgets/state` — `WidgetStateFeedback`, `widgetStateCopy`,
|
|
24
|
+
`resolveWidgetFeedbackState` and the shared state props.
|
|
25
|
+
- `@atom63/widgets/runtime` — `WidgetHostedShell`, the title and content transitions, the loading
|
|
26
|
+
shell, the error fallback and the transition settings.
|
|
27
|
+
|
|
28
|
+
See the design system's [Widgets pattern page](https://system.atom63.io/patterns/pattern-widgets)
|
|
29
|
+
for the unit model, the contract tokens and the hosted shell.
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { createContext, useContext, useRef, useCallback, useLayoutEffect } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/utils.ts
|
|
5
|
+
function collect(value, out) {
|
|
6
|
+
if (!value) return;
|
|
7
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "bigint") {
|
|
8
|
+
out.push(String(value));
|
|
9
|
+
} else if (Array.isArray(value)) {
|
|
10
|
+
for (const item of value) collect(item, out);
|
|
11
|
+
} else if (typeof value === "object") {
|
|
12
|
+
for (const [name, enabled] of Object.entries(value)) if (enabled) out.push(name);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function cn(...inputs) {
|
|
16
|
+
const out = [];
|
|
17
|
+
for (const input of inputs) collect(input, out);
|
|
18
|
+
return out.join(" ");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/layout/widget-units.ts
|
|
22
|
+
var WIDGET_UNIT_SPAN = {
|
|
23
|
+
small: { cols: 1, rows: 1 },
|
|
24
|
+
medium: { cols: 2, rows: 1 },
|
|
25
|
+
large: { cols: 2, rows: 2 }
|
|
26
|
+
};
|
|
27
|
+
var WIDGET_UNIT_BASE_PX = 256;
|
|
28
|
+
var WIDGET_CANONICAL_CELL_PX = 188;
|
|
29
|
+
var WIDGET_MAX_PRESENTATION_SCALE = 1.375;
|
|
30
|
+
var WIDGET_TYPE_FLOOR = {
|
|
31
|
+
label: 11,
|
|
32
|
+
body: 12,
|
|
33
|
+
display: 0
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/layout/widget-scale.ts
|
|
37
|
+
var WIDGET_DENSITY_SCALE = {
|
|
38
|
+
compact: 0.9,
|
|
39
|
+
default: 1,
|
|
40
|
+
comfortable: 1.1
|
|
41
|
+
};
|
|
42
|
+
var WIDGET_CONTROL_MIN_TARGET_PX = 24;
|
|
43
|
+
function controlTargetStyle(scaleDivisor) {
|
|
44
|
+
const target = scaleDivisor ? `calc(${WIDGET_CONTROL_MIN_TARGET_PX}px / ${scaleDivisor})` : `${WIDGET_CONTROL_MIN_TARGET_PX}px`;
|
|
45
|
+
return {
|
|
46
|
+
"--a63-control-min-target": target,
|
|
47
|
+
"--a63-control-min-target-lg": target,
|
|
48
|
+
"--a63-control-min-target-xl": target
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function unitExpression(minScale) {
|
|
52
|
+
const raw = `calc(var(--widget-cell) / ${WIDGET_UNIT_BASE_PX} * var(--widget-scale, 1))`;
|
|
53
|
+
const maximumUnit = WIDGET_CANONICAL_CELL_PX * WIDGET_MAX_PRESENTATION_SCALE / WIDGET_UNIT_BASE_PX;
|
|
54
|
+
return minScale == null ? `min(${raw}, ${maximumUnit}px)` : `clamp(${minScale}px, ${raw}, ${maximumUnit}px)`;
|
|
55
|
+
}
|
|
56
|
+
function resolveScale(scale, density) {
|
|
57
|
+
return String(Math.round(scale * WIDGET_DENSITY_SCALE[density] * 1e6) / 1e6);
|
|
58
|
+
}
|
|
59
|
+
function widgetUnitStyle(cellPx, { density = "default", minScale, scale = 1 } = {}) {
|
|
60
|
+
const rawUnit = unitExpression(minScale);
|
|
61
|
+
return {
|
|
62
|
+
...controlTargetStyle(),
|
|
63
|
+
"--widget-cell": `${cellPx}px`,
|
|
64
|
+
"--widget-raw-u": rawUnit,
|
|
65
|
+
"--widget-scale": resolveScale(scale, density),
|
|
66
|
+
"--widget-u": "var(--widget-raw-u)"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function widgetPresentationStyle(cellPx = WIDGET_CANONICAL_CELL_PX) {
|
|
70
|
+
const presentationScale = String(
|
|
71
|
+
Math.min(cellPx / WIDGET_CANONICAL_CELL_PX, WIDGET_MAX_PRESENTATION_SCALE)
|
|
72
|
+
);
|
|
73
|
+
return {
|
|
74
|
+
...controlTargetStyle("var(--widget-presentation-scale)"),
|
|
75
|
+
"--widget-interaction-target": "calc(44px / var(--widget-presentation-scale))",
|
|
76
|
+
"--widget-presentation-scale": presentationScale,
|
|
77
|
+
"--widget-u": "calc(var(--widget-raw-u) / var(--widget-presentation-scale))",
|
|
78
|
+
// The canvas is a fixed-size box that the transform below scales — it must
|
|
79
|
+
// never be resized by its parent's layout. A host whose viewport element is
|
|
80
|
+
// a flex container (atom63.io's WidgetChrome adds `flex flex-col`) makes
|
|
81
|
+
// this a flex item, and a canvas laid out ABOVE the host box then shrinks to
|
|
82
|
+
// fit it before the transform shrinks it again: at a 165px mobile cell the
|
|
83
|
+
// 188px canvas collapsed to 165, scaled to 144.8, and a 1×1 tile rendered
|
|
84
|
+
// 165×144.8 instead of square. Invisible above the canonical cell, where the
|
|
85
|
+
// canvas is already smaller than its box and there is nothing to shrink.
|
|
86
|
+
flexShrink: 0,
|
|
87
|
+
height: "calc((var(--widget-rows) * var(--widget-cell) + (var(--widget-rows) - 1) * var(--widget-gap, 0px)) / var(--widget-presentation-scale))",
|
|
88
|
+
minWidth: 0,
|
|
89
|
+
transform: "scale(var(--widget-presentation-scale))",
|
|
90
|
+
transformOrigin: "top left",
|
|
91
|
+
width: "calc(100cqi / var(--widget-presentation-scale))"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
var CELL_FORMULA = "calc((100cqi - (var(--widget-span) - 1) * var(--widget-gap, 0px)) / var(--widget-span))";
|
|
95
|
+
function widgetSizeStyle(size, { density = "default", minScale, scale = 1 } = {}) {
|
|
96
|
+
const { cols, rows } = WIDGET_UNIT_SPAN[size];
|
|
97
|
+
const rawUnit = unitExpression(minScale);
|
|
98
|
+
return {
|
|
99
|
+
...controlTargetStyle(),
|
|
100
|
+
"--widget-cell": CELL_FORMULA,
|
|
101
|
+
"--widget-raw-u": rawUnit,
|
|
102
|
+
"--widget-rows": String(rows),
|
|
103
|
+
"--widget-scale": resolveScale(scale, density),
|
|
104
|
+
"--widget-span": String(cols),
|
|
105
|
+
"--widget-u": "var(--widget-raw-u)",
|
|
106
|
+
gridColumn: `span ${cols}`,
|
|
107
|
+
gridRow: `span ${rows}`,
|
|
108
|
+
height: "100%"
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/layout/widget-unit-style.ts
|
|
113
|
+
function wu(designPx) {
|
|
114
|
+
return `calc(${designPx} * var(--widget-u, 1px))`;
|
|
115
|
+
}
|
|
116
|
+
function wuClamp(designPx, minPx, maxPx) {
|
|
117
|
+
const mid = wu(designPx);
|
|
118
|
+
if (minPx != null && maxPx != null) {
|
|
119
|
+
return `clamp(${minPx}px, ${mid}, ${maxPx}px)`;
|
|
120
|
+
}
|
|
121
|
+
if (minPx != null) {
|
|
122
|
+
return `max(${minPx}px, ${mid})`;
|
|
123
|
+
}
|
|
124
|
+
if (maxPx != null) {
|
|
125
|
+
return `min(${mid}, ${maxPx}px)`;
|
|
126
|
+
}
|
|
127
|
+
return mid;
|
|
128
|
+
}
|
|
129
|
+
var wuStyle = {
|
|
130
|
+
p: (n) => ({ padding: wu(n) }),
|
|
131
|
+
px: (n) => ({ paddingInline: wu(n) }),
|
|
132
|
+
py: (n) => ({ paddingBlock: wu(n) }),
|
|
133
|
+
pt: (n) => ({ paddingTop: wu(n) }),
|
|
134
|
+
pb: (n) => ({ paddingBottom: wu(n) }),
|
|
135
|
+
gap: (n) => ({ gap: wu(n) }),
|
|
136
|
+
gapX: (n) => ({ columnGap: wu(n) }),
|
|
137
|
+
gapY: (n) => ({ rowGap: wu(n) }),
|
|
138
|
+
m: (n) => ({ margin: wu(n) }),
|
|
139
|
+
mt: (n) => ({ marginTop: wu(n) }),
|
|
140
|
+
mb: (n) => ({ marginBottom: wu(n) }),
|
|
141
|
+
ml: (n) => ({ marginLeft: wu(n) }),
|
|
142
|
+
mr: (n) => ({ marginRight: wu(n) }),
|
|
143
|
+
mx: (n) => ({ marginInline: wu(n) }),
|
|
144
|
+
my: (n) => ({ marginBlock: wu(n) }),
|
|
145
|
+
size: (n) => ({ width: wu(n), height: wu(n) }),
|
|
146
|
+
h: (n) => ({ height: wu(n) }),
|
|
147
|
+
w: (n) => ({ width: wu(n) }),
|
|
148
|
+
text: (n) => ({ fontSize: wu(n) }),
|
|
149
|
+
textMin: (n, minPx) => ({
|
|
150
|
+
fontSize: wuClamp(n, minPx)
|
|
151
|
+
}),
|
|
152
|
+
rounded: (n) => ({ borderRadius: wu(n) })
|
|
153
|
+
};
|
|
154
|
+
function wuMerge(...parts) {
|
|
155
|
+
const merged = {};
|
|
156
|
+
for (const part of parts) {
|
|
157
|
+
if (part) Object.assign(merged, part);
|
|
158
|
+
}
|
|
159
|
+
return merged;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/layout/widget-inset.ts
|
|
163
|
+
var WIDGET_BODY_INSET = {
|
|
164
|
+
small: 16,
|
|
165
|
+
medium: 22,
|
|
166
|
+
large: 22
|
|
167
|
+
};
|
|
168
|
+
var WIDGET_BODY_GAP = {
|
|
169
|
+
small: 11,
|
|
170
|
+
medium: 11,
|
|
171
|
+
large: 16
|
|
172
|
+
};
|
|
173
|
+
function widgetInsetPx(size) {
|
|
174
|
+
return WIDGET_BODY_INSET[size];
|
|
175
|
+
}
|
|
176
|
+
function widgetInsetStyle(size, mode = "face", options) {
|
|
177
|
+
const inset = WIDGET_BODY_INSET[size];
|
|
178
|
+
const includeGap = options?.gap !== false;
|
|
179
|
+
const style = {
|
|
180
|
+
paddingInline: wu(inset),
|
|
181
|
+
paddingBottom: wu(inset)
|
|
182
|
+
};
|
|
183
|
+
if (mode === "face") {
|
|
184
|
+
style.paddingTop = wu(inset);
|
|
185
|
+
}
|
|
186
|
+
if (includeGap) {
|
|
187
|
+
style.gap = wu(WIDGET_BODY_GAP[size]);
|
|
188
|
+
}
|
|
189
|
+
return style;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/layout/widget-type.ts
|
|
193
|
+
var WIDGET_TYPE_ROLE_FLOOR = {
|
|
194
|
+
/** Quiet uppercase identity on the chrome header. */
|
|
195
|
+
chrome: "label",
|
|
196
|
+
/** Smallest supporting labels (stat keys, legends, zone tags). */
|
|
197
|
+
label: "label",
|
|
198
|
+
/** Default reading copy. */
|
|
199
|
+
body: "body",
|
|
200
|
+
/** Compact identity (handles, short names). */
|
|
201
|
+
name: "body",
|
|
202
|
+
/** Content headings that are not the hero figure. */
|
|
203
|
+
title: "body",
|
|
204
|
+
/** Featured content name (project title, primary listing). */
|
|
205
|
+
headline: "body",
|
|
206
|
+
/** Mid-weight digital / tabular figures (profile stats). */
|
|
207
|
+
stat: "body",
|
|
208
|
+
/** Hero figures — temperature, big totals. Unfloored. */
|
|
209
|
+
display: "display",
|
|
210
|
+
/** Dense hero digits (clock faces beside a second column). Unfloored. */
|
|
211
|
+
displayCompact: "display"
|
|
212
|
+
};
|
|
213
|
+
var WIDGET_TYPE_RAMP = {
|
|
214
|
+
chrome: {
|
|
215
|
+
// Mid quiet chrome: ~10.3px at OS63 (14×188/256), floored to 10 — between
|
|
216
|
+
// the old text-xs (~12) and the too-quiet 9px experiment.
|
|
217
|
+
designPx: 14,
|
|
218
|
+
weight: 500,
|
|
219
|
+
trackingEm: 0.025,
|
|
220
|
+
transform: "uppercase",
|
|
221
|
+
leading: 1,
|
|
222
|
+
floorPx: 10,
|
|
223
|
+
// Icon sits just above the cap height.
|
|
224
|
+
iconDesignPx: 14,
|
|
225
|
+
iconFloorPx: 11
|
|
226
|
+
},
|
|
227
|
+
label: {
|
|
228
|
+
designPx: 15,
|
|
229
|
+
weight: 500
|
|
230
|
+
},
|
|
231
|
+
body: {
|
|
232
|
+
designPx: 17,
|
|
233
|
+
weight: 400
|
|
234
|
+
},
|
|
235
|
+
name: {
|
|
236
|
+
designPx: { small: 18, medium: 19, large: 22 },
|
|
237
|
+
weight: 600
|
|
238
|
+
},
|
|
239
|
+
title: {
|
|
240
|
+
designPx: { small: 20, medium: 22, large: 24 },
|
|
241
|
+
weight: 600
|
|
242
|
+
},
|
|
243
|
+
headline: {
|
|
244
|
+
designPx: { small: 26, medium: 28, large: 32 },
|
|
245
|
+
weight: 600,
|
|
246
|
+
// Display serif (Hedvig Letters Serif) with tall ascenders — 1.12 read as
|
|
247
|
+
// two lines fighting for the same band once the headline cleared its floor.
|
|
248
|
+
leading: 1.18
|
|
249
|
+
},
|
|
250
|
+
stat: {
|
|
251
|
+
designPx: { small: 22, medium: 23, large: 26 },
|
|
252
|
+
weight: 600
|
|
253
|
+
},
|
|
254
|
+
display: {
|
|
255
|
+
designPx: { small: 48, medium: 44, large: 64 },
|
|
256
|
+
weight: 600
|
|
257
|
+
},
|
|
258
|
+
displayCompact: {
|
|
259
|
+
designPx: { small: 40, medium: 34, large: 52 },
|
|
260
|
+
weight: 600
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
function resolveDesignPx(designPx, size) {
|
|
264
|
+
return typeof designPx === "number" ? designPx : designPx[size];
|
|
265
|
+
}
|
|
266
|
+
function widgetTypeDesignPx(role, size = "medium") {
|
|
267
|
+
return resolveDesignPx(WIDGET_TYPE_RAMP[role].designPx, size);
|
|
268
|
+
}
|
|
269
|
+
function widgetTypeStyle(role, size = "medium", options) {
|
|
270
|
+
const recipe = WIDGET_TYPE_RAMP[role];
|
|
271
|
+
const floorRole = WIDGET_TYPE_ROLE_FLOOR[role];
|
|
272
|
+
const floorPx = recipe.floorPx ?? WIDGET_TYPE_FLOOR[floorRole];
|
|
273
|
+
const designPx = options?.designPx ?? resolveDesignPx(recipe.designPx, size);
|
|
274
|
+
const weight = options?.weight ?? recipe.weight;
|
|
275
|
+
const trackingEm = options?.trackingEm ?? recipe.trackingEm;
|
|
276
|
+
const leading = options?.leading ?? recipe.leading;
|
|
277
|
+
const style = {
|
|
278
|
+
fontSize: floorPx > 0 ? wuClamp(designPx, floorPx) : wu(designPx),
|
|
279
|
+
fontWeight: weight
|
|
280
|
+
};
|
|
281
|
+
if (trackingEm != null) {
|
|
282
|
+
style.letterSpacing = `${trackingEm}em`;
|
|
283
|
+
}
|
|
284
|
+
if (recipe.transform) {
|
|
285
|
+
style.textTransform = recipe.transform;
|
|
286
|
+
}
|
|
287
|
+
if (leading != null) {
|
|
288
|
+
style.lineHeight = leading;
|
|
289
|
+
}
|
|
290
|
+
return style;
|
|
291
|
+
}
|
|
292
|
+
function widgetChromeIconStyle() {
|
|
293
|
+
const recipe = WIDGET_TYPE_RAMP.chrome;
|
|
294
|
+
const designPx = recipe.iconDesignPx ?? resolveDesignPx(recipe.designPx, "medium");
|
|
295
|
+
const floorPx = recipe.iconFloorPx ?? recipe.floorPx ?? WIDGET_TYPE_FLOOR.label;
|
|
296
|
+
return {
|
|
297
|
+
width: floorPx > 0 ? wuClamp(designPx, floorPx) : wu(designPx),
|
|
298
|
+
height: floorPx > 0 ? wuClamp(designPx, floorPx) : wu(designPx)
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function widgetClampRelief(content = "text") {
|
|
302
|
+
const relief = content === "emoji" ? "0.55em" : "0.24em";
|
|
303
|
+
return {
|
|
304
|
+
paddingBottom: relief,
|
|
305
|
+
marginBottom: `-${relief}`
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
var WidgetSizeContext = createContext("small");
|
|
309
|
+
function useWidgetSize() {
|
|
310
|
+
return useContext(WidgetSizeContext);
|
|
311
|
+
}
|
|
312
|
+
function WidgetSizeProvider({ children, size }) {
|
|
313
|
+
return /* @__PURE__ */ jsx(WidgetSizeContext.Provider, { value: size, children });
|
|
314
|
+
}
|
|
315
|
+
function WidgetGrid({
|
|
316
|
+
children,
|
|
317
|
+
columns = 2,
|
|
318
|
+
gap = 12,
|
|
319
|
+
ref,
|
|
320
|
+
style,
|
|
321
|
+
...props
|
|
322
|
+
}) {
|
|
323
|
+
const gridStyle = {
|
|
324
|
+
"--widget-cols": String(columns),
|
|
325
|
+
"--widget-gap": `${gap}px`,
|
|
326
|
+
display: "grid",
|
|
327
|
+
gap: `${gap}px`,
|
|
328
|
+
gridAutoRows: "calc((100cqi - (var(--widget-cols) - 1) * var(--widget-gap)) / var(--widget-cols))",
|
|
329
|
+
gridTemplateColumns: "repeat(var(--widget-cols), minmax(0, 1fr))",
|
|
330
|
+
...style
|
|
331
|
+
};
|
|
332
|
+
return /* @__PURE__ */ jsx("div", { ref, style: { containerType: "inline-size" }, ...props, children: /* @__PURE__ */ jsx("div", { style: gridStyle, children }) });
|
|
333
|
+
}
|
|
334
|
+
function assignRef(ref, value) {
|
|
335
|
+
if (typeof ref === "function") {
|
|
336
|
+
ref(value);
|
|
337
|
+
} else if (ref) {
|
|
338
|
+
ref.current = value;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function WidgetViewport({
|
|
342
|
+
cellPx,
|
|
343
|
+
children,
|
|
344
|
+
className,
|
|
345
|
+
ref,
|
|
346
|
+
size,
|
|
347
|
+
style,
|
|
348
|
+
...props
|
|
349
|
+
}) {
|
|
350
|
+
const viewportRef = useRef(null);
|
|
351
|
+
const canvasRef = useRef(null);
|
|
352
|
+
const setViewportRef = useCallback(
|
|
353
|
+
(node) => {
|
|
354
|
+
viewportRef.current = node;
|
|
355
|
+
assignRef(ref, node);
|
|
356
|
+
},
|
|
357
|
+
[ref]
|
|
358
|
+
);
|
|
359
|
+
useLayoutEffect(() => {
|
|
360
|
+
const viewport = viewportRef.current;
|
|
361
|
+
const canvas = canvasRef.current;
|
|
362
|
+
if (!viewport || !canvas) return;
|
|
363
|
+
if (cellPx != null) return;
|
|
364
|
+
const updatePresentationScale = () => {
|
|
365
|
+
const computedStyle = getComputedStyle(viewport);
|
|
366
|
+
const span = Number.parseFloat(computedStyle.getPropertyValue("--widget-span")) || 1;
|
|
367
|
+
const gap = Number.parseFloat(computedStyle.getPropertyValue("--widget-gap")) || 0;
|
|
368
|
+
const cellPx2 = (viewport.getBoundingClientRect().width - (span - 1) * gap) / span;
|
|
369
|
+
const scale = Math.min(cellPx2 / WIDGET_CANONICAL_CELL_PX, WIDGET_MAX_PRESENTATION_SCALE);
|
|
370
|
+
canvas.style.setProperty("--widget-presentation-scale", String(scale));
|
|
371
|
+
};
|
|
372
|
+
updatePresentationScale();
|
|
373
|
+
if (typeof ResizeObserver === "undefined") {
|
|
374
|
+
window.addEventListener("resize", updatePresentationScale);
|
|
375
|
+
return () => window.removeEventListener("resize", updatePresentationScale);
|
|
376
|
+
}
|
|
377
|
+
const observer = new ResizeObserver(updatePresentationScale);
|
|
378
|
+
observer.observe(viewport);
|
|
379
|
+
return () => observer.disconnect();
|
|
380
|
+
}, [cellPx, size]);
|
|
381
|
+
const presentationStyle = cellPx == null ? widgetPresentationStyle() : {
|
|
382
|
+
...widgetPresentationStyle(cellPx),
|
|
383
|
+
// Off the cell, onto the box. The cell-derived height is the row's
|
|
384
|
+
// resting height, which is the same number — until the host animates
|
|
385
|
+
// the shell between two sizes, when the box is the one that is still
|
|
386
|
+
// true. `100%` resolves against the viewport, which is `size-full`.
|
|
387
|
+
height: "calc(100% / var(--widget-presentation-scale))"
|
|
388
|
+
};
|
|
389
|
+
return /* @__PURE__ */ jsx(WidgetSizeProvider, { size, children: /* @__PURE__ */ jsx(
|
|
390
|
+
"article",
|
|
391
|
+
{
|
|
392
|
+
className: cn("a63-WidgetViewport", className),
|
|
393
|
+
"data-widget-viewport": "",
|
|
394
|
+
"data-widget-viewport-size": size,
|
|
395
|
+
ref: setViewportRef,
|
|
396
|
+
style: {
|
|
397
|
+
...widgetSizeStyle(size),
|
|
398
|
+
// A known cell replaces the `100cqi`-derived one, so `--widget-u`
|
|
399
|
+
// stops tracking a travelling width along with it.
|
|
400
|
+
...cellPx == null ? null : { "--widget-cell": `${cellPx}px` },
|
|
401
|
+
...style
|
|
402
|
+
},
|
|
403
|
+
...props,
|
|
404
|
+
children: /* @__PURE__ */ jsx("div", { "data-widget-presentation-canvas": "", ref: canvasRef, style: presentationStyle, children })
|
|
405
|
+
}
|
|
406
|
+
) });
|
|
407
|
+
}
|
|
408
|
+
function withWidgetViewport(Component) {
|
|
409
|
+
function WidgetViewportBoundary(props) {
|
|
410
|
+
return /* @__PURE__ */ jsx(WidgetViewport, { className: "a63-WidgetViewport-fill", size: props.size, children: /* @__PURE__ */ jsx(Component, { ...props }) });
|
|
411
|
+
}
|
|
412
|
+
WidgetViewportBoundary.displayName = `withWidgetViewport(${Component.displayName ?? Component.name ?? "Widget"})`;
|
|
413
|
+
return WidgetViewportBoundary;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export { WIDGET_BODY_GAP, WIDGET_BODY_INSET, WIDGET_CANONICAL_CELL_PX, WIDGET_DENSITY_SCALE, WIDGET_MAX_PRESENTATION_SCALE, WIDGET_TYPE_FLOOR, WIDGET_TYPE_RAMP, WIDGET_TYPE_ROLE_FLOOR, WIDGET_UNIT_BASE_PX, WIDGET_UNIT_SPAN, WidgetGrid, WidgetSizeProvider, WidgetViewport, cn, useWidgetSize, widgetChromeIconStyle, widgetClampRelief, widgetInsetPx, widgetInsetStyle, widgetPresentationStyle, widgetSizeStyle, widgetTypeDesignPx, widgetTypeStyle, widgetUnitStyle, withWidgetViewport, wu, wuClamp, wuMerge, wuStyle };
|
|
417
|
+
//# sourceMappingURL=chunk-F5NV6XJ5.js.map
|
|
418
|
+
//# sourceMappingURL=chunk-F5NV6XJ5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/layout/widget-units.ts","../src/layout/widget-scale.ts","../src/layout/widget-unit-style.ts","../src/layout/widget-inset.ts","../src/layout/widget-type.ts","../src/layout/widget-grid.tsx","../src/layout/widget-viewport.tsx"],"names":["cellPx","jsx"],"mappings":";;;;AAGA,SAAS,OAAA,CAAQ,OAAmB,GAAA,EAAqB;AACvD,EAAA,IAAI,CAAC,KAAA,EAAO;AACZ,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,OAAO,UAAU,QAAA,IAAY,OAAO,UAAU,QAAA,EAAU;AACvF,IAAA,GAAA,CAAI,IAAA,CAAK,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,EACxB,CAAA,MAAA,IAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAC/B,IAAA,KAAA,MAAW,IAAA,IAAQ,KAAA,EAAO,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAA;AAAA,EAC7C,CAAA,MAAA,IAAW,OAAO,KAAA,KAAU,QAAA,EAAU;AACpC,IAAA,KAAA,MAAW,CAAC,IAAA,EAAM,OAAO,CAAA,IAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG,IAAI,OAAA,EAAS,GAAA,CAAI,IAAA,CAAK,IAAI,CAAA;AAAA,EACjF;AACF;AASO,SAAS,MAAM,MAAA,EAA8B;AAClD,EAAA,MAAM,MAAgB,EAAC;AACvB,EAAA,KAAA,MAAW,KAAA,IAAS,MAAA,EAAQ,OAAA,CAAQ,KAAA,EAAO,GAAG,CAAA;AAC9C,EAAA,OAAO,GAAA,CAAI,KAAK,GAAG,CAAA;AACrB;;;ACVO,IAAM,gBAAA,GAAuD;AAAA,EAClE,KAAA,EAAO,EAAE,IAAA,EAAM,CAAA,EAAG,MAAM,CAAA,EAAE;AAAA,EAC1B,MAAA,EAAQ,EAAE,IAAA,EAAM,CAAA,EAAG,MAAM,CAAA,EAAE;AAAA,EAC3B,KAAA,EAAO,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| bigint | boolean | null | undefined\n\nfunction collect(value: ClassValue, out: string[]): void {\n if (!value) return\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint') {\n out.push(String(value))\n } else if (Array.isArray(value)) {\n for (const item of value) collect(item, out)\n } else if (typeof value === 'object') {\n for (const [name, enabled] of Object.entries(value)) if (enabled) out.push(name)\n }\n}\n\n/**\n * Joins class names, skipping empty ones (the `clsx` input shapes).\n *\n * It does not merge utilities: the package's own classes live in the\n * stylesheet's `components` layer, so a consumer's Tailwind utility already\n * wins over them through the cascade.\n */\nexport function cn(...inputs: ClassValue[]): string {\n const out: string[] = []\n for (const input of inputs) collect(input, out)\n return out.join(' ')\n}\n","import type { WidgetSize } from '../types'\n\n/** Span of a widget in widget units (one unit = one cell of the host grid). */\nexport interface WidgetUnitSpan {\n cols: number\n rows: number\n}\n\n/**\n * Single source of truth for widget geometry.\n *\n * Hosts map a widget unit onto their own grid:\n * - os63 desktop: 1 widget unit = 2 desktop cells\n * - atom63.io web: 1 widget unit = 1 CSS grid column\n */\nexport const WIDGET_UNIT_SPAN: Record<WidgetSize, WidgetUnitSpan> = {\n small: { cols: 1, rows: 1 },\n medium: { cols: 2, rows: 1 },\n large: { cols: 2, rows: 2 },\n}\n\n/**\n * Internal authoring coordinate width for one widget unit.\n *\n * Existing widget values are authored on this coordinate system. Presentation\n * scale is measured against WIDGET_CANONICAL_CELL_PX instead.\n */\nexport const WIDGET_UNIT_BASE_PX = 256\n\n/** OS63-sized 100% presentation width of one widget cell, in CSS px. */\nexport const WIDGET_CANONICAL_CELL_PX = 188\n\n/** Largest supported proportional presentation scale above the canonical cell. */\nexport const WIDGET_MAX_PRESENTATION_SCALE = 1.375\n\n/**\n * Minimum font size per floor bucket on the canonical presentation canvas.\n * Whole-canvas presentation scaling preserves these proportions in smaller\n * hosts rather than reflowing around a fixed physical type floor.\n *\n * Intent roles (chrome / label / body / title / …) live in `WIDGET_TYPE_RAMP`\n * and map onto these buckets via `WIDGET_TYPE_ROLE_FLOOR`.\n *\n * `display` is deliberately unfloored: a 40px figure at 24px is still legible,\n * and flooring it would distort the composition it anchors.\n */\nexport const WIDGET_TYPE_FLOOR = {\n label: 11,\n body: 12,\n display: 0,\n} as const\n\n/** Floor buckets used by the type ramp. Prefer `WidgetTypeRampRole` for authoring. */\nexport type WidgetTypeFloorRole = keyof typeof WIDGET_TYPE_FLOOR\n\n/** @deprecated Use `WidgetTypeFloorRole` or `WidgetTypeRampRole`. */\nexport type WidgetTypeRole = WidgetTypeFloorRole\n\n// No accessor function: consumers index `WIDGET_UNIT_SPAN[size]` directly.\n// A one-line wrapper would add public surface that enforces nothing.\n","import type { CSSProperties } from 'react'\nimport type { WidgetSize } from '../types'\nimport {\n WIDGET_CANONICAL_CELL_PX,\n WIDGET_MAX_PRESENTATION_SCALE,\n WIDGET_UNIT_BASE_PX,\n WIDGET_UNIT_SPAN,\n} from './widget-units'\n\n/** Optical density presets — multiply `--widget-scale`. */\nexport const WIDGET_DENSITY_SCALE = {\n compact: 0.9,\n default: 1,\n comfortable: 1.1,\n} as const\n\nexport type WidgetDensity = keyof typeof WIDGET_DENSITY_SCALE\n\nexport interface WidgetSizeStyleOptions {\n /** Extra multiplier on `--widget-u`. @default 1 */\n scale?: number\n /** Named density preset; multiplies `scale`. @default 'default' */\n density?: WidgetDensity\n /**\n * Floor for `--widget-u` in CSS px. Unset by default — legibility is\n * protected by per-role type floors, not by arresting the unit. A unit\n * floor lets content outgrow its own tile and overflow.\n */\n minScale?: number\n}\n\nexport type WidgetSizeStyle = CSSProperties & {\n '--a63-control-min-target': string\n '--a63-control-min-target-lg': string\n '--a63-control-min-target-xl': string\n '--widget-cell': string\n '--widget-raw-u': string\n '--widget-rows': string\n '--widget-scale': string\n '--widget-span': string\n '--widget-u': string\n}\n\n/** The design-unit properties alone — no span, no grid placement. */\nexport type WidgetUnitStyle = CSSProperties & {\n '--a63-control-min-target': string\n '--a63-control-min-target-lg': string\n '--a63-control-min-target-xl': string\n '--widget-cell': string\n '--widget-raw-u': string\n '--widget-scale': string\n '--widget-u': string\n}\n\nexport type WidgetPresentationStyle = CSSProperties & {\n '--a63-control-min-target': string\n '--a63-control-min-target-lg': string\n '--a63-control-min-target-xl': string\n '--widget-interaction-target': string\n '--widget-presentation-scale': string\n '--widget-u': string\n}\n\n/**\n * WCAG 2.2 SC 2.5.8 minimum, in physical px — the floor this repo commits to\n * for widget controls (see IMPLEMENTATION.md §8).\n */\nconst WIDGET_CONTROL_MIN_TARGET_PX = 24\n\n/**\n * Pin the shared control ergonomics floor inside a widget.\n *\n * `@atom63/styles` raises `--a63-control-min-target` to 44px on coarse pointers,\n * and every control recipe floors its RENDERED geometry with it\n * (`--button-height: max(control-height, min-target)`). That lever is right for\n * page chrome and wrong for a widget: the tile is a fixed-proportion canvas, so\n * an inflated control does not gain room, it takes it from the composition —\n * one button would claim a quarter of a 188px cell on any phone.\n *\n * Widgets reach the enhanced 44px target the other way, by expanding the hit\n * area past the visible control with `--widget-interaction-target`, so the\n * geometry can stay proportional at the documented 24px floor. Expressed\n * against the host's presentation scale where there is one, so the floor is 24\n * PHYSICAL px rather than 24 pre-transform px.\n */\nfunction controlTargetStyle(scaleDivisor?: string) {\n const target = scaleDivisor\n ? `calc(${WIDGET_CONTROL_MIN_TARGET_PX}px / ${scaleDivisor})`\n : `${WIDGET_CONTROL_MIN_TARGET_PX}px`\n\n return {\n '--a63-control-min-target': target,\n '--a63-control-min-target-lg': target,\n '--a63-control-min-target-xl': target,\n }\n}\n\n/**\n * `--widget-u` from a cell width. The OS63 cell is the 100% presentation size,\n * while fluid hosts scale the same composition proportionally in either\n * direction, capped at WIDGET_MAX_PRESENTATION_SCALE when growing.\n */\nfunction unitExpression(minScale: number | undefined): string {\n const raw = `calc(var(--widget-cell) / ${WIDGET_UNIT_BASE_PX} * var(--widget-scale, 1))`\n const maximumUnit =\n (WIDGET_CANONICAL_CELL_PX * WIDGET_MAX_PRESENTATION_SCALE) / WIDGET_UNIT_BASE_PX\n return minScale == null\n ? `min(${raw}, ${maximumUnit}px)`\n : `clamp(${minScale}px, ${raw}, ${maximumUnit}px)`\n}\n\nfunction resolveScale(scale: number, density: WidgetDensity): string {\n /** Rounded to avoid IEEE-754 artifacts leaking into CSS (`3 * 1.1` → `3.3000000000000003`). */\n return String(Math.round(scale * WIDGET_DENSITY_SCALE[density] * 1e6) / 1e6)\n}\n\n/**\n * Design-unit properties for a host whose cell width is **known in px** — the\n * os63 desktop, whose tiles are laid out on a fixed grid rather than inside a\n * `WidgetGrid` container.\n *\n * `widgetSizeStyle()` cannot serve that host: its cell is `100cqi`-derived, so\n * with no `@container` ancestor it silently resolves against the VIEWPORT, and\n * its `gridColumn`/`gridRow` would fight the desktop's own placement. This\n * returns the unit properties only, so content authored in `wuStyle` renders in\n * both hosts instead of collapsing to dropped `calc()` declarations in one.\n */\nexport function widgetUnitStyle(\n cellPx: number,\n { density = 'default', minScale, scale = 1 }: WidgetSizeStyleOptions = {}\n): WidgetUnitStyle {\n const rawUnit = unitExpression(minScale)\n\n return {\n ...controlTargetStyle(),\n '--widget-cell': `${cellPx}px`,\n '--widget-raw-u': rawUnit,\n '--widget-scale': resolveScale(scale, density),\n '--widget-u': 'var(--widget-raw-u)',\n }\n}\n\n/**\n * Normalize a widget back to its canonical 188px composition, then transform\n * the complete canvas to the host cell. This catches fixed rem/Tailwind values\n * as well as design-unit values, preserving the original spacing and type\n * ratios both above and below the canonical size. A transform is used instead\n * of CSS zoom so the presentation contract behaves consistently in Firefox.\n */\nexport function widgetPresentationStyle(\n cellPx = WIDGET_CANONICAL_CELL_PX\n): WidgetPresentationStyle {\n const presentationScale = String(\n Math.min(cellPx / WIDGET_CANONICAL_CELL_PX, WIDGET_MAX_PRESENTATION_SCALE)\n )\n\n return {\n ...controlTargetStyle('var(--widget-presentation-scale)'),\n '--widget-interaction-target': 'calc(44px / var(--widget-presentation-scale))',\n '--widget-presentation-scale': presentationScale,\n '--widget-u': 'calc(var(--widget-raw-u) / var(--widget-presentation-scale))',\n // The canvas is a fixed-size box that the transform below scales — it must\n // never be resized by its parent's layout. A host whose viewport element is\n // a flex container (atom63.io's WidgetChrome adds `flex flex-col`) makes\n // this a flex item, and a canvas laid out ABOVE the host box then shrinks to\n // fit it before the transform shrinks it again: at a 165px mobile cell the\n // 188px canvas collapsed to 165, scaled to 144.8, and a 1×1 tile rendered\n // 165×144.8 instead of square. Invisible above the canonical cell, where the\n // canvas is already smaller than its box and there is nothing to shrink.\n flexShrink: 0,\n height:\n 'calc((var(--widget-rows) * var(--widget-cell) + (var(--widget-rows) - 1) * var(--widget-gap, 0px)) / var(--widget-presentation-scale))',\n minWidth: 0,\n transform: 'scale(var(--widget-presentation-scale))',\n transformOrigin: 'top left',\n width: 'calc(100cqi / var(--widget-presentation-scale))',\n }\n}\n\n/**\n * Width of one widget unit: total inline size minus the gaps *between* the\n * spanned cells, divided by the span. `--widget-gap` is published by WidgetGrid.\n */\nconst CELL_FORMULA =\n 'calc((100cqi - (var(--widget-span) - 1) * var(--widget-gap, 0px)) / var(--widget-span))'\n\n/**\n * Build the geometry and design-unit custom properties for a widget size.\n *\n * The unit divides by the span, so a `medium` tile is twice as wide yet resolves\n * the same `--widget-u` as a `small` — type and padding stay constant across\n * sizes, and only the composition gains room.\n */\nexport function widgetSizeStyle(\n size: WidgetSize,\n { density = 'default', minScale, scale = 1 }: WidgetSizeStyleOptions = {}\n): WidgetSizeStyle {\n const { cols, rows } = WIDGET_UNIT_SPAN[size]\n const rawUnit = unitExpression(minScale)\n\n // `height: 100%` rather than a cqi-derived length: a tile cannot resolve `cqi`\n // against the `@container` it itself establishes. Row height comes from the\n // grid's `grid-auto-rows`; 100% then fills that row whether the chrome is a\n // direct grid item OR nested inside a wrapper (e.g. RecentWriting's tilted\n // stack plate), where `gridRow`/`gridColumn` would otherwise be inert.\n return {\n ...controlTargetStyle(),\n '--widget-cell': CELL_FORMULA,\n '--widget-raw-u': rawUnit,\n '--widget-rows': String(rows),\n '--widget-scale': resolveScale(scale, density),\n '--widget-span': String(cols),\n '--widget-u': 'var(--widget-raw-u)',\n gridColumn: `span ${cols}`,\n gridRow: `span ${rows}`,\n height: '100%',\n }\n}\n","import type { CSSProperties } from 'react'\n\n/**\n * Inline-style helpers for authoring widget content in DESIGN px against\n * `--widget-u`, the design unit `widgetSizeStyle()` publishes on every tile.\n *\n * These live here because the package owns `--widget-u`; a host defining its\n * own readers for a package-owned custom property is the inversion this fixes.\n * Prefer them over Tailwind arbitrary classes: dynamic class strings are never\n * seen by the Tailwind scanner.\n *\n * ## What design px does NOT do\n *\n * It does not make a value \"scale with the tile\" where a fixed rem or px value\n * would not. `WidgetViewport` wraps every widget in a transform-scaled canvas\n * (`widgetPresentationStyle`), and a transform scales the whole composition —\n * fixed rem, fixed px and design-unit lengths alike. A `2.4rem` box measured\n * 38.4px at the canonical cell and 52.7px at a 1.372 host, exactly like a\n * `wu()` length would.\n *\n * So the reason to author in design px is CONSISTENCY, not scaling: the type\n * ramp, the insets and the gaps all live on the same 256 canvas, so one dial\n * moves the whole composition and no value has to be converted by hand. Do not\n * justify a conversion as a rendering fix — it will not change the render, and\n * a changeset that claims it did is wrong.\n */\n\n/**\n * Length from a design-px value.\n * Use in inline `style` (not Tailwind class strings — scanners never see dynamic classes).\n *\n * Falls back to `1px` — design px == CSS px — when no host published a unit.\n * Without the fallback the `calc()` is INVALID and the browser drops the whole\n * declaration, so a widget in an unpublishing host loses every padding, gap and\n * font size at once and renders as unstyled text. That is a silent, total\n * collapse that types, tests and lint cannot see. Degrading to design px keeps\n * the widget legible; hosts that publish a cell-derived unit still override it.\n *\n * @example style={{ padding: wu(16), gap: wu(12) }}\n */\nexport function wu(designPx: number): string {\n return `calc(${designPx} * var(--widget-u, 1px))`\n}\n\n/**\n * Proportional length with optional a11y floor / ceiling in CSS px.\n */\nexport function wuClamp(designPx: number, minPx?: number, maxPx?: number): string {\n const mid = wu(designPx)\n if (minPx != null && maxPx != null) {\n return `clamp(${minPx}px, ${mid}, ${maxPx}px)`\n }\n if (minPx != null) {\n return `max(${minPx}px, ${mid})`\n }\n if (maxPx != null) {\n return `min(${mid}, ${maxPx}px)`\n }\n return mid\n}\n\ntype Style = CSSProperties\n\n/**\n * Inline-style helpers for design-px space / type / size.\n *\n * Prefer these over Tailwind arbitrary classes — dynamic class strings are not\n * detected by the Tailwind scanner.\n */\nexport const wuStyle = {\n p: (n: number): Style => ({ padding: wu(n) }),\n px: (n: number): Style => ({ paddingInline: wu(n) }),\n py: (n: number): Style => ({ paddingBlock: wu(n) }),\n pt: (n: number): Style => ({ paddingTop: wu(n) }),\n pb: (n: number): Style => ({ paddingBottom: wu(n) }),\n gap: (n: number): Style => ({ gap: wu(n) }),\n gapX: (n: number): Style => ({ columnGap: wu(n) }),\n gapY: (n: number): Style => ({ rowGap: wu(n) }),\n m: (n: number): Style => ({ margin: wu(n) }),\n mt: (n: number): Style => ({ marginTop: wu(n) }),\n mb: (n: number): Style => ({ marginBottom: wu(n) }),\n ml: (n: number): Style => ({ marginLeft: wu(n) }),\n mr: (n: number): Style => ({ marginRight: wu(n) }),\n mx: (n: number): Style => ({ marginInline: wu(n) }),\n my: (n: number): Style => ({ marginBlock: wu(n) }),\n size: (n: number): Style => ({ width: wu(n), height: wu(n) }),\n h: (n: number): Style => ({ height: wu(n) }),\n w: (n: number): Style => ({ width: wu(n) }),\n text: (n: number): Style => ({ fontSize: wu(n) }),\n textMin: (n: number, minPx: number): Style => ({\n fontSize: wuClamp(n, minPx),\n }),\n rounded: (n: number): Style => ({ borderRadius: wu(n) }),\n} as const\n\n/** Merge style objects (later wins). */\nexport function wuMerge(...parts: Array<Style | undefined | null | false>): Style {\n const merged: Style = {}\n for (const part of parts) {\n if (part) Object.assign(merged, part)\n }\n return merged\n}\n","import type { CSSProperties } from 'react'\nimport type { WidgetSize } from '../types'\nimport { wu } from './widget-unit-style'\n\n/**\n * Shared body / face inset in design-px (256 authoring canvas).\n *\n * Calibrated so the OS63 188 cell resolves ≈ prior Tailwind `px-3` / `px-4`:\n * - 16 × 188/256 ≈ 11.75px (was `px-3`)\n * - 22 × 188/256 ≈ 16.1px (was `px-4`)\n *\n * Prefer `widgetInsetStyle` over local `wuStyle.p(…)` or `px-3` / `p-3.5`.\n */\nexport const WIDGET_BODY_INSET = {\n small: 16,\n medium: 22,\n large: 22,\n} as const satisfies Record<WidgetSize, number>\n\n/**\n * Shared stack gap in design-px between body children.\n * ≈ Tailwind `gap-2` / `gap-3` at the OS63 cell.\n */\nexport const WIDGET_BODY_GAP = {\n small: 11,\n medium: 11,\n large: 16,\n} as const satisfies Record<WidgetSize, number>\n\nexport type WidgetInsetMode =\n /** Full-face chrome-less body — padding on all sides. */\n | 'face'\n /**\n * Horizontal + bottom only. Used under `WidgetCardHeader`, and for\n * chrome-less faces with intentional top bleed (e.g. Behance ribbons).\n */\n | 'body'\n\nexport interface WidgetInsetStyleOptions {\n /** Include `gap` from `WIDGET_BODY_GAP`. Default true. */\n gap?: boolean\n}\n\n/** Design-px inset for a footprint. */\nexport function widgetInsetPx(size: WidgetSize): number {\n return WIDGET_BODY_INSET[size]\n}\n\n/**\n * Inline padding (+ optional gap) from the shared inset ramp.\n *\n * @example\n * // Chrome-less Behance / Instagram / Location / Weather\n * style={widgetInsetStyle(size, 'face')}\n *\n * // Under WidgetCardHeader (GitHub, Profile, …)\n * style={widgetInsetStyle(size, 'body')}\n */\nexport function widgetInsetStyle(\n size: WidgetSize,\n mode: WidgetInsetMode = 'face',\n options?: WidgetInsetStyleOptions\n): CSSProperties {\n const inset = WIDGET_BODY_INSET[size]\n const includeGap = options?.gap !== false\n const style: CSSProperties = {\n paddingInline: wu(inset),\n paddingBottom: wu(inset),\n }\n\n if (mode === 'face') {\n style.paddingTop = wu(inset)\n }\n\n if (includeGap) {\n style.gap = wu(WIDGET_BODY_GAP[size])\n }\n\n return style\n}\n","import type { CSSProperties } from 'react'\nimport type { WidgetSize } from '../types'\nimport { WIDGET_TYPE_FLOOR, type WidgetTypeFloorRole } from './widget-units'\nimport { wu, wuClamp } from './widget-unit-style'\n\n/**\n * Intent roles for widget content type.\n *\n * Floors live on three buckets (`label` / `body` / `display`). Ramp roles map\n * onto those buckets so authors pick meaning, not raw px.\n *\n * Design-px targets are authored against `--widget-u` (256 design canvas).\n * Footprint steps (`small` / `medium` / `large`) are hand-authored growth for\n * roles that earn more room — they are not automatic scale-with-box.\n */\nexport const WIDGET_TYPE_ROLE_FLOOR = {\n /** Quiet uppercase identity on the chrome header. */\n chrome: 'label',\n /** Smallest supporting labels (stat keys, legends, zone tags). */\n label: 'label',\n /** Default reading copy. */\n body: 'body',\n /** Compact identity (handles, short names). */\n name: 'body',\n /** Content headings that are not the hero figure. */\n title: 'body',\n /** Featured content name (project title, primary listing). */\n headline: 'body',\n /** Mid-weight digital / tabular figures (profile stats). */\n stat: 'body',\n /** Hero figures — temperature, big totals. Unfloored. */\n display: 'display',\n /** Dense hero digits (clock faces beside a second column). Unfloored. */\n displayCompact: 'display',\n} as const satisfies Record<string, WidgetTypeFloorRole>\n\nexport type WidgetTypeRampRole = keyof typeof WIDGET_TYPE_ROLE_FLOOR\n\ntype SteppedDesignPx = Record<WidgetSize, number>\n\ninterface WidgetTypeRecipe {\n designPx: number | SteppedDesignPx\n weight: number\n trackingEm?: number\n transform?: 'uppercase'\n leading?: number\n /**\n * Optional CSS-px floor override. When set, replaces the role's bucket floor\n * (`WIDGET_TYPE_FLOOR[…]`). Use for chrome that should sit quieter than\n * content `label` copy.\n */\n floorPx?: number\n /** Leading chrome icon design-px (WidgetCardTitle). */\n iconDesignPx?: number\n /** Leading chrome icon CSS-px floor. */\n iconFloorPx?: number\n}\n\n/**\n * Derived from the live widget inventory (Location place/temp/clock, Behance\n * stats, Open Source title, Instagram handle, WidgetCardTitle chrome).\n * Prefer `widgetTypeStyle(role, size)` over local SIZE maps or Tailwind\n * `text-*` for content type.\n *\n * ## Read this before changing a design-px value\n *\n * `--widget-u` is ALWAYS `188 / 256` ≈ `0.734`, at every host and every cell\n * size. `widgetPresentationStyle` divides the unit back out of the presentation\n * transform, so one canonical composition is scaled as a whole canvas rather\n * than re-resolved per cell. A design-px value therefore renders at\n * `design × 0.734` — the 256 canvas never renders 1:1.\n *\n * That makes the CSS-px floors (`WIDGET_TYPE_FLOOR`) load-bearing rather than a\n * rare safety net, and the ramp was previously authored as if they were rare:\n * `label` (10), `body` (13), `name` (14) and `title` (16) all resolved BELOW\n * their floor and rendered at a single 11–12px step, so four distinct roles\n * were separated only by weight and colour, and the authored headline-to-body\n * ratio of 1.69 rendered as 1.35. `chrome` even inverted — authored larger than\n * `label`, rendered smaller, because its `floorPx` override let it through.\n *\n * The content roles are now authored so `design × 0.734` clears the floor on\n * its own and lands on a deliberate rendered ladder at the 1×1 footprint:\n *\n * | role | design | renders |\n * | -------- | ------ | ------- |\n * | chrome | 14 | 10.3 |\n * | label | 15 | 11.0 |\n * | body | 17 | 12.5 |\n * | name | 18 | 13.2 |\n * | title | 20 | 14.7 |\n * | stat | 22 | 16.2 |\n * | headline | 26 | 19.1 |\n * | display | 48 | 35.3 |\n *\n * `display` / `displayCompact` are unchanged: they never floored, so their\n * rendered figures were already the calibrated ones.\n *\n * ## The footprint columns are a curve, not three free values\n *\n * `body` is deliberately FLAT at 17 across all three footprints: it is reading\n * copy, and a widget that changes its reading size when the tile grows is\n * harder to scan across a desktop, not easier. A wider tile buys measure and\n * room, not bigger prose.\n *\n * That makes every heading role's footprint column a RATIO against a fixed\n * body, and the previous values let the top of the ramp run away from the\n * bottom exactly where there is most type on screen:\n *\n * | role | small | medium | large | old title:body |\n * | -------- | ----- | ------ | ----- | -------------- |\n * | title | 20 | 23 | 30 | 1.18 → 1.76 |\n * | stat | 22 | 24 | 29 | |\n * | headline | 26 | 26 | 34 | |\n *\n * A 1.18 step at 1×1 and a 1.76 step at 2×2 are not one hierarchy, they are two\n * — and the 2×2 one shouts, which is the whole \"widget type feels too big\"\n * complaint. `headline` was also non-monotonic (26 at both small and medium,\n * then a jump to 34), so doubling the tile width bought the hero name nothing\n * and doubling it again bought it 31%.\n *\n * `name` (18 / 19 / 22) was already the disciplined curve — roughly ×1.06 and\n * ×1.22 off its 1×1 value — so the other heading roles now follow it. The 1×1\n * column is untouched: that ladder is the calibrated one above, and the defect\n * was never there.\n *\n * | role | small | medium | large | title:body |\n * | -------- | ----- | ------ | ----- | ------------ |\n * | title | 20 | 22 | 24 | 1.18 → 1.41 |\n * | stat | 22 | 23 | 26 | |\n * | headline | 26 | 28 | 32 | |\n *\n * When adding a footprint step, move along this curve. A role that needs a\n * bigger jump than the curve gives is usually the wrong role for the job.\n */\nexport const WIDGET_TYPE_RAMP = {\n chrome: {\n // Mid quiet chrome: ~10.3px at OS63 (14×188/256), floored to 10 — between\n // the old text-xs (~12) and the too-quiet 9px experiment.\n designPx: 14,\n weight: 500,\n trackingEm: 0.025,\n transform: 'uppercase',\n leading: 1,\n floorPx: 10,\n // Icon sits just above the cap height.\n iconDesignPx: 14,\n iconFloorPx: 11,\n },\n label: {\n designPx: 15,\n weight: 500,\n },\n body: {\n designPx: 17,\n weight: 400,\n },\n name: {\n designPx: { small: 18, medium: 19, large: 22 },\n weight: 600,\n },\n title: {\n designPx: { small: 20, medium: 22, large: 24 },\n weight: 600,\n },\n headline: {\n designPx: { small: 26, medium: 28, large: 32 },\n weight: 600,\n // Display serif (Hedvig Letters Serif) with tall ascenders — 1.12 read as\n // two lines fighting for the same band once the headline cleared its floor.\n leading: 1.18,\n },\n stat: {\n designPx: { small: 22, medium: 23, large: 26 },\n weight: 600,\n },\n display: {\n designPx: { small: 48, medium: 44, large: 64 },\n weight: 600,\n },\n displayCompact: {\n designPx: { small: 40, medium: 34, large: 52 },\n weight: 600,\n },\n} as const satisfies Record<WidgetTypeRampRole, WidgetTypeRecipe>\n\nexport interface WidgetTypeStyleOptions {\n /** Override design-px when a composition needs a one-off step. Prefer ramp. */\n designPx?: number\n /** Override weight (e.g. weather display uses extralight). */\n weight?: number\n leading?: number\n trackingEm?: number\n}\n\nfunction resolveDesignPx(designPx: number | SteppedDesignPx, size: WidgetSize): number {\n return typeof designPx === 'number' ? designPx : designPx[size]\n}\n\n/** Design-px target for a ramp role at a footprint. */\nexport function widgetTypeDesignPx(role: WidgetTypeRampRole, size: WidgetSize = 'medium'): number {\n return resolveDesignPx(WIDGET_TYPE_RAMP[role].designPx, size)\n}\n\n/**\n * Inline type styles for a ramp role.\n *\n * Returns `fontSize` (wu + floor), `fontWeight`, and chrome extras when present.\n * Pair with Tailwind only for color / truncation / layout — not for size.\n */\nexport function widgetTypeStyle(\n role: WidgetTypeRampRole,\n size: WidgetSize = 'medium',\n options?: WidgetTypeStyleOptions\n): CSSProperties {\n // Narrow `as const` recipes omit optional fields; widen to the recipe shape.\n const recipe: WidgetTypeRecipe = WIDGET_TYPE_RAMP[role]\n const floorRole = WIDGET_TYPE_ROLE_FLOOR[role]\n const floorPx = recipe.floorPx ?? WIDGET_TYPE_FLOOR[floorRole]\n const designPx = options?.designPx ?? resolveDesignPx(recipe.designPx, size)\n const weight = options?.weight ?? recipe.weight\n const trackingEm = options?.trackingEm ?? recipe.trackingEm\n const leading = options?.leading ?? recipe.leading\n\n const style: CSSProperties = {\n fontSize: floorPx > 0 ? wuClamp(designPx, floorPx) : wu(designPx),\n fontWeight: weight,\n }\n\n if (trackingEm != null) {\n style.letterSpacing = `${trackingEm}em`\n }\n if (recipe.transform) {\n style.textTransform = recipe.transform\n }\n if (leading != null) {\n style.lineHeight = leading\n }\n\n return style\n}\n\n/**\n * Leading icon box for `WidgetCardTitle` — sized from the chrome recipe so the\n * glyph tracks the quiet header label.\n */\nexport function widgetChromeIconStyle(): CSSProperties {\n const recipe: WidgetTypeRecipe = WIDGET_TYPE_RAMP.chrome\n const designPx = recipe.iconDesignPx ?? resolveDesignPx(recipe.designPx, 'medium')\n const floorPx = recipe.iconFloorPx ?? recipe.floorPx ?? WIDGET_TYPE_FLOOR.label\n return {\n width: floorPx > 0 ? wuClamp(designPx, floorPx) : wu(designPx),\n height: floorPx > 0 ? wuClamp(designPx, floorPx) : wu(designPx),\n }\n}\n\n/**\n * Descender relief for text that also carries `line-clamp-*`.\n *\n * `line-clamp` implies `overflow: hidden`, and the clip box is exactly\n * `line-height × lines`. Any ramp role authored with tight leading therefore\n * has a line box SHORTER than the font's own box, and the last line's\n * descenders are shaved — silently, at every width, whether or not the clamp\n * actually truncates anything.\n *\n * Measured on the open-source headline (Hedvig Letters Serif 600, leading\n * 1.12): the box ended 1.95px above the ink. `0.24em` covers the font's full\n * declared descent rather than one sample string, so no glyph can reach past\n * it, and the matching negative margin hands the space back to layout — the\n * glyphs become whole without anything moving.\n *\n * `truncate` has the same problem for the same reason — it also sets\n * `overflow: hidden`, and a single line box is just as short.\n *\n * Pass `'emoji'` for a line that can carry one. Emoji ink runs well past the\n * font's declared descent, so the text relief only halves the cut: the profile\n * stat row still shaved 3px off a cat's chin at `leading: 1`.\n *\n * @example\n * <span className=\"line-clamp-4\" style={widgetClampRelief()}>{title}</span>\n * <dt className=\"truncate\" style={widgetClampRelief('emoji')}>{label}</dt>\n */\nexport function widgetClampRelief(content: 'emoji' | 'text' = 'text'): CSSProperties {\n const relief = content === 'emoji' ? '0.55em' : '0.24em'\n return {\n paddingBottom: relief,\n marginBottom: `-${relief}`,\n }\n}\n","import {\n createContext,\n useContext,\n type ComponentPropsWithRef,\n type CSSProperties,\n type ReactNode,\n} from 'react'\nimport type { WidgetSize } from '../types'\n\nconst WidgetSizeContext = createContext<WidgetSize>('small')\n\n/**\n * Reports the size a widget is being rendered at, so a widget supporting more\n * than one size can pick the matching composition.\n */\nexport function useWidgetSize(): WidgetSize {\n return useContext(WidgetSizeContext)\n}\n\nexport interface WidgetSizeProviderProps {\n children: ReactNode\n size: WidgetSize\n}\n\nexport function WidgetSizeProvider({ children, size }: WidgetSizeProviderProps) {\n return <WidgetSizeContext.Provider value={size}>{children}</WidgetSizeContext.Provider>\n}\n\ntype WidgetGridStyle = CSSProperties & {\n '--widget-cols': string\n '--widget-gap': string\n}\n\nexport interface WidgetGridProps extends ComponentPropsWithRef<'div'> {\n /** Track count. Fixed, not responsive — every size keeps its shape at every width. @default 2 */\n columns?: number\n /** Gutter in CSS px. @default 12 */\n gap?: number\n}\n\n/**\n * Widget grid container. Owns track count and gap, and publishes both as custom\n * properties so each tile's cell-derived unit can divide them out.\n *\n * Tracks are explicit rather than `auto-fill`: with intrinsic tracks a narrow\n * container resolves to one column and a `span 2` tile would create an implicit\n * second column and overflow.\n *\n * Rows are sized here rather than on the tile: an element cannot resolve\n * container-query units against the `@container` it establishes itself, so the\n * grid is wrapped in a container and `grid-auto-rows` resolves `100cqi` against\n * that ancestor. Tiles just fill their area, and spanning tiles inherit the\n * inter-row gaps from the grid.\n */\nexport function WidgetGrid({\n children,\n columns = 2,\n gap = 12,\n ref,\n style,\n ...props\n}: WidgetGridProps) {\n const gridStyle: WidgetGridStyle = {\n '--widget-cols': String(columns),\n '--widget-gap': `${gap}px`,\n display: 'grid',\n gap: `${gap}px`,\n gridAutoRows:\n 'calc((100cqi - (var(--widget-cols) - 1) * var(--widget-gap)) / var(--widget-cols))',\n gridTemplateColumns: 'repeat(var(--widget-cols), minmax(0, 1fr))',\n ...style,\n }\n\n return (\n <div ref={ref} style={{ containerType: 'inline-size' }} {...props}>\n <div style={gridStyle}>{children}</div>\n </div>\n )\n}\n","import {\n type ComponentPropsWithRef,\n type ComponentType,\n type ReactNode,\n type Ref,\n useCallback,\n useLayoutEffect,\n useRef,\n} from 'react'\nimport type { WidgetSize } from '../types'\nimport { cn } from '../utils'\nimport { WidgetSizeProvider } from './widget-grid'\nimport { widgetPresentationStyle, widgetSizeStyle } from './widget-scale'\nimport { WIDGET_CANONICAL_CELL_PX, WIDGET_MAX_PRESENTATION_SCALE } from './widget-units'\n\nexport interface WidgetViewportProps extends Omit<ComponentPropsWithRef<'article'>, 'children'> {\n /**\n * The host grid's cell width in CSS px, when the host already knows it.\n *\n * Left unset the viewport derives the cell from its own measured box, which\n * is right at rest and wrong while that box is moving: a host that animates\n * the shell between two sizes re-fires the observer every frame, the cell\n * follows the travelling width, and the composition zooms inside the growing\n * box instead of reflowing in it. The cell a tile lands in is a property of\n * the *grid*, identical for a 1x1 and a 2x1, so a host that measures its own\n * tracks can say so once and the observer never runs.\n *\n * Passing it also frees the canvas height to follow the host box rather than\n * the cell — the two are the same number at rest, and only the first of them\n * is still true mid-flight.\n */\n cellPx?: number\n children: ReactNode\n size: WidgetSize\n}\n\nfunction assignRef<T>(ref: Ref<T> | undefined, value: T | null) {\n if (typeof ref === 'function') {\n ref(value)\n } else if (ref) {\n ref.current = value\n }\n}\n\n/**\n * Fluid host boundary for a canonical widget view.\n *\n * The viewport owns grid placement and publishes the design unit. The widget\n * view inside owns all visible surface, composition, and state styling.\n */\nexport function WidgetViewport({\n cellPx,\n children,\n className,\n ref,\n size,\n style,\n ...props\n}: WidgetViewportProps) {\n const viewportRef = useRef<HTMLElement | null>(null)\n const canvasRef = useRef<HTMLDivElement | null>(null)\n const setViewportRef = useCallback(\n (node: HTMLElement | null) => {\n viewportRef.current = node\n assignRef(ref, node)\n },\n [ref]\n )\n\n useLayoutEffect(() => {\n const viewport = viewportRef.current\n const canvas = canvasRef.current\n if (!viewport || !canvas) return\n // The host told us the cell, so there is nothing to measure and nothing to\n // watch: the scale is already on the canvas, from `widgetPresentationStyle`.\n if (cellPx != null) return\n\n const updatePresentationScale = () => {\n const computedStyle = getComputedStyle(viewport)\n const span = Number.parseFloat(computedStyle.getPropertyValue('--widget-span')) || 1\n const gap = Number.parseFloat(computedStyle.getPropertyValue('--widget-gap')) || 0\n const cellPx = (viewport.getBoundingClientRect().width - (span - 1) * gap) / span\n const scale = Math.min(cellPx / WIDGET_CANONICAL_CELL_PX, WIDGET_MAX_PRESENTATION_SCALE)\n canvas.style.setProperty('--widget-presentation-scale', String(scale))\n }\n\n updatePresentationScale()\n\n if (typeof ResizeObserver === 'undefined') {\n window.addEventListener('resize', updatePresentationScale)\n return () => window.removeEventListener('resize', updatePresentationScale)\n }\n\n const observer = new ResizeObserver(updatePresentationScale)\n observer.observe(viewport)\n return () => observer.disconnect()\n }, [cellPx, size])\n\n const presentationStyle =\n cellPx == null\n ? widgetPresentationStyle()\n : {\n ...widgetPresentationStyle(cellPx),\n // Off the cell, onto the box. The cell-derived height is the row's\n // resting height, which is the same number — until the host animates\n // the shell between two sizes, when the box is the one that is still\n // true. `100%` resolves against the viewport, which is `size-full`.\n height: 'calc(100% / var(--widget-presentation-scale))',\n }\n\n return (\n <WidgetSizeProvider size={size}>\n <article\n className={cn('a63-WidgetViewport', className)}\n data-widget-viewport=\"\"\n data-widget-viewport-size={size}\n ref={setViewportRef}\n style={{\n ...widgetSizeStyle(size),\n // A known cell replaces the `100cqi`-derived one, so `--widget-u`\n // stops tracking a travelling width along with it.\n ...(cellPx == null ? null : { '--widget-cell': `${cellPx}px` }),\n ...style,\n }}\n {...props}\n >\n <div data-widget-presentation-canvas=\"\" ref={canvasRef} style={presentationStyle}>\n {children}\n </div>\n </article>\n </WidgetSizeProvider>\n )\n}\n\n/**\n * Wrap a sized widget component so it carries its own viewport.\n *\n * A widget's composition is authored on a 256 design-px canvas and only\n * resolves against real pixels once a host publishes `--widget-u`. Grid hosts\n * (the OS63 desktop, the atom63.io board) publish it by placing tiles in a\n * `WidgetViewport` themselves. Hosts that render a widget on its own — agent\n * chat renders one per message, in an intrinsically sized frame — have no grid\n * to hang that on, and a widget mounted without it silently renders design px\n * at 1:1: ~36% oversized type, padding and gaps, clipped by the shell wherever\n * the overflow lands.\n *\n * Use this at the registry boundary of such a host so the widget arrives\n * already scaled, rather than re-deriving the unit per call site.\n *\n * @example\n * component: () => import('./weather').then(m => withWidgetViewport(m.Weather))\n */\nexport function withWidgetViewport<P extends { size: WidgetSize }>(\n Component: ComponentType<P>\n): ComponentType<P> {\n function WidgetViewportBoundary(props: P) {\n return (\n <WidgetViewport className=\"a63-WidgetViewport-fill\" size={props.size}>\n <Component {...props} />\n </WidgetViewport>\n )\n }\n\n WidgetViewportBoundary.displayName = `withWidgetViewport(${Component.displayName ?? Component.name ?? 'Widget'})`\n\n return WidgetViewportBoundary\n}\n"]}
|